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