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