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