Changeset 486 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 12/30/05 16:37:41 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r485 r486 146 146 loadFromFile false 147 147 #type kdTree 148 type vspKdTree148 #type vspKdTree 149 149 #type bspTree 150 #type vspBspTree150 type vspBspTree 151 151 152 152 #type sceneDependent … … 217 217 PostProcess { 218 218 maxCostRatio 0.005 219 minViewCells 200219 minViewCells 100 220 220 maxPvsSize 50000 221 221 } … … 230 230 samples 300000 231 231 epsilon 0.005 232 randomize true 232 233 } 233 234 … … 282 283 PostProcess { 283 284 maxCostRatio 0.1 284 minViewCells 200285 minViewCells 100 285 286 maxPvsSize 500 286 287 useRaysForMerge false -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r482 r486 7 7 #include "Ray.h" 8 8 #include "Polygon3.h" 9 #include "Mesh.h" 9 10 10 11 #define FATAL Debug … … 1865 1866 } 1866 1867 1868 1869 void AxisAlignedBox3::AddBoxToMesh(Mesh *mesh) const 1870 { 1871 // add 6 vertices of the box 1872 int index = (int)mesh->mVertices.size(); 1873 1874 for (int i=0; i < 8; i++) 1875 { 1876 Vector3 v; 1877 GetVertex(i, v); 1878 mesh->mVertices.push_back(v); 1879 } 1880 1881 mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 1882 mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 1883 mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 1884 1885 mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 1886 mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 1887 mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 1888 1889 } -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r482 r486 9 9 class Ray; 10 10 class Polygon3; 11 11 class Mesh; 12 12 // -------------------------------------------------------- 13 13 // CAABox class. … … 329 329 const AxisAlignedBox3 &neighbour) const; 330 330 331 /** Adds the box faces to the mesh. 332 */ 333 void AddBoxToMesh(Mesh *mesh) const; 334 331 335 #define __EXTENT_HACK 332 336 // get the extent of face -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r485 r486 1751 1751 "vsp_bsp_term_post_process_use_rays_for_merge=", 1752 1752 "false"); 1753 1753 1754 RegisterOption("VspBspTree.Construction.randomize", 1755 optBool, 1756 "vsp_bsp_construction_randomize=", 1757 "false"); 1754 1758 ////////////////////////////////////////////////////////////////////////////////// 1755 1759 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r482 r486 22 22 class VspBspTree; 23 23 class RssTree; 24 class Mesh; 24 25 25 26 class Exporter … … 109 110 ExportGeometry(const ObjectContainer &objects) = 0; 110 111 112 virtual void 113 ExportMesh(Mesh *mesh) = 0; 114 111 115 virtual bool 112 116 ExportRssTree2(const RssTree &tree, -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r485 r486 197 197 mGenerateViewCells(true) 198 198 { 199 200 199 201 Randomize(); // initialise random generator for heuristics 200 202 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r485 r486 90 90 int i = 0; 91 91 for (it = rays.begin(); it != it_end; ++ it) 92 { if ((i ++) % 50000 == 0) 93 cout << "Computed 50000 samples" << endl; 92 { Debug << "here " << i ++ << endl; 94 93 ComputeSampleContributions(*(*it)); 94 Debug << "**" << endl; 95 95 } 96 96 } … … 316 316 Ray hray(ray); 317 317 float tmin = 0, tmax = 1.0; 318 Debug << "here2" << endl;318 319 319 //hray.Init(ray.GetOrigin(), ray.GetDir(), Ray::LINE_SEGMENT); 320 320 if (!GetSceneBbox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) … … 344 344 345 345 ray.mRelativePvsContribution += contribution; 346 } Debug << "here5" << endl;346 } 347 347 } 348 348 … … 1340 1340 1341 1341 // collapse siblings belonging to the same view cell 1342 mVspKdTree->RefineViewCells( );1342 mVspKdTree->RefineViewCells(rays); 1343 1343 1344 1344 // evaluale view cell stats … … 1614 1614 vector<VspKdLeaf *>::const_iterator it, it_end = kdVc->mLeaves.end(); 1615 1615 1616 Mesh m; 1616 1617 for (it = kdVc->mLeaves.begin(); it != it_end; ++ it) 1617 exporter->ExportBox(mVspKdTree->GetBBox(*it)); 1618 { 1619 mVspKdTree->GetBBox(*it).AddBoxToMesh(&m); 1620 } 1621 1622 exporter->ExportMesh(&m); 1618 1623 } 1619 1624 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r485 r486 47 47 mOnlyDrivingAxis(false) 48 48 { 49 Randomize(); // initialise random generator for heuristics 49 bool randomize = false; 50 environment->GetBoolValue("VspBspTree.Construction.randomize", randomize); 51 if (randomize) 52 Randomize(); // initialise random generator for heuristics 50 53 51 54 //-- termination criteria for autopartition … … 96 99 Debug << "max polygon candidates: " << mMaxPolyCandidates << endl; 97 100 Debug << "max plane candidates: " << mMaxRayCandidates << endl; 101 Debug << "randomize: " << randomize << endl; 98 102 99 103 Debug << "Split plane strategy: "; … … 1904 1908 // find intersection of ray segment with plane 1905 1909 extp = splitPlane.FindIntersection(origin, extp, &t); 1910 //cout << "x"; 1906 1911 } 1907 1912 else 1908 1913 { 1914 //cout << "o"; 1909 1915 // reached leaf => intersection with view cell 1910 1916 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); … … 1931 1937 } 1932 1938 } 1933 1939 //cout << "!!!!!!!!!!!" << endl; 1934 1940 return hits; 1935 1941 } … … 2428 2434 BspViewCell *vc2) const 2429 2435 { 2430 //Debug << "old pvs: " << vc1->GetPvs().GetSize() + vc2->GetPvs().GetSize()2431 // << " (" << vc1->GetPvs().GetSize() << ", " << vc2->GetPvs().GetSize() << ")" << endl;2432 2436 // compute new pvs and area 2433 2437 vc1->GetPvs().SubtractPvs(*leaf->mPvs); … … 2455 2459 }*/ 2456 2460 2457 leaf->SetViewCell(vc2); 2461 leaf->SetViewCell(vc2); // finally change view cell 2458 2462 2459 2463 //Debug << "new pvs: " << vc1->GetPvs().GetSize() + vc2->GetPvs().GetSize() -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
r485 r486 529 529 Plane3 ChooseCandidatePlane3(const RayInfoContainer &rays) const; 530 530 531 /** Shuffles, i.e. takes border leaf from view cell 1 and adds it 532 to view cell 2. 533 */ 531 534 void ShuffleLeaf(BspLeaf *leaf, 532 535 BspViewCell *vc1, -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
r485 r486 179 179 180 180 181 /************************************************************** /182 /* class VspKdLeaf implementation*/183 /************************************************************** /181 /*******************************************************************/ 182 /* class VspKdLeaf implementation */ 183 /*******************************************************************/ 184 184 185 185 … … 2351 2351 2352 2352 2353 void VspKdTree::RefineViewCells() 2354 { 2355 //TODO 2356 } 2353 int VspKdTree::RefineViewCells(const VssRayContainer &rays) 2354 { 2355 int shuffled = 0; 2356 2357 Debug << "refining " << (int)mMergeQueue.size() << " candidates " << endl; 2358 BspLeaf::NewMail(); 2359 2360 // Use priority queue of remaining leaf pairs 2361 // These candidates either share the same view cells or 2362 // are border leaves which share a boundary. 2363 // We test if they can be shuffled, i.e., 2364 // either one leaf is made part of one view cell or the other 2365 // leaf is made part of the other view cell. It is tested if the 2366 // remaining view cells are "better" than the old ones. 2367 while (!mMergeQueue.empty()) 2368 { 2369 MergeCandidate mc = mMergeQueue.top(); 2370 mMergeQueue.pop(); 2371 2372 // both view cells equal or already shuffled 2373 if ((mc.GetLeaf1()->GetViewCell() == mc.GetLeaf2()->GetViewCell()) || 2374 (mc.GetLeaf1()->Mailed()) || (mc.GetLeaf2()->Mailed())) 2375 continue; 2376 2377 // candidate for shuffling 2378 const bool wasShuffled = false; 2379 //ShuffleLeaves(mc.GetLeaf1(), mc.GetLeaf2()); 2380 2381 //-- stats 2382 if (wasShuffled) 2383 ++ shuffled; 2384 } 2385 2386 return shuffled; 2387 } 2388 2389 2390 inline int AddedPvsSize(ObjectPvs pvs1, const ObjectPvs &pvs2) 2391 { 2392 return pvs1.AddPvs(pvs2); 2393 } 2394 2395 2396 inline int SubtractedPvsSize(ObjectPvs pvs1, const ObjectPvs &pvs2) 2397 { 2398 return pvs1.SubtractPvs(pvs2); 2399 } 2400 2401 2402 float GetShuffledVcCost(VspKdLeaf *leaf, VspKdViewCell *vc1, VspKdViewCell *vc2) 2403 { 2404 #if 0 // TODO 2405 const int pvs1 = SubtractedPvsSize(vc1->GetPvs(), *leaf->mPvs); 2406 const int pvs2 = AddedPvsSize(vc2->GetPvs(), *leaf->mPvs); 2407 2408 const float area1 = vc1->GetArea() - leaf->mArea; 2409 const float area2 = vc2->GetArea() + leaf->mArea; 2410 2411 const float cost1 = pvs1 * area1; 2412 const float cost2 = pvs2 * area2; 2413 2414 return cost1 + cost2; 2415 #else 2416 return -1; 2417 #endif 2418 } 2419 2420 2421 void VspKdTree::ShuffleLeaf(VspKdLeaf *leaf, 2422 VspKdViewCell *vc1, 2423 VspKdViewCell *vc2) const 2424 { 2425 #if 0 // TODO 2426 // compute new pvs and area 2427 vc1->GetPvs().SubtractPvs(*leaf->mPvs); 2428 vc2->GetPvs().AddPvs(*leaf->mPvs); 2429 2430 vc1->SetArea(vc1->GetArea() - leaf->mArea); 2431 vc2->SetArea(vc2->GetArea() + leaf->mArea); 2432 2433 /// add to second view cell 2434 vc2->mLeaves.push_back(leaf); 2435 2436 // erase leaf from old view cell 2437 vector<VspKdLeaf *>::iterator it = vc1->mLeaves.begin(); 2438 2439 for (; *it != leaf; ++ it); 2440 vc1->mLeaves.erase(it); 2441 2442 leaf->SetViewCell(vc2); // finally change view cell 2443 #endif 2444 } 2445 2446 2447 bool VspKdTree::ShuffleLeaves(VspKdLeaf *leaf1, VspKdLeaf *leaf2) const 2448 { 2449 VspKdViewCell *vc1 = leaf1->GetViewCell(); 2450 VspKdViewCell *vc2 = leaf2->GetViewCell(); 2451 2452 const float cost1 = vc1->GetPvs().GetSize() * vc1->GetArea(); 2453 const float cost2 = vc2->GetPvs().GetSize() * vc2->GetArea(); 2454 2455 const float oldCost = cost1 + cost2; 2456 2457 float shuffledCost1 = Limits::Infinity; 2458 float shuffledCost2 = Limits::Infinity; 2459 2460 // the view cell should not be empty after the shuffle 2461 if (vc1->mLeaves.size() > 1) 2462 shuffledCost1 = GetShuffledVcCost(leaf1, vc1, vc2); 2463 if (vc2->mLeaves.size() > 1) 2464 shuffledCost2 = GetShuffledVcCost(leaf2, vc2, vc1); 2465 2466 // shuffling unsuccessful 2467 if ((oldCost <= shuffledCost1) && (oldCost <= shuffledCost2)) 2468 return false; 2469 2470 if (shuffledCost1 < shuffledCost2) 2471 { 2472 ShuffleLeaf(leaf1, vc1, vc2); 2473 leaf1->Mail(); 2474 } 2475 else 2476 { 2477 ShuffleLeaf(leaf2, vc2, vc1); 2478 leaf2->Mail(); 2479 } 2480 2481 return true; 2482 } 2483 2484 2357 2485 2358 2486 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
r485 r486 603 603 */ 604 604 void CollectViewCells(ViewCellContainer &viewCells) const; 605 /** Refines view cells in a post processing step. 606 */ 607 void RefineViewCells(); 605 606 /** Refines view cells using shuffling, i.e., border leaves 607 of two view cells are exchanged if the resulting view cells 608 are tested to be "better" than the old ones. 609 @returns number of refined view cells 610 */ 611 int RefineViewCells(const VssRayContainer &rays); 608 612 609 613 /** Collects candidates for the merge in the merge queue. … … 726 730 void RepairVcLeafLists(); 727 731 732 /** Shuffles the leaves, i.e., tests if exchanging 733 the view cells the leaves belong to helps in improving the view cells. 734 */ 735 bool ShuffleLeaves(VspKdLeaf *leaf1, VspKdLeaf *leaf2) const; 736 737 /** Shuffles, i.e. takes border leaf from view cell 1 and adds it 738 to view cell 2. 739 */ 740 void ShuffleLeaf(VspKdLeaf *leaf, 741 VspKdViewCell *vc1, 742 VspKdViewCell *vc2) const; 728 743 protected: 729 744 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r483 r486 678 678 679 679 680 void 681 X3dExporter::AddBoxToMesh(const AxisAlignedBox3 &box, 682 Mesh *mesh) 683 { 684 // add 6 vertices of the box 685 int index = (int)mesh->mVertices.size(); 686 687 for (int i=0; i < 8; i++) { 688 Vector3 v; 689 box.GetVertex(i, v); 690 mesh->mVertices.push_back(v); 691 } 692 693 mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 694 mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 695 mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 696 697 mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 698 mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 699 mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 700 701 } 680 702 681 703 682 bool … … 726 705 AxisAlignedBox3 box; 727 706 box = tree.GetBBox(leaf); 728 AddBoxToMesh(box,mesh);707 box.AddBoxToMesh(mesh); 729 708 730 709 if (tree.ValidLeaf(leaf)) { … … 829 808 box = tree.GetBBox(leaf); 830 809 Mesh *mesh = new Mesh; 831 AddBoxToMesh(box,mesh);810 box.AddBoxToMesh(mesh); 832 811 833 812 // get 4 corners of the ray directions … … 1226 1205 box = tree.GetShrankedBBox(leaf); 1227 1206 Mesh *mesh = new Mesh; 1228 AddBoxToMesh(box,mesh);1207 box.AddBoxToMesh(mesh); 1229 1208 1230 1209 // get 4 corners of the ray directions -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r482 r486 133 133 ExportBspTreeRayDensity(const BspTree &tree); 134 134 135 void136 AddBoxToMesh(const AxisAlignedBox3 &box,137 Mesh *mesh);138 139 135 void ExportBspNodeSplits(BspNode *root, 140 136 const AxisAlignedBox3 &box,
Note: See TracChangeset
for help on using the changeset viewer.