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

Revision 712, 7.6 KB checked in by mattausch, 18 years ago (diff)

added exporter for Vrml
added transformations to x3d loader

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