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

Revision 2600, 8.3 KB checked in by mattausch, 17 years ago (diff)

preparing for moving objects (contains compile errors!)

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