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

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

added mesh instance support
improved support for occlusion queries + other extensions

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