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

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

preparing for moving objects (contains compile errors!)

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 SceneGraphLeaf;
20class Mesh;
21class Material;
22class ViewCellsManager;
23
24
25
26class X3dParseHandlers : public HandlerBase
27{
28public:
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
39        typedef std::map<std::string, int, ltstr> ResourceDefinitions;
40
41  // -----------------------------------------------------------------------
42  //  Constructors and Destructor
43  // -----------------------------------------------------------------------
44  X3dParseHandlers(SceneGraphLeaf *root, const bool loadMeshes = false);
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
81  SceneGraphLeaf *mCurrentNode;
82 
83  vector<VertexIndexContainer> mCurrentVertexIndices;
84  VertexContainer mCurrentVertices;
85
86  //string mCurrentMeshName;
87  Mesh *mCurrentMesh;
88
89  Material *mCurrentMaterial;
90 
91  bool mLoadMeshes;
92
93  typedef std::stack<Matrix4x4> TrafoStack;
94
95  bool mUsingMeshDefinition;
96
97  // stack of accumulated transformations
98  TrafoStack mTransformations;
99
100  ResourceDefinitions mMaterialDefinitions;
101  ResourceDefinitions mMeshDefinitions;
102
103  bool mIsMeshDefinition;
104
105  // Handlers for X3D
106  void
107  StartIndexedFaceSet(
108                      AttributeList&  attributes);
109 
110  void
111  EndShape();
112
113  void EndTransform();
114  void StartTransform(AttributeList&  attributes);
115
116  void
117  StartCoordinate(
118                  AttributeList&  attributes);
119
120  void
121  StartMaterial(
122                AttributeList&  attributes);
123 
124  /** applies transformation matrix m to this mesh.
125  */
126  void ApplyTransformation(Mesh *mesh, const Matrix4x4 &m) const;
127
128  /** transforms mesh using the given transformations.
129  */
130  void ApplyTransformations(TrafoStack trafos, Mesh *mesh) const;
131  void ApplyTransformations(TrafoStack trafos, TransformedMeshInstance *mi) const;
132
133  static int mUniqueMeshIdx;
134
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
160/** Parser handlers for view cell x3d files.
161*/
162class X3dViewCellsParseHandlers : public HandlerBase
163{
164public:
165  // -----------------------------------------------------------------------
166  //  Constructors and Destructor
167  // -----------------------------------------------------------------------
168  X3dViewCellsParseHandlers(ViewCellsManager *viewCellsManager,
169                                                        const float viewCellHeight);
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  }
195
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
206  ViewCellsManager *mViewCellsManager;
207  float mViewCellHeight;
208 
209
210  VertexIndexContainer mCurrentVertexIndices;
211  VertexContainer mCurrentVertices;
212
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
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
302}
303
304#endif
Note: See TracBrowser for help on using the repository browser.