Changeset 683


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

fixed a bsp node geometry problem (debug code)

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

Legend:

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

    r648 r683  
    167167                 
    168168                if (side > 0) 
     169                { 
    169170                        onFrontSide = true; 
     171                } 
    170172                else if (side < 0) 
     173                { 
    171174                        onBackSide = true; 
    172                  
     175                } 
     176 
    173177                //TODO: check if split goes through vertex 
    174178                if (onFrontSide && onBackSide) // split  
     
    413417                                                        const float epsilon) 
    414418{ 
    415         PolygonContainer::const_iterator it; 
    416  
    417419        bool onFrontSide = false; 
    418420        bool onBackSide = false; 
    419          
     421        PolygonContainer::const_iterator it; 
     422 
    420423        // find intersections 
    421424        for (it = polys.begin(); it != polys.end(); ++ it) 
  • 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 =  
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r682 r683  
    218218        Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 
    219219 
    220         if (0) // export initial view cells 
     220        if (1) // export initial view cells 
    221221        { 
    222222                cout << "exporting initial view cells (=leaves) ... "; 
     
    34863486                        mVspBspTree->ConstructGeometry(leaf, geom); 
    34873487 
    3488                         const int cf = Polygon3::ClassifyPlane(geom.GetPolys(), *clipPlane, 0.0005); 
    3489  
    3490                         if (cf == Polygon3::BACK_SIDE) 
     3488                        const int cf = Polygon3::ClassifyPlane(geom.GetPolys(), *clipPlane, 0.00000001f); 
     3489 
     3490                        /*if (cf == Polygon3::BACK_SIDE) 
    34913491                        { 
    34923492                                exporter->ExportPolygons(geom.GetPolys()); 
    34933493                        } 
    34943494                        else if (cf == Polygon3::SPLIT) 
    3495                         { 
     3495                        {*/ 
    34963496                                geom.SplitGeometry(front, 
    34973497                                                                   back, 
    34983498                                                                   *clipPlane, 
    34993499                                                                   mViewSpaceBox,  
    3500                                                                    0.0001f); 
    3501          
    3502                                 if (back.Size() >= 3) 
     3500                                                                   0.00000001f); 
     3501         
     3502                                Debug << "here geo size: " << geom.Size() << endl; 
     3503                                Debug << "here size b: " << back.Size() << " f: " << front.Size() << endl; 
     3504                                if (back.Valid()) 
     3505                                { 
     3506                                        Debug << "here3 size: " << back.Size() << endl; 
    35033507                                        exporter->ExportPolygons(back.GetPolys()); 
    3504                         } 
     3508                                } 
     3509                                else 
     3510                                        Debug << "here2 size: " << back.Size() << endl; 
     3511                        //} 
    35053512                } 
    35063513        } 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r682 r683  
    25112511                        Plane3 halfSpace = dynamic_cast<BspInterior *>(interior)->GetPlane(); 
    25122512 
    2513             if (interior->GetFront() != lastNode) 
     2513            if (interior->GetBack() != lastNode) 
    25142514                                halfSpace.ReverseOrientation(); 
    25152515 
     
    25302530        vector<Plane3> candidatePlanes; 
    25312531 
    2532         // bounded planes are added to the polygons (reverse polygons 
    2533         // as they have to be outfacing) 
     2532        // bounded planes are added to the polygons 
    25342533        for (int i = 0; i < (int)halfSpaces.size(); ++ i) 
    25352534        { 
     
    25382537                if (p->Valid(mEpsilon)) 
    25392538                { 
    2540                         candidatePolys.push_back(p->CreateReversePolygon()); 
    2541                         // Why? 
    2542                         Plane3 candidatePlane = p->GetSupportingPlane(); //halfSpaces[i]; 
    2543                         //candidatePlane.ReverseOrientation(); 
    2544                         candidatePlanes.push_back(candidatePlane); 
    2545  
    2546                         DEL_PTR(p); 
     2539                        candidatePolys.push_back(p); 
     2540                        candidatePlanes.push_back(halfSpaces[i]); 
    25472541                } 
    25482542        } 
     
    25902584                                        DEL_PTR(candidatePolys[i]); 
    25912585 
    2592                                         if (frontPoly->Valid(mEpsilon)) 
    2593                                                 candidatePolys[i] = frontPoly; 
     2586                                        if (backPoly->Valid(mEpsilon)) 
     2587                                                candidatePolys[i] = backPoly; 
    25942588                                        else 
    2595                                                 DEL_PTR(frontPoly); 
    2596  
    2597                                         DEL_PTR(backPoly); 
     2589                                                DEL_PTR(backPoly); 
     2590 
     2591                                        // outside, don't need this 
     2592                                        DEL_PTR(frontPoly); 
    25982593                                        break; 
    2599  
    2600                                 case Polygon3::BACK_SIDE: 
     2594                                // polygon outside of halfspace 
     2595                                case Polygon3::FRONT_SIDE: 
    26012596                                        DEL_PTR(candidatePolys[i]); 
    26022597                                        break; 
    26032598                                // just take polygon as it is 
    2604                                 case Polygon3::FRONT_SIDE: 
     2599                                case Polygon3::BACK_SIDE: 
    26052600                                case Polygon3::COINCIDENT: 
    26062601                                default: 
     
    26852680                                                                                                        mEpsilon); 
    26862681 
    2687                                                 if (cf == Polygon3::BACK_SIDE) 
     2682                                                if (cf == Polygon3::FRONT_SIDE) 
    26882683                                                { 
    26892684                                                        isAdjacent = false; 
     
    27042699                                                                                                        mEpsilon); 
    27052700 
    2706                                                 if (cf == Polygon3::BACK_SIDE) 
     2701                                                if (cf == Polygon3::FRONT_SIDE) 
    27072702                                                { 
    27082703                                                        isAdjacent = false; 
     
    27382733                                                                mEpsilon); 
    27392734                 
    2740                         if (cf == Polygon3::FRONT_SIDE) 
    2741                         { 
    2742                                 nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 
    2743                                 DEL_PTR(bGeom); 
     2735                        if (cf == Polygon3::BACK_SIDE) 
     2736                        { 
     2737                                nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 
     2738                                DEL_PTR(fGeom); 
    27442739                        } 
    27452740                        else 
    27462741                        { 
    2747                                 if (cf == Polygon3::BACK_SIDE) 
     2742                                if (cf == Polygon3::FRONT_SIDE) 
    27482743                                { 
    2749                                         nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 
    2750                                         DEL_PTR(fGeom); 
     2744                                        nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 
     2745                                        DEL_PTR(bGeom); 
    27512746                                } 
    27522747                                else 
     
    28302825                                                                mEpsilon); 
    28312826                 
    2832                         if (cf == Polygon3::FRONT_SIDE) 
    2833                         { 
    2834                                 nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 
    2835                                 DEL_PTR(bGeom); 
     2827                        if (cf == Polygon3::BACK_SIDE) 
     2828                        { 
     2829                                nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 
     2830                                DEL_PTR(fGeom); 
    28362831                        } 
    28372832                        else 
    28382833                        { 
    2839                                 if (cf == Polygon3::BACK_SIDE) 
     2834                                if (cf == Polygon3::FRONT_SIDE) 
    28402835                                { 
    2841                                         nodeStack.push(bspNodePair(interior->GetBack(), bGeom)); 
    2842                                         DEL_PTR(fGeom); 
     2836                                        nodeStack.push(bspNodePair(interior->GetFront(), fGeom)); 
     2837                                        DEL_PTR(bGeom); 
    28432838                                } 
    28442839                                else 
     
    30443039 
    30453040        float t; 
    3046         const float thresh = 1 ? 1e-6f : 0.0f; 
     3041        //const float thresh = 1 ? 1e-6f : 0.0f; 
     3042        const float thresh = 0.01f; 
    30473043 
    30483044        while (1) 
Note: See TracChangeset for help on using the changeset viewer.