Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

TemplateMeshBuilderGeometry3DVisitor.h

Go to the documentation of this file.
00001 
00002 //                            TemplateMeshBuilderGeometry3DVisitor.h          //
00004 
00005 #ifndef TEMPLATEMESHBUILDERGEOMETRY3DVISITOR_H
00006 #define TEMPLATEMESHBUILDERGEOMETRY3DVISITOR_H
00007 
00008 #include "Geometry3DVisitor.h"
00009 #include "TemplateMeshBuilderGlobalVariables.h"
00010 #include "Coordinate.h"
00011 #include "Box.h"
00012 #include "Cone.h"
00013 #include "Cylinder.h"
00014 #include "IndexedFaceSet.h"
00015 #include "Sphere.h"
00016 #include "MESH_TemplateMesh.h"
00017 
00018 namespace X3DTK {
00019 namespace X3D {
00020 
00022 
00023 template<class MData, class VData, class EData, class FData>
00024 class TemplateMeshBuilderGeometry3DVisitor : public Geometry3DVisitor
00025 {
00026 public:
00028   TemplateMeshBuilderGeometry3DVisitor()
00029   : Geometry3DVisitor()
00030   {
00031     // Enter functions.
00032     defineNewEnterFunction(&TemplateMeshBuilderGeometry3DVisitor::enterIndexedFaceSet);
00033 
00034     // GlobalVariables assignation.
00035     globalVariables = GVManager::getInstanceOf<TemplateMeshBuilderGlobalVariables>();
00036   };
00037   
00039   virtual ~TemplateMeshBuilderGeometry3DVisitor()
00040   {
00041   };
00042 
00044   virtual void enterIndexedFaceSet(IndexedFaceSet *I) const
00045   {
00046     // future optim? reserve the vertices and edges.
00047   
00048     typedef MESH::TemplateVertex<VData, EData, FData> Vertex;
00049     typedef MESH::MTemplateVertex<VData, EData, FData> MVertex;
00050     typedef MESH::TemplateEdge<EData, FData, VData> Edge;
00051     typedef MESH::MTemplateEdge<EData, FData, VData> MEdge;
00052     typedef MESH::TemplateFace<FData, VData, EData> Face;
00053     typedef MESH::MTemplateFace<FData, VData, EData> MFace;
00054            
00055     MESH::TemplateMesh<MData, VData, EData, FData> *TM = new MESH::TemplateMesh<MData, VData, EData, FData>();
00056     globalVariables->getTop()->addChild(TM);
00057     globalVariables->pushNode(TM);
00058     
00059     // filling the mesh.
00060     // points creation
00061     Coordinate *CoordNode = static_cast<Coordinate *>(I->getCoord());
00062     if (CoordNode == NULL)
00063       return;
00064     
00065     MFVec3f pointArray = CoordNode->getPoint();
00066     if (pointArray.empty())
00067       return;
00068     
00069     TM->start(I);
00070     
00071     // iterating the points
00072     for (MFVec3f::const_iterator itPoint = pointArray.begin(); itPoint != pointArray.end(); ++itPoint)
00073       TM->createVertex();
00074     
00075     SFBool ccw = I->getCcw();
00076     
00077     //iterating the faces
00078     const MFInt32 &coordIndex = I->getCoordIndex();
00079     MFInt32::const_iterator itCoordIndex = coordIndex.begin();
00080     
00081     while (itCoordIndex != coordIndex.end())
00082     {
00083       Vertex *A, *B;      
00084       Edge *E;
00085       // creating the edges of the face.
00086       Vertex *start = TM->getVertices()[*itCoordIndex];
00087       
00088       A = start;
00089       ++itCoordIndex;
00090 
00091       std::vector<Edge *> faceEdgeList;      
00092       while (*itCoordIndex != -1)
00093       {
00094         B = TM->getVertices()[*itCoordIndex];
00095         ++itCoordIndex;
00096       
00097         E = TM->getEdge(A, B);
00098         if (E == 0)
00099           E = TM->createEdge(A, B);
00100             
00101         faceEdgeList.push_back(E);
00102         // moving to the next edge.
00103         A = B;
00104       }
00105       // ending the loop
00106       B = start;
00107       E = TM->getEdge(A, B);
00108       if (E == 0)
00109         E = TM->createEdge(A, B);
00110   
00111       faceEdgeList.push_back(E);
00112         
00113       // creating a new face.
00114       MEdge me(faceEdgeList, ccw);
00115       
00116       Face *F = TM->createFace(me);
00117       
00118       // processing the new face.
00119       TM->processNewFace(I, F);
00120 
00121       ++itCoordIndex;
00122     }
00123     
00124     // ending the algorithm.
00125     TM->end(I);
00126   };
00127   
00128 protected:
00129   TemplateMeshBuilderGlobalVariables *globalVariables;
00130 };
00131 
00132 }
00133 }
00134 
00135 #endif

Generated on Thu Oct 9 13:50:54 2003 for X3DToolKit by doxygen1.2.18