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