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