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

Revision 658, 7.2 KB checked in by mattausch, 19 years ago (diff)

added switch for loading polys as meshes

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