source: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h @ 1379

Revision 1379, 8.2 KB checked in by mattausch, 18 years ago (diff)

fixed sah for objeect partition
loader for single triangles also for x3d

Line 
1#ifndef _X3D_PARSER_XERCES__H
2#define _X3D_PARSER_XERCES__H
3
4// ---------------------------------------------------------------------------
5//  Includes
6// ---------------------------------------------------------------------------
7#include <xercesc/sax/HandlerBase.hpp>
8#include "Mesh.h"
9#include <stack>
10
11XERCES_CPP_NAMESPACE_USE
12XERCES_CPP_NAMESPACE_BEGIN
13class AttributeList;
14XERCES_CPP_NAMESPACE_END
15
16namespace GtpVisibilityPreprocessor {
17
18class SceneGraphNode;
19class Mesh;
20class Material;
21class ViewCellsManager;
22
23
24
25class X3dParseHandlers : public HandlerBase
26{
27public:
28
29        // used for generating name / key pair
30        struct ltstr
31        {
32                bool operator()(const std::string &s1, const std::string &s2) const
33                {
34                        return s1 < s2;
35                }
36        };
37
38        typedef map<string, int, ltstr> ResourceDefinitions;
39
40  // -----------------------------------------------------------------------
41  //  Constructors and Destructor
42  // -----------------------------------------------------------------------
43  X3dParseHandlers(SceneGraphNode *root, const bool loadMeshes = false);
44  ~X3dParseHandlers();
45 
46 
47  // -----------------------------------------------------------------------
48  //  Getter methods
49  // -----------------------------------------------------------------------
50  unsigned int GetElementCount()
51  {
52    return mElementCount;
53  }
54 
55  unsigned int GetAttrCount()
56  {
57    return mAttrCount;
58  }
59 
60  unsigned int GetCharacterCount()
61  {
62    return mCharacterCount;
63  }
64 
65  unsigned int GetSpaceCount()
66  {
67    return mSpaceCount;
68  }
69
70
71  // -----------------------------------------------------------------------
72  //  Handlers for the SAX DocumentHandler interface
73  // -----------------------------------------------------------------------
74  void endElement(const XMLCh* const name);
75  void startElement(const XMLCh* const name, AttributeList& attributes);
76  void characters(const XMLCh* const chars, const unsigned int length);
77  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
78  void resetDocument();
79
80  SceneGraphNode *mCurrentNode;
81 
82  vector<VertexIndexContainer> mCurrentVertexIndices;
83  VertexContainer mCurrentVertices;
84
85  //string mCurrentMeshName;
86  Mesh *mCurrentMesh;
87
88  Material *mCurrentMaterial;
89 
90  bool mLoadMeshes;
91
92  typedef stack<Matrix4x4> TrafoStack;
93
94  bool mUsingMeshDefinition;
95
96  // stack of accumulated transformations
97  TrafoStack mTransformations;
98
99  ResourceDefinitions mMaterialDefinitions;
100  ResourceDefinitions mMeshDefinitions;
101
102  bool mIsMeshDefinition;
103
104  // Handlers for X3D
105  void
106  StartIndexedFaceSet(
107                      AttributeList&  attributes);
108 
109  void
110  EndShape();
111
112  void EndTransform();
113  void StartTransform(AttributeList&  attributes);
114
115  void
116  StartCoordinate(
117                  AttributeList&  attributes);
118
119  void
120  StartMaterial(
121                AttributeList&  attributes);
122 
123  /** applies transformation matrix m to this mesh.
124  */
125  void ApplyTransformation(Mesh *mesh, const Matrix4x4 &m) const;
126
127  /** transforms mesh using the given transformations.
128  */
129  void ApplyTransformations(TrafoStack trafos, Mesh *mesh) const;
130  void ApplyTransformations(TrafoStack trafos, TransformedMeshInstance *mi) const;
131
132  static int mUniqueMeshIdx;
133
134  // -----------------------------------------------------------------------
135  //  Handlers for the SAX ErrorHandler interface
136  // -----------------------------------------------------------------------
137  void warning(const SAXParseException& exc);
138  void error(const SAXParseException& exc);
139  void fatalError(const SAXParseException& exc);
140 
141 
142private:
143  // -----------------------------------------------------------------------
144  //  Private data members
145  //
146  //  fAttrCount
147  //  fCharacterCount
148  //  fElementCount
149  //  fSpaceCount
150  //      These are just counters that are run upwards based on the input
151  //      from the document handlers.
152  // -----------------------------------------------------------------------
153  unsigned int    mAttrCount;
154  unsigned int    mCharacterCount;
155  unsigned int    mElementCount;
156  unsigned int    mSpaceCount;
157};
158
159/** Parser handlers for view cell x3d files.
160*/
161class X3dViewCellsParseHandlers : public HandlerBase
162{
163public:
164  // -----------------------------------------------------------------------
165  //  Constructors and Destructor
166  // -----------------------------------------------------------------------
167  X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager,
168                                                        const float viewCellHeight);
169  ~X3dViewCellsParseHandlers();
170 
171 
172  // -----------------------------------------------------------------------
173  //  Getter methods
174  // -----------------------------------------------------------------------
175  unsigned int GetElementCount()
176  {
177    return mElementCount;
178  }
179 
180  unsigned int GetAttrCount()
181  {
182    return mAttrCount;
183  }
184 
185  unsigned int GetCharacterCount()
186  {
187    return mCharacterCount;
188  }
189 
190  unsigned int GetSpaceCount()
191  {
192    return mSpaceCount;
193  }
194
195
196  // -----------------------------------------------------------------------
197  //  Handlers for the SAX DocumentHandler interface
198  // -----------------------------------------------------------------------
199  void endElement(const XMLCh* const name);
200  void startElement(const XMLCh* const name, AttributeList& attributes);
201  void characters(const XMLCh* const chars, const unsigned int length);
202  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
203  void resetDocument();
204
205  ViewCellsManager *mViewCellsManager;
206  float mViewCellHeight;
207 
208
209  VertexIndexContainer mCurrentVertexIndices;
210  VertexContainer mCurrentVertices;
211
212  // Handlers for X3D
213  void
214  StartIndexedFaceSet(
215                      AttributeList&  attributes);
216 
217  void
218  EndShape();
219
220  void
221  StartCoordinate(
222                  AttributeList&  attributes);
223
224  void
225  StartMaterial(
226                AttributeList&  attributes);
227 
228 
229  // -----------------------------------------------------------------------
230  //  Handlers for the SAX ErrorHandler interface
231  // -----------------------------------------------------------------------
232  void warning(const SAXParseException& exc);
233  void error(const SAXParseException& exc);
234  void fatalError(const SAXParseException& exc);
235 
236 
237private:
238  // -----------------------------------------------------------------------
239  //  Private data members
240  //
241  //  fAttrCount
242  //  fCharacterCount
243  //  fElementCount
244  //  fSpaceCount
245  //      These are just counters that are run upwards based on the input
246  //      from the document handlers.
247  // -----------------------------------------------------------------------
248  unsigned int    mAttrCount;
249  unsigned int    mCharacterCount;
250  unsigned int    mElementCount;
251  unsigned int    mSpaceCount;
252};
253
254
255// ---------------------------------------------------------------------------
256//  This is a simple class that lets us do easy (though not terribly efficient)
257//  trancoding of XMLCh data to local code page for display.
258// ---------------------------------------------------------------------------
259class StrX
260{
261public :
262  // -----------------------------------------------------------------------
263  //  Constructors and Destructor
264  // -----------------------------------------------------------------------
265  StrX(const XMLCh* const toTranscode)
266  {
267    // Call the private transcoding method
268    mLocalForm = XMLString::transcode(toTranscode);
269  }
270 
271  ~StrX()
272  {
273    XMLString::release(&mLocalForm);
274  }
275 
276  // -----------------------------------------------------------------------
277  //  Getter methods
278  // -----------------------------------------------------------------------
279  const char* LocalForm() const
280  {
281    return mLocalForm;
282  }
283 
284private :
285  // -----------------------------------------------------------------------
286  //  Private data members
287  //
288  //  fLocalForm
289  //      This is the local code page form of the string.
290  // -----------------------------------------------------------------------
291  char*   mLocalForm;
292};
293
294inline XERCES_STD_QUALIFIER ostream&
295operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
296{
297  target << toDump.LocalForm();
298  return target;
299}
300
301}
302
303#endif
Note: See TracBrowser for help on using the repository browser.