00001
00002
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
00034 defineNewEnterFunction<TemplateMeshBuilderGeometry3DVisitor, IndexedFaceSet>(&TemplateMeshBuilderGeometry3DVisitor::enterIndexedFaceSet);
00035
00036
00037 globalVariables = GVManager::getInstanceOf<TemplateMeshBuilderGlobalVariables>();
00038 };
00039
00041 virtual ~TemplateMeshBuilderGeometry3DVisitor()
00042 {
00043 };
00044
00046 virtual void enterIndexedFaceSet(IndexedFaceSet *I) const
00047 {
00048
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
00062
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
00074 for (MFVec3f::const_iterator itPoint = pointArray.begin(); itPoint != pointArray.end(); ++itPoint)
00075 TM->createVertex();
00076
00077 SFBool ccw = I->getCcw();
00078
00079
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
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
00106 A = B;
00107 }
00108
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
00117 MEdge me(faceEdgeList, ccw);
00118
00119 Face *F = TM->createFace(me);
00120
00121
00122 Mesh::processNewFace<IndexedFaceSet, Face, Mesh::TemplateMesh<MData, VData, EData, FData> >(I, F, TM);
00123
00124 ++itCoordIndex;
00125 }
00126
00127
00128 Mesh::end<IndexedFaceSet, Mesh::TemplateMesh<MData, VData, EData, FData> >(I, TM);
00129
00130
00131
00132
00133
00134 };
00135
00136 protected:
00137 TemplateMeshBuilderGlobalVariables *globalVariables;
00138 };
00139
00140 }
00141 }
00142
00143 #endif