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