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

Revision 2048, 7.3 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 *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;
99int 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  ViewCell *GetOrCreateViewCell(const int id, const bool isLeaf);
134
135  void StartBspLeaf(AttributeList& attributes);
136  void StartBspInterior(AttributeList& attributes);
137  void EndBspInterior();
138
139  void StartVspLeaf(AttributeList& attributes);
140  void StartVspInterior(AttributeList& attributes);
141  void EndVspInterior();
142
143  void StartViewCellPvs(ObjectPvs &pvs, const char *ptr);
144
145  void EndViewCells();
146  void EndBoundingBoxes();
147
148  void StartBspElement(string element, AttributeList& attributes);
149  void StartVspElement(string element, AttributeList& attributes);
150
151  void StartViewSpaceHierarchy(AttributeList& attributes);
152  void StartObjectSpaceHierarchy(AttributeList& attributes);
153
154  void StartBoundingBox(AttributeList& attributes);
155  void StartViewCell(AttributeList& attributes, const bool isLeaf);
156  void EndViewCellInterior();
157
158  void StartViewSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
159  void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
160  void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes);
161
162  void StartOspElement(string element, AttributeList& attributes);
163
164  void StartOspLeaf(AttributeList& attributes);
165  void StartOspInterior(AttributeList& attributes);
166
167  void CreateViewSpaceHierarchy();
168
169  void StartBvhLeaf(AttributeList& attributes);
170  void StartBvhInterior(AttributeList& attributes);
171  void StartBvhElement(string element, AttributeList& attributes);
172
173  void EndViewSpaceHierarchyInterior();
174  void EndObjectSpaceHierarchyInterior();
175
176  void EndBvhInterior();
177  void EndOspInterior();
178
179  void EndObjectSpaceHierarchy();
180
181  void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr);
182
183  // -----------------------------------------------------------------------
184  //  Handlers for the SAX ErrorHandler interface
185  // -----------------------------------------------------------------------
186
187  void warning(const SAXParseException& exc);
188  void error(const SAXParseException& exc);
189  void fatalError(const SAXParseException& exc);
190 
191 
192private:
193  // -----------------------------------------------------------------------
194  //  Private data members
195  //
196  //  fAttrCount
197  //  fCharacterCount
198  //  fElementCount
199  //  fSpaceCount
200  //      These are just counters that are run upwards based on the input
201  //      from the document handlers.
202  // -----------------------------------------------------------------------
203  unsigned int    mAttrCount;
204  unsigned int    mCharacterCount;
205  unsigned int    mElementCount;
206  unsigned int    mSpaceCount;
207};
208
209// ---------------------------------------------------------------------------
210//  This is a simple class that lets us do easy (though not terribly efficient)
211//  trancoding of XMLCh data to local code page for display.
212// ---------------------------------------------------------------------------
213class StrX
214{
215public :
216  // -----------------------------------------------------------------------
217  //  Constructors and Destructor
218  // -----------------------------------------------------------------------
219  StrX(const XMLCh* const toTranscode)
220  {
221          // Call the private transcoding method
222          mLocalForm = XMLString::transcode(toTranscode);
223  }
224 
225  ~StrX()
226  {
227          XMLString::release(&mLocalForm);
228  }
229 
230  // -----------------------------------------------------------------------
231  //  Getter methods
232  // -----------------------------------------------------------------------
233  const char* LocalForm() const
234  {
235    return mLocalForm;
236  }
237 
238private :
239  // -----------------------------------------------------------------------
240  //  Private data members
241  //
242  //  fLocalForm
243  //      This is the local code page form of the string.
244  // -----------------------------------------------------------------------
245  char*   mLocalForm;
246};
247
248inline XERCES_STD_QUALIFIER ostream&
249operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
250{
251  target << toDump.LocalForm();
252  return target;
253}
254}
255
256#endif
Note: See TracBrowser for help on using the repository browser.