source: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp @ 1715

Revision 1715, 35.0 KB checked in by bittner, 18 years ago (diff)

new visibility filter support

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