Changeset 503 for trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
- Timestamp:
- 01/05/06 20:41:52 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r501 r503 835 835 836 836 837 /* 837 838 float VspBspTree::EvalCostRatio(const VspBspTraversalData &tData, 838 839 const AxisAlignedBox3 &box, … … 949 950 return (mCtDivCi + newCost) / oldCost; 950 951 } 951 952 */ 952 953 953 954 … … 1304 1305 1305 1306 1306 void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves) const 1307 void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves, 1308 const bool onlyUnmailed, 1309 const int maxPvsSize) const 1307 1310 { 1308 1311 stack<BspNode *> nodeStack; … … 1317 1320 { 1318 1321 // 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))) 1320 1326 { 1321 BspLeaf *leaf = (BspLeaf *)node;1322 1327 leaves.push_back(leaf); 1323 1328 } … … 1641 1646 1642 1647 void 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 1651 1649 { 1652 1650 vector<Plane3> halfSpaces; … … 1726 1724 1727 1725 if (candidatePolys[i]) 1728 cell.push_back(candidatePolys[i]);1726 geom.mPolys.push_back(candidatePolys[i]); 1729 1727 } 1730 1728 } … … 1732 1730 1733 1731 void VspBspTree::ConstructGeometry(BspViewCell *vc, 1734 PolygonContainer&vcGeom) const1732 BspNodeGeometry &vcGeom) const 1735 1733 { 1736 1734 vector<BspLeaf *> leaves = vc->mLeaves; … … 1745 1743 const bool onlyUnmailed) const 1746 1744 { 1747 PolygonContainergeom;1745 BspNodeGeometry geom; 1748 1746 ConstructGeometry(n, geom); 1749 1747 … … 1770 1768 // test all planes of current node if candidate really 1771 1769 // is neighbour 1772 PolygonContainerneighborCandidate;1770 BspNodeGeometry neighborCandidate; 1773 1771 ConstructGeometry(node, neighborCandidate); 1774 1772 … … 1777 1775 { 1778 1776 const int cf = 1779 Polygon3::ClassifyPlane(neighborCandidate ,1777 Polygon3::ClassifyPlane(neighborCandidate.mPolys, 1780 1778 halfSpaces[i], 1781 1779 mEpsilon); … … 1787 1785 if (isAdjacent) 1788 1786 neighbors.push_back(dynamic_cast<BspLeaf *>(node)); 1789 1790 CLEAR_CONTAINER(neighborCandidate);1791 1787 } 1792 1788 } … … 1795 1791 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1796 1792 1797 const int cf = Polygon3::ClassifyPlane(geom ,1793 const int cf = Polygon3::ClassifyPlane(geom.mPolys, 1798 1794 interior->GetPlane(), 1799 1795 mEpsilon); … … 1813 1809 } 1814 1810 1815 CLEAR_CONTAINER(geom);1816 1811 return (int)neighbors.size(); 1817 1812 } … … 1837 1832 { 1838 1833 BspInterior *interior = dynamic_cast<BspInterior *>(node); 1839 1840 1834 BspNode *next; 1841 1842 PolygonContainer geom; 1835 BspNodeGeometry geom; 1843 1836 1844 1837 // todo: not very efficient: constructs full cell everytime 1845 1838 ConstructGeometry(interior, geom); 1846 1839 1847 const int cf = Polygon3::ClassifyPlane(geom, halfspace, mEpsilon); 1840 const int cf = 1841 Polygon3::ClassifyPlane(geom.mPolys, halfspace, mEpsilon); 1848 1842 1849 1843 if (cf == Polygon3::BACK_SIDE) … … 2248 2242 2249 2243 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); 2244 int VspBspTree::CollectMergeCandidates(const vector<BspLeaf *> leaves) 2245 { 2256 2246 BspLeaf::NewMail(); 2257 2247 … … 2291 2281 vector<BspRay *> bspRays; 2292 2282 2283 long startTime = GetTime(); 2293 2284 ConstructBspRays(bspRays, rays); 2285 Debug << (int)bspRays.size() << " bsp rays constructed in " << TimeDiff(startTime, GetTime()) * 1e-3f << " secs" << endl; 2286 2294 2287 map<BspLeaf *, vector<BspLeaf*> > neighborMap; 2295 2296 2288 vector<BspIntersection>::const_iterator iit; 2297 2289 2298 int leaves = 0;2290 int numLeaves = 0; 2299 2291 2300 2292 BspLeaf::NewMail(); … … 2321 2313 leaf->mArea * leaf->mPvs->GetSize(); 2322 2314 2323 ++ leaves;2315 ++ numLeaves; 2324 2316 } 2325 2317 … … 2345 2337 leaf->mArea * leaf->mPvs->GetSize(); 2346 2338 2347 ++ leaves;2339 ++ numLeaves; 2348 2340 } 2349 2341 … … 2379 2371 Debug << "neighbormap size: " << (int)neighborMap.size() << endl; 2380 2372 Debug << "mergequeue: " << (int)mMergeQueue.size() << endl; 2381 Debug << "leaves in queue: " << leaves << endl;2373 Debug << "leaves in queue: " << numLeaves << endl; 2382 2374 Debug << "overall cost: " << BspMergeCandidate::sOverallCost << endl; 2383 2375 2384 2376 CLEAR_CONTAINER(bspRays); 2385 2377 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; 2387 2385 } 2388 2386 … … 2440 2438 mergeStats.nodes = CollectMergeCandidates(rays); 2441 2439 else 2442 mergeStats.nodes = CollectMergeCandidates(); 2440 { 2441 vector<BspLeaf *> leaves; 2442 CollectLeaves(leaves); 2443 mergeStats.nodes = CollectMergeCandidates(leaves); 2444 } 2443 2445 2444 2446 mergeStats.collectTime = TimeDiff(startTime, GetTime()); … … 2735 2737 } 2736 2738 2739 #define USE_ASCII 0 2740 bool 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 2788 bool 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 2737 2873 2738 2874 /************************************************************************/
Note: See TracChangeset
for help on using the changeset viewer.