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

Generated on Wed Sep 10 11:25:14 2003 for X3DToolKit by doxygen1.3