Ignore:
Timestamp:
03/09/06 04:27:07 (18 years ago)
Author:
mattausch
Message:

fixed a bsp node geometry problem (debug code)

File:
1 edited

Legend:

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

    r682 r683  
    23172317                        Plane3 halfSpace = dynamic_cast<BspInterior *>(interior)->GetPlane(); 
    23182318 
    2319             if (interior->GetFront() != lastNode) 
     2319            if (interior->GetBack() != lastNode) 
    23202320                                halfSpace.ReverseOrientation(); 
    23212321 
     
    23442344 
    23452345 
    2346 void BspTree::SetViewCellsManager(ViewCellsManager *vcm) 
    2347 { 
    2348         mViewCellsManager = vcm; 
    2349 } 
    2350  
    2351  
    2352 void BspTree::ConstructGeometry(BspNode *n, BspNodeGeometry &geom) const 
     2346void BspTree::ConstructGeometry(BspNode *n, 
     2347                                                                BspNodeGeometry &geom) const 
    23532348{ 
    23542349        vector<Plane3> halfSpaces; 
    23552350        ExtractHalfSpaces(n, halfSpaces); 
    23562351 
    2357         PolygonContainer candidates; 
     2352        PolygonContainer candidatePolys; 
    23582353        vector<Plane3> candidatePlanes; 
    23592354 
    2360         // bounded planes are added to the polygons (reverse polygons 
    2361         // as they have to be outfacing 
    2362         // comment: why is this? 
     2355        // bounded planes are added to the polygons 
    23632356        for (int i = 0; i < (int)halfSpaces.size(); ++ i) 
    23642357        { 
    23652358                Polygon3 *p = GetBoundingBox().CrossSection(halfSpaces[i]); 
    2366                  
     2359 
    23672360                if (p->Valid(mEpsilon)) 
    23682361                { 
    2369                         candidates.push_back(p->CreateReversePolygon()); 
    2370  
    2371                         Plane3 candidatePlane = p->GetSupportingPlane();//halfSpaces[i]; 
    2372                         //candidatePlane.ReverseOrientation(); 
    2373                         candidatePlanes.push_back(candidatePlane); 
    2374  
    2375                         DEL_PTR(p); 
     2362                        candidatePolys.push_back(p); 
     2363                        candidatePlanes.push_back(halfSpaces[i]); 
    23762364                } 
    23772365        } 
     
    23812369        { 
    23822370                VertexContainer vertices; 
    2383          
     2371 
    23842372                for (int j = 0; j < 4; ++ j) 
    23852373                        vertices.push_back(mBox.GetFace(i).mVertices[j]); 
    23862374 
    23872375                Polygon3 *poly = new Polygon3(vertices); 
    2388                 candidates.push_back(new Polygon3(vertices)); 
     2376 
     2377                candidatePolys.push_back(poly); 
    23892378                candidatePlanes.push_back(poly->GetSupportingPlane()); 
    23902379        } 
    23912380 
    2392  
    2393         for (int i = 0; i < (int)candidates.size(); ++ i) 
     2381        for (int i = 0; i < (int)candidatePolys.size(); ++ i) 
    23942382        { 
    23952383                // polygon is split by all other planes 
    2396                 for (int j = 0; (j < (int)halfSpaces.size()) && candidates[i]; ++ j) 
     2384                for (int j = 0; (j < (int)halfSpaces.size()) && candidatePolys[i]; ++ j) 
    23972385                { 
    23982386                        if (i == j) // polygon and plane are coincident 
     
    24022390                        Polygon3 *frontPoly, *backPoly; 
    24032391 
    2404                         const int cf = candidates[i]-> 
    2405                                 ClassifyPlane(halfSpaces[j], mEpsilon); 
    2406                          
     2392                        const int cf = 
     2393                                candidatePolys[i]->ClassifyPlane(halfSpaces[j], 
     2394                                                                                                 mEpsilon); 
     2395 
    24072396                        switch (cf) 
    24082397                        { 
     
    24112400                                        backPoly = new Polygon3(); 
    24122401 
    2413                                         candidates[i]->Split(halfSpaces[j],  
    2414                                                                                  *frontPoly,  
    2415                                                                                 *backPoly, 
    2416                                                                                 mEpsilon); 
    2417  
    2418                                         DEL_PTR(candidates[i]); 
     2402                                        candidatePolys[i]->Split(halfSpaces[j], 
     2403                                                                                         *frontPoly, 
     2404                                                                                        *backPoly, 
     2405                                                                                        mEpsilon); 
     2406 
     2407                                        DEL_PTR(candidatePolys[i]); 
    24192408 
    24202409                                        if (frontPoly->Valid(mEpsilon)) 
    2421                                                 candidates[i] = frontPoly; 
     2410                                                candidatePolys[i] = frontPoly; 
    24222411                                        else 
    24232412                                                DEL_PTR(frontPoly); 
     
    24252414                                        DEL_PTR(backPoly); 
    24262415                                        break; 
    2427                                 case Polygon3::BACK_SIDE: 
    2428                                         DEL_PTR(candidates[i]); 
     2416                                // polygon outside of halfspace 
     2417                                case Polygon3::FRONT_SIDE: 
     2418                                        DEL_PTR(candidatePolys[i]); 
    24292419                                        break; 
    24302420                                // just take polygon as it is 
    2431                                 case Polygon3::FRONT_SIDE: 
     2421                                case Polygon3::BACK_SIDE: 
    24322422                                case Polygon3::COINCIDENT: 
    24332423                                default: 
     
    24352425                        } 
    24362426                } 
    2437                  
    2438                 if (candidates[i]) 
    2439                 { 
    2440                         geom.Add(candidates[i], candidatePlanes[i]); 
    2441                 //      geom.mPolys.push_back(candidates[i]); 
    2442                 } 
    2443         } 
     2427 
     2428                if (candidatePolys[i]) 
     2429                { 
     2430                        geom.Add(candidatePolys[i], candidatePlanes[i]); 
     2431                        //      geom.mPolys.push_back(candidates[i]); 
     2432                } 
     2433        } 
     2434} 
     2435 
     2436 
     2437void BspTree::SetViewCellsManager(ViewCellsManager *vcm) 
     2438{ 
     2439        mViewCellsManager = vcm; 
    24442440} 
    24452441 
     
    24482444 
    24492445 
    2450 int BspTree::FindNeighbors(BspNode *n, vector<BspLeaf *> &neighbors, 
     2446int BspTree::FindNeighbors(BspNode *n, vector<BspLeaf *>  
     2447                                                   &neighbors, 
    24512448                                                   const bool onlyUnmailed) const 
    24522449{ 
     
    24942491                                                                                                        mEpsilon); 
    24952492 
    2496                                                 if (cf == Polygon3::BACK_SIDE) 
     2493                                                if (cf == Polygon3::FRONT_SIDE) 
    24972494                                                { 
    24982495                                                        isAdjacent = false; 
     
    25132510                                                                                                        mEpsilon); 
    25142511 
    2515                                                 if (cf == Polygon3::BACK_SIDE) 
     2512                                                if (cf == Polygon3::FRONT_SIDE) 
    25162513                                                { 
    25172514                                                        isAdjacent = false; 
     
    25442541                                                                interior->GetPlane(), 
    25452542                                                                mBox, 
     2543                                                                //0.0000001f); 
    25462544                                                                mEpsilon); 
    25472545                 
    2548                         if (cf == Polygon3::FRONT_SIDE) 
     2546                        if (cf == Polygon3::BACK_SIDE) 
    25492547                        { 
    2550                                 nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 
    2551                                 DEL_PTR(bGeom); 
     2548                                nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 
     2549                                DEL_PTR(fGeom); 
    25522550                        } 
    25532551                        else 
    25542552                        { 
    2555                                 if (cf == Polygon3::BACK_SIDE) 
     2553                                if (cf == Polygon3::FRONT_SIDE) 
    25562554                                { 
    2557                                         nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 
    2558                                         DEL_PTR(fGeom); 
     2555                                        nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 
     2556                                        DEL_PTR(bGeom); 
    25592557                                } 
    25602558                                else 
     
    25702568 
    25712569        return (int)neighbors.size(); 
    2572 } 
    2573  
    2574  
    2575 BspLeaf *BspTree::GetRandomLeaf(const Plane3 &halfspace) 
    2576 { 
    2577     stack<BspNode *> nodeStack; 
    2578         nodeStack.push(mRoot); 
    2579          
    2580         int mask = rand(); 
    2581    
    2582         while (!nodeStack.empty())  
    2583         { 
    2584                 BspNode *node = nodeStack.top(); 
    2585                 nodeStack.pop(); 
    2586            
    2587                 if (node->IsLeaf())  
    2588                 { 
    2589                         return dynamic_cast<BspLeaf *>(node); 
    2590                 }  
    2591                 else  
    2592                 { 
    2593                         BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    2594                         BspNode *next; 
    2595          
    2596                         BspNodeGeometry geom; 
    2597                         // todo: not very efficient: constructs full cell everytime 
    2598                         ConstructGeometry(interior, geom); 
    2599  
    2600                         const int cf = Polygon3::ClassifyPlane(geom.GetPolys(),  
    2601                                                                                                    halfspace,  
    2602                                                                                                    mEpsilon); 
    2603  
    2604                         if (cf == Polygon3::BACK_SIDE) 
    2605                                 next = interior->GetFront(); 
    2606                         else 
    2607                                 if (cf == Polygon3::FRONT_SIDE) 
    2608                                         next = interior->GetFront(); 
    2609                         else  
    2610                         { 
    2611                                 // random decision 
    2612                                 if (mask & 1) 
    2613                                         next = interior->GetBack(); 
    2614                                 else 
    2615                                         next = interior->GetFront(); 
    2616                                 mask = mask >> 1; 
    2617                         } 
    2618  
    2619                         nodeStack.push(next); 
    2620                 } 
    2621         } 
    2622          
    2623         return NULL; 
    26242570} 
    26252571 
     
    30853031                                splitsGeom = false; 
    30863032 
    3087                                 if (DotProd(mPlanes[i].mNormal,  splitPlane.mNormal > 0)) 
     3033                                if (DotProd(mPlanes[i].mNormal, splitPlane.mNormal > 0)) 
    30883034                                        back.Add(new Polygon3(mPolys[i]->mVertices), mPlanes[i]); 
    30893035                                else 
     
    30983044        if (planePoly) 
    30993045        { 
    3100                 // add polygon with reverse orientation to front cell 
     3046        // add polygon with reverse orientation to front cell 
    31013047                Plane3 reversePlane(splitPlane); 
    31023048                reversePlane.ReverseOrientation(); 
    31033049 
    3104                 //Debug << "poly normal : " << ndummy << " split plane normal " << splitPlane.mNormal << endl; 
    31053050                // add polygon with normal pointing into positive half space to back cell 
    31063051                back.Add(planePoly, splitPlane); 
    31073052                //back.mPolys.push_back(planePoly); 
     3053 
    31083054                Polygon3 *reversePoly = planePoly->CreateReversePolygon(); 
    31093055                front.Add(reversePoly, reversePlane); 
    31103056                Debug << "poly normal : " << reversePoly->GetSupportingPlane().mNormal << " split plane normal " << reversePlane.mNormal << endl; 
    31113057        } 
    3112  
     3058        else Debug << "err" << endl; 
    31133059 
    31143060        return splitsGeom; 
     
    31203066{ 
    31213067        if (!planePoly->Valid(epsilon)) 
     3068        { 
     3069                Debug << "not valid!!" << endl; 
    31223070                DEL_PTR(planePoly); 
    3123  
     3071        } 
    31243072        // polygon is split by all other planes 
    31253073        for (int i = 0; (i < (int)mPolys.size()) && planePoly; ++ i) 
    31263074        { 
    3127 #if 0 
    3128                 Plane3 plane = mPolys[i]->GetSupportingPlane(); 
    3129 #else 
     3075                //Plane3 plane = mPolys[i]->GetSupportingPlane(); 
    31303076                Plane3 plane = mPlanes[i]; 
    3131          
    3132 #endif 
     3077 
     3078                Debug << "*******************" << endl; 
     3079                Debug << "support: " << mPolys[i]->GetSupportingPlane() << endl; 
     3080                Debug << "plane: " << mPlanes[i] << endl; 
     3081 
    31333082                /// don't use epsilon here to get exact split planes 
    31343083                const int cf =  
Note: See TracChangeset for help on using the changeset viewer.