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

Revision 2227, 7.9 KB checked in by mattausch, 18 years ago (diff)

added render cost bound for objects, improved undersampling compensation

RevLine 
[2115]1#ifndef _VIEWCELLS_PARSER_XERCES__H
2#define _VIEWCELLS_PARSER_XERCES__H
[508]3
4// ---------------------------------------------------------------------------
5//  Includes
6// ---------------------------------------------------------------------------
7#include <xercesc/sax/HandlerBase.hpp>
8#include "Mesh.h"
[931]9#include "BoundingBoxConverter.h"
[2123]10#include <hash_map>
[508]11
[2227]12#include "Timer/PerfTimer.h"
[2176]13
[860]14namespace GtpVisibilityPreprocessor {
15
[508]16XERCES_CPP_NAMESPACE_USE
17XERCES_CPP_NAMESPACE_BEGIN
18class AttributeList;
19XERCES_CPP_NAMESPACE_END
20
21class VspBspTree;
[575]22class BspTree;
[508]23class ViewCellsManager;
[651]24class ViewCellsTree;
[1022]25class VspTree;
26class OspTree;
[1201]27class VspNode;
[1286]28class BvhNode;
[1263]29class BvHierarchy;
[1278]30class HierarchyManager;
[2116]31class ObjectPvs;
32class BspNode;
[508]33
[2123]34/*
35struct pvs_hash_compare
36{
37   enum
38   {
39      bucket_size = 4,
40      min_buckets = 8
41   };
[1278]42
[2123]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
[508]59class ViewCellsParseHandlers: public HandlerBase
60{
61public:
62  // -----------------------------------------------------------------------
63  //  Constructors and Destructor
64  // -----------------------------------------------------------------------
[2113]65  ViewCellsParseHandlers(ObjectContainer &pvsObjects,
66                                                 ObjectContainer &preprocessorObjects,
67                                                 BoundingBoxConverter *bconverter);
[508]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
[2115]104  void CreateViewCellsManager();
[575]105
106
[1551]107  /////////////////////////
108
[508]109  VspBspTree *mVspBspTree;
[1278]110  HierarchyManager *mHierarchyManager;
[1551]111 
[575]112  BspTree *mBspTree;
[651]113  ViewCellsTree *mViewCellsTree;
[1278]114  VspTree *mVspTree;
[651]115
[590]116  BspNode *mCurrentBspNode;
[1286]117  BvhNode *mCurrentBvhNode;
118  KdNode *mCurrentOspNode;
[1201]119  VspNode *mCurrentVspNode;
[1551]120 
[651]121  ViewCell *mCurrentViewCell;
[1286]122   
[1263]123  BspNode *mBspRoot;
124  VspNode *mVspRoot;
125  ViewCell *mViewCellRoot;
[2113]126 
127  int mUniqueObjectId;
[2048]128  vector<BvhLeaf *> mBvhLeaves;
129  //typedef map<int, ViewCell *> ViewCellsMap;
[1623]130  //ViewCellsMap mViewCells;
[1999]131  ViewCellContainer mViewCells;
[1551]132
[508]133  ViewCellsManager *mViewCellsManager;
[2113]134
135  ObjectContainer &mPvsObjects;
[2115]136  const ObjectContainer &mPreprocessorObjects;
[2113]137
[931]138  BoundingBoxConverter *mBoundingBoxConverter;
[577]139  AxisAlignedBox3 mViewSpaceBox;
[931]140  IndexedBoundingBoxContainer mIBoundingBoxes;
[1004]141 
[1263]142  /// current state of the parser
143  int mCurrentState;
144 
[1286]145  enum {
146          PARSE_OPTIONS,
147          PARSE_VIEWCELLS,
148          PARSE_VIEWSPACE_HIERARCHY,
[2114]149          PARSE_OBJECTSPACE_HIERARCHY
150  };
[1201]151
[1263]152  /// view space / object space hierarchy types
153  enum {BSP, VSP, OSP, BVH};
154
155  int mViewSpaceHierarchyType;
156  int mObjectSpaceHierarchyType;
[2048]157  int nViewCells;
158  int nObjects;
159 
[2123]160  PerfTimer mBoxTimer;
161  PerfTimer mPvsTimer;
162  PerfTimer mObjectTimer;
163
164  pvs_hash mHashPvs;
165
[1551]166  ////////////////////////////////
167
168
[508]169  // Handlers for X3D
[2123]170
171  void CreateHashVector();
172
[575]173  void StartBspLeaf(AttributeList& attributes);
174  void StartBspInterior(AttributeList& attributes);
175  void EndBspInterior();
[1201]176
177  void StartVspLeaf(AttributeList& attributes);
178  void StartVspInterior(AttributeList& attributes);
179  void EndVspInterior();
180
[1551]181  void StartViewCellPvs(ObjectPvs &pvs, const char *ptr);
182
[508]183  void EndViewCells();
[931]184  void EndBoundingBoxes();
[575]185
[2176]186  void StartBspElement(std::string element, AttributeList& attributes);
187  void StartVspElement(std::string element, AttributeList& attributes);
[1201]188
[1264]189  void StartViewSpaceHierarchy(AttributeList& attributes);
190  void StartObjectSpaceHierarchy(AttributeList& attributes);
[651]191
[931]192  void StartBoundingBox(AttributeList& attributes);
[1551]193  void StartViewCell(AttributeList& attributes, const bool isLeaf);
[651]194  void EndViewCellInterior();
195
[1233]196  void StartViewSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
197  void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
[1201]198  void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes);
[651]199
[2176]200  void StartOspElement(std::string element, AttributeList& attributes);
[1201]201
202  void StartOspLeaf(AttributeList& attributes);
203  void StartOspInterior(AttributeList& attributes);
204
[1264]205  void CreateViewSpaceHierarchy();
[1201]206
[1264]207  void StartBvhLeaf(AttributeList& attributes);
208  void StartBvhInterior(AttributeList& attributes);
[2176]209  void StartBvhElement(std::string element, AttributeList& attributes);
[1264]210
[1286]211  void EndViewSpaceHierarchyInterior();
212  void EndObjectSpaceHierarchyInterior();
[1264]213
[1286]214  void EndBvhInterior();
215  void EndOspInterior();
216
217  void EndObjectSpaceHierarchy();
218
219  void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr);
220
[508]221  // -----------------------------------------------------------------------
222  //  Handlers for the SAX ErrorHandler interface
223  // -----------------------------------------------------------------------
[651]224
[508]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}
[860]292}
293
[508]294#endif
Note: See TracBrowser for help on using the repository browser.