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

Revision 2176, 7.9 KB checked in by mattausch, 17 years ago (diff)

removed using namespace std from .h

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