source: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h @ 2114

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