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