Changeset 491 for trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
- Timestamp:
- 01/03/06 18:37:32 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r490 r491 34 34 35 35 float BspMergeCandidate::sOverallCost = 0; 36 37 38 /// Adds object to the pvs of the front and back node 39 inline void AddObject2Pvs(Intersectable *object, 40 const int side, 41 int &pvsBack, 42 int &pvsFront) 43 { 44 if (!object) 45 return; 46 47 if (side <= 0) 48 { 49 if (!object->Mailed() && !object->Mailed(2)) 50 { 51 ++ pvsBack; 52 53 if (object->Mailed(1)) 54 object->Mail(2); 55 else 56 object->Mail(); 57 } 58 } 59 60 if (side >= 0) 61 { 62 if (!object->Mailed(1) && !object->Mailed(2)) 63 { 64 ++ pvsFront; 65 66 if (object->Mailed()) 67 object->Mail(2); 68 else 69 object->Mail(1); 70 } 71 } 72 } 73 36 74 37 75 /****************************************************************/ … … 509 547 510 548 // subdivide polygons 511 mStat.splits +=SplitPolygons(interior->GetPlane(),512 513 514 515 549 SplitPolygons(interior->GetPlane(), 550 *tData.mPolygons, 551 *frontData.mPolygons, 552 *backData.mPolygons, 553 coincident); 516 554 517 555 … … 755 793 756 794 float VspBspTree::SelectAxisAlignedPlane(Plane3 &plane, 757 const VspBspTraversalData &tData) 795 const VspBspTraversalData &tData, 796 int &bestAxis) 758 797 { 759 798 AxisAlignedBox3 box; … … 771 810 float nPosition[3]; 772 811 float nCostRatio[3]; 773 intbestAxis = -1;812 bestAxis = -1; 774 813 775 814 const int sAxis = box.Size().DrivingAxis(); … … 815 854 Vector3 normal(0,0,0); normal[bestAxis] = 1; 816 855 plane = Plane3(normal, nPosition[bestAxis]); 817 856 818 857 return nCostRatio[bestAxis]; 819 858 } 859 860 861 float VspBspTree::EvalCostRatio(const VspBspTraversalData &tData, 862 const AxisAlignedBox3 &box, 863 const int axis, 864 const float position, 865 int &raysBack, 866 int &raysFront, 867 int &pvsBack, 868 int &pvsFront) 869 { 870 raysBack = 0; 871 raysFront = 0; 872 pvsFront = 0; 873 pvsBack = 0; 874 875 Intersectable::NewMail(3); 876 877 // eval pvs size 878 const int pvsSize = tData.mPvs; 879 880 // create unique ids for pvs heuristics 881 GenerateUniqueIdsForPvs(); 882 883 // this is the main ray classification loop! 884 for(RayInfoContainer::iterator ri = tData.mRays->begin(); 885 ri != tData.mRays->end(); ++ ri) 886 { 887 if (!(*ri).mRay->IsActive()) 888 continue; 889 890 // determine the side of this ray with respect to the plane 891 float t; 892 int side = (*ri).ComputeRayIntersection(axis, position, t); 893 894 if (side <= 0) 895 ++ raysBack; 896 897 if (side >= 0) 898 ++ raysFront; 899 900 AddObjToPvs((*ri).mRay->mTerminationObject, side, pvsBack, pvsFront); 901 } 902 903 //-- only one of these options should be one 904 905 if (0) //-- only pvs 906 { 907 const float sum = float(pvsBack + pvsFront); 908 const float oldCost = (float)pvsSize; 909 910 return sum / oldCost; 911 } 912 913 //-- pvs + probability heuristics 914 float pBack, pFront, pOverall; 915 916 if (0) 917 { 918 // box length substitute for probability 919 const float minBox = box.Min(axis); 920 const float maxBox = box.Max(axis); 921 922 pBack = position - minBox; 923 pFront = maxBox - position; 924 pOverall = maxBox - minBox; 925 } 926 927 if (1) //-- area substitute for probability 928 { 929 930 const bool useMidSplit = true; 931 //const bool useMidSplit = false; 932 933 pOverall = box.SurfaceArea(); 934 935 if (!useMidSplit) 936 { 937 Vector3 pos = box.Max(); pos[axis] = position; 938 pBack = AxisAlignedBox3(box.Min(), pos).SurfaceArea(); 939 940 pos = box.Min(); pos[axis] = position; 941 pFront = AxisAlignedBox3(pos, box.Max()).SurfaceArea(); 942 } 943 else 944 { 945 //-- simplified computation for mid split 946 const int axis2 = (axis + 1) % 3; 947 const int axis3 = (axis + 2) % 3; 948 949 const float faceArea = 950 (box.Max(axis2) - box.Min(axis2)) * 951 (box.Max(axis3) - box.Min(axis3)); 952 953 pBack = pFront = pOverall * 0.5f + faceArea; 954 } 955 } 956 957 //-- ray density substitute for probability 958 if (0) 959 { 960 pBack = (float)raysBack; 961 pFront = (float)raysFront; 962 pOverall = (float)tData.mRays->size(); 963 } 964 965 //Debug << axis << " " << pvsSize << " " << pvsBack << " " << pvsFront << endl; 966 //Debug << pFront << " " << pBack << " " << pOverall << endl; 967 968 // float sum = raysBack*(position - minBox) + raysFront*(maxBox - position); 969 const float newCost = pvsBack * pBack + pvsFront * pFront; 970 // float oldCost = leaf->mRays.size(); 971 const float oldCost = (float)pvsSize * pOverall; 972 973 return (mCtDivCi + newCost) / oldCost; 974 } 975 820 976 821 977 … … 835 991 return true; 836 992 } 837 else838 {839 //-- choose plane on midpoint of a ray840 const int candidateIdx = (int)RandomValue(0, (Real)((int)data.mRays->size() - 1));841 842 const Vector3 minPt = (*data.mRays)[candidateIdx].ExtrapOrigin();843 const Vector3 maxPt = (*data.mRays)[candidateIdx].ExtrapTermination();844 845 const Vector3 pt = (maxPt + minPt) * 0.5;846 847 const Vector3 normal = (*data.mRays)[candidateIdx].mRay->GetDir();848 849 plane = Plane3(normal, pt);850 return true;851 }852 853 return false;854 993 } 855 994 … … 938 1077 // intermediate plane 939 1078 Plane3 plane; 1079 bool useAxisAlignedPlane = false; 940 1080 941 1081 const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); … … 967 1107 } 968 1108 969 #if 0 970 //-- choose candidate planes extracted from rays 971 //-- different methods are available 972 for (int i = 0; i < mMaxRayCandidates; ++ i) 973 { 974 plane = ChooseCandidatePlane3(*data.mRays); 975 candidateCost = SplitPlaneCost(plane, data); 976 977 if (candidateCost < lowestCost) 978 { 979 bestPlane = plane; 980 lowestCost = candidateCost; 981 } 982 } 983 #endif 984 985 // axis aligned splits 986 candidateCost = SelectAxisAlignedPlane(plane, data); 1109 //-- axis aligned splits 1110 int axis; 1111 candidateCost = SelectAxisAlignedPlane(plane, data, axis); 987 1112 988 1113 if (candidateCost < lowestCost) 989 { 1114 { 1115 if (!useAxisAlignedPlane) 1116 { 1117 useAxisAlignedPlane = true; 1118 //! error also computed if cost ratio is missed 1119 ++ mStat.splits[axis]; 1120 } 1121 990 1122 bestPlane = plane; 991 1123 lowestCost = candidateCost; … … 1031 1163 if (mSplitPlaneStrategy & PVS) 1032 1164 { 1165 // matt: change back!! 1166 Intersectable::NewMail(3); 1033 1167 // create unique ids for pvs heuristics 1034 GenerateUniqueIdsForPvs();1168 //GenerateUniqueIdsForPvs(); 1035 1169 1036 1170 if (mPvsUseArea) // use front and back cell areas to approximate volume … … 1056 1190 bool useRand; 1057 1191 1058 // choose test polyongs randomly if over threshold1192 // choose test rays randomly if too much 1059 1193 if ((int)data.mRays->size() > mMaxTests) 1060 1194 { … … 1095 1229 1096 1230 // add the termination object 1097 AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 1231 //AddObjToPvs(ray->mTerminationObject, cf, frontPvs, backPvs); 1232 AddObject2Pvs(ray->mTerminationObject, cf, frontPvs, backPvs); 1098 1233 // add the source object 1099 AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs);1100 1101 // use number o r length of rays to approximate volume1234 //AddObjToPvs(ray->mOriginObject, cf, frontPvs, backPvs); 1235 1236 // use number of rays to approximate volume 1102 1237 if (!mPvsUseArea) 1103 1238 { 1104 float len = 1; 1105 1106 if (pvsUseLen) // use length of rays 1107 len = rayInf.SqrSegmentLength(); 1108 1109 pOverall += len; 1110 1111 if (cf == 1) 1112 pFront += len; 1113 else if (cf == -1) 1114 pBack += len; 1115 else if (cf == 0) 1116 { 1117 // use length of rays to approximate volume 1118 if (pvsUseLen) 1119 { 1120 float newLen = len * 1121 (rayInf.GetMaxT() - t) / 1122 (rayInf.GetMaxT() - rayInf.GetMinT()); 1123 1124 if (candidatePlane.Side(rayInf.ExtrapOrigin()) <= 0) 1125 { 1126 pBack += newLen; 1127 pFront += len - newLen; 1128 } 1129 else 1130 { 1131 pFront += newLen; 1132 pBack += len - newLen; 1133 } 1134 } 1135 else 1136 { 1137 ++ pFront; 1138 ++ pBack; 1139 } 1140 } 1239 ++ pOverall; 1240 1241 if (cf >= 0) 1242 ++ pFront; 1243 if (cf <= 0) 1244 ++ pBack; 1141 1245 } 1142 1246 } … … 1215 1319 } 1216 1320 } 1321 1217 1322 1218 1323 void VspBspTree::CollectLeaves(vector<BspLeaf *> &leaves) const
Note: See TracChangeset
for help on using the changeset viewer.