source: trunk/VUT/GtpVisibilityPreprocessor/src/X3dParser.cpp @ 162

Revision 162, 3.4 KB checked in by bittner, 19 years ago (diff)

functional raycasting version

Line 
1
2#include "X3dParser.h"
3
4
5bool
6X3dParser::ParseFile(const string filename,
7                     SceneGraphNode **root)
8{
9 
10 
11 
12}
13
14 
15namespace X3DTK {
16namespace MESH {
17
18MyStructureComputer::MyStructureComputer()
19{
20  setGraphTraversal(new DFSGraphTraversal());
21        setComponentVisitor(new MyStructureComputerCoreVisitor());
22      }
23     
24      MyStructureComputer::~MyStructureComputer()
25      {
26        Singleton<MyStructureComputerStateVariables>::removeInstance();
27      }
28     
29      MySimpleMesh *MyStructureComputer::compute(SFNode N)
30      {
31        Singleton<MyStructureComputerStateVariables>::getInstance()->init();
32        traverse(N);
33        Singleton<MyStructureComputerStateVariables>::getInstance()->finish();
34       
35        return Singleton<MyStructureComputerStateVariables>::getInstance()->getMesh();
36      }
37     
38     
39      MyStructureComputerCoreVisitor::MyStructureComputerCoreVisitor()
40      {
41        // Enter functions.
42        define(Recorder<Mesh>::getEnterFunction(&MyStructureComputerCoreVisitor::enterMesh));
43        define(Recorder<Transform>::getEnterFunction(&MyStructureComputerCoreVisitor::enterTransform));
44        // Leave function.
45        define(Recorder<X3DGroupingNode>::getLeaveFunction(&MyStructureComputerCoreVisitor::leaveX3DGroupingNode));
46      }
47     
48      void MyStructureComputerCoreVisitor::enterMesh(Mesh *M)
49      {
50        // StateVariables assignation.
51        MyStructureComputerStateVariables *stateVariables = Singleton<MyStructureComputerStateVariables>::getInstance();
52       
53        SFMatrix34f T = stateVariables->getMatrix();
54
55  // Beginning a new Mesh by memorizing the current vertex index.
56  stateVariables->beginNewMesh();
57
58  // filling the vertices.
59  for (Mesh::MFVertex::const_iterator v = M->getVertices().begin(); v != M->getVertices().end(); ++v)
60  {
61    SFPoint3f P = T*(*v)->data().getPoint();
62    stateVariables->addVertex(P.x, P.y, P.z);
63  }
64 
65  // filling the faces.
66  for (Mesh::MFFace::const_iterator
67         f = M->getFaces().begin(); f != M->getFaces().end(); ++f)
68  {
69    const SFFace::MFEdge &edges = (*f)->getEdges();
70    list<unsigned int> indexList;
71    for (SFFace::MFEdge::const_iterator e = edges.begin(); e != edges.end(); ++e)
72      indexList.push_back((*e)->getFromVertex()->getIndex());
73   
74    stateVariables->addFace(indexList);
75  }
76}
77
78void MyStructureComputerCoreVisitor::enterTransform(Transform *T)
79{
80  Singleton<MyStructureComputerStateVariables>::getInstance()->pushMatrix(T->getTransform());
81}
82
83void MyStructureComputerCoreVisitor::leaveX3DGroupingNode(X3DGroupingNode *)
84{
85  Singleton<MyStructureComputerStateVariables>::getInstance()->popMatrix();
86}
87
88: StateVariables(), _mesh(0), _decal(0)
89{
90}
91
92void MyStructureComputerStateVariables::init()
93{
94  _mesh = new MySimpleMesh();
95  _matrixStack.push_front(SFMatrix34f::identity);
96}
97
98void MyStructureComputerStateVariables::finish()
99{
100  _matrixStack.clear();
101}
102
103void MyStructureComputerStateVariables::beginNewMesh()
104{
105  _decal = _mesh->getVertexArray().size();
106}
107
108void MyStructureComputerStateVariables::addFace(const Face &face)
109{
110  //  MyFace decalFace = face;
111  //  for (MyFace::iterator it = decalFace.begin(); it != decalFace.end(); ++it)
112  //    *it = _decal + *it;
113   
114  //  _mesh->addFace(decalFace);
115};
116
117void MyStructureComputerStateVariables::pushMatrix(const SFMatrix34f &transformation)
118{
119  _matrixStack.push_front(_matrixStack.front()*transformation);
120}
121
122void MyStructureComputerStateVariables::popMatrix()
123{
124  _matrixStack.pop_front();
125}
126
127}
128
Note: See TracBrowser for help on using the repository browser.