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

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