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 "BoundingBoxConverter.h"
|
---|
10 |
|
---|
11 |
|
---|
12 | namespace GtpVisibilityPreprocessor {
|
---|
13 |
|
---|
14 | XERCES_CPP_NAMESPACE_USE
|
---|
15 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
16 | class AttributeList;
|
---|
17 | XERCES_CPP_NAMESPACE_END
|
---|
18 |
|
---|
19 | class VspBspTree;
|
---|
20 | class BspTree;
|
---|
21 | class ViewCellsManager;
|
---|
22 | class ViewCellsTree;
|
---|
23 | class VspTree;
|
---|
24 | class OspTree;
|
---|
25 | class VspNode;
|
---|
26 | class BvhNode;
|
---|
27 | class BvHierarchy;
|
---|
28 | class HierarchyManager;
|
---|
29 |
|
---|
30 |
|
---|
31 | class ViewCellsParseHandlers: public HandlerBase
|
---|
32 | {
|
---|
33 | public:
|
---|
34 | // -----------------------------------------------------------------------
|
---|
35 | // Constructors and Destructor
|
---|
36 | // -----------------------------------------------------------------------
|
---|
37 | ViewCellsParseHandlers(ObjectContainer *objects, BoundingBoxConverter *bconverter);
|
---|
38 | ~ViewCellsParseHandlers();
|
---|
39 |
|
---|
40 |
|
---|
41 | // -----------------------------------------------------------------------
|
---|
42 | // Getter methods
|
---|
43 | // -----------------------------------------------------------------------
|
---|
44 | unsigned int GetElementCount()
|
---|
45 | {
|
---|
46 | return mElementCount;
|
---|
47 | }
|
---|
48 |
|
---|
49 | unsigned int GetAttrCount()
|
---|
50 | {
|
---|
51 | return mAttrCount;
|
---|
52 | }
|
---|
53 |
|
---|
54 | unsigned int GetCharacterCount()
|
---|
55 | {
|
---|
56 | return mCharacterCount;
|
---|
57 | }
|
---|
58 |
|
---|
59 | unsigned int GetSpaceCount()
|
---|
60 | {
|
---|
61 | return mSpaceCount;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | // -----------------------------------------------------------------------
|
---|
66 | // Handlers for the SAX DocumentHandler interface
|
---|
67 | // -----------------------------------------------------------------------
|
---|
68 | void endElement(const XMLCh* const name);
|
---|
69 | void startElement(const XMLCh* const name, AttributeList& attributes);
|
---|
70 | void characters(const XMLCh* const chars, const unsigned int length);
|
---|
71 | void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
|
---|
72 | void resetDocument();
|
---|
73 |
|
---|
74 | void CreateViewCellsManager(/*const char *name*/);
|
---|
75 |
|
---|
76 |
|
---|
77 | /////////////////////////
|
---|
78 |
|
---|
79 | VspBspTree *mVspBspTree;
|
---|
80 | HierarchyManager *mHierarchyManager;
|
---|
81 |
|
---|
82 | BspTree *mBspTree;
|
---|
83 | ViewCellsTree *mViewCellsTree;
|
---|
84 | VspTree *mVspTree;
|
---|
85 |
|
---|
86 | BspNode *mCurrentBspNode;
|
---|
87 | BvhNode *mCurrentBvhNode;
|
---|
88 | KdNode *mCurrentOspNode;
|
---|
89 | VspNode *mCurrentVspNode;
|
---|
90 |
|
---|
91 | ViewCell *mCurrentViewCell;
|
---|
92 |
|
---|
93 | BspNode *mBspRoot;
|
---|
94 | VspNode *mVspRoot;
|
---|
95 | ViewCell *mViewCellRoot;
|
---|
96 |
|
---|
97 | // typedef map<int, ViewCell *> ViewCellsMap;
|
---|
98 | //ViewCellsMap mViewCells;
|
---|
99 | ViewCellContainer mViewCells;
|
---|
100 |
|
---|
101 | ViewCellsManager *mViewCellsManager;
|
---|
102 | ObjectContainer *mObjects;
|
---|
103 | BoundingBoxConverter *mBoundingBoxConverter;
|
---|
104 | AxisAlignedBox3 mViewSpaceBox;
|
---|
105 | IndexedBoundingBoxContainer mIBoundingBoxes;
|
---|
106 |
|
---|
107 | /// current state of the parser
|
---|
108 | int mCurrentState;
|
---|
109 |
|
---|
110 | enum {
|
---|
111 | PARSE_OPTIONS,
|
---|
112 | PARSE_VIEWCELLS,
|
---|
113 | PARSE_VIEWSPACE_HIERARCHY,
|
---|
114 | PARSE_OBJECTSPACE_HIERARCHY};
|
---|
115 |
|
---|
116 | /// view space / object space hierarchy types
|
---|
117 | enum {BSP, VSP, OSP, BVH};
|
---|
118 |
|
---|
119 | int mViewSpaceHierarchyType;
|
---|
120 | int mObjectSpaceHierarchyType;
|
---|
121 | int nViewCells;
|
---|
122 | int nObjects;
|
---|
123 | ////////////////////////////////
|
---|
124 |
|
---|
125 |
|
---|
126 | // Handlers for X3D
|
---|
127 | ViewCell *GetOrCreateViewCell(const int id, const bool isLeaf);
|
---|
128 |
|
---|
129 | void StartBspLeaf(AttributeList& attributes);
|
---|
130 | void StartBspInterior(AttributeList& attributes);
|
---|
131 | void EndBspInterior();
|
---|
132 |
|
---|
133 | void StartVspLeaf(AttributeList& attributes);
|
---|
134 | void StartVspInterior(AttributeList& attributes);
|
---|
135 | void EndVspInterior();
|
---|
136 |
|
---|
137 | void StartViewCellPvs(ObjectPvs &pvs, const char *ptr);
|
---|
138 |
|
---|
139 | void EndViewCells();
|
---|
140 | void EndBoundingBoxes();
|
---|
141 |
|
---|
142 | void StartBspElement(string element, AttributeList& attributes);
|
---|
143 | void StartVspElement(string element, AttributeList& attributes);
|
---|
144 |
|
---|
145 | void StartViewSpaceHierarchy(AttributeList& attributes);
|
---|
146 | void StartObjectSpaceHierarchy(AttributeList& attributes);
|
---|
147 |
|
---|
148 | void StartBoundingBox(AttributeList& attributes);
|
---|
149 | void StartViewCell(AttributeList& attributes, const bool isLeaf);
|
---|
150 | void EndViewCellInterior();
|
---|
151 |
|
---|
152 | void StartViewSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
153 | void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
154 | void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
155 |
|
---|
156 | void StartOspElement(string element, AttributeList& attributes);
|
---|
157 |
|
---|
158 | void StartOspLeaf(AttributeList& attributes);
|
---|
159 | void StartOspInterior(AttributeList& attributes);
|
---|
160 |
|
---|
161 | void CreateViewSpaceHierarchy();
|
---|
162 |
|
---|
163 | void StartBvhLeaf(AttributeList& attributes);
|
---|
164 | void StartBvhInterior(AttributeList& attributes);
|
---|
165 | void StartBvhElement(string element, AttributeList& attributes);
|
---|
166 |
|
---|
167 | void EndViewSpaceHierarchyInterior();
|
---|
168 | void EndObjectSpaceHierarchyInterior();
|
---|
169 |
|
---|
170 | void EndBvhInterior();
|
---|
171 | void EndOspInterior();
|
---|
172 |
|
---|
173 | void EndObjectSpaceHierarchy();
|
---|
174 |
|
---|
175 | void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr);
|
---|
176 |
|
---|
177 | // -----------------------------------------------------------------------
|
---|
178 | // Handlers for the SAX ErrorHandler interface
|
---|
179 | // -----------------------------------------------------------------------
|
---|
180 |
|
---|
181 | void warning(const SAXParseException& exc);
|
---|
182 | void error(const SAXParseException& exc);
|
---|
183 | void fatalError(const SAXParseException& exc);
|
---|
184 |
|
---|
185 |
|
---|
186 | private:
|
---|
187 | // -----------------------------------------------------------------------
|
---|
188 | // Private data members
|
---|
189 | //
|
---|
190 | // fAttrCount
|
---|
191 | // fCharacterCount
|
---|
192 | // fElementCount
|
---|
193 | // fSpaceCount
|
---|
194 | // These are just counters that are run upwards based on the input
|
---|
195 | // from the document handlers.
|
---|
196 | // -----------------------------------------------------------------------
|
---|
197 | unsigned int mAttrCount;
|
---|
198 | unsigned int mCharacterCount;
|
---|
199 | unsigned int mElementCount;
|
---|
200 | unsigned int mSpaceCount;
|
---|
201 | };
|
---|
202 |
|
---|
203 | // ---------------------------------------------------------------------------
|
---|
204 | // This is a simple class that lets us do easy (though not terribly efficient)
|
---|
205 | // trancoding of XMLCh data to local code page for display.
|
---|
206 | // ---------------------------------------------------------------------------
|
---|
207 | class StrX
|
---|
208 | {
|
---|
209 | public :
|
---|
210 | // -----------------------------------------------------------------------
|
---|
211 | // Constructors and Destructor
|
---|
212 | // -----------------------------------------------------------------------
|
---|
213 | StrX(const XMLCh* const toTranscode)
|
---|
214 | {
|
---|
215 | // Call the private transcoding method
|
---|
216 | mLocalForm = XMLString::transcode(toTranscode);
|
---|
217 | }
|
---|
218 |
|
---|
219 | ~StrX()
|
---|
220 | {
|
---|
221 | XMLString::release(&mLocalForm);
|
---|
222 | }
|
---|
223 |
|
---|
224 | // -----------------------------------------------------------------------
|
---|
225 | // Getter methods
|
---|
226 | // -----------------------------------------------------------------------
|
---|
227 | const char* LocalForm() const
|
---|
228 | {
|
---|
229 | return mLocalForm;
|
---|
230 | }
|
---|
231 |
|
---|
232 | private :
|
---|
233 | // -----------------------------------------------------------------------
|
---|
234 | // Private data members
|
---|
235 | //
|
---|
236 | // fLocalForm
|
---|
237 | // This is the local code page form of the string.
|
---|
238 | // -----------------------------------------------------------------------
|
---|
239 | char* mLocalForm;
|
---|
240 | };
|
---|
241 |
|
---|
242 | inline XERCES_STD_QUALIFIER ostream&
|
---|
243 | operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
244 | {
|
---|
245 | target << toDump.LocalForm();
|
---|
246 | return target;
|
---|
247 | }
|
---|
248 | }
|
---|
249 |
|
---|
250 | #endif
|
---|