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