Changeset 1201


Ignore:
Timestamp:
08/11/06 17:39:54 (18 years ago)
Author:
mattausch
Message:

added loader for osp trees

Location:
GTP/trunk/Lib/Vis/Preprocessing/src
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp

    r1197 r1201  
    11351135 
    11361136 
    1137  
    1138 void KdTree::ExportBinLeaf(ofstream &stream, KdLeaf *leaf) 
     1137void KdTree::ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf) 
    11391138{ 
    11401139        ObjectContainer::const_iterator it, it_end = leaf->mObjects.end(); 
     
    11571156 
    11581157 
    1159 KdLeaf *KdTree::ImportBinLeaf(ifstream &stream,  
     1158KdLeaf *KdTree::ImportBinLeaf(IN_STREAM &stream,  
    11601159                                                          KdInterior *parent, 
    11611160                                                          const ObjectContainer &objects) 
     
    11941193 
    11951194 
    1196 void KdTree::ExportBinInterior(ofstream &stream, KdInterior *interior) 
     1195void KdTree::ExportBinInterior(OUT_STREAM &stream, KdInterior *interior) 
    11971196{ 
    11981197        int interiorid = TYPE_INTERIOR; 
     
    12071206 
    12081207 
    1209 KdInterior *KdTree::ImportBinInterior(ifstream &stream, KdInterior *parent) 
     1208KdInterior *KdTree::ImportBinInterior(IN_STREAM &stream, KdInterior *parent) 
    12101209{ 
    12111210        KdInterior *interior = new KdInterior(parent); 
     
    12261225bool KdTree::ExportBinTree(const string &filename) 
    12271226{ 
    1228         ofstream stream(filename.c_str(), ios::binary); 
     1227        OUT_STREAM stream(filename.c_str(), OUT_BIN_MODE); 
    12291228         
    1230         if (!stream.is_open()) 
    1231                 return false; 
     1229        //if (!stream.is_open()) return false; 
    12321230 
    12331231        // export binary version of mesh 
     
    12611259 
    12621260 
    1263 KdNode *KdTree::LoadNextNode(ifstream &stream,  
     1261KdNode *KdTree::LoadNextNode(IN_STREAM &stream,  
    12641262                                                         KdInterior *parent, 
    12651263                                                         const ObjectContainer &objects) 
     
    12881286        // export binary version of mesh 
    12891287        queue<TraversalData> tStack; 
    1290         ifstream stream(filename.c_str(), ios::binary); 
    1291  
    1292         if (!stream.is_open()) 
    1293                 return false; 
     1288        IN_STREAM stream(filename.c_str(), IN_BIN_MODE); 
     1289 
     1290        //if (!stream.is_open()) return false; 
    12941291 
    12951292        std::stable_sort(objects.begin(), objects.end(), ilt); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h

    r1197 r1201  
    557557        void ProcessMultipleRefs(KdLeaf *leaf) const; 
    558558 
    559         void ExportBinLeaf(ofstream &stream, KdLeaf *leaf); 
    560         void ExportBinInterior(ofstream &stream, KdInterior *interior); 
    561         KdLeaf *ImportBinLeaf(ifstream &stream, KdInterior *parent, const ObjectContainer &objects); 
    562         KdInterior *ImportBinInterior(ifstream &stream, KdInterior *parent); 
    563         KdNode *LoadNextNode(ifstream &stream, KdInterior *parent, const ObjectContainer &objects); 
     559        void ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf); 
     560        void ExportBinInterior(OUT_STREAM &stream, KdInterior *interior); 
     561        KdLeaf *ImportBinLeaf(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 
     562        KdInterior *ImportBinInterior(IN_STREAM &stream, KdInterior *parent); 
     563        KdNode *LoadNextNode(IN_STREAM &stream, KdInterior *parent, const ObjectContainer &objects); 
    564564 
    565565  int mTermMaxNodes; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp

    r1199 r1201  
    323323  mSceneGraph->CollectObjects(&root->mObjects); 
    324324   
     325  long startTime = GetTime(); 
     326 
     327  cout << "building kd tree ... " << endl; 
    325328  mKdTree->Construct(); 
     329  cout << "construction finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs " << endl; 
    326330  return true; 
    327331} 
  • GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp

    r1166 r1201  
    2424        Vector3 normal; 
    2525           
    26         const int i = RandomValue(0, (int)mPreprocessor.mObjects.size() - 1); 
     26        const int i = RandomValue(0, float((int)mPreprocessor.mObjects.size() - 1)); 
    2727 
    2828        Intersectable *object = mPreprocessor.mObjects[i]; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp

    r1199 r1201  
    21822182 
    21832183 
    2184 #if ZIPPED_VIEWCELLS 
    2185 bool ViewCellsTree::Export(ogzstream &stream, const bool exportPvs) 
    2186 #else 
    2187 bool ViewCellsTree::Export(ofstream &stream, const bool exportPvs) 
    2188 #endif 
     2184bool ViewCellsTree::Export(OUT_STREAM &stream, const bool exportPvs) 
    21892185{ 
    21902186        // export recursivly all view cells from the root 
     
    22232219} 
    22242220 
    2225 #if ZIPPED_VIEWCELLS 
    2226 void ViewCellsTree::ExportPvs(ViewCell *viewCell, ogzstream &stream) 
    2227 #else 
    2228 void ViewCellsTree::ExportPvs(ViewCell *viewCell, ofstream &stream) 
    2229 #endif 
     2221 
     2222void ViewCellsTree::ExportPvs(ViewCell *viewCell, OUT_STREAM &stream) 
    22302223{ 
    22312224        ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end(); 
     
    22372230} 
    22382231 
    2239 #if ZIPPED_VIEWCELLS 
    2240 void ViewCellsTree::ExportViewCell(ViewCell *viewCell, ogzstream &stream, const bool exportPvs) 
    2241 #else 
    2242 void ViewCellsTree::ExportViewCell(ViewCell *viewCell, ofstream &stream, const bool exportPvs) 
    2243 #endif 
     2232 
     2233void ViewCellsTree::ExportViewCell(ViewCell *viewCell,  
     2234                                                                   OUT_STREAM &stream,  
     2235                                                                   const bool exportPvs) 
    22442236{ 
    22452237        if (viewCell->IsLeaf()) 
     
    22582250 
    22592251                stream << "\" />" << endl; 
    2260                 //stream << " </Leaf>" << endl; 
    22612252        } 
    22622253        else 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h

    r1168 r1201  
    487487        /** Exports view cells to file. 
    488488        */ 
    489 #if ZIPPED_VIEWCELLS 
    490         bool Export(ogzstream &stream, const bool exportPvs = false); 
    491 #else 
    492         bool Export(ofstream &stream, const bool exportPvs = false); 
    493 #endif 
     489        bool Export(OUT_STREAM &stream, const bool exportPvs = false); 
    494490 
    495491        /** Export statistics of this view cell tree. 
     
    603599                NOTE: should be in exporter!! 
    604600        */ 
    605 #if ZIPPED_VIEWCELLS 
    606         void ExportViewCell(ViewCell *viewCell, ogzstream &stream, const bool exportPvs); 
    607 #else 
    608         void ExportViewCell(ViewCell *viewCell, ofstream &stream, const bool exportPvs);         
    609 #endif 
     601        void ExportViewCell(ViewCell *viewCell, OUT_STREAM &stream, const bool exportPvs);       
    610602 
    611603        /** Exports pvs of a view cell. 
    612604        */ 
    613 #if ZIPPED_VIEWCELLS 
    614         void ExportPvs(ViewCell *viewCell, ogzstream &stream); 
    615 #else 
    616         void ExportPvs(ViewCell *viewCell, ofstream &stream); 
    617 #endif 
     605        void ExportPvs(ViewCell *viewCell, OUT_STREAM &stream); 
    618606 
    619607        int GetEntriesInPvsForCompressedStorage(ViewCell *vc) const; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r1199 r1201  
    716716        cout << "exporting view cells to xml ... "; 
    717717         
    718 #if ZIPPED_VIEWCELLS 
    719         ogzstream stream(filename.c_str()); 
    720 #else 
    721         std::ofstream stream(filename.c_str()); 
    722 #endif 
     718        OUT_STREAM stream(filename.c_str()); 
    723719 
    724720        // for output we need unique ids for each view cell 
     
    48974893        Debug << mOspTree->GetStatistics() << endl; 
    48984894 
     4895        OUT_STREAM stream("osptree.xml.zip"); 
     4896        mOspTree->Export(stream); 
     4897 
    48994898        // print view cell statistics 
    49004899        ResetViewCells(); 
     
    54565455        cout << "exporting view cells to xml ... "; 
    54575456         
    5458 #if ZIPPED_VIEWCELLS 
    5459         ogzstream stream(filename.c_str()); 
    5460 #else 
    5461         std::ofstream stream(filename.c_str()); 
    5462 #endif 
     5457        OUT_STREAM stream(filename.c_str()); 
    54635458 
    54645459        // for output we need unique ids for each view cell 
     
    54685463        stream << "<VisibilitySolution>" << endl; 
    54695464 
    5470         //-- the view space bounding box 
     5465        //-- export view space bounding box 
     5466         
    54715467        stream << "<ViewSpaceBox"  
    54725468                   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\"" 
     
    54755471         
    54765472        //-- export bounding boxes 
     5473 
    54775474        stream << "<BoundingBoxes>" << endl; 
    54785475 
     
    54945491 
    54955492        //-- export the view cells and the pvs 
    5496         stream << "<HierarchyType name=\"vspTree\" />" << endl; 
    5497  
     5493 
     5494        stream << "<Hierarchy name=\"vspTree\" />" << endl; 
    54985495        const int numViewCells = mCurrentViewCellsStats.viewCells; 
    54995496 
    55005497        stream << "<ViewCells number=\"" << numViewCells << "\" >" << endl; 
    5501          
    55025498        mViewCellsTree->Export(stream, exportPvs); 
    5503  
    55045499        stream << "</ViewCells>" << endl; 
    55055500 
    55065501 
    5507         //-- export the spatial hierarchy 
     5502        //-- export the view space hierarchy 
     5503         
     5504        // the type of the view space partition 
     5505        stream << "<ViewSpacePartition>" << endl; 
     5506        mVspTree->Export(stream); 
     5507        stream << endl << "</ViewSpacePartitioin>" << endl; 
     5508 
     5509         
     5510        //-- export the object space partition 
    55085511         
    55095512        // the type of the view cells hierarchy 
    5510         stream << "<Hierarchy>" << endl; 
    5511         mVspTree->Export(stream); 
    5512         stream << endl << "</Hierarchy>" << endl; 
     5513        stream << "<ObjectSpacePartition>" << endl; 
     5514        mOspTree->Export(stream); 
     5515        stream << endl << "</ObjectSpacePartition>" << endl; 
     5516 
    55135517 
    55145518        stream << "</VisibilitySolution>" << endl; 
    5515  
    5516  
    55175519        stream.close(); 
     5520         
    55185521        cout << "finished" << endl; 
    55195522 
     
    57285731} 
    57295732 
     5733 
     5734ViewCellsManager *VspOspViewCellsManager::LoadViewCells(const string &filename,  
     5735                                                                                                                ObjectContainer *objects, 
     5736                                                                                                                const bool finalizeViewCells, 
     5737                                                                                                                BoundingBoxConverter *bconverter) 
     5738                                                                                                  
     5739{ 
     5740        ViewCellsManager *vm =  
     5741                ViewCellsManager::LoadViewCells(filename, objects, finalizeViewCells, bconverter); 
     5742 
     5743        mOspTree->InsertObjects(mOspTree->GetRoot(), *objects); 
     5744 
     5745        return vm; 
     5746} 
     5747 
     5748 
    57305749#if TEST_EVALUATION 
    57315750void VspOspViewCellsManager::EvalViewCellPartition() 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r1184 r1201  
    10111011                                                                                        const bool storeViewCells); 
    10121012 
     1013        ViewCellsManager *LoadViewCells(const string &filename,  
     1014                ObjectContainer *objects, 
     1015                const bool finalizeViewCells, 
     1016                BoundingBoxConverter *bconverter); 
     1017 
     1018 
    10131019protected: 
    10141020 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp

    r1197 r1201  
    3131#include "GzFileInputSource.h" 
    3232#include "VspOspTree.h" 
     33#include "KdTree.h" 
     34 
    3335 
    3436 
     
    8183  , mBspTree(NULL) 
    8284  , mViewCellsTree(NULL) 
    83   , mParseViewCells(true) 
     85  , mCurrentTask(PARSE_OPTIONS) 
    8486  , mCurrentViewCell(NULL) 
    8587  , mCurrentBspNode(NULL) 
     88  , mCurrentVspNode(NULL) 
     89  , mCurrentKdNode(NULL) 
    8690  , mObjects(objects) 
    8791  , mBoundingBoxConverter(bconverter) 
     
    113117 
    114118  // inside the view cell description 
    115   if (mParseViewCells) 
     119  if (mCurrentTask == PARSE_VIEWCELLS) 
    116120  { 
    117121          if (element == "Interior") 
     
    136140 
    137141 
     142void ViewCellsParseHandlers::EndVspInterior() 
     143{ 
     144        // go one up in the tree 
     145        if (mCurrentVspNode->GetParent()) 
     146        {       Debug << "]"; 
     147                mCurrentVspNode = mCurrentVspNode->GetParent(); 
     148        } 
     149} 
     150 
    138151void ViewCellsParseHandlers::EndViewCellInterior() 
    139152{ 
     
    156169        // sort view cells to help associating view cells according to their id 
    157170        stable_sort(mViewCells.begin(), mViewCells.end(), vlt); 
    158         mParseViewCells = false; 
     171 
     172        // not parsing view cells anymore 
     173        mCurrentTask = PARSE_OPTIONS; 
    159174} 
    160175 
     
    195210 
    196211 
    197 void ViewCellsParseHandlers::startBspElement(string element, 
     212void ViewCellsParseHandlers::StartBspElement(string element, 
    198213                                                                                         AttributeList& attributes) 
    199214{ 
     
    212227 
    213228 
     229void ViewCellsParseHandlers::StartVspElement(string element, 
     230                                                                                         AttributeList& attributes) 
     231{ 
     232        if (element == "Interior")  
     233        { 
     234                Debug << "["; 
     235                StartVspInterior(attributes); 
     236        } 
     237 
     238        if (element == "Leaf")  
     239        { 
     240                Debug << "l"; 
     241                StartVspLeaf(attributes); 
     242        } 
     243} 
     244 
     245 
     246void ViewCellsParseHandlers::StartOspElement(string element, 
     247                                                                                         AttributeList& attributes) 
     248{ 
     249        if (element == "Interior")  
     250        { 
     251                Debug << "["; 
     252                StartOspInterior(attributes); 
     253        } 
     254 
     255        if (element == "Leaf")  
     256        { 
     257                Debug << "l"; 
     258                StartOspLeaf(attributes); 
     259        } 
     260} 
     261 
     262void ViewCellsParseHandlers::StartViewSpacePartitionElement(const std::string &element, 
     263                                                                                                                        AttributeList& attributes) 
     264{ 
     265        if (!mViewCellsManager) 
     266                return; 
     267 
     268        //-- use cell type according to the chosen view cell manager 
     269        switch (mViewCellsManager->GetType()) 
     270        { 
     271                case ViewCellsManager::BSP: 
     272                case ViewCellsManager::VSP_BSP: 
     273                        StartBspElement(element, attributes); 
     274                        break; 
     275                case ViewCellsManager::VSP_OSP: 
     276                        StartVspElement(element, attributes); 
     277                        break; 
     278                default: 
     279                        Debug << "not implemented" << endl; 
     280                        break; 
     281        } 
     282} 
     283 
     284 
     285void ViewCellsParseHandlers::StartObjectSpacePartitionElement(const std::string &element, 
     286                                                                                                                          AttributeList& attributes) 
     287{ 
     288        if (!mViewCellsManager) 
     289                return; 
     290 
     291        //-- use cell type according to the chosen view cell manager 
     292        switch (mViewCellsManager->GetType()) 
     293        { 
     294                case ViewCellsManager::VSP_OSP: 
     295                        StartOspElement(element, attributes); 
     296                        break; 
     297                default: 
     298                        Debug << "not implemented" << endl; 
     299                        break; 
     300        } 
     301} 
     302 
     303 
     304void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element, 
     305                                                                                                                   AttributeList& attributes) 
     306{ 
     307        // interiors + leaves interpreted view cells else 
     308        if (element == "Interior")  
     309        { 
     310                Debug << "["; 
     311                StartViewCellInterior(attributes); 
     312        } 
     313 
     314        if (element == "Leaf")  
     315        { 
     316                Debug << "l"; 
     317                StartViewCellLeaf(attributes); 
     318        } 
     319} 
     320 
     321 
    214322void ViewCellsParseHandlers::startElement(const XMLCh* const name, 
    215323                                                                                  AttributeList& attributes) 
     
    218326        string element(lname.LocalForm()); 
    219327 
    220  
    221328        if (element == "ViewCells") 
    222329        { 
    223                 Debug << "parsing view cells" << endl; 
    224                 mParseViewCells = true; 
     330                cout << "parsing view cells" << endl; 
     331                mCurrentTask = PARSE_VIEWCELLS; 
     332        } 
     333 
     334        // decides about the view cells manager type 
     335        if (element == "Hierarchy") 
     336        { 
     337                cout << "parsing view cells manager type" << endl; 
     338                StartHierarchy(attributes); 
    225339        } 
    226340 
    227341        // decides about the view cell hierarchy 
    228         if (element == "HierarchyType") 
    229         //if (element == "Hierarchy") 
    230         { 
    231                 //Debug << "parsing spatial hierarchy" << endl; 
    232                 //mParseViewCells = false; 
    233                 StartHierarchy(attributes); 
     342        if (element == "ViewSpacePartition") 
     343        { 
     344                //StartViewSpacePartition(attributes); 
     345                cout << "parsing view space partition" << endl; 
     346                mCurrentTask = PARSE_VSP; 
     347        } 
     348 
     349        // decides about the view cell hierarchy 
     350        if (element == "ObjectSpacePartition") 
     351        { 
     352                //StartObjectSpacePartition(attributes); 
     353                cout << "parsing object space partition" << endl; 
     354                mCurrentTask = PARSE_OSP; 
    234355        } 
    235356         
     
    248369        } 
    249370 
    250          
    251         if (!mParseViewCells) 
    252         { 
    253                 //-- use different methods for the given view cell hierarchy types 
    254                 if (mViewCellsManager) 
    255                 { 
    256                         switch (mViewCellsManager->GetType()) 
    257                         { 
    258                         case ViewCellsManager::BSP: 
    259                         case ViewCellsManager::VSP_BSP: 
    260                                 startBspElement(element, attributes); 
    261                                 break; 
    262          
    263                         default: 
    264                                 Debug << "not implemented" << endl; 
    265                                 break; 
    266                         } 
    267                 } 
    268         } 
    269         else 
    270         { 
    271                 // interiors + leaves interpreted view cells else 
    272                 if (element == "Interior")  
    273                 { 
    274                         Debug << "["; 
    275                         StartViewCellInterior(attributes); 
    276                 } 
    277  
    278                 if (element == "Leaf")  
    279                 { 
    280                         Debug << "l"; 
    281                         StartViewCellLeaf(attributes); 
    282                 } 
    283         } 
    284  
     371        // parse view space partition 
     372        switch (mCurrentTask) 
     373        { 
     374        case PARSE_VSP: 
     375                StartViewSpacePartitionElement(element, attributes); 
     376                break; 
     377        case PARSE_OSP: 
     378                StartObjectSpacePartitionElement(element, attributes); 
     379                break; 
     380        case PARSE_VIEWCELLS: 
     381                StartViewCellHierarchyElement(element, attributes); 
     382                break; 
     383        default: 
     384                break; 
     385        } 
     386         
    285387        ++ mElementCount; 
    286388        mAttrCount += attributes.getLength(); 
     
    673775 
    674776 
     777void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes) 
     778{ 
     779        VspLeaf * leaf =  
     780                new VspLeaf(dynamic_cast<VspInterior *>(mCurrentVspNode), NULL); 
     781 
     782        if (mCurrentVspNode) // replace front or (if not NULL) back child 
     783        { 
     784                dynamic_cast<VspInterior *>(mCurrentVspNode)->ReplaceChildLink(NULL, leaf); 
     785        } 
     786        else 
     787        { 
     788                mVspTree->mRoot = leaf; 
     789        } 
     790 
     791        //-- find associated view cell 
     792        int viewCellId; 
     793         
     794        int len = attributes.getLength(); 
     795           
     796        for (int i = 0; i < len; ++ i)  
     797        { 
     798                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     799                StrX attrValue(attributes.getValue(i)); 
     800 
     801                const char *ptr = attrValue.LocalForm(); 
     802                char *endptr = NULL; 
     803 
     804                if (attrName == "viewCellId")  
     805                { 
     806                        viewCellId = strtol(ptr, &endptr, 10); 
     807                } 
     808        } 
     809         
     810        if (viewCellId >= 0) // valid view cell 
     811        { 
     812                // TODO: get view cell with specified id 
     813                ViewCellInterior dummyVc; 
     814                dummyVc.SetId(viewCellId); 
     815 
     816                ViewCellContainer::iterator vit = 
     817                        lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt); 
     818                         
     819                VspViewCell *viewCell = dynamic_cast<VspViewCell *>(*vit); 
     820         
     821                if (viewCell->GetId() == viewCellId) 
     822                { 
     823                        leaf->SetViewCell(viewCell); 
     824                        viewCell->mLeaf = leaf; 
     825                } 
     826                else 
     827                { 
     828                        Debug << "error: view cell does not exist" << endl; 
     829                } 
     830        } 
     831        else 
     832        { 
     833                // add to invalid view space 
     834                leaf->SetViewCell(mVspTree->GetOrCreateOutOfBoundsCell()); 
     835                leaf->SetTreeValid(false); 
     836                mVspTree->PropagateUpValidity(leaf); 
     837        } 
     838} 
     839 
     840 
     841void ViewCellsParseHandlers::StartVspInterior(AttributeList& attributes) 
     842{ 
     843        AxisAlignedPlane plane; 
     844        int len = attributes.getLength(); 
     845 
     846        for (int i = 0; i < len; ++ i)  
     847        { 
     848                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     849                StrX attrValue(attributes.getValue(i)); 
     850                const char *ptr = attrValue.LocalForm(); 
     851 
     852                if (attrName == "plane")  
     853                { 
     854                        sscanf(ptr, "%d %f", 
     855                                   &plane.mAxis, &plane.mPosition); 
     856                } 
     857        } 
     858 
     859        VspInterior* interior = new VspInterior(plane); 
     860         
     861        if (mCurrentVspNode) // replace NULL child of parent with current node 
     862        { 
     863                VspInterior *current = dynamic_cast<VspInterior *>(mCurrentVspNode); 
     864 
     865                current->ReplaceChildLink(NULL, interior); 
     866                interior->SetParent(current); 
     867        } 
     868        else 
     869        { 
     870                mVspTree->mRoot = interior; 
     871        } 
     872 
     873        mCurrentVspNode = interior; 
     874} 
     875 
     876 
     877void ViewCellsParseHandlers::StartOspInterior(AttributeList& attributes) 
     878{ 
     879        AxisAlignedPlane plane; 
     880        int len = attributes.getLength(); 
     881 
     882        for (int i = 0; i < len; ++ i)  
     883        { 
     884                string attrName(StrX(attributes.getName(i)).LocalForm()); 
     885                StrX attrValue(attributes.getValue(i)); 
     886                const char *ptr = attrValue.LocalForm(); 
     887 
     888                if (attrName == "plane")  
     889                { 
     890                        sscanf(ptr, "%d %f", 
     891                                   &plane.mAxis, &plane.mPosition); 
     892                } 
     893        } 
     894 
     895        KdInterior* interior = new KdInterior(NULL); 
     896         
     897        interior->mAxis = plane.mAxis; 
     898        interior->mPosition = plane.mPosition; 
     899 
     900        if (mCurrentKdNode) // replace NULL child of parent with current node 
     901        { 
     902                KdInterior *parent = dynamic_cast<KdInterior *>(mCurrentKdNode); 
     903                parent->ReplaceChildLink(NULL, interior); 
     904                interior->mParent = parent; 
     905        } 
     906        else 
     907        { 
     908                mOspTree->mRoot = interior; 
     909        } 
     910 
     911        mCurrentKdNode = interior; 
     912} 
     913 
     914 
     915void ViewCellsParseHandlers::StartOspLeaf(AttributeList& attributes) 
     916{ 
     917        KdLeaf * leaf =  
     918                new KdLeaf(dynamic_cast<KdInterior *>(mCurrentKdNode), NULL); 
     919 
     920        if (mCurrentKdNode) // replace front or (if not NULL) back child 
     921        { 
     922                dynamic_cast<KdInterior *>(mCurrentKdNode)->ReplaceChildLink(NULL, leaf); 
     923        } 
     924        else 
     925        { 
     926                mOspTree->mRoot = leaf; 
     927        } 
     928} 
     929 
     930 
     931 
     932 
    675933// --------------------------------------------------------------------------- 
    676934//  StdInParseHandlers: Overrides of the SAX ErrorHandler interface 
    677935// --------------------------------------------------------------------------- 
     936 
     937 
    678938void 
    679939ViewCellsParseHandlers::error(const SAXParseException& e) 
     
    7551015      { 
    7561016        const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis(); 
    757 #if ZIPPED_VIEWCELLS 
     1017#if USE_GZLIB 
    7581018        XMLCh *myFilePath = XMLString::transcode(filename.c_str()); 
    7591019         
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h

    r1022 r1201  
    88#include "Mesh.h" 
    99#include "BoundingBoxConverter.h" 
    10 //#include "gzstream.h" 
     10 
    1111 
    1212namespace GtpVisibilityPreprocessor { 
     
    2323class VspTree; 
    2424class OspTree; 
    25  
     25class VspNode; 
    2626 
    2727 
     
    8080 
    8181  BspNode *mCurrentBspNode; 
     82  VspNode *mCurrentVspNode; 
    8283  ViewCell *mCurrentViewCell; 
     84  KdNode *mCurrentKdNode; 
    8385 
    8486  ViewCellContainer mViewCells; 
     
    8688  ObjectContainer *mObjects; 
    8789  BoundingBoxConverter *mBoundingBoxConverter; 
    88  
    8990  AxisAlignedBox3 mViewSpaceBox; 
    90  
    9191  IndexedBoundingBoxContainer mIBoundingBoxes; 
    9292  
    93   bool mParseViewCells; 
     93  /// current task for the parser 
     94  int mCurrentTask; 
     95 
     96  enum {PARSE_OPTIONS, PARSE_VIEWCELLS, PARSE_VSP, PARSE_OSP}; 
    9497 
    9598  // Handlers for X3D 
     
    97100  void StartBspInterior(AttributeList& attributes); 
    98101  void EndBspInterior(); 
    99   
     102 
     103  void StartVspLeaf(AttributeList& attributes); 
     104  void StartVspInterior(AttributeList& attributes); 
     105  void EndVspInterior(); 
     106 
    100107  void StartViewCell(ViewCell *viewCell, AttributeList&  attributes); 
    101108  void EndViewCells(); 
     
    104111  void StartHierarchy(AttributeList& attributes); 
    105112 
    106   void startBspElement(string element, AttributeList& attributes); 
     113  void StartBspElement(string element, AttributeList& attributes); 
     114  void StartVspElement(string element, AttributeList& attributes); 
     115 
    107116  void StartViewSpaceBox(AttributeList&  attributes); 
    108117 
     
    111120  void StartViewCellInterior(AttributeList& attributes); 
    112121  void EndViewCellInterior(); 
     122 
     123  void StartViewSpacePartitionElement(const std::string &element, AttributeList& attributes); 
     124  void StartObjectSpacePartitionElement(const std::string &element, AttributeList& attributes); 
     125  void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes); 
     126 
     127  void StartOspElement(string element, AttributeList& attributes); 
     128 
     129  void StartOspLeaf(AttributeList& attributes); 
     130  void StartOspInterior(AttributeList& attributes); 
    113131 
    114132 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r1193 r1201  
    40024002} 
    40034003 
    4004 #if ZIPPED_VIEWCELLS 
    4005 bool VspBspTree::Export(ogzstream &stream) 
    4006 #else 
    4007 bool VspBspTree::Export(ofstream &stream) 
    4008 #endif 
     4004 
     4005bool VspBspTree::Export(OUT_STREAM &stream) 
    40094006{ 
    40104007        ExportNode(mRoot, stream); 
     
    40134010} 
    40144011 
    4015 #if ZIPPED_VIEWCELLS 
    4016 void VspBspTree::ExportNode(BspNode *node, ogzstream &stream) 
    4017 #else 
    4018 void VspBspTree::ExportNode(BspNode *node, ofstream &stream) 
    4019 #endif 
     4012 
     4013void VspBspTree::ExportNode(BspNode *node, OUT_STREAM &stream) 
    40204014{ 
    40214015        if (node->IsLeaf()) 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h

    r1145 r1201  
    321321        /** Writes tree to output stream 
    322322        */ 
    323 #if ZIPPED_VIEWCELLS 
    324         bool Export(ogzstream &stream); 
    325 #else 
    326         bool Export(ofstream &stream); 
    327 #endif 
     323        bool Export(OUT_STREAM &stream); 
    328324 
    329325        /** Casts beam, i.e. a 5D frustum of rays, into tree. 
     
    697693                @note: should be implemented as visitor. 
    698694        */ 
    699 #if ZIPPED_VIEWCELLS 
    700         void ExportNode(BspNode *node, ogzstream &stream); 
    701 #else 
    702         void ExportNode(BspNode *node, ofstream &stream); 
    703 #endif 
     695        void ExportNode(BspNode *node, OUT_STREAM &stream); 
    704696 
    705697        /** Returns estimated memory usage of tree. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp

    r1196 r1201  
    27022702} 
    27032703 
    2704 #if ZIPPED_VIEWCELLS 
    2705 bool VspTree::Export(ogzstream &stream) 
    2706 #else 
    2707 bool VspTree::Export(ofstream &stream) 
    2708 #endif 
     2704 
     2705bool VspTree::Export(OUT_STREAM &stream) 
    27092706{ 
    27102707        ExportNode(mRoot, stream); 
     
    27142711 
    27152712 
    2716 #if ZIPPED_VIEWCELLS 
    2717 void VspTree::ExportNode(VspNode *node, ogzstream &stream) 
    2718 #else 
    2719 void VspTree::ExportNode(VspNode *node, ofstream &stream) 
    2720 #endif 
     2713void VspTree::ExportNode(VspNode *node, OUT_STREAM &stream) 
    27212714{ 
    27222715        if (node->IsLeaf()) 
     
    54165409 
    54175410 
     5411bool OspTree::Export(OUT_STREAM &stream) 
     5412{ 
     5413        ExportNode(mRoot, stream); 
     5414 
     5415        return true; 
     5416} 
     5417 
     5418 
     5419void OspTree::ExportNode(KdNode *node, OUT_STREAM &stream) 
     5420{ 
     5421        if (node->IsLeaf()) 
     5422        { 
     5423                KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 
     5424 
     5425                stream << "<Leaf "; 
     5426                stream << "objects=\""; 
     5427                 
     5428                //-- export objects in kd leaves 
     5429                //if (mExportObjects) ExportObjects(leaf, stream); 
     5430                 
     5431                stream << "\" />" << endl; 
     5432                //stream << " </Leaf>" << endl; 
     5433        } 
     5434        else 
     5435        {        
     5436                KdInterior *interior = dynamic_cast<KdInterior *>(node); 
     5437         
     5438                stream << "<Interior plane=\"" << interior->mPosition << " "  
     5439                           << interior->mAxis << "\">" << endl; 
     5440 
     5441                ExportNode(interior->mBack, stream); 
     5442                ExportNode(interior->mFront, stream); 
     5443 
     5444                stream << "</Interior>" << endl; 
     5445        } 
     5446} 
     5447 
     5448 
     5449struct KdObjectsTraversalData 
     5450{ 
     5451        KdNode *node; 
     5452        ObjectContainer *objects; 
     5453}; 
     5454 
     5455 
     5456void OspTree::InsertObjects(KdNode *node, const ObjectContainer &objects) 
     5457{ 
     5458        stack<KdObjectsTraversalData> tStack; 
     5459 
     5460        while (!tStack.empty()) 
     5461        { 
     5462                KdObjectsTraversalData tData = tStack.top(); 
     5463        tStack.pop(); 
     5464 
     5465                KdNode *node = tData.node; 
     5466                 
     5467                if (node->IsLeaf()) 
     5468                { 
     5469                        KdLeaf *leaf = dynamic_cast<KdLeaf *>(node); 
     5470 
     5471                        ObjectContainer::const_iterator oit, oit_end = tData.objects->end(); 
     5472 
     5473                        for (oit = tData.objects->begin(); oit != oit_end; ++ oit) 
     5474                        { 
     5475                                leaf->mObjects.push_back(*oit); 
     5476                        } 
     5477                } 
     5478                else // interior 
     5479                { 
     5480                        KdObjectsTraversalData frontData, backData; 
     5481                        KdInterior *interior = dynamic_cast<KdInterior *>(node); 
     5482 
     5483                        frontData.objects = new ObjectContainer(); 
     5484                        backData.objects = new ObjectContainer(); 
     5485 
     5486                        ObjectContainer::const_iterator oit, oit_end = tData.objects->end(); 
     5487                         
     5488                    for (oit = tData.objects->begin(); oit != oit_end; ++ oit)  
     5489                        { 
     5490                                Intersectable *object = *oit; 
     5491                 
     5492                                // determine the side of this ray with respect to the plane 
     5493                                const AxisAlignedBox3 box = object->GetBox(); 
     5494 
     5495                                if (box.Max(interior->mAxis) >= interior->mPosition) 
     5496                                { 
     5497                                        frontData.objects->push_back(object); 
     5498                                } 
     5499 
     5500                                if (box.Min(interior->mAxis) < interior->mPosition) 
     5501                                { 
     5502                                        backData.objects->push_back(object); 
     5503                                } 
     5504                        } 
     5505 
     5506                        tStack.push(backData); 
     5507                        tStack.push(frontData); 
     5508                } 
     5509 
     5510                DEL_PTR(tData.objects); 
     5511        } 
     5512} 
     5513 
    54185514 
    54195515/*******************************************************************/ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h

    r1189 r1201  
    733733        /** Writes tree to output stream 
    734734        */ 
    735 #if ZIPPED_VIEWCELLS 
    736         bool Export(ogzstream &stream); 
    737 #else 
    738         bool Export(ofstream &stream); 
    739 #endif 
     735        bool Export(OUT_STREAM &stream); 
    740736 
    741737        /** Casts beam, i.e. a 5D frustum of rays, into tree. 
     
    10331029                @note: should be implemented as visitor. 
    10341030        */ 
    1035 #if ZIPPED_VIEWCELLS 
    1036         void ExportNode(VspNode *node, ogzstream &stream); 
    1037 #else 
    1038         void ExportNode(VspNode *node, ofstream &stream); 
    1039 #endif 
     1031        void ExportNode(VspNode *node, OUT_STREAM &stream); 
    10401032 
    10411033        /** Returns estimated memory usage of tree. 
     
    13351327        void CollectLeaves(vector<KdLeaf *> &leaves) const; 
    13361328 
    1337  
    13381329        /** Returns bounding box of the whole tree (= bbox of root node) 
    13391330        */ 
     
    13901381        /** Writes tree to output stream 
    13911382        */ 
    1392 #if ZIPPED_VIEWCELLS 
    1393         bool Export(ogzstream &stream); 
    1394 #else 
    1395         bool Export(ofstream &stream); 
    1396 #endif 
     1383        bool Export(OUT_STREAM &stream); 
    13971384 
    13981385        /** Returns or creates a new intersectable for use in a kd based pvs. 
     
    14231410        float EvalRenderCost(const VssRayContainer &myrays); 
    14241411        float EvalLeafCost(const OspTraversalData &tData); 
     1412 
     1413        /** Adds this objects to the kd leaf objects. 
     1414                @warning: Can corrupt the tree 
     1415        */ 
     1416        void InsertObjects(KdNode *node, const ObjectContainer &objects); 
    14251417 
    14261418protected: 
     
    16211613                @note: should be implemented as visitor. 
    16221614        */ 
    1623 #if ZIPPED_VIEWCELLS 
    1624         void ExportNode(KdNode *node, ogzstream &stream); 
    1625 #else 
    1626         void ExportNode(KdNode *node, ofstream &stream); 
    1627 #endif 
     1615        void ExportNode(KdNode *node, OUT_STREAM &stream); 
    16281616 
    16291617        /** Returns estimated memory usage of tree. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/common.h

    r1161 r1201  
    7575#define strncasecmp strnicmp 
    7676#endif // __WATCOMC__ 
     77 
     78// matt 
     79 
     80#define USE_GZLIB 1 
     81 
     82#if USE_GZLIB 
     83 
     84#define OUT_BIN_MODE ios::out 
     85#define IN_BIN_MODE ios::in 
     86 
     87#else 
    7788 
    7889#ifdef sgi 
     
    89100#endif // sgi 
    90101 
     102#endif 
    91103 
    92104//  #ifndef HAS_BOOL 
     
    483495} 
    484496 
    485 // if the view cells should be exported and inported as gzstream 
    486 #define ZIPPED_VIEWCELLS 1 
    487  
    488 #endif 
    489  
    490  
    491  
    492  
    493  
    494  
    495  
    496  
    497  
    498  
    499  
     497 
     498#if USE_GZLIB 
     499        // type of out put and input streams 
     500        #define OUT_STREAM ogzstream 
     501        #define IN_STREAM igzstream 
     502#else 
     503        #define OUT_STREAM ofstream 
     504        #define IN_STREAM ifstream 
     505#endif 
     506 
     507#endif 
     508 
     509 
     510 
     511 
     512 
     513 
     514 
     515 
     516 
     517 
  • GTP/trunk/Lib/Vis/Preprocessing/src/gzstream.h

    r372 r1201  
    9999  void close(); 
    100100  gzstreambuf* rdbuf() { return &buf; } 
     101  int is_open() { return buf.is_open(); } 
    101102}; 
    102103 
  • GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp

    r1199 r1201  
    164164        preprocessor->BuildKdTree(); 
    165165        preprocessor->KdTreeStatistics(cout); 
    166         preprocessor->mKdTree->ExportBinTree("kd.bin"); 
     166        preprocessor->mKdTree->ExportBinTree("kd.bin.gz"); 
    167167         
    168168        MeshManager::GetSingleton()->ExportEntries("meshes.bin"); 
    169169 
    170170        KdTree *kdTree2 = new KdTree; 
    171         kdTree2->LoadBinTree("kd.bin", preprocessor->mObjects); 
    172         Exporter *exporter = Exporter::GetExporter("testkd.x3d"); 
    173          
     171 
     172        cout << "loading kd tree ... "; 
     173        long startTime = GetTime(); 
     174        kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects); 
     175                 
     176        cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 
     177 
     178        Exporter *exporter = Exporter::GetExporter("testkd.x3d"); 
    174179        MeshManager::GetSingleton()->ExportEntries("meshes.bin"); 
    175180 
Note: See TracChangeset for help on using the changeset viewer.