- Timestamp:
- 11/10/05 09:55:50 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
r382 r401 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (1.07a) (Qt 3.3.2) on: Sat Nov 05 19:00:35 20053 # Generated by qmake (1.07a) (Qt 3.3.2) on: Wed Nov 09 22:44:25 2005 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 228 228 common.h \ 229 229 Material.h \ 230 VssRay.h \ 230 231 Parser.h \ 231 232 Mesh.h \ … … 235 236 Pvs.h \ 236 237 Ray.h \ 238 Polygon3.h \ 237 239 238 240 … … 261 263 Material.h \ 262 264 Exporter.h \ 265 VssRay.h \ 263 266 264 267 … … 281 284 common.h \ 282 285 Ray.h \ 286 Polygon3.h \ 283 287 284 288 … … 342 346 ViewCell.h \ 343 347 Polygon3.h \ 348 VssRay.h \ 344 349 Containers.h \ 345 350 AxisAlignedBox3.h \ … … 367 372 common.h \ 368 373 Exporter.h \ 374 VssRay.h \ 369 375 Material.h \ 370 376 Pvs.h \ … … 442 448 common.h \ 443 449 Ray.h \ 450 Polygon3.h \ 444 451 VssRay.h \ 445 452 … … 466 473 Exporter.h \ 467 474 Containers.h \ 468 Material.h \ 475 VssRay.h \ 476 Material.h \ 477 Vector3.h \ 478 common.h \ 469 479 470 480 … … 485 495 Intersectable.h \ 486 496 Material.h \ 497 VssRay.h \ 487 498 488 499 … … 546 557 common.h \ 547 558 Material.h \ 559 VssRay.h \ 548 560 Intersectable.h \ 549 561 … … 621 633 Pvs.h \ 622 634 Rectangle3.h \ 635 VssRay.h \ 623 636 624 637 … … 642 655 VssRay.h \ 643 656 Intersectable.h \ 657 Ray.h \ 644 658 AxisAlignedBox3.h \ 645 659 Statistics.h \ -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r392 r401 290 290 }; 291 291 292 struct SimpleRay 293 { 294 Vector3 mOrigin; 295 Vector3 mDirection; 296 SimpleRay() {} 297 SimpleRay(const Vector3 &o, const Vector3 &d):mOrigin(o), mDirection(d) {} 298 }; 299 300 typedef vector<SimpleRay> SimpleRayContainer; 292 301 293 302 #endif -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r387 r401 39 39 VssPreprocessor::CastRay( 40 40 Vector3 &viewPoint, 41 Vector3 &direction 41 Vector3 &direction, 42 VssRayContainer &vssRays 42 43 ) 43 44 { … … 60 61 box.ComputeMinMaxT(ray, &tmin, &tmax); 61 62 if (tmax > bsize) { 62 cerr<<"Warning: tmax > box size tmax="<<tmax<<" tmin="<<tmin<<" size="<<bsize<<endl;63 cerr<<"ray"<<ray<<endl;63 // cerr<<"Warning: tmax > box size tmax="<<tmax<<" tmin="<<tmin<<" size="<<bsize<<endl; 64 // cerr<<"ray"<<ray<<endl; 64 65 } 65 66 pointA = ray.Extrap(tmax); … … 85 86 box.ComputeMinMaxT(ray, &tmin, &tmax); 86 87 if (tmax > bsize) { 87 cerr<<"Warning: tmax > box size tmax="<<tmax<<" tmin="<<tmin<<" size="<<bsize<<endl;88 cerr<<"ray"<<ray<<endl;88 // cerr<<"Warning: tmax > box size tmax="<<tmax<<" tmin="<<tmin<<" size="<<bsize<<endl; 89 // cerr<<"ray"<<ray<<endl; 89 90 } 90 91 … … 108 109 objectB, 109 110 objectA); 110 mVssRays.push_back(vssRay);111 vssRays.push_back(vssRay); 111 112 hits ++; 112 113 } … … 117 118 objectA, 118 119 objectB); 119 mVssRays.push_back(vssRay);120 vssRays.push_back(vssRay); 120 121 hits ++; 121 122 } … … 150 151 } 151 152 153 int 154 VssPreprocessor::RandomizedImportanceSampling(VssTree *vssTree, 155 const int desiredSamples) 156 { 157 float minRayContribution; 158 float maxRayContribution; 159 float avgRayContribution; 160 161 vssTree->GetRayContributionStatistics(minRayContribution, 162 maxRayContribution, 163 avgRayContribution); 164 165 cout<< 166 "#MIN_RAY_CONTRIB\n"<<minRayContribution<<endl<< 167 "#MAX_RAY_CONTRIB\n"<<maxRayContribution<<endl<< 168 "#AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl; 169 170 float p = desiredSamples/(float)(avgRayContribution*vssTree->stat.Leaves()); 171 SimpleRayContainer rays; 172 int num = vssTree->GenerateRays(p, rays); 173 cout<<"Generated "<<num<<" rays."<<endl; 174 175 VssRayContainer vssRays; 176 177 for (int i=0; i < rays.size(); i++) 178 CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays); 179 180 vssTree->AddRays(vssRays); 181 return num; 182 } 152 183 153 184 … … 175 206 } 176 207 177 bool useViewSpaceBox = true;208 bool useViewSpaceBox = false; 178 209 if (useViewSpaceBox) 179 210 viewSpaceBox = &box; 180 211 212 VssTree *vssTree = NULL; 213 181 214 while (totalSamples < mTotalSamples) { 182 215 int passContributingSamples = 0; … … 193 226 Vector3 direction = GetDirection(viewpoint); 194 227 195 sampleContributions = CastRay(viewpoint, direction );228 sampleContributions = CastRay(viewpoint, direction, mVssRays); 196 229 197 230 … … 226 259 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 227 260 "#AvgRayContrib\n" << avgRayContrib << endl; 261 262 263 264 228 265 } 229 266 … … 257 294 cout<<"done."<<endl<<flush; 258 295 259 VssTree *vssTree = new VssTree; 260 296 297 298 299 vssTree = new VssTree; 300 261 301 vssTree->Construct(mVssRays, viewSpaceBox); 262 302 263 303 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 264 265 266 304 305 306 int samples = 0; 307 for (int i=0; i < 50; i++) { 308 int num = 100000; 309 if (0) { 310 VssRayContainer vssRays; 311 for (int j=0; j < num; j++) { 312 Vector3 viewpoint = GetViewpoint(viewSpaceBox); 313 Vector3 direction = GetDirection(viewpoint); 314 CastRay(viewpoint, direction, vssRays); 315 } 316 vssTree->AddRays(vssRays); 317 } else { 318 num = RandomizedImportanceSampling(vssTree, num); 319 } 320 samples+=num; 321 float pvs = vssTree->GetAvgPvsSize(); 322 cout<<samples<<" avgPVS ="<<pvs<<endl; 323 } 324 325 delete vssTree; 326 267 327 return true; 268 328 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
r386 r401 7 7 #include "Preprocessor.h" 8 8 #include "VssRay.h" 9 class VssTree; 9 10 10 11 /** Sampling based visibility preprocessing. The implementation is based on heuristical … … 44 45 CastRay( 45 46 Vector3 &viewPoint, 46 Vector3 &direction 47 Vector3 &direction, 48 VssRayContainer &vssRays 49 47 50 ); 48 51 … … 51 54 virtual bool BuildBspTree() { return false; } 52 55 56 int 57 RandomizedImportanceSampling(VssTree *vssTree, const int desiredSamples); 58 53 59 }; 54 60 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
r395 r401 23 23 #include "VssRay.h" 24 24 #include "Intersectable.h" 25 #include "Ray.h" 25 26 26 27 … … 197 198 198 199 void 199 VssTreeLeaf:: EvalPvsSize()200 VssTreeLeaf::UpdatePvsSize() 200 201 { 201 202 if (!mValidPvs) { … … 273 274 274 275 stat.rays = leaf->rays.size(); 275 leaf-> EvalPvsSize();276 leaf->UpdatePvsSize(); 276 277 stat.initialPvsSize = leaf->GetPvsSize(); 277 278 // Subdivide(); … … 1372 1373 return pvsSize; 1373 1374 } 1375 1376 void 1377 VssTree::GetRayContributionStatistics( 1378 float &minRayContribution, 1379 float &maxRayContribution, 1380 float &avgRayContribution 1381 ) 1382 { 1383 stack<VssTreeNode *> tstack; 1384 tstack.push(root); 1385 1386 minRayContribution = 1.0f; 1387 maxRayContribution = 0.0f; 1388 float sumRayContribution = 0.0f; 1389 int leaves = 0; 1390 1391 while (!tstack.empty()) { 1392 VssTreeNode *node = tstack.top(); 1393 tstack.pop(); 1394 1395 if (node->IsLeaf()) { 1396 leaves++; 1397 VssTreeLeaf *leaf = (VssTreeLeaf *)node; 1398 float c = leaf->GetAvgRayContribution(); 1399 if (c > maxRayContribution) 1400 maxRayContribution = c; 1401 if (c < minRayContribution) 1402 minRayContribution = c; 1403 sumRayContribution += c; 1404 1405 } else { 1406 VssTreeInterior *in = (VssTreeInterior *)node; 1407 // both nodes for directional splits 1408 tstack.push(in->front); 1409 tstack.push(in->back); 1410 } 1411 } 1412 1413 cout<<"sum="<<sumRayContribution<<endl; 1414 cout<<"leaves="<<leaves<<endl; 1415 avgRayContribution = sumRayContribution/(float)leaves; 1416 } 1417 1418 1419 int 1420 VssTree::GenerateRays(const float ratioPerLeaf, 1421 SimpleRayContainer &rays) 1422 { 1423 stack<VssTreeNode *> tstack; 1424 tstack.push(root); 1425 1426 while (!tstack.empty()) { 1427 VssTreeNode *node = tstack.top(); 1428 tstack.pop(); 1429 1430 if (node->IsLeaf()) { 1431 VssTreeLeaf *leaf = (VssTreeLeaf *)node; 1432 float c = leaf->GetAvgRayContribution(); 1433 int num = (c*ratioPerLeaf + 0.5); 1434 // cout<<num<<" "; 1435 1436 for (int i=0; i < num; i++) { 1437 Vector3 origin = GetBBox(leaf).GetRandomPoint(); 1438 Vector3 dirVector = GetDirBBox(leaf).GetRandomPoint(); 1439 Vector3 direction = Vector3(sin(dirVector.x), sin(dirVector.y), cos(dirVector.x)); 1440 //cout<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl; 1441 rays.push_back(SimpleRay(origin, direction)); 1442 } 1443 1444 } else { 1445 VssTreeInterior *in = (VssTreeInterior *)node; 1446 // both nodes for directional splits 1447 tstack.push(in->front); 1448 tstack.push(in->back); 1449 } 1450 } 1451 1452 return rays.size(); 1453 } 1454 1455 1456 float 1457 VssTree::GetAvgPvsSize() 1458 { 1459 stack<VssTreeNode *> tstack; 1460 tstack.push(root); 1461 1462 int sumPvs = 0; 1463 int leaves = 0; 1464 while (!tstack.empty()) { 1465 VssTreeNode *node = tstack.top(); 1466 tstack.pop(); 1467 1468 if (node->IsLeaf()) { 1469 VssTreeLeaf *leaf = (VssTreeLeaf *)node; 1470 // update pvs size 1471 leaf->UpdatePvsSize(); 1472 sumPvs += leaf->GetPvsSize(); 1473 leaves++; 1474 } else { 1475 VssTreeInterior *in = (VssTreeInterior *)node; 1476 // both nodes for directional splits 1477 tstack.push(in->front); 1478 tstack.push(in->back); 1479 } 1480 } 1481 1482 1483 return sumPvs/(float)leaves; 1484 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
r395 r401 29 29 30 30 #include "Statistics.h" 31 #include "Ray.h" 31 32 32 33 // -------------------------------------------------------------- … … 412 413 413 414 void 414 EvalPvsSize();415 UpdatePvsSize(); 415 416 416 417 void Mail() { mailbox = mailID; } … … 423 424 424 425 float GetAvgRayContribution() const { 425 return GetPvsSize()/( float)rays.size();426 return GetPvsSize()/((float)rays.size() + Limits::Small); 426 427 } 427 428 }; … … 610 611 VssRayContainer &add 611 612 ); 612 613 614 virtual void AddRays( 615 VssRayContainer &add 616 ) 617 { 618 VssRayContainer remove; 619 UpdateRays(remove, add); 620 } 621 613 622 614 623 … … 772 781 int 773 782 GetPvsSize(VssTreeNode *node, const AxisAlignedBox3 &box) const; 774 783 784 void 785 GetRayContributionStatistics( 786 float &minRayContribution, 787 float &maxRayContribution, 788 float &avgRayContribution 789 ); 790 791 int 792 GenerateRays(const float ratioPerLeaf, 793 SimpleRayContainer &rays); 794 795 float 796 GetAvgPvsSize(); 797 775 798 }; 776 799 -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r387 r401 24 24 25 25 VssPreprocessor { 26 totalSamples 10000026 totalSamples 200000 27 27 samplesPerPass 50000 28 28 } … … 32 32 33 33 maxDepth 40 34 minPvs 1034 minPvs 5 35 35 minSize 0.00001 36 36 maxCostRatio 0.95 37 maxRayContribution 0. 237 maxRayContribution 0.3 38 38 39 39 maxTotalMemory 400
Note: See TracChangeset
for help on using the changeset viewer.