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 | void ExchangeElements();
|
---|
77 | void ExchangePvs(ViewCell *vc);
|
---|
78 |
|
---|
79 |
|
---|
80 | /////////////////////////
|
---|
81 |
|
---|
82 | VspBspTree *mVspBspTree;
|
---|
83 | HierarchyManager *mHierarchyManager;
|
---|
84 |
|
---|
85 | BspTree *mBspTree;
|
---|
86 | ViewCellsTree *mViewCellsTree;
|
---|
87 | VspTree *mVspTree;
|
---|
88 |
|
---|
89 | BspNode *mCurrentBspNode;
|
---|
90 | BvhNode *mCurrentBvhNode;
|
---|
91 | KdNode *mCurrentOspNode;
|
---|
92 | VspNode *mCurrentVspNode;
|
---|
93 |
|
---|
94 | ViewCell *mCurrentViewCell;
|
---|
95 |
|
---|
96 | BspNode *mBspRoot;
|
---|
97 | VspNode *mVspRoot;
|
---|
98 | ViewCell *mViewCellRoot;
|
---|
99 | int mUniqueObjectId;
|
---|
100 | vector<BvhLeaf *> mBvhLeaves;
|
---|
101 | //typedef map<int, ViewCell *> ViewCellsMap;
|
---|
102 | //ViewCellsMap mViewCells;
|
---|
103 | ViewCellContainer mViewCells;
|
---|
104 |
|
---|
105 | ViewCellsManager *mViewCellsManager;
|
---|
106 | ObjectContainer *mObjects;
|
---|
107 | BoundingBoxConverter *mBoundingBoxConverter;
|
---|
108 | AxisAlignedBox3 mViewSpaceBox;
|
---|
109 | IndexedBoundingBoxContainer mIBoundingBoxes;
|
---|
110 |
|
---|
111 | /// current state of the parser
|
---|
112 | int mCurrentState;
|
---|
113 |
|
---|
114 | enum {
|
---|
115 | PARSE_OPTIONS,
|
---|
116 | PARSE_VIEWCELLS,
|
---|
117 | PARSE_VIEWSPACE_HIERARCHY,
|
---|
118 | PARSE_OBJECTSPACE_HIERARCHY};
|
---|
119 |
|
---|
120 | /// view space / object space hierarchy types
|
---|
121 | enum {BSP, VSP, OSP, BVH};
|
---|
122 |
|
---|
123 | int mViewSpaceHierarchyType;
|
---|
124 | int mObjectSpaceHierarchyType;
|
---|
125 | int nViewCells;
|
---|
126 | int nObjects;
|
---|
127 |
|
---|
128 |
|
---|
129 | ////////////////////////////////
|
---|
130 |
|
---|
131 |
|
---|
132 | // Handlers for X3D
|
---|
133 |
|
---|
134 | void StartBspLeaf(AttributeList& attributes);
|
---|
135 | void StartBspInterior(AttributeList& attributes);
|
---|
136 | void EndBspInterior();
|
---|
137 |
|
---|
138 | void StartVspLeaf(AttributeList& attributes);
|
---|
139 | void StartVspInterior(AttributeList& attributes);
|
---|
140 | void EndVspInterior();
|
---|
141 |
|
---|
142 | void StartViewCellPvs(ObjectPvs &pvs, const char *ptr);
|
---|
143 |
|
---|
144 | void EndViewCells();
|
---|
145 | void EndBoundingBoxes();
|
---|
146 |
|
---|
147 | void StartBspElement(string element, AttributeList& attributes);
|
---|
148 | void StartVspElement(string element, AttributeList& attributes);
|
---|
149 |
|
---|
150 | void StartViewSpaceHierarchy(AttributeList& attributes);
|
---|
151 | void StartObjectSpaceHierarchy(AttributeList& attributes);
|
---|
152 |
|
---|
153 | void StartBoundingBox(AttributeList& attributes);
|
---|
154 | void StartViewCell(AttributeList& attributes, const bool isLeaf);
|
---|
155 | void EndViewCellInterior();
|
---|
156 |
|
---|
157 | void StartViewSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
158 | void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
159 | void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
160 |
|
---|
161 | void StartOspElement(string element, AttributeList& attributes);
|
---|
162 |
|
---|
163 | void StartOspLeaf(AttributeList& attributes);
|
---|
164 | void StartOspInterior(AttributeList& attributes);
|
---|
165 |
|
---|
166 | void CreateViewSpaceHierarchy();
|
---|
167 |
|
---|
168 | void StartBvhLeaf(AttributeList& attributes);
|
---|
169 | void StartBvhInterior(AttributeList& attributes);
|
---|
170 | void StartBvhElement(string element, AttributeList& attributes);
|
---|
171 |
|
---|
172 | void EndViewSpaceHierarchyInterior();
|
---|
173 | void EndObjectSpaceHierarchyInterior();
|
---|
174 |
|
---|
175 | void EndBvhInterior();
|
---|
176 | void EndOspInterior();
|
---|
177 |
|
---|
178 | void EndObjectSpaceHierarchy();
|
---|
179 |
|
---|
180 | void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr);
|
---|
181 |
|
---|
182 | // -----------------------------------------------------------------------
|
---|
183 | // Handlers for the SAX ErrorHandler interface
|
---|
184 | // -----------------------------------------------------------------------
|
---|
185 |
|
---|
186 | void warning(const SAXParseException& exc);
|
---|
187 | void error(const SAXParseException& exc);
|
---|
188 | void fatalError(const SAXParseException& exc);
|
---|
189 |
|
---|
190 |
|
---|
191 | private:
|
---|
192 | // -----------------------------------------------------------------------
|
---|
193 | // Private data members
|
---|
194 | //
|
---|
195 | // fAttrCount
|
---|
196 | // fCharacterCount
|
---|
197 | // fElementCount
|
---|
198 | // fSpaceCount
|
---|
199 | // These are just counters that are run upwards based on the input
|
---|
200 | // from the document handlers.
|
---|
201 | // -----------------------------------------------------------------------
|
---|
202 | unsigned int mAttrCount;
|
---|
203 | unsigned int mCharacterCount;
|
---|
204 | unsigned int mElementCount;
|
---|
205 | unsigned int mSpaceCount;
|
---|
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 | // ---------------------------------------------------------------------------
|
---|
212 | class StrX
|
---|
213 | {
|
---|
214 | public :
|
---|
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 |
|
---|
237 | private :
|
---|
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 |
|
---|
247 | inline XERCES_STD_QUALIFIER ostream&
|
---|
248 | operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
249 | {
|
---|
250 | target << toDump.LocalForm();
|
---|
251 | return target;
|
---|
252 | }
|
---|
253 | }
|
---|
254 |
|
---|
255 | #endif
|
---|