Ignore:
Timestamp:
01/05/06 20:41:52 (18 years ago)
Author:
mattausch
Message:

added mesh creation function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp

    r501 r503  
    835835 
    836836 
     837/* 
    837838float VspBspTree::EvalCostRatio(const VspBspTraversalData &tData, 
    838839                                                                const AxisAlignedBox3 &box, 
     
    949950        return  (mCtDivCi + newCost) / oldCost; 
    950951} 
    951  
     952*/ 
    952953 
    953954 
     
    13041305 
    13051306 
    1306 void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves) const 
     1307void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves,  
     1308                                                           const bool onlyUnmailed, 
     1309                                                           const int maxPvsSize) const 
    13071310{ 
    13081311        stack<BspNode *> nodeStack; 
     
    13171320                { 
    13181321                        // test if this leaf is in valid view space 
    1319                         if (node->TreeValid()) 
     1322                        BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); 
     1323                        if (leaf->TreeValid() &&  
     1324                                (!onlyUnmailed || leaf->Mailed()) && 
     1325                                ((maxPvsSize < 0) || (leaf->GetViewCell()->GetPvs().GetSize() <= maxPvsSize))) 
    13201326                        { 
    1321                                 BspLeaf *leaf = (BspLeaf *)node; 
    13221327                                leaves.push_back(leaf); 
    13231328                        } 
     
    16411646 
    16421647void VspBspTree::ConstructGeometry(BspNode *n, 
    1643                                                                    BspNodeGeometry &cell) const 
    1644 { 
    1645         ConstructGeometry(n, cell.mPolys); 
    1646 } 
    1647  
    1648  
    1649 void VspBspTree::ConstructGeometry(BspNode *n, 
    1650                                                                    PolygonContainer &cell) const 
     1648                                                                   BspNodeGeometry &geom) const 
    16511649{ 
    16521650        vector<Plane3> halfSpaces; 
     
    17261724 
    17271725                if (candidatePolys[i]) 
    1728                         cell.push_back(candidatePolys[i]); 
     1726                        geom.mPolys.push_back(candidatePolys[i]); 
    17291727        } 
    17301728} 
     
    17321730 
    17331731void VspBspTree::ConstructGeometry(BspViewCell *vc,  
    1734                                                                    PolygonContainer &vcGeom) const 
     1732                                                                   BspNodeGeometry &vcGeom) const 
    17351733{ 
    17361734        vector<BspLeaf *> leaves = vc->mLeaves; 
     
    17451743                                                   const bool onlyUnmailed) const 
    17461744{ 
    1747         PolygonContainer geom; 
     1745        BspNodeGeometry geom; 
    17481746        ConstructGeometry(n, geom); 
    17491747 
     
    17701768                                // test all planes of current node if candidate really 
    17711769                                // is neighbour 
    1772                                 PolygonContainer neighborCandidate; 
     1770                                BspNodeGeometry neighborCandidate; 
    17731771                                ConstructGeometry(node, neighborCandidate); 
    17741772 
     
    17771775                                { 
    17781776                                        const int cf = 
    1779                                                 Polygon3::ClassifyPlane(neighborCandidate, 
     1777                                                Polygon3::ClassifyPlane(neighborCandidate.mPolys, 
    17801778                                                                                                halfSpaces[i], 
    17811779                                                                                                mEpsilon); 
     
    17871785                                if (isAdjacent) 
    17881786                                        neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 
    1789  
    1790                                 CLEAR_CONTAINER(neighborCandidate); 
    17911787                        } 
    17921788                } 
     
    17951791                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    17961792 
    1797                         const int cf = Polygon3::ClassifyPlane(geom, 
     1793                        const int cf = Polygon3::ClassifyPlane(geom.mPolys, 
    17981794                                                                                                   interior->GetPlane(), 
    17991795                                                                                                   mEpsilon); 
     
    18131809        } 
    18141810 
    1815         CLEAR_CONTAINER(geom); 
    18161811        return (int)neighbors.size(); 
    18171812} 
     
    18371832                { 
    18381833                        BspInterior *interior = dynamic_cast<BspInterior *>(node); 
    1839  
    18401834                        BspNode *next; 
    1841  
    1842                         PolygonContainer geom; 
     1835                        BspNodeGeometry geom; 
    18431836 
    18441837                        // todo: not very efficient: constructs full cell everytime 
    18451838                        ConstructGeometry(interior, geom); 
    18461839 
    1847                         const int cf = Polygon3::ClassifyPlane(geom, halfspace, mEpsilon); 
     1840                        const int cf =  
     1841                                Polygon3::ClassifyPlane(geom.mPolys, halfspace, mEpsilon); 
    18481842 
    18491843                        if (cf == Polygon3::BACK_SIDE) 
     
    22482242 
    22492243 
    2250 int VspBspTree::CollectMergeCandidates() 
    2251 { 
    2252         vector<BspLeaf *> leaves; 
    2253  
    2254         // collect the leaves, e.g., the "voxels" that will build the view cells 
    2255         CollectLeaves(leaves); 
     2244int VspBspTree::CollectMergeCandidates(const vector<BspLeaf *> leaves) 
     2245{ 
    22562246        BspLeaf::NewMail(); 
    22572247 
     
    22912281        vector<BspRay *> bspRays; 
    22922282 
     2283        long startTime = GetTime(); 
    22932284        ConstructBspRays(bspRays, rays); 
     2285        Debug << (int)bspRays.size() << " bsp rays constructed in " << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 
     2286 
    22942287        map<BspLeaf *, vector<BspLeaf*> > neighborMap; 
    2295  
    22962288        vector<BspIntersection>::const_iterator iit; 
    22972289 
    2298         int leaves = 0; 
     2290        int numLeaves = 0; 
    22992291         
    23002292        BspLeaf::NewMail(); 
     
    23212313                                leaf->mArea * leaf->mPvs->GetSize(); 
    23222314                         
    2323                         ++ leaves; 
     2315                        ++ numLeaves; 
    23242316                } 
    23252317                 
     
    23452337                                        leaf->mArea * leaf->mPvs->GetSize(); 
    23462338 
    2347                                 ++ leaves; 
     2339                                ++ numLeaves; 
    23482340                        } 
    23492341                 
     
    23792371        Debug << "neighbormap size: " << (int)neighborMap.size() << endl; 
    23802372        Debug << "mergequeue: " << (int)mMergeQueue.size() << endl; 
    2381         Debug << "leaves in queue: " << leaves << endl; 
     2373        Debug << "leaves in queue: " << numLeaves << endl; 
    23822374        Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 
    23832375 
    23842376        CLEAR_CONTAINER(bspRays); 
    23852377 
    2386         return leaves; 
     2378        //-- collect the leaves which haven't been found by ray casting 
     2379        vector<BspLeaf *> leaves; 
     2380        CollectLeaves(leaves, true, mMaxPvs); 
     2381        Debug << "found " << (int)leaves.size() << " new leaves" << endl; 
     2382        //CollectMergeCandidates(leaves); 
     2383 
     2384        return numLeaves; 
    23872385} 
    23882386 
     
    24402438                mergeStats.nodes = CollectMergeCandidates(rays); 
    24412439        else 
    2442                 mergeStats.nodes = CollectMergeCandidates(); 
     2440        { 
     2441                vector<BspLeaf *> leaves; 
     2442                CollectLeaves(leaves); 
     2443                mergeStats.nodes = CollectMergeCandidates(leaves); 
     2444        } 
    24432445 
    24442446        mergeStats.collectTime = TimeDiff(startTime, GetTime()); 
     
    27352737} 
    27362738 
     2739#define USE_ASCII 0 
     2740bool VspBspTree::WriteVspBspTree() 
     2741{ 
     2742        char fileName[100]; 
     2743        environment->GetStringValue("VspBspTree.viewCellsFilename", fileName); 
     2744         
     2745        /*VssRayContainer::const_iterator it, it_end = samples.end(); 
     2746         
     2747#if USE_ASCII 
     2748        ofstream samplesOut(fileName); 
     2749        if (!samplesOut.is_open()) 
     2750                return false; 
     2751 
     2752        for (it = samples.begin(); it != it_end; ++ it) 
     2753        { 
     2754                VssRay *ray = *it; 
     2755                int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;                
     2756                int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;        
     2757 
     2758                samplesOut << ray->GetOrigin().x << " " << ray->GetOrigin().y << " " << ray->GetOrigin().z << " "  
     2759                                   << ray->GetTermination().x << " " << ray->GetTermination().y << " " << ray->GetTermination().z << " "  
     2760                                   << sourceid << " " << termid << "\n"; 
     2761        } 
     2762#else 
     2763        ofstream samplesOut(fileName, ios::binary); 
     2764        if (!samplesOut.is_open()) 
     2765                return false; 
     2766 
     2767        for (it = samples.begin(); it != it_end; ++ it) 
     2768        {        
     2769                VssRay *ray = *it; 
     2770                Vector3 origin(ray->GetOrigin()); 
     2771                Vector3 termination(ray->GetTermination()); 
     2772                 
     2773                int sourceid = ray->mOriginObject ? ray->mOriginObject->mId : -1;                
     2774                int termid = ray->mTerminationObject ? ray->mTerminationObject->mId : -1;                
     2775 
     2776                samplesOut.write(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 
     2777                samplesOut.write(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 
     2778                samplesOut.write(reinterpret_cast<char *>(&sourceid), sizeof(int)); 
     2779                samplesOut.write(reinterpret_cast<char *>(&termid), sizeof(int)); 
     2780    } 
     2781#endif 
     2782 
     2783        samplesOut.close(); 
     2784        */ 
     2785        return true; 
     2786} 
     2787 
     2788bool VspBspTree::LoadVspBspTree() 
     2789{ 
     2790        /*std::stable_sort(objects.begin(), objects.end(), ilt); 
     2791        char fileName[100]; 
     2792        environment->GetStringValue("Preprocessor.samplesFilename", fileName); 
     2793         
     2794    Vector3 origin, termination; 
     2795        // HACK: needed only for lower_bound algorithm to find the  
     2796        // intersected objects 
     2797        MeshInstance sObj(NULL); 
     2798        MeshInstance tObj(NULL); 
     2799 
     2800#if USE_ASCII 
     2801        ifstream samplesIn(fileName, ios::binary); 
     2802        if (!samplesIn.is_open()) 
     2803                return false; 
     2804 
     2805        string buf; 
     2806        while (!(getline(samplesIn, buf)).eof()) 
     2807        { 
     2808                sscanf(buf.c_str(), "%f %f %f %f %f %f %d %d",  
     2809                           &origin.x, &origin.y, &origin.z, 
     2810                           &termination.x, &termination.y, &termination.z,  
     2811                           &(sObj.mId), &(tObj.mId)); 
     2812                 
     2813                Intersectable *sourceObj = NULL; 
     2814                Intersectable *termObj = NULL; 
     2815                 
     2816                if (sObj.mId >= 0) 
     2817                { 
     2818                        ObjectContainer::iterator oit = 
     2819                                lower_bound(objects.begin(), objects.end(), &sObj, ilt); 
     2820                        sourceObj = *oit; 
     2821                } 
     2822                 
     2823                if (tObj.mId >= 0) 
     2824                { 
     2825                        ObjectContainer::iterator oit = 
     2826                                lower_bound(objects.begin(), objects.end(), &tObj, ilt); 
     2827                        termObj = *oit; 
     2828                } 
     2829 
     2830                samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 
     2831        } 
     2832#else 
     2833        ifstream samplesIn(fileName, ios::binary); 
     2834        if (!samplesIn.is_open()) 
     2835                return false; 
     2836 
     2837        while (1) 
     2838        { 
     2839                 samplesIn.read(reinterpret_cast<char *>(&origin), sizeof(Vector3)); 
     2840                 samplesIn.read(reinterpret_cast<char *>(&termination), sizeof(Vector3)); 
     2841                 samplesIn.read(reinterpret_cast<char *>(&(sObj.mId)), sizeof(int)); 
     2842                 samplesIn.read(reinterpret_cast<char *>(&(tObj.mId)), sizeof(int)); 
     2843                 
     2844                 if (samplesIn.eof()) 
     2845                        break; 
     2846 
     2847                Intersectable *sourceObj = NULL; 
     2848                Intersectable *termObj = NULL; 
     2849                 
     2850                if (sObj.mId >= 0) 
     2851                { 
     2852                        ObjectContainer::iterator oit = 
     2853                                lower_bound(objects.begin(), objects.end(), &sObj, ilt); 
     2854                        sourceObj = *oit; 
     2855                } 
     2856                 
     2857                if (tObj.mId >= 0) 
     2858                { 
     2859                        ObjectContainer::iterator oit = 
     2860                                lower_bound(objects.begin(), objects.end(), &tObj, ilt); 
     2861                        termObj = *oit; 
     2862                } 
     2863 
     2864                samples.push_back(new VssRay(origin, termination, sourceObj, termObj)); 
     2865        } 
     2866 
     2867#endif 
     2868        samplesIn.close(); 
     2869*/ 
     2870        return true; 
     2871} 
     2872 
    27372873 
    27382874/************************************************************************/ 
Note: See TracChangeset for help on using the changeset viewer.