Changeset 1287 for GTP/trunk/Lib/Vis
- Timestamp:
- 08/27/06 23:39:50 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1286 r1287 25 25 26 26 static float debugVol = 0; 27 int BvhNode::sMailId = 0;27 int BvhNode::sMailId = 2147483647; 28 28 BvHierarchy *BvHierarchy::BvhSubdivisionCandidate::sBvHierarchy = NULL; 29 29 … … 44 44 45 45 BvhNode::BvhNode(const AxisAlignedBox3 &bbox): 46 m BoundingBox(bbox)46 mParent(NULL), mBoundingBox(bbox) 47 47 { 48 48 } … … 91 91 92 92 93 BvhLeaf::BvhLeaf(const AxisAlignedBox3 &bbox, BvhInterior *parent, const int numObjects): 93 BvhLeaf::BvhLeaf(const AxisAlignedBox3 &bbox, 94 BvhInterior *parent, 95 const int numObjects): 94 96 BvhNode(bbox, parent) 95 97 { … … 115 117 116 118 BvhInterior::BvhInterior(const AxisAlignedBox3 &bbox): 117 BvhNode(bbox) 119 BvhNode(bbox), mFront(NULL), mBack(NULL) 118 120 { 119 121 } … … 121 123 122 124 BvhInterior::BvhInterior(const AxisAlignedBox3 &bbox, BvhInterior *parent): 123 BvhNode(bbox, parent) 125 BvhNode(bbox, parent), mFront(NULL), mBack(NULL) 124 126 { 125 127 } … … 197 199 Environment::GetSingleton()->GetIntValue("OspTree.Termination.maxLeaves", mTermMaxLeaves); 198 200 Environment::GetSingleton()->GetIntValue("OspTree.Termination.minObjects", mTermMinObjects); 199 Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minProbability", mTermMin Volume);201 Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minProbability", mTermMinProbability); 200 202 201 203 Environment::GetSingleton()->GetIntValue("OspTree.Termination.missTolerance", mTermMissTolerance); … … 233 235 234 236 Debug << "max depth: " << mTermMaxDepth << endl; 235 Debug << "min probabiliy: " << mTermMin Volume<< endl;237 Debug << "min probabiliy: " << mTermMinProbability<< endl; 236 238 Debug << "min objects: " << mTermMinObjects << endl; 237 239 Debug << "max cost ratio: " << mTermMaxCostRatio << endl; … … 278 280 BvhInterior *node = new BvhInterior(tData.mBoundingBox, leaf->GetParent()); 279 281 282 cout << "here55 " << tData.mBoundingBox << " | " << node->GetBoundingBox() << endl; 280 283 281 284 //-- the front and back traversal data is filled with the new values 282 285 283 286 frontData.mDepth = backData.mDepth = tData.mDepth + 1; 284 285 // frontData.mRays = new RayInfoContainer(); 286 // backData.mRays = new RayInfoContainer(); 287 288 frontData.mBoundingBox = ComputeBoundingBox(frontObjects); 289 backData.mBoundingBox = ComputeBoundingBox(backObjects); 287 288 frontData.mBoundingBox = ComputeBoundingBox(frontObjects, &(tData.mBoundingBox)); 289 backData.mBoundingBox = ComputeBoundingBox(backObjects, &(tData.mBoundingBox)); 290 290 //RemoveParentViewCellsPvs(leaf, *tData.mRays); 291 292 291 293 292 ///////////// 294 293 //-- create front and back leaf 295 294 296 BvhLeaf *back = new BvhLeaf(backData.mBoundingBox, node, (int)backObjects.size()); 297 BvhLeaf *front = new BvhLeaf(frontData.mBoundingBox, node, (int)frontObjects.size()); 295 BvhLeaf *back = 296 new BvhLeaf(backData.mBoundingBox, node, (int)backObjects.size()); 297 BvhLeaf *front = 298 new BvhLeaf(frontData.mBoundingBox, node, (int)frontObjects.size()); 298 299 299 300 BvhInterior *parent = leaf->GetParent(); … … 333 334 AssociateObjectsWithLeaf(front); 334 335 335 336 336 // compute probability, i.e., volume of seen view cells 337 frontData.m Volume = frontData.mBoundingBox.GetVolume();338 backData.m Volume = backData.mBoundingBox.GetVolume();337 frontData.mProbability = EvalViewCellsVolume(frontObjects); 338 backData.mProbability = EvalViewCellsVolume(backObjects); 339 339 340 340 return node; … … 371 371 tBackData.mMaxCostMisses = maxCostMisses; 372 372 373 // decrease the weighted average cost of the subdivisoin 373 374 mTotalCost -= sc->GetRenderCostDecrease(); 374 375 375 376 // subdivision statistics 376 if (1) EvalSubdivisionStats(*sc);377 if (1) PrintSubdivisionStats(*sc); 377 378 378 379 //-- push the new split candidates on the queue 379 380 380 BvhSubdivisionCandidate *frontCandidate = new BvhSubdivisionCandidate(tFrontData); 381 BvhSubdivisionCandidate *backCandidate = new BvhSubdivisionCandidate(tBackData); 381 BvhSubdivisionCandidate *frontCandidate = 382 new BvhSubdivisionCandidate(tFrontData); 383 BvhSubdivisionCandidate *backCandidate = 384 new BvhSubdivisionCandidate(tBackData); 382 385 383 386 EvalSubdivisionCandidate(*frontCandidate); … … 416 419 void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate) 417 420 { 418 ObjectContainer frontObjects, backObjects;419 420 421 // compute best object partition 421 const float ratio = 422 SelectObjectPartition(splitCandidate.mParentData, frontObjects, backObjects); 423 422 const float ratio = SelectObjectPartition( 423 splitCandidate.mParentData, 424 splitCandidate.mFrontObjects, 425 splitCandidate.mBackObjects); 426 424 427 const bool success = ratio < mTermMaxCostRatio; 425 428 426 float oldRenderCost; 429 BvhLeaf *leaf = splitCandidate.mParentData.mNode; 430 431 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 432 433 const float oldRenderCost = 434 splitCandidate.mParentData.mProbability * (float)leaf->mObjects.size() / viewSpaceVol; 427 435 428 436 // compute global decrease in render cost 429 const float renderCostDecr = EvalRenderCostDecrease(frontObjects, 430 backObjects, 431 splitCandidate.mParentData, 432 oldRenderCost); 433 437 float newRenderCost = EvalRenderCost(splitCandidate.mParentData, 438 splitCandidate.mFrontObjects, 439 splitCandidate.mBackObjects); 440 441 newRenderCost /= viewSpaceVol; 442 443 const float renderCostDecr = oldRenderCost - newRenderCost; 444 445 Debug << "!!render cost decr: " << renderCostDecr << endl; 434 446 splitCandidate.SetRenderCostDecrease(renderCostDecr); 435 447 … … 488 500 } 489 501 490 if (data.m Volume <= mTermMinVolume)502 if (data.mProbability <= mTermMinProbability) 491 503 ++ mBvhStats.minProbabilityNodes; 492 504 … … 502 514 503 515 516 float BvHierarchy::EvalLocalObjectPartition(const BvhTraversalData &tData, 517 const int axis, 518 ObjectContainer &objectsFront, 519 ObjectContainer &objectsBack) 520 { 521 const float maxBox = tData.mBoundingBox.Max(axis); 522 const float minBox = tData.mBoundingBox.Min(axis); 523 524 float midPoint = (maxBox + minBox) * 0.5f; 525 526 ObjectContainer::const_iterator oit, oit_end = tData.mNode->mObjects.end(); 527 528 for (oit = tData.mNode->mObjects.begin(); oit != oit_end; ++ oit) 529 { 530 Intersectable *obj = *oit; 531 AxisAlignedBox3 box = obj->GetBox(); 532 const float objMid = (box.Max(axis) + box.Min(axis)) * 0.5; 533 // object mailed => belongs to back objects 534 if (objMid < midPoint) 535 objectsBack.push_back(obj); 536 else 537 objectsFront.push_back(obj); 538 } 539 540 const float oldRenderCost = tData.mProbability * (float)tData.mNode->mObjects.size(); 541 const float newRenderCost = 542 EvalRenderCost(tData, objectsFront, objectsBack); 543 544 const float ratio = newRenderCost / oldRenderCost; 545 return ratio; 546 } 547 548 504 549 float BvHierarchy::EvalLocalCostHeuristics(const BvhTraversalData &tData, 505 550 const int axis, … … 507 552 ObjectContainer &objectsBack) 508 553 { 509 // the relative cost ratio510 float ratio = 99999999.0f;554 // prepare the heuristics by setting mailboxes and counters. 555 const float totalVol = PrepareHeuristics(tData, axis); 511 556 512 557 // go through the lists, count the number of objects left and right 513 // and evaluate the following cost funcion: 514 // C = ct_div_ci + (ol + or)/queries 515 516 const float minBox = tData.mBoundingBox.Min(axis); 517 const float maxBox = tData.mBoundingBox.Max(axis); 518 519 const float sizeBox = maxBox - minBox; 520 521 float minBand = minBox + mSplitBorder * (maxBox - minBox); 522 float maxBand = minBox + (1.0f - mSplitBorder) * (maxBox - minBox); 523 524 //-- sort so we can use a sweep 525 SortSubdivisionCandidates(tData, axis, minBand, maxBand); 526 527 float totalVol = PrepareHeuristics(tData); 528 float voll = 0; 529 float volr = totalVol; 530 531 /// this is kind of a reverse pvs 532 const int totalObjects = (int)tData.mNode->mObjects.size(); 533 534 int objectsl = 0; 535 int objectsr = totalObjects; 536 537 float sum = (float)totalVol * objectsr; 538 539 540 bool splitPlaneFound = false; 558 // and evaluate the cost funcion 559 560 // local helper variables 561 float volLeft = 0; 562 float volRight = totalVol; 563 564 int nObjectsLeft = 0; 565 566 const int nTotalObjects = (int)tData.mNode->mObjects.size(); 567 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 568 569 vector<SortableEntry>::const_iterator currentPos = 570 mSubdivisionCandidates->begin(); 541 571 542 572 ///////////////////////////////// 543 573 // the parameters for the current optimum 544 574 545 float volBack = voll; 546 float volFront = volr; 547 548 int nObjectsBack = objectsl; 549 int nObjectsFront = objectsr; 550 551 float minSum = 1e20f; 552 553 ///////////////////////////// 554 555 debugVol = 0; 556 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 575 float volBack = volLeft; 576 float volFront = volRight; 577 578 float newRenderCost = nTotalObjects * totalVol; 579 557 580 558 581 ///////////////////////////// 559 582 // the sweep heuristics 560 561 // mail the objects on the left side562 Intersectable::NewMail();563 583 564 584 //-- traverse through events and find best split plane 565 vector<SortableEntry>::const_iterator ci, ci_end = mSubdivisionCandidates->end(); 566 567 for (ci = mSubdivisionCandidates->begin(); ci != ci_end; ++ ci) 568 { 569 Intersectable *object = (*ci).mObject; 570 571 EvalHeuristicsContribution(tData.mNode, *ci, voll, volr, objectsl); 572 objectsr = totalObjects - objectsl; 573 574 // Note: sufficient to compare size of bounding boxes of front and back side? 575 576 if (((*ci).mPos >= minBand) && ((*ci).mPos <= maxBand)) 585 586 vector<SortableEntry>::const_iterator cit, cit_end = mSubdivisionCandidates->end(); 587 588 for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit) 589 { 590 Intersectable *object = (*cit).mObject; 591 592 // evaluate change in l and r volume 593 // voll = view cells that see only left node (i.e., left pvs) 594 // volr = view cells that see only right node (i.e., right pvs) 595 EvalHeuristicsContribution(object, volLeft, volRight); 596 597 ++ nObjectsLeft; 598 599 const int nObjectsRight = nTotalObjects - nObjectsLeft; 600 601 // view cells that see both child nodes 602 //const float volLeftAndRight = totalVol - volLeft - volRight; 603 604 // the heuristics 605 const float sum = volLeft * (float)nObjectsLeft + 606 volRight * (float)nObjectsRight; 607 // volLeftAndRight * (float)nTotalObjects; 608 609 if (sum < newRenderCost) 577 610 { 578 // voll = view cells that see only left node (i.e., left pvs) 579 // volr = view cells that see only right node (i.e., right pvs) 580 // rest = view cells that see both nodes (i.e., total pvs) 581 sum = voll * objectsl + volr * objectsr + (totalVol - voll - volr) * totalObjects; 582 583 float currentPos; 584 585 // HACK: current positition is BETWEEN visibility events 586 if (1 && ((ci + 1) != ci_end)) 587 currentPos = ((*ci).mPos + (*(ci + 1)).mPos) * 0.5f; 588 else 589 currentPos = (*ci).mPos; 590 591 if ((totalVol - voll - volr - debugVol) / viewSpaceVol > 0.0001) 592 Debug << "front and back volume: " << (totalVol - voll - volr) / viewSpaceVol << " error: " << (totalVol - voll - volr - debugVol) / viewSpaceVol << endl; 593 #if 0 594 Debug << "pos: " << currentPos 595 << "\t (pvsl: " << pvsl << ", pvsr: " << pvsr << ")" 596 << "\t (voll: " << voll << ", volr: " << volr << ")" 597 << "\t (vcl: " << vcl << ", vcr: " << vcr << ", nvc: " << numViewCells << ")" 598 << "\t sum: " << sum << endl; 599 600 #endif 601 if (sum < minSum) 602 { 603 splitPlaneFound = true; 604 605 minSum = sum; 606 607 nObjectsBack = objectsl; 608 nObjectsFront = objectsr; 609 610 volBack = voll; 611 volFront = volr; 612 } 611 newRenderCost = sum; 612 613 volBack = volLeft; 614 volFront = volRight; 615 616 // objects belongs to left side now 617 for (; currentPos != (cit + 1); ++ currentPos); 613 618 } 614 619 } 615 616 //-- compute cost 617 const float frontAndBackVol = totalVol - volFront - volBack; 618 619 const float oldRenderCost = (float)totalObjects * totalVol + Limits::Small; 620 const float newRenderCost = (float)nObjectsFront * volFront + 621 (float)nObjectsBack * volBack + 622 (float)totalObjects * frontAndBackVol; 623 624 if (splitPlaneFound) 625 { 626 ratio = newRenderCost / oldRenderCost; 627 } 628 629 //Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" 630 // << position << " t=" << (position - minBox) / (maxBox - minBox) 631 // << "\t pb=(" << volBack << ")\t pf=(" << volFront << ")" << endl; 620 621 //-- assign object to front and back volume 622 623 // belongs to back bv 624 for (cit = mSubdivisionCandidates->begin(); cit != currentPos; ++ cit) 625 objectsBack.push_back((*cit).mObject); 626 627 // belongs to front bv 628 for (cit = currentPos; cit != cit_end; ++ cit) 629 objectsFront.push_back((*cit).mObject); 630 631 tData.mNode->mObjects.end(); 632 633 const float oldRenderCost = (float)nTotalObjects * totalVol + Limits::Small; 634 // the relative cost ratio 635 const float ratio = newRenderCost / oldRenderCost; 632 636 633 637 Debug << "\n§§§§ eval local cost §§§§" << endl 634 << "back pvs: " << nObjectsBack << " front pvs: " << nObjectsFront << " total pvs: " << totalObjects << endl638 << "back pvs: " << (int)objectsBack.size() << " front pvs: " << objectsFront.size() << " total pvs: " << nTotalObjects << endl 635 639 << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl 636 640 << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl 637 641 << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl; 638 642 639 if (oldRenderCost < newRenderCost)640 Debug << "\nwarning!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl;641 642 // assign objects643 ObjectContainer::const_iterator oit, oit_end = tData.mNode->mObjects.end();644 645 for (oit = tData.mNode->mObjects.begin(); oit != oit_end; ++ oit)646 {647 Intersectable *obj = *oit;648 649 if (obj->Mailed()) // belongs to back objects650 objectsBack.push_back(obj);651 else652 objectsFront.push_back(obj);653 }654 655 643 return ratio; 656 644 } … … 658 646 659 647 void BvHierarchy::SortSubdivisionCandidates(const BvhTraversalData &tData, 660 const int axis, 661 float minBand, 662 float maxBand) 663 648 const int axis) 664 649 { 665 650 mSubdivisionCandidates->clear(); … … 669 654 670 655 // compute requested size 671 int requestedSize = 0; 672 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 673 for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit) 674 requestedSize += 2 + (int)(*oit)->mVssRays.size() * 2; 656 const int requestedSize = (int)leaf->mObjects.size() * 2; 675 657 676 658 // creates a sorted split candidates array … … 683 665 684 666 mSubdivisionCandidates->reserve(requestedSize); 685 686 float pos;687 667 688 668 //-- insert object queries … … 691 671 //-- there is no ray associated with these events!! 692 672 673 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end(); 674 693 675 for (oit = leaf->mObjects.begin(); oit < oit_end; ++ oit) 694 676 { … … 696 678 697 679 Intersectable *object = *oit; 698 const AxisAlignedBox3 box = object->GetBox(); 699 700 mSubdivisionCandidates->push_back( 701 SortableEntry(SortableEntry::OBJECT, 702 box.Min(axis), 703 object, 704 NULL) 705 ); 706 707 708 //-- insert ray queries 709 //-- we are intersested only in rays which intersect an object that 710 //-- is part of the kd node because they can induce a change in view cell 711 //-- volume on the left and the right part. 712 //-- Note that they cannot induce a change in pvs size!! 713 714 VssRayContainer::const_iterator rit, rit_end = obj->mVssRays.end(); 715 716 for (rit = obj->mVssRays.begin(); rit < rit_end; ++ rit) 717 { 718 VssRay *ray = (*rit); 719 const bool positive = ray->HasPosDir(axis); 720 721 pos = ray->mTermination[axis]; 722 723 mSubdivisionCandidates->push_back( 724 SortableEntry(SortableEntry::VIEWCELLS, 725 pos, 726 ray->mTerminationObject, 727 ray) 728 ); 729 } 680 const AxisAlignedBox3 &box = object->GetBox(); 681 const float midPt = (box.Min(axis) + box.Max(axis)) * 0.5f; 682 683 mSubdivisionCandidates->push_back(SortableEntry(object, midPt)); 730 684 } 731 685 … … 740 694 741 695 742 void BvHierarchy::EvalRayContribution(const VssRay &ray, 743 float &volLeft, 744 float &volRight) 745 { 696 float BvHierarchy::PrepareHeuristics(const BvhTraversalData &tData, const int axis) 697 { 698 //-- sort so we can use a sweep from right to left 699 SortSubdivisionCandidates(tData, axis); 700 701 float vol = 0; 702 BvhLeaf *leaf = tData.mNode; 703 704 // collect and mark the view cells as belonging to front pvs 746 705 ViewCellContainer viewCells; 747 mVspTree->GetViewCells(ray, viewCells); 706 CollectViewCells(tData.mNode->mObjects, viewCells, true); 707 708 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 709 710 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 711 { 712 vol += (*vit)->GetVolume(); 713 } 714 715 // mail view cells on the left side 716 ViewCell::NewMail(); 717 718 // mail the objects on the left side 719 Intersectable::NewMail(); 720 721 return vol; 722 } 723 /////////////////////////////////////////////////////////// 724 725 726 void BvHierarchy::EvalHeuristicsContribution(Intersectable *obj, 727 float &volLeft, 728 float &volRight) 729 { 730 // collect all view cells associated with this objects 731 // (also multiple times, if they are pierced by several rays) 732 733 ViewCellContainer viewCells; 734 735 const bool useMailboxing = false; 736 CollectViewCells(obj, viewCells, useMailboxing); 737 748 738 749 739 /// classify view cells and compute volume contri accordingly … … 766 756 767 757 // we now see view cell from both nodes 768 // => remove ref to right childnode769 vol Right -= vol;770 debugVol += vol;758 // => add volume to left node 759 volLeft += vol; 760 //volRight -= vol; 771 761 } 772 762 … … 775 765 { 776 766 // view cell was previously seen from both nodes => 777 // contributes only to left node now 778 volLeft += vol; 779 debugVol -= vol; 767 // remove volume from right node 768 volRight -= vol; 780 769 } 781 770 } 782 }783 784 785 float BvHierarchy::PrepareHeuristics(const VssRay &ray)786 {787 float vol = 0;788 789 ViewCellContainer viewCells;790 mVspTree->GetViewCells(ray, viewCells);791 792 ViewCellContainer::const_iterator vit, vit_end = viewCells.end();793 794 for (vit = viewCells.begin(); vit != vit_end; ++ vit)795 {796 ViewCell *vc = (*vit);797 798 if (!vc->Mailed())799 {800 //Debug << "single vol: "<< vc->GetVolume() << endl;801 vc->Mail();802 vc->mCounter = 0;803 vol += vc->GetVolume();804 }805 806 // view cell volume already added => just increase counter807 ++ vc->mCounter;808 }809 810 return vol;811 }812 813 814 float BvHierarchy::PrepareHeuristics(const BvhTraversalData &tData)815 {816 float vol = 0;817 debugVol = 0;818 819 ViewCell::NewMail();820 821 BvhLeaf *leaf = tData.mNode;822 823 VssRayContainer rays;824 CollectRays(leaf->mObjects, rays);825 826 VssRayContainer::const_iterator rit, rit_end = rays.end();827 828 for (rit = rays.begin(); rit < rit_end; ++ rit)829 {830 VssRay *ray = (*rit);831 832 const float volContri = PrepareHeuristics(*ray);833 834 // if hitpoint with one of the objects is inside this node, we835 // evaluate the volume of the view cells seen by this ray836 if (ray->mTerminationObject)837 {838 vol += volContri;839 }840 841 // count double if both hit points are within the kd node842 if (0 && ray->mOriginObject)843 {844 vol += volContri;845 }846 }847 848 return vol;849 }850 ///////////////////////////////////////////////////////////851 852 853 void BvHierarchy::EvalHeuristicsContribution(BvhLeaf *leaf,854 const SortableEntry &ci,855 float &volLeft,856 float &volRight,857 int &objectsLeft)858 {859 Intersectable *obj = ci.mObject;860 VssRay *ray = ci.mRay;861 862 // switch between different types of events863 switch (ci.mType)864 {865 case SortableEntry::OBJECT:866 cout << "o";867 ci.mObject->Mail();868 ++ objectsLeft;869 break;870 871 // compute volume contribution from view cells872 case SortableEntry::VIEWCELLS:873 cout << "v";874 // process ray if the hit point with termination / origin object875 // is inside this kd leaf876 EvalRayContribution(*ray, volLeft, volRight);877 break;878 879 default:880 cout << "should not come here" << endl;881 break;882 }883 //cout << "vol left: " << volLeft << " vol right " << volRight << endl;884 771 } 885 772 … … 923 810 if (!mOnlyDrivingAxis || (axis == sAxis)) 924 811 { 925 if ( 1 ||mUseCostHeuristics)812 if (mUseCostHeuristics) 926 813 { 927 814 //-- partition objects using heuristics 928 929 815 nCostRatio[axis] = 930 816 EvalLocalCostHeuristics( … … 932 818 axis, 933 819 nFrontObjects[axis], 934 nBackObjects[axis]); 820 nBackObjects[axis]); 935 821 } 822 else 823 { 824 nCostRatio[axis] = 825 EvalLocalObjectPartition( 826 tData, 827 axis, 828 nFrontObjects[axis], 829 nBackObjects[axis]); 830 } 831 936 832 if (bestAxis == -1) 937 833 { … … 946 842 947 843 //-- assign values 948 844 949 845 frontObjects = nFrontObjects[bestAxis]; 950 backObjects = n FrontObjects[bestAxis];846 backObjects = nBackObjects[bestAxis]; 951 847 952 848 Debug << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; … … 977 873 978 874 979 void BvHierarchy::EvalSubdivisionStats(const SubdivisionCandidate &sc) 980 { 981 const float costDecr = sc.GetRenderCostDecrease(); 982 983 AddSubdivisionStats(mBvhStats.Leaves(), 984 costDecr, 985 mTotalCost 986 ); 987 } 988 989 990 void BvHierarchy::AddSubdivisionStats(const int leaves, 991 const float renderCostDecr, 992 const float totalRenderCost) 993 { 875 void BvHierarchy::PrintSubdivisionStats(const SubdivisionCandidate &sc) 876 { 877 const float costDecr = sc.GetRenderCostDecrease(); 878 994 879 mSubdivisionStats 995 << "#Leaves\n" << leaves << endl996 << "#RenderCostDecrease\n" << renderCostDecr << endl997 << "#TotalRenderCost\n" << totalRenderCost << endl;880 << "#Leaves\n" << mBvhStats.Leaves() 881 << "#RenderCostDecrease\n" << costDecr << endl 882 << "#TotalRenderCost\n" << mTotalCost << endl; 998 883 //<< "#AvgRenderCost\n" << avgRenderCost << endl; 999 884 } … … 1029 914 1030 915 1031 void BvHierarchy::MailViewCells(const ObjectContainer &objects, 1032 const bool isFront, 1033 ViewCellContainer &collectedViewCells) const 1034 { 1035 VssRayContainer rays; 1036 CollectRays(objects, rays); 1037 1038 VssRayContainer::const_iterator rit, rit_end = rays.end(); 1039 1040 for (rit = rays.begin(); rit < rit_end; ++ rit) 1041 { 1042 VssRay *ray = (*rit); 1043 1044 // view cell is assigned to left and / or right child 1045 ViewCellContainer viewCells; 1046 mVspTree->GetViewCells(*ray, viewCells); 1047 1048 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1049 1050 // mail view cell 1051 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 916 void BvHierarchy::ClassifyViewCells(const ViewCellContainer &viewCells, 917 const bool isFront) const 918 { 919 int mailed = 0; 920 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 921 922 // mail view cell 923 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 924 { 925 ViewCell *vc = *vit; 926 927 if (isFront) 1052 928 { 1053 ViewCell *vc = *vit; 1054 1055 if (!vc->Mailed() && !vc->Mailed(1) && !vc->Mailed(2)) 1056 collectedViewCells.push_back(vc); 1057 1058 if (isFront) 929 if (!vc->Mailed()) 1059 930 { 1060 if (!vc->Mailed()) 1061 vc->Mail(); 931 vc->Mail(); 932 //Debug << " " << vc->mMailBox << endl; 933 ++ mailed; 1062 934 } 1063 else 935 } 936 else 937 { 938 if (vc->Mailed()) 1064 939 { 1065 if (!vc->Mailed()) 1066 vc->Mail(1); 1067 else 1068 vc->Mail(2); 940 vc->Mail(2); 941 //Debug << " " << vc->mMailBox << endl; 942 ++ mailed; 1069 943 } 1070 } 1071 } 1072 } 1073 1074 1075 float BvHierarchy::EvalRenderCostDecrease(const ObjectContainer &objectsFront, 944 else if (!vc->Mailed(1) && !vc->Mailed(2)) 945 { 946 vc->Mail(1); 947 //Debug << " " << vc->mMailBox << endl; 948 ++ mailed; 949 } 950 951 } 952 } 953 954 Debug << "mailed " << mailed << " view cells " << endl; 955 } 956 957 958 float BvHierarchy::EvalRenderCost(const BvhTraversalData &tData, 959 const ObjectContainer &objectsFront, 960 const ObjectContainer &objectsBack) const 961 { 962 BvhLeaf *leaf = tData.mNode; 963 964 // probability that view point lies in a view cell which sees this node 965 const float pFront = EvalViewCellsVolume(objectsFront); 966 const float pBack = EvalViewCellsVolume(objectsBack); 967 968 const int totalObjects = (int)leaf->mObjects.size(); 969 const int nObjectsFront = (int)objectsFront.size(); 970 const int nObjectsBack = (int)objectsBack.size(); 971 972 //-- pvs rendering heuristics 973 const float newRenderCost = nObjectsFront * pFront + 974 nObjectsBack * pBack; 975 976 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 977 Debug << "\n***** eval render cost *********\n" 978 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << endl 979 << "new rc: " << newRenderCost / viewSpaceVol << endl; 980 981 982 return newRenderCost; 983 } 984 985 986 /*float BvHierarchy::EvalRenderCostDecrease(const BvhTraversalData &tData, 987 const ObjectContainer &objectsFront, 1076 988 const ObjectContainer &objectsBack, 1077 const BvhTraversalData &tData,1078 989 float &normalizedOldRenderCost) const 1079 990 { 1080 // probability that view point lies in back / front node 991 BvhLeaf *leaf = tData.mNode; 992 993 // probability that view point lies in a view cell which sees this node 1081 994 float pOverall = 0; 1082 995 float pFront = 0; … … 1085 998 1086 999 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 1087 1088 BvhLeaf *leaf = tData.mNode; 1089 1000 1001 ViewCellContainer collectedViewCells; 1002 ViewCellContainer viewCellsFront, viewCellsBack; 1003 1004 // the view cells seen from the front bv 1005 1006 CollectViewCells(objectsFront, viewCellsFront); 1007 // the view cells seen from the back bv 1008 CollectViewCells(objectsBack, viewCellsBack); 1009 // the view cells seen from both bvs 1010 // note: could be evaluated simpler 1011 CollectViewCells(leaf->mObjects, collectedViewCells); 1012 1013 1090 1014 // sum up volume seen from the objects of left and right children 1091 1015 // => the volume is the weight for the render cost equation 1016 1092 1017 ViewCell::NewMail(3); 1093 1094 ViewCellContainer collectedViewCells; 1095 MailViewCells(objectsFront, true, collectedViewCells); 1096 MailViewCells(objectsBack, false, collectedViewCells); 1018 ClassifyViewCells(viewCellsFront, true); 1019 ClassifyViewCells(viewCellsBack, false); 1097 1020 1098 1021 ViewCellContainer::const_iterator vit, vit_end = collectedViewCells.end(); … … 1101 1024 for (vit = collectedViewCells.begin(); vit != vit_end; ++ vit) 1102 1025 { 1103 AddViewCellVolumeContri(*vit, pFront, pBack, pFrontAndBack); 1026 ViewCell *vc = *vit; 1027 if (vc->Mailed()) 1028 pFront += vc->GetVolume(); 1029 else if (vc->Mailed(1)) 1030 pBack += vc->GetVolume(); 1031 else if (vc->Mailed(2)) 1032 pFrontAndBack += vc->GetVolume(); 1104 1033 } 1105 1034 … … 1113 1042 //-- pvs rendering heuristics 1114 1043 const float oldRenderCost = pOverall * totalObjects; 1115 const float newRenderCost = nObjectsFront * pFront + nObjectsBack * pBack + totalObjects * pFrontAndBack; 1044 const float newRenderCost = nObjectsFront * pFront + 1045 nObjectsBack * pBack + 1046 totalObjects * pFrontAndBack; 1116 1047 1117 1048 // normalize volume with view space volume … … 1127 1058 normalizedOldRenderCost = oldRenderCost / viewSpaceVol; 1128 1059 1129 if (oldRenderCost < newRenderCost * 0.99)1130 Debug << "\nwarning2!!:\n" << "old rc: " << oldRenderCost * viewSpaceVol << " new rc: " << newRenderCost * viewSpaceVol << endl;1131 1132 1060 return renderCostDecrease; 1133 } 1134 1135 1136 AxisAlignedBox3 BvHierarchy::ComputeBoundingBox(const ObjectContainer &objects) 1137 { 1061 }*/ 1062 1063 1064 AxisAlignedBox3 BvHierarchy::ComputeBoundingBox(const ObjectContainer &objects, 1065 const AxisAlignedBox3 *parentBox) 1066 { 1067 if (parentBox && objects.empty()) 1068 return *parentBox; 1069 1138 1070 AxisAlignedBox3 box; 1139 1071 box.Initialize(); … … 1147 1079 1148 1080 // compute bounding box of view space 1149 mBoundingBox.Include(obj->GetBox()); 1150 } 1081 box.Include(obj->GetBox()); 1082 } 1083 1151 1084 return box; 1152 1153 1085 } 1154 1086 … … 1163 1095 BvhNode *node = nodeStack.top(); 1164 1096 nodeStack.pop(); 1097 1165 1098 if (node->IsLeaf()) 1166 1099 { … … 1185 1118 1186 1119 1187 void BvHierarchy::CollectViewCells( BvhLeaf *leaf, ViewCellContainer &viewCells)1188 { 1189 ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();1190 1120 void BvHierarchy::CollectViewCells(const ObjectContainer &objects, 1121 ViewCellContainer &viewCells, 1122 const bool setCounter) const 1123 { 1191 1124 ViewCell::NewMail(); 1125 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1192 1126 1193 1127 // loop through all object and collect view cell pvs of this node 1194 for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit) 1195 { 1196 Intersectable *obj = *oit; 1197 1198 ViewCellPvsMap::const_iterator vit, vit_end = obj->mViewCellPvs.mEntries.end(); 1199 1200 for (vit = obj->mViewCellPvs.mEntries.begin(); vit != vit_end; ++ vit) 1201 { 1202 ViewCell *vc = (*vit).first; 1203 1204 if (!vc->Mailed()) 1205 { 1206 vc->Mail(); 1207 viewCells.push_back(vc); 1208 } 1209 } 1210 } 1211 } 1212 1213 1214 void BvHierarchy::CollectDirtyCandidates(BvhSubdivisionCandidate *sc, 1215 vector<SubdivisionCandidate *> &dirtyList) 1216 { 1217 BvhTraversalData &tData = sc->mParentData; 1218 BvhLeaf *node = tData.mNode; 1219 1220 ViewCell::NewMail(); 1221 1222 ViewCellContainer viewCells; 1223 ViewCellContainer tmpViewCells; 1224 1225 VssRayContainer rays; 1226 CollectRays(node->mObjects, rays); 1227 1228 VssRayContainer::const_iterator rit, rit_end = rays.end(); 1229 1230 // find all view cells associated with the rays, add them to view cells 1231 for (rit = rays.begin(); rit != rit_end; ++ rit) 1128 for (oit = objects.begin(); oit != oit_end; ++ oit) 1129 { 1130 CollectViewCells(*oit, viewCells, true, setCounter); 1131 } 1132 } 1133 1134 1135 void BvHierarchy::CollectViewCells(Intersectable *obj, 1136 ViewCellContainer &viewCells, 1137 const bool useMailBoxing, 1138 const bool setCounter) const 1139 { 1140 VssRayContainer::const_iterator rit, rit_end = obj->mVssRays.end(); 1141 1142 for (rit = obj->mVssRays.begin(); rit < rit_end; ++ rit) 1232 1143 { 1233 1144 VssRay *ray = (*rit); 1145 ViewCellContainer tmpViewCells; 1146 1234 1147 mVspTree->GetViewCells(*ray, tmpViewCells); 1235 1148 … … 1240 1153 VspViewCell *vc = dynamic_cast<VspViewCell *>(*vit); 1241 1154 1242 if (!vc->Mailed()) 1155 // store view cells 1156 if (!useMailBoxing || !vc->Mailed()) 1243 1157 { 1244 vc->Mail(); 1158 if (useMailBoxing) 1159 { 1160 vc->Mail(); 1161 if (setCounter) 1162 vc->mCounter = 0; 1163 } 1164 1245 1165 viewCells.push_back(vc); 1246 1166 } 1167 1168 if (setCounter) 1169 { 1170 ++ vc->mCounter; 1171 } 1247 1172 } 1248 1173 } 1249 1250 1251 // split candidates holding this view cells 1252 // are thrown into dirty list 1174 } 1175 1176 1177 void BvHierarchy::CollectDirtyCandidates(BvhSubdivisionCandidate *sc, 1178 vector<SubdivisionCandidate *> &dirtyList) 1179 { 1180 BvhTraversalData &tData = sc->mParentData; 1181 BvhLeaf *node = tData.mNode; 1182 1183 ViewCellContainer viewCells; 1184 CollectViewCells(node->mObjects, viewCells); 1185 1186 // split candidates handling 1187 // these view cells are thrown into dirty list 1253 1188 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1254 1189 … … 1358 1293 1359 1294 1360 void BvHierarchy::AddViewCellVolumeContri(ViewCell *vc,1361 float &frontVol,1362 float &backVol,1363 float &frontAndBackVol) const1364 {1365 if (vc->Mailed())1366 {1367 frontVol += vc->GetVolume();1368 }1369 else if (vc->Mailed(1))1370 {1371 backVol += vc->GetVolume();1372 }1373 else if (vc->Mailed(2))1374 {1375 frontAndBackVol += vc->GetVolume();1376 }1377 }1378 1379 1295 /* 1380 1296 int BvHierarchy::UpdateViewCellsPvs(BvhLeaf *leaf, … … 1469 1385 { 1470 1386 BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node); 1471 1387 const AxisAlignedBox3 box = leaf->GetBoundingBox(); 1472 1388 stream << "<Leaf" 1473 << " min=\"" << leaf->GetBoundingBox().Min()1474 << " max=\"" << leaf->GetBoundingBox().Max()1389 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 1390 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\"" 1475 1391 << " objects=\""; 1476 1392 … … 1483 1399 { 1484 1400 BvhInterior *interior = dynamic_cast<BvhInterior *>(node); 1485 1401 const AxisAlignedBox3 box = interior->GetBoundingBox(); 1402 1486 1403 stream << "<Interior" 1487 << " min=\"" << interior->GetBoundingBox().Min()1488 << " max=\"" << interior->GetBoundingBox().Max()1404 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 1405 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z 1489 1406 << "\">" << endl; 1490 1407 … … 1497 1414 1498 1415 1499 float BvHierarchy::EvalViewCellsVolume( BvhLeaf *leaf) const1416 float BvHierarchy::EvalViewCellsVolume(const ObjectContainer &objects) const 1500 1417 { 1501 1418 float vol = 0; 1502 1419 1503 VssRayContainer rays; 1504 CollectRays(leaf->mObjects, rays); 1505 1506 ViewCell::NewMail(); 1507 1508 VssRayContainer::const_iterator rit, rit_end = rays.end(); 1509 1510 for (rit = rays.begin(); rit < rit_end; ++ rit) 1511 { 1512 VssRay *ray = (*rit); 1513 1514 ViewCellContainer viewCells; 1515 mVspTree->GetViewCells(*ray, viewCells); 1516 1517 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1518 1519 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1520 { 1521 ViewCell *vc = (*vit); 1522 1523 if (!vc->Mailed()) 1524 { 1525 //Debug << "single vol: "<< vc->GetVolume() << endl; 1526 vc->Mail(); 1527 vol += vc->GetVolume(); 1528 } 1529 } 1420 ViewCellContainer viewCells; 1421 CollectViewCells(objects, viewCells); 1422 1423 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 1424 1425 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 1426 { 1427 vol += (*vit)->GetVolume(); 1530 1428 } 1531 1429 … … 1535 1433 1536 1434 SubdivisionCandidate *BvHierarchy::PrepareConstruction(const VssRayContainer &sampleRays, 1537 ObjectContainer &objects, 1538 AxisAlignedBox3 *forcedObjectSpace 1539 //, RayInfoContainer &rays 1435 const ObjectContainer &objects 1436 //,AxisAlignedBox3 *forcedObjectSpace 1540 1437 ) 1541 1438 { 1439 // note matt: we assume that we have objects sorted by their id 1440 1542 1441 // store pointer to this tree 1543 1442 BvhSubdivisionCandidate::sBvHierarchy = this; … … 1545 1444 1546 1445 // compute bounding box from objects 1547 if (forcedObjectSpace) 1548 mBoundingBox = *forcedObjectSpace; 1549 else 1550 mBoundingBox = ComputeBoundingBox(objects); 1551 1552 mTermMinVolume *= mBoundingBox.GetVolume(); 1446 mBoundingBox = ComputeBoundingBox(objects); 1447 1448 mTermMinProbability *= mBoundingBox.GetVolume(); 1553 1449 mGlobalCostMisses = 0; 1554 1555 // sort objects by id in order to have sorted objects in 1556 // the leaf nodes 1557 stable_sort(objects.begin(), objects.end(), ilt); 1558 1450 1559 1451 //-- create new root 1560 1452 … … 1569 1461 1570 1462 //-- add first candidate for object space partition 1463 1464 // probabilty is voume of all "seen" view cells 1465 #if 1 1466 const float prop = EvalViewCellsVolume(bvhleaf->mObjects); 1467 #else 1468 const float prop = GetBoundingBox().GetVolume(); 1469 #endif 1571 1470 1572 1471 // create osp traversal data 1573 BvhTraversalData oData(bvhleaf, 0, mBoundingBox .GetVolume());1472 BvhTraversalData oData(bvhleaf, 0, mBoundingBox, prop); 1574 1473 1575 1474 //-- first split candidate … … 1581 1480 EvalSubdivisionCandidate(*oSubdivisionCandidate); 1582 1481 1583 // probabilty is voume of all "seen" view cells 1584 #if 1 1585 const float prop = EvalViewCellsVolume(bvhleaf); 1586 #else 1587 const float prop = GetBoundingBox().GetVolume(); 1588 #endif 1589 mTotalCost = (float)objects.size() * prop / 1590 mVspTree->GetBoundingBox().GetVolume(); 1591 1592 EvalSubdivisionStats(*oSubdivisionCandidate); 1482 const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume(); 1483 mTotalCost = (float)objects.size() * prop / viewSpaceVol; 1484 1485 PrintSubdivisionStats(*oSubdivisionCandidate); 1593 1486 1594 1487 return oSubdivisionCandidate; -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r1286 r1287 261 261 /// universal counter 262 262 int mCounter; 263 264 263 265 protected: 264 266 … … 289 291 /// current depth 290 292 int mDepth; 291 /// rays piercing this node 292 //RayInfoContainer *mRays; 293 /// the volume of this node 294 float mVolume; 293 /// the probability that this node is seen 294 float mProbability; 295 295 /// the bounding box of the node 296 296 AxisAlignedBox3 mBoundingBox; … … 305 305 BvhTraversalData(): 306 306 mNode(NULL), 307 //mRays(NULL),308 307 mDepth(0), 309 m Volume(0.0),308 mProbability(0.0), 310 309 mMaxCostMisses(0), 311 310 mPriority(0), … … 315 314 BvhTraversalData(BvhLeaf *node, 316 315 const int depth, 317 //RayInfoContainer *rays,316 const AxisAlignedBox3 &box, 318 317 const float v): 319 318 mNode(node), 320 319 mDepth(depth), 321 //mRays(rays),322 m Volume(v),320 mBoundingBox(box), 321 mProbability(v), 323 322 mMaxCostMisses(0), 324 323 mPriority(0), … … 326 325 {} 327 326 328 BvhTraversalData(329 const int depth330 //,RayInfoContainer *rays331 ):332 mNode(NULL),333 mDepth(depth),334 //mRays(rays),335 mVolume(0),336 mMaxCostMisses(0),337 mAxis(0)338 {}339 327 340 328 /** Returns cost of the traversal data. … … 531 519 bool GlobalTerminationCriteriaMet(const BvhTraversalData &data) const; 532 520 533 // -------------------------------------------------------------- 534 // For sorting objects 535 // -------------------------------------------------------------- 521 /** For sorting the objects during the heuristics 522 */ 536 523 struct SortableEntry 537 524 { 538 /** There is a 3th "event" for rays which intersect a 539 box in the middle. These "events" don't induce a change in 540 pvs size, but may induce a change in view cell volume. 541 */ 542 enum EType 543 { 544 OBJECT, 545 VIEWCELLS 546 }; 547 548 int mType; 525 Intersectable *mObject; 549 526 float mPos; 550 527 551 VssRay *mRay;552 Intersectable *mObject;553 554 528 SortableEntry() {} 555 529 556 SortableEntry( 557 const int type, 558 const float pos, 559 Intersectable *obj, 560 VssRay *ray): 561 mType(type), 562 mPos(pos), 563 mObject(obj), 564 mRay(ray) 530 SortableEntry(Intersectable *obj, const float pos): 531 mObject(obj), mPos(pos) 565 532 {} 566 533 … … 571 538 }; 572 539 573 /** faster evaluation of split plane cost for kd axis aligned cells. 574 */ 575 float EvalLocalSplitCost(const BvhTraversalData &data, 576 const AxisAlignedBox3 &box, 577 const int axis, 578 const float &position, 579 float &pFront, 580 float &pBack) const; 540 /** Evaluate balanced object partition. 541 */ 542 float EvalLocalObjectPartition( 543 const BvhTraversalData &tData, 544 const int axis, 545 ObjectContainer &objectsFront, 546 ObjectContainer &objectsBack); 581 547 582 548 /** Computes priority of the traversal data and stores it in tData. … … 584 550 void EvalPriority(BvhTraversalData &tData) const; 585 551 586 /** Evaluates render cost decrease of next split. 587 */ 588 float EvalRenderCostDecrease( 552 /** Evaluates render cost of next split. 553 */ 554 float EvalRenderCost( 555 const BvhTraversalData &tData, 589 556 const ObjectContainer &objectsLeft, 590 const ObjectContainer &objectsRight, 591 const BvhTraversalData &tData, 592 float &normalizedOldRenderCost) const; 557 const ObjectContainer &objectsRight) const; 593 558 594 559 /** Evaluates tree stats in the BSP tree leafs. … … 658 623 void SortSubdivisionCandidates( 659 624 const BvhTraversalData &data, 660 const int axis, 661 float minBand, 662 float maxBand); 625 const int axis); 663 626 664 627 /** Computes best cost for axis aligned planes. … … 670 633 ObjectContainer &objectsFBack); 671 634 672 /** Evaluate the volume of view cells seeing the left and right child cell. 673 */ 674 void EvalRayContribution(const VssRay &ray, float &volLeft, float &volRight); 675 676 677 /** Evaluates the influence on the pvs of the event. 678 @param ve the visibility event 679 @param pvsLeft updates the left pvs 680 @param rightPvs updates the right pvs 635 /** Evaluates the contribution to the front and back volume 636 when this object is changing sides in the bvs. 637 638 @param object the object 639 @param volLeft updates the left pvs 640 @param volPvs updates the right pvs 681 641 */ 682 642 void EvalHeuristicsContribution( 683 BvhLeaf *leaf, 684 const SortableEntry &ci, 643 Intersectable *obj, 685 644 float &volLeft, 686 float &volRight, 687 int &objectsLeft); 645 float &volRight); 688 646 689 647 /** Prepares objects for the cost heuristics. 690 648 @returns sum of volume of associated view cells 691 649 */ 692 float PrepareHeuristics(const BvhTraversalData &tData); 693 694 /** Prepares heuristics for a particular ray. 695 */ 696 float PrepareHeuristics(const VssRay &ray); 697 698 void AddViewCellVolumeContri( 699 ViewCell *vc, 700 float &frontVol, 701 float &backVol, 702 float &frontAndBackVol) const; 703 704 650 float PrepareHeuristics(const BvhTraversalData &tData, const int axis); 651 652 705 653 //////////////////////////////////////////////// 706 654 … … 708 656 /** Prepares construction for vsp and osp trees. 709 657 */ 710 AxisAlignedBox3 ComputeBoundingBox(const ObjectContainer &objects); 711 712 void CollectDirtyCandidates(BvhSubdivisionCandidate *sc, 658 AxisAlignedBox3 ComputeBoundingBox( 659 const ObjectContainer &objects, 660 const AxisAlignedBox3 *parentBox = NULL); 661 662 void CollectDirtyCandidates( 663 BvhSubdivisionCandidate *sc, 713 664 vector<SubdivisionCandidate *> &dirtyList); 714 665 715 /** Collect view cells which see this kd leaf. 716 */ 717 void CollectViewCells(BvhLeaf *leaf, ViewCellContainer &viewCells); 666 /** Collect view cells which see this bvh leaf. 667 */ 668 void CollectViewCells( 669 const ObjectContainer &objects, 670 ViewCellContainer &viewCells, 671 const bool setCounter = false) const; 672 673 /** Collects view cells which see an object. 674 */ 675 void CollectViewCells( 676 Intersectable *object, 677 ViewCellContainer &viewCells, 678 const bool useMailBoxing, 679 const bool setCounter = false) const; 718 680 719 681 /** Rays will be clipped to the bounding box. … … 724 686 RayInfoContainer &rays); 725 687 726 727 void EvalSubdivisionStats(const SubdivisionCandidate &tData); 688 /** Print the subdivision stats in the subdivison log. 689 */ 690 void PrintSubdivisionStats(const SubdivisionCandidate &tData); 728 691 729 692 void AddSubdivisionStats( … … 734 697 void AssociateObjectsWithRays(const VssRayContainer &rays); 735 698 736 //float EvalViewCellsVolume(BvhLeaf *leaf) const;737 738 /* int RemoveParentViewCellsPvs(BvhLeaf *leaf, const RayInfoContainer &rays) const;739 int UpdateViewCellsPvs(BvhLeaf *leaf, const RayInfoContainer &rays) const;740 bool AddViewCellToObjectPvs(741 Intersectable *obj,742 ViewCell *vc,743 float &contribution,744 bool onlyMailed) const;745 */746 747 699 bool IsObjectInLeaf(BvhLeaf *, Intersectable *object) const; 748 700 749 void MailViewCells( 750 const ObjectContainer &objects, 751 const bool isFront, 752 ViewCellContainer &collectedViewCells) const; 753 754 SubdivisionCandidate *PrepareConstruction(const VssRayContainer &sampleRays, 755 ObjectContainer &objects, 756 AxisAlignedBox3 *forcedObjectSpace 757 //, RayInfoContainer &rays 758 ); 759 760 float EvalViewCellsVolume(BvhLeaf *leaf) const; 701 /** Classifies view cells using the mail id. 702 0 = front bv, 1 = back bv, 2 = both bvs 703 */ 704 void ClassifyViewCells( 705 const ViewCellContainer &objects, 706 const bool isFront) const; 707 708 SubdivisionCandidate *PrepareConstruction( 709 const VssRayContainer &sampleRays, 710 const ObjectContainer &objects 711 //,AxisAlignedBox3 *forcedObjectSpace 712 ); 713 714 float EvalViewCellsVolume(const ObjectContainer &objects) const; 761 715 762 716 763 717 protected: 764 765 718 766 719 /// pointer to the hierarchy of view cells … … 790 743 int mTermMaxDepth; 791 744 /// mininum probability 792 float mTermMin Volume;745 float mTermMinProbability; 793 746 /// minimal number of objects 794 747 int mTermMinObjects; -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r1221 r1287 2311 2311 optBool, 2312 2312 "osp_use_cost_heuristics=", 2313 " false");2313 "true"); 2314 2314 2315 2315 RegisterOption("OspTree.subdivisionStats", -
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
r1233 r1287 4 4 #include "KdTree.h" 5 5 #include "KdIntersectable.h" 6 #include "BvHierarchy.h" 6 7 7 8 … … 67 68 } 68 69 69 ExportGeometry(leaf->mObjects);70 if (0) ExportGeometry(leaf->mObjects); 70 71 } 71 72 … … 102 103 103 104 105 bool Exporter::ExportBvHierarchy(const BvHierarchy &bvHierarchy, 106 const int maxPvs) 107 { 108 vector<BvhLeaf *> leaves; 109 bvHierarchy.CollectLeaves(leaves); 110 111 mUseForcedMaterial = true; 112 113 vector<BvhLeaf *>::const_iterator it, it_end = leaves.end(); 114 115 Material white; 116 white.mDiffuseColor.r = 1; 117 white.mDiffuseColor.g = 1; 118 white.mDiffuseColor.b = 1; 119 int objSize = 0; 120 121 for (it = leaves.begin(); it != it_end; ++ it) 122 { 123 BvhLeaf *leaf = *it; 124 125 SetWireframe(); 126 SetForcedMaterial(white); 127 ExportBox(leaf->GetBoundingBox()); 128 129 SetFilled(); 130 131 if (maxPvs) // color code pvs 132 { 133 mForcedMaterial.mDiffuseColor.b = 1.0f; 134 const float importance = (float)leaf->mObjects.size() / (float)maxPvs; 135 136 mForcedMaterial.mDiffuseColor.r = importance; 137 mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 138 } 139 else 140 { 141 SetForcedMaterial(RandomMaterial()); 142 } 143 144 if (1) 145 { 146 SetFilled(); 147 ExportGeometry(leaf->mObjects); 148 objSize += leaf->mObjects.size(); 149 } 150 } 151 152 return true; 104 153 } 154 155 156 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h
r1197 r1287 29 29 class OspTree; 30 30 class KdIntersectable; 31 31 class BvHierarchy; 32 32 33 33 class Exporter … … 149 149 150 150 void ExportKdIntersectable(const KdIntersectable &kdObj); 151 bool ExportBvHierarchy(const BvHierarchy &bvHierarchy, const int maxPvs); 151 152 }; 152 153 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1286 r1287 135 135 136 136 SubdivisionCandidate *osc = 137 mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace,objectSpaceRays);137 mOspTree->PrepareConstruction(sampleRays, objects, objectSpaceRays); 138 138 139 139 mTQueue.Push(osc); … … 145 145 const float costDecr = tData.GetRenderCostDecrease(); 146 146 147 //mTotalCost -= costDecr; 148 //mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs; 149 150 AddSubdivisionStats(mOspTree->mOspStats.Leaves() + mVspTree->mVspStats.Leaves(), 151 costDecr, 152 mTotalCost 153 ); 147 switch (mObjectSpaceSubdivisonType) 148 { 149 case KD_BASED_OBJ_SUBDIV: 150 AddSubdivisionStats(mOspTree->mOspStats.Leaves() + mVspTree->mVspStats.Leaves(), 151 costDecr, 152 mTotalCost 153 ); 154 break; 155 case BV_BASED_OBJ_SUBDIV: 156 AddSubdivisionStats(mBvHierarchy->mBvhStats.Leaves() + mVspTree->mVspStats.Leaves(), 157 costDecr, 158 mTotalCost 159 ); 160 break; 161 default: 162 AddSubdivisionStats(mVspTree->mVspStats.Leaves(), 163 costDecr, 164 mTotalCost 165 ); 166 break; 167 } 154 168 } 155 169 … … 198 212 199 213 200 bool HierarchyManager:: SubdivideSubdivisionCandidate(SubdivisionCandidate *sc)214 bool HierarchyManager::ApplySubdivisionCandidate(SubdivisionCandidate *sc) 201 215 { 202 216 const bool globalTerminationCriteriaMet = … … 211 225 else 212 226 { 213 KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 227 if (mObjectSpaceSubdivisonType == KD_BASED_OBJ_SUBDIV) 228 { 229 KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 230 } 231 else if (mObjectSpaceSubdivisonType == BV_BASED_OBJ_SUBDIV) 232 { 233 BvhNode *n = mBvHierarchy->Subdivide(mTQueue, sc, globalTerminationCriteriaMet); 234 } 214 235 } 215 236 … … 241 262 //-- subdivide leaf node 242 263 243 if ( SubdivideSubdivisionCandidate(splitCandidate))264 if (ApplySubdivisionCandidate(splitCandidate)) 244 265 { 245 266 // subdivision successful … … 249 270 // for view space splits, this would be object space splits 250 271 // and other way round 251 if (repair) 252 RepairQueue(); 272 if (repair) RepairQueue(); 253 273 254 274 cout << "candidate: " << splitCandidate->Type() << ", priority: " << splitCandidate->GetPriority() << endl; … … 455 475 456 476 457 void HierarchyManager::ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const 477 void HierarchyManager::ExportObjectSpaceHierarchy(Exporter *exporter, 478 const ObjectContainer &objects) const 458 479 { 459 480 switch (mObjectSpaceSubdivisonType) … … 461 482 case KD_BASED_OBJ_SUBDIV: 462 483 { 463 ExportOspTree ForViz(objects);464 break; 465 } 466 case BV_BASED_OBJ_SUBDIV: 467 { 468 ExportBv hForViz(objects);484 ExportOspTree(exporter, objects); 485 break; 486 } 487 case BV_BASED_OBJ_SUBDIV: 488 { 489 ExportBvHierarchy(exporter, objects); 469 490 break; 470 491 } … … 475 496 476 497 477 void HierarchyManager::ExportBvhForViz(const ObjectContainer &objects) const 478 { 479 } 480 481 482 void HierarchyManager::ExportOspTreeForViz(const ObjectContainer &objects) const 483 { 484 //-- export final object partition 485 Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 486 487 if (exporter) 488 { 489 cout << "exporting object space partition ... "; 490 491 if (1) exporter->ExportGeometry(objects); 498 void HierarchyManager::ExportBvHierarchy(Exporter *exporter, 499 const ObjectContainer &objects) const 500 { 501 exporter->SetWireframe(); 502 exporter->ExportBvHierarchy(*mBvHierarchy, 0); 503 } 504 505 506 void HierarchyManager::ExportOspTree(Exporter *exporter, 507 const ObjectContainer &objects) const 508 { 509 if (0) exporter->ExportGeometry(objects); 492 510 493 #if 0 494 // export rays 495 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 496 #endif 497 exporter->SetWireframe(); 498 499 const int colorCode = 0; 500 const int maxPvs = 0;//mOspTree.GetStatistics().maxPvs; 501 502 exporter->ExportOspTree(*mOspTree, 0); 503 delete exporter; 504 505 cout << "finished" << endl; 506 } 511 exporter->SetWireframe(); 512 const int maxPvs = 0;//mOspTree.GetStatistics().maxPvs; 513 514 exporter->ExportOspTree(*mOspTree, 0); 507 515 } 508 516 … … 561 569 case KD_BASED_OBJ_SUBDIV: 562 570 { 563 ConstructOspTree(sampleRays, objects , forcedViewSpace);564 break; 565 } 566 case BV_BASED_OBJ_SUBDIV: 567 { 568 ConstructBvHierarchy(sampleRays, objects , forcedViewSpace);571 ConstructOspTree(sampleRays, objects); 572 break; 573 } 574 case BV_BASED_OBJ_SUBDIV: 575 { 576 ConstructBvHierarchy(sampleRays, objects); 569 577 break; 570 578 } … … 576 584 577 585 void HierarchyManager::ConstructBvHierarchy(const VssRayContainer &sampleRays, 578 const ObjectContainer &objects, 579 AxisAlignedBox3 *forcedViewSpace) 586 const ObjectContainer &objects 587 //,AxisAlignedBox3 *forcedViewSpace 588 ) 580 589 581 590 { … … 583 592 cout << "starting bv hierarchy construction ... " << endl; 584 593 594 //ObjectContainer obj = objects; 595 596 // compute first candidate 597 SubdivisionCandidate *sc = 598 mBvHierarchy->PrepareConstruction(sampleRays, objects); 599 600 mTotalCost = mBvHierarchy->mTotalCost; 601 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 602 603 mTQueue.Push(sc); 604 605 mBvHierarchy->mBvhStats.Reset(); 606 mBvHierarchy->mBvhStats.Start(); 607 608 const long startTime = GetTime(); 609 const bool repairQueue = false; 610 611 // process object space candidates 612 RunConstruction(repairQueue); 613 614 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 615 616 mBvHierarchy->mBvhStats.Stop(); 617 } 618 619 620 void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 621 const ObjectContainer &objects) 622 623 { 624 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 625 626 Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 627 cout << "starting osp tree construction ... " << endl; 628 585 629 // start with one big kd cell - all objects can be seen from everywhere 586 630 // note: only true for view space = object space 587 631 588 ObjectContainer obj = objects;589 590 632 // compute first candidate 591 SubdivisionCandidate *sc = 592 mBvHierarchy->PrepareConstruction(sampleRays, obj, forcedViewSpace); 593 633 SubdivisionCandidate *osc = 634 mOspTree->PrepareConstruction(sampleRays, objects, *objectSpaceRays); 635 636 mTotalCost = mOspTree->mTotalCost; 594 637 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 595 mTotalCost = mOspTree->mTotalCost; 596 597 mTQueue.Push(sc); 638 639 mTQueue.Push(osc); 598 640 599 641 mOspTree->mOspStats.Reset(); … … 602 644 const long startTime = GetTime(); 603 645 const bool repairQueue = false; 604 646 605 647 // process object space candidates 606 648 RunConstruction(repairQueue); … … 618 660 } 619 661 620 621 void HierarchyManager::ConstructOspTree(const VssRayContainer &sampleRays, 622 const ObjectContainer &objects, 623 AxisAlignedBox3 *forcedViewSpace) 624 625 { 626 RayInfoContainer *objectSpaceRays = new RayInfoContainer(); 627 628 Debug << "\n$$$$$$$$$ osp tree construction $$$$$$$$$$\n" << endl; 629 cout << "starting osp tree construction ... " << endl; 630 631 // start with one big kd cell - all objects can be seen from everywhere 632 // note: only true for view space = object space 633 634 // compute first candidate 635 SubdivisionCandidate *osc = 636 mOspTree->PrepareConstruction(sampleRays, objects, forcedViewSpace, *objectSpaceRays); 637 638 Debug << "reseting cost, new total cost: " << mTotalCost << endl; 639 mTotalCost = mOspTree->mTotalCost; 640 641 mTQueue.Push(osc); 642 643 mOspTree->mOspStats.Reset(); 644 mOspTree->mOspStats.Start(); 645 646 const long startTime = GetTime(); 647 const bool repairQueue = false; 648 649 // process object space candidates 650 RunConstruction(repairQueue); 651 652 cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 653 654 mOspTree->mOspStats.Stop(); 655 656 ////////////////////////// 657 // matt: only for debugging purpose 658 659 const float rc = mOspTree->EvalRenderCost(sampleRays); 660 661 Debug << "My render cost evalulation: " << rc << endl; 662 } 663 664 } 662 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1286 r1287 40 40 class KdTreeStatistics; 41 41 class BvHierarchy; 42 42 class Exporter; 43 43 44 44 #if 0 … … 154 154 VspTree *GetVspTree() { return mVspTree; } 155 155 156 void ExportObjectSpaceHierarchyForViz(const ObjectContainer &objects) const; 156 void ExportObjectSpaceHierarchy( 157 Exporter *exporter, 158 const ObjectContainer &objects) const; 157 159 158 160 … … 172 174 173 175 void RunConstruction(const bool repair); 174 bool SubdivideSubdivisionCandidate(SubdivisionCandidate *sc);176 bool ApplySubdivisionCandidate(SubdivisionCandidate *sc); 175 177 176 178 bool FinishedConstruction() const; … … 199 201 void CollectObjectSpaceDirtyList(SubdivisionCandidateContainer &dirtyList); 200 202 201 void ExportOspTreeForViz(const ObjectContainer &objects) const; 202 void ExportBvhForViz(const ObjectContainer &objects) const; 203 void ExportOspTree(Exporter *exporter, const ObjectContainer &objects) const; 204 void ExportBvHierarchy(Exporter *exporter, const ObjectContainer &objects) const; 205 203 206 204 207 void ConstructBvHierarchy( 205 208 const VssRayContainer &sampleRays, 206 const ObjectContainer &objects, 207 AxisAlignedBox3 *forcedViewSpace); 209 const ObjectContainer &objects); 208 210 209 211 void ConstructOspTree( 210 212 const VssRayContainer &sampleRays, 211 const ObjectContainer &objects, 212 AxisAlignedBox3 *forcedViewSpace); 213 const ObjectContainer &objects); 213 214 214 215 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
r1199 r1287 9 9 bool MeshDebug = false; 10 10 11 int Intersectable::sMailId = 21 843194198;11 int Intersectable::sMailId = 2147483647; 12 12 int Intersectable::sReservedMailboxes = 1; 13 13 -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
r1286 r1287 397 397 backData.mNode = back; 398 398 399 400 399 // compute probability, i.e., volume of seen view cells 401 400 frontData.mProbability = EvalViewCellsVolume(front, *frontData.mRays); 402 401 backData.mProbability = EvalViewCellsVolume(back, *backData.mRays); 403 404 402 405 403 //delete leaf; … … 1648 1646 1649 1647 1650 void OspTree::ComputeBoundingBox(const ObjectContainer &objects, 1651 AxisAlignedBox3 *forcedBoundingBox) 1652 { 1653 if (forcedBoundingBox) 1654 { 1655 mBoundingBox = *forcedBoundingBox; 1656 } 1657 else // compute vsp tree bounding box 1658 { 1659 mBoundingBox.Initialize(); 1660 1661 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1662 1663 //-- compute bounding box 1664 for (oit = objects.begin(); oit != oit_end; ++ oit) 1665 { 1666 Intersectable *obj = *oit; 1667 1668 // compute bounding box of view space 1669 mBoundingBox.Include(obj->GetBox()); 1670 } 1648 void OspTree::ComputeBoundingBox(const ObjectContainer &objects) 1649 { 1650 mBoundingBox.Initialize(); 1651 1652 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1653 1654 //-- compute bounding box 1655 for (oit = objects.begin(); oit != oit_end; ++ oit) 1656 { 1657 Intersectable *obj = *oit; 1658 1659 // compute bounding box of view space 1660 mBoundingBox.Include(obj->GetBox()); 1671 1661 } 1672 1662 } … … 2657 2647 SubdivisionCandidate * OspTree::PrepareConstruction(const VssRayContainer &sampleRays, 2658 2648 const ObjectContainer &objects, 2659 AxisAlignedBox3 *forcedObjectSpace,2660 2649 RayInfoContainer &rays) 2661 2650 { … … 2665 2654 2666 2655 // compute bounding box from objects 2667 ComputeBoundingBox(objects , forcedObjectSpace);2656 ComputeBoundingBox(objects); 2668 2657 2669 2658 mTermMinProbability *= mBoundingBox.GetVolume(); -
GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h
r1259 r1287 627 627 @returns pvs size of the node 628 628 */ 629 float PrepareHeuristics(const OspTraversalData &tData, ViewCellContainer &touchedViewCells); 629 float PrepareHeuristics( 630 const OspTraversalData &tData, 631 ViewCellContainer &touchedViewCells); 630 632 631 633 /** Prepares heuristics for a particular ray. 632 634 */ 633 void PrepareHeuristics(const VssRay &ray, ViewCellContainer &touchedViewCells); 635 void PrepareHeuristics( 636 const VssRay &ray, 637 ViewCellContainer &touchedViewCells); 634 638 635 639 /** Prepares construction for vsp and osp trees. 636 640 */ 637 void ComputeBoundingBox(const ObjectContainer &objects, 638 AxisAlignedBox3 *forcedBoundingBox); 641 void ComputeBoundingBox(const ObjectContainer &objects); 639 642 640 643 void CollectDirtyCandidates(OspSubdivisionCandidate *sc, … … 727 730 const VssRayContainer &sampleRays, 728 731 const ObjectContainer &objects, 729 AxisAlignedBox3 *forcedObjectSpace,730 732 RayInfoContainer &rays); 731 733 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1286 r1287 18 18 #include "BvHierarchy.h" 19 19 #include "HierarchyManager.h" 20 #include "VssRay.h" 21 20 22 21 23 #ifdef GTP_INTERNAL … … 483 485 const bool ishack = true; 484 486 485 if (ishack) 486 { 487 /*if (ishack) 487 488 mHierarchyManager = new HierarchyManager(mVspTree, mKdTree); 488 }489 489 else 490 {491 490 mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV); 492 } 491 */ 492 mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::BV_BASED_OBJ_SUBDIV); 493 493 494 494 mViewCellsManager = new VspOspViewCellsManager(vcTree, mHierarchyManager); … … 831 831 objectB, 832 832 objectA, 833 probability, 834 mPass); 833 mPass, 834 probability 835 ); 835 836 836 837 vssRays.push_back(vssRay); … … 844 845 objectA, 845 846 objectB, 846 probability, 847 mPass); 847 mPass, 848 probability 849 ); 848 850 849 851 vssRays.push_back(vssRay); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1283 r1287 28 28 class BvHierarchy; 29 29 class Intersectable; 30 class VssRay; 30 31 31 32 /** Namespace for the external visibility preprocessor -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r1286 r1287 27 27 RuntimeTypeInfo="TRUE" 28 28 UsePrecompiledHeader="0" 29 BrowseInformation="1" 29 30 WarningLevel="3" 30 31 Detect64BitPortabilityProblems="TRUE" … … 68 69 OmitFramePointers="TRUE" 69 70 EnableFiberSafeOptimizations="TRUE" 70 OptimizeForProcessor=" 3"71 OptimizeForProcessor="0" 71 72 OptimizeForWindowsApplication="TRUE" 72 73 AdditionalIncludeDirectories="..\include;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost" -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r1286 r1287 26 26 RuntimeLibrary="3" 27 27 UsePrecompiledHeader="0" 28 BrowseInformation="1" 28 29 WarningLevel="3" 29 30 Detect64BitPortabilityProblems="TRUE" … … 75 76 EnableIntrinsicFunctions="TRUE" 76 77 FavorSizeOrSpeed="1" 77 OptimizeForProcessor=" 3"78 OptimizeForProcessor="0" 78 79 OptimizeForWindowsApplication="TRUE" 79 80 AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\MultiLevelRayTracing" -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r1286 r1287 32 32 myless<vector<ViewCell *>::value_type> > TraversalQueue; 33 33 34 int ViewCell::sMailId = 0;//21843194198;34 int ViewCell::sMailId = 2147483647; 35 35 int ViewCell::sReservedMailboxes = 1; 36 36 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1286 r1287 5101 5101 cout << "exporting view cells after post process ... "; 5102 5102 5103 if (0)5104 {5105 // export view space box5106 exporter->SetWireframe();5107 exporter->ExportBox(mViewSpaceBox);5108 exporter->SetFilled();5109 }5110 5111 5103 if (mExportGeometry) 5112 5104 { … … 5120 5112 } 5121 5113 5122 //exporter->SetFilled();5123 5124 5114 // HACK: export without clip plane 5125 5115 const bool b = mUseClipPlaneForViz; … … 5137 5127 } 5138 5128 5139 mHierarchyManager->ExportObjectSpaceHierarchyForViz(objects); 5140 5141 //-- export single view cells 5129 if (1) 5130 { 5131 // export final object partition 5132 Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl"); 5133 5134 if (exporter) 5135 { 5136 cout << "exporting object space hierarchy ... "; 5137 mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects); 5138 5139 delete exporter; 5140 cout << "finished" << endl; 5141 } 5142 } 5143 5144 // export pvss of some view cell 5142 5145 ExportPvs(objects, visRays); 5143 5146 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1286 r1287 159 159 if (mObjectSpaceHierarchyType == OSP) 160 160 { 161 // for a spatial subdivision, it is not necessary to store 162 // the objects with the leaves, they can be classified now 161 163 mHierarchyManager->mOspTree->InsertObjects( 162 164 mHierarchyManager->mOspTree->mRoot, *mObjects); 163 165 } 166 else 167 cout << "here209" << endl; 168 164 169 } 165 170 … … 279 284 280 285 281 void ViewCellsParseHandlers::StartHierarchy(AttributeList& attributes)282 {283 int len = attributes.getLength();284 285 for (int i = 0; i < len; ++ i)286 {287 string attrName(StrX(attributes.getName(i)).LocalForm());288 289 if (attrName == "name")290 {291 StrX attrValue(attributes.getValue(i));292 293 const char *ptr = attrValue.LocalForm();294 295 // the view cells manager is created here296 //CreateViewCellsManager(ptr);297 }298 }299 }300 301 302 286 void ViewCellsParseHandlers::StartBspElement(string element, 303 287 AttributeList& attributes) … … 437 421 // create new view cells hierarchy 438 422 mViewCellsTree = new ViewCellsTree(); 439 }440 441 // decides about the view cells manager type442 if (element == "Hierarchy")443 {444 cout << "parsing view cells manager type" << endl;445 StartHierarchy(attributes);446 423 } 447 424 … … 688 665 const char *ptr = attrValue.LocalForm(); 689 666 690 691 667 if (attrName == "id") 692 668 { … … 711 687 void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes) 712 688 { 713 BspLeaf * leaf = 714 new BspLeaf(dynamic_cast<BspInterior *>(mCurrentBspNode), NULL); 689 BspLeaf * leaf; 715 690 716 691 if (mCurrentBspNode) // replace front or (if not NULL) back child 717 692 { 718 dynamic_cast<BspInterior *>(mCurrentBspNode)->ReplaceChildLink(NULL, leaf); 693 BspInterior *interior = dynamic_cast<BspInterior *>(mCurrentBspNode); 694 695 leaf = new BspLeaf(interior); 696 interior->ReplaceChildLink(NULL, leaf); 719 697 } 720 698 else 721 699 { 700 leaf = new BspLeaf(); 722 701 mVspBspTree->mRoot = leaf; 723 702 } … … 797 776 if (mCurrentBspNode) // replace NULL child of parent with current node 798 777 { 799 BspInterior * current = dynamic_cast<BspInterior *>(mCurrentBspNode);800 801 current->ReplaceChildLink(NULL, interior);802 interior->SetParent( current);778 BspInterior *parent = dynamic_cast<BspInterior *>(mCurrentBspNode); 779 780 parent->ReplaceChildLink(NULL, interior); 781 interior->SetParent(parent); 803 782 } 804 783 else … … 856 835 void ViewCellsParseHandlers::CreateViewSpaceHierarchy() 857 836 { 858 ViewCellContainer::iterator it, it_end = mViewCells.end();859 cout << "\n====================" << endl << endl;860 for (it = mViewCells.begin(); it != it_end; ++ it)861 {862 cout << (*it)->GetId() << " ";863 }864 cout << endl;865 837 if (mViewSpaceHierarchyType == BSP) 866 838 { … … 936 908 } 937 909 } 938 cout << "************************" << endl; 939 it_end = mViewCells.end(); 940 for (it = mViewCells.begin(); it != it_end; ++ it) 941 { 942 cout << (*it)->GetId() << " "; 943 } 944 cout << endl; 945 cout << "\nview space box: " << mViewSpaceBox << endl; 910 //cout << "\nview space box: " << mViewSpaceBox << endl; 946 911 } 947 912 … … 992 957 void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes) 993 958 { 994 VspLeaf * leaf = 995 new VspLeaf(dynamic_cast<VspInterior *>(mCurrentVspNode), NULL); 996 959 VspLeaf * leaf; 960 997 961 if (mCurrentVspNode) // replace front or (if not NULL) back child 998 962 { 999 dynamic_cast<VspInterior *>(mCurrentVspNode)->ReplaceChildLink(NULL, leaf); 963 VspInterior *interior = dynamic_cast<VspInterior *>(mCurrentVspNode); 964 leaf = new VspLeaf(interior); 965 interior->ReplaceChildLink(NULL, leaf); 1000 966 } 1001 967 else 1002 968 { 969 leaf = new VspLeaf(); 1003 970 mVspTree->mRoot = leaf; 1004 971 } … … 1029 996 dummyVc.SetId(viewCellId); 1030 997 1031 cout << "\nsearching view cell with id " << viewCellId << endl;998 //cout << "\nsearching view cell with id " << viewCellId << endl; 1032 999 1033 1000 ViewCellContainer::iterator vit = … … 1087 1054 AxisAlignedBox3 frontBox, backBox; 1088 1055 1089 parent->GetBoundingBox().Split(parent->GetPlane().mAxis, parent->GetPlane().mPosition, frontBox, backBox); 1056 parent->GetBoundingBox().Split( 1057 parent->GetPlane().mAxis, 1058 parent->GetPlane().mPosition, 1059 frontBox, 1060 backBox); 1061 1090 1062 if (parent->GetFront() == interior) 1091 1063 interior->SetBoundingBox(frontBox); … … 1134 1106 1135 1107 parent->mBox.Split(parent->mAxis, parent->mPosition, frontBox, backBox); 1108 1136 1109 if (parent->mFront == interior) 1137 1110 interior->mBox = frontBox; … … 1180 1153 if (attrName == "min") 1181 1154 { 1182 sscanf(ptr, "%f %f %f", &minBox );1155 sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 1183 1156 } 1184 1157 if (attrName == "max") 1185 1158 { 1186 sscanf(ptr, "%f %f %f", &maxBox );1159 sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 1187 1160 } 1188 1161 if (attrName == "objects") … … 1192 1165 } 1193 1166 1194 BvhLeaf * leaf = 1195 new BvhLeaf(AxisAlignedBox3(minBox, maxBox), 1196 dynamic_cast<BvhInterior *>(mCurrentBvhNode), (int)objects.size()); 1167 AxisAlignedBox3 box = AxisAlignedBox3(minBox, maxBox); 1168 1169 BvhLeaf *leaf; 1170 1171 if (mCurrentBvhNode) // replace front or (if not NULL) back child 1172 { 1173 BvhInterior *interior = dynamic_cast<BvhInterior *>(mCurrentBvhNode); 1174 leaf = new BvhLeaf(box, interior, (int)objects.size()); 1175 interior->ReplaceChildLink(NULL, leaf); 1176 } 1177 else 1178 { 1179 leaf = new BvhLeaf(box, NULL, (int)objects.size()); 1180 mHierarchyManager->mBvHierarchy->mRoot = leaf; 1181 } 1197 1182 1198 1183 leaf->mObjects = objects; 1199 1200 if (mCurrentBvhNode) // replace front or (if not NULL) back child1201 {1202 dynamic_cast<BvhInterior *>(mCurrentBvhNode)->ReplaceChildLink(NULL, leaf);1203 }1204 else1205 {1206 mHierarchyManager->mBvHierarchy->mRoot = leaf;1207 }1208 1184 } 1209 1185 … … 1219 1195 { 1220 1196 const int index = strtol(ptr, &endptr, 10); 1221 1222 1197 if (ptr == endptr) break; 1223 1198 1224 1199 objIndices.push_back(index); 1225 1226 1200 ptr = endptr; 1227 1201 } … … 1239 1213 1240 1214 ObjectContainer::iterator oit = 1241 lower_bound(mObjects->begin(), mObjects->end(), (Intersectable *)&dummyInst, ilt); 1215 lower_bound(mObjects->begin(), 1216 mObjects->end(), 1217 (Intersectable *)&dummyInst, 1218 ilt); 1242 1219 1243 1220 if ((oit != mObjects->end()) && ((*oit)->GetId() == objId)) … … 1260 1237 for (int i = 0; i < len; ++ i) 1261 1238 { 1239 cout << "here5" << endl; 1262 1240 string attrName(StrX(attributes.getName(i)).LocalForm()); 1263 1241 StrX attrValue(attributes.getValue(i)); … … 1265 1243 1266 1244 if (attrName == "min") 1267 { 1268 sscanf(ptr, "%f %f %f", &minBox );1245 {cout << "here6" << endl; 1246 sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z); 1269 1247 } 1270 1248 if (attrName == "max") 1271 { 1272 sscanf(ptr, "%f %f %f", &maxBox );1249 {cout << "here7" << endl; 1250 sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z); 1273 1251 } 1274 1252 } … … 1278 1256 if (mCurrentBvhNode) // replace NULL child of parent with current node 1279 1257 { 1258 cout << "here8" << endl; 1280 1259 BvhInterior *parent = dynamic_cast<BvhInterior *>(mCurrentBvhNode); 1281 1260 parent->ReplaceChildLink(NULL, interior); … … 1283 1262 } 1284 1263 else 1285 { 1286 m BvHierarchy->mRoot = interior;1287 } 1288 1264 {cout << "here18" << endl; 1265 mHierarchyManager->mBvHierarchy->mRoot = interior; 1266 } 1267 cout << "here28" << endl; 1289 1268 mCurrentBvhNode = interior; 1290 1269 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
r1286 r1287 77 77 VspBspTree *mVspBspTree; 78 78 HierarchyManager *mHierarchyManager; 79 BvHierarchy *mBvHierarchy;79 //vHierarchy *mBvHierarchy; 80 80 81 81 BspTree *mBspTree; … … 129 129 void EndViewCells(); 130 130 void EndBoundingBoxes(); 131 132 void StartHierarchy(AttributeList& attributes);133 131 134 132 void StartBspElement(string element, AttributeList& attributes); -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
r1233 r1287 1181 1181 } 1182 1182 1183 // hack: all object exported as one mesh 1183 /////////////////////////////////// 1184 // method 2 (hacky) 1185 // all object exported as one mesh 1184 1186 PolygonContainer polys; 1185 1187 1186 1188 for (oit = objects.begin(); oit != oit_end; ++ oit) 1187 1189 { 1188 polys.push_back(new Polygon3(dynamic_cast<MeshInstance *>(*oit)->GetMesh()->mVertices)); 1190 MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 1191 polys.push_back(new Polygon3(mi->GetMesh()->mVertices)); 1189 1192 } 1190 1193 -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r1286 r1287 2854 2854 void VspTree::GetViewCells(const VssRay &ray, ViewCellContainer &viewCells) 2855 2855 { 2856 #if 02856 #if 1 2857 2857 // use view cells manager to compute view cells 2858 mViewCellsManager->ComputeSampleContribution(ray, false, true);2859 viewCells = ray.mViewCells; 2860 ray.mViewCells.clear();2861 2858 VssRay vcRay(ray); 2859 2860 mViewCellsManager->ComputeSampleContribution(vcRay, false, true); 2861 viewCells = vcRay.mViewCells; 2862 2862 #else 2863 2863 static Ray hray; -
GTP/trunk/Lib/Vis/Preprocessing/src/common.h
r1201 r1287 269 269 270 270 271 271 /*inline int 272 RandomValue(int a, int b) 273 { 274 int range = abs(a - b); 275 return (rand() * range) / RAND_MAX + ((a < b) ? a : b); 276 }*/ 272 277 273 278 inline Real sqr(Real a) … … 275 280 return a*a; 276 281 } 282 277 283 278 284 template <class T>
Note: See TracChangeset
for help on using the changeset viewer.