Changeset 2332 for GTP/trunk/Lib/Vis/Preprocessing
- Timestamp:
- 04/23/07 16:19:30 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r2176 r2332 2356 2356 2357 2357 point *= 1.0f / sum; 2358 2359 2358 //normal = face.GetNormal(); 2360 2359 -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r2255 r2332 27 27 #define USE_VOLUMES_FOR_HEURISTICS 1 28 28 #define TEST_POWERPLANT 0 29 #define USE_BETTER_RENDERCOST_EST 0 29 30 30 31 31 //int BvhNode::sMailId = 10000; … … 53 53 /* class BvhNode implementation */ 54 54 /***************************************************************/ 55 56 55 57 56 BvhNode::BvhNode(): … … 387 386 388 387 388 void BvHierarchy::UpdateViewCells(const BvhSubdivisionCandidate &sc) 389 { 390 ViewCellContainer viewCells, frontViewCells, backViewCells; 391 392 CollectViewCells(*sc.mParentData.mSampledObjects, viewCells, false, false); 393 CollectViewCells(sc.mSampledFrontObjects, frontViewCells, false, false); 394 CollectViewCells(sc.mSampledBackObjects, backViewCells, false, false); 395 396 const float frontTri = (float)sc.mFrontObjects.size(); 397 const float backTri = (float)sc.mBackObjects.size(); 398 const float totalTri = (float)(*sc.mParentData.mSortedObjects[0]).size(); 399 400 ViewCell::NewMail(3); 401 402 ViewCellContainer::const_iterator fit, fit_end = frontViewCells.end(); 403 404 for (fit = frontViewCells.begin(); fit != fit_end; ++ fit) 405 { 406 ViewCell *vc = *fit; 407 vc->Mail(0); 408 } 409 410 ViewCellContainer::const_iterator bit, bit_end = backViewCells.end(); 411 412 for (bit = backViewCells.begin(); bit != bit_end; ++ bit) 413 { 414 ViewCell *vc = *bit; 415 416 if (vc->Mailed(0)) 417 vc->Mail(2); 418 else 419 vc->Mail(1); 420 } 421 422 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 423 424 for (vit = viewCells.begin(); vit != viewCells.end(); ++ vit) 425 { 426 ViewCell *vc = *vit; 427 428 float vcTri; 429 int vcObj; 430 431 float oldVcTri = vc->GetPvsCost(); 432 int oldVcObj = vc->GetEntriesInPvs(); 433 434 // both objects in view cell 435 if (vc->Mailed(2)) 436 { 437 vcTri = oldVcTri; 438 vcObj = oldVcObj + 1; 439 } 440 else if (vc->Mailed(1)) 441 { 442 vcTri = oldVcTri - totalTri + backTri; 443 vcObj = oldVcObj; 444 } 445 else // (vc->Mailed(0)) 446 { 447 vcTri = oldVcTri - totalTri + frontTri; 448 vcObj = oldVcObj; 449 } 450 451 vc->SetPvsCost(vcTri); 452 vc->SetEntriesInPvs(vcObj); 453 454 //cout << "old pvs tri: " << oldVcTri << " new: " << vcTri << endl; 455 //cout << "old pvs obj: " << oldVcObj << " new: " << vcObj<< endl; 456 } 457 } 458 459 389 460 BvhInterior *BvHierarchy::SubdivideNode(const BvhSubdivisionCandidate &sc, 390 461 BvhTraversalData &frontData, … … 439 510 440 511 441 //////////////////////////////// ////////512 //////////////////////////////// 442 513 //-- fill front and back traversal data with the new values 443 514 … … 467 538 //-- compute pvs correction to cope with undersampling 468 539 469 frontData.mPvs = (float)sc.mNumFrontViewCells; //(float)CountViewCells(sc.mSampledFrontObjects);470 backData.mPvs = (float)sc.mNumBackViewCells; //(float)CountViewCells(sc.mSampledBackObjects);540 frontData.mPvs = (float)sc.mNumFrontViewCells; 541 backData.mPvs = (float)sc.mNumBackViewCells; 471 542 472 543 frontData.mCorrectedPvs = sc.mCorrectedFrontPvs; … … 476 547 // compute probability of this node being visible, 477 548 // i.e., volume of the view cells that can see this node 478 frontData.mVolume = sc.mVolumeFrontViewCells; //EvalViewCellsVolume(sc.mSampledFrontObjects) / GetViewSpaceVolume();479 backData.mVolume = sc.mVolumeBackViewCells; //EvalViewCellsVolume(sc.mSampledBackObjects) / GetViewSpaceVolume();549 frontData.mVolume = sc.mVolumeFrontViewCells; 550 backData.mVolume = sc.mVolumeBackViewCells; 480 551 481 552 frontData.mCorrectedVolume = sc.mCorrectedFrontVolume; … … 495 566 AssignSortedObjects(sc, frontData, backData); 496 567 } 568 569 // compute e.g., new render cost decrease after this split 570 UpdateViewCells(sc); 497 571 498 572 mNodeTimer.Exit(); … … 649 723 mPlaneTimer.Entry(); 650 724 725 const BvhTraversalData &tData = splitCandidate.mParentData; 726 BvhLeaf *leaf = tData.mNode; 727 651 728 #if STORE_VIEWCELLS_WITH_BVH 652 729 if (preprocessViewCells) // fill view cells cache … … 658 735 splitCandidate.mFrontObjects.clear(); 659 736 splitCandidate.mBackObjects.clear(); 737 660 738 splitCandidate.mSampledFrontObjects.clear(); 661 739 splitCandidate.mSampledBackObjects.clear(); 662 740 663 741 const bool sufficientSamples = 664 splitCandidate.mParentData.mNumRays > mMinRaysForVisibility; 665 666 //if (!sufficientSamples) cout << splitCandidate.mParentData.mNumRays << " "; 742 tData.mNumRays > mMinRaysForVisibility; 667 743 668 744 const bool useVisibiliyBasedHeuristics = … … 673 749 674 750 // compute best object partition 675 const float ratio = SelectObjectPartition( splitCandidate.mParentData,751 const float ratio = SelectObjectPartition(tData, 676 752 splitCandidate.mFrontObjects, 677 753 splitCandidate.mBackObjects, … … 691 767 mPlaneTimer.Exit(); 692 768 769 770 /////////////////// 771 693 772 mEvalTimer.Entry(); 694 773 695 const BvhTraversalData &tData = splitCandidate.mParentData; 696 BvhLeaf *leaf = tData.mNode; 697 698 // avg contribution of a ray to a pvs 699 const float pvs = (float)CountViewCells(*tData.mSampledObjects); 700 //const float avgRayContri = AvgRayContribution((int)pvs, tData.mNumRays); 774 ViewCellContainer viewCells, frontViewCells, backViewCells; 775 776 CollectViewCells(*tData.mSampledObjects, viewCells, false, false); 777 CollectViewCells(splitCandidate.mSampledFrontObjects, frontViewCells, false, false); 778 CollectViewCells(splitCandidate.mSampledBackObjects, backViewCells, false, false); 779 780 // compute view cells seen from front and back side of the split 781 float volFront = 0, volBack = 0, parentVol = 0; 782 783 ViewCell::NewMail(3); 784 785 ViewCellContainer::const_iterator fvit, fvit_end = frontViewCells.end(); 786 787 for (fvit = frontViewCells.begin(); fvit != fvit_end; ++ fvit) 788 { 789 ViewCell *vc = *fvit; 790 vc->Mail(0); 791 792 volFront += vc->GetVolume(); 793 parentVol += vc->GetVolume(); 794 } 795 796 ViewCellContainer::const_iterator bvit, bvit_end = backViewCells.end(); 797 798 int frontAndBackViewCells = 0; 799 800 for (bvit = backViewCells.begin(); bvit != bvit_end; ++ bvit) 801 { 802 ViewCell *vc = *bvit; 803 804 if (vc->Mailed(0)) 805 { 806 // view cell sees front AND on back side 807 ++ frontAndBackViewCells; 808 vc->Mail(2); 809 } 810 else 811 { 812 vc->Mail(1); 813 parentVol += vc->GetVolume(); 814 } 815 816 volBack += vc->GetVolume(); 817 } 818 819 820 ///////////////////// 821 //-- this bvh node is a pvs entry in all the view cells that see one of the objects. 822 823 // pvs size induced by this bvh node is #view cells 824 const float pvs = (float)viewCells.size(); 701 825 const float avgRaysPerObject = AvgRaysPerObject((int)pvs, tData.mNumRays); 702 826 703 // high avg ray contri,the result is influenced by undersampling827 // for low #rays per object => the result is influenced by undersampling 704 828 splitCandidate.SetAvgRaysPerObject(avgRaysPerObject); 705 829 const float viewSpaceVol = GetViewSpaceVolume(); 706 830 707 const float oldVolume = EvalViewCellsVolume(*tData.mSampledObjects) / viewSpaceVol; 708 const float oldRatio = (tData.mVolume > 0) ? oldVolume / tData.mVolume : 1; 709 const float parentVol = tData.mCorrectedVolume * oldRatio; 710 711 //cout << "h " << avgRaysPerObject << " "; 712 // this leaf is a pvs entry in all the view cells 713 // that see one of the objects. 714 splitCandidate.mVolumeFrontViewCells = EvalViewCellsVolume(splitCandidate.mSampledFrontObjects) / viewSpaceVol; 715 splitCandidate.mVolumeBackViewCells = EvalViewCellsVolume(splitCandidate.mSampledBackObjects) / viewSpaceVol; 716 717 splitCandidate.mNumFrontViewCells = CountViewCells(splitCandidate.mSampledFrontObjects); 718 splitCandidate.mNumBackViewCells = CountViewCells(splitCandidate.mSampledBackObjects); 719 831 splitCandidate.mVolumeFrontViewCells = volFront / viewSpaceVol; 832 splitCandidate.mVolumeBackViewCells = volBack / viewSpaceVol; 833 834 splitCandidate.mNumFrontViewCells = (int)frontViewCells.size(); 835 splitCandidate.mNumBackViewCells = (int)backViewCells.size(); 836 837 // currently not working!! 838 // todo matt: fix this to cope with undersampling for new evaluation method 720 839 splitCandidate.mCorrectedFrontVolume = 721 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, parentVol, avgRaysPerObject); 840 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeFrontViewCells, 841 parentVol, 842 avgRaysPerObject); 722 843 723 844 splitCandidate.mCorrectedBackVolume = 724 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeBackViewCells, parentVol, avgRaysPerObject); 725 726 const float relfrontCost = splitCandidate.mCorrectedFrontVolume * 727 EvalAbsCost(splitCandidate.mFrontObjects); 728 const float relBackCost = splitCandidate.mCorrectedBackVolume * 729 EvalAbsCost(splitCandidate.mBackObjects); 730 const float relParentCost = parentVol * EvalAbsCost(leaf->mObjects); 845 mHierarchyManager->EvalCorrectedPvs(splitCandidate.mVolumeBackViewCells, 846 parentVol, 847 avgRaysPerObject); 848 849 /////////////////////////////////// 850 851 852 float newRenderCost = 0, oldRenderCost = 0; 853 854 const float frontTri = (float)splitCandidate.mFrontObjects.size(); 855 const float backTri = (float)splitCandidate.mBackObjects.size(); 856 // total #triangles in parent 857 const float totalTri = (float)(*tData.mSortedObjects[0]).size(); 858 859 860 // compute render cost decrease in the seen view cells 861 ViewCellContainer::const_iterator vit, vit_end = viewCells.end(); 862 863 for (vit = viewCells.begin(); vit != viewCells.end(); ++ vit) 864 { 865 ViewCell *vc = *vit; 866 867 // triangles in this view cell 868 float vcTri; 869 // #entries in this view cell 870 int vcObj; 871 872 float oldVcTri = vc->GetPvsCost(); 873 int oldVcObj = vc->GetEntriesInPvs(); 874 875 // both nodes in this view cell 876 if (vc->Mailed(2)) 877 { 878 vcTri = oldVcTri; 879 // #entries is increasing 880 vcObj = oldVcObj + 1; 881 } 882 else if (vc->Mailed(1)) 883 { 884 // only front node in this view cell: #triangles is decreasing 885 vcTri = oldVcTri - totalTri + backTri; 886 vcObj = oldVcObj; 887 } 888 else // (vc->Mailed(0)) 889 { 890 // // only back node in this view cell: #triangles is decreasing 891 vcTri = oldVcTri - totalTri + frontTri; 892 vcObj = oldVcObj; 893 } 894 895 oldRenderCost += mViewCellsManager->ComputeRenderCost((int)oldVcTri, (int)oldVcObj) * vc->GetVolume() / viewSpaceVol; 896 newRenderCost += mViewCellsManager->ComputeRenderCost((int)vcTri, (int)vcObj) * vc->GetVolume() / viewSpaceVol; 897 //cout << "old rc=" << oldRenderCost << " new rc " << newRenderCost << endl; 898 } 731 899 732 900 // compute global decrease in render cost 733 const float newRenderCost = relfrontCost + relBackCost; 734 const float renderCostDecr = relParentCost - newRenderCost; 735 901 const float renderCostDecr = (oldRenderCost - newRenderCost); 902 903 // for each view cell seen from front and back there is a new entry 904 const int pvsEntriesIncr = frontAndBackViewCells; 905 736 906 splitCandidate.SetRenderCostDecrease(renderCostDecr); 737 738 // increase in pvs entries739 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate,740 avgRaysPerObject,741 (int)pvs,742 splitCandidate.mNumFrontViewCells,743 splitCandidate.mNumBackViewCells);744 745 907 splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 746 908 747 if (0) 748 { 749 cout << "bvh volume cost" 750 << " avg rays per object: " << avgRaysPerObject << " ratio: " << oldRatio 751 << " parent: " << parentVol << " old vol: " << oldVolume 752 << " frontvol: " << splitCandidate.mVolumeFrontViewCells << " corr. " << splitCandidate.mCorrectedFrontVolume 753 << " backvol: " << splitCandidate.mVolumeBackViewCells << " corr. " << splitCandidate.mCorrectedBackVolume << endl; 754 } 755 756 #ifdef GTP_DEBUG 757 Debug << "old render cost: " << oldRenderCost << endl; 758 Debug << "new render cost: " << newRenderCost << endl; 759 Debug << "render cost decrease: " << renderCostDecr << endl; 760 #endif 761 762 float priority = EvalPriority(splitCandidate, 763 renderCostDecr, 764 relParentCost); 765 766 // compute global decrease in render cost 909 //cout << "bvh render cost decrease=" << renderCostDecr << endl; 910 911 // at last computed priority based on render cost reduction / memory increase 912 const float priority = EvalPriority(splitCandidate, renderCostDecr, oldRenderCost); 767 913 splitCandidate.SetPriority(priority); 768 914 … … 782 928 const int numBackViewCells) //const 783 929 { 784 const float oldPvsSize = (float)numParentViewCells;//CountViewCells(*splitCandidate.mParentData.mSampledObjects); 785 const float oldPvsRatio = (splitCandidate.mParentData.mPvs > 0) ? oldPvsSize / splitCandidate.mParentData.mPvs : 1; 930 const float oldPvsSize = (float)numParentViewCells; 931 const float oldPvsRatio = 932 (splitCandidate.mParentData.mPvs > 0) ? oldPvsSize / splitCandidate.mParentData.mPvs : 1; 786 933 787 934 const float parentPvs = splitCandidate.mParentData.mCorrectedPvs * oldPvsRatio; 788 935 789 const int frontViewCells = numFrontViewCells; //CountViewCells(splitCandidate.mSampledFrontObjects);790 const int backViewCells = numBackViewCells; //CountViewCells(splitCandidate.mSampledBackObjects);936 const int frontViewCells = numFrontViewCells; 937 const int backViewCells = numBackViewCells; 791 938 792 939 splitCandidate.mCorrectedFrontPvs = … … 1036 1183 PrepareLocalSubdivisionCandidates(tData, axis); 1037 1184 1038 const float totalRenderCost = EvalAbsCost(tData.mNode->mObjects);1185 const float totalRenderCost = (float)tData.mNode->mObjects.size(); 1039 1186 float objectsLeft = 0, objectsRight = totalRenderCost; 1040 1187 … … 1088 1235 Intersectable *obj = (*cit).mObject; 1089 1236 1090 #if USE_BETTER_RENDERCOST_EST1091 const float renderCost = ViewCellsManager::EvalRenderCost(obj);1092 1093 objectsLeft += renderCost;1094 objectsRight -= renderCost;1095 1096 const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small));1097 1098 #else1099 1237 ++ objectsLeft; 1100 1238 -- objectsRight; 1101 1239 1102 const bool noValidSplit = !objectsLeft || !objectsRight; 1103 #endif 1240 const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small)); 1104 1241 const AxisAlignedBox3 obox = obj->GetBox(); 1105 1242 … … 1131 1268 const float sum = noValidSplit ? 1e25f : objectsLeft * al + objectsRight * ar; 1132 1269 #endif 1133 /*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=("1134 << lbox.SurfaceArea() << "," << rbox.SurfaceArea() << ")" << endl;1135 cout << "minborder: " << minBorder << " maxborder: " << maxBorder << endl;1136 cout << "cost= " << sum << endl;*/1137 1270 1138 1271 if (sum < minSum) … … 1183 1316 PrepareLocalSubdivisionCandidates(tData, axis); 1184 1317 1185 const float totalRenderCost = EvalAbsCost(tData.mNode->mObjects);1318 const float totalRenderCost = (float)tData.mNode->mObjects.size(); 1186 1319 float objectsLeft = 0, objectsRight = totalRenderCost; 1187 1320 … … 1242 1375 Intersectable *obj = (*cit).mObject; 1243 1376 1244 const float renderCost = ViewCellsManager::EvalRenderCost(obj); 1245 1246 objectsLeft += renderCost; 1247 objectsRight -= renderCost; 1377 objectsLeft ++;; 1378 objectsRight --; 1248 1379 1249 1380 const AxisAlignedBox3 obox = obj->GetBox(); … … 1270 1401 1271 1402 const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small)); 1272 const float sum = noValidSplit ? 1e25 : objectsLeft * al + objectsRight * ar;1403 const float sum = noValidSplit ? 1e25f : objectsLeft * al + objectsRight * ar; 1273 1404 1274 /*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=("1275 << lbox.SurfaceArea() << "," << rbox.SurfaceArea() << ")" << endl;1276 cout << "minborder: " << minBorder << " maxborder: " << maxBorder << endl;1277 cout << "cost= " << sum << endl;*/1278 1279 1405 if (sum < minSum) 1280 1406 { … … 1367 1493 //-- left and right and evaluate the cost funcion 1368 1494 1369 // prepare the heuristics by settingmailboxes and counters1495 // prepare the heuristics, set mailboxes and counters 1370 1496 const float totalVol = PrepareHeuristics(tData, axis); 1371 1497 … … 1374 1500 float volRight = totalVol; 1375 1501 1376 const float nTotalObjects = EvalAbsCost(tData.mNode->mObjects);1502 const float nTotalObjects = (float)tData.mNode->mObjects.size(); 1377 1503 float nObjectsLeft = 0; 1378 1504 float nObjectsRight = nTotalObjects; … … 1419 1545 EvalHeuristicsContribution(object, volLeft, volRight); 1420 1546 1421 #if USE_BETTER_RENDERCOST_EST1422 1423 const float rc = ViewCellsManager::EvalRenderCost(object);1424 1425 nObjectsLeft += rc;1426 nObjectsRight -= rc;1427 1428 #else1429 1547 ++ nObjectsLeft; 1430 1548 -- nObjectsRight; 1431 #endif1432 1549 1433 1550 // split is only valid if #objects on left and right is not zero 1434 1551 const bool noValidSplit = (nObjectsRight <= Limits::Small); 1435 1552 1436 #if BOUND_RENDERCOST1437 1438 const float rcLeft = max(nObjectsLeft, MIN_RENDERCOST);1439 const float rcRight = max(nObjectsRight, MIN_RENDERCOST);1440 1441 // the heuristics1442 const float sum = noValidSplit ?1443 1e25f : volLeft * (float)rcLeft + volRight * (float)rcRight;1444 #else1445 1446 1553 // the heuristics 1447 1554 const float sum = noValidSplit ? 1448 1555 1e25f : volLeft * (float)nObjectsLeft + volRight * (float)nObjectsRight; 1449 #endif 1556 1450 1557 1451 1558 #ifdef GTP_DEBUG … … 1829 1936 #endif 1830 1937 } 1831 1832 1938 } 1833 1939 … … 1887 1993 const float viewSpaceArea = mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 1888 1994 1889 return EvalAbsCost(leaf->mObjects) * area / viewSpaceArea;1995 return (float)leaf->mObjects.size() * area / viewSpaceArea; 1890 1996 } 1891 1997 … … 1896 2002 //-- render cost heuristics 1897 2003 1898 const float objRenderCost = EvalAbsCost(objects);2004 const float objRenderCost = (float)objects.size(); 1899 2005 1900 2006 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); … … 2923 3029 2924 3030 2925 BvhNode *BvHierarchy::SubdivideAndCopy(SplitQueue &tQueue,2926 SubdivisionCandidate *splitCandidate)2927 {2928 BvhSubdivisionCandidate *sc =2929 static_cast<BvhSubdivisionCandidate *>(splitCandidate);2930 BvhTraversalData &tData = sc->mParentData;2931 2932 BvhNode *currentNode = tData.mNode;2933 BvhNode *oldNode = (BvhNode *)splitCandidate->mEvaluationHack;2934 2935 if (!oldNode->IsLeaf())2936 {2937 //////////////2938 //-- continue subdivision2939 2940 BvhTraversalData tFrontData;2941 BvhTraversalData tBackData;2942 2943 BvhInterior *oldInterior = static_cast<BvhInterior *>(oldNode);2944 2945 sc->mFrontObjects.clear();2946 sc->mBackObjects.clear();2947 2948 oldInterior->GetFront()->CollectObjects(sc->mFrontObjects);2949 oldInterior->GetBack()->CollectObjects(sc->mBackObjects);2950 2951 // evaluate the changes in render cost and pvs entries2952 EvalSubdivisionCandidate(*sc, false, true);2953 2954 // create new interior node and two leaf node2955 currentNode = SubdivideNode(*sc, tFrontData, tBackData);2956 2957 //oldNode->mRenderCostDecr += sc->GetRenderCostDecrease();2958 //oldNode->mPvsEntriesIncr += sc->GetPvsEntriesIncr();2959 2960 //oldNode->mRenderCostDecr = sc->GetRenderCostDecrease();2961 //oldNode->mPvsEntriesIncr = sc->GetPvsEntriesIncr();2962 2963 ///////////////////////////2964 //-- push the new split candidates on the queue2965 2966 BvhSubdivisionCandidate *frontCandidate = new BvhSubdivisionCandidate(tFrontData);2967 BvhSubdivisionCandidate *backCandidate = new BvhSubdivisionCandidate(tBackData);2968 2969 frontCandidate->SetPriority((float)-oldInterior->GetFront()->GetTimeStamp());2970 backCandidate->SetPriority((float)-oldInterior->GetBack()->GetTimeStamp());2971 2972 frontCandidate->mEvaluationHack = oldInterior->GetFront();2973 backCandidate->mEvaluationHack = oldInterior->GetBack();2974 2975 // cross reference2976 tFrontData.mNode->SetSubdivisionCandidate(frontCandidate);2977 tBackData.mNode->SetSubdivisionCandidate(backCandidate);2978 2979 //cout << "f: " << frontCandidate->GetPriority() << " b: " << backCandidate->GetPriority() << endl;2980 tQueue.Push(frontCandidate);2981 tQueue.Push(backCandidate);2982 }2983 2984 /////////////////////////////////2985 //-- node is a leaf => terminate traversal2986 2987 if (currentNode->IsLeaf())2988 {2989 // this leaf is no candidate for splitting anymore2990 // => detach subdivision candidate2991 tData.mNode->SetSubdivisionCandidate(NULL);2992 // detach node so we don't delete it with the traversal data2993 tData.mNode = NULL;2994 }2995 2996 return currentNode;2997 }2998 2999 3000 3031 void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, 3001 3032 ObjectContainer &objects) … … 3171 3202 3172 3203 // HACK 3173 float BvHierarchy::GetRenderCostIncrementially(BvhNode *node) const 3174 { 3175 if (node->mRenderCost < 0) // render cost must be evaluated ... 3176 { 3204 float BvHierarchy::GetTriangleSizeIncrementially(BvhNode *node) const 3205 { 3206 if (node->mRenderCost < 0) 3207 { 3208 //cout <<"p"; 3177 3209 if (node->IsLeaf()) 3178 3210 { 3179 3211 BvhLeaf *leaf = static_cast<BvhLeaf *>(node); 3180 node->mRenderCost = EvalAbsCost(leaf->mObjects); 3181 //if (leaf->mObjects.size() < 100) cout <<"p"; 3212 node->mRenderCost = (float)leaf->mObjects.size(); 3182 3213 } 3183 3214 else … … 3185 3216 BvhInterior *interior = static_cast<BvhInterior *>(node); 3186 3217 3187 node->mRenderCost = Get RenderCostIncrementially(interior->GetFront()) +3188 Get RenderCostIncrementially(interior->GetBack());3218 node->mRenderCost = GetTriangleSizeIncrementially(interior->GetFront()) + 3219 GetTriangleSizeIncrementially(interior->GetBack()); 3189 3220 } 3190 3221 } -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
r2255 r2332 52 52 int Nodes() const {return nodes;} 53 53 int Interior() const { return nodes / 2; } 54 int Leaves() const { return (nodes / 2)+ 1; }54 int Leaves() const { return nodes / 2 + 1; } 55 55 56 56 double AvgDepth() const … … 668 668 void StoreSampledObjects(ObjectContainer &sampledObjects, const ObjectContainer &objects); 669 669 670 ///////////////////////////671 // hacks in order to provide interleaved heurisitcs672 673 BvhNode *SubdivideAndCopy(SplitQueue &tQueue, SubdivisionCandidate *splitCandidate);674 675 670 ///////////////////////////////// 676 671 677 static inline float EvalAbsCost(const ObjectContainer &objects);678 679 672 void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects); 680 673 681 float Get RenderCostIncrementially(BvhNode *node) const;674 float GetTriangleSizeIncrementially(BvhNode *node) const; 682 675 683 676 void Compress(); … … 995 988 */ 996 989 void SetUniqueNodeIds(); 990 991 void UpdateViewCells(const BvhSubdivisionCandidate &sc); 992 997 993 998 994 protected: … … 1101 1097 1102 1098 1103 float BvHierarchy::EvalAbsCost(const ObjectContainer &objects) 1104 { 1105 float result; 1106 1107 #if USE_BETTER_RENDERCOST_EST 1108 1109 const float switchcost = 1.0f; 1110 1111 float o = 0; 1112 1113 ObjectContainer::const_iterator oit, oit_end = objects.end(); 1114 1115 for (oit = objects.begin(); oit != oit_end; ++ oit) 1116 { 1117 o += ViewCellsManager::GetRendercost(*oit); 1118 } 1119 1120 float n = (float)objects.size() * switchcost; 1121 1122 #else 1123 1124 result = (float)objects.size(); 1099 1100 } 1125 1101 1126 1102 #endif 1127 1128 #if BOUND_RENDERCOST1129 1130 if (result > MIN_RENDERCOST)1131 return result;1132 else1133 {1134 //std::cout << "b";1135 return MIN_RENDERCOST;1136 }1137 #endif1138 1139 return result;1140 }1141 1142 }1143 1144 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
r2228 r2332 1532 1532 "0.1"); 1533 1533 1534 RegisterOption("ViewCells.triangleWeight", 1535 optFloat, 1536 "view_cells_triangle_weight=", 1537 "1.0"); 1538 1539 RegisterOption("ViewCells.objectWeight", 1540 optFloat, 1541 "view_cells_object_weight=", 1542 "0.0"); 1543 1534 1544 RegisterOption("ViewCells.filename", 1535 1545 optString, -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r2237 r2332 304 304 305 305 306 void HierarchyManager:: EvalSubdivisionStats()306 void HierarchyManager::PrintSubdivisionStats() 307 307 { 308 308 … … 492 492 493 493 // create first nodes 494 mVspTree->Initialise(sampleRays, forcedViewSpace );494 mVspTree->Initialise(sampleRays, forcedViewSpace, objects); 495 495 InitialiseObjectSpaceSubdivision(objects); 496 496 497 497 // hack: assume that object space can be seen from view space 498 mHierarchyStats.mTotalCost = mInitialRenderCost = (float)objects.size(); 498 mHierarchyStats.mTotalCost = mInitialRenderCost = GetViewCellsManager()->ComputeRenderCost(objects.size(), 1); 499 499 500 // only one entry for start 500 501 mHierarchyStats.mPvsEntries = 1; 501 502 mHierarchyStats.mMemory = (float)ObjectPvs::GetEntrySizeByte(); 502 503 503 EvalSubdivisionStats();504 PrintSubdivisionStats(); 504 505 Debug << "setting total cost to " << mHierarchyStats.mTotalCost << endl; 505 506 … … 678 679 mHierarchyStats.mPvsEntries = 1; 679 680 mHierarchyStats.mMemory = (float)ObjectPvs::GetEntrySizeByte(); 680 mHierarchyStats.mTotalCost = (float)objects.size();681 mHierarchyStats.mTotalCost = GetViewCellsManager()->ComputeRenderCost(objects.size(), 1); 681 682 682 683 mHierarchyStats.mRenderCostDecrease = 0; 683 684 684 EvalSubdivisionStats();685 PrintSubdivisionStats(); 685 686 Debug << "setting total cost to " << mHierarchyStats.mTotalCost << endl; 686 687 … … 689 690 690 691 // create only roots 691 mVspTree->Initialise(sampleRays, forcedViewSpace );692 mVspTree->Initialise(sampleRays, forcedViewSpace, objects); 692 693 InitialiseObjectSpaceSubdivision(objects); 693 694 … … 745 746 //-- new stats 746 747 747 mHierarchyStats.mTotalCost = mVspTree->mTotalCost; 748 cout << "\nreseting cost for vsp, new total cost: " << mHierarchyStats.mTotalCost << endl; 748 if (0) 749 { 750 mHierarchyStats.mTotalCost = mVspTree->mTotalCost; 751 cout << "\nreseting cost for vsp construction, new total cost: " << mHierarchyStats.mTotalCost << endl; 752 } 749 753 } 750 754 … … 960 964 961 965 // output stats 962 EvalSubdivisionStats();966 PrintSubdivisionStats(); 963 967 964 968 return true; … … 1223 1227 1224 1228 // evaluate stats before first subdivision 1225 EvalSubdivisionStats();1229 PrintSubdivisionStats(); 1226 1230 cout << "finished bv hierarchy preparation" << endl; 1227 1231 } … … 1241 1245 AxisAlignedBox3 *forcedViewSpace) 1242 1246 { 1243 ViewCellsManager *vm = mVspTree->mViewCellsManager;1247 ViewCellsManager *vm = GetViewCellsManager(); 1244 1248 1245 1249 // HACK: rather not destroy vsp tree … … 1250 1254 mVspTree->mViewCellsManager = vm; 1251 1255 1252 mVspTree->Initialise(sampleRays, forcedViewSpace); 1256 mVspTree->Initialise(sampleRays, forcedViewSpace, objects); 1257 1253 1258 1254 1259 ////////// 1255 1260 //-- reset stats 1261 1256 1262 mHierarchyStats.mNodes = GetObjectSpaceSubdivisionNodes(); 1257 1263 //-mVspTree->mVspStats.nodes + 1; … … 1266 1272 1267 1273 // evaluate new stats before first subdivsiion 1268 EvalSubdivisionStats();1274 PrintSubdivisionStats(); 1269 1275 } 1270 1276 … … 1278 1284 mHierarchyStats.mNodes = 2; 1279 1285 1280 mHierarchyStats.mTotalCost = (float)objects.size();1286 mHierarchyStats.mTotalCost = GetViewCellsManager()->ComputeRenderCost(objects.size(), 1); 1281 1287 Debug << "setting total cost to " << mHierarchyStats.mTotalCost << endl; 1282 1288 … … 1285 1291 1286 1292 // initialise view / object space 1287 mVspTree->Initialise(sampleRays, forcedViewSpace );1293 mVspTree->Initialise(sampleRays, forcedViewSpace, objects); 1288 1294 InitialiseObjectSpaceSubdivision(objects); 1289 1295 … … 1987 1993 1988 1994 void HierarchyManager::ComputePvs(const ObjectPvs &pvs, 1989 float & rc,1995 float &triangles, 1990 1996 int &pvsEntries) 1991 1997 { … … 2026 2032 ObjectContainer objects; 2027 2033 activeNode->CollectObjects(objects); 2028 rc += mBvHierarchy->EvalAbsCost(objects);2034 triangles += (float)objects.size(); 2029 2035 #else 2030 rc += mBvHierarchy->GetRenderCostIncrementially(activeNode);2036 triangles += mBvHierarchy->GetTriangleSizeIncrementially(activeNode); 2031 2037 #endif 2032 2038 ++ pvsEntries; … … 2232 2238 { 2233 2239 ViewCell *vc = *vit; 2234 float rc = 0; 2235 2240 2236 2241 #if STUPID_METHOD 2237 2242 ObjectPvs pvs; … … 2254 2259 vc->Mail(); 2255 2260 2261 float triangles = 0; 2262 int entries = 0; 2263 2256 2264 if (useFilter) 2257 2265 { 2258 2266 const long startT = GetTime(); 2267 2259 2268 ObjectPvs filteredPvs; 2260 mVspTree->mViewCellsManager->ApplyFilter2(vc, false, 1.0f, filteredPvs); 2269 GetViewCellsManager()->ApplyFilter2(vc, false, 1.0f, filteredPvs); 2270 2261 2271 const long endT = GetTime(); 2262 2272 2263 2273 //cout << "filter computed in " << TimeDiff(startT, endT) * 1e-3f << " secs" << endl; 2264 ComputePvs(filteredPvs, rc, pvsEntries); 2274 2275 ComputePvs(filteredPvs, triangles, entries); 2265 2276 } 2266 2277 else 2267 2278 { 2268 ComputePvs(vc->GetPvs(), rc, pvsEntries); 2269 vc->SetPvsCost(rc); 2270 } 2271 2272 rc *= vc->GetVolume(); 2279 ComputePvs(vc->GetPvs(), triangles, entries); 2280 vc->SetPvsCost(triangles); 2281 } 2282 2283 const float rc = GetViewCellsManager()->ComputeRenderCost((int)triangles, entries) * vc->GetVolume(); 2284 2273 2285 renderCost += rc; 2274 } 2275 2276 renderCost /= mVspTree->mViewCellsManager->GetViewSpaceBox().GetVolume(); 2286 pvsEntries += entries; 2287 } 2288 2289 renderCost /= GetViewCellsManager()->GetViewSpaceBox().GetVolume(); 2277 2290 memory = pvsEntries * ObjectPvs::GetEntrySize(); 2278 2291 … … 2297 2310 const string filename = string(statsPrefix) + string(str); 2298 2311 2299 mVspTree->mViewCellsManager->EvalViewCellHistogramForPvsSize(filename, viewCells);2312 GetViewCellsManager()->EvalViewCellHistogramForPvsSize(filename, viewCells); 2300 2313 2301 2314 histoUsed = true; … … 2322 2335 2323 2336 2324 void HierarchyManager::ExportStats(ofstream &stats, 2325 SplitQueue &tQueue, 2326 const ObjectContainer &objects) 2327 { 2328 HierarchySubdivisionStats subStats; 2329 subStats.Reset(); 2330 2331 ///////////// 2332 //-- initial situation 2333 2334 subStats.mNumSplits = 0; 2335 subStats.mTotalRenderCost = (float)objects.size(); 2336 subStats.mEntriesInPvs = 1; 2337 subStats.mMemoryCost = (float)ObjectPvs::GetEntrySize(); 2338 subStats.mFullMemory = subStats.mMemoryCost; 2339 subStats.mViewSpaceSplits = 0; 2340 subStats.mObjectSpaceSplits = 0; 2341 subStats.mRenderCostDecrease = 0; 2342 subStats.Print(stats); 2343 2344 cout << "exporting vsposp stats ... " << endl; 2345 2346 //-- go through tree in the order of render cost decrease 2347 //-- which is the same order as the view cells were merged 2348 //-- or the reverse order of subdivision for subdivision-only 2349 //-- view cell hierarchies. 2350 2351 while (!tQueue.Empty()) 2352 { 2353 SubdivisionCandidate *nextCandidate = NextSubdivisionCandidate(tQueue); 2354 bool isLeaf; 2355 int timeStamp; 2356 //float rcDecr; 2357 //int entriesIncr; 2358 2359 if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 2360 { 2361 timeStamp = (int)-nextCandidate->GetPriority(); 2362 2363 VspNode *newNode = mVspTree->SubdivideAndCopy(tQueue, nextCandidate); 2364 VspNode *oldNode = (VspNode *)nextCandidate->mEvaluationHack; 2365 2366 isLeaf = newNode->IsLeaf(); 2367 //subStats.mRenderCostDecrease = oldNode->mRenderCostDecr; 2368 //entriesIncr = oldNode->mPvsEntriesIncr; 2369 } 2370 else 2371 { 2372 timeStamp = (int)-nextCandidate->GetPriority(); 2373 2374 BvhNode *newNode = mBvHierarchy->SubdivideAndCopy(tQueue, nextCandidate); 2375 BvhNode *oldNode = (BvhNode *)nextCandidate->mEvaluationHack; 2376 2377 isLeaf = newNode->IsLeaf(); 2378 //subStats.mRenderCostDecrease = oldNode->mRenderCostDecr; 2379 //entriesIncr = oldNode->mPvsEntriesIncr; 2380 } 2381 2382 if (!isLeaf) 2383 { 2384 subStats.mTotalRenderCost -= subStats.mRenderCostDecrease; 2385 //subStats.mEntriesInPvs += entriesIncr; 2386 2387 if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE) 2388 { 2389 ++ subStats.mViewSpaceSplits; 2390 //cout << "v"; 2391 //cout << "vsp t: " << timeStamp << " rc: " << rcDecr << " pvs: " << entriesIncr << endl; 2392 } 2393 else 2394 { 2395 ++ subStats.mObjectSpaceSplits; 2396 //cout << "o"; 2397 //"osp t: " << timeStamp << " rc: " << rcDecr << " pvs: " << entriesIncr << endl; 2398 } 2399 2400 ++ subStats.mNumSplits; 2401 2402 if ((subStats.mNumSplits % 500) == 499) 2403 cout << subStats.mNumSplits << " steps taken" << endl; 2404 2405 subStats.mMemoryCost = (float)subStats.mEntriesInPvs * (float)ObjectPvs::GetEntrySize(); 2406 subStats.mFullMemory = subStats.mMemoryCost; 2407 2408 subStats.Print(stats); 2409 2410 } 2411 2412 DEL_PTR(nextCandidate); 2413 } 2414 2415 stats.close(); 2416 } 2417 2418 2419 void HierarchyManager::EvaluateSubdivision(const VssRayContainer &sampleRays, 2420 const ObjectContainer &objects, 2421 const string &filename) 2422 { 2423 #if 0 2424 VspTree *oldVspTree = mVspTree; 2425 ViewCellsManager *vm = mVspTree->mViewCellsManager; 2426 BvHierarchy *oldHierarchy = mBvHierarchy; 2427 2428 mBvHierarchy = new BvHierarchy(); 2429 mBvHierarchy->mHierarchyManager = this; 2430 mBvHierarchy->mViewCellsManager = vm; 2431 2432 mVspTree = new VspTree(); 2433 mVspTree->mHierarchyManager = this; 2434 mVspTree->mViewCellsManager = vm; 2435 2436 // create first nodes 2437 mVspTree->Initialise(sampleRays, &oldVspTree->mBoundingBox); 2438 InitialiseObjectSpaceSubdivision(objects); 2439 2440 const long startTime = GetTime(); 2441 cout << "Constructing evaluation hierarchies ... \n"; 2442 2443 ofstream stats; 2444 stats.open(filename.c_str()); 2445 SplitQueue tQueue; 2446 2447 BvhNode *oldBvhRoot = oldHierarchy->GetRoot(); 2448 VspNode *oldVspRoot = oldVspTree->GetRoot(); 2449 2450 RayInfoContainer *viewSpaceRays = new RayInfoContainer(); 2451 2452 SubdivisionCandidate *firstVsp = mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays); 2453 tQueue.Push(firstVsp); 2454 2455 mBvHierarchy->PrepareConstruction(tQueue, sampleRays, objects); 2456 2457 firstVsp->mEvaluationHack = oldVspRoot; 2458 firstBvh->mEvaluationHack = oldBvhRoot; 2459 2460 firstVsp->SetPriority((float)-oldVspRoot->mTimeStamp); 2461 firstBvh->SetPriority((float)-oldBvhRoot->GetTimeStamp()); 2462 2463 ExportStats(stats, tQueue, objects); 2464 2465 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 2466 RemoveRayRefs(objects); 2467 2468 // view cells needed only for evaluation 2469 ViewCellContainer viewCells; 2470 mVspTree->CollectViewCells(viewCells, false); 2471 2472 // helper trees can be destroyed 2473 DEL_PTR(mVspTree); 2474 DEL_PTR(mBvHierarchy); 2475 2476 CLEAR_CONTAINER(viewCells); 2477 2478 // reset hierarchies 2479 mVspTree = oldVspTree; 2480 mBvHierarchy = oldHierarchy; 2481 2482 // reinstall old bv refs 2483 vector<BvhLeaf *> leaves; 2484 mBvHierarchy->CollectLeaves(mBvHierarchy->GetRoot(), leaves); 2485 vector<BvhLeaf *>::const_iterator bit, bit_end = leaves.end(); 2486 2487 for (bit = leaves.begin(); bit != bit_end; ++ bit) 2488 { 2489 mBvHierarchy->AssociateObjectsWithLeaf(*bit); 2490 } 2491 #endif 2492 } 2493 2494 2495 void HierarchyManager::EvaluateSubdivision2(ofstream &splitsStats, 2496 const int splitsStepSize, 2497 const bool useFilter, 2498 const bool useHisto, 2499 const int histoMem, 2500 const int pass) 2337 2338 void HierarchyManager::EvaluateSubdivision(ofstream &splitsStats, 2339 const int splitsStepSize, 2340 const bool useFilter, 2341 const bool useHisto, 2342 const int histoMem, 2343 const int pass) 2501 2344 { 2502 2345 vector<HierarchySubdivisionStats> subStatsContainer; … … 2645 2488 if (!mTraversalTree) 2646 2489 { 2647 return mVspTree->CastLineSegment(origin, termination, viewcells, useMailboxing);2490 return mVspTree->CastLineSegment(origin, termination, viewcells, useMailboxing); 2648 2491 } 2649 2492 else 2650 2493 { 2651 return mTraversalTree->CastLineSegment(origin,termination, viewcells, useMailboxing); 2652 } 2653 } 2654 2655 2656 } 2494 return mTraversalTree->CastLineSegment(origin, termination, viewcells, useMailboxing); 2495 } 2496 } 2497 2498 2499 ViewCellsManager *HierarchyManager::GetViewCellsManager() 2500 { 2501 return mVspTree->mViewCellsManager; 2502 } 2503 2504 2505 } -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r2237 r2332 294 294 inline bool ConsiderMemory() const { return mConsiderMemory; } 295 295 296 void EvaluateSubdivision(const VssRayContainer &sampleRays, 297 const ObjectContainer &objects, 298 const std::string &filename); 299 300 void EvaluateSubdivision2(std::ofstream &splitsStats, 296 void EvaluateSubdivision(std::ofstream &splitsStats, 301 297 const int splitsStepSize, 302 298 const bool useFilter, … … 409 405 SubdivisionCandidateContainer &dirtyList); 410 406 411 /** Evaluatesubdivision stats for log.412 */ 413 void EvalSubdivisionStats();407 /** Print subdivision stats for log. 408 */ 409 void PrintSubdivisionStats(); 414 410 415 411 void AddSubdivisionStats(const int splits, … … 563 559 bool &histoUsed); 564 560 565 void ComputePvs(const ObjectPvs &pvs, float & rc, int &pvsEntries);561 void ComputePvs(const ObjectPvs &pvs, float &triangles, int &pvsEntries); 566 562 void GetPvsIncrementially(ViewCell *vc, ObjectPvs &pvs) const; 567 563 void PullUpPvsIncrementally(ViewCell *viewCell) const; … … 571 567 float EvalFullMem() const; 572 568 569 ViewCellsManager *GetViewCellsManager(); 573 570 574 571 protected: -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
r2176 r2332 15 15 // $$JB HACK 16 16 #define KD_PVS_AREA (1e-5f) 17 18 #define TYPE_INTERIOR -2 19 #define TYPE_LEAF -3 20 17 21 18 22 namespace GtpVisibilityPreprocessor { … … 1098 1102 } 1099 1103 1100 int1101 KdTree::CollectLeafPvs()1102 {1103 1104 // matt: no more kd pvs1105 int totalPvsSize = 0;1106 /*1107 stack<KdNode *> nodeStack;1108 1109 nodeStack.push(mRoot);1110 1111 while (!nodeStack.empty()) {1112 KdNode *node = nodeStack.top();1113 nodeStack.pop();1114 if (node->IsLeaf()) {1115 KdLeaf *leaf = (KdLeaf *)node;1116 for (int j=0; j < leaf->mObjects.size(); j++) {1117 Intersectable *object = leaf->mObjects[j];1118 if (!object->Mailed()) {1119 object->Mail();1120 // add this node to pvs of all nodes it can see1121 KdPvsMap::iterator ni = object->mKdPvs.mEntries.begin();1122 for (; ni != object->mKdPvs.mEntries.end(); ni++) {1123 KdNode *node = (*ni).first;1124 // $$ JB TEMPORARY solution -> should add object PVS or explictly computed1125 // kd tree PVS1126 float contribution;1127 if (leaf->mKdPvs.AddSample(node, 1.0f, contribution))1128 totalPvsSize++;1129 }1130 }1131 }1132 } else {1133 KdInterior *interior = (KdInterior *)node;1134 nodeStack.push(interior->mFront);1135 nodeStack.push(interior->mBack);1136 }1137 }1138 */1139 return totalPvsSize;1140 }1141 1142 1104 1143 1105 KdNode * … … 1223 1185 1224 1186 1225 #define TYPE_INTERIOR -21226 #define TYPE_LEAF -31227 1228 1229 1187 void KdTree::ExportBinLeaf(OUT_STREAM &stream, KdLeaf *leaf) 1230 1188 { … … 1319 1277 OUT_STREAM stream(filename.c_str(), OUT_BIN_MODE); 1320 1278 1321 //if (!stream.is_open()) return false;1279 if (!stream.is_open()) return false; 1322 1280 1323 1281 // export binary version of mesh … … 1400 1358 DEL_PTR(mRoot); 1401 1359 1402 KdNode *node = LoadNextNode(stream, NULL, objects); 1403 mRoot = node; 1404 1405 tStack.push(TraversalData(node, mBox, 0)); 1360 mRoot = LoadNextNode(stream, NULL, objects); 1361 1362 tStack.push(TraversalData(mRoot, mBox, 0)); 1406 1363 mStat.Reset(); 1407 1364 mStat.nodes = 1; -
GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
r2176 r2332 422 422 ); 423 423 424 int425 CollectLeafPvs();426 427 424 bool ExportBinTree(const std::string &filename); 425 426 /// loads kd tree from disk. note: sorts objects by id 428 427 bool LoadBinTree(const std::string &filename, ObjectContainer &object); 429 428 -
GTP/trunk/Lib/Vis/Preprocessing/src/ObjectPvs.cpp
r2176 r2332 91 91 92 92 leaf->Mail(); 93 return BvHierarchy::EvalAbsCost(leaf->mObjects);93 return (float)leaf->mObjects.size(); 94 94 } 95 95 … … 114 114 115 115 // add #objects exclusivly in this node 116 pvs += BvHierarchy::EvalAbsCost(leaf->mObjects);116 pvs += (float)leaf->mObjects.size(); 117 117 } 118 118 else // traverse tree -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.icproj
r2255 r2332 943 943 RelativePath=".\sparsehash\src\google\sparsehash\densehashtable.h"/> 944 944 <File 945 RelativePath=".\sparsehash\src\windows\hash_fun.h"/> 946 <File 945 947 RelativePath=".\sparsehash\src\google\sparsehash\hash_fun.h"/> 946 <File947 RelativePath=".\sparsehash\src\windows\hash_fun.h"/>948 948 <File 949 949 RelativePath=".\sparsehash\src\windows\hash_map.h"/> -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r2288 r2332 106 106 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 107 107 </Configuration> 108 <Configuration 109 Name="mlrt|Win32" 110 OutputDirectory="$(ConfigurationName)" 111 IntermediateDirectory="$(ConfigurationName)" 112 ConfigurationType="4" 113 CharacterSet="2"> 114 <Tool 115 Name="VCCLCompilerTool" 116 Optimization="2" 117 GlobalOptimizations="FALSE" 118 InlineFunctionExpansion="0" 119 EnableIntrinsicFunctions="FALSE" 120 FavorSizeOrSpeed="1" 121 OmitFramePointers="FALSE" 122 EnableFiberSafeOptimizations="FALSE" 123 OptimizeForProcessor="3" 124 OptimizeForWindowsApplication="TRUE" 125 AdditionalIncludeDirectories="..\include;"$(QTDIR)\include\QtCore";"$(QTDIR)\include\QtGui";"$(QTDIR)\include";"$(QTDIR)\include\QtOpenGl";..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\..\Preprocessing\MultiLevelRayTracing" 126 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL" 127 MinimalRebuild="TRUE" 128 ExceptionHandling="TRUE" 129 RuntimeLibrary="2" 130 DisableLanguageExtensions="FALSE" 131 ForceConformanceInForLoopScope="FALSE" 132 RuntimeTypeInfo="TRUE" 133 UsePrecompiledHeader="0" 134 WarningLevel="2" 135 Detect64BitPortabilityProblems="TRUE" 136 DebugInformationFormat="3"/> 137 <Tool 138 Name="VCCustomBuildTool"/> 139 <Tool 140 Name="VCLibrarianTool"/> 141 <Tool 142 Name="VCMIDLTool"/> 143 <Tool 144 Name="VCPostBuildEventTool"/> 145 <Tool 146 Name="VCPreBuildEventTool"/> 147 <Tool 148 Name="VCPreLinkEventTool"/> 149 <Tool 150 Name="VCResourceCompilerTool"/> 151 <Tool 152 Name="VCWebServiceProxyGeneratorTool"/> 153 <Tool 154 Name="VCXMLDataGeneratorTool"/> 155 <Tool 156 Name="VCManagedWrapperGeneratorTool"/> 157 <Tool 158 Name="VCAuxiliaryManagedWrapperGeneratorTool"/> 159 </Configuration> 108 160 109 <Configuration 161 110 Name="Release_Internal|Win32" … … 224 173 OptimizeForWindowsApplication="TRUE" 225 174 AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing;"$(QTDIR)\include\QtCore";"$(QTDIR)\include\QtGui";"$(QTDIR)\include";"$(QTDIR)\include\QtOpenGl";"$(CG_INC_PATH)";Timer;..\src\sparsehash\src\google\sparsehash;..\src\sparsehash\src\windows;..\src\sparsehash\src\google;..\src\sparsehash\src;..\src\ootl\;..\src\ootl\src\;..\src\ootl\src\cpp;..\src\ootl\src\cpp\include\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;..\src\ootl\src\cpp\include\ootl\mswin" 226 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;USE_QT;USE_HASH_PV ;USE_SSE"175 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;USE_QT;USE_HASH_PV" 227 176 StringPooling="TRUE" 228 177 MinimalRebuild="TRUE" … … 268 217 ConfigurationType="4" 269 218 CharacterSet="2" 270 WholeProgramOptimization=" FALSE">219 WholeProgramOptimization="TRUE"> 271 220 <Tool 272 221 Name="VCCLCompilerTool" … … 282 231 OptimizeForProcessor="1" 283 232 OptimizeForWindowsApplication="TRUE" 284 AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing ;"$(QTDIR)\include\QtCore";"$(QTDIR)\include\QtGui";"$(QTDIR)\include""285 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;NO_QT "233 AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing" 234 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;NO_QT;USE_SSE" 286 235 StringPooling="TRUE" 287 236 MinimalRebuild="TRUE" … … 688 637 Outputs=""/> 689 638 </FileConfiguration> 690 <FileConfiguration 691 Name="mlrt|Win32"> 692 <Tool 693 Name="VCCustomBuildTool" 694 Description="" 695 CommandLine="" 696 Outputs=""/> 697 </FileConfiguration> 639 698 640 <FileConfiguration 699 641 Name="Release_Internal|Win32"> … … 748 690 Outputs=""/> 749 691 </FileConfiguration> 750 <FileConfiguration 751 Name="mlrt|Win32"> 752 <Tool 753 Name="VCCustomBuildTool" 754 Description="" 755 CommandLine="" 756 Outputs=""/> 757 </FileConfiguration> 692 758 693 <FileConfiguration 759 694 Name="Release_Internal|Win32"> … … 1174 1109 </File> 1175 1110 <File 1111 RelativePath=".\sparsehash\src\google\sparsehash\hash_fun.h"> 1112 </File> 1113 <File 1176 1114 RelativePath=".\sparsehash\src\windows\hash_fun.h"> 1177 </File>1178 <File1179 RelativePath=".\sparsehash\src\google\sparsehash\hash_fun.h">1180 1115 </File> 1181 1116 <File -
GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.cpp
r2239 r2332 109 109 110 110 111 112 111 113 void GetRayInfoSets(const RayInfoContainer &sourceRays, 112 114 const int maxSize, -
GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.h
r2239 r2332 120 120 } 121 121 122 123 124 122 #if USE_FIXEDPOINT_T 125 123 float RayInfo::GetMinT () const … … 166 164 } 167 165 #endif 166 167 168 168 169 } 169 170 #endif -
GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
r2288 r2332 38 38 LinkIncremental="2" 39 39 AdditionalLibraryDirectories="..\include;..\src\GL;"..\lib\$(ConfigurationName)";..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib" 40 GenerateDebugInformation=" TRUE"40 GenerateDebugInformation="FALSE" 41 41 ProgramDatabaseFile="$(OutDir)/TestPreprocessor.pdb" 42 42 SubSystem="1" … … 126 126 </Configuration> 127 127 <Configuration 128 Name="mlrt|Win32"129 OutputDirectory="$(ConfigurationName)"130 IntermediateDirectory="$(ConfigurationName)"131 ConfigurationType="1"132 CharacterSet="2">133 <Tool134 Name="VCCLCompilerTool"135 Optimization="2"136 GlobalOptimizations="FALSE"137 FavorSizeOrSpeed="1"138 OptimizeForProcessor="3"139 AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;"$(QTDIR)\include\QtOpenGl";..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\MultiLevelRayTracing"140 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL"141 MinimalRebuild="TRUE"142 RuntimeLibrary="2"143 RuntimeTypeInfo="TRUE"144 UsePrecompiledHeader="0"145 WarningLevel="3"146 Detect64BitPortabilityProblems="TRUE"147 DebugInformationFormat="3"/>148 <Tool149 Name="VCCustomBuildTool"/>150 <Tool151 Name="VCLinkerTool"152 AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib Preprocessor.lib RTWorld.lib RTScene.lib"153 OutputFile="$(OutDir)/Preprocessor.exe"154 LinkIncremental="1"155 AdditionalLibraryDirectories="..\src\mlrt;"$(CG_LIB_PATH)";..\src\GL;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\..\Preprocessing\MultiLevelRayTracing\RTScene\Release;..\..\Preprocessing\MultiLevelRayTracing\RTWorld\Release"156 GenerateDebugInformation="FALSE"157 SubSystem="1"158 OptimizeReferences="2"159 EnableCOMDATFolding="2"160 TargetMachine="1"161 FixedBaseAddress="1"/>162 <Tool163 Name="VCMIDLTool"/>164 <Tool165 Name="VCPostBuildEventTool"/>166 <Tool167 Name="VCPreBuildEventTool"/>168 <Tool169 Name="VCPreLinkEventTool"/>170 <Tool171 Name="VCResourceCompilerTool"/>172 <Tool173 Name="VCWebServiceProxyGeneratorTool"/>174 <Tool175 Name="VCXMLDataGeneratorTool"/>176 <Tool177 Name="VCWebDeploymentTool"/>178 <Tool179 Name="VCManagedWrapperGeneratorTool"/>180 <Tool181 Name="VCAuxiliaryManagedWrapperGeneratorTool"/>182 </Configuration>183 <Configuration184 128 Name="Release Internal|Win32" 185 129 OutputDirectory="..\bin\Release" … … 201 145 OptimizeForWindowsApplication="TRUE" 202 146 AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;"$(QTDIR)\include\QtOpenGl";"$(QTDIR)\include\Qt";"$(QTDIR)\include\QtCore";"$(QTDIR)\include";QtInterface;..\src\sparsehash\src\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;$(NOINHERIT)" 203 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;USE_CG;USE_HASH_PV ;USE_SSE"147 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;USE_CG;USE_HASH_PV" 204 148 StringPooling="TRUE" 205 149 MinimalRebuild="TRUE" … … 269 213 OptimizeForWindowsApplication="TRUE" 270 214 AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;"$(QTDIR)\include\QtOpenGl";"$(QTDIR)\include\Qt";"$(QTDIR)\include\QtCore";"$(QTDIR)\include"" 271 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;NO_QT "215 PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;NO_QT;USE_SSE" 272 216 RuntimeLibrary="2" 273 217 EnableEnhancedInstructionSet="2" … … 285 229 LinkIncremental="1" 286 230 AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release" 287 GenerateDebugInformation=" FALSE"231 GenerateDebugInformation="TRUE" 288 232 SubSystem="1" 289 233 OptimizeReferences="2" -
GTP/trunk/Lib/Vis/Preprocessing/src/Trackball.cpp
r1743 r2332 193 193 * Avoid problems with out-of-control values... 194 194 */ 195 if (t > 1.0 ) t = 1.0;196 if (t < -1.0 ) t = -1.0;197 phi = 2.0 * asin(t);195 if (t > 1.0f) t = 1.0f; 196 if (t < -1.0f) t = -1.0f; 197 phi = 2.0f * asin(t); 198 198 199 199 axis_to_quat(a,phi,q); -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
r2227 r2332 824 824 825 825 obj->Mail(); 826 renderCost + = mViewCellsManager->EvalRenderCost(obj);826 renderCost ++; 827 827 } 828 828 … … 836 836 if (!obj->Mailed()) 837 837 { 838 renderCost + = ViewCellsManager::EvalRenderCost(obj);838 renderCost ++; 839 839 } 840 840 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
r2199 r2332 291 291 } 292 292 293 void SetEntriesInPvs(const int e) { 294 mEntriesInPvs = e; 295 } 296 293 297 float GetPvsCost() const { 294 298 return mPvsCost; 299 } 300 301 int GetEntriesInPvs() const { 302 return mEntriesInPvs; 295 303 } 296 304 … … 324 332 /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves 325 333 float mPvsCost; 326 /** stores number of entries in pvs 327 this variable has the same value as mPvsSize for object pvs, 328 but usually not for kd cell based pvs 329 */ 334 /// stores number of entries in pvs 330 335 int mEntriesInPvs; 331 336 /** if the pvs size scalar (+ entries into pvs) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2280 r2332 166 166 Environment::GetSingleton()->GetStringValue("ViewCells.samplingType", buf); 167 167 168 Environment::GetSingleton()->GetFloatValue("ViewCells.triangleWeight", mTriangleWeight); 169 Environment::GetSingleton()->GetFloatValue("ViewCells.objectWeight", mObjectWeight); 170 168 171 // mix of sampling strategies 169 172 if (1) … … 306 309 Debug << "export pvs for view cells: " << mExportPvs << endl; 307 310 Debug << "use kd pvs " << mUseKdPvs << endl; 311 312 Debug << "triangle weight: " << mTriangleWeight << endl; 313 Debug << "object weight: " << mObjectWeight << endl; 308 314 309 315 Debug << endl; … … 1702 1708 1703 1709 1704 float ViewCellsManager::EvalRenderCost(Intersectable *obj) //const 1705 { 1706 switch (sRenderCostEvaluationType) 1707 { 1708 case PER_OBJECT: 1709 return 1.0f; 1710 1711 case PER_TRIANGLE: 1712 { 1713 return (float)obj->NumberOfFaces(); 1714 } 1715 default: 1716 cout << "default" << endl; 1717 return 1.0f; 1718 } 1719 1720 // should not come here 1721 return 0.0f; 1710 1711 float ViewCellsManager::ComputeRenderCost(const int tri, const int obj) //const 1712 { 1713 return max((float)tri * mTriangleWeight, (float)obj * mObjectWeight); 1722 1714 } 1723 1715 … … 2095 2087 sum += ComputeSampleContribution(*(*it), addContributions, storeViewCells, useHitObjects); 2096 2088 } 2089 2097 2090 } 2098 2091 … … 2792 2785 2793 2786 ++ mSamplesStat.mRays; 2794 2787 2795 2788 if (!ray.mTerminationObject) 2796 2797 2789 return 0.0f; 2790 2798 2791 static Ray hray; 2799 2792 hray.Init(ray); … … 2801 2794 float tmin = 0, tmax = 1.0; 2802 2795 2803 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) { 2804 // cerr<<"ray outside view space box\n"; 2805 return 0; 2796 if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax)) 2797 { 2798 // cerr<<"ray outside view space box\n"; 2799 return 0; 2806 2800 } 2807 2801 2808 2802 Vector3 origin = hray.Extrap(tmin); 2809 2803 Vector3 termination = hray.Extrap(tmax); 2810 2804 2811 2805 ViewCell::NewMail(); 2812 2806 2813 2807 viewCellCastTimer.Entry(); 2814 2808 2815 2809 static ViewCellContainer viewCells; 2816 2810 static VssRay *lastVssRay = NULL; 2817 2811 2818 2812 // check if last ray was not same ray with reverse direction 2819 2813 if (1) … … 2824 2818 { 2825 2819 viewCells.clear(); 2826 2820 2827 2821 // traverse the view space subdivision 2828 2822 CastLineSegment(origin, termination, viewCells); 2829 2823 2830 2831 } 2832 2824 lastVssRay = &ray; 2825 } 2826 2833 2827 viewCellCastTimer.Exit(); 2834 2828 … … 2837 2831 if (storeViewCells) 2838 2832 { 2839 2840 2833 // cerr << "Store viewcells should not be used in the test!" << endl; 2834 // copy viewcells memory efficiently 2841 2835 #if VSS_STORE_VIEWCELLS 2842 2843 2836 ray.mViewCells.reserve(viewCells.size()); 2837 ray.mViewCells = viewCells; 2844 2838 #else 2845 2846 2839 cerr << "Vss store viewcells not supported." << endl; 2840 exit(1); 2847 2841 #endif 2848 2842 } 2849 2843 2850 2844 Intersectable *terminationObj; 2851 2845 2852 2846 objTimer.Entry(); 2853 2847 2854 2848 // obtain pvs entry (can be different from hit object) 2855 2849 terminationObj = ray.mTerminationObject; 2856 2850 2857 2851 objTimer.Exit(); 2858 2852 2859 2853 pvsTimer.Entry(); 2860 2854 … … 2864 2858 { 2865 2859 ComputeViewCellContribution(*it, 2866 2860 ray, 2867 2861 terminationObj, 2868 2862 ray.mTermination, … … 2875 2869 if (ray.mPvsContribution) 2876 2870 ++ mSamplesStat.mContributingRays; 2877 2871 2878 2872 #if AVG_RAY_CONTRIBUTIONS 2879 2873 ray.mRelativePvsContribution /= (float)viewCells.size(); 2880 2874 #endif 2881 2875 2882 2876 #if USE_RAY_LENGTH_AS_CONTRIBUTION 2883 2877 float c = 0.0f; 2884 2878 if (terminationObj) 2885 2879 c = ray.Length(); 2886 2880 ray.mRelativePvsContribution = ray.mPvsContribution = c; 2887 2881 return c; 2888 2882 #else 2889 2883 return ABS_CONTRIBUTION_WEIGHT*ray.mPvsContribution + 2890 2884 (1.0f - ABS_CONTRIBUTION_WEIGHT)*ray.mRelativePvsContribution; 2891 2885 #endif 2892 2886 } … … 6898 6892 6899 6893 ofstream ofstr(filename.c_str()); 6900 mHierarchyManager->EvaluateSubdivision 2(ofstr, splitsStepSize, false, useHisto, histoMem, pass);6894 mHierarchyManager->EvaluateSubdivision(ofstr, splitsStepSize, false, useHisto, histoMem, pass); 6901 6895 6902 6896 timeDiff = TimeDiff(startTime, GetTime()); … … 7000 6994 7001 6995 7002 } 6996 #if TEST_PACKETS 6997 #ifdef USE_SSE 6998 6999 float ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 7000 const bool addContributions, 7001 const bool storeViewCells, 7002 const bool useHitObjects) 7003 { 7004 float sum = 0.0f; 7005 7006 VssRayContainer::const_iterator it, it_end = rays.end(); 7007 7008 VssRayContainer tmpRays; 7009 RayPacket packet; 7010 7011 for (it = rays.begin(); it != it_end; ++ it) 7012 { 7013 if (!ViewCellsConstructed()) 7014 { 7015 // view cells not yet constructed 7016 // just take the lenghts of the rays as contributions 7017 if ((*it)->mTerminationObject) 7018 { 7019 sum += (*it)->Length(); 7020 } 7021 } 7022 else 7023 { 7024 sum += ComputeSampleContribution(*(*it), addContributions, storeViewCells, useHitObjects); 7025 7026 tmpRays.push_back(new VssRay(*it)); 7027 7028 if (tmpRays.size() == 4) 7029 { 7030 RayPacket packet(tmpRays); 7031 7032 mHierarchyManager->CastLineSegment(packet); 7033 7034 for (int i = 0; i < 4; ++ i) 7035 { 7036 ComputeSampleContribution(tmpRays[i], addContributions, true, useHitObjects); 7037 } 7038 7039 // compare results 7040 ////////// 7041 7042 CLEAR_CONTAINER(tmpRays); 7043 } 7044 } 7045 } 7046 7047 cout << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 7048 Debug << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl; 7049 7050 cout << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 7051 Debug << "pvs time: " << pvsTimer.TotalTime() << " s" << endl; 7052 7053 return sum; 7054 } 7055 7056 #endif 7057 #endif 7058 7059 } -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r2232 r2332 8 8 #include "ViewCell.h" 9 9 10 #define TEST_PACKETS 0 10 11 11 12 namespace GtpVisibilityPreprocessor { … … 162 163 @param storeViewCells true if view cells should be stored in the ray 163 164 */ 164 float ComputeSampleContributions(const VssRayContainer &rays,165 166 const bool storeViewCells,167 const bool useHitObject = false);165 virtual float ComputeSampleContributions(const VssRayContainer &rays, 166 const bool addContributions, 167 const bool storeViewCells, 168 const bool useHitObject = false); 168 169 169 170 /** Computes sample contribution of a simgle ray to the view cells PVS. … … 495 496 ViewCellContainer &viewCells); 496 497 497 /** Evaluates the render cost of a view cell. 498 */ 499 static float EvalRenderCost(Intersectable *obj); 500 498 float ComputeRenderCost(const int tri, const int obj); //const 499 501 500 /** Sets pvs size of view cell as a scalar. Used when storing pvs only in the leaves 502 501 of the hierarchy. … … 906 905 bool mUsePredefinedViewCells; 907 906 908 909 vector<PerViewCellStat> mPerViewCellStat; 910 SamplesStatistics mSamplesStat; 907 float mTriangleWeight; 908 float mObjectWeight; 909 910 vector<PerViewCellStat> mPerViewCellStat; 911 SamplesStatistics mSamplesStat; 911 912 }; 912 913 … … 1299 1300 virtual void FinalizeViewCells(const bool createMesh); 1300 1301 1302 #if TEST_PACKETS 1303 #ifdef USE_SSE 1304 1305 float ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays, 1306 const bool addContributions, 1307 const bool storeViewCells, 1308 const bool useHitObjects); 1309 1310 #endif 1311 #endif 1312 1301 1313 protected: 1302 1314 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r2176 r2332 963 963 DEL_PTR(vc); 964 964 965 //(*vit).second = bspVc;965 //(*vit).second = bspVc; 966 966 (*vit) = bspVc; 967 967 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
r2288 r2332 59 59 } 60 60 61 #if WORK_WITH_VIEWCELLS62 static bool ViewCellHasMultipleReferences(Intersectable *obj,63 ViewCell *vc,64 bool checkOnlyMailed)65 {66 MailablePvsData *vdata = obj->mViewCellPvs.Find(vc);67 68 if (vdata)69 {70 // more than one view cell sees this object inside different kd cells71 if (!checkOnlyMailed || !vdata->Mailed())72 {73 if (checkOnlyMailed)74 vdata->Mail();75 //Debug << "sumpdf: " << vdata->mSumPdf << endl;76 if (vdata->mSumPdf > 1.5f)77 return true;78 }79 }80 81 return false;82 }83 84 85 void VspTree::RemoveParentViewCellReferences(ViewCell *parent) const86 {87 KdLeaf::NewMail();88 89 // remove the parents from the object pvss90 ObjectPvsEntries::const_iterator oit, oit_end = parent->GetPvs().mEntries.end();91 92 for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)93 {94 Intersectable *object = (*oit).first;95 // HACK: make sure that the view cell is removed from the pvs96 const float high_contri = 9999999;97 98 // remove reference count of view cells99 object->mViewCellPvs.RemoveSample(parent, high_contri);100 }101 }102 103 104 void VspTree::AddViewCellReferences(ViewCell *vc) const105 {106 KdLeaf::NewMail();107 108 // Add front view cell to the object pvsss109 ObjectPvsEntries::const_iterator oit, oit_end = vc->GetPvs().mEntries.end();110 111 for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)112 {113 Intersectable *object = (*oit).first;114 115 // increase reference count of view cells116 object->mViewCellPvs.AddSample(vc, 1);117 }118 }119 120 #endif121 61 122 62 void VspTreeStatistics::Print(ostream &app) const … … 185 125 mTreeValid(true), 186 126 mTimeStamp(0) 187 //,mRenderCostDecr(0)188 //,mMemoryIncr(0)189 //,mPvsEntriesIncr(0)190 127 {} 191 128 … … 194 131 mParent(parent), 195 132 mTreeValid(true), 196 //,mMemoryIncr(0)197 //,mRenderCostDecr(0)198 //,mPvsEntriesIncr(0)199 133 mTimeStamp(0) 200 134 {} … … 602 536 603 537 604 void VspTree::CreateViewCell(VspTraversalData &tData, const bool updatePvs) 538 void VspTree::CreateViewCell(VspTraversalData &tData, 539 const bool updatePvs, 540 const float renderCost, 541 const int pvs) 605 542 { 606 543 /////////////// … … 628 565 mVspStats.contributingSamples += conSamp; 629 566 mVspStats.sampleContributions += (int)sampCon; 567 } 568 else 569 { 570 // todo: set correct scalars 571 viewCell->SetPvsCost(renderCost); 572 viewCell->SetEntriesInPvs(pvs); 573 //cout << "create view cell with tri=" << (int)renderCost << " pvs=" << pvs << endl; 630 574 } 631 575 … … 802 746 VspLeaf *leaf = static_cast<VspLeaf *>(splitCandidate.mParentData.mNode); 803 747 804 748 ////////////// 805 749 //-- compute global decrease in render cost 806 750 … … 810 754 811 755 float frontRenderCost = 0, backRenderCost = 0, totalRenderCost = 0; 812 int frontSize = 0, backSize = 0, totalSize = 0; 756 float frontTriangles = 0, backTriangles = 0, totalTriangles = 0; 757 int frontObjects = 0, backObjects = 0, totalObjects = 0; 813 758 814 759 Intersectable::NewMail(3); … … 827 772 828 773 VssRay *ray = rayInf.mRay; 774 829 775 #if HACK_PERFORMANCE 830 776 Intersectable *obj = (*ray).mTerminationObject; … … 835 781 // and back pvs with respect to the classification 836 782 UpdateContributionsToPvs(leaf, cf, 837 front RenderCost, backRenderCost, totalRenderCost,838 front Size, backSize, totalSize);783 frontTriangles, backTriangles, totalTriangles, 784 frontObjects, backObjects, totalObjects); 839 785 840 786 #if COUNT_ORIGIN_OBJECTS … … 847 793 848 794 UpdateContributionsToPvs(leaf, cf, 849 front RenderCost, backRenderCost, totalRenderCost,850 front Size, backSize, totalSize);795 frontTriangles, backTriangles, totalTriangles, 796 frontObjects, backObjects, totalObjects); 851 797 } 852 798 #endif … … 857 803 } 858 804 805 totalRenderCost = mViewCellsManager->ComputeRenderCost((int)totalTriangles, totalObjects); 806 backRenderCost = mViewCellsManager->ComputeRenderCost((int)backTriangles, backObjects); 807 frontRenderCost = mViewCellsManager->ComputeRenderCost((int)frontTriangles, frontObjects); 808 809 859 810 ///////////// 860 811 // avg ray contri 861 812 862 const float avgRayContri = (float)total Size/813 const float avgRayContri = (float)totalObjects / 863 814 ((float)splitCandidate.mParentData.mRays->size() + Limits::Small); 864 815 … … 866 817 867 818 const float avgRaysPerObject = 868 (float)splitCandidate.mParentData.mRays->size() / ((float)total Size+ Limits::Small);819 (float)splitCandidate.mParentData.mRays->size() / ((float)totalTriangles + Limits::Small); 869 820 870 821 splitCandidate.SetAvgRayContribution(avgRayContri); … … 872 823 873 824 825 // todo: compute old render cost in the function 826 // using michi's render cost evaluation 874 827 float oldRenderCost; 875 const float renderCostDecr = EvalRenderCostDecrease(splitCandidate, oldRenderCost, 876 totalRenderCost, frontRenderCost, backRenderCost); 828 const float renderCostDecr = EvalRenderCostDecrease(splitCandidate, 829 oldRenderCost, 830 totalRenderCost, 831 frontRenderCost, 832 backRenderCost); 833 877 834 splitCandidate.SetRenderCostDecrease(renderCostDecr); 878 835 879 836 // the increase in pvs entries num induced by this split 880 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, total Size, frontSize, backSize);837 const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate, totalObjects, frontObjects, backObjects); 881 838 splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr); 882 839 840 splitCandidate.mFrontTriangles = frontTriangles; 841 splitCandidate.mBackTriangles = backTriangles; 842 883 843 // take render cost of node into account 884 844 // otherwise danger of being stuck in a local minimum! … … 894 854 splitCandidate.SetPriority(priority); 895 855 856 //cout << "vsp render cost decrease=" << renderCostDecr<<endl; 896 857 mEvalTimer.Exit(); 897 858 } … … 958 919 959 920 //-- compute pvs 960 frontData.mPvs = sc.mFrontPvs; //(float)EvalPvsEntriesSize(*frontData.mRays);961 backData.mPvs = sc.mBackPvs; //(float)EvalPvsEntriesSize(*backData.mRays);921 frontData.mPvs = sc.mFrontPvs; 922 backData.mPvs = sc.mBackPvs; 962 923 963 924 //-- compute pvs correction for coping with undersampling … … 975 936 976 937 //-- compute render cost 977 frontData.mRenderCost = sc.mFrontRenderCost; //(float)EvalPvsCost(*frontData.mRays);978 backData.mRenderCost = sc.mBackRenderCost; //(float)EvalPvsCost(*backData.mRays);938 frontData.mRenderCost = sc.mFrontRenderCost; 939 backData.mRenderCost = sc.mBackRenderCost; 979 940 980 941 frontData.mCorrectedRenderCost = sc.mCorrectedFrontRenderCost; … … 1006 967 parent->ReplaceChildLink(leaf, interior); 1007 968 interior->SetParent(parent); 1008 1009 #if WORK_WITH_VIEWCELLS1010 // remove "parent" view cell from pvs of all objects (traverse through rays)1011 RemoveParentViewCellReferences(tData.mNode->GetViewCell());1012 #endif1013 969 } 1014 970 else // new root … … 1031 987 1032 988 // create front and back view cell for the new leaves 1033 CreateViewCell(frontData, false );1034 CreateViewCell(backData, false );989 CreateViewCell(frontData, false, sc.mFrontTriangles, (int)sc.mFrontPvs); 990 CreateViewCell(backData, false, sc.mBackTriangles, (int)sc.mBackPvs); 1035 991 1036 992 // set the time stamp so the order of traversal can be reconstructed … … 1444 1400 1445 1401 const int leaves = mVspStats.Leaves(); 1446 const bool showViz = (leaves % 30== 0);1402 const bool showViz = (leaves >= 3000) && (leaves % 497 == 0); 1447 1403 1448 1404 if (showViz) … … 1685 1641 1686 1642 const AxisAlignedPlane &candidatePlane = sc.mSplitPlane; 1687 //const float avgRayContri = sc.GetAvgRayContribution();1688 1643 const float avgRaysPerObject = sc.GetAvgRaysPerObject(); 1689 1644 1690 ///////////////////////// /////////////////////1645 ///////////////////////// 1691 1646 // mark objects in the front / back / both using mailboxing 1692 1647 // then count pvs sizes … … 1713 1668 1714 1669 const float oldRenderCostRatio = (tData.mRenderCost > 0)? (totalPvs / tData.mRenderCost) : 1; 1715 1716 1670 const float penaltyOld = tData.mCorrectedRenderCost * oldRenderCostRatio; 1717 1671 … … 1731 1685 // the render cost decrase for this split 1732 1686 const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol; 1733 1734 if (0)1735 cout << "vsp render cost"1736 << " avg rays per object: " << avgRaysPerObject << " ratio: " << oldRenderCostRatio1737 << " parent: " << penaltyOld << " " << " old vol: " << totalPvs1738 << " front cost: " << sc.mCorrectedFrontRenderCost << " corr. " << sc.mCorrectedFrontRenderCost1739 << " back cost: " << sc.mCorrectedBackRenderCost << " corr. " << sc.mCorrectedBackRenderCost << endl;1740 1741 #ifdef GTP_DEBUG1742 Debug << "\nvsp render cost decrease" << endl1743 << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl1744 << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << " p: " << pOverall / viewSpaceVol << endl1745 << "old rc: " << normalizedOldRenderCost << " new rc: " << newRenderCost / viewSpaceVol << endl1746 << "render cost decrease: " << renderCostDecrease << endl;1747 #endif1748 1687 1749 1688 return renderCostDecrease; … … 1809 1748 if (!obj) return; 1810 1749 1811 const float renderCost = ViewCellsManager::EvalRenderCost(obj);1812 1813 1750 // object in none of the pvss => new object 1814 1751 if (!obj->Mailed() && !obj->Mailed(1) && !obj->Mailed(2)) 1815 1752 { 1816 totalPvs += renderCost;1753 totalPvs += 1.0f; 1817 1754 } 1818 1755 … … 1824 1761 if (!obj->Mailed() && !obj->Mailed(2)) 1825 1762 { 1826 frontPvs += renderCost;1763 frontPvs += 1.0f; 1827 1764 1828 1765 // already in back pvs => in both pvss … … 1838 1775 if (!obj->Mailed(1) && !obj->Mailed(2)) 1839 1776 { 1840 backPvs += renderCost;1777 backPvs += 1.0f; 1841 1778 1842 1779 // already in front pvs => in both pvss … … 1860 1797 1861 1798 const float renderCost = countEntries ? 1 : 1862 mBvHierarchy->EvalAbsCost(leaf->mObjects);1799 (float)leaf->mObjects.size(); 1863 1800 1864 1801 // leaf in no pvs => new … … 1907 1844 int &totalSize) const 1908 1845 { 1909 const float renderCost = mBvHierarchy->EvalAbsCost(leaf->mObjects);1910 1911 // leaf in no pvs =>new1846 const float triSize = (float)leaf->mObjects.size(); 1847 1848 // object in no pvs => count as new 1912 1849 if (!leaf->Mailed() && !leaf->Mailed(1) && !leaf->Mailed(2)) 1913 1850 { 1914 totalPvs += renderCost;1851 totalPvs += triSize; 1915 1852 ++ totalSize; 1916 1853 } … … 1920 1857 if (!leaf->Mailed() && !leaf->Mailed(2)) 1921 1858 { 1922 frontPvs += renderCost;1859 frontPvs += triSize; 1923 1860 ++ frontSize; 1924 1861 … … 1935 1872 if (!leaf->Mailed(1) && !leaf->Mailed(2)) 1936 1873 { 1937 backPvs += renderCost;1874 backPvs += triSize; 1938 1875 ++ backSize; 1939 1876 … … 2569 2506 // cases N1,N2,N3,P5,Z2,Z3 2570 2507 continue; 2571 } else 2508 } 2509 else 2572 2510 { 2573 2511 // case N4 … … 2639 2577 return hits; 2640 2578 } 2579 2580 2581 #ifdef USE_SSE 2582 int VspTree::TraverseRayPacket(RayPacket &rp, 2583 const bool useMailboxing) 2584 { 2585 int hits = 0; 2586 2587 // reciprocal of ray directions 2588 float one = 1.0f; 2589 float zero = 0.0f; 2590 2591 __m128 one4 = _mm_load_ps(&one); 2592 __m128 zero4 = _mm_load_ps(&zero); 2593 2594 __m128 *entp4; 2595 __m128 *extp4; 2596 2597 union { float mask[4]; __m128 mask4; }; 2598 mask4 = one4; 2599 2600 __m128 entpX4 = rp.mOriginX4; 2601 __m128 entpY4 = rp.mOriginY4; 2602 __m128 entpZ4 = rp.mOriginZ4; 2603 2604 __m128 extpX4 = rp.mTerminationX4; 2605 __m128 extpY4 = rp.mTerminationY4; 2606 __m128 extpZ4 = rp.mTerminationZ4; 2607 2608 __m128 *origin = &rp.mOriginX4; 2609 __m128 *termination = &rp.mTerminationX4; 2610 2611 // ray directions 2612 __m128 dirX4 = _mm_sub_ps(rp.mTerminationX4, rp.mOriginX4); 2613 __m128 dirY4 = _mm_sub_ps(rp.mTerminationY4, rp.mOriginY4);; 2614 __m128 dirZ4 = _mm_sub_ps(rp.mTerminationZ4, rp.mOriginZ4);; 2615 2616 __m128 rdx4 = _mm_div_ps(one4, dirX4); 2617 __m128 rdy4 = _mm_div_ps(one4, dirY4); 2618 __m128 rdz4 = _mm_div_ps(one4, dirZ4); 2619 2620 __m128 maxT4 = one4; 2621 __m128 minT4 = zero4; 2622 2623 stack<PacketTraversalData *> tStack; 2624 2625 2626 VspNode *node = mRoot; 2627 VspNode *farChild; 2628 2629 float position; 2630 int axis; 2631 2632 __m128 position4; 2633 2634 while (1) 2635 { 2636 if (!node->IsLeaf()) 2637 { 2638 VspInterior *in = static_cast<VspInterior *>(node); 2639 2640 entp4 = &entpX4; 2641 extp4 = &extpX4; 2642 2643 position = in->GetPosition(); 2644 axis = in->GetAxis(); 2645 2646 position4 = _mm_load_ps(&position); 2647 2648 // are the entry points all in near leaf? 2649 if (_mm_movemask_ps(_mm_and_ps(_mm_cmple_ps(entp4[axis], position4), mask4))) 2650 { 2651 // are the exit points all in near leaf? 2652 if (_mm_movemask_ps(_mm_and_ps(_mm_cmpgt_ps(extp4[axis], position4), mask4))) 2653 { 2654 node = in->GetBack(); 2655 // cases N1,N2,N3,P5,Z2,Z3 2656 continue; 2657 } 2658 else // traverse both children 2659 { 2660 // case N4 2661 node = in->GetBack(); 2662 farChild = in->GetFront(); 2663 } 2664 } 2665 else 2666 { 2667 if (_mm_movemask_ps(_mm_and_ps(_mm_cmpgt_ps(position4, extp4[axis]), mask4))) 2668 { 2669 node = in->GetFront(); 2670 // cases P1,P2,P3,N5,Z1 2671 continue; 2672 } 2673 else // traverse both children 2674 { 2675 node = in->GetFront(); 2676 farChild = in->GetBack(); 2677 // case P4 2678 } 2679 } 2680 2681 // $$ modification 3.5.2004 - hints from Kamil Ghais 2682 // case N4 or P4 2683 const __m128 tDist4 = _mm_mul_ps(_mm_sub_ps(position4, origin[axis]), termination[axis]); 2684 2685 // push far child for further processing 2686 tStack.push(new PacketTraversalData(farChild, extpX4, extpY4, extpZ4, maxT4, mask4)); 2687 2688 // compute new exit point 2689 extpX4 = _mm_add_ps(_mm_mul_ps(dirX4, tDist4), rp.mOriginX4); 2690 extpY4 = _mm_add_ps(_mm_mul_ps(dirY4, tDist4), rp.mOriginY4); 2691 extpZ4 = _mm_add_ps(_mm_mul_ps(dirZ4, tDist4), rp.mOriginZ4); 2692 2693 maxT4 = tDist4; 2694 2695 mask4 = _mm_cmplt_ps( maxT4, minT4); 2696 } 2697 else 2698 { 2699 // compute intersection with all objects in this leaf 2700 VspLeaf *leaf = static_cast<VspLeaf *>(node); 2701 ViewCell *viewCell; 2702 2703 viewCell = leaf->GetViewCell(); 2704 2705 // note: don't have to mail if each view 2706 // cell belongs to exactly one leaf 2707 if (!useMailboxing || !viewCell->Mailed()) 2708 { 2709 if (useMailboxing) 2710 viewCell->Mail(); 2711 2712 for (int i = 0; i < 4; ++i) 2713 { 2714 if (mask[i]) 2715 rp.mViewCells[i].push_back(viewCell); 2716 } 2717 2718 ++ hits; 2719 } 2720 2721 // get the next node from the stack 2722 if (tStack.empty()) 2723 break; 2724 2725 entpX4 = extpX4; 2726 entpY4 = extpY4; 2727 entpZ4 = extpZ4; 2728 2729 minT4 = maxT4; 2730 2731 PacketTraversalData *s = tStack.top(); 2732 node = s->mNode; 2733 2734 extpX4 = s->mExitPointX4; 2735 extpY4 = s->mExitPointY4; 2736 extpZ4 = s->mExitPointZ4; 2737 2738 maxT4 = s->mMaxT4; 2739 2740 mask4 = s->mMask4; 2741 2742 tStack.pop(); 2743 delete s; 2744 } 2745 } 2746 2747 return hits; 2748 2749 /* 2750 const int offs[4] = {(rp.dx[0] >= 0) ? 1 : 0, (rp.dy[0] >= 0)? 1 : 0, (rp.dz[0] >= 0)? 1 : 0, 0}; 2751 2752 while (!node->IsLeaf()) 2753 { 2754 PacketTraversalData *tData = tStack.top(); 2755 tStack.pop(); 2756 2757 node = tData->node; 2758 VspInterior *interior = static_cast<VspInterior *>(node); 2759 tn4 = tData->tn4; 2760 tf4 = tData->tf4; 2761 mask = tData->mask4; 2762 2763 position = interior->GetPosition(); 2764 const __m128 position4 = _mm_load_ps(&pos); 2765 2766 const int axis = interior->GetAxis(); 2767 const __m128 d4 = _mm_mul_ps(_mm_sub_ps(splitPos, origin[axis]), termination[axis]); 2768 2769 VspNode* ln = offs[axis] ? interior->GetFront() : interior->GetBack(); 2770 2771 if (!_mm_movemask_ps(_mm_and_ps(_mm_cmpgt_ps(d4, tn4), mask))) 2772 { 2773 node = ln; 2774 continue; 2775 } 2776 2777 node = offs[axis]^1 ? interior->GetFront() : interior->GetBack();// + (offs[aidx]^1); 2778 2779 if (_mm_movemask_ps( _mm_and_ps( _mm_cmplt_ps(d4, tf4), mask))) 2780 { 2781 const __m128 mask2 = _mm_cmpgt_ps(d4, tn4); 2782 const __m128 mask3 = _mm_cmplt_ps(d4, tf4); 2783 2784 2785 tData->tf4 = tf4 = _mm_or_ps(_mm_and_ps(mask3, d4), _mm_andnot_ps( mask3, tf4)); 2786 tData->node = (VspNode *)ln; 2787 tData->mask4 = mask; 2788 tData->tn4 = _mm_or_ps( _mm_and_ps( mask2, d4 ), _mm_andnot_ps( mask2, tn4 ) ); 2789 mask = _mm_cmplt_ps( tn4, tf4 ); 2790 } 2791 }*/ 2792 } 2793 #endif 2641 2794 2642 2795 … … 3057 3210 else 3058 3211 { 3059 //cout << " o";3212 //cout << "r"; 3060 3213 // store object only for one ray 3061 3214 //lastVssRay->mOriginObject = ray->mTerminationObject; … … 3091 3244 3092 3245 void VspTree::Initialise(const VssRayContainer &rays, 3093 AxisAlignedBox3 *forcedBoundingBox) 3246 AxisAlignedBox3 *forcedBoundingBox, 3247 const ObjectContainer &objects) 3094 3248 { 3095 3249 ComputeBoundingBox(rays, forcedBoundingBox); … … 3100 3254 VspViewCell *viewCell = new VspViewCell(); 3101 3255 leaf->SetViewCell(viewCell); 3256 3257 viewCell->SetPvsCost((float)objects.size()); 3258 viewCell->SetEntriesInPvs(1); 3102 3259 3103 3260 // set view cell values … … 3276 3433 // simple render cost evaluation 3277 3434 if (-- leaf->mCounter == 0) 3278 return BvHierarchy::EvalAbsCost(leaf->mObjects);3435 return (float)leaf->mObjects.size(); 3279 3436 else 3280 3437 return 0.0f; … … 3341 3498 leaf->Mail(); 3342 3499 leaf->mCounter = 1; 3343 return BvHierarchy::EvalAbsCost(leaf->mObjects);3500 return (float)leaf->mObjects.size(); 3344 3501 } 3345 3502 else … … 3418 3575 { 3419 3576 leaf->Mail(); 3420 return BvHierarchy::EvalAbsCost(leaf->mObjects);3577 return (float)leaf->mObjects.size(); 3421 3578 } 3422 3579 else … … 3576 3733 { 3577 3734 leaf->Mail(); 3578 return BvHierarchy::EvalAbsCost(leaf->mObjects);3735 return (float)leaf->mObjects.size(); 3579 3736 } 3580 3737 else … … 3655 3812 3656 3813 return pvs; 3657 }3658 3659 3660 VspNode *VspTree::SubdivideAndCopy(SplitQueue &tQueue,3661 SubdivisionCandidate *splitCandidate)3662 {3663 // todo remove dynamic cast3664 VspSubdivisionCandidate *sc = static_cast<VspSubdivisionCandidate *>(splitCandidate);3665 3666 VspTraversalData &tData = sc->mParentData;3667 VspNode *newNode = tData.mNode;3668 VspNode *oldNode = (VspNode *)splitCandidate->mEvaluationHack;3669 3670 if (!oldNode->IsLeaf())3671 {3672 ///////////3673 //-- continue subdivision3674 3675 VspTraversalData tFrontData;3676 VspTraversalData tBackData;3677 3678 VspInterior *oldInterior = static_cast<VspInterior *>(oldNode);3679 3680 // create new interior node and two leaf node3681 const AxisAlignedPlane splitPlane = oldInterior->GetPlane();3682 sc->mSplitPlane = splitPlane;3683 3684 // evaluate the changes in render cost and pvs entries3685 EvalSubdivisionCandidate(*sc, false);3686 3687 newNode = SubdivideNode(*sc, tFrontData, tBackData);3688 3689 //oldNode->mRenderCostDecr += sc->GetRenderCostDecrease();3690 //oldNode->mPvsEntriesIncr += sc->GetPvsEntriesIncr();3691 3692 //oldNode->mRenderCostDecr = sc->GetRenderCostDecrease();3693 //oldNode->mPvsEntriesIncr = sc->GetPvsEntriesIncr();3694 3695 /////////////3696 //-- evaluate new split candidates for global greedy cost heuristics3697 3698 VspSubdivisionCandidate *frontCandidate = new VspSubdivisionCandidate(tFrontData);3699 VspSubdivisionCandidate *backCandidate = new VspSubdivisionCandidate(tBackData);3700 3701 frontCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp);3702 backCandidate->SetPriority((float)-oldInterior->GetBack()->mTimeStamp);3703 3704 frontCandidate->mEvaluationHack = oldInterior->GetFront();3705 backCandidate->mEvaluationHack = oldInterior->GetBack();3706 3707 // cross reference3708 tFrontData.mNode->SetSubdivisionCandidate(frontCandidate);3709 tBackData.mNode->SetSubdivisionCandidate(backCandidate);3710 3711 tQueue.Push(frontCandidate);3712 tQueue.Push(backCandidate);3713 3714 // note: leaf is not destroyed because it is needed to collect3715 // dirty candidates in hierarchy manager3716 }3717 3718 if (newNode->IsLeaf()) // subdivision terminated3719 {3720 // detach subdivision candidate: this leaf is no candidate for splitting anymore3721 tData.mNode->SetSubdivisionCandidate(NULL);3722 // detach node so it won't get deleted3723 tData.mNode = NULL;3724 }3725 3726 return newNode;3727 3814 } 3728 3815 … … 3857 3944 } 3858 3945 3859 #if 0 3860 void VspTree::TraverseRayPacket(RayBundle &rays); 3861 { 3862 float splitPos [3]; 3863 float dist[3]; 3864 3865 const int allValid = 1xf; 3866 int mask = all_valid; 3867 3868 int comparisonResult = 0; 3869 3870 while (!node->IsLeaf()) 3871 { 3872 comparisonResult = 0; 3873 3874 for (int i = 0; i < 4; ++ i) 3875 { 3876 splitPos[i] = node->splitPos; 3877 dist[i] = (splitpos[i] rp.origin[i][axis]) / (rp.dir[i][axis]); 3878 3879 comparisonresult |= ((dist[i] <= tnear[i]) << i); 3880 } 3881 3882 comparisonresult &= mask; 3883 3884 if (comparisonresult == allValid) 3885 { 3886 node = node->far; 3887 continue 3888 } 3889 3890 comparisonresult = 0; 3891 3892 for (int i = 0; i < 4; ++ i){ 3893 3894 comparisonresult |= (dist[i] >= tfar[i]); 3895 } 3896 3897 comparisonresult &= mask; 3898 3899 if (comparisonresult == allValid) 3900 { 3901 node = node->near; 3902 continue; 3903 } 3904 3905 if (comparisonresult) 3906 { 3907 3908 Push( node->far, dist[0...3], tfar[0...3] ) 3909 3910 node = node->near; 3911 3912 mask = 0; 3913 3914 for (int i = 0; i < 4; ++ i) 3915 { 3916 bool b = (tnear[i] < tfar[i]); 3917 mask |= b; 3918 3919 if (b) 3920 { 3921 tfar[i] = dist[i]; 3922 } 3923 3924 } 3925 3926 } 3927 } 3928 #endif 3929 3930 3931 3932 void VspTree::TraverseRayPacket()//RayBundle &rays) 3933 { 3934 #ifdef USE_SSE 3935 VspNode *node; 3936 3937 RayPacket rp; 3938 3939 __m128 mask; 3940 __m128 tf4; 3941 __m128 tn4; 3942 //const int offs[4] = { (RP->dcell[0] >= 0)?1:0, (RP->dcell[4] >= 0)?1:0, (RP->dcell[8] >= 0)?1:0, 0 }; 3943 3944 const int offs[4] = { 0, 0, 0, 0 }; 3945 3946 while (!node->IsLeaf()) 3947 { 3948 VspInterior *interior = static_cast<VspInterior *>(node); 3949 3950 float pos = interior->GetPosition(); 3951 const __m128 spos = _mm_load_ps(&pos); 3952 3953 const int aidx = interior->GetAxis(); 3954 const __m128 d4;// = _mm_mul_ps( _mm_sub_ps( spos, RP->oc4[aidx] ), RP->rdc4[aidx] ); 3955 3956 VspNode* ln = interior->GetBack();// + offs[aidx]; 3957 3958 if (!_mm_movemask_ps( _mm_and_ps( _mm_cmpgt_ps( d4, tn4 ), mask ) )) 3959 { 3960 node = ln; 3961 continue; 3962 } 3963 3964 node = interior->GetBack();// + (offs[aidx]^1); 3965 3966 if (_mm_movemask_ps( _mm_and_ps( _mm_cmplt_ps( d4, tf4 ), mask ) )) 3967 { 3968 const __m128 mask2 = _mm_cmpgt_ps( d4, tn4 ); 3969 const __m128 mask3 = _mm_cmplt_ps( d4, tf4 ); 3970 3971 //m_Stack[stackptr].tf4 = tf4; 3972 3973 tf4 = _mm_or_ps( _mm_and_ps( mask3, d4 ), _mm_andnot_ps( mask3, tf4 ) ); 3974 3975 //m_Stack[stackptr].node = (KdTreeNode*)ln; 3976 //m_Stack[stackptr].mask = mask; 3977 //m_Stack[stackptr++].tn4 = _mm_or_ps( _mm_and_ps( mask2, d4 ), _mm_andnot_ps( mask2, tn4 ) ); 3978 mask = _mm_cmplt_ps( tn4, tf4 ); 3979 } 3980 } 3981 #endif 3982 3983 } 3984 3985 } 3946 3947 3948 3949 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
r2288 r2332 45 45 46 46 47 #define WORK_WITH_VIEWCELLS 048 47 49 48 /** View space partition statistics. … … 573 572 float mBackPvs; 574 573 574 float mFrontTriangles; 575 float mBackTriangles; 576 575 577 float mCorrectedFrontRenderCost; 576 578 float mCorrectedBackRenderCost; … … 733 735 void SetViewCellsTree(ViewCellsTree *vt) { mViewCellsTree = vt; } 734 736 735 #if WORK_WITH_VIEWCELLS736 /** Remove the references of the parent view cell from the kd nodes associated with737 the objects.738 */739 void RemoveParentViewCellReferences(ViewCell *parent) const;740 741 /** Adds references to the view cell to the kd nodes associated with the objects.742 */743 void AddViewCellReferences(ViewCell *vc) const;744 #endif745 746 VspNode *SubdivideAndCopy(SplitQueue &tQueue, SubdivisionCandidate *splitCandidate);747 737 748 738 PerfTimer mSortTimer; … … 1075 1065 ViewCell *back) const; 1076 1066 1077 void CreateViewCell(VspTraversalData &tData, const bool updatePvs); 1067 void CreateViewCell(VspTraversalData &tData, 1068 const bool updatePvs, 1069 const float renderCost, 1070 const int pvs); 1078 1071 1079 1072 /** Collect split candidates which are affected by the last split … … 1113 1106 */ 1114 1107 void Initialise(const VssRayContainer &rays, 1115 AxisAlignedBox3 *forcedBoundingBox); 1108 AxisAlignedBox3 *forcedBoundingBox, 1109 const ObjectContainer &objects); 1116 1110 1117 1111 int CompressObjects(); 1118 1112 1119 1113 int CompressObjects(VspLeaf *leaf); 1120 1121 void TraverseRayPacket();1122 1114 1123 1115 #ifdef USE_SSE … … 1125 1117 struct RayPacket 1126 1118 { 1127 union { float ox[4]; __m128 ox4; }; 1128 union { float oy[4]; __m128 oy4; }; 1129 union { float oz[4]; __m128 oz4; }; 1130 union { float dx[4]; __m128 dx4; }; 1131 union { float dy[4]; __m128 dy4; }; 1132 union { float dz[4]; __m128 dz4; }; 1119 union { float mOriginX[4]; __m128 mOriginX4; }; 1120 union { float mOriginY[4]; __m128 mOriginY4; }; 1121 union { float mOriginZ[4]; __m128 mOriginZ4; }; 1122 1123 union { float mTerminationX[4]; __m128 mTerminationX4; }; 1124 union { float mTerminationY[4]; __m128 mTerminationY4; }; 1125 union { float mTerminationZ[4]; __m128 mTerminationZ4; }; 1126 1127 ViewCellContainer mViewCells[4]; 1133 1128 }; 1129 1130 struct PacketTraversalData 1131 { 1132 VspNode *mNode; 1133 1134 union { float mExitPointX[4]; __m128 mExitPointX4; }; 1135 union { float mExitPointY[4]; __m128 mExitPointY4; }; 1136 union { float mExitPointZ[4]; __m128 mExitPointZ4; }; 1137 1138 union { float mMaxT[4]; __m128 mMaxT4; }; 1139 union { float mMask[4]; __m128 mMask4; }; 1140 1141 PacketTraversalData () {} 1142 PacketTraversalData (VspNode *n, 1143 const __m128 &px, const __m128 &py, const __m128 &pz, 1144 const __m128 &maxt, 1145 const __m128 &mask): 1146 mNode(n), 1147 mExitPointX4(px), mExitPointY4(py), mExitPointZ4(pz), 1148 mMaxT4(maxt), 1149 mMask4(mask) 1150 {} 1151 }; 1152 1153 1154 int TraverseRayPacket(RayPacket &rp, 1155 const bool useMailboxing); 1156 1134 1157 #endif 1135 1158 … … 1141 1164 HierarchyManager *mHierarchyManager; 1142 1165 BvHierarchy *mBvHierarchy; 1143 1144 //OspTree *mOspTree;1145 //bool mUseKdPvsForHeuristics;1146 1166 1147 1167 ViewCellsManager *mViewCellsManager; -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r2283 r2332 463 463 "#AvgRayContrib\n" << avgRayContrib << endl; 464 464 } 465 466 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;467 468 469 470 465 } 471 466
Note: See TracChangeset
for help on using the changeset viewer.