[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"
|
---|
[590] | 30 | #include "VspKdTree.h"
|
---|
[508] | 31 | #include "ViewCellsManager.h"
|
---|
| 32 |
|
---|
| 33 | // ---------------------------------------------------------------------------
|
---|
| 34 | // Local data
|
---|
| 35 | //
|
---|
| 36 | // doNamespaces
|
---|
| 37 | // Indicates whether namespace processing should be enabled or not.
|
---|
| 38 | // The default is no, but -n overrides that.
|
---|
| 39 | //
|
---|
| 40 | // doSchema
|
---|
| 41 | // Indicates whether schema processing should be enabled or not.
|
---|
| 42 | // The default is no, but -s overrides that.
|
---|
| 43 | //
|
---|
| 44 | // schemaFullChecking
|
---|
| 45 | // Indicates whether full schema constraint checking should be enabled or not.
|
---|
| 46 | // The default is no, but -s overrides that.
|
---|
| 47 | //
|
---|
| 48 | // valScheme
|
---|
| 49 | // Indicates what validation scheme to use. It defaults to 'auto', but
|
---|
| 50 | // can be set via the -v= command.
|
---|
| 51 | // ---------------------------------------------------------------------------
|
---|
| 52 | static bool doNamespaces = false;
|
---|
| 53 | static bool doSchema = false;
|
---|
| 54 | static bool schemaFullChecking = false;
|
---|
| 55 | static SAXParser::ValSchemes valScheme = SAXParser::Val_Auto;
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | // ---------------------------------------------------------------------------
|
---|
| 62 | // StdInParseHandlers: Constructors and Destructor
|
---|
| 63 | // ---------------------------------------------------------------------------
|
---|
[577] | 64 | ViewCellsParseHandlers::ViewCellsParseHandlers(ObjectContainer *objects):
|
---|
[508] | 65 | mElementCount(0)
|
---|
| 66 | , mAttrCount(0)
|
---|
| 67 | , mCharacterCount(0)
|
---|
| 68 | , mSpaceCount(0)
|
---|
[577] | 69 | , mViewCellsManager(NULL)
|
---|
| 70 | , mVspBspTree(NULL)
|
---|
| 71 | , mBspTree(NULL)
|
---|
[651] | 72 | , mViewCellsTree(NULL)
|
---|
| 73 | , mParseViewCells(true)
|
---|
| 74 | , mCurrentViewCell(NULL)
|
---|
| 75 | , mCurrentBspNode(NULL)
|
---|
[508] | 76 | {
|
---|
| 77 | mObjects = objects;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[575] | 80 |
|
---|
[508] | 81 | ViewCellsParseHandlers::~ViewCellsParseHandlers()
|
---|
| 82 | {
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | // ---------------------------------------------------------------------------
|
---|
| 87 | // StdInParseHandlers: Implementation of the SAX DocumentHandler interface
|
---|
| 88 | // ---------------------------------------------------------------------------
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | void ViewCellsParseHandlers::endElement(const XMLCh* const name)
|
---|
| 92 | {
|
---|
| 93 | StrX lname(name);
|
---|
| 94 | string element(lname.LocalForm());
|
---|
[651] | 95 |
|
---|
[508] | 96 | if (element == "ViewCells")
|
---|
| 97 | EndViewCells();
|
---|
[651] | 98 |
|
---|
| 99 | if (mParseViewCells)
|
---|
| 100 | {
|
---|
| 101 | if (element == "Interior")
|
---|
| 102 | EndViewCellInterior();
|
---|
| 103 | }
|
---|
| 104 | else
|
---|
| 105 | {
|
---|
| 106 | if (element == "Interior")
|
---|
| 107 | EndBspInterior();
|
---|
| 108 | }
|
---|
[508] | 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
[575] | 112 | void ViewCellsParseHandlers::EndBspInterior()
|
---|
[508] | 113 | {
|
---|
| 114 | // go one up in the tree
|
---|
[590] | 115 | if (mCurrentBspNode->GetParent())
|
---|
[508] | 116 | { cout << "]";
|
---|
[590] | 117 | mCurrentBspNode = mCurrentBspNode->GetParent();
|
---|
[508] | 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
[651] | 122 | void ViewCellsParseHandlers::EndViewCellInterior()
|
---|
| 123 | {
|
---|
| 124 | // go one up in the tree
|
---|
| 125 | if (mCurrentViewCell->GetParent())
|
---|
| 126 | { cout << "]";
|
---|
| 127 | mCurrentViewCell = mCurrentViewCell->GetParent();
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[508] | 131 | inline bool vlt(ViewCell *v1, ViewCell *v2)
|
---|
| 132 | {
|
---|
| 133 | return v1->mId < v2->mId;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 | void ViewCellsParseHandlers::EndViewCells()
|
---|
| 138 | {
|
---|
[575] | 139 | // sort view cells to help associating view cells according to their id
|
---|
[508] | 140 | stable_sort(mViewCells.begin(), mViewCells.end(), vlt);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 |
|
---|
[575] | 144 |
|
---|
| 145 | void ViewCellsParseHandlers::StartHierarchy(AttributeList& attributes)
|
---|
[508] | 146 | {
|
---|
[575] | 147 | int len = attributes.getLength();
|
---|
| 148 |
|
---|
| 149 | for (int i = 0; i < len; ++ i)
|
---|
| 150 | {
|
---|
| 151 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 152 |
|
---|
| 153 | if (attrName == "name")
|
---|
| 154 | {
|
---|
| 155 | StrX attrValue(attributes.getValue(i));
|
---|
| 156 |
|
---|
| 157 | const char *ptr = attrValue.LocalForm();
|
---|
| 158 |
|
---|
| 159 | CreateViewCellsManager(ptr);
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | void ViewCellsParseHandlers::startBspElement(string element,
|
---|
| 166 | AttributeList& attributes)
|
---|
| 167 | {
|
---|
[508] | 168 | if (element == "Interior")
|
---|
| 169 | {
|
---|
| 170 | cout << "[";
|
---|
[575] | 171 | StartBspInterior(attributes);
|
---|
[508] | 172 | }
|
---|
| 173 |
|
---|
| 174 | if (element == "Leaf")
|
---|
| 175 | {
|
---|
[651] | 176 | cout << "l";
|
---|
| 177 | Debug << "leaf" << endl;
|
---|
[575] | 178 | StartBspLeaf(attributes);
|
---|
[508] | 179 | }
|
---|
[575] | 180 | }
|
---|
[508] | 181 |
|
---|
[575] | 182 |
|
---|
| 183 | void ViewCellsParseHandlers::startElement(const XMLCh* const name,
|
---|
| 184 | AttributeList& attributes)
|
---|
| 185 | {
|
---|
| 186 | StrX lname(name);
|
---|
| 187 | string element(lname.LocalForm());
|
---|
[577] | 188 |
|
---|
| 189 | // decides the used view cell hierarchy
|
---|
[651] | 190 | if (element == "ViewCells")
|
---|
| 191 | {
|
---|
| 192 | cout << "parsing view cells" << endl;
|
---|
| 193 | mParseViewCells = true;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
[575] | 196 | if (element == "Hierarchy")
|
---|
| 197 | {
|
---|
[651] | 198 | cout << "parsing spatial hierarchy" << endl;
|
---|
| 199 | mParseViewCells = false;
|
---|
[575] | 200 | StartHierarchy(attributes);
|
---|
| 201 | }
|
---|
[577] | 202 |
|
---|
| 203 | // decides the used view cell hierarchy
|
---|
| 204 | if (element == "ViewSpaceBox")
|
---|
| 205 | {
|
---|
[651] | 206 | cout << "b";
|
---|
[577] | 207 | StartViewSpaceBox(attributes);
|
---|
| 208 | }
|
---|
[575] | 209 |
|
---|
[577] | 210 |
|
---|
| 211 | // use different methods for the given view cell hierarchy types
|
---|
[651] | 212 | if (!mParseViewCells)
|
---|
[577] | 213 | {
|
---|
[651] | 214 | if (mViewCellsManager)
|
---|
[577] | 215 | {
|
---|
[651] | 216 | switch (mViewCellsManager->GetType())
|
---|
| 217 | {
|
---|
| 218 | case ViewCellsManager::BSP:
|
---|
| 219 | case ViewCellsManager::VSP_BSP:
|
---|
| 220 | startBspElement(element, attributes);
|
---|
| 221 | break;
|
---|
[575] | 222 |
|
---|
[651] | 223 | default:
|
---|
| 224 | Debug << "not implemented" << endl;
|
---|
| 225 | break;
|
---|
| 226 | }
|
---|
[577] | 227 | }
|
---|
| 228 | }
|
---|
[651] | 229 | else
|
---|
| 230 | {
|
---|
| 231 | if (element == "Interior")
|
---|
| 232 | {
|
---|
| 233 | cout << "[";
|
---|
| 234 | StartViewCellInterior(attributes);
|
---|
| 235 | }
|
---|
[575] | 236 |
|
---|
[651] | 237 | if (element == "Leaf")
|
---|
| 238 | {
|
---|
| 239 | cout << "l";
|
---|
| 240 | StartViewCellLeaf(attributes);
|
---|
| 241 | }
|
---|
| 242 | }
|
---|
| 243 |
|
---|
[508] | 244 | ++ mElementCount;
|
---|
| 245 | mAttrCount += attributes.getLength();
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 |
|
---|
| 249 | inline bool ilt(Intersectable *obj1, Intersectable *obj2)
|
---|
| 250 | {
|
---|
| 251 | return obj1->mId < obj2->mId;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 |
|
---|
[651] | 255 | void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, AttributeList& attributes)
|
---|
[508] | 256 | {
|
---|
| 257 | int len = attributes.getLength();
|
---|
| 258 | vector<int> objIndices;
|
---|
[590] | 259 |
|
---|
[508] | 260 | for (int i = 0; i < len; ++ i)
|
---|
| 261 | {
|
---|
| 262 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 263 |
|
---|
| 264 | if (attrName == "pvs")
|
---|
| 265 | {
|
---|
| 266 | StrX attrValue(attributes.getValue(i));
|
---|
| 267 |
|
---|
| 268 | // handle coordIndex
|
---|
| 269 | objIndices.clear();
|
---|
| 270 | const char *ptr = attrValue.LocalForm();
|
---|
| 271 | char *endptr;
|
---|
| 272 |
|
---|
| 273 | while (1)
|
---|
| 274 | {
|
---|
| 275 | int index = strtol(ptr, &endptr, 10);
|
---|
| 276 |
|
---|
| 277 | if (ptr == endptr)
|
---|
| 278 | break;
|
---|
| 279 |
|
---|
| 280 | objIndices.push_back(index);
|
---|
| 281 |
|
---|
| 282 | ptr = endptr;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
| 285 | //TODO: find objects and add them to pvs
|
---|
| 286 | // TODO: get view cell with specified id
|
---|
| 287 | MeshInstance dummyInst(NULL);
|
---|
| 288 |
|
---|
| 289 | vector<int>::const_iterator it, it_end = objIndices.end();
|
---|
| 290 | for (it = objIndices.begin(); it != it_end; ++ it)
|
---|
| 291 | {
|
---|
| 292 | const int objId = *it;
|
---|
| 293 | dummyInst.SetId(objId);
|
---|
| 294 |
|
---|
| 295 | ObjectContainer::iterator oit =
|
---|
[556] | 296 | lower_bound(mObjects->begin(), mObjects->end(), &dummyInst, ilt);
|
---|
| 297 |
|
---|
[508] | 298 | Intersectable *obj = *oit;
|
---|
| 299 |
|
---|
| 300 | if (obj->GetId() == objId)
|
---|
| 301 | {
|
---|
[556] | 302 | // $$JB we should store a float a per object which corresponds
|
---|
| 303 | // to sumof pdfs, i.e. its relative visibility
|
---|
| 304 | // temporarily set to 1.0f
|
---|
| 305 | viewCell->GetPvs().AddSample(obj, 1.0f);
|
---|
[508] | 306 | }
|
---|
| 307 | else
|
---|
| 308 | {
|
---|
| 309 | Debug << "error: object does not exist" << endl;
|
---|
| 310 | }
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | else if (attrName == "id")
|
---|
| 314 | {
|
---|
| 315 | StrX attrValue(attributes.getValue(i));
|
---|
| 316 |
|
---|
| 317 | const char *ptr = attrValue.LocalForm();
|
---|
| 318 | char *endptr = NULL;
|
---|
| 319 | const int id = strtol(ptr, &endptr, 10);
|
---|
| 320 |
|
---|
| 321 | viewCell->SetId(id);
|
---|
| 322 | }
|
---|
[651] | 323 | else if (attrName == "active")
|
---|
| 324 | {
|
---|
| 325 | StrX attrValue(attributes.getValue(i));
|
---|
| 326 |
|
---|
| 327 | const char *ptr = attrValue.LocalForm();
|
---|
| 328 | char *endptr = NULL;
|
---|
| 329 | const bool isActive = (bool)strtol(ptr, &endptr, 10);
|
---|
| 330 |
|
---|
| 331 | viewCell->mIsActive = isActive;
|
---|
| 332 | }
|
---|
| 333 | else if (attrName == "mergecost")
|
---|
| 334 | {
|
---|
| 335 | StrX attrValue(attributes.getValue(i));
|
---|
| 336 |
|
---|
| 337 | const char *ptr = attrValue.LocalForm();
|
---|
| 338 | char *endptr = NULL;
|
---|
| 339 | const float cost = (float)strtod(ptr, &endptr);
|
---|
| 340 |
|
---|
| 341 | viewCell->SetMergeCost(cost);
|
---|
| 342 | }
|
---|
[508] | 343 | }
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 |
|
---|
[577] | 347 | void ViewCellsParseHandlers::StartViewSpaceBox(AttributeList& attributes)
|
---|
| 348 | {
|
---|
| 349 | int len = attributes.getLength();
|
---|
| 350 |
|
---|
| 351 | Vector3 bmin, bmax;
|
---|
| 352 |
|
---|
| 353 | for (int i = 0; i < len; ++ i)
|
---|
| 354 | {
|
---|
| 355 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 356 | StrX attrValue(attributes.getValue(i));
|
---|
| 357 | const char *ptr = attrValue.LocalForm();
|
---|
| 358 |
|
---|
| 359 | if (attrName == "min")
|
---|
| 360 | {
|
---|
| 361 | sscanf(ptr, "%f %f %f",
|
---|
| 362 | &bmin.x, &bmin.y, &bmin.z);
|
---|
| 363 | }
|
---|
| 364 | else if (attrName == "max")
|
---|
| 365 | {
|
---|
| 366 | sscanf(ptr, "%f %f %f",
|
---|
| 367 | &bmax.x, &bmax.y, &bmax.z);
|
---|
| 368 | }
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | mViewSpaceBox = AxisAlignedBox3(bmin, bmax);
|
---|
| 372 |
|
---|
| 373 | Debug << "view space box: " << mViewSpaceBox << endl;
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 |
|
---|
[575] | 377 | void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes)
|
---|
[508] | 378 | {
|
---|
| 379 | BspLeaf * leaf =
|
---|
[590] | 380 | new BspLeaf(dynamic_cast<BspInterior *>(mCurrentBspNode), NULL);
|
---|
[508] | 381 |
|
---|
[590] | 382 | if (mCurrentBspNode) // replace front or (if not NULL) back child
|
---|
[508] | 383 | {
|
---|
[590] | 384 | dynamic_cast<BspInterior *>(mCurrentBspNode)->ReplaceChildLink(NULL, leaf);
|
---|
[508] | 385 | }
|
---|
| 386 | else
|
---|
| 387 | {
|
---|
[575] | 388 | if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
|
---|
[577] | 389 | {
|
---|
[575] | 390 | mBspTree->mRoot = leaf;
|
---|
[577] | 391 | }
|
---|
| 392 | else if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP)
|
---|
| 393 | {
|
---|
[575] | 394 | mVspBspTree->mRoot = leaf;
|
---|
[577] | 395 | }
|
---|
[508] | 396 | }
|
---|
| 397 |
|
---|
| 398 | //-- find associated view cell
|
---|
| 399 | int viewCellId;
|
---|
| 400 |
|
---|
| 401 | int len = attributes.getLength();
|
---|
| 402 |
|
---|
| 403 | for (int i = 0; i < len; ++ i)
|
---|
| 404 | {
|
---|
| 405 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 406 | StrX attrValue(attributes.getValue(i));
|
---|
| 407 |
|
---|
| 408 | const char *ptr = attrValue.LocalForm();
|
---|
| 409 | char *endptr = NULL;
|
---|
| 410 |
|
---|
| 411 | if (attrName == "viewCellId")
|
---|
| 412 | {
|
---|
| 413 | viewCellId = strtol(ptr, &endptr, 10);
|
---|
| 414 | }
|
---|
| 415 | }
|
---|
[654] | 416 |
|
---|
[590] | 417 |
|
---|
[508] | 418 | if (viewCellId >= 0) // valid view cell
|
---|
| 419 | {
|
---|
| 420 | // TODO: get view cell with specified id
|
---|
[590] | 421 | ViewCellInterior dummyVc;
|
---|
[508] | 422 | dummyVc.SetId(viewCellId);
|
---|
| 423 |
|
---|
| 424 | ViewCellContainer::iterator vit =
|
---|
| 425 | lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt);
|
---|
| 426 |
|
---|
[651] | 427 | BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit);
|
---|
[580] | 428 |
|
---|
[654] | 429 |
|
---|
[508] | 430 | if (viewCell->GetId() == viewCellId)
|
---|
| 431 | {
|
---|
[651] | 432 | leaf->SetViewCell(viewCell);
|
---|
| 433 | viewCell->mLeaf = leaf;
|
---|
[508] | 434 | }
|
---|
| 435 | else
|
---|
| 436 | {
|
---|
| 437 | Debug << "error: view cell does not exist" << endl;
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | else
|
---|
| 441 | {
|
---|
[575] | 442 | if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP)
|
---|
| 443 | {
|
---|
| 444 | leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell());
|
---|
| 445 | leaf->SetTreeValid(false);
|
---|
| 446 | mVspBspTree->PropagateUpValidity(leaf);
|
---|
| 447 | }
|
---|
[654] | 448 | }
|
---|
[508] | 449 | }
|
---|
| 450 |
|
---|
| 451 |
|
---|
[575] | 452 | void ViewCellsParseHandlers::StartBspInterior(AttributeList& attributes)
|
---|
[508] | 453 | {
|
---|
| 454 | Plane3 plane;
|
---|
| 455 | int len = attributes.getLength();
|
---|
| 456 |
|
---|
| 457 | for (int i = 0; i < len; ++ i)
|
---|
| 458 | {
|
---|
| 459 | string attrName(StrX(attributes.getName(i)).LocalForm());
|
---|
| 460 | StrX attrValue(attributes.getValue(i));
|
---|
| 461 | const char *ptr = attrValue.LocalForm();
|
---|
| 462 |
|
---|
| 463 | if (attrName == "plane")
|
---|
| 464 | {
|
---|
| 465 | sscanf(ptr, "%f %f %f %f",
|
---|
| 466 | &plane.mNormal.x, &plane.mNormal.y, &plane.mNormal.z, &plane.mD);
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | BspInterior* interior = new BspInterior(plane);
|
---|
| 471 |
|
---|
[590] | 472 | if (mCurrentBspNode) // replace NULL child of parent with current node
|
---|
[508] | 473 | {
|
---|
[590] | 474 | BspInterior *current = dynamic_cast<BspInterior *>(mCurrentBspNode);
|
---|
[508] | 475 |
|
---|
| 476 | current->ReplaceChildLink(NULL, interior);
|
---|
| 477 | interior->SetParent(current);
|
---|
| 478 | }
|
---|
| 479 | else
|
---|
| 480 | {
|
---|
[575] | 481 | if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
|
---|
[577] | 482 | {
|
---|
[575] | 483 | mBspTree->mRoot = interior;
|
---|
[577] | 484 | }
|
---|
[575] | 485 | else
|
---|
[577] | 486 | {
|
---|
[575] | 487 | mVspBspTree->mRoot = interior;
|
---|
[577] | 488 | }
|
---|
[508] | 489 | }
|
---|
| 490 |
|
---|
[590] | 491 | mCurrentBspNode = interior;
|
---|
[508] | 492 | }
|
---|
| 493 |
|
---|
| 494 |
|
---|
[651] | 495 | void ViewCellsParseHandlers::StartViewCellLeaf(AttributeList& attributes)
|
---|
| 496 | {
|
---|
| 497 | BspViewCell *viewCell = new BspViewCell();
|
---|
[575] | 498 |
|
---|
[651] | 499 | if (mCurrentViewCell) // replace front or (if not NULL) back child
|
---|
| 500 | {
|
---|
| 501 | ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(mCurrentViewCell);
|
---|
| 502 | interior->SetupChildLink(viewCell);
|
---|
| 503 | }
|
---|
| 504 | else // root
|
---|
| 505 | {
|
---|
| 506 | mViewCellsTree->SetRoot(viewCell);
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | StartViewCell(viewCell, attributes);
|
---|
| 510 |
|
---|
| 511 | // collect leaves
|
---|
| 512 | mViewCells.push_back(viewCell);
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 |
|
---|
| 516 | void ViewCellsParseHandlers::StartViewCellInterior(AttributeList& attributes)
|
---|
| 517 | {
|
---|
| 518 | ViewCellInterior* interior = new ViewCellInterior();
|
---|
| 519 |
|
---|
| 520 | if (mCurrentViewCell) // replace NULL child of parent with current node
|
---|
| 521 | {
|
---|
| 522 | ViewCellInterior *current = dynamic_cast<ViewCellInterior *>(mCurrentViewCell);
|
---|
| 523 |
|
---|
| 524 | current->SetupChildLink(interior);
|
---|
| 525 | }
|
---|
| 526 | else
|
---|
| 527 | {
|
---|
| 528 | mViewCellsTree->SetRoot(interior);
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | mCurrentViewCell = interior;
|
---|
| 532 |
|
---|
| 533 | StartViewCell(interior, attributes);
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 |
|
---|
| 537 |
|
---|
[575] | 538 | void ViewCellsParseHandlers::CreateViewCellsManager(const char *name)
|
---|
| 539 | {
|
---|
| 540 | if (strcmp(name, "bspTree") == 0)
|
---|
| 541 | {
|
---|
| 542 | Debug << "view cell type: Bsp" << endl;
|
---|
| 543 |
|
---|
[577] | 544 | mBspTree = new BspTree();
|
---|
[590] | 545 | mBspTree->mBox = mViewSpaceBox;
|
---|
[651] | 546 | //mCurrentBspNode = mBspTree->GetRoot();
|
---|
[575] | 547 |
|
---|
| 548 | mViewCellsManager = new BspViewCellsManager(mBspTree);
|
---|
| 549 | }
|
---|
| 550 | else if (strcmp(name, "vspBspTree") == 0)
|
---|
| 551 | {
|
---|
[577] | 552 | Debug << "view cell type: VspBsp" << endl;
|
---|
| 553 |
|
---|
[575] | 554 | mVspBspTree = new VspBspTree();
|
---|
[651] | 555 | //mCurrentBspNode = mVspBspTree->GetRoot();
|
---|
[575] | 556 |
|
---|
| 557 | mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
|
---|
[577] | 558 |
|
---|
[590] | 559 | mVspBspTree->mBox = mViewSpaceBox;
|
---|
[577] | 560 | Debug << "creating vsp bsp view cells manager" << endl;
|
---|
[575] | 561 | }
|
---|
[590] | 562 | else if (strcmp(name, "vspKdTree") == 0)
|
---|
[575] | 563 | {
|
---|
[590] | 564 | // TODO
|
---|
| 565 | mVspKdTree = new VspKdTree();
|
---|
| 566 | mViewCellsManager = new VspKdViewCellsManager(mVspKdTree);
|
---|
| 567 | }
|
---|
[575] | 568 | else
|
---|
| 569 | {
|
---|
| 570 | cerr<<"Wrong view cells type" << name << endl;
|
---|
| 571 | exit(1);
|
---|
| 572 | }
|
---|
[577] | 573 |
|
---|
[651] | 574 | mViewCellsTree = mViewCellsManager->GetViewCellsTree();
|
---|
[577] | 575 | mViewCellsManager->SetViewSpaceBox(mViewSpaceBox);
|
---|
[575] | 576 | }
|
---|
| 577 |
|
---|
| 578 |
|
---|
[508] | 579 | void ViewCellsParseHandlers::characters(const XMLCh* const chars,
|
---|
| 580 | const unsigned int length)
|
---|
| 581 | {
|
---|
| 582 | mCharacterCount += length;
|
---|
| 583 | }
|
---|
| 584 |
|
---|
| 585 |
|
---|
| 586 | void ViewCellsParseHandlers::ignorableWhitespace(const XMLCh* const chars,
|
---|
| 587 | const unsigned int length)
|
---|
| 588 | {
|
---|
| 589 | mSpaceCount += length;
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 |
|
---|
| 593 | void ViewCellsParseHandlers::resetDocument()
|
---|
| 594 | {
|
---|
| 595 | mAttrCount = 0;
|
---|
| 596 | mCharacterCount = 0;
|
---|
| 597 | mElementCount = 0;
|
---|
| 598 | mSpaceCount = 0;
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 |
|
---|
| 602 | // ---------------------------------------------------------------------------
|
---|
| 603 | // StdInParseHandlers: Overrides of the SAX ErrorHandler interface
|
---|
| 604 | // ---------------------------------------------------------------------------
|
---|
| 605 | void
|
---|
| 606 | ViewCellsParseHandlers::error(const SAXParseException& e)
|
---|
| 607 | {
|
---|
| 608 | XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId())
|
---|
| 609 | << ", line " << e.getLineNumber()
|
---|
| 610 | << ", char " << e.getColumnNumber()
|
---|
| 611 | << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | void
|
---|
| 615 | ViewCellsParseHandlers::fatalError(const SAXParseException& e)
|
---|
| 616 | {
|
---|
| 617 | XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId())
|
---|
| 618 | << ", line " << e.getLineNumber()
|
---|
| 619 | << ", char " << e.getColumnNumber()
|
---|
| 620 | << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | void
|
---|
| 624 | ViewCellsParseHandlers::warning(const SAXParseException& e)
|
---|
| 625 | {
|
---|
| 626 | XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId())
|
---|
| 627 | << ", line " << e.getLineNumber()
|
---|
| 628 | << ", char " << e.getColumnNumber()
|
---|
| 629 | << "): " << StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
| 630 | }
|
---|
| 631 |
|
---|
| 632 |
|
---|
| 633 | bool ViewCellsParser::ParseFile(const string filename,
|
---|
[575] | 634 | ViewCellsManager **viewCells,
|
---|
[508] | 635 | ObjectContainer *objects)
|
---|
| 636 | {
|
---|
| 637 | // Initialize the XML4C system
|
---|
| 638 | try {
|
---|
| 639 | XMLPlatformUtils::Initialize();
|
---|
| 640 | }
|
---|
| 641 |
|
---|
| 642 | catch (const XMLException& toCatch)
|
---|
| 643 | {
|
---|
| 644 | XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
|
---|
| 645 | << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
|
---|
| 646 | return false;
|
---|
| 647 | }
|
---|
| 648 |
|
---|
| 649 |
|
---|
| 650 | //
|
---|
| 651 | // Create a SAX parser object. Then, according to what we were told on
|
---|
| 652 | // the command line, set the options.
|
---|
| 653 | //
|
---|
| 654 | SAXParser* parser = new SAXParser;
|
---|
| 655 | parser->setValidationScheme(valScheme);
|
---|
| 656 | parser->setDoNamespaces(doNamespaces);
|
---|
| 657 | parser->setDoSchema(doSchema);
|
---|
| 658 | parser->setValidationSchemaFullChecking(schemaFullChecking);
|
---|
| 659 |
|
---|
| 660 |
|
---|
| 661 | //
|
---|
| 662 | // Create our SAX handler object and install it on the parser, as the
|
---|
| 663 | // document and error handler. We are responsible for cleaning them
|
---|
| 664 | // up, but since its just stack based here, there's nothing special
|
---|
| 665 | // to do.
|
---|
| 666 | //
|
---|
[577] | 667 | ViewCellsParseHandlers handler(objects);
|
---|
[508] | 668 | parser->setDocumentHandler(&handler);
|
---|
| 669 | parser->setErrorHandler(&handler);
|
---|
| 670 |
|
---|
| 671 | unsigned long duration;
|
---|
| 672 | int errorCount = 0;
|
---|
| 673 | // create a faux scope so that 'src' destructor is called before
|
---|
| 674 | // XMLPlatformUtils::Terminate
|
---|
| 675 | {
|
---|
| 676 | //
|
---|
| 677 | // Kick off the parse and catch any exceptions. Create a standard
|
---|
| 678 | // input input source and tell the parser to parse from that.
|
---|
| 679 | //
|
---|
| 680 | // StdInInputSource src;
|
---|
| 681 | try
|
---|
| 682 | {
|
---|
| 683 | const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
|
---|
| 684 | parser->parse(filename.c_str());
|
---|
| 685 | const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
|
---|
| 686 | duration = endMillis - startMillis;
|
---|
| 687 | errorCount = parser->getErrorCount();
|
---|
| 688 | }
|
---|
| 689 | catch (const OutOfMemoryException&)
|
---|
| 690 | {
|
---|
| 691 | XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
|
---|
| 692 | errorCount = 2;
|
---|
| 693 | return false;
|
---|
| 694 | }
|
---|
| 695 | catch (const XMLException& e)
|
---|
| 696 | {
|
---|
| 697 | XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n"
|
---|
| 698 | << StrX(e.getMessage())
|
---|
| 699 | << "\n" << XERCES_STD_QUALIFIER endl;
|
---|
| 700 | errorCount = 1;
|
---|
| 701 | return false;
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 |
|
---|
| 705 | // Print out the stats that we collected and time taken
|
---|
| 706 | if (!errorCount) {
|
---|
| 707 | XERCES_STD_QUALIFIER cout << filename << ": " << duration << " ms ("
|
---|
| 708 | << handler.GetElementCount() << " elems, "
|
---|
| 709 | << handler.GetAttrCount() << " attrs, "
|
---|
| 710 | << handler.GetSpaceCount() << " spaces, "
|
---|
| 711 | << handler.GetCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
|
---|
| 712 | }
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | //
|
---|
| 716 | // Delete the parser itself. Must be done prior to calling Terminate, below.
|
---|
| 717 | //
|
---|
| 718 | delete parser;
|
---|
| 719 |
|
---|
| 720 | XMLPlatformUtils::Terminate();
|
---|
| 721 |
|
---|
[577] | 722 | // assign new view cells manager
|
---|
| 723 | *viewCells = handler.mViewCellsManager;
|
---|
[651] | 724 |
|
---|
[508] | 725 | if (errorCount > 0)
|
---|
| 726 | return false;
|
---|
| 727 | else
|
---|
| 728 | return true;
|
---|
[556] | 729 | }
|
---|