- Timestamp:
- 11/22/05 20:51:37 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r426 r427 1160 1160 "1000000"); 1161 1161 1162 RegisterOption("VssPreprocessor.samplesPerPass", 1162 RegisterOption("VssPreprocessor.vssSamplesPerPass", 1163 optInt, 1164 "-vss_samples_per_pass=", 1165 "1000"); 1166 1167 RegisterOption("VssPreprocessor.samplesPerPass", 1163 1168 optInt, 1164 1169 "-samples_per_pass=", -
trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
r401 r427 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (1.07a) (Qt 3.3.2) on: Wed Nov 09 22:44:2520053 # Generated by qmake (1.07a) (Qt 3.3.2) on: Tue Nov 22 12:10:40 2005 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 74 74 VssRay.cpp \ 75 75 VssTree.cpp \ 76 VssPreprocessor.cpp 76 VssPreprocessor.cpp \ 77 RenderSimulator.cpp \ 78 VspKdTree.cpp \ 79 RayInfo.cpp 77 80 OBJECTS = Preprocessor.obj \ 78 81 SamplingPreprocessor.obj \ … … 107 110 VssRay.obj \ 108 111 VssTree.obj \ 109 VssPreprocessor.obj 112 VssPreprocessor.obj \ 113 RenderSimulator.obj \ 114 VspKdTree.obj \ 115 RayInfo.obj 110 116 FORMS = 111 117 UICDECLS = … … 202 208 -$(DEL_FILE) VssTree.obj 203 209 -$(DEL_FILE) VssPreprocessor.obj 210 -$(DEL_FILE) RenderSimulator.obj 211 -$(DEL_FILE) VspKdTree.obj 212 -$(DEL_FILE) RayInfo.obj 204 213 205 214 … … 220 229 ViewCell.h \ 221 230 Environment.h \ 222 Containers.h \ 223 AxisAlignedBox3.h \ 224 Rectangle3.h \ 225 Matrix4x4.h \ 226 Vector3.h \ 227 Plane3.h \ 228 common.h \ 229 Material.h \ 230 VssRay.h \ 231 RenderSimulator.h \ 232 Containers.h \ 233 AxisAlignedBox3.h \ 234 Rectangle3.h \ 235 Matrix4x4.h \ 236 Vector3.h \ 237 Plane3.h \ 238 common.h \ 239 Material.h \ 240 VssRay.h \ 241 Ray.h \ 231 242 Parser.h \ 232 243 Mesh.h \ 233 244 KdTree.h \ 234 245 ViewCellBsp.h \ 235 Intersectable.h \ 236 Pvs.h \ 237 Ray.h \ 238 Polygon3.h \ 246 VspKdTree.h \ 247 Intersectable.h \ 248 Pvs.h \ 249 Polygon3.h \ 250 Statistics.h \ 251 RayInfo.h \ 239 252 240 253 … … 248 261 Polygon3.h \ 249 262 ViewCell.h \ 263 RenderSimulator.h \ 250 264 Containers.h \ 251 265 AxisAlignedBox3.h \ … … 258 272 Pvs.h \ 259 273 Preprocessor.h \ 260 Mesh.h \ 261 ViewCellBsp.h \ 262 Intersectable.h \ 263 Material.h \ 264 Exporter.h \ 265 VssRay.h \ 274 VssRay.h \ 275 Mesh.h \ 276 ViewCellBsp.h \ 277 VspKdTree.h \ 278 Intersectable.h \ 279 Material.h \ 280 Statistics.h \ 281 RayInfo.h \ 282 Exporter.h \ 266 283 267 284 … … 274 291 ViewCellBsp.h \ 275 292 ViewCell.h \ 276 Intersectable.h \ 277 Plane3.h \ 278 Matrix4x4.h \ 279 AxisAlignedBox3.h \ 280 Material.h \ 281 Pvs.h \ 282 Rectangle3.h \ 283 Vector3.h \ 284 common.h \ 285 Ray.h \ 286 Polygon3.h \ 293 VspKdTree.h \ 294 Intersectable.h \ 295 Plane3.h \ 296 Matrix4x4.h \ 297 AxisAlignedBox3.h \ 298 Material.h \ 299 Pvs.h \ 300 Rectangle3.h \ 301 Vector3.h \ 302 common.h \ 303 Ray.h \ 304 Polygon3.h \ 305 Statistics.h \ 306 VssRay.h \ 307 RayInfo.h \ 287 308 288 309 … … 347 368 Polygon3.h \ 348 369 VssRay.h \ 349 Containers.h \ 350 AxisAlignedBox3.h \ 351 Rectangle3.h \ 352 Matrix4x4.h \ 353 Vector3.h \ 354 Plane3.h \ 355 Exporter.h \ 356 Material.h \ 357 Intersectable.h \ 358 Pvs.h \ 359 Ray.h \ 370 VspKdTree.h \ 371 Containers.h \ 372 AxisAlignedBox3.h \ 373 Rectangle3.h \ 374 Matrix4x4.h \ 375 Vector3.h \ 376 Plane3.h \ 377 Exporter.h \ 378 Material.h \ 379 Ray.h \ 380 Intersectable.h \ 381 Pvs.h \ 382 Statistics.h \ 383 RayInfo.h \ 360 384 361 385 … … 374 398 VssRay.h \ 375 399 Material.h \ 400 Ray.h \ 376 401 Pvs.h \ 377 402 … … 434 459 SceneGraph.h \ 435 460 Preprocessor.h \ 436 Containers.h \ 437 Mesh.h \ 438 KdTree.h \ 439 ViewCellBsp.h \ 440 Intersectable.h \ 441 Plane3.h \ 442 Matrix4x4.h \ 443 AxisAlignedBox3.h \ 444 Material.h \ 445 Pvs.h \ 446 Rectangle3.h \ 447 Vector3.h \ 448 common.h \ 449 Ray.h \ 450 Polygon3.h \ 451 VssRay.h \ 461 VssRay.h \ 462 Containers.h \ 463 Mesh.h \ 464 KdTree.h \ 465 ViewCellBsp.h \ 466 VspKdTree.h \ 467 Intersectable.h \ 468 Plane3.h \ 469 Matrix4x4.h \ 470 AxisAlignedBox3.h \ 471 Material.h \ 472 Pvs.h \ 473 Rectangle3.h \ 474 Vector3.h \ 475 common.h \ 476 Ray.h \ 477 Polygon3.h \ 478 Statistics.h \ 479 RayInfo.h \ 452 480 453 481 … … 476 504 Material.h \ 477 505 Vector3.h \ 478 common.h \ 506 Ray.h \ 507 common.h \ 508 Matrix4x4.h \ 479 509 480 510 … … 595 625 Vector3.h \ 596 626 common.h \ 627 Statistics.h \ 597 628 598 629 … … 628 659 Vector3.h \ 629 660 Containers.h \ 661 Statistics.h \ 630 662 Intersectable.h \ 631 663 Matrix4x4.h \ … … 644 676 AxisAlignedBox3.h \ 645 677 Vector3.h \ 646 common.h \ 647 Rectangle3.h \ 648 Matrix4x4.h \ 678 Ray.h \ 679 common.h \ 680 Matrix4x4.h \ 681 Rectangle3.h \ 649 682 Plane3.h \ 650 683 … … 660 693 Vector3.h \ 661 694 common.h \ 662 Rectangle3.h \663 Matrix4x4.h \695 Matrix4x4.h \ 696 Rectangle3.h \ 664 697 Plane3.h \ 665 698 Pvs.h \ … … 689 722 Mesh.h \ 690 723 ViewCellBsp.h \ 691 Intersectable.h \ 692 Material.h \ 693 Exporter.h \ 694 Statistics.h \ 724 VspKdTree.h \ 725 Intersectable.h \ 726 Material.h \ 727 Statistics.h \ 728 RayInfo.h \ 729 Exporter.h \ 730 731 732 RenderSimulator.obj: RenderSimulator.cpp \ 733 RenderSimulator.h \ 734 KdTree.h \ 735 ViewCellBsp.h \ 736 ViewCell.h \ 737 common.h \ 738 Statistics.h \ 739 Containers.h \ 740 AxisAlignedBox3.h \ 741 Ray.h \ 742 Pvs.h \ 743 Rectangle3.h \ 744 Matrix4x4.h \ 745 Vector3.h \ 746 Plane3.h \ 747 Mesh.h \ 748 Polygon3.h \ 749 Intersectable.h \ 750 Material.h \ 751 752 753 VspKdTree.obj: VspKdTree.cpp \ 754 VspKdTree.h \ 755 Environment.h \ 756 VssRay.h \ 757 Intersectable.h \ 758 Ray.h \ 759 RayInfo.h \ 760 AxisAlignedBox3.h \ 761 Statistics.h \ 762 Vector3.h \ 763 common.h \ 764 Matrix4x4.h \ 765 Rectangle3.h \ 766 Plane3.h \ 767 Pvs.h \ 768 769 770 RayInfo.obj: RayInfo.cpp \ 771 RayInfo.h \ 772 Ray.h \ 773 VssRay.h \ 774 Matrix4x4.h \ 775 Vector3.h \ 776 common.h \ 695 777 696 778 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r403 r427 10 10 #include "VssTree.h" 11 11 12 13 bool useViewSpaceBox = true; 14 bool use2dSampling = false; 15 bool useViewspacePlane = false; 16 12 17 VssPreprocessor::VssPreprocessor(): 13 18 mPass(0), … … 18 23 environment->GetIntValue("VssPreprocessor.initialSamples", mInitialSamples); 19 24 environment->GetIntValue("VssPreprocessor.vssSamples", mVssSamples); 25 environment->GetIntValue("VssPreprocessor.vssSamplesPerPass", mVssSamplesPerPass); 20 26 environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling); 21 27 … … 49 55 static Ray ray; 50 56 AxisAlignedBox3 box = mKdTree->GetBox(); 57 58 AxisAlignedBox3 sbox = box; 59 sbox.Enlarge(Vector3(-Limits::Small)); 60 if (!sbox.IsInside(viewPoint)) 61 return 0; 51 62 52 63 SetupRay(ray, viewPoint, direction); … … 145 156 146 157 Vector3 147 VssPreprocessor::GetDirection(const Vector3 &viewpoint) 148 { 149 int i = RandomValue(0, mObjects.size()-1); 150 Intersectable *object = mObjects[i]; 151 Vector3 point, normal; 152 object->GetRandomSurfacePoint(point, normal); 158 VssPreprocessor::GetDirection(const Vector3 &viewpoint, 159 AxisAlignedBox3 *viewSpaceBox 160 ) 161 { 162 Vector3 point; 163 if (!use2dSampling) { 164 Vector3 normal; 165 int i = RandomValue(0, mObjects.size()-1); 166 Intersectable *object = mObjects[i]; 167 object->GetRandomSurfacePoint(point, normal); 168 } else { 169 AxisAlignedBox3 box; 170 171 if (viewSpaceBox) 172 box =*viewSpaceBox; 173 else 174 box = mKdTree->GetBox(); 175 176 point = box.GetRandomPoint(); 177 point.y = viewpoint.y; 178 } 179 153 180 return point - viewpoint; 154 181 } 155 182 156 183 int 157 VssPreprocessor::RandomizedImportanceSampling(VssTree *vssTree, 158 const int desiredSamples) 159 { 160 float minRayContribution; 161 float maxRayContribution; 162 float avgRayContribution; 163 164 vssTree->GetRayContributionStatistics(minRayContribution, 165 maxRayContribution, 166 avgRayContribution); 167 168 cout<< 169 "#MIN_RAY_CONTRIB\n"<<minRayContribution<<endl<< 170 "#MAX_RAY_CONTRIB\n"<<maxRayContribution<<endl<< 171 "#AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl; 172 173 float p = desiredSamples/(float)(avgRayContribution*vssTree->stat.Leaves()); 174 SimpleRayContainer rays; 175 int num = vssTree->GenerateRays(p, rays); 184 VssPreprocessor::GenerateImportanceRays(VssTree *vssTree, 185 const int desiredSamples, 186 SimpleRayContainer &rays 187 ) 188 { 189 int num; 190 if (0) { 191 float minRayContribution; 192 float maxRayContribution; 193 float avgRayContribution; 194 195 vssTree->GetRayContributionStatistics(minRayContribution, 196 maxRayContribution, 197 avgRayContribution); 198 199 cout<< 200 "#MIN_RAY_CONTRIB\n"<<minRayContribution<<endl<< 201 "#MAX_RAY_CONTRIB\n"<<maxRayContribution<<endl<< 202 "#AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl; 203 204 float p = desiredSamples/(float)(avgRayContribution*vssTree->stat.Leaves()); 205 num = vssTree->GenerateRays(p, rays); 206 } else { 207 int leaves = vssTree->stat.Leaves()/2; 208 num = vssTree->GenerateRays(desiredSamples, leaves, rays); 209 } 210 176 211 cout<<"Generated "<<num<<" rays."<<endl; 177 212 178 VssRayContainer vssRays;179 180 for (int i=0; i < rays.size(); i++)181 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays);182 183 vssTree->AddRays(vssRays);184 213 return num; 185 214 } 186 215 216 217 bool 218 VssPreprocessor::ExportRays(const char *filename, 219 const VssRayContainer &vssRays, 220 const int number 221 ) 222 { 223 cout<<"Exporting vss rays..."<<endl<<flush; 224 225 float prob = number/(float)vssRays.size(); 226 227 228 Exporter *exporter = NULL; 229 exporter = Exporter::GetExporter(filename); 230 // exporter->SetWireframe(); 231 // exporter->ExportKdTree(*mKdTree); 232 exporter->SetFilled(); 233 exporter->ExportScene(mSceneGraph->mRoot); 234 exporter->SetWireframe(); 235 236 if (mViewSpaceBox) { 237 exporter->SetForcedMaterial(RgbColor(1,0,0)); 238 exporter->ExportBox(*mViewSpaceBox); 239 exporter->ResetForcedMaterial(); 240 } 241 242 VssRayContainer rays; for (int i=0; i < vssRays.size(); i++) 243 if (RandomValue(0,1) < prob) 244 rays.push_back(vssRays[i]); 245 246 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 247 248 delete exporter; 249 250 cout<<"done."<<endl<<flush; 251 252 return true; 253 } 254 255 256 bool 257 VssPreprocessor::ExportVssTreeLeaf(char *filename, 258 VssTree *tree, 259 VssTreeLeaf *leaf) 260 { 261 Exporter *exporter = NULL; 262 exporter = Exporter::GetExporter(filename); 263 exporter->SetWireframe(); 264 exporter->ExportKdTree(*mKdTree); 265 266 if (mViewSpaceBox) { 267 exporter->SetForcedMaterial(RgbColor(1,0,0)); 268 exporter->ExportBox(*mViewSpaceBox); 269 exporter->ResetForcedMaterial(); 270 } 271 272 exporter->SetForcedMaterial(RgbColor(0,0,1)); 273 exporter->ExportBox(tree->GetBBox(leaf)); 274 exporter->ResetForcedMaterial(); 275 276 VssRayContainer rays[4]; 277 for (int i=0; i < leaf->rays.size(); i++) { 278 int k = leaf->rays[i].GetRayClass(); 279 rays[k].push_back(leaf->rays[i].mRay); 280 } 281 282 // SOURCE RAY 283 exporter->ExportRays(rays[0], RgbColor(1, 0, 0)); 284 // TERMINATION RAY 285 exporter->ExportRays(rays[1], RgbColor(1, 1, 1)); 286 // PASSING_RAY 287 exporter->ExportRays(rays[2], RgbColor(1, 1, 0)); 288 // CONTAINED_RAY 289 exporter->ExportRays(rays[3], RgbColor(0, 0, 1)); 290 291 delete exporter; 292 return true; 293 } 294 295 void 296 VssPreprocessor::ExportVssTreeLeaves(VssTree *tree, const int number) 297 { 298 vector<VssTreeLeaf *> leaves; 299 tree->CollectLeaves(leaves); 300 301 int num = 0; 302 int i; 303 float p = number / (float)leaves.size(); 304 for (i=0; i < leaves.size(); i++) { 305 if (RandomValue(0,1) < p) { 306 char filename[64]; 307 sprintf(filename, "vss-leaf-%04d.x3d", num); 308 ExportVssTreeLeaf(filename, tree, leaves[i]); 309 num++; 310 } 311 if (num >= number) 312 break; 313 } 314 } 187 315 188 316 bool … … 196 324 int totalSamples = 0; 197 325 198 AxisAlignedBox3 *viewSpaceBox = NULL; 199 200 AxisAlignedBox3 box = mKdTree->GetBox(); 201 202 203 if (1) 204 box.Enlarge(box.Size()*-Vector3(0.45, 0.45, 0.45)); 205 else { 326 327 AxisAlignedBox3 *box = new AxisAlignedBox3(mKdTree->GetBox()); 328 329 if (!useViewspacePlane) { 330 float size = 0.01f; 331 float s = 0.5f - size; 332 float olds = Magnitude(box->Size()); 333 box->Enlarge(box->Size()*Vector3(-s)); 334 Vector3 translation = Vector3(-olds*0.1f, 0, 0); 335 box->SetMin(box->Min() + translation); 336 box->SetMax(box->Max() + translation); 337 } else { 338 206 339 // sample city like heights 207 box.SetMin(1, box.Min(1) + box.Size(1)*0.1); 208 box.SetMax(1, box.Min(1) + box.Size(1)*0.2); 209 } 210 211 bool useViewSpaceBox = false; 340 box->SetMin(1, box->Min(1) + box->Size(1)*0.1); 341 box->SetMax(1, box->Min(1) + box->Size(1)*0.2); 342 } 343 344 if (use2dSampling) 345 box->SetMax(1, box->Min(1)); 346 212 347 if (useViewSpaceBox) 213 viewSpaceBox = &box; 348 mViewSpaceBox = box; 349 else 350 mViewSpaceBox = NULL; 351 214 352 215 353 VssTree *vssTree = NULL; … … 223 361 int sampleContributions; 224 362 225 226 for (int k=0; k < mSamplesPerPass; k++) {363 int s = Min(mSamplesPerPass, mInitialSamples); 364 for (int k=0; k < s; k++) { 227 365 228 Vector3 viewpoint = GetViewpoint( viewSpaceBox);229 Vector3 direction = GetDirection(viewpoint );366 Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 367 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 230 368 231 369 sampleContributions = CastRay(viewpoint, direction, mVssRays); … … 271 409 cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush; 272 410 273 cout<<"Exporting vss rays..."<<endl<<flush; 274 275 int exportRays = 10000; 276 277 if (exportRays) { 278 float prob = exportRays/(float)mVssRays.size(); 279 280 Exporter *exporter = NULL; 281 exporter = Exporter::GetExporter("vss-rays.x3d"); 282 exporter->SetWireframe(); 283 exporter->ExportKdTree(*mKdTree); 284 if (viewSpaceBox) { 285 exporter->SetForcedMaterial(RgbColor(1,0,0)); 286 exporter->ExportBox(*viewSpaceBox); 287 exporter->ResetForcedMaterial(); 288 } 289 VssRayContainer rays; 290 for (int i=0; i < mVssRays.size(); i++) 291 if (RandomValue(0,1) < prob) 292 rays.push_back(mVssRays[i]); 293 exporter->ExportRays(rays, RgbColor(1, 0, 0)); 294 295 delete exporter; 296 } 297 cout<<"done."<<endl<<flush; 411 412 // int numExportRays = 10000; 413 414 int numExportRays = 0; 415 416 if (numExportRays) { 417 char filename[64]; 418 sprintf(filename, "vss-rays-initial.x3d"); 419 ExportRays(filename, mVssRays, numExportRays); 420 } 298 421 299 422 … … 302 425 vssTree = new VssTree; 303 426 304 vssTree->Construct(mVssRays, viewSpaceBox);427 vssTree->Construct(mVssRays, mViewSpaceBox); 305 428 306 429 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 307 430 431 ExportVssTreeLeaves(vssTree, 10); 308 432 309 433 int samples = 0; 434 int pass = 0; 310 435 while (1) { 311 int num = mSamplesPerPass; 436 int num = mVssSamplesPerPass; 437 SimpleRayContainer rays; 438 VssRayContainer vssRays; 439 312 440 if (!mUseImportanceSampling) { 313 VssRayContainer vssRays;314 441 for (int j=0; j < num; j++) { 315 Vector3 viewpoint = GetViewpoint( viewSpaceBox);316 Vector3 direction = GetDirection(viewpoint );317 CastRay(viewpoint, direction, vssRays);442 Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 443 Vector3 direction = GetDirection(viewpoint, mViewSpaceBox); 444 rays.push_back(SimpleRay(viewpoint, direction)); 318 445 } 319 vssTree->AddRays(vssRays);320 446 } else { 321 num = RandomizedImportanceSampling(vssTree, num); 322 } 447 num = GenerateImportanceRays(vssTree, num, rays); 448 } 449 450 451 for (int i=0; i < rays.size(); i++) 452 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 453 454 vssTree->AddRays(vssRays); 455 456 if (1) { 457 int subdivided = vssTree->UpdateSubdivision(); 458 cout<<"subdivided leafs = "<<subdivided<<endl; 459 } 460 461 if (numExportRays) { 462 char filename[64]; 463 if (mUseImportanceSampling) 464 sprintf(filename, "vss-rays-i%04d.x3d", pass); 465 else 466 sprintf(filename, "vss-rays-%04d.x3d", pass); 467 468 ExportRays(filename, vssRays, numExportRays); 469 } 470 471 323 472 samples+=num; 324 473 float pvs = vssTree->GetAvgPvsSize(); 474 cout<<"*****************************\n"; 325 475 cout<<samples<<" avgPVS ="<<pvs<<endl; 476 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 477 cout<<"*****************************\n"; 326 478 if (samples >= mVssSamples) 327 479 break; 480 pass++; 328 481 } 329 482 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
r403 r427 8 8 #include "VssRay.h" 9 9 class VssTree; 10 class VssTreeLeaf; 10 11 11 12 /** Sampling based visibility preprocessing. The implementation is based on heuristical … … 15 16 int mPass; 16 17 int mSamplesPerPass; 18 int mVssSamplesPerPass; 17 19 int mInitialSamples; 18 20 int mVssSamples; 19 21 bool mUseImportanceSampling; 22 23 AxisAlignedBox3 *mViewSpaceBox; 20 24 21 25 ofstream mStats; … … 35 39 36 40 Vector3 37 GetDirection(const Vector3 &viewpoint); 41 GetDirection(const Vector3 &viewpoint, 42 AxisAlignedBox3 *viewSpaceBox 43 ); 38 44 39 45 void … … 57 63 virtual bool BuildBspTree() { return false; } 58 64 65 66 bool 67 ExportRays(const char *filename, 68 const VssRayContainer &vssRays, 69 const int number 70 ); 71 59 72 int 60 RandomizedImportanceSampling(VssTree *vssTree, const int desiredSamples); 73 GenerateImportanceRays(VssTree *vssTree, 74 const int desiredSamples, 75 SimpleRayContainer &rays 76 ); 61 77 78 79 bool 80 ExportVssTreeLeaf(char *filename, 81 VssTree *tree, 82 VssTreeLeaf *leaf); 83 84 void 85 ExportVssTreeLeaves(VssTree *tree, const int number); 86 87 62 88 }; 63 89 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
r426 r427 163 163 mTermination += translation; 164 164 } 165 165 166 void SetupEndPoints(const Vector3 &origin, 167 const Vector3 &termination) 168 { 169 mOrigin = origin; 170 mTermination = termination; 171 Precompute(); 172 } 173 166 174 bool HasPosDir(const int axis) const { return mFlags & (1<<axis); } 167 175 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
r403 r427 184 184 app << "#N_PMAXRAYCONTRIBLEAVES ( Percentage of leaves with maximal ray contribution )\n"<< 185 185 maxRayContribNodes*100/(double)Leaves()<<endl; 186 187 app << "#N_PMAXCOSTRATIOLEAVES ( Percentage of leaves with max cost ratio )\n"<< 188 maxCostRatioNodes*100/(double)Leaves()<<endl; 186 189 187 190 app << "#N_ADDED_RAYREFS (Number of dynamically added ray references )\n"<< … … 230 233 } 231 234 235 bool 236 VssTree::ClipRay( 237 VssTreeNode::RayInfo &rayInfo, 238 const AxisAlignedBox3 &box 239 ) 240 { 241 float tmin, tmax; 242 static Ray ray; 243 ray.Init(rayInfo.mRay->GetOrigin(), rayInfo.mRay->GetDir(), Ray::LINE_SEGMENT); 244 box.ComputeMinMaxT(ray, &tmin, &tmax); 245 if (tmin >= tmax) 246 return false; 247 248 if (tmin > 0.0f) 249 rayInfo.SetMinT(tmin); 250 251 if (tmax < 1.0f) 252 rayInfo.SetMaxT(tmax); 253 254 // vssRay->SetupEndPoints( 255 // origin, 256 // termination 257 // ); 258 return true; 259 } 260 232 261 233 262 void … … 256 285 ri != rays.end(); 257 286 ri++) { 258 leaf->AddRay(VssTreeNode::RayInfo(*ri)); 259 287 288 VssTreeNode::RayInfo info(*ri); 289 if (forcedBoundingBox) 290 if (!ClipRay(info, *forcedBoundingBox)) 291 continue; 292 leaf->AddRay(info); 293 260 294 bbox.Include((*ri)->GetOrigin()); 261 295 bbox.Include((*ri)->GetTermination()); … … 271 305 272 306 273 if ( forcedBoundingBox ) 307 if ( forcedBoundingBox ) 274 308 bbox = *forcedBoundingBox; 275 309 276 310 cout<<"Bbox = "<<bbox<<endl; 277 311 cout<<"Dirr Bbox = "<<dirBBox<<endl; … … 296 330 } 297 331 332 int 333 VssTree::UpdateSubdivision() 334 { 335 priority_queue<TraversalData> tStack; 336 // stack<TraversalData> tStack; 337 338 tStack.push(TraversalData(root, bbox, 0)); 339 340 AxisAlignedBox3 backBox; 341 AxisAlignedBox3 frontBox; 342 343 maxMemory = maxTotalMemory; 344 int subdivided = 0; 345 int lastMem = 0; 346 while (!tStack.empty()) { 347 348 float mem = GetMemUsage(); 349 350 if ( lastMem/10 != ((int)mem)/10) { 351 cout<<mem<<" MB"<<endl; 352 } 353 lastMem = (int)mem; 354 355 if ( mem > maxMemory ) { 356 // count statistics on unprocessed leafs 357 while (!tStack.empty()) { 358 // EvaluateLeafStats(tStack.top()); 359 tStack.pop(); 360 } 361 break; 362 } 363 364 TraversalData data = tStack.top(); 365 tStack.pop(); 366 367 if (data.node->IsLeaf()) { 368 VssTreeNode *node = SubdivideNode((VssTreeLeaf *) data.node, 369 data.bbox, 370 backBox, 371 frontBox 372 ); 373 if (!node->IsLeaf()) { 374 subdivided++; 375 VssTreeInterior *interior = (VssTreeInterior *) node; 376 // push the children on the stack 377 tStack.push(TraversalData(interior->back, backBox, data.depth+1)); 378 tStack.push(TraversalData(interior->front, frontBox, data.depth+1)); 379 } else { 380 // EvaluateLeafStats(data); 381 } 382 } else { 383 VssTreeInterior *interior = (VssTreeInterior *) data.node; 384 tStack.push(TraversalData(interior->back, GetBBox(interior->back), data.depth+1)); 385 tStack.push(TraversalData(interior->front, GetBBox(interior->front), data.depth+1)); 386 } 387 } 388 return subdivided; 389 } 298 390 299 391 … … 403 495 if (costRatio > termMaxCostRatio) { 404 496 // cout<<"Too big cost ratio "<<costRatio<<endl; 497 stat.maxCostRatioNodes++; 405 498 return -1; 406 499 } … … 436 529 pvsBack = 0; 437 530 438 float newCost;439 531 440 532 Intersectable::NewMail(3); 441 533 bool costImportance = true; 442 534 // eval pvs size 443 535 int pvsSize = leaf->GetPvsSize(); 536 float ratio; 444 537 445 538 Intersectable::NewMail(3); … … 464 557 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 465 558 } 466 559 467 560 AxisAlignedBox3 box = GetBBox(leaf); 468 561 … … 471 564 float sizeBox = maxBox - minBox; 472 565 473 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 474 float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 475 476 newCost = ct_div_ci + sum/sizeBox; 566 if (!costImportance) { 567 568 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 569 float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 570 float newCost = ct_div_ci + sum/sizeBox; 571 float oldCost = pvsSize; 572 ratio = newCost/oldCost; 573 } else { 574 // importance based cost 575 #if 0 576 float newContrib = 577 ((position - minBox)*sqr(pvsBack/(raysBack + Limits::Small)) + 578 (maxBox - position)*sqr(pvsFront/(raysFront + Limits::Small)))/sizeBox; 579 580 // float newContrib = 581 // sqr(pvsBack/(raysBack + Limits::Small)) + 582 // sqr(pvsFront/(raysFront + Limits::Small)); 583 float oldContrib = sqr(leaf->GetAvgRayContribution()); 584 ratio = oldContrib/newContrib; 585 #else 586 float newCost = raysBack*pvsBack + raysFront*pvsFront; 587 float oldCost = leaf->rays.size()*pvsSize; 588 ratio = newCost/oldCost; 589 #endif 590 } 477 591 478 592 } else { … … 499 613 // (*ri).mRay->mSide = side; 500 614 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 501 615 502 616 } 503 617 … … 507 621 float maxBox = box.Max(axis-3); 508 622 float sizeBox = maxBox - minBox; 509 510 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 511 float sum = 512 pvsBack*(position - minBox) + 513 pvsFront*(maxBox - position); 514 // float sum = pvsBack + pvsFront; 515 newCost = ct_div_ci + sum/sizeBox; 516 } 517 623 624 if (!costImportance) { 625 626 float directionalPenalty = 1.0f; 627 float sum = 628 (pvsBack*(position - minBox) + 629 pvsFront*(maxBox - position))*directionalPenalty; 630 float newCost = ct_div_ci + sum/sizeBox; 631 float oldCost = pvsSize; 632 ratio = newCost/oldCost; 633 } else { 634 #if 0 635 float directionalPenalty = 0.7f; 636 // importance based cost 637 float newContrib = 638 directionalPenalty*((position - minBox)*sqr(pvsBack/(raysBack + Limits::Small)) + 639 (maxBox - position)*sqr(pvsFront/(raysFront + Limits::Small)))/sizeBox; 640 float oldContrib = sqr(leaf->GetAvgRayContribution()); 641 ratio = oldContrib/newContrib; 642 #else 643 float newCost = raysBack*pvsBack + raysFront*pvsFront; 644 float oldCost = leaf->rays.size()*pvsSize; 645 ratio = newCost/oldCost; 646 #endif 647 } 648 } 518 649 // cout<<axis<<" "<<pvsSize<<" "<<pvsBack<<" "<<pvsFront<<endl; 519 650 // float oldCost = leaf->rays.size(); 520 float oldCost = pvsSize; 521 float ratio = newCost/oldCost; 651 522 652 // cout<<"ratio="<<ratio<<endl; 523 653 return ratio; … … 534 664 int &pvsFront 535 665 ) 536 {666 { 537 667 int nRaysBack[6], nRaysFront[6]; 538 668 int nPvsBack[6], nPvsFront[6]; … … 547 677 int dAxis = dBox.Size().DrivingAxis() + 3; 548 678 549 bool onlyDrivingAxis = true; 550 551 for (axis = 0; axis < 6; axis++) { 679 bool onlyDrivingAxis = false; 680 681 float dirSplitBoxSize = 0.01f; 682 bool allowDirSplit = Magnitude(sBox.Size())*dirSplitBoxSize < Magnitude(bbox.Size()); 683 684 685 for (axis = 0; axis < 5; axis++) { 552 686 if (!onlyDrivingAxis || axis == sAxis || axis == dAxis) { 553 687 if (axis < 3) … … 765 899 } 766 900 901 bool 902 VssTree::TerminationCriteriaSatisfied(VssTreeLeaf *leaf) 903 { 904 return ( (leaf->GetPvsSize() < termMinPvs) || 905 (leaf->rays.size() < termMinRays) || 906 // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 907 (leaf->depth >= termMaxDepth) || 908 SqrMagnitude(GetBBox(leaf).Size()) <= termMinSize ); 909 } 767 910 768 911 … … 776 919 { 777 920 778 if ( (leaf->GetPvsSize() < termMinPvs) || 779 (leaf->rays.size() < termMinRays) || 780 // (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 781 (leaf->depth >= termMaxDepth) || 782 SqrMagnitude(box.Size()) <= termMinSize ) { 783 921 if (TerminationCriteriaSatisfied(leaf)) { 784 922 #if 0 785 923 if (leaf->depth >= termMaxDepth) { … … 802 940 // select subdivision axis 803 941 int axis = SelectPlane( leaf, box, position, raysBack, raysFront, pvsBack, pvsFront); 804 942 // cout<<axis<<" "; 943 805 944 // cout<<"rays back="<<raysBack<<" rays front="<<raysFront<<" pvs back="<<pvsBack<<" pvs front="<< 806 945 // pvsFront<<endl; … … 966 1105 VssTreeNode * 967 1106 VssTree::SubdivideLeaf( 968 VssTreeLeaf *leaf, 969 const float sizeThreshold 1107 VssTreeLeaf *leaf 970 1108 ) 971 1109 { 972 1110 VssTreeNode *node = leaf; 973 1111 974 1112 AxisAlignedBox3 leafBBox = GetBBox(leaf); 975 1113 … … 978 1116 979 1117 // check if we should perform a dynamic subdivision of the leaf 980 if ( 981 // leaf->rays.size() > (unsigned)termMinCost && 982 (leaf->GetPvsSize() >= termMinPvs) && 983 SqrMagnitude(leafBBox.Size()) > sizeThreshold) { 1118 if (!TerminationCriteriaSatisfied(leaf)) { 984 1119 985 1120 // memory check and realese... … … 998 1133 ); 999 1134 } 1135 1000 1136 return node; 1001 1137 } … … 1036 1172 ri != add.end(); 1037 1173 ri++) { 1038 AddRay(*ri);1039 } 1040 1041 1174 VssTreeNode::RayInfo info(*ri); 1175 if (ClipRay(info, bbox)) 1176 AddRay(info); 1177 } 1042 1178 } 1043 1179 … … 1128 1264 1129 1265 void 1130 VssTree::AddRay(Vss Ray *ray)1266 VssTree::AddRay(VssTreeNode::RayInfo &info) 1131 1267 { 1132 1268 1133 1269 stack<RayTraversalData> tstack; 1134 1270 1135 tstack.push(RayTraversalData(root, VssTreeNode::RayInfo(ray)));1271 tstack.push(RayTraversalData(root, info)); 1136 1272 1137 1273 RayTraversalData data; … … 1461 1597 } 1462 1598 1599 void 1600 VssTree::CollectLeaves(vector<VssTreeLeaf *> &leaves) 1601 { 1602 stack<VssTreeNode *> tstack; 1603 tstack.push(root); 1604 1605 while (!tstack.empty()) { 1606 VssTreeNode *node = tstack.top(); 1607 tstack.pop(); 1608 1609 if (node->IsLeaf()) { 1610 VssTreeLeaf *leaf = (VssTreeLeaf *)node; 1611 leaves.push_back(leaf); 1612 } else { 1613 VssTreeInterior *in = (VssTreeInterior *)node; 1614 // both nodes for directional splits 1615 tstack.push(in->front); 1616 tstack.push(in->back); 1617 } 1618 } 1619 } 1620 1621 int 1622 VssTree::GenerateRays(const int numberOfRays, 1623 const int numberOfLeaves, 1624 SimpleRayContainer &rays) 1625 { 1626 1627 vector<VssTreeLeaf *> leaves; 1628 1629 CollectLeaves(leaves); 1630 1631 sort(leaves.begin(), 1632 leaves.end(), 1633 GreaterContribution); 1634 1635 1636 float sumContrib = 0.0; 1637 int i; 1638 for (i=0; i < numberOfLeaves; i++) { 1639 float c = leaves[i]->GetAvgRayContribution(); 1640 sumContrib += c; 1641 // cout<<"ray contrib "<<i<<" : "<<c<<endl; 1642 } 1643 1644 float avgContrib = sumContrib/numberOfLeaves; 1645 float ratioPerLeaf = numberOfRays/(avgContrib*numberOfLeaves); 1646 1647 for (i=0; i < numberOfLeaves; i++) { 1648 VssTreeLeaf *leaf = leaves[i]; 1649 float c = leaf->GetAvgRayContribution(); 1650 int num = (c*ratioPerLeaf + 0.5); 1651 // cout<<num<<" "; 1652 1653 for (int i=0; i < num; i++) { 1654 Vector3 origin = GetBBox(leaf).GetRandomPoint(); 1655 Vector3 dirVector = GetDirBBox(leaf).GetRandomPoint(); 1656 Vector3 direction = Vector3(sin(dirVector.x), sin(dirVector.y), cos(dirVector.x)); 1657 //cout<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 1658 rays.push_back(SimpleRay(origin, direction)); 1659 } 1660 } 1661 return rays.size(); 1662 } 1663 1463 1664 1464 1665 float … … 1491 1692 return sumPvs/(float)leaves; 1492 1693 } 1694 1695 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
r403 r427 60 60 // max depth nodes 61 61 int minSizeNodes; 62 62 int maxCostRatioNodes; 63 63 64 // max number of rays per node 64 65 int maxRayRefs; … … 91 92 maxRayContribNodes = 0; 92 93 minSizeNodes = 0; 94 maxCostRatioNodes = 0; 93 95 } 94 96 … … 140 142 public: 141 143 142 #define USE_FIXEDPOINT_T 1144 #define USE_FIXEDPOINT_T 0 143 145 144 146 struct RayInfo … … 159 161 #if USE_FIXEDPOINT_T 160 162 #define FIXEDPOINT_ONE 0x7FFE 161 162 163 // mMaxT(0xFFFF) 164 mMaxT(FIXEDPOINT_ONE) 163 165 #else 164 166 mMaxT(1.0f) … … 167 169 168 170 RayInfo(VssRay *r, 169 170 171 171 const float _min, 172 const float _max 173 ):mRay(r) { 172 174 SetMinT(_min); 173 175 SetMaxT(_max); … … 175 177 176 178 RayInfo(VssRay *r, 177 178 179 179 const short _min, 180 const float _max 181 ):mRay(r), mMinT(_min) { 180 182 SetMaxT(_max); 181 183 } … … 187 189 SetMinT(_min); 188 190 } 191 192 enum { 193 SOURCE_RAY = 0, 194 TERMINATION_RAY, 195 PASSING_RAY, 196 CONTAINED_RAY 197 }; 198 199 int GetRayClass() const { 200 201 bool startsBefore = GetMinT() > 0.0f; 202 bool terminatesAfter = GetMaxT() < 1.0f; 203 204 if (startsBefore && terminatesAfter) 205 return PASSING_RAY; 206 207 if (!startsBefore && !terminatesAfter) 208 return CONTAINED_RAY; 209 210 if (!startsBefore) 211 return SOURCE_RAY; 212 213 return TERMINATION_RAY; 214 } 189 215 190 216 friend bool operator<(const RayInfo &a, const RayInfo &b) { … … 224 250 225 251 226 int ComputeRayIntersection(const float axis,252 int ComputeRayIntersection(const int axis, 227 253 const float position, 228 254 float &t … … 433 459 } 434 460 461 // comparator for the 462 struct less_contribution : public 463 binary_function<const VssTreeLeaf *, const VssTreeLeaf *, bool> { 464 465 bool operator()(const VssTreeLeaf * a, const VssTreeLeaf *b) { 466 return a->GetAvgRayContribution() < b->GetAvgRayContribution(); 467 } 468 }; 469 470 struct greater_contribution : public 471 binary_function<const VssTreeLeaf *, const VssTreeLeaf *, bool> { 472 473 bool operator()(const VssTreeLeaf * a, const VssTreeLeaf *b) { 474 return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 475 } 476 }; 477 478 friend bool GreaterContribution(const VssTreeLeaf * a, const VssTreeLeaf *b) { 479 return a->GetAvgRayContribution() > b->GetAvgRayContribution(); 480 } 481 435 482 }; 436 483 … … 762 809 VssTreeNode * 763 810 SubdivideLeaf( 764 VssTreeLeaf *leaf, 765 const float SAThreshold 811 VssTreeLeaf *leaf 766 812 ); 767 813 … … 772 818 ); 773 819 774 void 775 AddRay(VssRay *ray); 776 820 // void 821 // AddRay(VssRay *ray); 822 void 823 AddRay(VssTreeNode::RayInfo &info); 824 777 825 void 778 826 TraverseInternalNode( … … 803 851 SimpleRayContainer &rays); 804 852 853 int 854 GenerateRays(const int numberOfRays, 855 const int numberOfLeaves, 856 SimpleRayContainer &rays); 857 805 858 float 806 859 GetAvgPvsSize(); 807 860 861 int 862 UpdateSubdivision(); 863 864 bool 865 TerminationCriteriaSatisfied(VssTreeLeaf *leaf); 866 867 void 868 CollectLeaves(vector<VssTreeLeaf *> &leaves); 869 870 bool 871 ClipRay( 872 VssTreeNode::RayInfo &rayInfo, 873 const AxisAlignedBox3 &box 874 ); 875 876 808 877 }; 809 878 -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r426 r427 86 86 stream<<"<Shape>"<<endl; 87 87 stream<<"<Appearance>"<<endl; 88 stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<<88 stream<<"<Material diffuseColor=\""<<color.r<<" "<<color.g<<" "<<color.b<< 89 89 "\" />"<<endl; 90 90 stream<<"</Appearance>"<<endl; … … 135 135 stream<<"<Shape>"<<endl; 136 136 stream<<"<Appearance>"<<endl; 137 stream<<"<Material ambientColor=\""<<color.r<<" "<<color.g<<" "<<color.b<<137 stream<<"<Material diffuseColor=\""<<color.r<<" "<<color.g<<" "<<color.b<< 138 138 "\" />"<<endl; 139 139 stream<<"</Appearance>"<<endl; … … 347 347 348 348 if (mWireframe) 349 stream<<"<IndexedLineSet c cw=\"TRUE\" coordIndex=\""<<endl;349 stream<<"<IndexedLineSet coordIndex=\""<<endl; 350 350 else 351 351 stream<<"<IndexedFaceSet ccw=\"TRUE\" coordIndex=\""<<endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r410 r427 13 13 #;../data/vienna/vienna-plane.x3d 14 14 # filename ../data/vienna/viewcells-25-sel.x3d 15 #filename ../data/atlanta/atlanta2.x3d15 filename ../data/atlanta/atlanta2.x3d 16 16 # filename ../data/soda/soda.dat 17 filename ../data/soda/soda5.dat17 # filename ../data/soda/soda5.dat 18 18 } 19 19 … … 25 25 VssPreprocessor { 26 26 samplesPerPass 100000 27 initialSamples 200000 27 initialSamples 2000000 28 28 vssSamples 1000000 29 vssSamplesPerPass 100000 29 30 useImportanceSampling true 30 31 } … … 34 35 35 36 maxDepth 40 36 minPvs 137 minRays 5038 minSize 0.00 00139 maxCostRatio 0.95 37 minPvs 3 38 minRays 100 39 minSize 0.001 40 maxCostRatio 0.98 40 41 maxRayContribution 0.05 41 42 42 maxTotalMemory 40043 maxStaticMemory 2043 maxTotalMemory 200 44 maxStaticMemory 50 44 45 45 46 splitType regular -
trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
r382 r427 38 38 Exporter.cpp Camera.cpp X3dParser.cpp MeshKdTree.cpp Pvs.cpp \ 39 39 MutualVisibility.cpp Triangle3.cpp Rectangle3.cpp Plane3.cpp Polygon3.cpp \ 40 ViewCell.cpp ViewCellBsp.cpp Halton.cpp VssRay.cpp VssTree.cpp VssPreprocessor.cpp 40 ViewCell.cpp ViewCellBsp.cpp Halton.cpp VssRay.cpp VssTree.cpp VssPreprocessor.cpp \ 41 RenderSimulator.cpp VspKdTree.cpp RayInfo.cpp 41 42
Note: See TracChangeset
for help on using the changeset viewer.