- Timestamp:
- 11/07/05 23:17:14 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r376 r387 54 54 return mMax[axis]; 55 55 } 56 56 57 float Size(const int axis) const { 58 return Max(axis) - Min(axis); 59 } 60 57 61 // Read-only const access tomMin and max vectors using references 58 62 const Vector3& Min() const { return mMin;} -
trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
r382 r387 17 17 int mId; 18 18 19 // universal counter 20 int mCounter; 21 19 22 // object based pvs 20 23 KdPvs mKdPvs; … … 51 54 virtual float IntersectionComplexity() = 0; 52 55 53 virtual int Type() const = 0; 56 virtual int NumberOfFaces() const = 0; 57 58 virtual int Type() const = 0; 54 59 55 60 virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r372 r387 192 192 virtual float IntersectionComplexity() { return (float)mMesh->mFaces.size(); } 193 193 194 virtual int NumberOfFaces() const { return mMesh->mFaces.size(); } 195 194 196 virtual int Type() const { return MESH_INSTANCE; } 195 197 -
trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
r372 r387 92 92 } 93 93 94 int 95 SplitFilenames(const string str, 96 vector<string> &filenames) 97 { 98 int pos = 0; 99 100 while(1) { 101 int npos = str.find(';', pos); 102 103 if (npos < 0 || npos - pos < 1) 104 break; 105 filenames.push_back(string(str, pos, npos - pos)); 106 pos = npos + 1; 107 } 108 109 filenames.push_back(string(str, pos, str.size() - pos)); 110 return filenames.size(); 111 } 112 94 113 bool 95 114 Preprocessor::LoadScene(const string filename) … … 101 120 102 121 Parser *parser; 103 104 if (strstr(filename.c_str(), ".x3d")) 105 parser = new X3dParser; 106 else 107 parser = new UnigraphicsParser; 108 109 bool result = parser->ParseFile(filename, &mSceneGraph->mRoot); 110 111 112 113 delete parser; 114 115 if (result) 122 vector<string> filenames; 123 int files = SplitFilenames(filename, filenames); 124 cout<<files<<endl; 125 bool result = false; 126 if (files == 1) { 127 128 if (strstr(filename.c_str(), ".x3d")) 129 parser = new X3dParser; 130 else 131 parser = new UnigraphicsParser; 132 133 cout<<filename<<endl; 134 result = parser->ParseFile(filename, &mSceneGraph->mRoot); 135 136 delete parser; 137 138 } else { 139 // root for different files 140 mSceneGraph->mRoot = new SceneGraphNode; 141 for (int i= 0; i < filenames.size(); i++) { 142 if (strstr(filenames[i].c_str(), ".x3d")) 143 parser = new X3dParser; 144 else 145 parser = new UnigraphicsParser; 146 147 SceneGraphNode *node; 148 if (parser->ParseFile(filenames[i], &node)) { 149 mSceneGraph->mRoot->mChildren.push_back(node); 150 // at least one file parsed 151 result = true; 152 } 153 delete parser; 154 } 155 } 156 157 158 if (result) { 116 159 mSceneGraph->AssignObjectIds(); 160 int intersectables, faces; 161 mSceneGraph->GetStatistics(intersectables, faces); 162 cout<<filename<<" parsed successfully."<<endl; 163 cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; 164 cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl; 165 } 166 117 167 118 168 return result; -
trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp
r339 r387 77 77 return id; 78 78 } 79 80 void 81 SceneGraph::GetStatistics(int &intersectables, int &faces) const 82 { 83 stack<SceneGraphNode *> nodeStack; 84 85 nodeStack.push(mRoot); 86 faces = 0; 87 intersectables = 0; 88 while (!nodeStack.empty()) { 89 SceneGraphNode *node = nodeStack.top(); 90 nodeStack.pop(); 91 92 ObjectContainer::const_iterator mi = node->mGeometry.begin(); 93 for (; mi != node->mGeometry.end(); mi++) { 94 intersectables++; 95 faces += (*mi)->NumberOfFaces(); 96 } 97 98 SceneGraphNodeContainer::iterator ni = node->mChildren.begin(); 99 for (; ni != node->mChildren.end(); ni++) { 100 nodeStack.push(*ni); 101 } 102 } 103 104 } -
trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.h
r372 r387 26 26 bool Export(const string filename); 27 27 28 int CollectObjects(ObjectContainer *instances); 29 28 int 29 CollectObjects(ObjectContainer *instances); 30 30 31 int 31 32 AssignObjectIds(); 33 34 void 35 GetStatistics(int &intersectables, int &faces) const; 32 36 33 37 protected: -
trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
r386 r387 76 76 77 77 if (mKdTree->CastRay(ray)) { 78 78 79 objectB = ray.intersections[0].mObject; 79 80 pointB = ray.Extrap(ray.intersections[0].mT); 81 80 82 } else { 81 83 objectB = NULL; … … 92 94 VssRay *vssRay = NULL; 93 95 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) { 104 vssRay = new VssRay(pointA, 105 pointB, 106 objectA, 107 objectB); 108 mVssRays.push_back(vssRay); 109 hits ++; 110 96 bool validSample = true; 97 if (detectEmptyViewSpace) { 98 if (Distance(pointA, pointB) < 99 Distance(viewPoint, pointA) + Distance(viewPoint, pointB) - Limits::Small) { 100 validSample = false; 101 } 102 } 103 104 if (validSample) { 105 if (objectA) { 106 vssRay = new VssRay(pointB, 107 pointA, 108 objectB, 109 objectA); 110 mVssRays.push_back(vssRay); 111 hits ++; 112 } 113 114 if (objectB) { 115 vssRay = new VssRay(pointA, 116 pointB, 117 objectA, 118 objectB); 119 mVssRays.push_back(vssRay); 120 hits ++; 121 } 111 122 } 112 123 … … 122 133 if (viewSpaceBox) 123 134 box =*viewSpaceBox; 124 else 135 else 125 136 box = mKdTree->GetBox(); 126 137 … … 146 157 147 158 mSceneGraph->CollectObjects(&mObjects); 148 cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<mObjects.size()<<endl;149 159 150 160 long startTime = GetTime(); … … 155 165 156 166 AxisAlignedBox3 box = mKdTree->GetBox(); 157 box.Enlarge(box.Size()*-Vector3(0.45, 0.45, 0.45)); 158 159 bool useViewSpaceBox = false; 167 168 169 if (1) 170 box.Enlarge(box.Size()*-Vector3(0.45, 0.45, 0.45)); 171 else { 172 // sample city like heights 173 box.SetMin(1, box.Min(1) + box.Size(1)*0.1); 174 box.SetMax(1, box.Min(1) + box.Size(1)*0.2); 175 } 176 177 bool useViewSpaceBox = true; 160 178 if (useViewSpaceBox) 161 179 viewSpaceBox = &box; … … 243 261 vssTree->Construct(mVssRays, viewSpaceBox); 244 262 263 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 245 264 246 265 -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
r386 r387 272 272 ri++) 273 273 if ((*ri).mRay->IsActive()) { 274 Intersectable *object = (*ri).mRay->mOriginObject; 274 Intersectable *object; 275 #if BIDIRECTIONAL_RAY 276 object = (*ri).mRay->mOriginObject; 275 277 if (object && !object->Mailed()) { 276 278 pvsSize++; 277 279 object->Mail(); 278 280 } 281 #endif 279 282 object = (*ri).mRay->mTerminationObject; 280 283 if (object && !object->Mailed()) { … … 365 368 366 369 if (splitType == ESplitRegular) { 367 int sRaysBack, sRaysFront; 368 int dRaysBack, dRaysFront; 369 int sPvsBack, sPvsFront; 370 int dPvsBack, dPvsFront; 371 372 373 int sAxis = box.Size().DrivingAxis(); 374 float sPosition = (box.Min()[sAxis] + box.Max()[sAxis])*0.5f; 375 float sCostRatio = EvalCostRatio(leaf, 376 sAxis, 377 sPosition, 378 sRaysBack, 379 sRaysFront, 380 sPvsBack, 381 sPvsFront 370 costRatio = BestCostRatioRegular(leaf, 371 axis, 372 position, 373 raysBack, 374 raysFront, 375 pvsBack, 376 pvsFront 382 377 ); 383 // cout<<"srays back="<<sRaysBack<<" rays front="<<sRaysFront<<" pvs back="<<sPvsBack<< 384 // " pvs front="<<sPvsFront<<endl; 385 386 AxisAlignedBox3 dirBox = GetDirBBox(leaf); 387 int dAxis = dirBox.Size().DrivingAxis(); 388 float dPosition = (dirBox.Min()[dAxis] + dirBox.Max()[dAxis])*0.5f; 389 float dCostRatio = EvalCostRatio(leaf, 390 dAxis+3, 391 dPosition, 392 dRaysBack, 393 dRaysFront, 394 dPvsBack, 395 dPvsFront 396 ); 397 398 // cout<<"drays back="<<dRaysBack<<" rays front="<<dRaysFront<<" pvs back="<<dPvsBack<< 399 // " pvs front="<<dPvsFront<<endl; 400 401 if (sCostRatio < dCostRatio) { 402 costRatio = sCostRatio; 403 axis = sAxis; 404 position = sPosition; 405 raysBack = sRaysBack; 406 raysFront = sRaysFront; 407 pvsBack = sPvsBack; 408 pvsFront = sPvsFront; 409 410 } else { 411 costRatio = dCostRatio; 412 axis = dAxis+3; 413 position = dPosition; 414 raysBack = dRaysBack; 415 raysFront = dRaysFront; 416 pvsBack = dPvsBack; 417 pvsFront = dPvsFront; 418 } 419 378 420 379 } else { 421 380 if (splitType == ESplitHeuristic) … … 487 446 // determine the side of this ray with respect to the plane 488 447 int side = (*ri).ComputeRayIntersection(axis, position, (*ri).mRay->mT); 489 490 448 // (*ri).mRay->mSide = side; 491 449 … … 496 454 raysFront++; 497 455 498 #if BIDIRECTIONAL_RAY499 AddObject2Pvs((*ri).mRay->mOriginObject, side, pvsBack, pvsFront);500 #endif501 456 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 502 503 457 } 504 458 … … 536 490 537 491 // (*ri).mRay->mSide = side; 538 539 #if BIDIRECTIONAL_RAY540 AddObject2Pvs((*ri).mRay->mOriginObject, side, pvsBack, pvsFront);541 #endif542 492 AddObject2Pvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 543 493 … … 551 501 552 502 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 553 float sum = pvsBack*(position - minBox) + pvsFront*(maxBox - position); 503 float sum = 504 pvsBack*(position - minBox) + 505 pvsFront*(maxBox - position); 554 506 // float sum = pvsBack + pvsFront; 555 507 newCost = ct_div_ci + sum/sizeBox; … … 566 518 float 567 519 VssTree::BestCostRatioRegular( 568 VssTreeLeaf * node,520 VssTreeLeaf *leaf, 569 521 int &axis, 570 522 float &position, … … 573 525 int &pvsBack, 574 526 int &pvsFront 575 576 527 ) 577 528 { 578 579 return 0; 529 int nRaysBack[6], nRaysFront[6]; 530 int nPvsBack[6], nPvsFront[6]; 531 float nPosition[6]; 532 float nCostRatio[6]; 533 int bestAxis = -1; 534 535 AxisAlignedBox3 sBox = GetBBox(leaf); 536 AxisAlignedBox3 dBox = GetDirBBox(leaf); 537 // int sAxis = box.Size().DrivingAxis(); 538 int sAxis = sBox.Size().DrivingAxis(); 539 int dAxis = dBox.Size().DrivingAxis() + 3; 540 541 bool onlyDrivingAxis = true; 542 543 for (axis = 0; axis < 6; axis++) { 544 if (!onlyDrivingAxis || axis == sAxis || axis == dAxis) { 545 if (axis < 3) 546 nPosition[axis] = (sBox.Min()[axis] + sBox.Max()[axis])*0.5f; 547 else 548 nPosition[axis] = (dBox.Min()[axis-3] + dBox.Max()[axis-3])*0.5f; 549 550 nCostRatio[axis] = EvalCostRatio(leaf, 551 axis, 552 nPosition[axis], 553 nRaysBack[axis], 554 nRaysFront[axis], 555 nPvsBack[axis], 556 nPvsFront[axis] 557 ); 558 559 if ( bestAxis == -1) 560 bestAxis = axis; 561 else 562 if ( nCostRatio[axis] < nCostRatio[bestAxis] ) 563 bestAxis = axis; 564 } 565 } 566 567 axis = bestAxis; 568 position = nPosition[bestAxis]; 569 570 raysBack = nRaysBack[bestAxis]; 571 raysFront = nRaysFront[bestAxis]; 572 573 pvsBack = nPvsBack[bestAxis]; 574 pvsFront = nPvsFront[bestAxis]; 575 576 return nCostRatio[bestAxis]; 580 577 } 581 578 582 579 float 583 580 VssTree::BestCostRatioHeuristic( 584 VssTreeLeaf * node,581 VssTreeLeaf *leaf, 585 582 int &axis, 586 583 float &position, … … 591 588 ) 592 589 { 593 AxisAlignedBox3 box = GetBBox( node);594 AxisAlignedBox3 dirBox = GetDirBBox(node);595 590 AxisAlignedBox3 box = GetBBox(leaf); 591 // AxisAlignedBox3 dirBox = GetDirBBox(node); 592 596 593 axis = box.Size().DrivingAxis(); 597 598 SortSplitCandidates(node, axis); 599 600 // go through the lists, count the number of objects left and right 601 // and evaluate the following cost funcion: 602 // C = ct_div_ci + (ql*rl + qr*rr)/queries 603 604 int rl=0, rr=node->rays.size(); 605 606 float minBox = box.Min(axis); 607 float maxBox = box.Max(axis); 608 float sizeBox = maxBox - minBox; 609 610 float minBand = minBox + 0.1*(maxBox - minBox); 611 float maxBand = minBox + 0.9*(maxBox - minBox); 612 613 float sum = rr*sizeBox; 614 float minSum = 1e20; 615 616 for(vector<SortableEntry>::const_iterator ci = splitCandidates->begin(); 617 ci < splitCandidates->end(); 618 ci++) { 619 620 switch ((*ci).type) { 621 case SortableEntry::ERayMin: 622 rl++; 623 break; 624 case SortableEntry::ERayMax: 625 rr--; 626 break; 627 } 628 629 if ((*ci).value > minBand && (*ci).value < maxBand) { 630 631 sum = rl*((*ci).value - minBox) + rr*(maxBox - (*ci).value); 632 633 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 634 // cout<<"cost= "<<sum<<endl; 635 636 if (sum < minSum) { 594 595 SortSplitCandidates(leaf, axis); 596 597 // go through the lists, count the number of objects left and right 598 // and evaluate the following cost funcion: 599 // C = ct_div_ci + (ql*rl + qr*rr)/queries 600 601 int rl=0, rr = leaf->rays.size(); 602 int pl=0, pr = leaf->mPvsSize; 603 float minBox = box.Min(axis); 604 float maxBox = box.Max(axis); 605 float sizeBox = maxBox - minBox; 606 607 float minBand = minBox + 0.1*(maxBox - minBox); 608 float maxBand = minBox + 0.9*(maxBox - minBox); 609 610 float sum = rr*sizeBox; 611 float minSum = 1e20; 612 613 Intersectable::NewMail(); 614 // set all object as belonging to the fron pvs 615 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 616 ri != leaf->rays.end(); 617 ri++) 618 if ((*ri).mRay->IsActive()) { 619 Intersectable *object = (*ri).mRay->mTerminationObject; 620 if (object) 621 if (!object->Mailed()) { 622 object->Mail(); 623 object->mCounter = 1; 624 } else 625 object->mCounter++; 626 } 627 628 Intersectable::NewMail(); 629 630 for(vector<SortableEntry>::const_iterator ci = splitCandidates->begin(); 631 ci < splitCandidates->end(); 632 ci++) { 633 VssRay *ray; 634 switch ((*ci).type) { 635 case SortableEntry::ERayMin: { 636 rl++; 637 ray = (VssRay *) (*ci).data; 638 Intersectable *object = ray->mTerminationObject; 639 if (object && !object->Mailed()) { 640 object->Mail(); 641 pl++; 642 } 643 break; 644 } 645 case SortableEntry::ERayMax: { 646 rr--; 647 ray = (VssRay *) (*ci).data; 648 Intersectable *object = ray->mTerminationObject; 649 if (object) { 650 if (--object->mCounter == 0) 651 pr--; 652 } 653 break; 654 } 655 } 656 if ((*ci).value > minBand && (*ci).value < maxBand) { 657 658 sum = pl*((*ci).value - minBox) + pr*(maxBox - (*ci).value); 659 660 // cout<<"pos="<<(*ci).value<<"\t q=("<<ql<<","<<qr<<")\t r=("<<rl<<","<<rr<<")"<<endl; 661 // cout<<"cost= "<<sum<<endl; 662 663 if (sum < minSum) { 637 664 minSum = sum; 638 665 position = (*ci).value; … … 641 668 raysFront = rr; 642 669 670 pvsBack = pl; 671 pvsFront = pr; 672 643 673 } 644 674 } 645 675 } 646 676 647 float oldCost = node->rays.size();677 float oldCost = leaf->mPvsSize; 648 678 float newCost = ct_div_ci + minSum/sizeBox; 649 679 float ratio = newCost/oldCost; … … 652 682 // cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox) 653 683 // <<"\t q=("<<queriesBack<<","<<queriesFront<<")\t r=("<<raysBack<<","<<raysFront<<")"<<endl; 654 655 684 return ratio; 656 685 } … … 1290 1319 return totalRayCount - rayCount; 1291 1320 } 1321 1322 1323 int 1324 VssTree::GetPvsSize(VssTreeNode *node, const AxisAlignedBox3 &box) const 1325 { 1326 stack<VssTreeNode *> tstack; 1327 tstack.push(root); 1328 1329 Intersectable::NewMail(); 1330 int pvsSize = 0; 1331 1332 while (!tstack.empty()) { 1333 VssTreeNode *node = tstack.top(); 1334 tstack.pop(); 1335 1336 1337 if (node->IsLeaf()) { 1338 VssTreeLeaf *leaf = (VssTreeLeaf *)node; 1339 for(VssTreeNode::RayInfoContainer::iterator ri = leaf->rays.begin(); 1340 ri != leaf->rays.end(); 1341 ri++) 1342 if ((*ri).mRay->IsActive()) { 1343 Intersectable *object; 1344 #if BIDIRECTIONAL_RAY 1345 object = (*ri).mRay->mOriginObject; 1346 if (object && !object->Mailed()) { 1347 pvsSize++; 1348 object->Mail(); 1349 } 1350 #endif 1351 object = (*ri).mRay->mTerminationObject; 1352 if (object && !object->Mailed()) { 1353 pvsSize++; 1354 object->Mail(); 1355 } 1356 } 1357 } else { 1358 VssTreeInterior *in = (VssTreeInterior *)node; 1359 if (in->axis < 3) { 1360 if (box.Max(in->axis) >= in->position ) 1361 tstack.push(in->front); 1362 1363 if (box.Min(in->axis) <= in->position ) 1364 tstack.push(in->back); 1365 } else { 1366 // both nodes for directional splits 1367 tstack.push(in->front); 1368 tstack.push(in->back); 1369 } 1370 } 1371 } 1372 return pvsSize; 1373 } -
trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.h
r386 r387 469 469 leafb->rays.size()*b.bbox.GetVolume(); 470 470 #endif 471 #if 0471 #if 1 472 472 return 473 leafa->mPvsSize*a.bbox.GetVolume() *473 leafa->mPvsSize*a.bbox.GetVolume() 474 474 < 475 475 leafb->mPvsSize*b.bbox.GetVolume(); … … 481 481 leafb->mPvsSize; 482 482 #endif 483 #if 1483 #if 0 484 484 return 485 485 leafa->mPvsSize/(leafa->rays.size()+1) … … 487 487 leafb->mPvsSize/(leafb->rays.size()+1); 488 488 #endif 489 #if o489 #if 0 490 490 return 491 491 leafa->mPvsSize*leafa->rays.size() … … 754 754 EvalLeafPvs(VssTreeLeaf *leaf); 755 755 756 int 757 GetRootPvsSize() const { 758 return GetPvsSize(root, bbox); 759 } 760 761 int 762 GetPvsSize(VssTreeNode *node, const AxisAlignedBox3 &box) const; 756 763 757 764 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r386 r387 9 9 # filename vienna.x3d 10 10 # filename ../data/vienna/vienna-simple.x3d 11 # filename ../data/vienna/vienna-buildings.x3d 11 #filename ../data/vienna/vienna-buildings.x3d 12 #filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d 13 #;../data/vienna/vienna-plane.x3d 12 14 # filename ../data/vienna/viewcells-25-sel.x3d 13 filename ../data/atlanta/atlanta2.x3d15 # filename ../data/atlanta/atlanta2.x3d 14 16 # filename ../data/soda/soda.dat 15 #filename ../data/soda/soda5.dat17 filename ../data/soda/soda5.dat 16 18 } 17 19 … … 22 24 23 25 VssPreprocessor { 24 totalSamples 100000 026 totalSamples 100000 25 27 samplesPerPass 50000 26 28 } -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r386 r387 52 52 53 53 p->LoadScene(filename); 54 54 55 55 p->BuildKdTree(); 56 56 p->KdTreeStatistics(cout);
Note: See TracChangeset
for help on using the changeset viewer.