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

Revision 2627, 7.8 KB checked in by bittner, 16 years ago (diff)

commit before merge with vlastimil

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