Changeset 697


Ignore:
Timestamp:
03/15/06 18:13:36 (18 years ago)
Author:
mattausch
Message:
 
Location:
GTP/trunk/Lib/Vis/Preprocessing
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env

    r685 r697  
    235235                clipPlaneAxis 1 
    236236                clipPlanePos 0.35 
     237        } 
     238 
     239        Filter { 
     240                width 10.0 
     241                maxSize 4 
    237242        } 
    238243 
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp

    r557 r697  
    15701570} 
    15711571 
     1572 
     1573Plane3 AxisAlignedBox3::GetPlane(const int face) const 
     1574{ 
     1575        switch (face)  
     1576        { 
     1577         
     1578        case 0: 
     1579                return Plane3(Vector3(-1, 0, 0), mMin); 
     1580        case 1:  
     1581                return Plane3(Vector3(1, 0, 0), mMax); 
     1582        case 2: 
     1583                return Plane3(Vector3(0, -1, 0), mMin); 
     1584        case 3: 
     1585                return Plane3(Vector3(0, 1, 0), mMax); 
     1586        case 4: 
     1587                return Plane3(Vector3(0, 0, -1), mMin); 
     1588        case 5: 
     1589                return Plane3(Vector3(0, 0, 1), mMax); 
     1590        } 
     1591 
     1592        // should not come here 
     1593        return Plane3(); 
     1594} 
     1595 
     1596 
    15721597int 
    15731598AxisAlignedBox3::GetFaceVisibilityMask(const Rectangle3 &rectangle) const 
     
    15781603  return mask; 
    15791604} 
     1605 
    15801606 
    15811607int 
  • GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h

    r647 r697  
    111111  void Include(const int &axis, const float &newBound); 
    112112 
    113    
     113 
    114114  int 
    115115  Side(const Plane3 &plane) const; 
     
    277277 
    278278  Rectangle3 GetFace(const int face) const; 
     279  
     280  /** Extracts plane of bounding box. 
     281  */ 
     282  Plane3 GetPlane(const int face) const; 
    279283   
    280284  // For a given point returns the region, where the point is located 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp

    r685 r697  
    12491249                                        "20000"); 
    12501250 
     1251        RegisterOption("ViewCells.Filter.maxSize", 
     1252                                        optInt, 
     1253                                        "view_cells_filter_max_size=", 
     1254                                        "4"); 
     1255 
     1256        RegisterOption("ViewCells.Filter.width", 
     1257                                        optFloat, 
     1258                                        "view_cells_filter_width=", 
     1259                                        "10.0"); 
     1260 
    12511261        RegisterOption("ViewCells.loadFromFile", 
    12521262                                        optBool, 
  • GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h

    r639 r697  
    4040  } 
    4141 
     42  enum {BACK_SIDE = -1, INTERSECTS = 0, FRONT_SIDE = 1}; 
     43                  
     44                 
    4245  /** Returns 1 if v is on front side, -1 if on back side, 0 if on plane. 
    4346  */ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp

    r694 r697  
    1414 
    1515 
    16  
     16#define ROTATE_SCENE 1 
    1717// HACK 
    1818static void RotateMesh(Mesh *mesh) 
     
    158158      if (meshGrouping != 0 && 
    159159                                        currentMesh->mFaces.size() >=  meshGrouping) { 
    160                 if (1) 
     160                if (ROTATE_SCENE) 
    161161                        RotateMesh(currentMesh); 
    162162                                currentMesh->Preprocess(); 
     
    177177          if (1) 
    178178                RotateMesh(currentMesh); 
    179   cout << "here9999" << endl;      
     179  
    180180    currentMesh->Preprocess(); 
    181181    MeshInstance *mi = new MeshInstance(currentMesh); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp

    r694 r697  
    29152915 
    29162916 
     2917void BspNodeGeometry::GetBoundingBox(AxisAlignedBox3 &box) const 
     2918{ 
     2919        box.Initialize(); 
     2920        Polygon3::IncludeInBox(mPolys, box); 
     2921} 
     2922 
     2923 
     2924int BspNodeGeometry::Side(const Plane3 &plane) const 
     2925{ 
     2926        PolygonContainer::const_iterator it, it_end = mPolys.end(); 
     2927 
     2928        bool onFrontSide = false; 
     2929        bool onBackSide = false; 
     2930 
     2931        for (it = mPolys.begin(); it != it_end; ++ it) 
     2932        { 
     2933        const int side = (*it)->Side(plane, 0.0f); 
     2934 
     2935                if (side == -1) 
     2936                        onBackSide = true; 
     2937                else if (side == 1) 
     2938                        onFrontSide = true; 
     2939                 
     2940                if ((side == 0) || (onBackSide && onFrontSide)) 
     2941                        return 0; 
     2942        } 
     2943 
     2944        if (onFrontSide) 
     2945                return 1; 
     2946 
     2947        return -1; 
     2948} 
     2949 
     2950 
     2951int BspNodeGeometry::ComputeIntersection(const AxisAlignedBox3 &box) const 
     2952{ 
     2953        AxisAlignedBox3 boundingBox; 
     2954        GetBoundingBox(boundingBox); 
     2955 
     2956        const bool overlap = Overlap(boundingBox, box); 
     2957 
     2958        // no intersections with bounding box 
     2959        if (!overlap) 
     2960        { 
     2961                return 1; 
     2962        } 
     2963        int result = -1; 
     2964 
     2965        // 1: box does not intersect geometry 
     2966        // 0: box intersects geometry 
     2967        // -1: box contains geometry 
     2968        for (int i = 0; i < 6; ++ i)  
     2969        {                
     2970                const int side = Side(box.GetPlane(i)); 
     2971                 
     2972                // box does not intersects geometry 
     2973                if (side == 1) 
     2974                        return 1; 
     2975 
     2976                if (side == 0) 
     2977            result = 0; 
     2978  } 
     2979 
     2980  return result; 
     2981} 
     2982 
     2983 
    29172984Vector3 BspNodeGeometry::CenterOfMass() const 
    29182985{ 
     
    31543221 
    31553222 
    3156 void BspNodeGeometry::IncludeInBox(AxisAlignedBox3 &box) 
    3157 { 
    3158         Polygon3::IncludeInBox(mPolys, box); 
    3159 } 
    3160  
    3161  
    31623223bool BspTree::Export(ofstream &stream) 
    31633224{ 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h

    r679 r697  
    5454                                           const float epsilon) const; 
    5555 
     56        /** Computes the intersection of the box with the node geometry. 
     57        */ 
     58        int ComputeIntersection(const AxisAlignedBox3 &box) const; 
     59 
    5660        /** Computes bounding box of the geometry. 
    5761        */ 
    58         void IncludeInBox(AxisAlignedBox3 &box); 
     62        void GetBoundingBox(AxisAlignedBox3 &box) const; 
     63 
     64        /** Returns  
     65                1 of geometry in front of plane 
     66                0 if plane intersects geometry, 
     67                -1 if geometry in back of plane 
     68        */ 
     69        int Side(const Plane3 &plane) const; 
    5970 
    6071        /** Splits the polygon and returns the part of the polygon inside of the node geometry. 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp

    r694 r697  
    1919#define TEST_EMPTY_VIEW_CELLS 0 
    2020 
     21 
     22 
     23template <typename T> class myless 
     24{ 
     25public: 
     26        //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const 
     27        bool operator() (T v1, T v2) const 
     28        { 
     29                return (v1->GetMergeCost() < v2->GetMergeCost()); 
     30        } 
     31}; 
     32 
     33typedef priority_queue<ViewCell *, vector<ViewCell *>, myless<vector<ViewCell *>::value_type> > FilterQueue; 
     34 
     35 
     36 
    2137ViewCellsManager::ViewCellsManager(): 
    2238mRenderer(NULL), 
     
    6783        environment->GetBoolValue("ViewCells.evaluateViewCells", mEvaluateViewCells); 
    6884        environment->GetBoolValue("ViewCells.showVisualization", mShowVisualization); 
    69          
     85        environment->GetIntValue("ViewCells.Filter.maxSize", mMaxFilterSize); 
     86        environment->GetFloatValue("ViewCells.Filter.width", mFilterWidth); 
     87 
    7088        char buf[100]; 
    7189        environment->GetStringValue("ViewCells.samplingType", buf); 
     
    118136        Debug << "sampling type: " << mSamplingType << endl; 
    119137        Debug << "show visualization: " << mShowVisualization << endl; 
     138        Debug << "filter width: " << mFilterWidth << endl; 
    120139 
    121140        Debug << endl; 
     
    173192                        { 
    174193                                Ray *pray = (*it)->mPiercingRays[0]; 
    175                                 Debug << "view cell " << (*it)->GetId() << " not empty, pvs: " << (*it)->GetPvs().GetSize() << " " << pray->intersections.size() << endl; 
     194                                Debug << "view cell " << (*it)->GetId() << " not empty, pvs: " << (*it)->GetPvs().GetSize() << " " << (int)pray->intersections.size() << endl; 
    176195 
    177196                                exporter->ExportRays((*it)->mPiercingRays); 
     
    282301        disposeRays(initialSamples, outRays); 
    283302         
     303        cout << "testing filter ... "; 
     304 
     305        TestFilter(preprocessor->mObjects); 
     306 
     307        cout << "finished" << endl; 
    284308 
    285309        // -- stats after contruction 
     
    533557 
    534558  return true; 
     559} 
     560 
     561 
     562AxisAlignedBox3 ViewCellsManager::GetFilterBBox(const Vector3 &viewPoint,  
     563                                                                                                const float width) const 
     564{ 
     565        Vector3 min = viewPoint - width * 0.5f; 
     566        Vector3 max = viewPoint + width * 0.5; 
     567 
     568        return AxisAlignedBox3(min, max); 
     569} 
     570 
     571 
     572void ViewCellsManager::GetPrVS(const Vector3 &viewPoint, PrVs &prvs) 
     573{ 
     574        const AxisAlignedBox3 box = GetFilterBBox(viewPoint, mFilterWidth); 
     575 
     576        ViewCellContainer viewCells; 
     577        ComputeBoxIntersections(box, viewCells); 
     578 
     579                 
    535580} 
    536581 
     
    27672812                mViewCellsTree->CollectBestViewCellSet(mViewCells, mNumActiveViewCells); 
    27682813        } 
    2769  
    2770 } 
    2771  
     2814} 
    27722815 
    27732816 
     
    35243567 
    35253568 
     3569int VspBspViewCellsManager::ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const 
     3570{ 
     3571        return mVspBspTree->ComputeBoxIntersections(box, viewCells); 
     3572} 
     3573 
     3574 
    35263575int VspBspViewCellsManager::CastLineSegment(const Vector3 &origin, 
    35273576                                                                                        const Vector3 &termination, 
     
    38593908                newVol += lVol; 
    38603909                subdivVol += (*it)->GetVolume(); 
     3910                 
     3911                float thres = 0.9; 
     3912                if ((lVol < ((*it)->GetVolume() * thres)) || (lVol * thres > ((*it)->GetVolume()))) 
     3913                        Debug << "warning: " << lVol << " " << (*it)->GetVolume() << endl; 
    38613914        } 
    38623915         
     
    38743927} 
    38753928 
     3929 
     3930void VspBspViewCellsManager::TestFilter(const ObjectContainer &objects) 
     3931{ 
     3932        Exporter *exporter = Exporter::GetExporter("filter.x3d"); 
     3933 
     3934        if (exporter) 
     3935        { 
     3936                AxisAlignedBox3 testBox = mViewSpaceBox; 
     3937                Vector3 bsize = mViewSpaceBox.Size(); 
     3938 
     3939                testBox.Enlarge(Vector3(-bsize[0] * 0.3, 0, -bsize[2] * 0.4)); 
     3940                 
     3941                ViewCellContainer viewCells; 
     3942         
     3943                mVspBspTree->ComputeBoxIntersections(testBox, viewCells); 
     3944                cout << "view cells: " << viewCells.size() << endl; 
     3945                 
     3946                exporter->SetWireframe(); 
     3947 
     3948                exporter->SetForcedMaterial(RgbColor(1,1,1)); 
     3949                exporter->ExportBox(testBox); 
     3950                 
     3951                exporter->SetFilled(); 
     3952                exporter->ResetForcedMaterial(); 
     3953        for (int i = 0; i < viewCells.size(); ++ i) 
     3954                { 
     3955                        BspNodeGeometry geom; 
     3956                                 
     3957                        mVspBspTree->ConstructGeometry(viewCells[i], geom); 
     3958                        exporter->ExportPolygons(geom.GetPolys()); 
     3959                }                
     3960 
     3961                exporter->SetForcedMaterial(RgbColor(1,0,0)); 
     3962                exporter->ExportGeometry(objects); 
     3963 
     3964                delete exporter; 
     3965        } 
     3966} 
    38763967 
    38773968 
  • GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h

    r694 r697  
    3535 
    3636/** Probably Visible Set */ 
    37 class PrVs { 
     37class PrVs  
     38{ 
     39public: 
    3840  /// viewcells 
    39   ViewCellContainer mVviewCells; 
    40   /// aggregatred pvs 
     41  ViewCellContainer mViewCells; 
     42  /// aggregated pvs 
    4143  ObjectPvs mPvs; 
    4244 
     
    6264  }; 
    6365   
     66 
    6467  /// view cell container types 
    6568  enum {BSP, KD, VSP_KD, VSP_BSP}; 
     
    9497                @param storeViewCells true if view cells should be stored in the ray 
    9598        */ 
    96   float ComputeSampleContributions(const VssRayContainer &rays, 
     99        float ComputeSampleContributions(const VssRayContainer &rays, 
    97100                                                                   const bool addContributions, 
    98101                                                                   const bool storeViewCells); 
    99102 
    100   /** Add sample contributions to the viewcells they intersect */ 
    101   void AddSampleContributions(const VssRayContainer &rays); 
     103        /** Add sample contributions to the viewcells they intersect */ 
     104        void AddSampleContributions(const VssRayContainer &rays); 
    102105   
    103106 
     
    218221        virtual void GetPvsStatistics(PvsStatistics &stat); 
    219222 
    220   virtual void GetPrVS(const Vector3 &viewPoint, 
    221                                            PrVs &prvs 
    222                                            ) {} 
     223        virtual void GetPrVS(const Vector3 &viewPoint, PrVs &prvs); 
    223224   
    224   /** Get a viewcell containing the specified point */ 
     225        /** Get a viewcell containing the specified point  
     226        */ 
    225227        virtual ViewCell *GetViewCell(const Vector3 &point) const = 0; 
    226228   
     
    383385        void EvalViewCellPartition(Preprocessor *preprocessor); 
    384386 
     387 
    385388protected: 
    386389 
     390        /** Returns the bounding box of filter width. 
     391        */ 
     392        AxisAlignedBox3 GetFilterBBox(const Vector3 &viewPoint, const float width) const; 
     393 
     394        /** Intersects box with the tree and returns the number of intersected boxes. 
     395                @returns number of view cells found 
     396        */ 
     397        virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const {return 0;}; 
     398 
     399        virtual void TestFilter(const ObjectContainer &objects) {}; 
    387400 
    388401        /** 
     
    486499        /// if rays should be used to collect merge candidates 
    487500        bool mUseRaysForMerge; 
    488          
     501        /// merge the view cells? 
    489502        bool mMergeViewCells; 
    490          
     503 
     504        /// the width of the box filter 
     505        float mFilterWidth; 
     506        int mMaxFilterSize; 
     507 
    491508        //-- visualization options 
    492509         
     
    783800        void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates); 
    784801 
     802        /** Returns true if this view cell is equivavalent to a spatial node. 
     803        */ 
    785804        bool EqualToSpatialNode(ViewCell *viewCell) const; 
    786805 
     806 
    787807protected: 
    788808 
     809        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 
    789810         
    790811        /** Returns node of the spatial hierarchy corresponding to the view cell 
     
    818839        ViewCell *ConstructSpatialMergeTree(BspNode *root); 
    819840 
     841        void TestFilter(const ObjectContainer &objects); 
     842 
     843 
     844 
    820845        /// the view space partition BSP tree. 
    821846        VspBspTree *mVspBspTree; 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp

    r694 r697  
    2828int VspBspTree::sFrontAndBackId = 0; 
    2929 
     30typedef pair<BspNode *, BspNodeGeometry *> bspNodePair; 
    3031 
    3132 
     
    18891890 
    18901891 
     1892int VspBspTree::ComputeBoxIntersections(const AxisAlignedBox3 &box,  
     1893                                                                                ViewCellContainer &viewCells) const 
     1894{ 
     1895        stack<bspNodePair> nodeStack; 
     1896        BspNodeGeometry *rgeom = new BspNodeGeometry(); 
     1897 
     1898        ConstructGeometry(mRoot, *rgeom); 
     1899 
     1900        nodeStack.push(bspNodePair(mRoot, rgeom)); 
     1901   
     1902        ViewCell::NewMail(); 
     1903 
     1904        while (!nodeStack.empty())  
     1905        { 
     1906                BspNode *node = nodeStack.top().first; 
     1907                BspNodeGeometry *geom = nodeStack.top().second; 
     1908                nodeStack.pop(); 
     1909 
     1910                const int side = geom->ComputeIntersection(box); 
     1911                 
     1912                switch (side) 
     1913                { 
     1914                case -1: 
     1915                        // node geometry is contained in box 
     1916                        CollectViewCells(node, true, viewCells, true); 
     1917                        break; 
     1918 
     1919                case 0: 
     1920                        if (node->IsLeaf()) 
     1921                        { 
     1922                                BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     1923                         
     1924                                if (!leaf->GetViewCell()->Mailed() && leaf->TreeValid()) 
     1925                                { 
     1926                                        leaf->GetViewCell()->Mail(); 
     1927                                        viewCells.push_back(leaf->GetViewCell()); 
     1928                                } 
     1929                        } 
     1930                        else  
     1931                        { 
     1932                                BspInterior *interior = dynamic_cast<BspInterior *>(node); 
     1933                         
     1934                                BspNode *first = interior->GetFront(); 
     1935                                BspNode *second = interior->GetBack(); 
     1936             
     1937                                BspNodeGeometry *firstGeom = new BspNodeGeometry(); 
     1938                                BspNodeGeometry *secondGeom = new BspNodeGeometry(); 
     1939 
     1940                                geom->SplitGeometry(*firstGeom, 
     1941                                                                        *secondGeom, 
     1942                                                                        interior->GetPlane(), 
     1943                                                                        mBox, 
     1944                                                                        //0.0000001f); 
     1945                                                                        mEpsilon); 
     1946 
     1947                                nodeStack.push(bspNodePair(first, firstGeom)); 
     1948                                nodeStack.push(bspNodePair(second, secondGeom)); 
     1949                        } 
     1950                         
     1951                        break; 
     1952                default: 
     1953                        // default: cull 
     1954                        break; 
     1955                } 
     1956                 
     1957                DEL_PTR(geom); 
     1958                 
     1959        } 
     1960 
     1961        return (int)viewCells.size(); 
     1962} 
     1963 
     1964 
    18911965float VspBspTree::EvalAxisAlignedSplitCost(const VspBspTraversalData &data, 
    18921966                                                                                   const AxisAlignedBox3 &box, 
     
    26292703        } 
    26302704} 
    2631  
    2632  
    2633 typedef pair<BspNode *, BspNodeGeometry *> bspNodePair; 
    26342705 
    26352706 
     
    32813352                 
    32823353                AxisAlignedBox3 box; 
    3283                 box.Initialize(); 
    3284                 geom->IncludeInBox(box); 
     3354                geom->GetBoundingBox(box); 
    32853355 
    32863356                const int side = beam.ComputeIntersection(box); 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h

    r694 r697  
    345345        void CollectRays(VssRayContainer &rays); 
    346346 
    347  
     347        /** Intersects box with the tree and returns the number of intersected boxes. 
     348                @returns number of view cells found 
     349        */ 
     350        int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 
     351 
     352        // pointer to the hierarchy of view cells 
    348353        ViewCellsTree *mViewCellsTree; 
    349354 
  • GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp

    r694 r697  
    852852  return true; 
    853853} 
     854 
     855 
Note: See TracChangeset for help on using the changeset viewer.