- Timestamp:
- 11/05/05 20:03:25 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r379 r382 1289 1289 "-preprocessor=", 1290 1290 "sampling"); 1291 1291 1292 1293 RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12"); 1294 RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "32"); 1295 RegisterOption("VssTree.maxCostRatio", optFloat, "maxcost=", "0.9"); 1296 RegisterOption("VssTree.maxRayContribution", optFloat, "maxraycontrib=", "0.5"); 1297 1298 RegisterOption("VssTree.epsilon", optFloat, "kd_eps=", "1e-6"); 1299 RegisterOption("VssTree.ct_div_ci", optFloat, "kd_ctdivci=", "1.0"); 1300 RegisterOption("VssTree.randomize", optBool, "randomize", "false"); 1301 RegisterOption("VssTree.splitType", optString, "split=", "queries"); 1302 RegisterOption("VssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000"); 1303 1304 RegisterOption("VssTree.minSize", optFloat, "minsize=", "0.001"); 1305 1306 RegisterOption("VssTree.maxTotalMemory", optFloat, "mem=", "60.0"); 1307 RegisterOption("VssTree.maxStaticMemory", optFloat, "statmem=", "8.0"); 1308 1309 RegisterOption("VssTree.queryType", optString, "qtype=", "static"); 1310 1311 RegisterOption("VssTree.queryPosWeight", optFloat, "qposweight=", "0.0"); 1312 RegisterOption("VssTree.useRefDirSplits", optBool, "refdir", "false"); 1313 RegisterOption("VssTree.refDirAngle", optFloat, "refangle=", "10"); 1314 RegisterOption("VssTree.refDirBoxMaxSize", optFloat, "refboxsize=", "0.1"); 1315 RegisterOption("VssTree.accessTimeThreshold", optInt, "accesstime=", "1000"); 1316 RegisterOption("VssTree.minCollapseDepth", optInt, "colldepth=", "4"); 1317 1292 1318 } 1293 1319 -
trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
r354 r382 11 11 // both mailId and mailbox should be unique for each thread!!! 12 12 static int sMailId; 13 static int sReservedMailboxes; 13 14 int mMailbox; 14 15 … … 26 27 int GetId() { return mId; } 27 28 29 30 static void NewMail(const int reserve = 1) { 31 sMailId += sReservedMailboxes; 32 sReservedMailboxes = reserve; 33 } 34 28 35 void Mail() { mMailbox = sMailId; } 29 static void NewMail() { sMailId++; }30 36 bool Mailed() const { return mMailbox == sMailId; } 31 int IncMail() { return ++mMailbox - sMailId; }32 37 38 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 39 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 40 41 int IncMail() { return ++mMailbox - sMailId; } 42 43 44 33 45 virtual AxisAlignedBox3 GetBox() = 0; 34 46 -
trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
r372 r382 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (1.07a) (Qt 3.3.2) on: Thu Nov 03 11:34:0820053 # Generated by qmake (1.07a) (Qt 3.3.2) on: Sat Nov 05 19:00:35 2005 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 415 415 main.obj: main.cpp \ 416 416 SamplingPreprocessor.h \ 417 VssPreprocessor.h \ 417 418 ExactPreprocessor.h \ 418 419 Parser.h \ … … 441 442 common.h \ 442 443 Ray.h \ 444 VssRay.h \ 443 445 444 446 … … 639 641 Environment.h \ 640 642 VssRay.h \ 643 Intersectable.h \ 641 644 AxisAlignedBox3.h \ 642 645 Statistics.h \ … … 646 649 Matrix4x4.h \ 647 650 Plane3.h \ 651 Pvs.h \ 648 652 649 653 … … 657 661 Polygon3.h \ 658 662 ViewCell.h \ 663 VssRay.h \ 664 VssTree.h \ 659 665 Containers.h \ 660 666 AxisAlignedBox3.h \ … … 672 678 Material.h \ 673 679 Exporter.h \ 680 Statistics.h \ 674 681 675 682 -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
r376 r382 5 5 6 6 int Intersectable::sMailId = 21843194198; 7 int Intersectable::sReservedMailboxes = 1; 7 8 8 9 void -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r376 r382 8 8 #include "ViewCell.h" 9 9 #include "VssRay.h" 10 #include "VssTree.h" 10 11 11 12 VssPreprocessor::VssPreprocessor(): … … 48 49 Intersectable *objectA, *objectB; 49 50 Vector3 pointA, pointB; 50 51 float bsize = Magnitude(box.Size()); 51 52 if (mKdTree->CastRay(ray)) { 52 53 objectA = ray.intersections[0].mObject; … … 57 58 float tmin, tmax; 58 59 box.ComputeMinMaxT(ray, &tmin, &tmax); 60 if (tmax > bsize) { 61 cerr<<"Warning: tmax > box size tmax="<<tmax<<" tmin="<<tmin<<" size="<<bsize<<endl; 62 cerr<<"ray"<<ray<<endl; 63 } 59 64 pointA = ray.Extrap(tmax); 65 60 66 } 61 67 … … 69 75 float tmin, tmax; 70 76 box.ComputeMinMaxT(ray, &tmin, &tmax); 77 if (tmax > bsize) { 78 cerr<<"Warning: tmax > box size tmax="<<tmax<<" tmin="<<tmin<<" size="<<bsize<<endl; 79 cerr<<"ray"<<ray<<endl; 80 } 81 71 82 pointB = ray.Extrap(tmax); 72 83 } … … 86 97 87 98 Vector3 88 VssPreprocessor::GetViewpoint() 89 { 90 AxisAlignedBox3 box = mKdTree->GetBox(); 91 99 VssPreprocessor::GetViewpoint(AxisAlignedBox3 *viewSpaceBox) 100 { 101 AxisAlignedBox3 box; 102 103 if (viewSpaceBox) 104 box =*viewSpaceBox; 105 else 106 box = mKdTree->GetBox(); 107 92 108 // shrink the box in the y direction 93 Vector3 diff(0, -box.Size().y*0.4f, 0);94 box.Enlarge(diff);95 96 109 return box.GetRandomPoint(); 97 110 } … … 100 113 VssPreprocessor::GetDirection(const Vector3 &viewpoint) 101 114 { 102 int i = RandomValue(0, mObjects.size() );115 int i = RandomValue(0, mObjects.size()-1); 103 116 Intersectable *object = mObjects[i]; 104 117 Vector3 point, normal; … … 114 127 115 128 mSceneGraph->CollectObjects(&mObjects); 116 117 129 cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<mObjects.size()<<endl; 130 118 131 long startTime = GetTime(); 119 132 … … 121 134 int totalSamples = 0; 122 135 123 136 AxisAlignedBox3 *viewSpaceBox = NULL; 137 138 AxisAlignedBox3 box = mKdTree->GetBox(); 139 box.Enlarge(box.Size()*-Vector3(0.45, 0.45, 0.45)); 140 141 bool useViewSpaceBox = false; 142 if (useViewSpaceBox) 143 viewSpaceBox = &box; 144 124 145 while (totalSamples < mTotalSamples) { 125 146 int passContributingSamples = 0; … … 132 153 133 154 for (int k=0; k < mSamplesPerPass; k++) { 134 135 Vector3 viewpoint = GetViewpoint( );155 156 Vector3 viewpoint = GetViewpoint(viewSpaceBox); 136 157 Vector3 direction = GetDirection(viewpoint); 137 158 138 159 VssRay *vssRay = CastRay(viewpoint, direction); 139 160 … … 153 174 154 175 mPass++; 155 176 156 177 int pvsSize = 0; 157 178 float avgRayContrib = (passContributingSamples > 0) ? … … 176 197 177 198 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 178 cout << "#totalRayStackSize=" << mVssRays.size() << endl; 179 199 cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush; 200 201 VssTree *vssTree = new VssTree; 202 203 vssTree->Construct(mVssRays, viewSpaceBox); 204 180 205 return true; 181 206 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
r376 r382 28 28 29 29 Vector3 30 GetViewpoint( );30 GetViewpoint(AxisAlignedBox3 *viewSpaceBox); 31 31 32 32 Vector3 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp
r372 r382 141 141 return SqrDistance(point, center) < sqrRadius; 142 142 } 143 144 145 float 146 VssRay::GetDirParametrization(const int axis) const 147 { 148 float angle; 149 Vector3 dir = GetNormalizedDir(); 150 if (axis == 0) { 151 angle = atan2(dir.x, dir.z); 152 } else { 153 angle = asin(dir.y); 154 } 155 return angle; 156 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
r376 r382 22 22 23 23 // side of the ray - used for the ray classification 24 char mSide;24 // char mSide; 25 25 26 26 // computed t … … 98 98 Vector3 GetNormalizedDir() const { return (mTermination - mOrigin)*mInvSize; } 99 99 100 float GetDirParametrization(const int axis) const; 101 100 102 float GetInvSize() const { return mInvSize; } 101 103 float GetOrigin(const int axis) const { return mOrigin[axis]; } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
r372 r382 22 22 #include "Environment.h" 23 23 #include "VssRay.h" 24 #include "Intersectable.h" 24 25 25 26 … … 32 33 VssTreeLeaf::mailID = 0; 33 34 35 inline void 36 AddObject2Pvs(Intersectable *object, 37 const int side, 38 int &pvsBack, 39 int &pvsFront) 40 { 41 42 if (!object) 43 return; 44 45 if (side <= 0) { 46 if (!object->Mailed() && !object->Mailed(2)) { 47 pvsBack++; 48 if (object->Mailed(1)) 49 object->Mail(2); 50 else 51 object->Mail(); 52 } 53 } 54 55 if (side >= 0) { 56 if (!object->Mailed(1) && !object->Mailed(2)) { 57 pvsFront++; 58 if (object->Mailed()) 59 object->Mail(2); 60 else 61 object->Mail(1); 62 } 63 } 64 } 65 34 66 35 67 // Constructor … … 37 69 { 38 70 environment->GetIntValue("VssTree.maxDepth", termMaxDepth); 39 40 environment->GetIntValue("VssTree.minCost", termMinCost); 71 environment->GetIntValue("VssTree.minPvs", termMinPvs); 72 environment->GetFloatValue("VssTree.maxRayContribution", termMaxRayContribution); 73 environment->GetFloatValue("VssTree.maxCostRatio", termMaxCostRatio); 41 74 42 75 environment->GetFloatValue("VssTree.minSize", termMinSize); 43 76 termMinSize = sqr(termMinSize); 44 77 45 78 environment->GetFloatValue("VssTree.refDirBoxMaxSize", refDirBoxMaxSize); 46 79 refDirBoxMaxSize = sqr(refDirBoxMaxSize); … … 48 81 environment->GetFloatValue("VssTree.epsilon", epsilon); 49 82 environment->GetFloatValue("VssTree.ct_div_ci", ct_div_ci); 50 83 51 84 environment->GetFloatValue("VssTree.maxTotalMemory", maxTotalMemory); 52 85 environment->GetFloatValue("VssTree.maxStaticMemory", maxStaticMemory); 53 86 54 environment->GetFloatValue("VssTree.maxCostRatio", maxCostRatio);55 87 56 88 … … 77 109 splitType = ESplitRegular; 78 110 else 79 if (name.compare(" volume") == 0)111 if (name.compare("heuristics") == 0) 80 112 splitType = ESplitVolume; 81 else 82 if (name.compare("queries") == 0) 83 splitType = ESplitQueries; 84 else { 85 cerr<<"Invalid VssTree split type "<<name<<endl; 86 exit(1); 87 } 113 else { 114 cerr<<"Invalid VssTree split type "<<name<<endl; 115 exit(1); 116 } 88 117 89 118 environment->GetBoolValue("VssTree.randomize", randomize); … … 91 120 root = NULL; 92 121 93 splitCandidates = new vector<S SortableEntry>;122 splitCandidates = new vector<SortableEntry>; 94 123 } 95 124 … … 109 138 app << "===== VssTree statistics ===============\n"; 110 139 111 app << "#N_RAYS Number of rays )\n"140 app << "#N_RAYS ( Number of rays )\n" 112 141 << rays <<endl; 113 app << "#N_DOMAINS ( Number of query domains )\n" 114 << queryDomains <<endl; 142 143 app << "#N_INITPVS ( Initial PVS size )\n" 144 << initialPvsSize <<endl; 115 145 116 146 app << "#N_NODES ( Number of nodes )\n" << nodes << "\n"; … … 135 165 maxRayRefs << "\n"; 136 166 137 app << "#N_NONEMPTYRAYREFS ( Number of rayRefs in nonEmpty leaves / non empty leaf )\n" <<138 rayRefsNonZeroQuery/(double)(Leaves() - zeroQueryNodes) << "\n";139 140 app << "#N_LEAFDOMAINREFS ( Number of query domain Refs / leaf )\n" <<141 queryDomainRefs/(double)Leaves() << "\n";142 167 143 168 // app << setprecision(4); 144 145 app << "#N_PEMPTYLEAVES ( Percentage of leaves with zero query domains )\n"<<146 zeroQueryNodes*100/(double)Leaves()<<endl;147 169 148 170 app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maxdepth )\n"<< … … 151 173 app << "#N_PMINCOSTLEAVES ( Percentage of leaves with minCost )\n"<< 152 174 minCostNodes*100/(double)Leaves()<<endl; 175 176 app << "#N_PMINSIZELEAVES ( Percentage of leaves with minSize )\n"<< 177 minSizeNodes*100/(double)Leaves()<<endl; 178 179 app << "#N_PMAXRAYCONTRIBLEAVES ( Percentage of leaves with maximal ray contribution )\n"<< 180 maxRayContribNodes*100/(double)Leaves()<<endl; 153 181 154 182 app << "#N_ADDED_RAYREFS (Number of dynamically added ray references )\n"<< … … 173 201 VssTree::Construct( 174 202 VssRayContainer &rays, 175 const bool onlyStaticPart203 AxisAlignedBox3 *forcedBoundingBox 176 204 ) 177 205 { 178 206 stat.Start(); 179 207 180 if (onlyStaticPart) 181 maxMemory = maxStaticMemory; 182 else 183 maxMemory = maxTotalMemory; 184 208 maxMemory = maxStaticMemory; 185 209 186 210 if (root) … … 194 218 195 219 bbox.Initialize(); 196 197 220 dirBBox.Initialize(); 198 221 … … 201 224 ri++) { 202 225 leaf->AddRay(VssTreeNode::RayInfo(*ri)); 226 203 227 bbox.Include((*ri)->GetOrigin()); 204 228 bbox.Include((*ri)->GetTermination()); 205 229 206 dirBBox.Include( (*ri)->GetNormalizedDir() ); 207 } 208 209 230 231 dirBBox.Include(Vector3( 232 (*ri)->GetDirParametrization(0), 233 (*ri)->GetDirParametrization(1), 234 0 235 ) 236 ); 237 } 238 239 240 if (forcedBoundingBox) 241 bbox = *forcedBoundingBox; 242 243 cout<<"Bbox = "<<bbox<<endl; 244 cout<<"Dirr Bbox = "<<dirBBox<<endl; 245 210 246 stat.rays = leaf->rays.size(); 211 247 EvalLeafPvs(leaf); 248 stat.initialPvsSize = leaf->mPvsSize; 212 249 // Subdivide(); 213 250 root = Subdivide(TraversalData(leaf, bbox, 0)); … … 216 253 // force realease of this vector 217 254 delete splitCandidates; 218 splitCandidates = new vector<S SortableEntry>;255 splitCandidates = new vector<SortableEntry>; 219 256 } 220 257 221 258 stat.Stop(); 222 259 223 cout<<"##################################"<<endl; 224 260 stat.Print(cout); 261 cout<<"#Total memory="<<GetMemUsage()<<endl; 262 263 } 264 265 void 266 VssTree::EvalLeafPvs(VssTreeLeaf *leaf) 267 { 268 Intersectable::NewMail(); 269 int pvsSize = 0; 270 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 271 ri != leaf->rays.end(); 272 ri++) 273 if ((*ri).mRay->IsActive()) { 274 Intersectable *object = (*ri).mRay->mOriginObject; 275 if (object && !object->Mailed()) { 276 pvsSize++; 277 object->Mail(); 278 } 279 object = (*ri).mRay->mTerminationObject; 280 if (object && !object->Mailed()) { 281 pvsSize++; 282 object->Mail(); 283 } 284 } 285 leaf->mPvsSize = pvsSize; 225 286 } 226 287 … … 283 344 VssTreeLeaf *leaf, 284 345 const AxisAlignedBox3 &box, 285 float &position 346 float &position, 347 int &raysBack, 348 int &raysFront, 349 int &pvsBack, 350 int &pvsFront 286 351 ) 287 352 { 288 353 289 354 int minDirDepth = 6; 290 291 Vector3 size = box.Size(); 292 293 float pDirSubdivision = 0.0f; 294 if (leaf->depth >= minDirDepth && RandomValue(0, 1) < pDirSubdivision) { 295 AxisAlignedBox3 dirbox = GetDirBBox(leaf); 296 Vector3 size = dirbox.Size(); 297 int axis = size.DrivingAxis(); 298 position = (dirbox.Min()[axis] + dirbox.Max()[axis])*0.5f; 299 return axis + 3; 300 } 301 302 int axis = size.DrivingAxis(); 303 304 355 int axis; 356 float costRatio; 357 305 358 if (splitType == ESplitRegular) { 306 position = (box.Min()[axis] + box.Max()[axis])*0.5f; 307 } 308 309 return axis; 359 int sRaysBack, sRaysFront; 360 int dRaysBack, dRaysFront; 361 int sPvsBack, sPvsFront; 362 int dPvsBack, dPvsFront; 363 364 365 int sAxis = box.Size().DrivingAxis(); 366 float sPosition = (box.Min()[sAxis] + box.Max()[sAxis])*0.5f; 367 float sCostRatio = EvalCostRatio(leaf, 368 sAxis, 369 sPosition, 370 sRaysBack, 371 sRaysFront, 372 sPvsBack, 373 sPvsFront 374 ); 375 // cout<<"srays back="<<sRaysBack<<" rays front="<<sRaysFront<<" pvs back="<<sPvsBack<< 376 // " pvs front="<<sPvsFront<<endl; 377 378 AxisAlignedBox3 dirBox = GetDirBBox(leaf); 379 int dAxis = dirBox.Size().DrivingAxis(); 380 float dPosition = (dirBox.Min()[dAxis] + dirBox.Max()[dAxis])*0.5f; 381 float dCostRatio = EvalCostRatio(leaf, 382 dAxis+3, 383 dPosition, 384 dRaysBack, 385 dRaysFront, 386 dPvsBack, 387 dPvsFront 388 ); 389 390 // cout<<"drays back="<<dRaysBack<<" rays front="<<dRaysFront<<" pvs back="<<dPvsBack<< 391 // " pvs front="<<dPvsFront<<endl; 392 393 if (sCostRatio < dCostRatio) { 394 costRatio = sCostRatio; 395 axis = sAxis; 396 position = sPosition; 397 raysBack = sRaysBack; 398 raysFront = sRaysFront; 399 pvsBack = sPvsBack; 400 pvsFront = sPvsFront; 401 402 } else { 403 costRatio = dCostRatio; 404 axis = dAxis+3; 405 position = dPosition; 406 raysBack = dRaysBack; 407 raysFront = dRaysFront; 408 pvsBack = dPvsBack; 409 pvsFront = dPvsFront; 410 } 411 412 } else { 413 if (splitType == ESplitVolume) 414 costRatio = BestCostRatio(leaf, 415 axis, 416 position, 417 raysBack, 418 raysFront); 419 else { 420 cerr<<"VssTree: Unknown split heuristics\n"; 421 exit(1); 422 } 423 } 424 425 if (costRatio > termMaxCostRatio) { 426 cout<<"Too big cost ratio "<<costRatio<<endl; 427 return -1; 428 } 429 430 #if 0 431 cout<< 432 "pvs="<<leaf->mPvsSize<< 433 " rays="<<leaf->rays.size()<< 434 " rc="<<leaf->GetAvgRayContribution()<< 435 " axis="<<axis<<endl; 436 #endif 437 438 return axis; 439 } 440 441 442 443 444 float 445 VssTree::EvalCostRatio( 446 VssTreeLeaf *leaf, 447 const int axis, 448 const float position, 449 int &raysBack, 450 int &raysFront, 451 int &pvsBack, 452 int &pvsFront 453 ) 454 { 455 raysBack = 0; 456 raysFront = 0; 457 pvsFront = 0; 458 pvsBack = 0; 459 460 float newCost; 461 462 Intersectable::NewMail(3); 463 464 // eval pvs size 465 int pvsSize = leaf->mPvsSize; 466 467 Intersectable::NewMail(3); 468 469 if (axis <= VssTreeNode::SPLIT_Z) { 470 // this is the main ray classification loop! 471 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 472 ri != leaf->rays.end(); 473 ri++) 474 if ((*ri).mRay->IsActive()) { 475 476 // determine the side of this ray with respect to the plane 477 int side = (*ri).ComputeRayIntersection(axis, position, (*ri).mRay->mT); 478 479 // (*ri).mRay->mSide = side; 480 481 if (side <= 0) 482 raysBack++; 483 484 if (side >= 0) 485 raysFront++; 486 487 AddObject2Pvs((*ri).mRay->mOriginObject, side, pvsBack, pvsFront); 488 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 489 490 } 491 492 AxisAlignedBox3 box = GetBBox(leaf); 493 494 float minBox = box.Min(axis); 495 float maxBox = box.Max(axis); 496 float sizeBox = maxBox - minBox; 497 498 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 499 float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 500 501 newCost = ct_div_ci + sum/sizeBox; 502 503 } else { 504 505 // directional split 506 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 507 ri != leaf->rays.end(); 508 ri++) 509 if ((*ri).mRay->IsActive()) { 510 511 // determine the side of this ray with respect to the plane 512 int side; 513 if ((*ri).mRay->GetDirParametrization(axis - 3) > position) 514 side = 1; 515 else 516 side = -1; 517 518 if (side <= 0) 519 raysBack++; 520 521 if (side >= 0) 522 raysFront++; 523 524 // (*ri).mRay->mSide = side; 525 526 AddObject2Pvs((*ri).mRay->mOriginObject, side, pvsBack, pvsFront); 527 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 528 529 } 530 531 AxisAlignedBox3 box = GetDirBBox(leaf); 532 533 float minBox = box.Min(axis-3); 534 float maxBox = box.Max(axis-3); 535 float sizeBox = maxBox - minBox; 536 537 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 538 float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 539 // float sum = pvsBack + pvsFront; 540 newCost = ct_div_ci + sum/sizeBox; 541 } 542 543 // cout<<axis<<" "<<pvsSize<<" "<<pvsBack<<" "<<pvsFront<<endl; 544 // float oldCost = leaf->rays.size(); 545 float oldCost = pvsSize; 546 float ratio = newCost/oldCost; 547 // cout<<"ratio="<<ratio<<endl; 548 return ratio; 549 } 550 551 float 552 VssTree::BestCostRatio( 553 VssTreeLeaf *node, 554 int &axis, 555 float &position, 556 int &raysBack, 557 int &raysFront 558 ) 559 { 560 AxisAlignedBox3 box = GetBBox(node); 561 AxisAlignedBox3 dirBox = GetDirBBox(node); 562 563 axis = box.Size().DrivingAxis(); 564 565 SortSplitCandidates(node, axis); 566 567 // go through the lists, count the number of objects left and right 568 // and evaluate the following cost funcion: 569 // C = ct_div_ci + (ql*rl + qr*rr)/queries 570 571 int rl=0, rr=node->rays.size(); 572 573 float minBox = box.Min(axis); 574 float maxBox = box.Max(axis); 575 float sizeBox = maxBox - minBox; 576 577 float minBand = minBox + 0.1*(maxBox - minBox); 578 float maxBand = minBox + 0.9*(maxBox - minBox); 579 580 float sum = rr*sizeBox; 581 float minSum = 1e20; 582 583 for(vector<SortableEntry>::const_iterator ci = splitCandidates->begin(); 584 ci < splitCandidates->end(); 585 ci++) { 586 587 switch ((*ci).type) { 588 case SortableEntry::ERayMin: 589 rl++; 590 break; 591 case SortableEntry::ERayMax: 592 rr--; 593 break; 594 } 595 596 if ((*ci).value > minBand && (*ci).value < maxBand) { 597 598 sum = rl*((*ci).value - minBox) + rr*(maxBox - (*ci).value); 599 600 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 601 // cout<<"cost= "<<sum<<endl; 602 603 if (sum < minSum) { 604 minSum = sum; 605 position = (*ci).value; 606 607 raysBack = rl; 608 raysFront = rr; 609 610 } 611 } 612 } 613 614 float oldCost = node->rays.size(); 615 float newCost = ct_div_ci + minSum/sizeBox; 616 float ratio = newCost/oldCost; 617 618 // cout<<"===================="<<endl; 619 // cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 620 // <<"\t q=("<<queriesBack<<","<<queriesFront<<")\t r=("<<raysBack<<","<<raysFront<<")"<<endl; 621 622 return ratio; 623 } 624 625 void 626 VssTree::SortSplitCandidates( 627 VssTreeLeaf *node, 628 const int axis 629 ) 630 { 631 632 splitCandidates->clear(); 633 634 int requestedSize = 2*(node->rays.size()); 635 // creates a sorted split candidates array 636 if (splitCandidates->capacity() > 500000 && 637 requestedSize < (int)(splitCandidates->capacity()/10) ) { 638 639 delete splitCandidates; 640 splitCandidates = new vector<SortableEntry>; 641 } 642 643 splitCandidates->reserve(requestedSize); 644 645 // insert all queries 646 for(VssTreeNode::RayInfoContainer::const_iterator ri = node->rays.begin(); 647 ri < node->rays.end(); 648 ri++) { 649 bool positive = (*ri).mRay->HasPosDir(axis); 650 splitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : 651 SortableEntry::ERayMax, 652 (*ri).ExtrapOrigin(axis), 653 (void *)&*ri) 654 ); 655 656 splitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : 657 SortableEntry::ERayMin, 658 (*ri).ExtrapTermination(axis), 659 (void *)&*ri) 660 ); 661 } 662 663 stable_sort(splitCandidates->begin(), splitCandidates->end()); 310 664 } 311 665 … … 318 672 VssTreeLeaf *leaf = (VssTreeLeaf *)data.node; 319 673 320 if (data.depth > termMaxDepth)674 if (data.depth >= termMaxDepth) 321 675 stat.maxDepthNodes++; 322 676 323 if ( (int)(leaf->rays.size()) < termMinCost) 324 stat.minCostNodes++; 325 326 327 if ( (int)(leaf->rays.size()) > stat.maxRayRefs) 677 // if ( (int)(leaf->rays.size()) < termMinCost) 678 // stat.minCostNodes++; 679 if ( leaf->mPvsSize < termMinPvs) 680 stat.minCostNodes++; 681 682 if (leaf->GetAvgRayContribution() > termMaxRayContribution ) 683 stat.maxRayContribNodes++; 684 685 if (SqrMagnitude(data.bbox.Size()) <= termMinSize) { 686 stat.minSizeNodes++; 687 } 688 689 if ( (int)(leaf->rays.size()) > stat.maxRayRefs) 328 690 stat.maxRayRefs = leaf->rays.size(); 329 691 330 692 } 331 693 … … 341 703 { 342 704 343 if ( ((int)leaf->rays.size() < termMinCost) || 344 (leaf->depth >= termMaxDepth) ) { 345 return leaf; 346 } 347 348 float position; 349 705 if ( (leaf->mPvsSize < termMinPvs) || 706 (leaf->GetAvgRayContribution() > termMaxRayContribution ) || 707 (leaf->depth >= termMaxDepth) || 708 SqrMagnitude(box.Size()) <= termMinSize ) { 709 710 #if 0 711 if (leaf->depth >= termMaxDepth) { 712 cout<<"Warning: max depth reached depth="<<(int)leaf->depth<<" rays="<<leaf->rays.size()<<endl; 713 cout<<"Bbox: "<<GetBBox(leaf)<<" dirbbox:"<<GetDirBBox(leaf)<<endl; 714 } 715 #endif 716 717 return leaf; 718 } 719 720 float position; 721 722 // first count ray sides 723 int raysBack; 724 int raysFront; 725 int pvsBack; 726 int pvsFront; 727 350 728 // select subdivision axis 351 int axis = SelectPlane( leaf, box, position); 729 int axis = SelectPlane( leaf, box, position, raysBack, raysFront, pvsBack, pvsFront); 730 731 // cout<<"rays back="<<raysBack<<" rays front="<<raysFront<<" pvs back="<<pvsBack<<" pvs front="<< 732 // pvsFront<<endl; 352 733 353 734 if (axis == -1) { … … 364 745 node->position = position; 365 746 node->bbox = box; 366 367 747 node->dirBBox = GetDirBBox(leaf); 368 748 … … 370 750 frontBBox = box; 371 751 372 // first count ray sides373 int raysBack = 0;374 int raysFront = 0;375 376 if (axis <= VssTreeNode::SPLIT_Z) {377 backBBox.SetMax(axis, position);378 frontBBox.SetMin(axis, position);379 380 // this is the main ray classification loop!381 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();382 ri != leaf->rays.end();383 ri++)384 if ((*ri).mRay->IsActive()) {385 386 // determine the side of this ray with respect to the plane387 int side = node->ComputeRayIntersection(*ri, (*ri).mRay->mT);388 389 (*ri).mRay->mSide = side;390 391 if (side <= 0)392 raysBack++;393 394 if (side >= 0)395 raysFront++;396 397 #if 0398 cout<<"-------------------"<<endl;399 cout<<"axis = "<<(int)node->axis<<"\t position="<<node->position<<endl;400 cout<<"origin="<<(*ri).ray->GetOrigin()<<"\t term="<<(*ri).ray->GetTermination()<<endl;401 cout<<"side = "<<side<<"\t t="<<t<<endl;402 cout<<"-------------------"<<endl;403 #endif404 }405 } else {406 // directional split407 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin();408 ri != leaf->rays.end();409 ri++)410 if ((*ri).mRay->IsActive()) {411 412 // determine the side of this ray with respect to the plane413 int side;414 if ((*ri).mRay->GetNormalizedDir(axis - 3) > position)415 side = 1;416 else417 side = -1;418 419 420 (*ri).mRay->mSide = side;421 422 if (side <= 0)423 raysBack++;424 425 if (side >= 0)426 raysFront++;427 }428 }429 430 752 VssTreeLeaf *back = new VssTreeLeaf(node, raysBack); 753 back->mPvsSize = pvsBack; 431 754 VssTreeLeaf *front = new VssTreeLeaf(node, raysFront); 755 front->mPvsSize = pvsFront; 432 756 433 757 // replace a link from node's parent … … 436 760 // and setup child links 437 761 node->SetupChildLinks(back, front); 438 439 762 440 763 if (axis <= VssTreeNode::SPLIT_Z) { 441 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 764 backBBox.SetMax(axis, position); 765 frontBBox.SetMin(axis, position); 766 767 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 442 768 ri != leaf->rays.end(); 443 769 ri++) { … … 446 772 // first unref ray from the former leaf 447 773 (*ri).mRay->Unref(); 448 449 if ((*ri).mRay->mSide == 0) { 774 775 // determine the side of this ray with respect to the plane 776 int side = node->ComputeRayIntersection(*ri, (*ri).mRay->mT); 777 778 if (side == 0) { 450 779 if ((*ri).mRay->HasPosDir(axis)) { 451 780 back->AddRay(VssTreeNode::RayInfo((*ri).mRay, … … 465 794 } 466 795 } else 467 if ( (*ri).mRay->mSide == 1)796 if (side == 1) 468 797 front->AddRay(*ri); 469 798 else … … 475 804 // rays front/back 476 805 477 #if DEBUG_DIR_SPLIT478 cout<<"dir split, depth="<<(int)leaf->depth<<" front= "<<raysFront<<" back="<<raysBack<<endl;479 #endif480 806 481 807 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); … … 485 811 // first unref ray from the former leaf 486 812 (*ri).mRay->Unref(); 487 488 if ((*ri).mRay->mSide == 1) 813 814 int side; 815 if ((*ri).mRay->GetDirParametrization(axis - 3) > position) 816 side = 1; 817 else 818 side = -1; 819 820 if (side == 1) 489 821 front->AddRay(*ri); 490 822 else … … 573 905 // check if we should perform a dynamic subdivision of the leaf 574 906 if ( 575 leaf->rays.size() > (unsigned)termMinCost && 907 // leaf->rays.size() > (unsigned)termMinCost && 908 (leaf->mPvsSize >= termMinPvs) && 576 909 SqrMagnitude(leafBBox.Size()) > sizeThreshold) { 577 910 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
r372 r382 43 43 // totals number of rays 44 44 int rays; 45 // total number of query domains 45 // initial size of the pvs 46 int initialPvsSize; 47 // total number of query domains 46 48 int queryDomains; 47 49 // total number of ray references 48 50 int rayRefs; 49 // refs in non empty leafs 50 int rayRefsNonZeroQuery; 51 // total number of query references 52 int queryDomainRefs; 53 // nodes with zero queries 54 int zeroQueryNodes; 55 // max depth nodes 51 52 // max depth nodes 56 53 int maxDepthNodes; 57 54 // max depth nodes 58 55 int minCostNodes; 56 // max ray contribution nodes 57 int maxRayContribNodes; 58 // max depth nodes 59 int minSizeNodes; 60 59 61 // max number of rays per node 60 62 int maxRayRefs; … … 78 80 splits[i] = 0; 79 81 rays = queryDomains = 0; 80 rayRefs = rayRefsNonZeroQuery = queryDomainRefs = 0; 81 zeroQueryNodes = 0; 82 rayRefs = 0; 82 83 maxDepthNodes = 0; 83 84 minCostNodes = 0; 84 85 maxRayRefs = 0; 85 86 addedRayRefs = removedRayRefs = 0; 87 initialPvsSize = 0; 88 maxRayContribNodes = 0; 89 minSizeNodes = 0; 86 90 } 87 91 … … 101 105 // For sorting rays 102 106 // -------------------------------------------------------------- 103 struct S SortableEntry107 struct SortableEntry 104 108 { 105 109 enum EType { … … 112 116 void *data; 113 117 114 S SortableEntry() {}115 S SortableEntry(const int t, const float v, void *d):type(t),116 117 118 119 friend bool operator<(const S SortableEntry &a, const SSortableEntry &b) {118 SortableEntry() {} 119 SortableEntry(const int t, const float v, void *d):type(t), 120 value(v), 121 data(d) {} 122 123 friend bool operator<(const SortableEntry &a, const SortableEntry &b) { 120 124 return a.value < b.value; 121 125 } … … 215 219 void SetMaxT (const float t) { mMaxT = t; } 216 220 #endif 221 222 223 int ComputeRayIntersection(const float axis, 224 const float position, 225 float &t 226 ) const { 227 228 // intersect the ray with the plane 229 float denom = mRay->GetDir(axis); 230 231 if (fabs(denom) < 1e-20) 232 //if (denom == 0.0f) 233 return (mRay->GetOrigin(axis) > position) ? 1 : -1; 234 235 t = (position - mRay->GetOrigin(axis))/denom; 236 237 if (t < GetMinT()) 238 return (denom > 0) ? 1 : -1; 239 240 if (t > GetMaxT()) 241 return (denom > 0) ? -1 : 1; 242 243 return 0; 244 } 245 246 217 247 }; 218 248 … … 329 359 330 360 361 331 362 int ComputeRayIntersection(const RayInfo &rayData, 332 363 float &t 333 364 ) { 334 335 // intersect the ray with the plane 336 float denom = rayData.mRay->GetDir(axis); 337 338 if (fabs(denom) < 1e-20) 339 //if (denom == 0.0f) 340 return (rayData.mRay->GetOrigin(axis) > position) ? 1 : -1; 341 342 t = (position - rayData.mRay->GetOrigin(axis))/denom; 343 344 if (t < rayData.GetMinT()) 345 return (denom > 0) ? 1 : -1; 346 347 if (t > rayData.GetMaxT()) 348 return (denom > 0) ? -1 : 1; 349 350 return 0; 365 return rayData.ComputeRayIntersection(axis, position, t); 351 366 } 352 367 … … 365 380 366 381 RayInfoContainer rays; 367 368 369 VssTreeLeaf(VssTreeInterior *p, const int n):VssTreeNode(p), rays() { 370 rays.reserve(n); 382 int mPvsSize; 383 384 VssTreeLeaf(VssTreeInterior *p, 385 const int nRays 386 ):VssTreeNode(p), rays(), mPvsSize(0) { 387 rays.reserve(nRays); 371 388 } 372 389 … … 392 409 } 393 410 411 float GetAvgRayContribution() const { 412 return mPvsSize/(float)rays.size(); 413 } 394 414 }; 395 415 … … 490 510 // max depth of the tree 491 511 int termMaxDepth; 492 // minimal cost of the node to still get subdivided493 int termMinCost;494 512 // minimal ratio of the volume of the cell and the query volume 495 513 float termMinSize; 496 514 497 // minimal cost imporvement to subdivide a node 498 float maxCostRatio; 499 515 // minimal pvs per node to still get subdivided 516 int termMinPvs; 517 518 // maximal cost ration to subdivide a node 519 float termMaxCostRatio; 520 521 // maximal contribution per ray to subdivide the node 522 float termMaxRayContribution; 523 524 500 525 // randomized construction 501 526 bool randomize; 502 527 503 528 // type of the splitting to use fo rthe tree construction 504 enum {ESplitRegular, ESplitVolume , ESplitQueries};529 enum {ESplitRegular, ESplitVolume }; 505 530 int splitType; 506 531 … … 528 553 529 554 // reusable array of split candidates 530 vector<S SortableEntry> *splitCandidates;555 vector<SortableEntry> *splitCandidates; 531 556 ///////////////////////////// 532 557 … … 540 565 Construct( 541 566 VssRayContainer &rays, 542 const bool onlyStaticPart567 AxisAlignedBox3 *forcedBoundingBox = NULL 543 568 ); 544 569 … … 565 590 int 566 591 SelectPlane(VssTreeLeaf *leaf, 567 const AxisAlignedBox3 &box, 568 float &position 569 ); 592 const AxisAlignedBox3 &box, 593 float &position, 594 int &raysBack, 595 int &raysFront, 596 int &pvsBack, 597 int &pvsFront 598 ); 570 599 571 600 void … … 590 619 } 591 620 621 float 622 BestCostRatio( 623 VssTreeLeaf *node, 624 int &axis, 625 float &position, 626 int &raysBack, 627 int &raysFront 628 ); 629 630 float 631 EvalCostRatio( 632 VssTreeLeaf *node, 633 const int axis, 634 const float position, 635 int &raysBack, 636 int &raysFront, 637 int &pvsBack, 638 int &pvsFront 639 ); 592 640 593 641 AxisAlignedBox3 GetBBox(const VssTreeNode *node) { … … 664 712 EvaluateLeafStats(const TraversalData &data); 665 713 714 void 715 EvalLeafPvs(VssTreeLeaf *leaf); 716 717 666 718 }; 667 719 -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r376 r382 9 9 # filename vienna.x3d 10 10 # filename ../data/vienna/vienna-simple.x3d 11 filename ../data/vienna/vienna-buildings.x3d11 # filename ../data/vienna/vienna-buildings.x3d 12 12 # filename ../data/vienna/viewcells-25-sel.x3d 13 13 # filename ../data/atlanta/atlanta2.x3d 14 14 # filename ../data/soda/soda.dat 15 #filename ../data/soda/soda5.dat15 filename ../data/soda/soda5.dat 16 16 } 17 17 … … 22 22 23 23 VssPreprocessor { 24 totalSamples 1000000 25 samplesPerPass 100000 24 totalSamples 200000 25 samplesPerPass 50000 26 } 27 28 VssTree { 29 epsilon 1e-6 30 31 maxDepth 40 32 minPvs 10 33 minSize 0.00001 34 maxCostRatio 1.0 35 maxRayContribution 0.5 36 37 maxTotalMemory 500 38 maxStaticMemory 200 39 40 splitType regular 41 # splitType heuristics 42 43 numberOfEndPointDomains 10000 44 ct_div_ci 0.0 45 randomize false 46 47 refDirBoxMaxSize 0.1 26 48 } 27 49 … … 66 88 67 89 Sampling { 68 totalSamples 10000000 090 totalSamples 10000000 69 91 samplesPerPass 3 70 92 } -
trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
r372 r382 40 40 ViewCell.cpp ViewCellBsp.cpp Halton.cpp VssRay.cpp VssTree.cpp VssPreprocessor.cpp 41 41 42
Note: See TracChangeset
for help on using the changeset viewer.