[508] | 1 | // ---------------------------------------------------------------------------
|
---|
| 2 | // Includes for all the program files to see
|
---|
| 3 | // ---------------------------------------------------------------------------
|
---|
| 4 | #include <string.h>
|
---|
| 5 | #include <stdlib.h>
|
---|
| 6 | #include <iostream>
|
---|
| 7 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
| 8 |
|
---|
| 9 | // ---------------------------------------------------------------------------
|
---|
| 10 | // Includes
|
---|
| 11 | // ---------------------------------------------------------------------------
|
---|
| 12 | #include <xercesc/framework/StdInInputSource.hpp>
|
---|
| 13 | #include <xercesc/parsers/SAXParser.hpp>
|
---|
| 14 | #include <xercesc/util/OutOfMemoryException.hpp>
|
---|
| 15 |
|
---|
| 16 | // ---------------------------------------------------------------------------
|
---|
| 17 | // Includes
|
---|
| 18 | // ---------------------------------------------------------------------------
|
---|
| 19 | #include <xercesc/sax/AttributeList.hpp>
|
---|
| 20 | #include <xercesc/sax/SAXParseException.hpp>
|
---|
| 21 | #include <xercesc/sax/SAXException.hpp>
|
---|
| 22 |
|
---|
| 23 | #include "ViewCellsParser.h"
|
---|
| 24 |
|
---|
| 25 | #include "ViewCellsParserXerces.h"
|
---|
| 26 | #include "Mesh.h"
|
---|
| 27 | #include "VspBspTree.h"
|
---|
| 28 | #include "ViewCellBsp.h"
|
---|
| 29 | #include "ViewCellsManager.h"
|
---|
[971] | 30 | #include "GzFileInputSource.h"
|
---|
[1233] | 31 | #include "OspTree.h"
|
---|
| 32 | #include "VspTree.h"
|
---|
[1201] | 33 | #include "KdTree.h"
|
---|
[1263] | 34 | #include "BvHierarchy.h"
|
---|
[1278] | 35 | #include "HierarchyManager.h"
|
---|
[508] | 36 |
|
---|
[1022] | 37 |
|
---|
[2176] | 38 | using namespace std;
|
---|
| 39 |
|
---|
[863] | 40 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 41 |
|
---|
| 42 |
|
---|
[508] | 43 | // ---------------------------------------------------------------------------
|
---|
| 44 | // Local data
|
---|
| 45 | //
|
---|
| 46 | // doNamespaces
|
---|
| 47 | // Indicates whether namespace processing should be enabled or not.
|
---|
| 48 | // The default is no, but -n overrides that.
|
---|
| 49 | //
|
---|
| 50 | // doSchema
|
---|
| 51 | // Indicates whether schema processing should be enabled or not.
|
---|
| 52 | // The default is no, but -s overrides that.
|
---|
| 53 | //
|
---|
| 54 | // schemaFullChecking
|
---|
| 55 | // Indicates whether full schema constraint checking should be enabled or not.
|
---|
| 56 | // The default is no, but -s overrides that.
|
---|
| 57 | //
|
---|
| 58 | // valScheme
|
---|
| 59 | // Indicates what validation scheme to use. It defaults to 'auto', but
|
---|
| 60 | // can be set via the -v= command.
|
---|
| 61 | // ---------------------------------------------------------------------------
|
---|
[2542] | 62 | static bool doNamespaces = false;
|
---|
| 63 | static bool doSchema = false;
|
---|
| 64 | static bool schemaFullChecking = false;
|
---|
| 65 | static SAXParser::ValSchemes valScheme = SAXParser::Val_Auto;
|
---|
[508] | 66 |
|
---|
[2093] | 67 | // hack for loading bvh nodes
|
---|
[2063] | 68 | #define PVS_HACK 0
|
---|
[2123] | 69 | #define USE_HASH_COMPARE 1
|
---|
[508] | 70 |
|
---|
[2123] | 71 |
|
---|
[1197] | 72 | inline static bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
| 73 | {
|
---|
| 74 | return obj1->mId < obj2->mId;
|
---|
| 75 | }
|
---|
[508] | 76 |
|
---|
| 77 |
|
---|
| 78 | // ---------------------------------------------------------------------------
|
---|
| 79 | // StdInParseHandlers: Constructors and Destructor
|
---|
| 80 | // ---------------------------------------------------------------------------
|
---|
[2113] | 81 | ViewCellsParseHandlers::ViewCellsParseHandlers(ObjectContainer &pvsObjects,
|
---|
| 82 | ObjectContainer &preprocessorObjects,
|
---|
| 83 | BoundingBoxConverter *bconverter
|
---|
| 84 | ):
|
---|
[508] | 85 | mElementCount(0)
|
---|
| 86 | , mAttrCount(0)
|
---|
| 87 | , mCharacterCount(0)
|
---|
| 88 | , mSpaceCount(0)
|
---|
[577] | 89 | , mViewCellsManager(NULL)
|
---|
| 90 | , mVspBspTree(NULL)
|
---|
| 91 | , mBspTree(NULL)
|
---|
[651] | 92 | , mViewCellsTree(NULL)
|
---|
[1263] | 93 | , mCurrentState(PARSE_OPTIONS)
|
---|
[651] | 94 | , mCurrentViewCell(NULL)
|
---|
| 95 | , mCurrentBspNode(NULL)
|
---|
[1201] | 96 | , mCurrentVspNode(NULL)
|
---|
[1286] | 97 | , mCurrentOspNode(NULL)
|
---|
| 98 | , mCurrentBvhNode(NULL)
|
---|
[2113] | 99 | , mPvsObjects(pvsObjects)
|
---|
| 100 | , mPreprocessorObjects(preprocessorObjects)
|
---|
[931] | 101 | , mBoundingBoxConverter(bconverter)
|
---|
[1278] | 102 | , mHierarchyManager(NULL)
|
---|
[1623] | 103 | , nViewCells(0)
|
---|
[2005] | 104 | , nObjects(0)
|
---|
[975] | 105 | {
|
---|
[508] | 106 | }
|
---|
| 107 |
|
---|
[575] | 108 |
|
---|
[508] | 109 | ViewCellsParseHandlers::~ViewCellsParseHandlers()
|
---|
| 110 | {
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 |
|
---|
[2123] | 114 | void ViewCellsParseHandlers::CreateHashVector()
|
---|
| 115 | {
|
---|
| 116 | ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end();
|
---|
| 117 |
|
---|
| 118 | for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit)
|
---|
| 119 | {
|
---|
| 120 | mHashPvs[(*oit)->GetId()] = (*oit);
|
---|
| 121 | }
|
---|
| 122 | //Debug<<"\nhsize: " << mHashPvs.size() << endl;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[2539] | 125 |
|
---|
[508] | 126 | // ---------------------------------------------------------------------------
|
---|
| 127 | // StdInParseHandlers: Implementation of the SAX DocumentHandler interface
|
---|
| 128 | // ---------------------------------------------------------------------------
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 | void ViewCellsParseHandlers::endElement(const XMLCh* const name)
|
---|
| 132 | {
|
---|
[1262] | 133 | StrX lname(name);
|
---|
| 134 | string element(lname.LocalForm());
|
---|
[651] | 135 |
|
---|
[1264] | 136 | if (element == "BoundingBoxes")
|
---|
[1286] | 137 | {
|
---|
[1264] | 138 | EndBoundingBoxes();
|
---|
[1286] | 139 | }
|
---|
[2123] | 140 | else if (element == "ViewCells")
|
---|
[1286] | 141 | {
|
---|
[1262] | 142 | EndViewCells();
|
---|
[2123] | 143 | Debug << "view cell hierarchy parsed" << endl;
|
---|
[1286] | 144 | }
|
---|
[2123] | 145 | else if (element == "ObjectSpaceHierarchy")
|
---|
[1262] | 146 | {
|
---|
[1286] | 147 | EndObjectSpaceHierarchy();
|
---|
[2123] | 148 | Debug << "object space hierarchy parsed" << endl;
|
---|
| 149 | mObjectTimer.Exit();
|
---|
[1262] | 150 | }
|
---|
[2123] | 151 | // finished paring, create view cells manager
|
---|
| 152 | else if (element == "VisibilitySolution")
|
---|
[1286] | 153 | {
|
---|
[1264] | 154 | CreateViewCellsManager();
|
---|
[2123] | 155 |
|
---|
| 156 | Debug << "pvs time: " << mPvsTimer.TotalTime() << endl;
|
---|
| 157 | Debug << "object time: " << mObjectTimer.TotalTime() << endl;
|
---|
| 158 | Debug << "box time: " << mBoxTimer.TotalTime() << endl;
|
---|
| 159 |
|
---|
[1286] | 160 | }
|
---|
[2123] | 161 | else if (element == "Interior")
|
---|
[1286] | 162 | {
|
---|
| 163 | switch (mCurrentState)
|
---|
| 164 | {
|
---|
| 165 | case PARSE_VIEWCELLS:
|
---|
| 166 | EndViewCellInterior();
|
---|
| 167 | break;
|
---|
| 168 | case PARSE_OBJECTSPACE_HIERARCHY:
|
---|
| 169 | EndObjectSpaceHierarchyInterior();
|
---|
| 170 | break;
|
---|
| 171 | case PARSE_VIEWSPACE_HIERARCHY:
|
---|
| 172 | EndViewSpaceHierarchyInterior();
|
---|
| 173 | break;
|
---|
| 174 | default:
|
---|
| 175 | break;
|
---|
| 176 | }
|
---|
| 177 | }
|
---|
[508] | 178 | }
|
---|
| 179 |
|
---|
| 180 |
|
---|
[1286] | 181 | void ViewCellsParseHandlers::EndObjectSpaceHierarchy()
|
---|
| 182 | {
|
---|
| 183 | if (mObjectSpaceHierarchyType == OSP)
|
---|
| 184 | {
|
---|
[1287] | 185 | // for a spatial subdivision, it is not necessary to store
|
---|
[1667] | 186 | // the objects with the leaves, they can be classified geometrically
|
---|
| 187 | mHierarchyManager->mOspTree->
|
---|
[2113] | 188 | InsertObjects(mHierarchyManager->mOspTree->mRoot, mPvsObjects);
|
---|
[1286] | 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 | void ViewCellsParseHandlers::EndViewSpaceHierarchyInterior()
|
---|
| 194 | {
|
---|
| 195 | switch (mViewSpaceHierarchyType)
|
---|
| 196 | {
|
---|
| 197 | case BSP:
|
---|
| 198 | EndBspInterior();
|
---|
| 199 | break;
|
---|
| 200 | case VSP:
|
---|
| 201 | EndVspInterior();
|
---|
| 202 | break;
|
---|
| 203 | default:
|
---|
| 204 | Debug << "not implemented view space hierarchy type " << mViewSpaceHierarchyType << endl;
|
---|
| 205 | break;
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 |
|
---|
| 210 | void ViewCellsParseHandlers::EndObjectSpaceHierarchyInterior()
|
---|
| 211 | {
|
---|
| 212 | switch (mObjectSpaceHierarchyType)
|
---|
| 213 | {
|
---|
| 214 | case OSP:
|
---|
| 215 | EndOspInterior();
|
---|
| 216 | break;
|
---|
| 217 | case BVH:
|
---|
| 218 | EndBvhInterior();
|
---|
| 219 | break;
|
---|
| 220 | default:
|
---|
| 221 | Debug << "not implemented object space hierarchy type " << mViewSpaceHierarchyType << endl;
|
---|
| 222 | break;
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 |
|
---|
[575] | 227 | void ViewCellsParseHandlers::EndBspInterior()
|
---|
[508] | 228 | {
|
---|
| 229 | // go one up in the tree
|
---|
[590] | 230 | if (mCurrentBspNode->GetParent())
|
---|
[2005] | 231 | { //cout << "]";
|
---|
[590] | 232 | mCurrentBspNode = mCurrentBspNode->GetParent();
|
---|
[508] | 233 | }
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 |
|
---|
[1286] | 237 | void ViewCellsParseHandlers::EndBvhInterior()
|
---|
| 238 | {
|
---|
| 239 | // go one up in the tree
|
---|
| 240 | if (mCurrentBvhNode->GetParent())
|
---|
[2005] | 241 | { //cout << "]";
|
---|
[1286] | 242 | mCurrentBvhNode = mCurrentBvhNode->GetParent();
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 | void ViewCellsParseHandlers::EndOspInterior()
|
---|
| 248 | {
|
---|
| 249 | // go one up in the tree
|
---|
| 250 | if (mCurrentOspNode->mParent)
|
---|
[2005] | 251 | {
|
---|
| 252 | //cout << "]";
|
---|
[1286] | 253 | mCurrentOspNode = mCurrentOspNode->mParent;
|
---|
| 254 | }
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 |
|
---|
[1201] | 258 | void ViewCellsParseHandlers::EndVspInterior()
|
---|
| 259 | {
|
---|
| 260 | // go one up in the tree
|
---|
| 261 | if (mCurrentVspNode->GetParent())
|
---|
[2005] | 262 | {
|
---|
| 263 | //cout << "]";
|
---|
[1201] | 264 | mCurrentVspNode = mCurrentVspNode->GetParent();
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[1262] | 268 |
|
---|
[651] | 269 | void ViewCellsParseHandlers::EndViewCellInterior()
|
---|
| 270 | {
|
---|
| 271 | // go one up in the tree
|
---|
| 272 | if (mCurrentViewCell->GetParent())
|
---|
[2005] | 273 | {
|
---|
| 274 | //cout << "]";
|
---|
[651] | 275 | mCurrentViewCell = mCurrentViewCell->GetParent();
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
| 278 |
|
---|
[931] | 279 |
|
---|
[863] | 280 | inline static bool vlt(ViewCell *v1, ViewCell *v2)
|
---|
[508] | 281 | {
|
---|
| 282 | return v1->mId < v2->mId;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 |
|
---|
| 286 | void ViewCellsParseHandlers::EndViewCells()
|
---|
| 287 | {
|
---|
[575] | 288 | // sort view cells to help associating view cells according to their id
|
---|
[2114] | 289 | sort(mViewCells.begin(), mViewCells.end(), vlt);
|
---|
[1201] | 290 |
|
---|
| 291 | // not parsing view cells anymore
|
---|
[1263] | 292 | mCurrentState = PARSE_OPTIONS;
|
---|
[508] | 293 | }
|
---|
| 294 |
|
---|
| 295 |
|
---|
[931] | 296 | void ViewCellsParseHandlers::EndBoundingBoxes()
|
---|
| 297 | {
|
---|
[1616] | 298 | const long startTime = GetTime();
|
---|
[2113] | 299 |
|
---|
[2123] | 300 | mBoxTimer.Entry();
|
---|
| 301 |
|
---|
[931] | 302 | if (mBoundingBoxConverter)
|
---|
[2113] | 303 | {
|
---|
[2114] | 304 | // all bounding boxes gathered in this step =>
|
---|
| 305 | // associate object ids with bounding boxes
|
---|
[2113] | 306 | mBoundingBoxConverter->IdentifyObjects(mIBoundingBoxes, mPvsObjects);
|
---|
[1595] | 307 | }
|
---|
[944] | 308 |
|
---|
[2123] | 309 | if (USE_HASH_COMPARE)
|
---|
| 310 | {
|
---|
| 311 | CreateHashVector();
|
---|
| 312 | }
|
---|
| 313 | else
|
---|
| 314 | {
|
---|
[2542] | 315 | // sort objects by id
|
---|
[2123] | 316 | sort(mPvsObjects.begin(), mPvsObjects.end(), ilt);
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[975] | 319 | Debug << "\nconverted bounding boxes to objects in "
|
---|
[2123] | 320 | << TimeDiff(startTime, GetTime()) * 1e-6 << " secs" << endl;
|
---|
[2542] | 321 |
|
---|
[2123] | 322 | mBoxTimer.Exit();
|
---|
[931] | 323 | }
|
---|
[575] | 324 |
|
---|
[931] | 325 |
|
---|
[1201] | 326 | void ViewCellsParseHandlers::StartBspElement(string element,
|
---|
[575] | 327 | AttributeList& attributes)
|
---|
| 328 | {
|
---|
[508] | 329 | if (element == "Interior")
|
---|
| 330 | {
|
---|
[2005] | 331 | //cout << "[";
|
---|
[575] | 332 | StartBspInterior(attributes);
|
---|
[508] | 333 | }
|
---|
| 334 |
|
---|
| 335 | if (element == "Leaf")
|
---|
| 336 | {
|
---|
[2005] | 337 | //cout << "l";
|
---|
[575] | 338 | StartBspLeaf(attributes);
|
---|
[508] | 339 | }
|
---|
[575] | 340 | }
|
---|
[508] | 341 |
|
---|
[575] | 342 |
|
---|
[1201] | 343 | void ViewCellsParseHandlers::StartVspElement(string element,
|
---|
| 344 | AttributeList& attributes)
|
---|
| 345 | {
|
---|
| 346 | if (element == "Interior")
|
---|
| 347 | {
|
---|
[2005] | 348 | //cout << "[";
|
---|
[1201] | 349 | StartVspInterior(attributes);
|
---|
| 350 | }
|
---|
| 351 | if (element == "Leaf")
|
---|
| 352 | {
|
---|
[2005] | 353 | //cout << "l";
|
---|
[1201] | 354 | StartVspLeaf(attributes);
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 |
|
---|
| 359 | void ViewCellsParseHandlers::StartOspElement(string element,
|
---|
| 360 | AttributeList& attributes)
|
---|
| 361 | {
|
---|
| 362 | if (element == "Interior")
|
---|
| 363 | {
|
---|
[2005] | 364 | //cout << "[";
|
---|
[1201] | 365 | StartOspInterior(attributes);
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | if (element == "Leaf")
|
---|
| 369 | {
|
---|
[2005] | 370 | //cout << "l";
|
---|
[1201] | 371 | StartOspLeaf(attributes);
|
---|
| 372 | }
|
---|
| 373 | }
|
---|
| 374 |
|
---|
[1264] | 375 |
|
---|
| 376 | void ViewCellsParseHandlers::StartBvhElement(string element,
|
---|
| 377 | AttributeList& attributes)
|
---|
| 378 | {
|
---|
| 379 | if (element == "Interior")
|
---|
| 380 | {
|
---|
[2005] | 381 | //cout << "[";
|
---|
[1264] | 382 | StartBvhInterior(attributes);
|
---|
| 383 | }
|
---|
| 384 |
|
---|
| 385 | if (element == "Leaf")
|
---|
| 386 | {
|
---|
[2005] | 387 | //cout << "l";
|
---|
[1264] | 388 | StartBvhLeaf(attributes);
|
---|
| 389 | }
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 |
|
---|
[1233] | 393 | void ViewCellsParseHandlers::StartViewSpaceHierarchyElement(const std::string &element,
|
---|
[1201] | 394 | AttributeList& attributes)
|
---|
| 395 | {
|
---|
[1264] | 396 | //-- use cell type according to the chosen method
|
---|
| 397 | switch (mViewSpaceHierarchyType)
|
---|
[1201] | 398 | {
|
---|
[1286] | 399 | case BSP:
|
---|
| 400 | StartBspElement(element, attributes);
|
---|
| 401 | break;
|
---|
| 402 | case VSP:
|
---|
| 403 | StartVspElement(element, attributes);
|
---|
| 404 | break;
|
---|
| 405 | default:
|
---|
| 406 | Debug << "not implemented" << endl;
|
---|
| 407 | break;
|
---|
[1201] | 408 | }
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 |
|
---|
[1233] | 412 | void ViewCellsParseHandlers::StartObjectSpaceHierarchyElement(const std::string &element,
|
---|
[1201] | 413 | AttributeList& attributes)
|
---|
| 414 | {
|
---|
[1264] | 415 | //-- use cell type according to the chosen method
|
---|
| 416 | switch (mObjectSpaceHierarchyType)
|
---|
[1201] | 417 | {
|
---|
[1264] | 418 | case OSP:
|
---|
[1201] | 419 | StartOspElement(element, attributes);
|
---|
| 420 | break;
|
---|
[1264] | 421 | case BVH:
|
---|
| 422 | StartBvhElement(element, attributes);
|
---|
| 423 | break;
|
---|
[1201] | 424 | default:
|
---|
| 425 | Debug << "not implemented" << endl;
|
---|
| 426 | break;
|
---|
| 427 | }
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 |
|
---|
| 431 | void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element,
|
---|
| 432 | AttributeList& attributes)
|
---|
| 433 | {
|
---|
| 434 | // interiors + leaves interpreted view cells else
|
---|
| 435 | if (element == "Interior")
|
---|
| 436 | {
|
---|
[1551] | 437 | StartViewCell(attributes, false);
|
---|
[2123] | 438 | return;
|
---|
[1201] | 439 | }
|
---|
| 440 |
|
---|
| 441 | if (element == "Leaf")
|
---|
| 442 | {
|
---|
[1551] | 443 | StartViewCell(attributes, true);
|
---|
[2123] | 444 | return;
|
---|
[1201] | 445 | }
|
---|
[2123] | 446 |
|
---|
| 447 | Debug << "StartViewCellHierarchyElement: should not come here: " << element << endl;
|
---|
[1201] | 448 | }
|
---|
| 449 |
|
---|
| 450 |
|
---|
[575] | 451 | void ViewCellsParseHandlers::startElement(const XMLCh* const name,
|
---|
| 452 | AttributeList& attributes)
|
---|
[975] | 453 | {
|
---|
[575] | 454 | StrX lname(name);
|
---|
| 455 | string element(lname.LocalForm());
|
---|
[971] | 456 |
|
---|
[651] | 457 | if (element == "ViewCells")
|
---|
| 458 | {
|
---|
[2005] | 459 | cout << "\nparsing view cells" << endl;
|
---|
[2113] | 460 | Debug << "\nparsing view cells" << endl;
|
---|
[1264] | 461 |
|
---|
[1263] | 462 | mCurrentState = PARSE_VIEWCELLS;
|
---|
[1264] | 463 |
|
---|
| 464 | // create new view cells hierarchy
|
---|
| 465 | mViewCellsTree = new ViewCellsTree();
|
---|
[651] | 466 | }
|
---|
[1201] | 467 | // decides about the view cell hierarchy
|
---|
[2123] | 468 | else if (element == "ViewSpaceHierarchy")
|
---|
[1264] | 469 | {
|
---|
[2113] | 470 | Debug << "\nparsing view space hierarchy" << endl;
|
---|
[2115] | 471 | cout << "\nparsing view space hierarchy" << endl;
|
---|
| 472 |
|
---|
[1264] | 473 | mCurrentState = PARSE_VIEWSPACE_HIERARCHY;
|
---|
| 474 | StartViewSpaceHierarchy(attributes);
|
---|
[1201] | 475 | }
|
---|
| 476 | // decides about the view cell hierarchy
|
---|
[2123] | 477 | else if (element == "ObjectSpaceHierarchy")
|
---|
[1201] | 478 | {
|
---|
[2115] | 479 | cout << "\nparsing object space hierarchy" << endl;
|
---|
[2113] | 480 | Debug << "\nparsing object space hierarchy" << endl;
|
---|
| 481 |
|
---|
[1264] | 482 | mCurrentState = PARSE_OBJECTSPACE_HIERARCHY;
|
---|
[2123] | 483 | mObjectTimer.Entry();
|
---|
[1264] | 484 | StartObjectSpaceHierarchy(attributes);
|
---|
[1201] | 485 | }
|
---|
[577] | 486 | // decides the used view cell hierarchy
|
---|
[2123] | 487 | else if (element == "BoundingBox")
|
---|
[931] | 488 | {
|
---|
| 489 | StartBoundingBox(attributes);
|
---|
| 490 | }
|
---|
[2123] | 491 | else
|
---|
[577] | 492 | {
|
---|
[2123] | 493 | // parse view space hierarchy
|
---|
| 494 | switch (mCurrentState)
|
---|
| 495 | {
|
---|
| 496 | case PARSE_VIEWSPACE_HIERARCHY:
|
---|
| 497 | if ((++ nViewCells % 1000) == 0)
|
---|
| 498 | {
|
---|
| 499 | cout << "\r" << nViewCells << " view cells parsed\r";
|
---|
| 500 | Debug << nViewCells << " view cells parsed" << endl;
|
---|
| 501 | }
|
---|
| 502 | StartViewSpaceHierarchyElement(element, attributes);
|
---|
| 503 | break;
|
---|
| 504 | case PARSE_OBJECTSPACE_HIERARCHY:
|
---|
| 505 | if ((++ nObjects % 1000) == 0)
|
---|
| 506 | cout <<"\r" << nObjects << " objects parsed\r";
|
---|
[2005] | 507 |
|
---|
[2123] | 508 | StartObjectSpaceHierarchyElement(element, attributes);
|
---|
| 509 | break;
|
---|
| 510 | case PARSE_VIEWCELLS:
|
---|
| 511 | StartViewCellHierarchyElement(element, attributes);
|
---|
| 512 | break;
|
---|
| 513 | default:
|
---|
| 514 | break;
|
---|
| 515 | }
|
---|
[1201] | 516 | }
|
---|
[575] | 517 |
|
---|
[508] | 518 | ++ mElementCount;
|
---|
| 519 | mAttrCount += attributes.getLength();
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 |
|
---|
[1551] | 523 | void ViewCellsParseHandlers::StartViewCellPvs(ObjectPvs &pvs, const char *ptr)
|
---|
[508] | 524 | {
|
---|
[2539] | 525 | // handle object indices
|
---|
[508] | 526 | vector<int> objIndices;
|
---|
[1551] | 527 | char *endptr;
|
---|
[508] | 528 |
|
---|
[1551] | 529 | while (1)
|
---|
[2539] | 530 | {
|
---|
| 531 | // read object ids
|
---|
[1551] | 532 | const int index = strtol(ptr, &endptr, 10);
|
---|
[2539] | 533 |
|
---|
[1551] | 534 | if (ptr == endptr)
|
---|
| 535 | break;
|
---|
[2539] | 536 |
|
---|
[1551] | 537 | objIndices.push_back(index);
|
---|
| 538 | ptr = endptr;
|
---|
| 539 | }
|
---|
[508] | 540 |
|
---|
[2123] | 541 | mPvsTimer.Entry();
|
---|
| 542 |
|
---|
[2539] | 543 | Intersectable::NewMail();
|
---|
| 544 |
|
---|
[1551] | 545 | // TODO:
|
---|
| 546 | // 1) find objects and add them to pvs
|
---|
| 547 | // 2) get view cell with specified id
|
---|
| 548 | MeshInstance dummyInst(NULL);
|
---|
[2539] | 549 | pair<ObjectContainer::const_iterator, ObjectContainer::const_iterator> result;
|
---|
[508] | 550 |
|
---|
[1551] | 551 | vector<int>::const_iterator it, it_end = objIndices.end();
|
---|
[2115] | 552 |
|
---|
[1551] | 553 | for (it = objIndices.begin(); it != it_end; ++ it)
|
---|
| 554 | {
|
---|
[2115] | 555 | const int objId = *it;
|
---|
[2123] | 556 |
|
---|
| 557 | #if USE_HASH_COMPARE
|
---|
| 558 | pvs_hash::iterator oit = mHashPvs.find(objId);
|
---|
[2115] | 559 |
|
---|
[2123] | 560 | if ((oit != mHashPvs.end()) && ((*oit).second->GetId() == objId))
|
---|
[2114] | 561 | {
|
---|
[2123] | 562 | pvs.AddSample((*oit).second, 1.0f);
|
---|
[2114] | 563 | }
|
---|
[2115] | 564 | #else
|
---|
[2539] | 565 | #if 0
|
---|
[2115] | 566 | dummyInst.SetId(objId);
|
---|
| 567 |
|
---|
| 568 | ObjectContainer::iterator oit =
|
---|
| 569 | lower_bound(mPvsObjects.begin(),
|
---|
| 570 | mPvsObjects.end(),
|
---|
[2539] | 571 | (Intersectable *)&dummyInst,
|
---|
| 572 | ilt);
|
---|
[2115] | 573 |
|
---|
| 574 | if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId))
|
---|
| 575 | {
|
---|
| 576 | pvs.AddSample(*oit, 1.0f);
|
---|
[508] | 577 | }
|
---|
[2539] | 578 | #else
|
---|
[2123] | 579 | pvs.AddSample(mPvsObjects[objId], 1.0f);
|
---|
[2539] | 580 | #endif
|
---|
[2123] | 581 | #endif
|
---|
[508] | 582 | }
|
---|
[2123] | 583 |
|
---|
| 584 | mPvsTimer.Exit();
|
---|
[508] | 585 | }
|
---|
| 586 |
|
---|
| 587 |
|
---|
[1264] | 588 | void ViewCellsParseHandlers::StartViewSpaceHierarchy(AttributeList& attributes)
|
---|
[577] | 589 | {
|
---|
| 590 | int len = attributes.getLength();
|
---|
| 591 |
|
---|
| 592 | Vector3 bmin, bmax;
|
---|
| 593 |
|
---|
| 594 | for (int i = 0; i < len; ++ i)
|
---|
| 595 | {
|
---|
| 596 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 597 | StrX attrValue(attributes.getValue(i));
|
---|
| 598 | const char *ptr = attrValue.LocalForm();
|
---|
| 599 |
|
---|
[1264] | 600 | // hierarchy type
|
---|
| 601 | if (attrName == "type")
|
---|
[577] | 602 | {
|
---|
[1264] | 603 | if (strcmp(ptr, "bsp") == 0)
|
---|
| 604 | {
|
---|
[1623] | 605 | Debug << "\nview space hierarchy: Bsp" << endl;
|
---|
[1264] | 606 | mViewSpaceHierarchyType = BSP;
|
---|
| 607 | }
|
---|
| 608 | else if (strcmp(ptr, "vsp") == 0)
|
---|
| 609 | {
|
---|
[1623] | 610 | Debug << "\nview space hierarchy: Vsp" << endl;
|
---|
[1264] | 611 | mViewSpaceHierarchyType = VSP;
|
---|
| 612 | }
|
---|
| 613 | }
|
---|
| 614 | else if (attrName == "min") // the view space extent
|
---|
| 615 | {
|
---|
[577] | 616 | sscanf(ptr, "%f %f %f",
|
---|
| 617 | &bmin.x, &bmin.y, &bmin.z);
|
---|
| 618 | }
|
---|
| 619 | else if (attrName == "max")
|
---|
| 620 | {
|
---|
| 621 | sscanf(ptr, "%f %f %f",
|
---|
| 622 | &bmax.x, &bmax.y, &bmax.z);
|
---|
| 623 | }
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | mViewSpaceBox = AxisAlignedBox3(bmin, bmax);
|
---|
| 627 |
|
---|
[1264] | 628 | // create the hierarchy based on this information
|
---|
| 629 | CreateViewSpaceHierarchy();
|
---|
[577] | 630 | }
|
---|
| 631 |
|
---|
| 632 |
|
---|
[1264] | 633 | void ViewCellsParseHandlers::StartObjectSpaceHierarchy(AttributeList& attributes)
|
---|
| 634 | {
|
---|
[1286] | 635 | const int len = attributes.getLength();
|
---|
| 636 | Vector3 bmin, bmax;
|
---|
[1264] | 637 |
|
---|
| 638 | for (int i = 0; i < len; ++ i)
|
---|
| 639 | {
|
---|
| 640 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 641 | StrX attrValue(attributes.getValue(i));
|
---|
| 642 | const char *ptr = attrValue.LocalForm();
|
---|
| 643 |
|
---|
| 644 | // hierarchy type
|
---|
| 645 | if (attrName == "type")
|
---|
| 646 | {
|
---|
[1278] | 647 | if (strcmp(ptr, "osp") == 0)
|
---|
[1264] | 648 | {
|
---|
[1623] | 649 | Debug << "\nobject space hierarchy: Osp" << endl;
|
---|
[1286] | 650 |
|
---|
[1284] | 651 | mHierarchyManager =
|
---|
[1421] | 652 | new HierarchyManager(HierarchyManager::KD_BASED_OBJ_SUBDIV);
|
---|
[1286] | 653 |
|
---|
[1421] | 654 | DEL_PTR(mHierarchyManager->mVspTree);
|
---|
| 655 | mHierarchyManager->mVspTree = mVspTree;
|
---|
| 656 |
|
---|
[1286] | 657 | mObjectSpaceHierarchyType = OSP;
|
---|
| 658 |
|
---|
| 659 | //std::stable_sort(objects.begin(), objects.end(), ilt);
|
---|
| 660 | mHierarchyManager->mOspTree->mBoundingBox.Initialize();
|
---|
[2113] | 661 | ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end();
|
---|
[1286] | 662 |
|
---|
| 663 | //-- compute bounding box
|
---|
[2113] | 664 | for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit)
|
---|
[1286] | 665 | {
|
---|
| 666 | Intersectable *obj = *oit;
|
---|
| 667 | // compute bounding box of view space
|
---|
| 668 | mHierarchyManager->mOspTree->mBoundingBox.Include(obj->GetBox());
|
---|
| 669 | }
|
---|
[1264] | 670 | }
|
---|
[1278] | 671 | else if (strcmp(ptr, "bvh") == 0)
|
---|
[1264] | 672 | {
|
---|
[1623] | 673 | Debug << "\nobject space hierarchy: Bvh" << endl;
|
---|
[2543] | 674 |
|
---|
[1286] | 675 | mObjectSpaceHierarchyType = BVH;
|
---|
[1284] | 676 | mHierarchyManager =
|
---|
[1421] | 677 | new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV);
|
---|
| 678 |
|
---|
| 679 | DEL_PTR(mHierarchyManager->mVspTree);
|
---|
| 680 | mHierarchyManager->mVspTree = mVspTree;
|
---|
[1264] | 681 | }
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 |
|
---|
[931] | 687 | void ViewCellsParseHandlers::StartBoundingBox(AttributeList& attributes)
|
---|
| 688 | {
|
---|
| 689 | int len = attributes.getLength();
|
---|
| 690 |
|
---|
| 691 | Vector3 bmin, bmax;
|
---|
| 692 | int id;
|
---|
| 693 |
|
---|
| 694 | for (int i = 0; i < len; ++ i)
|
---|
| 695 | {
|
---|
| 696 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 697 | StrX attrValue(attributes.getValue(i));
|
---|
[2542] | 698 |
|
---|
[931] | 699 | const char *ptr = attrValue.LocalForm();
|
---|
| 700 |
|
---|
| 701 | if (attrName == "id")
|
---|
| 702 | {
|
---|
| 703 | sscanf(ptr, "%d", &id);
|
---|
| 704 | }
|
---|
| 705 | if (attrName == "min")
|
---|
| 706 | {
|
---|
[1264] | 707 | sscanf(ptr, "%f %f %f", &bmin.x, &bmin.y, &bmin.z);
|
---|
[931] | 708 | }
|
---|
| 709 | else if (attrName == "max")
|
---|
| 710 | {
|
---|
[1264] | 711 | sscanf(ptr, "%f %f %f", &bmax.x, &bmax.y, &bmax.z);
|
---|
[931] | 712 | }
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | AxisAlignedBox3 box(bmin, bmax);
|
---|
| 716 | mIBoundingBoxes.push_back(IndexedBoundingBox(id, box));
|
---|
| 717 | }
|
---|
| 718 |
|
---|
| 719 |
|
---|
[575] | 720 | void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes)
|
---|
[508] | 721 | {
|
---|
[1287] | 722 | BspLeaf * leaf;
|
---|
[508] | 723 |
|
---|
[590] | 724 | if (mCurrentBspNode) // replace front or (if not NULL) back child
|
---|
[508] | 725 | {
|
---|
[2017] | 726 | BspInterior *interior = static_cast<BspInterior *>(mCurrentBspNode);
|
---|
[1287] | 727 |
|
---|
| 728 | leaf = new BspLeaf(interior);
|
---|
| 729 | interior->ReplaceChildLink(NULL, leaf);
|
---|
[508] | 730 | }
|
---|
| 731 | else
|
---|
| 732 | {
|
---|
[1287] | 733 | leaf = new BspLeaf();
|
---|
[1264] | 734 | mVspBspTree->mRoot = leaf;
|
---|
[508] | 735 | }
|
---|
| 736 |
|
---|
[1551] | 737 | ///////////
|
---|
[508] | 738 | //-- find associated view cell
|
---|
[1264] | 739 |
|
---|
[508] | 740 | int viewCellId;
|
---|
[1558] | 741 | const int len = attributes.getLength();
|
---|
[508] | 742 |
|
---|
| 743 | for (int i = 0; i < len; ++ i)
|
---|
| 744 | {
|
---|
| 745 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 746 | StrX attrValue(attributes.getValue(i));
|
---|
| 747 |
|
---|
| 748 | const char *ptr = attrValue.LocalForm();
|
---|
| 749 | char *endptr = NULL;
|
---|
| 750 |
|
---|
| 751 | if (attrName == "viewCellId")
|
---|
| 752 | {
|
---|
| 753 | viewCellId = strtol(ptr, &endptr, 10);
|
---|
| 754 | }
|
---|
| 755 | }
|
---|
[590] | 756 |
|
---|
[1264] | 757 | if (viewCellId >= 0) // valid view cell found
|
---|
[508] | 758 | {
|
---|
| 759 | // TODO: get view cell with specified id
|
---|
[1623] | 760 | ViewCellInterior dummyVc;
|
---|
| 761 | dummyVc.SetId(viewCellId);
|
---|
| 762 |
|
---|
| 763 | ViewCellContainer::iterator vit =
|
---|
| 764 | lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt);
|
---|
| 765 |
|
---|
| 766 | //ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
|
---|
[2017] | 767 | // BspViewCell *viewCell = static_cast<BspViewCell *>((*vit).second);
|
---|
[2053] | 768 |
|
---|
[2017] | 769 | BspViewCell *viewCell = static_cast<BspViewCell *>(*vit);
|
---|
[508] | 770 | if (viewCell->GetId() == viewCellId)
|
---|
| 771 | {
|
---|
[1284] | 772 | // create new view cell for bsp nodes
|
---|
[651] | 773 | leaf->SetViewCell(viewCell);
|
---|
[1551] | 774 | viewCell->mLeaves.push_back(leaf);
|
---|
[508] | 775 | }
|
---|
| 776 | else
|
---|
| 777 | {
|
---|
[2005] | 778 | cerr << "error: view cell does not exist" << endl;
|
---|
[508] | 779 | }
|
---|
| 780 | }
|
---|
| 781 | else
|
---|
| 782 | {
|
---|
[863] | 783 | // add to invalid view space
|
---|
[1286] | 784 | leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell());
|
---|
| 785 | leaf->SetTreeValid(false);
|
---|
| 786 | mVspBspTree->PropagateUpValidity(leaf);
|
---|
[654] | 787 | }
|
---|
[508] | 788 | }
|
---|
| 789 |
|
---|
| 790 |
|
---|
[575] | 791 | void ViewCellsParseHandlers::StartBspInterior(AttributeList& attributes)
|
---|
[508] | 792 | {
|
---|
| 793 | Plane3 plane;
|
---|
| 794 | int len = attributes.getLength();
|
---|
| 795 |
|
---|
| 796 | for (int i = 0; i < len; ++ i)
|
---|
| 797 | {
|
---|
| 798 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 799 | StrX attrValue(attributes.getValue(i));
|
---|
| 800 | const char *ptr = attrValue.LocalForm();
|
---|
| 801 |
|
---|
| 802 | if (attrName == "plane")
|
---|
| 803 | {
|
---|
| 804 | sscanf(ptr, "%f %f %f %f",
|
---|
| 805 | &plane.mNormal.x, &plane.mNormal.y, &plane.mNormal.z, &plane.mD);
|
---|
| 806 | }
|
---|
| 807 | }
|
---|
| 808 |
|
---|
| 809 | BspInterior* interior = new BspInterior(plane);
|
---|
| 810 |
|
---|
[590] | 811 | if (mCurrentBspNode) // replace NULL child of parent with current node
|
---|
[508] | 812 | {
|
---|
[2017] | 813 | BspInterior *parent = static_cast<BspInterior *>(mCurrentBspNode);
|
---|
[508] | 814 |
|
---|
[1287] | 815 | parent->ReplaceChildLink(NULL, interior);
|
---|
| 816 | interior->SetParent(parent);
|
---|
[508] | 817 | }
|
---|
| 818 | else
|
---|
| 819 | {
|
---|
[1264] | 820 | mVspBspTree->mRoot = interior;
|
---|
[508] | 821 | }
|
---|
| 822 |
|
---|
[590] | 823 | mCurrentBspNode = interior;
|
---|
[508] | 824 | }
|
---|
| 825 |
|
---|
| 826 |
|
---|
[1551] | 827 | void ViewCellsParseHandlers::StartViewCell(AttributeList& attributes, const bool isLeaf)
|
---|
[651] | 828 | {
|
---|
[1551] | 829 | ViewCell *viewCell = NULL;
|
---|
| 830 | const int len = attributes.getLength();
|
---|
| 831 | float mergeCost;
|
---|
[2093] | 832 |
|
---|
[1705] | 833 | if (isLeaf)
|
---|
| 834 | {
|
---|
| 835 | viewCell = new ViewCellLeaf();
|
---|
| 836 | }
|
---|
| 837 | else
|
---|
| 838 | {
|
---|
| 839 | viewCell = new ViewCellInterior();
|
---|
| 840 | }
|
---|
| 841 |
|
---|
[1551] | 842 | for (int i = 0; i < len; ++ i)
|
---|
[651] | 843 | {
|
---|
[1551] | 844 | const string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 845 |
|
---|
| 846 | if (attrName == "id")
|
---|
| 847 | {
|
---|
| 848 | const StrX attrValue(attributes.getValue(i));
|
---|
| 849 | const char *ptr = attrValue.LocalForm();
|
---|
| 850 | char *endptr = NULL;
|
---|
| 851 | const int id = strtol(ptr, &endptr, 10);
|
---|
[651] | 852 |
|
---|
[1551] | 853 | // create new view cell, otherwise use reference.
|
---|
[1623] | 854 | viewCell->SetId(id);
|
---|
| 855 |
|
---|
[2123] | 856 | if (mCurrentViewCell)
|
---|
| 857 | { // replace front or (if not NULL) back child
|
---|
[1551] | 858 | ViewCellInterior *interior =
|
---|
[2017] | 859 | static_cast<ViewCellInterior *>(mCurrentViewCell);
|
---|
[1551] | 860 | interior->SetupChildLink(viewCell);
|
---|
| 861 | }
|
---|
| 862 | else
|
---|
| 863 | { // set the new root
|
---|
| 864 | mViewCellsTree->SetRoot(viewCell);
|
---|
| 865 | }
|
---|
| 866 |
|
---|
| 867 | if (!isLeaf)
|
---|
| 868 | {
|
---|
| 869 | mCurrentViewCell = viewCell;
|
---|
| 870 | }
|
---|
| 871 | }
|
---|
| 872 | if (attrName == "pvs")
|
---|
[2071] | 873 | {
|
---|
[1551] | 874 | StrX attrValue(attributes.getValue(i));
|
---|
| 875 | const char *ptr = attrValue.LocalForm();
|
---|
| 876 |
|
---|
[2123] | 877 | // hack: assume that view cell id comes before pvs
|
---|
[1551] | 878 | // otherwise view cell is undefined
|
---|
[1623] | 879 |
|
---|
[2048] | 880 | StartViewCellPvs(viewCell->GetPvs(), ptr);
|
---|
[1623] | 881 | //StartViewCellPvs(pvs, ptr);
|
---|
[1551] | 882 | }
|
---|
| 883 | else if (attrName == "active")
|
---|
| 884 | {
|
---|
| 885 | StrX attrValue(attributes.getValue(i));
|
---|
| 886 | const char *ptr = attrValue.LocalForm();
|
---|
| 887 | char *endptr = NULL;
|
---|
| 888 | const bool isActive = (bool)strtol(ptr, &endptr, 10);
|
---|
| 889 |
|
---|
| 890 | if (isActive)
|
---|
| 891 | {
|
---|
| 892 | // TODO
|
---|
| 893 | }
|
---|
| 894 | }
|
---|
| 895 | else if (attrName == "mergecost")
|
---|
| 896 | {
|
---|
| 897 | StrX attrValue(attributes.getValue(i));
|
---|
| 898 |
|
---|
| 899 | const char *ptr = attrValue.LocalForm();
|
---|
| 900 | char *endptr = NULL;
|
---|
| 901 | mergeCost = (float)strtod(ptr, &endptr);
|
---|
| 902 | }
|
---|
[651] | 903 | }
|
---|
| 904 |
|
---|
[1551] | 905 | viewCell->SetMergeCost(mergeCost);
|
---|
[1623] | 906 | //viewCell->SetPvs(pvs);
|
---|
| 907 | mViewCells.push_back(viewCell);
|
---|
[651] | 908 | }
|
---|
| 909 |
|
---|
| 910 |
|
---|
[1264] | 911 | void ViewCellsParseHandlers::CreateViewSpaceHierarchy()
|
---|
[575] | 912 | {
|
---|
[1264] | 913 | if (mViewSpaceHierarchyType == BSP)
|
---|
[575] | 914 | {
|
---|
[1623] | 915 | Debug << "hierarchy type: Bsp" << endl;
|
---|
[1264] | 916 | mVspBspTree = new VspBspTree();
|
---|
[575] | 917 |
|
---|
[1264] | 918 | // set view space box
|
---|
[1563] | 919 | mVspBspTree->mBoundingBox = mViewSpaceBox;
|
---|
[1284] | 920 |
|
---|
[1623] | 921 | //ViewCellsMap::iterator vit, vit_end = mViewCells.end();
|
---|
| 922 | ViewCellContainer::iterator vit, vit_end = mViewCells.end();
|
---|
[1284] | 923 |
|
---|
[1999] | 924 | int i = 0;
|
---|
[1551] | 925 | // remove view cells and exchange them with the
|
---|
| 926 | // view cells specialized for the current hierarchy node type
|
---|
[1623] | 927 | for (vit = mViewCells.begin(); vit != vit_end; ++ vit, ++ i)
|
---|
[1284] | 928 | {
|
---|
[1623] | 929 | ViewCell *vc = (*vit);
|
---|
[1622] | 930 |
|
---|
[1551] | 931 | if (!vc->IsLeaf()) // exchange only leaves
|
---|
| 932 | continue;
|
---|
[1622] | 933 |
|
---|
[1284] | 934 | BspViewCell *bspVc = new BspViewCell();
|
---|
[1622] | 935 |
|
---|
[1551] | 936 | bspVc->SetId(vc->GetId());
|
---|
[1623] | 937 | //bspVc->GetPvs().reserve(vc->GetPvs().size());
|
---|
[1284] | 938 | bspVc->SetPvs(vc->GetPvs());
|
---|
| 939 |
|
---|
| 940 | if (vc->IsRoot())
|
---|
| 941 | {
|
---|
| 942 | mViewCellsTree->mRoot = bspVc;
|
---|
| 943 | }
|
---|
| 944 | else
|
---|
| 945 | {
|
---|
[1286] | 946 | vc->GetParent()->ReplaceChildLink(vc, bspVc);
|
---|
[1284] | 947 | }
|
---|
| 948 |
|
---|
[1999] | 949 | // delete old view cell
|
---|
[1284] | 950 | DEL_PTR(vc);
|
---|
[1999] | 951 |
|
---|
[2332] | 952 | //(*vit).second = bspVc;
|
---|
[1623] | 953 | (*vit) = bspVc;
|
---|
[1284] | 954 | }
|
---|
[2005] | 955 | cout << "finished creating view space hierarchy" << endl;
|
---|
[1264] | 956 | }
|
---|
| 957 | else if (mViewSpaceHierarchyType == VSP)
|
---|
[975] | 958 | {
|
---|
[1623] | 959 | Debug << "hierarchy type: Vsp" << endl;
|
---|
[1264] | 960 | mVspTree = new VspTree();
|
---|
[1278] | 961 |
|
---|
[1264] | 962 | // set view space box
|
---|
| 963 | mVspTree->mBoundingBox = mViewSpaceBox;
|
---|
[1278] | 964 |
|
---|
[1999] | 965 | // ViewCellsMap::iterator vit, vit_end = mViewCells.end();
|
---|
| 966 | ViewCellContainer::iterator vit, vit_end = mViewCells.end();
|
---|
| 967 |
|
---|
[1284] | 968 | // reset view cells using the current node type
|
---|
| 969 | for (vit = mViewCells.begin(); vit != vit_end; ++ vit)
|
---|
| 970 | {
|
---|
[1623] | 971 | //ViewCell *vc = (*vit).second;
|
---|
[1999] | 972 | ViewCell *vc = (*vit);
|
---|
| 973 |
|
---|
| 974 | if (!vc->IsLeaf()) // exchange only leaves
|
---|
| 975 | continue;
|
---|
| 976 |
|
---|
[1284] | 977 | VspViewCell *vspVc = new VspViewCell();
|
---|
[1999] | 978 |
|
---|
[1284] | 979 | vspVc->SetPvs(vc->GetPvs());
|
---|
| 980 | vspVc->SetId(vc->GetId());
|
---|
| 981 |
|
---|
| 982 | if (vc->IsRoot())
|
---|
| 983 | {
|
---|
| 984 | mViewCellsTree->mRoot = vspVc;
|
---|
| 985 | }
|
---|
| 986 | else
|
---|
| 987 | {
|
---|
[1286] | 988 | vc->GetParent()->ReplaceChildLink(vc, vspVc);
|
---|
[1284] | 989 | }
|
---|
| 990 |
|
---|
[1999] | 991 | // exchange view cell with new one
|
---|
| 992 | DEL_PTR(vc);
|
---|
[1623] | 993 | //(*vit).second = vspVc;
|
---|
| 994 | (*vit) = vspVc;
|
---|
[1284] | 995 | }
|
---|
| 996 |
|
---|
[1278] | 997 | if (mHierarchyManager)
|
---|
| 998 | {
|
---|
[2543] | 999 | // do this only if object hierarchy was already constructed
|
---|
[1278] | 1000 | mHierarchyManager->mVspTree = mVspTree;
|
---|
| 1001 | mVspTree->mHierarchyManager = mHierarchyManager;
|
---|
| 1002 | }
|
---|
[1264] | 1003 | }
|
---|
| 1004 | }
|
---|
[577] | 1005 |
|
---|
[1264] | 1006 |
|
---|
[1421] | 1007 | void ViewCellsParseHandlers::CreateViewCellsManager()
|
---|
[1264] | 1008 | {
|
---|
[1286] | 1009 | if (mViewSpaceHierarchyType == BSP)
|
---|
[1264] | 1010 | {
|
---|
[1928] | 1011 | Debug << "\ncreating view cells manager: VspBsp" << endl;
|
---|
[1264] | 1012 | mViewCellsManager = new VspBspViewCellsManager(mViewCellsTree, mVspBspTree);
|
---|
[1022] | 1013 | }
|
---|
[1264] | 1014 | else if (mViewSpaceHierarchyType == VSP)
|
---|
| 1015 | {
|
---|
[1928] | 1016 | Debug << "\ncreating view cells manager: VspOsp" << endl;
|
---|
[1278] | 1017 | mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mHierarchyManager);
|
---|
[1264] | 1018 | }
|
---|
[1263] | 1019 |
|
---|
[577] | 1020 | mViewCellsManager->SetViewSpaceBox(mViewSpaceBox);
|
---|
[575] | 1021 | }
|
---|
| 1022 |
|
---|
| 1023 |
|
---|
[508] | 1024 | void ViewCellsParseHandlers::characters(const XMLCh* const chars,
|
---|
| 1025 | const unsigned int length)
|
---|
| 1026 | {
|
---|
| 1027 | mCharacterCount += length;
|
---|
| 1028 | }
|
---|
| 1029 |
|
---|
| 1030 |
|
---|
| 1031 | void ViewCellsParseHandlers::ignorableWhitespace(const XMLCh* const chars,
|
---|
| 1032 | const unsigned int length)
|
---|
| 1033 | {
|
---|
| 1034 | mSpaceCount += length;
|
---|
| 1035 | }
|
---|
| 1036 |
|
---|
| 1037 |
|
---|
| 1038 | void ViewCellsParseHandlers::resetDocument()
|
---|
| 1039 | {
|
---|
| 1040 | mAttrCount = 0;
|
---|
| 1041 | mCharacterCount = 0;
|
---|
| 1042 | mElementCount = 0;
|
---|
| 1043 | mSpaceCount = 0;
|
---|
| 1044 | }
|
---|
| 1045 |
|
---|
| 1046 |
|
---|
[1201] | 1047 | void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes)
|
---|
| 1048 | {
|
---|
[1287] | 1049 | VspLeaf * leaf;
|
---|
| 1050 |
|
---|
[1201] | 1051 | if (mCurrentVspNode) // replace front or (if not NULL) back child
|
---|
| 1052 | {
|
---|
[2017] | 1053 | VspInterior *interior = static_cast<VspInterior *>(mCurrentVspNode);
|
---|
[1287] | 1054 | leaf = new VspLeaf(interior);
|
---|
| 1055 | interior->ReplaceChildLink(NULL, leaf);
|
---|
[1201] | 1056 | }
|
---|
| 1057 | else
|
---|
| 1058 | {
|
---|
[1287] | 1059 | leaf = new VspLeaf();
|
---|
[1201] | 1060 | mVspTree->mRoot = leaf;
|
---|
| 1061 | }
|
---|
| 1062 |
|
---|
[1551] | 1063 | /////////////
|
---|
| 1064 | //-- find view cell associated with the id
|
---|
| 1065 |
|
---|
[1201] | 1066 | int viewCellId;
|
---|
[1586] | 1067 | const int len = attributes.getLength();
|
---|
[1201] | 1068 |
|
---|
| 1069 | for (int i = 0; i < len; ++ i)
|
---|
| 1070 | {
|
---|
| 1071 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 1072 | StrX attrValue(attributes.getValue(i));
|
---|
| 1073 |
|
---|
| 1074 | const char *ptr = attrValue.LocalForm();
|
---|
| 1075 | char *endptr = NULL;
|
---|
| 1076 |
|
---|
| 1077 | if (attrName == "viewCellId")
|
---|
| 1078 | {
|
---|
| 1079 | viewCellId = strtol(ptr, &endptr, 10);
|
---|
| 1080 | }
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|
[1551] | 1083 | if (viewCellId >= 0) // valid view cell found
|
---|
[1201] | 1084 | {
|
---|
| 1085 | // TODO: get view cell with specified id
|
---|
[1623] | 1086 | ViewCellInterior dummyVc;
|
---|
[1201] | 1087 | dummyVc.SetId(viewCellId);
|
---|
| 1088 |
|
---|
| 1089 | ViewCellContainer::iterator vit =
|
---|
| 1090 | lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt);
|
---|
[1623] | 1091 |
|
---|
| 1092 | //ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
|
---|
[1284] | 1093 | if (vit == mViewCells.end())
|
---|
[1623] | 1094 | Debug << "error: view cell " << viewCellId << " not found" << endl;
|
---|
[1286] | 1095 |
|
---|
[2017] | 1096 | //VspViewCell *viewCell = static_cast<VspViewCell *>((*vit).second);
|
---|
| 1097 | VspViewCell *viewCell = static_cast<VspViewCell *>(*vit);
|
---|
[1286] | 1098 |
|
---|
[1201] | 1099 | if (viewCell->GetId() == viewCellId)
|
---|
| 1100 | {
|
---|
| 1101 | leaf->SetViewCell(viewCell);
|
---|
[1551] | 1102 | viewCell->mLeaves.push_back(leaf);
|
---|
[1201] | 1103 | }
|
---|
| 1104 | else
|
---|
| 1105 | {
|
---|
[1623] | 1106 | Debug << "error: view cell does not exist" << endl;
|
---|
[1201] | 1107 | }
|
---|
| 1108 | }
|
---|
| 1109 | else
|
---|
[1286] | 1110 | {
|
---|
[1201] | 1111 | // add to invalid view space
|
---|
| 1112 | leaf->SetViewCell(mVspTree->GetOrCreateOutOfBoundsCell());
|
---|
| 1113 | leaf->SetTreeValid(false);
|
---|
| 1114 | mVspTree->PropagateUpValidity(leaf);
|
---|
| 1115 | }
|
---|
| 1116 | }
|
---|
| 1117 |
|
---|
| 1118 |
|
---|
| 1119 | void ViewCellsParseHandlers::StartVspInterior(AttributeList& attributes)
|
---|
| 1120 | {
|
---|
| 1121 | AxisAlignedPlane plane;
|
---|
[1586] | 1122 | const int len = attributes.getLength();
|
---|
[1201] | 1123 |
|
---|
| 1124 | for (int i = 0; i < len; ++ i)
|
---|
| 1125 | {
|
---|
| 1126 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 1127 | StrX attrValue(attributes.getValue(i));
|
---|
| 1128 | const char *ptr = attrValue.LocalForm();
|
---|
| 1129 |
|
---|
| 1130 | if (attrName == "plane")
|
---|
| 1131 | {
|
---|
[1286] | 1132 | sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis);
|
---|
[1201] | 1133 | }
|
---|
| 1134 | }
|
---|
| 1135 |
|
---|
| 1136 | VspInterior* interior = new VspInterior(plane);
|
---|
| 1137 |
|
---|
| 1138 | if (mCurrentVspNode) // replace NULL child of parent with current node
|
---|
| 1139 | {
|
---|
[2017] | 1140 | VspInterior *parent = static_cast<VspInterior *>(mCurrentVspNode);
|
---|
[1201] | 1141 |
|
---|
[1286] | 1142 | parent->ReplaceChildLink(NULL, interior);
|
---|
| 1143 | interior->SetParent(parent);
|
---|
| 1144 |
|
---|
| 1145 | AxisAlignedBox3 frontBox, backBox;
|
---|
| 1146 |
|
---|
[1287] | 1147 | parent->GetBoundingBox().Split(
|
---|
| 1148 | parent->GetPlane().mAxis,
|
---|
| 1149 | parent->GetPlane().mPosition,
|
---|
| 1150 | frontBox,
|
---|
| 1151 | backBox);
|
---|
| 1152 |
|
---|
[1286] | 1153 | if (parent->GetFront() == interior)
|
---|
| 1154 | interior->SetBoundingBox(frontBox);
|
---|
| 1155 | else
|
---|
| 1156 | interior->SetBoundingBox(backBox);
|
---|
[1201] | 1157 | }
|
---|
| 1158 | else
|
---|
| 1159 | {
|
---|
| 1160 | mVspTree->mRoot = interior;
|
---|
[1286] | 1161 | interior->SetBoundingBox(mVspTree->GetBoundingBox());
|
---|
[1201] | 1162 | }
|
---|
| 1163 |
|
---|
| 1164 | mCurrentVspNode = interior;
|
---|
| 1165 | }
|
---|
| 1166 |
|
---|
| 1167 |
|
---|
| 1168 | void ViewCellsParseHandlers::StartOspInterior(AttributeList& attributes)
|
---|
| 1169 | {
|
---|
| 1170 | AxisAlignedPlane plane;
|
---|
| 1171 | int len = attributes.getLength();
|
---|
| 1172 |
|
---|
| 1173 | for (int i = 0; i < len; ++ i)
|
---|
| 1174 | {
|
---|
| 1175 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 1176 | StrX attrValue(attributes.getValue(i));
|
---|
| 1177 | const char *ptr = attrValue.LocalForm();
|
---|
| 1178 |
|
---|
| 1179 | if (attrName == "plane")
|
---|
| 1180 | {
|
---|
[1286] | 1181 | sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis);
|
---|
[1201] | 1182 | }
|
---|
| 1183 | }
|
---|
| 1184 |
|
---|
| 1185 | KdInterior* interior = new KdInterior(NULL);
|
---|
| 1186 |
|
---|
| 1187 | interior->mAxis = plane.mAxis;
|
---|
| 1188 | interior->mPosition = plane.mPosition;
|
---|
| 1189 |
|
---|
[1286] | 1190 | if (mCurrentOspNode) // replace NULL child of parent with current node
|
---|
[1201] | 1191 | {
|
---|
[2017] | 1192 | KdInterior *parent = static_cast<KdInterior *>(mCurrentOspNode);
|
---|
[1201] | 1193 | parent->ReplaceChildLink(NULL, interior);
|
---|
| 1194 | interior->mParent = parent;
|
---|
[1286] | 1195 |
|
---|
| 1196 | AxisAlignedBox3 frontBox, backBox;
|
---|
| 1197 |
|
---|
| 1198 | parent->mBox.Split(parent->mAxis, parent->mPosition, frontBox, backBox);
|
---|
[1287] | 1199 |
|
---|
[1286] | 1200 | if (parent->mFront == interior)
|
---|
| 1201 | interior->mBox = frontBox;
|
---|
| 1202 | else
|
---|
| 1203 | interior->mBox = backBox;
|
---|
[1201] | 1204 | }
|
---|
| 1205 | else
|
---|
| 1206 | {
|
---|
[1278] | 1207 | mHierarchyManager->mOspTree->mRoot = interior;
|
---|
[1286] | 1208 | interior->mBox = mHierarchyManager->mOspTree->mBoundingBox;
|
---|
[1201] | 1209 | }
|
---|
| 1210 |
|
---|
[1286] | 1211 | mCurrentOspNode = interior;
|
---|
[1201] | 1212 | }
|
---|
| 1213 |
|
---|
| 1214 |
|
---|
| 1215 | void ViewCellsParseHandlers::StartOspLeaf(AttributeList& attributes)
|
---|
| 1216 | {
|
---|
[2017] | 1217 | KdLeaf * leaf = new KdLeaf(static_cast<KdInterior *>(mCurrentOspNode), NULL);
|
---|
[1201] | 1218 |
|
---|
[1667] | 1219 | if (mCurrentOspNode)
|
---|
[1201] | 1220 | {
|
---|
[1667] | 1221 | // replace front or (if not NULL) back child
|
---|
[2017] | 1222 | static_cast<KdInterior *>(mCurrentOspNode)->ReplaceChildLink(NULL, leaf);
|
---|
[1201] | 1223 | }
|
---|
| 1224 | else
|
---|
| 1225 | {
|
---|
[1278] | 1226 | mHierarchyManager->mOspTree->mRoot = leaf;
|
---|
[1201] | 1227 | }
|
---|
| 1228 | }
|
---|
| 1229 |
|
---|
| 1230 |
|
---|
[1264] | 1231 | void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes)
|
---|
[1286] | 1232 | {
|
---|
| 1233 | const int len = attributes.getLength();
|
---|
| 1234 | Vector3 minBox, maxBox;
|
---|
[1201] | 1235 |
|
---|
[1286] | 1236 | ObjectContainer objects;
|
---|
| 1237 |
|
---|
| 1238 | for (int i = 0; i < len; ++ i)
|
---|
[1264] | 1239 | {
|
---|
[1286] | 1240 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 1241 | StrX attrValue(attributes.getValue(i));
|
---|
| 1242 | const char *ptr = attrValue.LocalForm();
|
---|
| 1243 |
|
---|
| 1244 | if (attrName == "min")
|
---|
| 1245 | {
|
---|
[1287] | 1246 | sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z);
|
---|
[1286] | 1247 | }
|
---|
| 1248 | if (attrName == "max")
|
---|
| 1249 | {
|
---|
[1287] | 1250 | sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z);
|
---|
[1286] | 1251 | }
|
---|
| 1252 | if (attrName == "objects")
|
---|
| 1253 | {
|
---|
[2115] | 1254 | if (!mPreprocessorObjects.empty())
|
---|
| 1255 | StartBvhLeafObjects(objects, ptr);
|
---|
[1286] | 1256 | }
|
---|
[1264] | 1257 | }
|
---|
[1286] | 1258 |
|
---|
[1287] | 1259 | AxisAlignedBox3 box = AxisAlignedBox3(minBox, maxBox);
|
---|
[1286] | 1260 |
|
---|
[1287] | 1261 | BvhLeaf *leaf;
|
---|
[1286] | 1262 |
|
---|
| 1263 | if (mCurrentBvhNode) // replace front or (if not NULL) back child
|
---|
| 1264 | {
|
---|
[2017] | 1265 | BvhInterior *interior = static_cast<BvhInterior *>(mCurrentBvhNode);
|
---|
[2115] | 1266 |
|
---|
[1287] | 1267 | leaf = new BvhLeaf(box, interior, (int)objects.size());
|
---|
| 1268 | interior->ReplaceChildLink(NULL, leaf);
|
---|
[1286] | 1269 | }
|
---|
[1264] | 1270 | else
|
---|
| 1271 | {
|
---|
[1287] | 1272 | leaf = new BvhLeaf(box, NULL, (int)objects.size());
|
---|
[1278] | 1273 | mHierarchyManager->mBvHierarchy->mRoot = leaf;
|
---|
[1286] | 1274 | }
|
---|
[1287] | 1275 |
|
---|
| 1276 | leaf->mObjects = objects;
|
---|
[2048] | 1277 | BvHierarchy::AssociateObjectsWithLeaf(leaf);
|
---|
[1264] | 1278 | }
|
---|
[1201] | 1279 |
|
---|
[1264] | 1280 |
|
---|
[1286] | 1281 | void ViewCellsParseHandlers::StartBvhLeafObjects(ObjectContainer &objects,
|
---|
| 1282 | const char *ptr)
|
---|
| 1283 | {
|
---|
| 1284 | vector<int> objIndices;
|
---|
| 1285 | char *endptr;
|
---|
| 1286 |
|
---|
| 1287 | while (1)
|
---|
| 1288 | {
|
---|
| 1289 | const int index = strtol(ptr, &endptr, 10);
|
---|
| 1290 | if (ptr == endptr) break;
|
---|
| 1291 |
|
---|
| 1292 | objIndices.push_back(index);
|
---|
| 1293 | ptr = endptr;
|
---|
| 1294 | }
|
---|
| 1295 |
|
---|
| 1296 | MeshInstance dummyInst(NULL);
|
---|
| 1297 | vector<int>::const_iterator it, it_end = objIndices.end();
|
---|
| 1298 |
|
---|
| 1299 | for (it = objIndices.begin(); it != it_end; ++ it)
|
---|
| 1300 | {
|
---|
| 1301 | const int objId = *it;
|
---|
| 1302 | dummyInst.SetId(objId);
|
---|
| 1303 |
|
---|
[2115] | 1304 | ObjectContainer::const_iterator oit =
|
---|
| 1305 | lower_bound(mPreprocessorObjects.begin(),
|
---|
| 1306 | mPreprocessorObjects.end(),
|
---|
[1287] | 1307 | (Intersectable *)&dummyInst,
|
---|
| 1308 | ilt);
|
---|
[1286] | 1309 |
|
---|
[2115] | 1310 | if ((oit != mPreprocessorObjects.end()) && ((*oit)->GetId() == objId))
|
---|
[1286] | 1311 | {
|
---|
[1486] | 1312 | objects.push_back(*oit);
|
---|
[1286] | 1313 | }
|
---|
| 1314 | else
|
---|
| 1315 | {
|
---|
[2113] | 1316 | //cerr << "StartBvhLeafObjects error: object with id " << objId << " does not exist" << endl;
|
---|
[1286] | 1317 | }
|
---|
| 1318 | }
|
---|
| 1319 | }
|
---|
| 1320 |
|
---|
| 1321 |
|
---|
[1264] | 1322 | void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes)
|
---|
[1286] | 1323 | {
|
---|
| 1324 | const int len = attributes.getLength();
|
---|
| 1325 | Vector3 minBox, maxBox;
|
---|
[1264] | 1326 |
|
---|
| 1327 | for (int i = 0; i < len; ++ i)
|
---|
| 1328 | {
|
---|
| 1329 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 1330 | StrX attrValue(attributes.getValue(i));
|
---|
| 1331 | const char *ptr = attrValue.LocalForm();
|
---|
| 1332 |
|
---|
[1286] | 1333 | if (attrName == "min")
|
---|
[1294] | 1334 | {
|
---|
[1287] | 1335 | sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z);
|
---|
[1264] | 1336 | }
|
---|
[1286] | 1337 | if (attrName == "max")
|
---|
[1294] | 1338 | {
|
---|
[1287] | 1339 | sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z);
|
---|
[1286] | 1340 | }
|
---|
[1264] | 1341 | }
|
---|
| 1342 |
|
---|
[1286] | 1343 | BvhInterior* interior = new BvhInterior(AxisAlignedBox3(minBox, maxBox));
|
---|
[1264] | 1344 |
|
---|
[1286] | 1345 | if (mCurrentBvhNode) // replace NULL child of parent with current node
|
---|
[1264] | 1346 | {
|
---|
[2017] | 1347 | BvhInterior *parent = static_cast<BvhInterior *>(mCurrentBvhNode);
|
---|
[1264] | 1348 | parent->ReplaceChildLink(NULL, interior);
|
---|
[1286] | 1349 | interior->SetParent(parent);
|
---|
[1264] | 1350 | }
|
---|
| 1351 | else
|
---|
[1294] | 1352 | {
|
---|
[1287] | 1353 | mHierarchyManager->mBvHierarchy->mRoot = interior;
|
---|
[1264] | 1354 | }
|
---|
[1294] | 1355 |
|
---|
[1286] | 1356 | mCurrentBvhNode = interior;
|
---|
[1264] | 1357 | }
|
---|
| 1358 |
|
---|
| 1359 |
|
---|
[508] | 1360 | // ---------------------------------------------------------------------------
|
---|
| 1361 | // StdInParseHandlers: Overrides of the SAX ErrorHandler interface
|
---|
| 1362 | // ---------------------------------------------------------------------------
|
---|
[1201] | 1363 |
|
---|
| 1364 |
|
---|
[508] | 1365 | void
|
---|
| 1366 | ViewCellsParseHandlers::error(const SAXParseException& e)
|
---|
| 1367 | {
|
---|
| 1368 | XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId())
|
---|
| 1369 | << ", line " << e.getLineNumber()
|
---|
| 1370 | << ", char " << e.getColumnNumber()
|
---|
| 1371 | << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
| 1372 | }
|
---|
| 1373 |
|
---|
| 1374 | void
|
---|
| 1375 | ViewCellsParseHandlers::fatalError(const SAXParseException& e)
|
---|
| 1376 | {
|
---|
| 1377 | XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId())
|
---|
| 1378 | << ", line " << e.getLineNumber()
|
---|
| 1379 | << ", char " << e.getColumnNumber()
|
---|
| 1380 | << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
| 1381 | }
|
---|
| 1382 |
|
---|
| 1383 | void
|
---|
| 1384 | ViewCellsParseHandlers::warning(const SAXParseException& e)
|
---|
| 1385 | {
|
---|
| 1386 | XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId())
|
---|
| 1387 | << ", line " << e.getLineNumber()
|
---|
| 1388 | << ", char " << e.getColumnNumber()
|
---|
| 1389 | << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
| 1390 | }
|
---|
| 1391 |
|
---|
| 1392 |
|
---|
[2113] | 1393 | bool ViewCellsParser::ParseViewCellsFile(const string &filename,
|
---|
[1221] | 1394 | ViewCellsManager **viewCells,
|
---|
[2113] | 1395 | ObjectContainer &pvsObjects,
|
---|
| 1396 | ObjectContainer &preprocessorObjects,
|
---|
[1221] | 1397 | BoundingBoxConverter *bconverter)
|
---|
[508] | 1398 | {
|
---|
[2114] | 1399 | // Initialize the XML4C system
|
---|
| 1400 | try {
|
---|
| 1401 | XMLPlatformUtils::Initialize();
|
---|
| 1402 | }
|
---|
[1715] | 1403 |
|
---|
[2114] | 1404 | catch (const XMLException& toCatch)
|
---|
| 1405 | {
|
---|
| 1406 | XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
---|
| 1407 | << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
| 1408 | return false;
|
---|
| 1409 | }
|
---|
[1715] | 1410 |
|
---|
[2114] | 1411 | // cout<<"parsing started"<<endl<<flush;
|
---|
[508] | 1412 |
|
---|
[2114] | 1413 | //
|
---|
| 1414 | // Create a SAX parser object. Then, according to what we were told on
|
---|
| 1415 | // the command line, set the options.
|
---|
| 1416 | //
|
---|
| 1417 | SAXParser* parser = new SAXParser;
|
---|
| 1418 | parser->setValidationScheme(valScheme);
|
---|
| 1419 | parser->setDoNamespaces(doNamespaces);
|
---|
| 1420 | parser->setDoSchema(doSchema);
|
---|
| 1421 | parser->setValidationSchemaFullChecking(schemaFullChecking);
|
---|
| 1422 |
|
---|
| 1423 |
|
---|
| 1424 | //
|
---|
| 1425 | // Create our SAX handler object and install it on the parser, as the
|
---|
| 1426 | // document and error handler. We are responsible for cleaning them
|
---|
| 1427 | // up, but since its just stack based here, there's nothing special
|
---|
| 1428 | // to do.
|
---|
| 1429 | //
|
---|
| 1430 | ViewCellsParseHandlers handler(pvsObjects, preprocessorObjects, bconverter);
|
---|
| 1431 | parser->setDocumentHandler(&handler);
|
---|
| 1432 | parser->setErrorHandler(&handler);
|
---|
| 1433 |
|
---|
| 1434 | unsigned long duration;
|
---|
| 1435 | int errorCount = 0;
|
---|
| 1436 | // create a faux scope so that 'src' destructor is called before
|
---|
| 1437 | // XMLPlatformUtils::Terminate
|
---|
[1264] | 1438 | {
|
---|
[2114] | 1439 | //
|
---|
| 1440 | // Kick off the parse and catch any exceptions. Create a standard
|
---|
| 1441 | // input input source and tell the parser to parse from that.
|
---|
| 1442 | //
|
---|
| 1443 | // StdInInputSource src;
|
---|
| 1444 | try
|
---|
| 1445 | {
|
---|
| 1446 | const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
---|
[1264] | 1447 |
|
---|
[1201] | 1448 | #if USE_GZLIB
|
---|
[2114] | 1449 | XMLCh *myFilePath = XMLString::transcode(filename.c_str());
|
---|
| 1450 |
|
---|
| 1451 | GzFileInputSource isource(myFilePath);
|
---|
| 1452 | parser->parse(isource);
|
---|
[971] | 1453 | #else
|
---|
[2114] | 1454 | parser->parse(filename.c_str());
|
---|
[2048] | 1455 |
|
---|
[971] | 1456 | #endif
|
---|
| 1457 |
|
---|
[2114] | 1458 | //if (mCreatePvsObjects)
|
---|
| 1459 | // handler.ReplacePvs();
|
---|
[2048] | 1460 |
|
---|
[2114] | 1461 | const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
---|
| 1462 | duration = endMillis - startMillis;
|
---|
| 1463 | errorCount = parser->getErrorCount();
|
---|
| 1464 | }
|
---|
| 1465 | catch (const OutOfMemoryException&)
|
---|
| 1466 | {
|
---|
| 1467 | XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
---|
| 1468 | errorCount = 2;
|
---|
| 1469 | return false;
|
---|
| 1470 | }
|
---|
| 1471 | catch (const XMLException& e)
|
---|
| 1472 | {
|
---|
[870] | 1473 | XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n"
|
---|
[2114] | 1474 | << StrX(e.getMessage())
|
---|
| 1475 | << "\n" << XERCES_STD_QUALIFIER endl;
|
---|
[870] | 1476 | errorCount = 1;
|
---|
| 1477 | return false;
|
---|
[2114] | 1478 | }
|
---|
[508] | 1479 |
|
---|
[2114] | 1480 |
|
---|
| 1481 | // Print out the stats that we collected and time taken
|
---|
| 1482 | if (!errorCount)
|
---|
| 1483 | {
|
---|
| 1484 | XERCES_STD_QUALIFIER cerr << filename << ": " << duration << " ms ("
|
---|
[508] | 1485 | << handler.GetElementCount() << " elems, "
|
---|
| 1486 | << handler.GetAttrCount() << " attrs, "
|
---|
| 1487 | << handler.GetSpaceCount() << " spaces, "
|
---|
| 1488 | << handler.GetCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
|
---|
[2114] | 1489 | }
|
---|
| 1490 | }
|
---|
[1715] | 1491 |
|
---|
[2114] | 1492 | //
|
---|
| 1493 | // Delete the parser itself. Must be done prior to calling Terminate, below.
|
---|
| 1494 | //
|
---|
| 1495 | delete parser;
|
---|
| 1496 |
|
---|
| 1497 | XMLPlatformUtils::Terminate();
|
---|
| 1498 |
|
---|
| 1499 | //-- assign new view cells manager
|
---|
| 1500 | *viewCells = handler.mViewCellsManager;
|
---|
| 1501 |
|
---|
| 1502 | if (errorCount > 0)
|
---|
| 1503 | return false;
|
---|
| 1504 | else
|
---|
| 1505 | return true;
|
---|
[556] | 1506 | }
|
---|
[860] | 1507 |
|
---|
[2114] | 1508 | } |
---|