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

Revision 1551, 7.1 KB checked in by mattausch, 18 years ago (diff)

updated view cells loading. probably no optimal for performance

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