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

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