Changeset 1603 for GTP/trunk/Lib
- Timestamp:
- 10/10/06 16:42:52 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1586 r1603 621 621 const int numMergedViewCells = UpdateActiveViewCells(activeViewCells); 622 622 623 624 //-- reset s / refinesthe view cells623 ///////////////// 624 //-- reset / refine the view cells 625 625 //-- priorities are recomputed 626 626 //-- the candidates are put back into merge queue 627 627 628 if (mRefineViewCells) 628 629 RefineViewCells(rays, objects); … … 687 688 688 689 // check if "siblings (back and front node of the same parent) 689 if (0 && mViewCellsManager->EqualToSpatialNode(mergedVc))690 if (0) 690 691 ++ mergeStats.siblings; 691 692 // set the coŽst for rendering a view cell … … 1531 1532 1532 1533 Debug << "******** Export stats **********" << endl; 1533 /*Debug << "vsb volume: " << vol << endl; 1534 Debug << "root volume: " << mRoot->GetVolume() << endl; 1535 Debug << "root pvs: " << rootPvs << endl; 1536 */ 1537 1534 1538 1535 float totalRenderCost, avgRenderCost, expectedCost; 1539 1536 … … 1547 1544 stats.open(mergeStats.c_str()); 1548 1545 1546 ///////////// 1549 1547 //-- first view cell 1548 1550 1549 UpdateStats(stats, 1551 1550 0, numViewCells, 0, totalRenderCost, … … 1595 1594 } 1596 1595 1597 1596 // update stats for this view cell 1598 1597 const float costDecr = (parentCost - childCost) / vol; 1599 1598 … … 2171 2170 /** Get costs resulting from each merge step. 2172 2171 */ 2173 void 2174 ViewCellsTree::GetCostFunction(vector<float> &costFunction) 2175 { 2176 TraversalQueue tqueue; 2177 tqueue.push(mRoot); 2178 2179 while (!tqueue.empty()) 2180 { 2181 ViewCell *vc = tqueue.top(); 2182 tqueue.pop(); 2183 // save the view cells if it is a leaf or if enough view cells have already been traversed 2184 // because of the priority queue, this will be the optimal set of v 2185 if (!vc->IsLeaf()) { 2186 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 2187 costFunction.push_back(interior->GetMergeCost()); 2172 void ViewCellsTree::GetCostFunction(vector<float> &costFunction) 2173 { 2174 TraversalQueue tqueue; 2175 tqueue.push(mRoot); 2176 2177 int numViewCells = 1; 2178 2179 const float vol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 2180 const int rootPvs = GetPvsSize(mRoot); 2181 2182 float totalRenderCost; 2183 2184 int totalPvs = rootPvs; 2185 totalRenderCost = (float)rootPvs; 2186 2187 costFunction.push_back(totalRenderCost); 2188 2189 //-- go through tree in the order of render cost decrease 2190 //-- which is the same order as the view cells were merged 2191 //-- or the reverse order of subdivision for subdivision-only 2192 //-- view cell hierarchies. 2193 2194 while (!tqueue.empty()) 2195 { 2196 ViewCell *vc = tqueue.top(); 2197 tqueue.pop(); 2198 2199 if (!vc->IsLeaf()) 2200 { 2201 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 2202 2203 const int parentPvs = GetPvsSize(interior); 2204 const float parentCost = (float)parentPvs * interior->GetVolume(); 2205 2206 -- numViewCells; 2207 2208 float childCost = 0; 2209 int childPvs = 0; 2210 2211 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 2212 2213 for (it = interior->mChildren.begin(); it != it_end; ++ it) 2214 { 2215 ViewCell *vc = *it; 2216 2217 const int pvsSize = GetPvsSize(vc); 2218 2219 childCost += (float) pvsSize * vc->GetVolume(); 2220 childPvs += pvsSize; 2221 2222 tqueue.push(vc); 2223 ++ numViewCells; 2224 } 2225 2226 // update stats for this view cell 2227 const float costDecr = (parentCost - childCost) / vol; 2228 totalRenderCost -= costDecr; 2229 const float expectedCost = totalRenderCost ;/// (float)numViewCells; 2188 2230 2189 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 2190 2191 for (it = interior->mChildren.begin(); it != it_end; ++ it) { 2192 tqueue.push(*it); 2193 } 2194 2195 } 2196 } 2197 } 2231 costFunction.push_back(expectedCost); 2232 } 2233 } 2234 } 2235 2236 2237 /** Get storage costs resulting from each merge step. 2238 */ 2239 void ViewCellsTree::GetStorageFunction(vector<int> &storageFunction) 2240 { 2241 TraversalQueue tqueue; 2242 tqueue.push(mRoot); 2243 2244 int numViewCells = 1; 2245 2246 const float vol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 2247 const int rootEntries = GetPvsEntries(mRoot); 2248 2249 int entriesInPvs = rootEntries; 2250 const int entryStorage = 1;//sizeof(PvsData) + sizeof(int); // one entry into the pvs 2251 2252 storageFunction.push_back(rootEntries); 2253 2254 //////////// 2255 //-- go through tree in the order of render cost decrease 2256 //-- which is the same order as the view cells were merged 2257 //-- or the reverse order of subdivision for subdivision-only 2258 //-- view cell hierarchies. 2259 2260 while (!tqueue.empty()) 2261 { 2262 ViewCell *vc = tqueue.top(); 2263 tqueue.pop(); 2264 2265 if (!vc->IsLeaf()) 2266 { 2267 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 2268 2269 const int parentPvs = GetPvsSize(interior); 2270 const int parentPvsEntries = GetPvsEntries(interior); 2271 const float parentCost = (float)parentPvs * interior->GetVolume(); 2272 2273 float childCost = 0; 2274 int childPvs = 0; 2275 int childPvsEntries = 0; 2276 2277 -- numViewCells; 2278 2279 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 2280 2281 for (it = interior->mChildren.begin(); it != it_end; ++ it) 2282 { 2283 ViewCell *vc = *it; 2284 2285 //const int pvsSize = GetPvsSize(vc); 2286 const int pvsEntries = GetPvsEntries(vc); 2287 2288 //childPvs += pvsSize; 2289 childPvsEntries += pvsEntries; 2290 2291 tqueue.push(vc); 2292 ++ numViewCells; 2293 } 2294 2295 // update stats for this view cell 2296 const float costDecr = (parentCost - childCost) / vol; 2297 2298 //totalPvs += childPvs - parentPvs; 2299 entriesInPvs += childPvsEntries - parentPvsEntries; 2300 2301 const int storageCost = entriesInPvs * entryStorage; 2302 storageFunction.push_back(storageCost); 2303 } 2304 } 2305 } 2306 2198 2307 2199 2308 … … 2358 2467 } 2359 2468 2469 2470 2360 2471 /**************************************************************************/ 2361 2472 /* MergeCandidate implementation */ … … 2438 2549 2439 2550 2440 2441 2551 /************************************************************************/ 2442 2552 /* MergeStatistics implementation */ -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r1586 r1603 416 416 */ 417 417 void GetCostFunction(vector<float> &costFunction); 418 418 419 /** Returns storage cost resulting from each merge step. 420 */ 421 void GetStorageFunction(vector<int> &storageCost); 422 419 423 /** Returns optimal set of view cells for a given number of view cells. 420 424 */ … … 504 508 void SetViewCellsManager(ViewCellsManager *vcm); 505 509 510 void Update(); 506 511 507 512 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1594 r1603 258 258 259 259 260 bool ViewCellsManager::EqualToSpatialNode(ViewCell *viewCell) const261 {262 return false;263 }264 265 266 260 int ViewCellsManager::CastPassSamples(const int samplesPerPass, 267 261 const int sampleType, … … 851 845 852 846 // should directional sampling be used? 853 bool dirSamples = (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION); 847 bool dirSamples = 848 (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION); 854 849 855 850 cout << "reseting pvs ... "; … … 914 909 cout << "compute new statistics ... " << endl; 915 910 916 /////////////// 7911 /////////////// 917 912 //-- propagate pvs or pvs size information 918 913 … … 3948 3943 3949 3944 mColorCode = savedColorCode; 3950 3951 }3952 3953 3954 bool VspBspViewCellsManager::EqualToSpatialNode(ViewCell *viewCell) const3955 {3956 return GetSpatialNode(viewCell) != NULL;3957 }3958 3959 3960 BspNode *VspBspViewCellsManager::GetSpatialNode(ViewCell *viewCell) const3961 {3962 if (!viewCell->IsLeaf())3963 {3964 BspViewCell *bspVc = dynamic_cast<BspViewCell *>(viewCell);3965 return bspVc->mLeaves[0];3966 }3967 else3968 {3969 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(viewCell);3970 3971 // cannot be node of binary tree3972 if (interior->mChildren.size() != 2)3973 return NULL;3974 3975 ViewCell *left = interior->mChildren[0];3976 ViewCell *right = interior->mChildren[1];3977 3978 BspNode *leftNode = GetSpatialNode(left);3979 BspNode *rightNode = GetSpatialNode(right);3980 3981 if (leftNode && rightNode && leftNode->IsSibling(rightNode))3982 {3983 return leftNode->GetParent();3984 }3985 }3986 3987 return NULL;3988 3945 } 3989 3946 … … 5713 5670 cout << "finished" << endl; 5714 5671 5672 vector<int> storageFunc; 5673 mViewCellsTree->GetStorageFunction(storageFunc); 5674 5675 vector<float> costFunc; 5676 mViewCellsTree->GetCostFunction(costFunc); 5677 5678 ofstream outstr("out.txt"); 5679 5680 for (int i = 0; i < storageFunc.size(); ++ i) 5681 outstr << i << ": " << storageFunc[i] << endl; 5682 outstr << endl; 5683 for (int i = 0; i < costFunc.size(); ++ i) 5684 outstr << i << ": " << costFunc[i] << endl; 5715 5685 if (0) 5716 5686 for (int i = 0; i <50; ++ i) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1582 r1603 479 479 ////////////////////////////////////////////////////////////////// 480 480 481 482 /** Returns true if the view cell is equivalent to a483 node of the spatial hierarchy. This function can be used for merged484 view cell.485 e.g. to see if the spatial tree can be reduced on this location486 note: not implemented487 */488 virtual bool EqualToSpatialNode(ViewCell *viewCell) const;489 490 481 /** If true, the kd nodes are stored instead of the object pvs. 491 482 */ … … 966 957 void CollectMergeCandidates(const VssRayContainer &rays, vector<MergeCandidate> &candidates); 967 958 968 /** Returns true if this view cell is equivavalent to a spatial node.969 */970 bool EqualToSpatialNode(ViewCell *viewCell) const;971 972 973 959 void ExportSingleViewCells( 974 960 const ObjectContainer &objects, … … 986 972 int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 987 973 988 /** Returns node of the spatial hierarchy corresponding to the view cell989 if such a node exists.990 */991 BspNode *GetSpatialNode(ViewCell *viewCell) const;992 993 974 /** Merges view cells according to some criteria 994 975 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1586 r1603 17 17 #include "ViewCellsManager.h" 18 18 #include "Beam.h" 19 #include "IntersectableWrapper.h" 19 20 20 21 … … 243 244 MeshInstance *parent) 244 245 { 246 if (!mesh) 247 return 0; 248 245 249 FaceContainer::const_iterator fi; 246 250 … … 260 264 } 261 265 } 266 262 267 return (int)mesh->mFaces.size(); 263 268 } … … 268 273 int maxObjects) 269 274 { 270 int limit = (maxObjects > 0) ?275 const int limit = (maxObjects > 0) ? 271 276 Min((int)viewCells.size(), maxObjects) : (int)viewCells.size(); 272 277 … … 277 282 Mesh *mesh = viewCells[i]->GetMesh(); 278 283 if (mesh) 279 { // //copy the mesh into polygons and add to BSP tree aabb284 { // copy the mesh into polygons and add to BSP tree aabb 280 285 mBoundingBox.Include(viewCells[i]->GetBox()); 281 286 polysSize += AddMeshToPolygons(mesh, … … 293 298 int maxObjects) 294 299 { 295 int limit = (maxObjects > 0) ?300 const int limit = (maxObjects > 0) ? 296 301 Min((int)objects.size(), maxObjects) : (int)objects.size(); 297 302 … … 305 310 case Intersectable::MESH_INSTANCE: 306 311 mesh = dynamic_cast<MeshInstance *>(object)->GetMesh(); 312 AddMeshToPolygons(mesh, polys, NULL); 307 313 break; 308 314 case Intersectable::VIEW_CELL: 309 315 mesh = dynamic_cast<ViewCell *>(object)->GetMesh(); 316 AddMeshToPolygons(mesh, polys, NULL); 310 317 break; 311 318 case Intersectable::TRANSFORMED_MESH_INSTANCE: 312 319 { 313 TransformedMeshInstance *mi = dynamic_cast<TransformedMeshInstance *>(object); 314 315 if (!mi->GetMesh()) 316 break; 317 mesh = new Mesh(); 318 mi->GetTransformedMesh(*mesh); 319 320 TransformedMeshInstance *mi = 321 dynamic_cast<TransformedMeshInstance *>(object); 322 323 Mesh mesh; 324 mi->GetTransformedMesh(mesh); 325 AddMeshToPolygons(&mesh, polys, NULL); 320 326 break; 321 327 } 328 case Intersectable::TRIANGLE_INTERSECTABLE: 329 { 330 TriangleIntersectable *intersect = 331 dynamic_cast<TriangleIntersectable *>(object); 332 333 Polygon3 *poly = new Polygon3(intersect->GetItem()); 334 335 if (poly->Valid(mEpsilon)) 336 polys.push_back(poly); 337 else 338 delete poly; 339 } 322 340 default: 323 Debug << "intersectable type not supported" << endl;341 Debug << "intersectable type not supported" << endl; 324 342 break; 325 343 } 326 344 327 if (mesh) // copy the mesh data to polygons 328 { 329 mBoundingBox.Include(object->GetBox()); // add to BSP tree aabb 330 AddMeshToPolygons(mesh, polys, NULL); 331 332 // cleanup 333 if (object->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 334 DEL_PTR(mesh); 335 } 345 mBoundingBox.Include(object->GetBox()); // add to BSP tree aabb 336 346 } 337 347 … … 413 423 } 414 424 break; 425 415 426 case Intersectable::MESH_INSTANCE: 416 427 { … … 419 430 } 420 431 break; 432 421 433 case Intersectable::TRIANGLE_INTERSECTABLE: 422 434 { 423 // TODO 424 cout << "not implemented yet" << endl; 435 TriangleIntersectable *intersect = 436 dynamic_cast<TriangleIntersectable *>(obj); 437 438 Polygon3 *poly = new Polygon3(intersect->GetItem()); 439 440 if (poly->Valid(mEpsilon)) 441 polys.push_back(poly); 442 else 443 delete poly; 425 444 } 445 break; 446 426 447 default: 448 cout << "not implemented yet" << endl; 427 449 break; 428 450 } … … 430 452 ++ numObj; 431 453 454 ///////// 432 455 //-- compute bounding box 456 433 457 if (!forcedBoundingBox) 458 { 434 459 mBoundingBox.Include(ray->mTermination); 460 } 435 461 } 436 462
Note: See TracChangeset
for help on using the changeset viewer.