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

Revision 971, 8.1 KB checked in by mattausch, 18 years ago (diff)

added stuff for view cell ziping (not working yet!)

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