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