Ignore:
Timestamp:
08/27/06 23:39:50 (18 years ago)
Author:
mattausch
Message:

implemented bv hierarchy

File:
1 edited

Legend:

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

    r1286 r1287  
    159159        if (mObjectSpaceHierarchyType == OSP) 
    160160        { 
     161                // for a spatial subdivision, it is not necessary to store 
     162                // the objects with the leaves, they can be classified now 
    161163                mHierarchyManager->mOspTree->InsertObjects( 
    162164                        mHierarchyManager->mOspTree->mRoot, *mObjects); 
    163165        } 
     166        else 
     167                cout << "here209" << endl; 
     168 
    164169} 
    165170 
     
    279284 
    280285 
    281 void ViewCellsParseHandlers::StartHierarchy(AttributeList&  attributes) 
    282 { 
    283         int len = attributes.getLength(); 
    284    
    285         for (int i = 0; i < len; ++ i)  
    286         { 
    287                 string attrName(StrX(attributes.getName(i)).LocalForm()); 
    288                  
    289                 if (attrName == "name")  
    290                 { 
    291                         StrX attrValue(attributes.getValue(i)); 
    292                          
    293                         const char *ptr = attrValue.LocalForm(); 
    294                          
    295                         // the view cells manager is created here 
    296                         //CreateViewCellsManager(ptr); 
    297                 } 
    298         } 
    299 } 
    300  
    301  
    302286void ViewCellsParseHandlers::StartBspElement(string element, 
    303287                                                                                         AttributeList& attributes) 
     
    437421                // create new view cells hierarchy 
    438422                mViewCellsTree = new ViewCellsTree(); 
    439         } 
    440  
    441         // decides about the view cells manager type 
    442         if (element == "Hierarchy") 
    443         { 
    444                 cout << "parsing view cells manager type" << endl; 
    445                 StartHierarchy(attributes); 
    446423        } 
    447424 
     
    688665                const char *ptr = attrValue.LocalForm(); 
    689666 
    690  
    691667                if (attrName == "id") 
    692668                { 
     
    711687void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes) 
    712688{ 
    713         BspLeaf * leaf =  
    714                 new BspLeaf(dynamic_cast<BspInterior *>(mCurrentBspNode), NULL); 
     689        BspLeaf * leaf; 
    715690 
    716691        if (mCurrentBspNode) // replace front or (if not NULL) back child 
    717692        { 
    718                 dynamic_cast<BspInterior *>(mCurrentBspNode)->ReplaceChildLink(NULL, leaf); 
     693                BspInterior *interior = dynamic_cast<BspInterior *>(mCurrentBspNode); 
     694 
     695                leaf = new BspLeaf(interior); 
     696                interior->ReplaceChildLink(NULL, leaf); 
    719697        } 
    720698        else 
    721699        { 
     700                leaf = new BspLeaf(); 
    722701                mVspBspTree->mRoot = leaf; 
    723702        } 
     
    797776        if (mCurrentBspNode) // replace NULL child of parent with current node 
    798777        { 
    799                 BspInterior *current = dynamic_cast<BspInterior *>(mCurrentBspNode); 
    800  
    801                 current->ReplaceChildLink(NULL, interior); 
    802                 interior->SetParent(current); 
     778                BspInterior *parent = dynamic_cast<BspInterior *>(mCurrentBspNode); 
     779 
     780                parent->ReplaceChildLink(NULL, interior); 
     781                interior->SetParent(parent); 
    803782        } 
    804783        else 
     
    856835void ViewCellsParseHandlers::CreateViewSpaceHierarchy() 
    857836{ 
    858         ViewCellContainer::iterator it, it_end = mViewCells.end(); 
    859         cout << "\n====================" << endl << endl; 
    860         for (it = mViewCells.begin(); it != it_end; ++ it) 
    861         { 
    862                 cout << (*it)->GetId() << " "; 
    863         } 
    864 cout << endl; 
    865837        if (mViewSpaceHierarchyType == BSP) 
    866838        { 
     
    936908                } 
    937909        } 
    938         cout << "************************" << endl; 
    939         it_end = mViewCells.end(); 
    940         for (it = mViewCells.begin(); it != it_end; ++ it) 
    941         { 
    942                 cout << (*it)->GetId() << " "; 
    943         } 
    944         cout << endl; 
    945         cout << "\nview space box: " << mViewSpaceBox << endl; 
     910        //cout << "\nview space box: " << mViewSpaceBox << endl; 
    946911} 
    947912 
     
    992957void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes) 
    993958{ 
    994         VspLeaf * leaf =  
    995                 new VspLeaf(dynamic_cast<VspInterior *>(mCurrentVspNode), NULL); 
    996  
     959        VspLeaf * leaf; 
     960                 
    997961        if (mCurrentVspNode) // replace front or (if not NULL) back child 
    998962        { 
    999                 dynamic_cast<VspInterior *>(mCurrentVspNode)->ReplaceChildLink(NULL, leaf); 
     963                VspInterior *interior = dynamic_cast<VspInterior *>(mCurrentVspNode); 
     964                leaf = new VspLeaf(interior); 
     965                interior->ReplaceChildLink(NULL, leaf); 
    1000966        } 
    1001967        else 
    1002968        { 
     969                leaf = new VspLeaf(); 
    1003970                mVspTree->mRoot = leaf; 
    1004971        } 
     
    1029996                dummyVc.SetId(viewCellId); 
    1030997 
    1031                 cout << "\nsearching view cell with id " << viewCellId << endl; 
     998                //cout << "\nsearching view cell with id " << viewCellId << endl; 
    1032999 
    10331000                ViewCellContainer::iterator vit = 
     
    10871054                AxisAlignedBox3 frontBox, backBox; 
    10881055 
    1089                 parent->GetBoundingBox().Split(parent->GetPlane().mAxis, parent->GetPlane().mPosition, frontBox, backBox); 
     1056                parent->GetBoundingBox().Split( 
     1057                        parent->GetPlane().mAxis,  
     1058                        parent->GetPlane().mPosition,  
     1059                        frontBox,  
     1060                        backBox); 
     1061 
    10901062                if (parent->GetFront() == interior) 
    10911063                        interior->SetBoundingBox(frontBox); 
     
    11341106 
    11351107                parent->mBox.Split(parent->mAxis, parent->mPosition, frontBox, backBox); 
     1108 
    11361109                if (parent->mFront == interior) 
    11371110                        interior->mBox = frontBox; 
     
    11801153                if (attrName == "min")  
    11811154                { 
    1182                         sscanf(ptr, "%f %f %f", &minBox); 
     1155                        sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 
    11831156                } 
    11841157                if (attrName == "max")  
    11851158                { 
    1186                         sscanf(ptr, "%f %f %f", &maxBox); 
     1159                        sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 
    11871160                } 
    11881161                if (attrName == "objects") 
     
    11921165        } 
    11931166 
    1194         BvhLeaf * leaf =  
    1195                 new BvhLeaf(AxisAlignedBox3(minBox, maxBox),  
    1196                                         dynamic_cast<BvhInterior *>(mCurrentBvhNode), (int)objects.size()); 
     1167        AxisAlignedBox3 box = AxisAlignedBox3(minBox, maxBox); 
     1168 
     1169        BvhLeaf *leaf; 
     1170 
     1171        if (mCurrentBvhNode) // replace front or (if not NULL) back child 
     1172        { 
     1173                BvhInterior *interior = dynamic_cast<BvhInterior *>(mCurrentBvhNode); 
     1174                leaf = new BvhLeaf(box, interior, (int)objects.size()); 
     1175                interior->ReplaceChildLink(NULL, leaf); 
     1176        } 
     1177        else 
     1178        { 
     1179                leaf = new BvhLeaf(box, NULL, (int)objects.size()); 
     1180                mHierarchyManager->mBvHierarchy->mRoot = leaf; 
     1181        } 
    11971182 
    11981183        leaf->mObjects = objects; 
    1199  
    1200         if (mCurrentBvhNode) // replace front or (if not NULL) back child 
    1201         { 
    1202                 dynamic_cast<BvhInterior *>(mCurrentBvhNode)->ReplaceChildLink(NULL, leaf); 
    1203         } 
    1204         else 
    1205         { 
    1206                 mHierarchyManager->mBvHierarchy->mRoot = leaf; 
    1207         } 
    12081184} 
    12091185 
     
    12191195        { 
    12201196                const int index = strtol(ptr, &endptr, 10); 
    1221  
    12221197                if (ptr == endptr) break; 
    12231198 
    12241199                objIndices.push_back(index); 
    1225  
    12261200                ptr = endptr; 
    12271201        } 
     
    12391213 
    12401214                ObjectContainer::iterator oit = 
    1241                         lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt);       
     1215                        lower_bound(mObjects->begin(),  
     1216                                                mObjects->end(),  
     1217                                                (Intersectable *)&dummyInst,  
     1218                                                ilt);    
    12421219                                                         
    12431220                if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) 
     
    12601237        for (int i = 0; i < len; ++ i)  
    12611238        { 
     1239                cout << "here5" << endl; 
    12621240                string attrName(StrX(attributes.getName(i)).LocalForm()); 
    12631241                StrX attrValue(attributes.getValue(i)); 
     
    12651243 
    12661244                if (attrName == "min")  
    1267                 { 
    1268                         sscanf(ptr, "%f %f %f", &minBox); 
     1245                {cout << "here6" << endl; 
     1246                        sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 
    12691247                } 
    12701248                if (attrName == "max")  
    1271                 { 
    1272                         sscanf(ptr, "%f %f %f", &maxBox); 
     1249                {cout << "here7" << endl; 
     1250                        sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 
    12731251                } 
    12741252        } 
     
    12781256        if (mCurrentBvhNode) // replace NULL child of parent with current node 
    12791257        { 
     1258                cout << "here8" << endl; 
    12801259                BvhInterior *parent = dynamic_cast<BvhInterior *>(mCurrentBvhNode); 
    12811260                parent->ReplaceChildLink(NULL, interior); 
     
    12831262        } 
    12841263        else 
    1285         { 
    1286                 mBvHierarchy->mRoot = interior; 
    1287         } 
    1288  
     1264        {cout << "here18" << endl; 
     1265                mHierarchyManager->mBvHierarchy->mRoot = interior; 
     1266        } 
     1267cout << "here28" << endl; 
    12891268        mCurrentBvhNode = interior; 
    12901269} 
Note: See TracChangeset for help on using the changeset viewer.