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

Generated on Tue Jul 15 16:46:52 2003 for X3DToolKit by doxygen1.3