Changeset 1047 for GTP/trunk/Lib/Vis/Preprocessing/src
- Timestamp:
- 06/21/06 18:26:17 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
r1012 r1047 2123 2123 } 2124 2124 2125 2125 2126 void AxisAlignedBox3::Split(const int axis, 2126 2127 const float value, 2127 AxisAlignedBox3 & left,2128 AxisAlignedBox3 & right) const2128 AxisAlignedBox3 &front, 2129 AxisAlignedBox3 &back) const 2129 2130 { 2130 2131 if ( (value >= mMin[axis]) && (value <= mMax[axis]) ) 2131 2132 { 2132 left.mMin = mMin; left.mMax = mMax; 2133 right.mMin = mMin; right.mMax = mMax; 2134 2135 left.mMax[axis] = value; 2136 right.mMin[axis] = value; 2137 2133 front.mMin = mMin; front.mMax = mMax; 2134 back.mMin = mMin; back.mMax = mMax; 2135 2136 back.mMax[axis] = value; 2137 front.mMin[axis] = value; 2138 2138 } 2139 2139 } 2140 } 2140 2141 2142 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h
r860 r1047 77 77 78 78 79 /** A definition for an axis aligned plane. 80 */ 81 struct AxisAlignedPlane 82 { 83 public: 84 AxisAlignedPlane(){} 85 AxisAlignedPlane(const int axis, const float position): 86 mAxis(axis), mPosition(position) 87 { 88 } 89 Plane3 GetPlane() const 90 { 91 Vector3 normal(0,0,0); normal[mAxis] = 1; 92 Vector3 point(0,0,0); point[mAxis] = mPosition; 93 94 return Plane3(normal, point); 95 } 96 97 /// the split axis: one of 0=x, 1=y, 2=z 98 int mAxis; 99 /// the absolute position of the split axis 100 float mPosition; 101 }; 102 103 79 104 } 80 105 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1027 r1047 1747 1747 Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.clipPlaneAxis", axis); 1748 1748 1749 Vector3 normal(0,0,0); 1750 normal[axis] = 1; 1751 1752 mClipPlane = Plane3(normal, point); 1749 mClipPlane = AxisAlignedPlane(axis, point[axis]); 1753 1750 } 1754 1751 … … 2428 2425 } 2429 2426 2427 2428 2430 2429 /**********************************************************************/ 2431 2430 /* BspViewCellsManager implementation */ … … 2927 2926 void BspViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 2928 2927 ViewCell *vc, 2929 const Plane3*clipPlane) const2928 const AxisAlignedPlane *clipPlane) const 2930 2929 { 2931 2930 // export mesh if available … … 2938 2937 if (clipPlane) 2939 2938 { 2939 const Plane3 plane = clipPlane->GetPlane(); 2940 2940 2941 ViewCellContainer leaves; 2941 2942 mViewCellsTree->CollectLeaves(vc, leaves); … … 2953 2954 2954 2955 const float eps = 0.00000001f; 2955 const int cf = geom.Side( *clipPlane, eps);2956 const int cf = geom.Side(plane, eps); 2956 2957 2957 2958 if (cf == -1) … … 2963 2964 geom.SplitGeometry(front, 2964 2965 back, 2965 *clipPlane,2966 plane, 2966 2967 mViewSpaceBox, 2967 2968 eps); … … 3067 3068 3068 3069 3069 bool BspViewCellsManager::ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects) 3070 bool BspViewCellsManager::ExportViewCells(const string filename, 3071 const bool exportPvs, 3072 const ObjectContainer &objects) 3070 3073 { 3071 3074 #if STILL_HAS_TODO … … 3472 3475 void KdViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 3473 3476 ViewCell *vc, 3474 const Plane3*clipPlane) const3477 const AxisAlignedPlane *clipPlane) const 3475 3478 { 3476 3479 ViewCellContainer leaves; … … 4154 4157 //-- export view cells 4155 4158 if (1) 4156 { // hack pvs 4159 { 4160 // hack pvs 4157 4161 const int savedColorCode = mColorCode; 4158 4162 mColorCode = 1; … … 4178 4182 4179 4183 // export rays 4180 if ( 1&& mExportRays)4184 if (0 && mExportRays) 4181 4185 { 4182 4186 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); … … 4359 4363 { 4360 4364 // output rays stored with the view cells during subdivision 4361 if ( 0)4365 if (1) 4362 4366 { 4363 4367 VssRayContainer vcRays; … … 4394 4398 } 4395 4399 4400 Debug << "here233 " << (int)vcRays.size() << endl; 4401 4396 4402 //-- export rays piercing this view cell 4397 4403 exporter->ExportRays(vcRays, RgbColor(1, 1, 1)); … … 4399 4405 4400 4406 // associate new rays with output view cell 4401 if ( 1)4407 if (0) 4402 4408 { 4403 4409 VssRayContainer vcRays; … … 4580 4586 void VspBspViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 4581 4587 ViewCell *vc, 4582 const Plane3*clipPlane) const4588 const AxisAlignedPlane *clipPlane) const 4583 4589 { 4584 4590 if (clipPlane) 4585 4591 { 4592 const Plane3 plane = clipPlane->GetPlane(); 4593 4586 4594 ViewCellContainer leaves; 4587 4595 mViewCellsTree->CollectLeaves(vc, leaves); … … 4599 4607 4600 4608 const float eps = 0.00000001f; 4601 const int cf = geom.Side( *clipPlane, eps);4609 const int cf = geom.Side(plane, eps); 4602 4610 4603 4611 if (cf == -1) … … 4609 4617 geom.SplitGeometry(front, 4610 4618 back, 4611 *clipPlane,4619 plane, 4612 4620 mViewSpaceBox, 4613 4621 eps); … … 4780 4788 4781 4789 /**************************************************************************/ 4782 /* Vsp BspViewCellsManager implementation */4790 /* VspOspViewCellsManager implementation */ 4783 4791 /**************************************************************************/ 4784 4792 … … 5136 5144 { 5137 5145 viewPoint = mViewSpaceBox.GetRandomPoint(); 5146 5138 5147 if (mVspTree->ViewPointValid(viewPoint)) 5139 5148 { … … 5149 5158 void VspOspViewCellsManager::ExportViewCellGeometry(Exporter *exporter, 5150 5159 ViewCell *vc, 5151 const Plane3*clipPlane) const5160 const AxisAlignedPlane *clipPlane) const 5152 5161 { 5153 5162 ViewCellContainer leaves; … … 5156 5165 ViewCellContainer::const_iterator it, it_end = leaves.end(); 5157 5166 5167 Plane3 plane; 5168 5169 if (clipPlane) 5170 plane = clipPlane->GetPlane(); 5171 5158 5172 for (it = leaves.begin(); it != it_end; ++ it) 5159 5173 { … … 5162 5176 5163 5177 const AxisAlignedBox3 box = mVspTree->GetBBox(vspVc->mLeaf); 5164 5165 if (!clipPlane || !box.Side(*clipPlane)) 5178 5179 if (clipPlane) 5180 { 5181 if (box.Side(plane) == -1) 5182 exporter->ExportBox(box); 5183 else if (box.Side(plane) == 0) 5184 { 5185 AxisAlignedBox3 fbox, bbox; 5186 5187 box.Split(clipPlane->mAxis, clipPlane->mPosition, fbox, bbox); 5188 5189 exporter->ExportBox(bbox); 5190 } 5191 } 5192 else 5193 { 5166 5194 exporter->ExportBox(box); 5195 } 5167 5196 } 5168 5197 } … … 5191 5220 //-- export view cells 5192 5221 if (1) 5193 { // hack pvs 5222 { 5223 // hack pvs 5194 5224 const int savedColorCode = mColorCode; 5195 mColorCode = 1;5225 mColorCode = 0; 5196 5226 5197 5227 Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl"); … … 5215 5245 5216 5246 // export rays 5217 if ( 1&& mExportRays)5247 if (0 && mExportRays) 5218 5248 { 5219 5249 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); … … 5292 5322 { 5293 5323 // output rays stored with the view cells during subdivision 5294 if ( 0)5324 if (1) 5295 5325 { 5296 5326 VssRayContainer vcRays; … … 5298 5328 5299 5329 raysOut = min((int)rays.size(), 100); 5330 5331 Debug << "here12 " << raysOut << endl; 5300 5332 5301 5333 // collect intial view cells … … 5307 5339 for (vit = leaves.begin(); vit != vit_end; ++ vit) 5308 5340 { 5309 BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaf;5341 VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaf; 5310 5342 5311 5343 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); … … 5332 5364 5333 5365 // associate new rays with output view cell 5334 if ( 1)5366 if (0) 5335 5367 { 5336 5368 VssRayContainer vcRays; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
r1027 r1047 36 36 class VspNode; 37 37 class HierarchyManager; 38 struct AxisAlignedPlane; 38 39 39 40 struct BspRay; … … 349 350 virtual void ExportViewCellGeometry(Exporter *exporter, 350 351 ViewCell *vc, 351 const Plane3*clipPlane = NULL) const = 0;352 const AxisAlignedPlane *clipPlane = NULL) const = 0; 352 353 353 354 /** Brings the view cells into their final state, computes meshes and volume. … … 574 575 575 576 //Environment *environment; 576 Plane3mClipPlane;577 AxisAlignedPlane mClipPlane; 577 578 578 579 bool mUseClipPlaneForViz; … … 704 705 void ExportViewCellGeometry(Exporter *exporter, 705 706 ViewCell *vc, 706 const Plane3*clipPlane = NULL) const;707 const AxisAlignedPlane *clipPlane = NULL) const; 707 708 708 709 void CollectMergeCandidates(const VssRayContainer &rays, … … 788 789 void ExportViewCellGeometry(Exporter *exporter, 789 790 ViewCell *vc, 790 const Plane3*clipPlane = NULL) const;791 const AxisAlignedPlane *clipPlane = NULL) const; 791 792 792 793 void CollectMergeCandidates(const VssRayContainer &rays, … … 860 861 void ExportViewCellGeometry(Exporter *exporter, 861 862 ViewCell *vc, 862 const Plane3*clipPlane = NULL) const;863 const AxisAlignedPlane *clipPlane = NULL) const; 863 864 864 865 //float GetVolume(ViewCell *viewCell) const; … … 1001 1002 void ExportViewCellGeometry(Exporter *exporter, 1002 1003 ViewCell *vc, 1003 const Plane3*clipPlane = NULL) const;1004 const AxisAlignedPlane *clipPlane = NULL) const; 1004 1005 1005 1006 int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; -
GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
r1020 r1047 34 34 const RgbColor &color) 35 35 { 36 if (rays.empty()) 37 return false; 36 38 RayContainer::const_iterator ri = rays.begin(); 37 39 … … 48 50 { 49 51 stream << index << " " << index + 1 << " -1\n"; 50 index +=2;52 index += 2; 51 53 } 52 54 … … 68 70 else 69 71 { 70 if ((*ri)->intersections. size()==0)72 if ((*ri)->intersections.empty()) 71 73 b = (*ri)->GetLoc() + length*(*ri)->GetDir(); 72 74 else … … 81 83 stream << "}" << endl; 82 84 stream << "}" << endl; 83 //stream << "}" << endl; 84 85 85 86 return true; 86 87 } … … 90 91 const RgbColor &color) 91 92 { 92 VssRayContainer::const_iterator ri = rays.begin(); 93 94 if (rays.empty()) 95 return false; 93 96 94 97 stream << "Shape {" << endl; … … 98 101 stream << "}" << endl; // end material 99 102 stream << "}" << endl; // end appearance 100 103 Debug << "here8" << endl; 101 104 stream << "geometry IndexedLineSet { coordIndex [" << endl; 102 105 103 106 int index = 0; 104 for (; ri != rays.end(); ri++) 107 VssRayContainer::const_iterator ri = rays.begin(); 108 109 for (; ri != rays.end(); ++ ri) 105 110 { 106 111 stream << index << " " << index + 1 << " -1\n"; 107 index += 2 ;112 index += 2 ; 108 113 } 109 114 … … 112 117 stream << "coord Coordinate { point [" << endl; 113 118 114 ri = rays.begin();115 for (; ri != rays.end(); ri++){116 117 const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir());118 //const Vector3 b = (*ri)->GetTermination(); // matt: change back!!119 120 stream<<a.x<<" "<<a.y<<" "<<a.z<<" ,";121 stream<<b.x<<" "<<b.y<<" "<<b.z<<" ,\n";119 for (ri = rays.begin(); ri != rays.end(); ++ ri) 120 { 121 const Vector3 a = (*ri)->GetOrigin(); 122 const Vector3 b = (*ri)->mTerminationObject ? (*ri)->GetTermination() : a + 1000 * Normalize((*ri)->GetDir()); 123 //const Vector3 b = (*ri)->GetTermination(); // matt: change back!! 124 125 stream << a.x << " " << a.y << " " << a.z << " ,"; 126 stream << b.x << " " << b.y << " " << b.z << " ,\n"; 122 127 } 128 123 129 stream << "]" << endl; 124 130 stream << "}" << endl; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1027 r1047 848 848 849 849 mBspStats.contributingSamples += conSamp; 850 mBspStats.sampleContributions += (int)sampCon;850 mBspStats.sampleContributions += (int)sampCon; 851 851 852 852 //-- store additional info … … 1224 1224 sc += contribution; 1225 1225 } 1226 1227 1228 1229 1230 1231 1232 //leaf->mVssRays.push_back(ray);1226 1227 sampleContributions += sc; 1228 1229 if (madeContrib) 1230 ++ contributingSamples; 1231 1232 if (0) leaf->mVssRays.push_back(new VssRay(*ray)); 1233 1233 } 1234 1234 } … … 1573 1573 1574 1574 // create back geometry from box 1575 // NOTE: the geometry is saved when possible 1575 // NOTE: the geometry is returned from the function so we 1576 // don't have to recompute it when possible 1576 1577 pos = box.Max(); pos[axis] = nPosition[axis]; 1577 1578 AxisAlignedBox3 bBox(box.Min(), pos); … … 2472 2473 extp = splitPlane.FindIntersection(ray.GetLoc(), extp, &t); 2473 2474 maxt *= t; 2474 2475 }else // reached leaf => intersection with view cell2475 } 2476 else // reached leaf => intersection with view cell 2476 2477 { 2477 2478 BspLeaf *leaf = dynamic_cast<BspLeaf *>(node); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
r1027 r1047 771 771 sc += contribution; 772 772 } 773 774 775 776 777 773 774 sampleContributions += sc; 775 776 if (madeContrib) 777 ++ contributingSamples; 778 778 779 //leaf->mVssRays.push_back(ray);780 } 781 } 782 783 784 void VspTree::SortSplitCandidates(const RayInfoContainer &rays, 785 786 787 779 if (1) leaf->mVssRays.push_back(new VssRay(*ray)); 780 } 781 } 782 783 784 void VspTree::SortSplitCandidates(const RayInfoContainer &rays, 785 const int axis, 786 float minBand, 787 float maxBand) 788 788 { 789 789 mSplitCandidates->clear(); 790 790 791 791 int requestedSize = 2 * (int)(rays.size()); 792 792 793 // creates a sorted split candidates array 793 794 if (mSplitCandidates->capacity() > 500000 && … … 863 864 864 865 865 // if no bordercan be found, take mid split866 // if no good split can be found, take mid split 866 867 position = minBox + 0.5f * sizeBox; 867 868 … … 952 953 } 953 954 } 954 955 955 956 956 … … 978 978 979 979 // -- compute cost 980 980 981 const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize(); 981 982 const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize(); 982 983 983 984 const float pOverall = sizeBox; 984 985 985 const float pBack = position - minBox; 986 986 const float pFront = maxBox - position; 987 987 988 /*const float pOverall = box.GetVolume(); 989 990 AxisAlignedBox3 bbox; 991 AxisAlignedBox3 fbox; 992 993 box.Split(axis, position, bbox, fbox); 994 995 const float pBack = fbox.GetVolume(); 996 const float pFront = bbox.GetVolume();*/ 997 988 998 const float penaltyOld = EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit); 989 999 const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit); 990 1000 const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit); 991 1001 992 const float oldRenderCost = penaltyOld * pOverall ;1002 const float oldRenderCost = penaltyOld * pOverall + Limits::Small; 993 1003 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 994 1004 995 1005 if (splitPlaneFound) 996 1006 { 997 ratio = newRenderCost / (oldRenderCost + Limits::Small);1007 ratio = newRenderCost / oldRenderCost; 998 1008 } 999 1009 //if (axis != 1) … … 1021 1031 int bestAxis = -1; 1022 1032 1033 //mOnlyDrivingAxis = true; 1034 1023 1035 // if we use some kind of specialised fixed axis 1024 1036 const bool useSpecialAxis = 1025 1037 mOnlyDrivingAxis || mCirculatingAxis; 1026 1027 int parentAxis = 0; 1028 VspNode *parent = tData.mNode->GetParent(); 1029 1030 if (parent) 1031 parentAxis = dynamic_cast<VspInterior *>(parent)->GetAxis(); 1032 1038 Debug << "data: " << tData.mBoundingBox << " pvs " << tData.mPvs << endl; 1033 1039 if (mCirculatingAxis) 1040 { 1041 int parentAxis = 0; 1042 VspNode *parent = tData.mNode->GetParent(); 1043 1044 if (parent) 1045 parentAxis = dynamic_cast<VspInterior *>(parent)->GetAxis(); 1046 1034 1047 sAxis = (parentAxis + 1) % 3; 1048 } 1035 1049 else if (mOnlyDrivingAxis) 1050 { 1036 1051 sAxis = box.Size().DrivingAxis(); 1037 1038 1039 for (int axis = 0; axis < 3 1052 } 1053 //sAxis = 2; 1054 for (int axis = 0; axis < 3; ++ axis) 1040 1055 { 1041 1056 if (!useSpecialAxis || (axis == sAxis)) … … 1070 1085 else if (nCostRatio[axis] < nCostRatio[bestAxis]) 1071 1086 { 1087 Debug << "old: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; 1072 1088 bestAxis = axis; 1089 1090 Debug << "new: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; 1073 1091 } 1074 1092 } 1075 1093 } 1076 1094 1095 1077 1096 //-- assign values 1097 1078 1098 plane.mAxis = bestAxis; 1099 // split plane position 1100 plane.mPosition = nPosition[bestAxis]; 1101 1079 1102 pFront = nProbFront[bestAxis]; 1080 1103 pBack = nProbBack[bestAxis]; 1081 1104 1082 //-- split plane position 1083 plane.mPosition = nPosition[bestAxis]; 1084 1105 1106 Debug << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl; 1085 1107 return nCostRatio[bestAxis]; 1086 1108 } … … 1098 1120 const VspTraversalData &data) const 1099 1121 { 1100 #if 11101 return -data.mDepth;1122 #if 0 1123 return (float)-data.mDepth; 1102 1124 #endif 1103 1125 float pvsFront = 0; … … 1752 1774 if (extp[axis] <= position) 1753 1775 { 1754 node = in->Get Front();1776 node = in->GetBack(); 1755 1777 // cases N1,N2,N3,P5,Z2,Z3 1756 1778 continue; … … 1758 1780 { 1759 1781 // case N4 1760 node = in->Get Front();1761 farChild = in->Get Back();1782 node = in->GetBack(); 1783 farChild = in->GetFront(); 1762 1784 } 1763 1785 } … … 1766 1788 if (position <= extp[axis]) 1767 1789 { 1768 node = in->Get Back();1790 node = in->GetFront(); 1769 1791 // cases P1,P2,P3,N5,Z1 1770 1792 continue; … … 1772 1794 else 1773 1795 { 1774 node = in->Get Back();1775 farChild = in->Get Front();1796 node = in->GetFront(); 1797 farChild = in->GetBack(); 1776 1798 // case P4 1777 1799 } … … 2086 2108 // get classification and receive new t 2087 2109 //-- test if start point behind or in front of plane 2088 const int side = plane.ComputeRayIntersection(bRay, t); 2110 const int side = bRay.ComputeRayIntersection(plane.mAxis, plane.mPosition, t); 2111 2112 2089 2113 #if 1 2090 2114 if (side == 0) … … 2157 2181 AxisAlignedBox3 box(parent->GetBoundingBox()); 2158 2182 2159 if (parent->Get Back() == node)2160 2161 2162 2183 if (parent->GetFront() == node) 2184 box.SetMin(parent->GetAxis(), parent->GetPosition()); 2185 else 2186 box.SetMax(parent->GetAxis(), parent->GetPosition()); 2163 2187 2164 2188 return box; -
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1027 r1047 42 42 return c1->GetPriority() < c2->GetPriority(); 43 43 } 44 };45 46 /** A definition for an axis aligned plane.47 */48 struct AxisAlignedPlane49 {50 public:51 52 /** Computes intersection of this plane with the ray segment.53 */54 int ComputeRayIntersection(const RayInfo &rayData, float &t) const55 {56 return rayData.ComputeRayIntersection(mAxis, mPosition, t);57 }58 59 /// the split axis: one of 0=x, 1=y, 2=z60 int mAxis;61 /// the absolute position of the split axis62 float mPosition;63 44 }; 64 45 … … 410 391 void SetBoundingBox(const AxisAlignedBox3 &box); 411 392 393 /** Computes intersection of this plane with the ray segment. 394 */ 395 int ComputeRayIntersection(const RayInfo &rayData, float &t) const 396 { 397 return rayData.ComputeRayIntersection(mPlane.mAxis, mPlane.mPosition, t); 398 } 399 400 412 401 protected: 413 402
Note: See TracChangeset
for help on using the changeset viewer.