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

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

worded on obj loading in Ogre

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