[Jderobot-admin] jderobot-r933 - in trunk/src/libs/geometry: collada math

ahcorde en jderobot.org ahcorde en jderobot.org
Lun Jun 17 10:14:44 CEST 2013


Author: ahcorde
Date: 2013-06-17 10:13:43 +0200 (Mon, 17 Jun 2013)
New Revision: 933

Modified:
   trunk/src/libs/geometry/collada/colladaparser.cpp
   trunk/src/libs/geometry/collada/colladaparser.h
   trunk/src/libs/geometry/collada/malla.cpp
   trunk/src/libs/geometry/collada/malla.h
   trunk/src/libs/geometry/collada/submalla.cpp
   trunk/src/libs/geometry/collada/submalla.h
   trunk/src/libs/geometry/math/vector3.cpp
   trunk/src/libs/geometry/math/vector3.h
Log:
[ahcorde]


Modified: trunk/src/libs/geometry/collada/colladaparser.cpp
===================================================================
--- trunk/src/libs/geometry/collada/colladaparser.cpp	2013-06-11 07:40:21 UTC (rev 932)
+++ trunk/src/libs/geometry/collada/colladaparser.cpp	2013-06-17 08:13:43 UTC (rev 933)
@@ -37,6 +37,10 @@
         mesh->setPath(this->filename);
 
         loadScene(mesh);
+
+        mesh->Scale(this->meter*100);
+
+        worldTo2D();
     }
 
     int ite = 0;
@@ -132,7 +136,6 @@
                 unsigned int indice =submalla->getIndex(k);
 
                 math::Vector3 v= submalla->getVertex(indice);
-                math::Vector3 normals= submalla->getNormal(indice);
                 if(submalla->getNormalCount()>0){
                     math::Vector3 normals= submalla->getNormal(indice);
                     glNormal3f(normals.vector(0), normals.vector(1), normals.vector(2));
@@ -1337,5 +1340,124 @@
         std::cout  << "profile_CG unsupported\n";
       return mat;
     }
+
+    void ColladaParser::worldTo2D()
+    {
+        std::vector<Segmento> listaSegmentos;
+
+        for(int i = 0; i < this->mesh->getSubMeshCount();i++){
+
+            SubMalla* submalla = this->mesh->getSubMesh(i);
+
+            Plano plano1(0, 0, 1, -0.5);
+            Plano plano2(0, 0, 1, 400.0);
+            Plano p_proyeccion(0, 0, 1, 0);
+
+            math::Vector3 inter1;
+
+            int triangulo = 0;
+            int indice_triangulo = 0;
+
+            for(int k = 0; k < submalla->getVertexCount()-1; k++){
+                unsigned int indice =submalla->getIndex(k);
+
+                triangulo++;
+                if(triangulo == 3){
+                    indice_triangulo++;
+                    triangulo = 0;
+                }
+
+                math::Vector3 v1= submalla->getVertex(indice%3 + indice_triangulo*3);
+                math::Vector3 v2= submalla->getVertex((indice+1)%3 + indice_triangulo*3);
+
+                inter1 = plano1.InterConRecta(v1, v2);
+
+                if(inter1.getX()!=0 && inter1.getY()!=0 && inter1.getZ()!=0 ){
+                    math::Vector3 proyeccion1 = p_proyeccion.proyeccionOrtogonal(v1, p_proyeccion.getCoefA(), p_proyeccion.getCoefB(), p_proyeccion.getCoefC());
+                    math::Vector3 proyeccion2 = p_proyeccion.proyeccionOrtogonal(v2, p_proyeccion.getCoefA(), p_proyeccion.getCoefB(), p_proyeccion.getCoefC());
+
+                    double dist = proyeccion1.distance(proyeccion2);
+
+                    if(dist > 1){
+                        listaSegmentos.push_back(Segmento(proyeccion1,proyeccion2));
+                    }
+                }
+
+                inter1 = plano2.InterConRecta(v1, v2);
+
+                if(inter1.getX()!=0 && inter1.getY()!=0 && inter1.getZ()!=0 ){
+                    math::Vector3 proyeccion1 = p_proyeccion.proyeccionOrtogonal(v1, p_proyeccion.getCoefA(), p_proyeccion.getCoefB(), p_proyeccion.getCoefC());
+                    math::Vector3 proyeccion2 = p_proyeccion.proyeccionOrtogonal(v2, p_proyeccion.getCoefA(), p_proyeccion.getCoefB(), p_proyeccion.getCoefC());
+
+                    double dist = proyeccion1.distance(proyeccion2);
+
+                    if(dist > 1){
+                        listaSegmentos.push_back(Segmento(proyeccion1,proyeccion2));
+                    }
+                }
+            }
+
+//            int verticesDentroSandwich = 0;
+//            float distanciaEntrePlanos = plano2.distanciaAPunto(0, 0, 1);
+//            std::vector<math::Vector3> vectorProyecciones;
+
+//            for(int k = 0; k < submalla->getVertexCount()-1; k++){
+//                unsigned int indice =submalla->getIndex(k);
+
+//                math::Vector3 v1= submalla->getVertex(indice);
+
+//                float distanciaEntrePlanos1_1 = plano1.distanciaAPunto(v1);
+
+//                float distanciaEntrePlanos1_2 = plano2.distanciaAPunto(v1);
+
+//                if(fabs(distanciaEntrePlanos1_1+distanciaEntrePlanos1_2)<=fabs(distanciaEntrePlanos)){
+//                    verticesDentroSandwich++;
+//                    vectorProyecciones.push_back(p_proyeccion.proyeccionOrtogonal(v1,
+//                                                                                  p_proyeccion.getCoefA(),
+//                                                                                  p_proyeccion.getCoefB(),
+//                                                                                  p_proyeccion.getCoefC()));
+//                }
+//            }
+
+//            if(submalla->getVertexCount()==verticesDentroSandwich){
+//                for(int k = 0; k < submalla->getVertexCount()-1; k++){
+//                    unsigned int indice =submalla->getIndex(k);
+
+//                    math::Vector3 v1= submalla->getVertex(indice);
+//                    math::Vector3 v2= submalla->getVertex(indice);
+
+//                    float dist = v1.distance(v2);
+
+//                    if(dist > 2){
+//                        listaSegmentos.push_back(Segmento( v1, v2));
+//                    }
+//                }
+//            }
+        }
+
+
+        math::Vector3 max = mesh->getMax();
+        math::Vector3 min = mesh->getMin();
+        image.create(max.getY() - min.getY(), max.getX() - min.getY(), CV_8UC3);
+
+        image = cv::Scalar(255, 255, 255);
+
+        for(int i = 0; i < listaSegmentos.size(); i++){
+            cv::line(image,
+                     cv::Point2f(listaSegmentos[i].x1 - min.getX(), listaSegmentos[i].y1 - min.getY()),
+                     cv::Point2f(listaSegmentos[i].x2 - min.getX(), listaSegmentos[i].y2 - min.getY()),
+                     cv::Scalar(0, 0, 0),
+                     3);
+        }
+        cv::imwrite("mapa.jpg", image);
+
+    }
+
+    cv::Mat ColladaParser::getWorld2D()
+    {
+        return this->image.clone();
+    }
+
 }
 
+

Modified: trunk/src/libs/geometry/collada/colladaparser.h
===================================================================
--- trunk/src/libs/geometry/collada/colladaparser.h	2013-06-11 07:40:21 UTC (rev 932)
+++ trunk/src/libs/geometry/collada/colladaparser.h	2013-06-17 08:13:43 UTC (rev 933)
@@ -19,6 +19,8 @@
 #include "math/matriz4x4.h"
 #include "math/matriz3x3.h"
 #include "math/vector3.h"
+#include "math/plano.h"
+#include "math/segmento.h"
 
 #include <GL/glut.h>
 #include <GL/gl.h>
@@ -29,6 +31,10 @@
     public:
         ColladaParser(std::string filename);
 
+        void worldTo2D();
+        cv::Mat getWorld2D();
+
+
         void loadScene(Malla *_mesh);
 
         void draw();
@@ -103,6 +109,10 @@
         private: std::map<std::string, std::string> materialMap;
 
     public: Malla *mesh;
+
+    public: cv::Mat image;
+
+
     };
 }
 

Modified: trunk/src/libs/geometry/collada/malla.cpp
===================================================================
--- trunk/src/libs/geometry/collada/malla.cpp	2013-06-11 07:40:21 UTC (rev 932)
+++ trunk/src/libs/geometry/collada/malla.cpp	2013-06-17 08:13:43 UTC (rev 933)
@@ -17,6 +17,14 @@
     }
 
     //////////////////////////////////////////////////
+    void Malla::Scale(double _factor)
+    {
+      std::vector<SubMalla*>::iterator iter;
+      for (iter = this->submeshes.begin(); iter != this->submeshes.end(); ++iter)
+        (*iter)->Scale(_factor);
+    }
+
+    //////////////////////////////////////////////////
     int Malla::addMaterial(Material *_mat)
     {
       int result = -1;

Modified: trunk/src/libs/geometry/collada/malla.h
===================================================================
--- trunk/src/libs/geometry/collada/malla.h	2013-06-11 07:40:21 UTC (rev 932)
+++ trunk/src/libs/geometry/collada/malla.h	2013-06-17 08:13:43 UTC (rev 933)
@@ -19,6 +19,8 @@
         SubMalla *getSubMesh(unsigned int i) const;
         Material *getMaterial(int index);
 
+        void Scale(double _factor);
+
         math::Vector3 getMax() const;
         math::Vector3 getMin() const;
 

Modified: trunk/src/libs/geometry/collada/submalla.cpp
===================================================================
--- trunk/src/libs/geometry/collada/submalla.cpp	2013-06-11 07:40:21 UTC (rev 932)
+++ trunk/src/libs/geometry/collada/submalla.cpp	2013-06-17 08:13:43 UTC (rev 933)
@@ -16,6 +16,18 @@
     }
 
     //////////////////////////////////////////////////
+    void SubMalla::Scale(double _factor)
+    {
+      for (std::vector<math::Vector3>::iterator iter = this->vertices.begin();
+           iter != this->vertices.end(); ++iter)
+      {
+          (*iter).vector(0) *= _factor;
+          (*iter).vector(1) *= _factor;
+          (*iter).vector(2) *= _factor;
+      }
+    }
+
+    //////////////////////////////////////////////////
     void SubMalla::setPrimitiveType(PrimitiveType _type)
     {
       this->primitiveType = _type;

Modified: trunk/src/libs/geometry/collada/submalla.h
===================================================================
--- trunk/src/libs/geometry/collada/submalla.h	2013-06-11 07:40:21 UTC (rev 932)
+++ trunk/src/libs/geometry/collada/submalla.h	2013-06-17 08:13:43 UTC (rev 933)
@@ -20,6 +20,8 @@
 
         public: virtual ~SubMalla();
 
+        void Scale(double _factor);
+
         public: void setName(const std::string &_n);
 
         public: void setPrimitiveType(PrimitiveType _type);

Modified: trunk/src/libs/geometry/math/vector3.cpp
===================================================================
--- trunk/src/libs/geometry/math/vector3.cpp	2013-06-11 07:40:21 UTC (rev 932)
+++ trunk/src/libs/geometry/math/vector3.cpp	2013-06-17 08:13:43 UTC (rev 933)
@@ -82,5 +82,11 @@
       return *this;
     }
 
+    double Vector3::distance(math::Vector3 p){
+        return sqrt( pow(p.getX()-this->vector(0),2) +
+                     pow(p.getY()-this->vector(1),2) +
+                     pow(p.getZ()-this->vector(2),2));
+    }
 
+
 }

Modified: trunk/src/libs/geometry/math/vector3.h
===================================================================
--- trunk/src/libs/geometry/math/vector3.h	2013-06-11 07:40:21 UTC (rev 932)
+++ trunk/src/libs/geometry/math/vector3.h	2013-06-17 08:13:43 UTC (rev 933)
@@ -23,6 +23,8 @@
         public: void setZ(float f);
 
         Vector3 normalize();
+        double distance(math::Vector3 p);
+
         public: Eigen::Vector3f vector;
 
     public: Vector3 operator+(const Vector3 &pt) const;



More information about the Jderobot-admin mailing list