[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"
|
---|
[2575] | 10 |
|
---|
| 11 | #ifdef __WINDOWS__
|
---|
[2123] | 12 | #include <hash_map>
|
---|
[2575] | 13 | #else
|
---|
| 14 | #include <map>
|
---|
| 15 | #endif
|
---|
[508] | 16 |
|
---|
[2575] | 17 | #ifdef PERFTIMER
|
---|
[2227] | 18 | #include "Timer/PerfTimer.h"
|
---|
[2575] | 19 | #endif
|
---|
[2176] | 20 |
|
---|
[860] | 21 | namespace GtpVisibilityPreprocessor {
|
---|
| 22 |
|
---|
[508] | 23 | XERCES_CPP_NAMESPACE_USE
|
---|
| 24 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
| 25 | class AttributeList;
|
---|
| 26 | XERCES_CPP_NAMESPACE_END
|
---|
| 27 |
|
---|
| 28 | class VspBspTree;
|
---|
[575] | 29 | class BspTree;
|
---|
[508] | 30 | class ViewCellsManager;
|
---|
[651] | 31 | class ViewCellsTree;
|
---|
[1022] | 32 | class VspTree;
|
---|
| 33 | class OspTree;
|
---|
[1201] | 34 | class VspNode;
|
---|
[1286] | 35 | class BvhNode;
|
---|
[1263] | 36 | class BvHierarchy;
|
---|
[1278] | 37 | class HierarchyManager;
|
---|
[2116] | 38 | class ObjectPvs;
|
---|
| 39 | class BspNode;
|
---|
[508] | 40 |
|
---|
[2123] | 41 | /*
|
---|
| 42 | struct pvs_hash_compare
|
---|
| 43 | {
|
---|
| 44 | enum
|
---|
| 45 | {
|
---|
| 46 | bucket_size = 4,
|
---|
| 47 | min_buckets = 8
|
---|
| 48 | };
|
---|
[1278] | 49 |
|
---|
[2123] | 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 |
|
---|
[2575] | 63 | #ifdef __WINDOWS__
|
---|
[2123] | 64 | typedef stdext::hash_map<int, Intersectable *> pvs_hash;
|
---|
[2575] | 65 | #else
|
---|
| 66 | typedef std::map<int, Intersectable *> pvs_hash;
|
---|
| 67 | #endif
|
---|
[2123] | 68 |
|
---|
[508] | 69 | class ViewCellsParseHandlers: public HandlerBase
|
---|
| 70 | {
|
---|
| 71 | public:
|
---|
| 72 | // -----------------------------------------------------------------------
|
---|
| 73 | // Constructors and Destructor
|
---|
| 74 | // -----------------------------------------------------------------------
|
---|
[2113] | 75 | ViewCellsParseHandlers(ObjectContainer &pvsObjects,
|
---|
| 76 | ObjectContainer &preprocessorObjects,
|
---|
| 77 | BoundingBoxConverter *bconverter);
|
---|
[508] | 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 |
|
---|
[2115] | 114 | void CreateViewCellsManager();
|
---|
[575] | 115 |
|
---|
| 116 |
|
---|
[1551] | 117 | /////////////////////////
|
---|
| 118 |
|
---|
[508] | 119 | VspBspTree *mVspBspTree;
|
---|
[1278] | 120 | HierarchyManager *mHierarchyManager;
|
---|
[1551] | 121 |
|
---|
[575] | 122 | BspTree *mBspTree;
|
---|
[651] | 123 | ViewCellsTree *mViewCellsTree;
|
---|
[1278] | 124 | VspTree *mVspTree;
|
---|
[651] | 125 |
|
---|
[590] | 126 | BspNode *mCurrentBspNode;
|
---|
[1286] | 127 | BvhNode *mCurrentBvhNode;
|
---|
| 128 | KdNode *mCurrentOspNode;
|
---|
[1201] | 129 | VspNode *mCurrentVspNode;
|
---|
[1551] | 130 |
|
---|
[651] | 131 | ViewCell *mCurrentViewCell;
|
---|
[1286] | 132 |
|
---|
[1263] | 133 | BspNode *mBspRoot;
|
---|
| 134 | VspNode *mVspRoot;
|
---|
| 135 | ViewCell *mViewCellRoot;
|
---|
[2113] | 136 |
|
---|
| 137 | int mUniqueObjectId;
|
---|
[2048] | 138 | vector<BvhLeaf *> mBvhLeaves;
|
---|
| 139 | //typedef map<int, ViewCell *> ViewCellsMap;
|
---|
[1623] | 140 | //ViewCellsMap mViewCells;
|
---|
[1999] | 141 | ViewCellContainer mViewCells;
|
---|
[1551] | 142 |
|
---|
[508] | 143 | ViewCellsManager *mViewCellsManager;
|
---|
[2113] | 144 |
|
---|
| 145 | ObjectContainer &mPvsObjects;
|
---|
[2115] | 146 | const ObjectContainer &mPreprocessorObjects;
|
---|
[2113] | 147 |
|
---|
[931] | 148 | BoundingBoxConverter *mBoundingBoxConverter;
|
---|
[577] | 149 | AxisAlignedBox3 mViewSpaceBox;
|
---|
[931] | 150 | IndexedBoundingBoxContainer mIBoundingBoxes;
|
---|
[1004] | 151 |
|
---|
[1263] | 152 | /// current state of the parser
|
---|
| 153 | int mCurrentState;
|
---|
| 154 |
|
---|
[1286] | 155 | enum {
|
---|
| 156 | PARSE_OPTIONS,
|
---|
| 157 | PARSE_VIEWCELLS,
|
---|
| 158 | PARSE_VIEWSPACE_HIERARCHY,
|
---|
[2114] | 159 | PARSE_OBJECTSPACE_HIERARCHY
|
---|
| 160 | };
|
---|
[1201] | 161 |
|
---|
[1263] | 162 | /// view space / object space hierarchy types
|
---|
| 163 | enum {BSP, VSP, OSP, BVH};
|
---|
| 164 |
|
---|
| 165 | int mViewSpaceHierarchyType;
|
---|
| 166 | int mObjectSpaceHierarchyType;
|
---|
[2048] | 167 | int nViewCells;
|
---|
| 168 | int nObjects;
|
---|
| 169 |
|
---|
[2575] | 170 | #ifdef PERFTIMER
|
---|
[2123] | 171 | PerfTimer mBoxTimer;
|
---|
| 172 | PerfTimer mPvsTimer;
|
---|
| 173 | PerfTimer mObjectTimer;
|
---|
[2575] | 174 | #endif
|
---|
| 175 |
|
---|
[2123] | 176 | pvs_hash mHashPvs;
|
---|
| 177 |
|
---|
[1551] | 178 | ////////////////////////////////
|
---|
| 179 |
|
---|
| 180 |
|
---|
[508] | 181 | // Handlers for X3D
|
---|
[2123] | 182 |
|
---|
| 183 | void CreateHashVector();
|
---|
| 184 |
|
---|
[575] | 185 | void StartBspLeaf(AttributeList& attributes);
|
---|
| 186 | void StartBspInterior(AttributeList& attributes);
|
---|
| 187 | void EndBspInterior();
|
---|
[1201] | 188 |
|
---|
| 189 | void StartVspLeaf(AttributeList& attributes);
|
---|
| 190 | void StartVspInterior(AttributeList& attributes);
|
---|
| 191 | void EndVspInterior();
|
---|
| 192 |
|
---|
[1551] | 193 | void StartViewCellPvs(ObjectPvs &pvs, const char *ptr);
|
---|
| 194 |
|
---|
[508] | 195 | void EndViewCells();
|
---|
[931] | 196 | void EndBoundingBoxes();
|
---|
[575] | 197 |
|
---|
[2176] | 198 | void StartBspElement(std::string element, AttributeList& attributes);
|
---|
| 199 | void StartVspElement(std::string element, AttributeList& attributes);
|
---|
[1201] | 200 |
|
---|
[1264] | 201 | void StartViewSpaceHierarchy(AttributeList& attributes);
|
---|
| 202 | void StartObjectSpaceHierarchy(AttributeList& attributes);
|
---|
[651] | 203 |
|
---|
[931] | 204 | void StartBoundingBox(AttributeList& attributes);
|
---|
[1551] | 205 | void StartViewCell(AttributeList& attributes, const bool isLeaf);
|
---|
[651] | 206 | void EndViewCellInterior();
|
---|
| 207 |
|
---|
[1233] | 208 | void StartViewSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
| 209 | void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
[1201] | 210 | void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes);
|
---|
[651] | 211 |
|
---|
[2176] | 212 | void StartOspElement(std::string element, AttributeList& attributes);
|
---|
[1201] | 213 |
|
---|
| 214 | void StartOspLeaf(AttributeList& attributes);
|
---|
| 215 | void StartOspInterior(AttributeList& attributes);
|
---|
| 216 |
|
---|
[1264] | 217 | void CreateViewSpaceHierarchy();
|
---|
[1201] | 218 |
|
---|
[1264] | 219 | void StartBvhLeaf(AttributeList& attributes);
|
---|
| 220 | void StartBvhInterior(AttributeList& attributes);
|
---|
[2176] | 221 | void StartBvhElement(std::string element, AttributeList& attributes);
|
---|
[1264] | 222 |
|
---|
[1286] | 223 | void EndViewSpaceHierarchyInterior();
|
---|
| 224 | void EndObjectSpaceHierarchyInterior();
|
---|
[1264] | 225 |
|
---|
[1286] | 226 | void EndBvhInterior();
|
---|
| 227 | void EndOspInterior();
|
---|
| 228 |
|
---|
| 229 | void EndObjectSpaceHierarchy();
|
---|
| 230 |
|
---|
| 231 | void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr);
|
---|
| 232 |
|
---|
[508] | 233 | // -----------------------------------------------------------------------
|
---|
| 234 | // Handlers for the SAX ErrorHandler interface
|
---|
| 235 | // -----------------------------------------------------------------------
|
---|
[651] | 236 |
|
---|
[508] | 237 | void warning(const SAXParseException& exc);
|
---|
| 238 | void error(const SAXParseException& exc);
|
---|
| 239 | void fatalError(const SAXParseException& exc);
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | private:
|
---|
| 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 | // ---------------------------------------------------------------------------
|
---|
| 263 | class StrX
|
---|
| 264 | {
|
---|
| 265 | public :
|
---|
| 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 |
|
---|
| 288 | private :
|
---|
| 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 |
|
---|
| 298 | inline XERCES_STD_QUALIFIER ostream&
|
---|
| 299 | operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
|
---|
| 300 | {
|
---|
| 301 | target << toDump.LocalForm();
|
---|
| 302 | return target;
|
---|
| 303 | }
|
---|
[860] | 304 | }
|
---|
| 305 |
|
---|
[508] | 306 | #endif
|
---|