- Timestamp:
- 11/07/05 11:27:38 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
r374 r386 48 48 // - components*mWidth; 49 49 50 vector<Ray > rays;50 vector<Ray *> rays; 51 51 52 52 long t1 = GetTime(); … … 74 74 pbuffer+=components; 75 75 76 if (exportRays && (x==222) && (y==97)) 77 rays.push_back(ray); 76 if (exportRays && (x==222) && (y==97)) { 77 Ray *nray = new Ray(ray); 78 rays.push_back(nray); 79 } 78 80 } 79 81 // pbuffer-=2*components*mWidth; … … 97 99 exporter->SetWireframe(); 98 100 exporter->ExportKdTree(*tree); 99 //exporter->ExportBspTree(*bsptree);101 //exporter->ExportBspTree(*bsptree); 100 102 exporter->ExportRays(rays, 10000); 101 103 exporter->SetFilled(); 102 104 int k =0; 103 105 for (int j=0; j < rays.size(); j++) 104 if (rays[j] .kdLeaves.size()) {105 Ray *ray = &(rays[j]);106 int i;107 if (1)108 for (i= 0; i < ray->kdLeaves.size(); i++)109 110 if (0)111 for (i= 0; i < ray->testedObjects.size(); i++)112 exporter->ExportIntersectable(ray->testedObjects[i]);113 106 if (rays[j]->kdLeaves.size()) { 107 Ray *ray = rays[j]; 108 int i; 109 if (1) 110 for (i= 0; i < ray->kdLeaves.size(); i++) 111 exporter->ExportBox(tree->GetBox(ray->kdLeaves[i])); 112 if (0) 113 for (i= 0; i < ray->testedObjects.size(); i++) 114 exporter->ExportIntersectable(ray->testedObjects[i]); 115 114 116 } 115 117 116 118 delete exporter; 117 119 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.h
r312 r386 42 42 } 43 43 44 void SetDirection(const Vector3 &dir) { 45 mDirection = dir; 46 Precompute(); 47 } 48 44 49 void LookInBox(const AxisAlignedBox3 &box) 45 50 { -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r383 r386 8 8 #include "Material.h" 9 9 #include "Containers.h" 10 #include "VssRay.h" 10 11 11 12 class KdTree; … … 49 50 ExportBspTree(const BspTree &tree) = 0; 50 51 51 virtual bool52 ExportRays(const vector<Ray> &rays,53 const float length=1000,54 const RgbColor &color = RgbColor(1,1,1)55 ) = 0;52 // virtual bool 53 // ExportRays(const vector<Ray> &rays, 54 // const float length=1000, 55 // const RgbColor &color = RgbColor(1,1,1) 56 // ) = 0; 56 57 57 58 virtual bool 58 59 ExportRays(const RayContainer &rays, 59 const float length=1000, 60 const RgbColor &color = RgbColor(1,1,1) 61 ) = 0; 60 const float length=1000, 61 const RgbColor &color = RgbColor(1,1,1) 62 ) = 0; 63 64 virtual bool 65 ExportRays(const VssRayContainer &rays, 66 const RgbColor &color = RgbColor(1,1,1) 67 ) = 0; 62 68 63 69 virtual void -
trunk/VUT/GtpVisibilityPreprocessor/src/Material.h
r162 r386 32 32 { 33 33 } 34 34 35 Material(const RgbColor &color):mDiffuseColor(color), 36 mAmbientColor(color), 37 mSpecularColor(0,0,0) 38 { 39 } 40 35 41 friend Material RandomMaterial(); 36 42 -
trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.cpp
r359 r386 529 529 mesh->AddRectangle(shaft->mSource); 530 530 mesh->AddRectangle(shaft->mTarget); 531 vector<Ray > rays;531 vector<Ray *> rays; 532 532 for (int j=0; j < 4; j++) { 533 Ray ray;534 shaft->GetRaySegment(j, ray);533 Ray *ray = new Ray; 534 shaft->GetRaySegment(j, *ray); 535 535 rays.push_back(ray); 536 536 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r385 r386 386 386 int pvsOut = Min((int)objects.size(), 10); 387 387 388 vector<Ray>rays[10];388 RayContainer rays[10]; 389 389 390 390 while (totalSamples < mTotalSamples) { … … 455 455 } 456 456 457 if ( i < pvsOut ) 458 rays[i].push_back(ray); 457 if ( i < pvsOut ) { 458 Ray *nray = new Ray(ray); 459 rays[i].push_back(nray); 460 } 459 461 460 462 if (!ray.intersections.empty()) { … … 462 464 for (int j = 0; j < pvsOut; j++) { 463 465 if (objects[j] == ray.intersections[0].mObject) { 464 rays[j].push_back(ray); 466 Ray *nray = new Ray(ray); 467 rays[j].push_back(nray); 465 468 } 466 469 } … … 635 638 636 639 for (i=0; i < pvsOut; i++) 637 exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0));640 exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0)); 638 641 exporter->SetFilled(); 639 642 640 643 delete exporter; 641 644 } … … 833 836 //-- some random view cells and rays for output 834 837 const int raysOut = min((int)mSampleRays.size(), 20000); 835 vector<Ray > vcRays[leafOut];838 vector<Ray *> vcRays[leafOut]; 836 839 vector<BspLeaf *> bspLeaves; 837 840 for (int i = 0; i < leafOut; ++ i) … … 852 855 if (bspLeaves[i]->GetViewCell() == leaf->GetViewCell()) 853 856 { 854 vcRays[i].push_back( *ray);857 vcRays[i].push_back(ray); 855 858 } 856 859 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r383 r386 36 36 } 37 37 38 VssRay * 38 int 39 39 VssPreprocessor::CastRay( 40 40 Vector3 &viewPoint, … … 42 42 ) 43 43 { 44 int hits = 0; 44 45 static Ray ray; 45 46 AxisAlignedBox3 box = mKdTree->GetBox(); … … 65 66 66 67 } 67 68 SetupRay(ray, viewPoint, -direction); 68 69 bool detectEmptyViewSpace = true; 70 71 if (detectEmptyViewSpace) { 72 SetupRay(ray, pointA, -direction); 73 } else 74 SetupRay(ray, viewPoint, -direction); 75 69 76 70 77 if (mKdTree->CastRay(ray)) { … … 84 91 85 92 VssRay *vssRay = NULL; 86 87 if (objectA || objectB) { 93 94 if (objectA) { 95 vssRay = new VssRay(pointB, 96 pointA, 97 objectB, 98 objectA); 99 mVssRays.push_back(vssRay); 100 hits ++; 101 } 102 103 if (objectB) { 88 104 vssRay = new VssRay(pointA, 89 105 pointB, 90 106 objectA, 91 107 objectB); 92 } 93 94 return vssRay; 108 mVssRays.push_back(vssRay); 109 hits ++; 110 111 } 112 113 return hits; 95 114 } 96 115 … … 156 175 Vector3 direction = GetDirection(viewpoint); 157 176 158 VssRay *vssRay = CastRay(viewpoint, direction); 159 160 if (vssRay) { 161 sampleContributions = vssRay->HitCount(); 162 mVssRays.push_back(vssRay); 163 } 177 sampleContributions = CastRay(viewpoint, direction); 178 164 179 165 180 //-- CORR matt: put block inside loop … … 198 213 cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush; 199 214 215 cout<<"Exporting vss rays..."<<endl<<flush; 216 217 int exportRays = 10000; 218 219 if (exportRays) { 220 float prob = exportRays/(float)mVssRays.size(); 221 222 Exporter *exporter = NULL; 223 exporter = Exporter::GetExporter("vss-rays.x3d"); 224 exporter->SetWireframe(); 225 exporter->ExportKdTree(*mKdTree); 226 if (viewSpaceBox) { 227 exporter->SetForcedMaterial(RgbColor(1,0,0)); 228 exporter->ExportBox(*viewSpaceBox); 229 exporter->ResetForcedMaterial(); 230 } 231 VssRayContainer rays; 232 for (int i=0; i < mVssRays.size(); i++) 233 if (RandomValue(0,1) < prob) 234 rays.push_back(mVssRays[i]); 235 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 236 237 delete exporter; 238 } 239 cout<<"done."<<endl<<flush; 240 200 241 VssTree *vssTree = new VssTree; 201 242 202 243 vssTree->Construct(mVssRays, viewSpaceBox); 203 244 245 246 247 204 248 return true; 205 249 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
r382 r386 41 41 42 42 43 VssRay *43 int 44 44 CastRay( 45 45 Vector3 &viewPoint, -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
r382 r386 39 39 Vector3 mTermination; 40 40 41 /// Termination object for the ray 42 /// only the termination object is actually used 41 43 Intersectable *mOriginObject; 42 44 Intersectable *mTerminationObject; … … 62 64 Vector3 dir = GetDir(); 63 65 66 #define BIDIRECTIONAL_RAY 0 67 #if BIDIRECTIONAL_RAY 64 68 if (dir.y < 0) { 65 69 // swap objects and poits … … 68 72 dir = -dir; 69 73 } 70 74 #endif 71 75 if (dir.x > 0.0f) mFlags |= FPosDirX; 72 76 if (dir.y > 0.0f) mFlags |= FPosDirY; … … 85 89 86 90 int HitCount() const { 91 #if BIDIRECTIONAL_RAY 87 92 if (mOriginObject && mTerminationObject) 88 93 return 2; … … 90 95 return 1; 91 96 return 0; 97 #else 98 return (mTerminationObject) ? 1 : 0; 99 #endif 92 100 } 93 101 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
r382 r386 109 109 splitType = ESplitRegular; 110 110 else 111 if (name.compare("heuristic s") == 0)112 splitType = ESplit Volume;111 if (name.compare("heuristic") == 0) 112 splitType = ESplitHeuristic; 113 113 else { 114 114 cerr<<"Invalid VssTree split type "<<name<<endl; … … 301 301 302 302 303 int lastMem = 0; 303 304 while (!tStack.empty()) { 304 305 305 if ( GetMemUsage() > maxMemory ) { 306 float mem = GetMemUsage(); 307 308 if ( lastMem/10 != ((int)mem)/10) { 309 cout<<mem<<" MB"<<endl; 310 } 311 lastMem = (int)mem; 312 313 if ( mem > maxMemory ) { 306 314 // count statistics on unprocessed leafs 307 315 while (!tStack.empty()) { … … 411 419 412 420 } else { 413 if (splitType == ESplitVolume) 414 costRatio = BestCostRatio(leaf, 415 axis, 416 position, 417 raysBack, 418 raysFront); 421 if (splitType == ESplitHeuristic) 422 costRatio = BestCostRatioHeuristic(leaf, 423 axis, 424 position, 425 raysBack, 426 raysFront, 427 pvsBack, 428 pvsFront 429 ); 419 430 else { 420 431 cerr<<"VssTree: Unknown split heuristics\n"; … … 424 435 425 436 if (costRatio > termMaxCostRatio) { 426 cout<<"Too big cost ratio "<<costRatio<<endl;437 // cout<<"Too big cost ratio "<<costRatio<<endl; 427 438 return -1; 428 439 } … … 485 496 raysFront++; 486 497 498 #if BIDIRECTIONAL_RAY 487 499 AddObject2Pvs((*ri).mRay->mOriginObject, side, pvsBack, pvsFront); 500 #endif 488 501 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 489 502 … … 524 537 // (*ri).mRay->mSide = side; 525 538 539 #if BIDIRECTIONAL_RAY 526 540 AddObject2Pvs((*ri).mRay->mOriginObject, side, pvsBack, pvsFront); 541 #endif 527 542 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 528 543 … … 550 565 551 566 float 552 VssTree::BestCostRatio( 553 VssTreeLeaf *node, 554 int &axis, 555 float &position, 556 int &raysBack, 557 int &raysFront 558 ) 567 VssTree::BestCostRatioRegular( 568 VssTreeLeaf *node, 569 int &axis, 570 float &position, 571 int &raysBack, 572 int &raysFront, 573 int &pvsBack, 574 int &pvsFront 575 576 ) 577 { 578 579 return 0; 580 } 581 582 float 583 VssTree::BestCostRatioHeuristic( 584 VssTreeLeaf *node, 585 int &axis, 586 float &position, 587 int &raysBack, 588 int &raysFront, 589 int &pvsBack, 590 int &pvsFront 591 ) 559 592 { 560 593 AxisAlignedBox3 box = GetBBox(node); -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
r382 r386 463 463 VssTreeLeaf *leafa = (VssTreeLeaf *) a.node; 464 464 VssTreeLeaf *leafb = (VssTreeLeaf *) b.node; 465 // return leafa->rays.size()*a.bbox.GetVolume() < leafb->rays.size()*b.bbox.GetVolume(); 466 return 465 #if 0 466 return 467 467 leafa->rays.size()*a.bbox.GetVolume() 468 468 < 469 469 leafb->rays.size()*b.bbox.GetVolume(); 470 #endif 471 #if 0 472 return 473 leafa->mPvsSize*a.bbox.GetVolume()* 474 < 475 leafb->mPvsSize*b.bbox.GetVolume(); 476 #endif 477 #if 0 478 return 479 leafa->mPvsSize 480 < 481 leafb->mPvsSize; 482 #endif 483 #if 1 484 return 485 leafa->mPvsSize/(leafa->rays.size()+1) 486 > 487 leafb->mPvsSize/(leafb->rays.size()+1); 488 #endif 489 #if o 490 return 491 leafa->mPvsSize*leafa->rays.size() 492 < 493 leafb->mPvsSize*leafb->rays.size(); 494 #endif 470 495 } 471 496 }; … … 527 552 528 553 // type of the splitting to use fo rthe tree construction 529 enum {ESplitRegular, ESplit Volume};554 enum {ESplitRegular, ESplitHeuristic }; 530 555 int splitType; 531 556 … … 620 645 621 646 float 622 BestCostRatio( 623 VssTreeLeaf *node, 624 int &axis, 625 float &position, 626 int &raysBack, 627 int &raysFront 628 ); 647 BestCostRatioHeuristic( 648 VssTreeLeaf *node, 649 int &axis, 650 float &position, 651 int &raysBack, 652 int &raysFront, 653 int &pvsBack, 654 int &pvsFront 655 ); 656 657 float 658 BestCostRatioRegular( 659 VssTreeLeaf *node, 660 int &axis, 661 float &position, 662 int &raysBack, 663 int &raysFront, 664 int &pvsBack, 665 int &pvsFront 666 667 ); 629 668 630 669 float -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r383 r386 8 8 #include "ViewCell.h" 9 9 #include "Polygon3.h" 10 #include "VssRay.h" 10 11 11 12 X3dExporter::X3dExporter(const string filename):Exporter(filename) … … 26 27 27 28 28 bool29 X3dExporter::ExportRays(const vector<Ray> &rays,30 const float length,31 const RgbColor &color)32 {33 vector<Ray>::const_iterator ri = rays.begin();34 stream<<"<Shape>"<<endl;35 stream<<"<Appearance>"<<endl;36 stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<<37 "\" />"<<endl;38 stream<<"</Appearance>"<<endl;39 40 stream<<"<IndexedLineSet coordIndex=\""<<endl;41 42 int index = 0;43 for (; ri != rays.end(); ri++) {44 stream<<index<<" "<<index+1<<" -1\n";45 index+=2;46 }47 48 stream<<"\" >"<<endl;49 50 stream<<"<Coordinate point=\""<<endl;51 52 ri = rays.begin();53 for (; ri != rays.end(); ri++) {54 Vector3 a = (*ri).GetLoc();29 // bool 30 // X3dExporter::ExportRays(const vector<Ray> &rays, 31 // const float length, 32 // const RgbColor &color) 33 // { 34 // vector<Ray>::const_iterator ri = rays.begin(); 35 // stream<<"<Shape>"<<endl; 36 // stream<<"<Appearance>"<<endl; 37 // stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<< 38 // "\" />"<<endl; 39 // stream<<"</Appearance>"<<endl; 40 41 // stream<<"<IndexedLineSet coordIndex=\""<<endl; 42 43 // int index = 0; 44 // for (; ri != rays.end(); ri++) { 45 // stream<<index<<" "<<index+1<<" -1\n"; 46 // index+=2; 47 // } 48 49 // stream<<"\" >"<<endl; 50 51 // stream<<"<Coordinate point=\""<<endl; 52 53 // ri = rays.begin(); 54 // for (; ri != rays.end(); ri++) { 55 // Vector3 a = (*ri).GetLoc(); 55 56 56 Vector3 b;57 if (length < 0)58 b = (*ri).GetLoc() - length*(*ri).GetDir();59 else60 if ((*ri).intersections.size()==0)61 b = (*ri).GetLoc() + length*(*ri).GetDir();62 else63 b = (*ri).Extrap((*ri).intersections[0].mT);57 // Vector3 b; 58 // if (length < 0) 59 // b = (*ri).GetLoc() - length*(*ri).GetDir(); 60 // else 61 // if ((*ri).intersections.size()==0) 62 // b = (*ri).GetLoc() + length*(*ri).GetDir(); 63 // else 64 // b = (*ri).Extrap((*ri).intersections[0].mT); 64 65 65 stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,"; 66 stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n"; 67 } 68 69 stream<<"\" >"<<endl; 70 stream<<"</Coordinate>"<<endl; 71 stream<<"</IndexedLineSet>"<<endl; 72 stream<<"</Shape>"<<endl; 73 return true; 74 } 66 // stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,"; 67 // stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n"; 68 // } 69 70 // stream<<"\" >"<<endl; 71 // stream<<"</Coordinate>"<<endl; 72 // stream<<"</IndexedLineSet>"<<endl; 73 // stream<<"</Shape>"<<endl; 74 // return true; 75 // } 76 75 77 76 78 bool 77 79 X3dExporter::ExportRays(const RayContainer &rays, 78 const float length,79 const RgbColor &color)80 const float length, 81 const RgbColor &color) 80 82 { 81 83 RayContainer::const_iterator ri = rays.begin(); … … 121 123 stream<<"</Shape>"<<endl; 122 124 125 return true; 126 } 127 128 bool 129 X3dExporter::ExportRays(const VssRayContainer &rays, 130 const RgbColor &color) 131 { 132 VssRayContainer::const_iterator ri = rays.begin(); 133 134 stream<<"<Shape>"<<endl; 135 stream<<"<Appearance>"<<endl; 136 stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<< 137 "\" />"<<endl; 138 stream<<"</Appearance>"<<endl; 139 140 stream<<"<IndexedLineSet coordIndex=\""<<endl; 141 142 int index = 0; 143 for (; ri != rays.end(); ri++) { 144 stream<<index<<" "<<index+1<<" -1\n"; 145 index+=2; 146 } 147 148 stream<<"\" >"<<endl; 149 150 stream<<"<Coordinate point=\""<<endl; 151 152 ri = rays.begin(); 153 for (; ri != rays.end(); ri++) { 154 Vector3 a = (*ri)->GetOrigin(); 155 156 Vector3 b = (*ri)->GetTermination(); 157 stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,"; 158 stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n"; 159 } 160 161 stream<<"\" >"<<endl; 162 stream<<"</Coordinate>"<<endl; 163 stream<<"</IndexedLineSet>"<<endl; 164 stream<<"</Shape>"<<endl; 165 123 166 return true; 124 167 } -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r383 r386 10 10 #include "Exporter.h" 11 11 #include "Containers.h" 12 #include "VssRay.h" 12 13 13 14 class SceneGraphNode; … … 30 31 31 32 32 bool33 ExportRays(const vector<Ray> &rays,34 const float length=1000,35 const RgbColor &color = RgbColor(1,1,1));33 // bool 34 // ExportRays(const vector<Ray> &rays, 35 // const float length=1000, 36 // const RgbColor &color = RgbColor(1,1,1)); 36 37 37 38 bool … … 82 83 bool 83 84 ExportRays(const RayContainer &rays, 84 const float length=1000,85 const RgbColor &color = RgbColor(1,1,1));85 const float length=1000, 86 const RgbColor &color = RgbColor(1,1,1)); 86 87 88 bool 89 ExportRays(const VssRayContainer &rays, 90 const RgbColor &color = RgbColor(1,1,1)); 91 87 92 virtual void 88 93 ExportBspViewCellPartition(const BspTree &tree, const int maxPvs = 0); -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r382 r386 11 11 # filename ../data/vienna/vienna-buildings.x3d 12 12 # filename ../data/vienna/viewcells-25-sel.x3d 13 #filename ../data/atlanta/atlanta2.x3d14 # 15 filename ../data/soda/soda5.dat13 filename ../data/atlanta/atlanta2.x3d 14 # filename ../data/soda/soda.dat 15 # filename ../data/soda/soda5.dat 16 16 } 17 17 … … 22 22 23 23 VssPreprocessor { 24 totalSamples 20000024 totalSamples 1000000 25 25 samplesPerPass 50000 26 26 } … … 32 32 minPvs 10 33 33 minSize 0.00001 34 maxCostRatio 1.035 maxRayContribution 0. 534 maxCostRatio 0.95 35 maxRayContribution 0.2 36 36 37 maxTotalMemory 50038 maxStaticMemory 20 037 maxTotalMemory 400 38 maxStaticMemory 20 39 39 40 40 splitType regular -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r374 r386 121 121 } 122 122 123 Camera camera; 123 124 if (0) { 124 Camera camera;125 125 //camera.LookAtBox(p->mKdTree->GetBox()); 126 126 camera.LookInBox(p->mKdTree->GetBox()); 127 127 camera.SetPosition(camera.mPosition + Vector3(0,300,0)); 128 128 camera.SnapImage("camera.jpg", p->mKdTree); 129 130 129 } 130 if (0) { 131 131 camera.LookInBox(p->mKdTree->GetBox()); 132 132 camera.SetPosition(camera.mPosition - Vector3(0,100,0)); 133 133 camera.SnapImage("camera2.jpg", p->mKdTree); 134 } 135 136 if (0) { 137 camera.SetPosition( p->mKdTree->GetBox().Center() - Vector3(0,-100,0) ); 138 camera.SetDirection(Vector3(1, 0, 0)); 139 camera.SnapImage("camera3.jpg", p->mKdTree); 134 140 } 135 141
Note: See TracChangeset
for help on using the changeset viewer.