- Timestamp:
- 10/04/05 03:05:08 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
r305 r306 73 73 # vertical axis = 64 74 74 75 splitPlaneStrategy 6475 splitPlaneStrategy 32 76 76 # least splits + balanced polygons 77 77 #splitPlaneStrategy 12 … … 92 92 constructionMethod viewCells 93 93 # constructionMethod sceneGeometry 94 maxCandidates 2594 maxCandidates 50 95 95 maxViewCells 999999 96 96 Termination { 97 maxPolysForAxisAligned 5097 maxPolysForAxisAligned 100 98 98 maxPolygons 0 99 maxDepth 10099 maxDepth 200 100 100 } 101 101 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r301 r306 37 37 #endif 38 38 return Plane3(mVertices[0], mVertices[1], mVertices[2]); 39 } 40 41 Vector3 Polygon3::GetNormal() const 42 { 43 return Normalize(CrossProd(mVertices[0]-mVertices[1], 44 mVertices[2]-mVertices[1])); 39 45 } 40 46 … … 109 115 float Polygon3::GetArea() const 110 116 { 111 VertexContainer vtx; 112 113 //-- rotate polygon to lie in xy plane 114 Vector3 v1 = mVertices[0] - mVertices[1]; 115 Vector3 v2 = mVertices[2] - mVertices[1]; 116 Vector3 n = Normalize(CrossProd(v2,v1)); 117 118 Matrix4x4 rot = GenRotation(v1, v2, n); 119 120 VertexContainer::const_iterator it, it_end = mVertices.end(); 121 122 for (it = mVertices.begin(); it != it_end; ++it) 123 vtx.push_back(rot * (*it)); 124 125 //-- compute area 126 Vector3 last = vtx.back(); 127 128 float area = 0.0f; 129 for (it = vtx.begin(); it != vtx.end(); ++it) 130 { 131 area += last.y * (*it).x - last.x * (*it).y; 132 133 last = *it; 134 } 135 //Debug << "area: " << area * 0.5 << endl; 136 return area * 0.5f; 117 Vector3 v = CrossProd(mVertices.back(), mVertices.front()); 118 119 for (int i=0; i < mVertices.size() - 1; ++i) 120 v += CrossProd(mVertices[i], mVertices[i+1]); 121 122 //Debug << "area2: " << 0.5f * fabs(DotProd(GetNormal(), v)) << endl; 123 124 return 0.5f * fabs(DotProd(GetNormal(), v)); 137 125 } 138 126 -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r299 r306 69 69 bool Valid() const; 70 70 71 Vector3 GetNormal() const; 72 71 73 /** Includes polygons to axis aligned box. 72 74 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r305 r306 29 29 float BspTree::sBalancedViewCellsFactor = 2.0f; 30 30 float BspTree::sVerticalSplitsFactor = 1.0f; // very important criterium for 2.5d scenes 31 31 float BspTree::sLargestPolyAreaFactor = 1.0f; 32 32 33 33 /** Evaluates split plane classification with respect to the plane's … … 365 365 366 366 // extract polygons that guide the split process 367 mStat.polys += AddMesh2Polygons(viewCell->GetMesh(), *polys );367 mStat.polys += AddMesh2Polygons(viewCell->GetMesh(), *polys, viewCell); 368 368 mBox.Include(viewCell->GetBox()); // add to BSP aabb 369 369 … … 460 460 polys.push_back(poly); 461 461 462 if (!poly->Valid()) 463 Debug << "Input polygon not valid: " << *poly 464 << endl << "Area: " << poly->GetArea() << endl; 462 //if (!poly->Valid()) 463 // Debug << "Input polygon not valid: " << *poly << endl << "Area: " << poly->GetArea() << endl; 465 464 466 465 ++ polysNum; … … 511 510 { 512 511 mBox.Include(object->GetBox()); // add to BSP tree aabb 513 AddMesh2Polygons(mesh, polys );512 AddMesh2Polygons(mesh, polys, mViewCell); 514 513 } 515 514 } … … 907 906 908 907 int candidateIdx = limit; 909 PolygonContainer debugPolys;bool dist = true;908 910 909 for (int i = 0; i < limit; ++ i) 911 910 { … … 922 921 lowestCost = candidateCost; 923 922 } 924 for (int i=0; i < debugPolys.size(); ++i)925 if (polys[candidateIdx] == debugPolys[i])926 {927 Debug << "FATAL ERROR" << endl;928 dist = false;929 }930 debugPolys.push_back(polys[candidateIdx]);931 923 } 932 924 933 925 //Debug << "Plane lowest cost: " << lowestCost << endl; 934 if (!dist)935 Debug << "FATAL ERROR DUPLICATE TESTS!!" << endl;936 926 return polys[bestPlaneIdx]->GetSupportingPlane(); 937 927 } … … 941 931 int candidateIdx = Random(currentIdx--); 942 932 933 //Debug << "new candidate " << candidateIdx << endl; 934 943 935 // swap candidates to avoid testing same plane 2 times 944 936 Polygon3 *p = polys[candidateIdx]; … … 958 950 // we put a penalty on the dot product between the "tiny" vertical axis 959 951 // and the split plane axis 960 // NOTE: weight with poly size because vertical split more important if too many polygons961 952 val += sVerticalSplitsFactor * 962 fabs(DotProd(candidatePlane.mNormal, tinyAxis)) * (float)polys.size(); 963 } 953 fabs(DotProd(candidatePlane.mNormal, tinyAxis)); 954 } 955 964 956 //-- strategies where the effect of the split plane on the polygons is tested 965 if ((sSplitPlaneStrategy & BALANCED_POLYS) || 966 (sSplitPlaneStrategy & LEAST_SPLITS) || 967 (sSplitPlaneStrategy & LARGEST_POLY_AREA)) 968 { 969 PolygonContainer::const_iterator it, it_end = polys.end(); 970 float sumBalancedPolys = 0; 971 float sumSplits = 0; 972 973 for (it = polys.begin(); it != it_end; ++ it) 974 { 975 int classification = (*it)->ClassifyPlane(candidatePlane); 976 977 if (sSplitPlaneStrategy & BALANCED_POLYS) 978 sumBalancedPolys += sBalancedPolysTable[classification]; 979 980 if (sSplitPlaneStrategy & LEAST_SPLITS) 981 sumSplits += sLeastSplitsTable[classification]; 982 983 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 984 { 985 if (classification == Polygon3::COINCIDENT) 986 { 987 float area = (*it)->GetArea(); 988 //Debug << "polygon area: " << area << " "; 989 if (area) val += 100.0f/area; 990 } 957 if (!((sSplitPlaneStrategy & BALANCED_POLYS) || 958 (sSplitPlaneStrategy & LEAST_SPLITS) || 959 (sSplitPlaneStrategy & LARGEST_POLY_AREA) || 960 (sSplitPlaneStrategy & BALANCED_VIEW_CELLS))) 961 return val; 962 963 PolygonContainer::const_iterator it, it_end = polys.end(); 964 float sumBalancedPolys = 0; 965 float sumSplits = 0; 966 float sumPolyArea = 0; 967 float sumBalancedViewCells = 0; 968 //float totalArea = 0; 969 970 // container for view cells 971 ObjectContainer frontViewCells; 972 ObjectContainer backViewCells; 973 974 for (it = polys.begin(); it != it_end; ++ it) 975 { 976 int classification = (*it)->ClassifyPlane(candidatePlane); 977 978 if (sSplitPlaneStrategy & BALANCED_POLYS) 979 sumBalancedPolys += sBalancedPolysTable[classification]; 980 981 if (sSplitPlaneStrategy & LEAST_SPLITS) 982 sumSplits += sLeastSplitsTable[classification]; 983 984 if (sSplitPlaneStrategy & LARGEST_POLY_AREA) 985 { 986 if (classification == Polygon3::COINCIDENT) 987 { 988 float area = (*it)->GetArea(); 989 //Debug << "polygon area: " << area << " "; 990 sumPolyArea += area; 991 991 } 992 } 993 val += sBalancedPolysFactor * fabs(sumBalancedPolys) + 994 sLeastSplitsFactor * sumSplits; 995 } 996 997 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 998 { 999 // store view cells 1000 ObjectContainer frontViewCells; 1001 ObjectContainer backViewCells; 1002 1003 float sumBalancedViewCells = 0; 1004 1005 PolygonContainer::const_iterator it, it_end = polys.end(); 992 //totalArea += area; 993 } 994 995 // order back and front view cells according to classificaion 996 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 997 { 998 Intersectable *viewCell = (*it)->mParent; 1006 999 1007 for (it = polys.begin(); it != it_end; ++ it) 1008 { 1009 int classification = (*it)->ClassifyPlane(candidatePlane); 1010 Intersectable *viewCell = (*it)->mParent; 1011 1012 if (viewCell && (classification == Polygon3::FRONT_SIDE)) 1000 if (classification == Polygon3::FRONT_SIDE) 1013 1001 frontViewCells.push_back(viewCell); 1014 1002 else if (viewCell && (classification == Polygon3::BACK_SIDE)) 1015 1003 backViewCells.push_back(viewCell); 1016 1004 } 1017 1005 } 1006 1007 if (sSplitPlaneStrategy & BALANCED_POLYS) 1008 val += sBalancedPolysFactor * fabs(sumBalancedPolys) / (float)polys.size(); 1009 1010 if (sSplitPlaneStrategy & LEAST_SPLITS) 1011 val += sLeastSplitsFactor * sumSplits / (float)polys.size(); 1012 1013 if ((sSplitPlaneStrategy & LARGEST_POLY_AREA) && sumPolyArea) 1014 val += sLargestPolyAreaFactor * (float)polys.size() / sumPolyArea; // HACK 1015 1016 if (sSplitPlaneStrategy & BALANCED_VIEW_CELLS) 1017 { 1018 1018 // count number of unique view cells 1019 1019 sort(frontViewCells.begin(), frontViewCells.end()); … … 1021 1021 1022 1022 ObjectContainer::const_iterator frontIt, frontIt_end = frontViewCells.end(); 1023 1023 1024 1024 Intersectable *intersect = NULL; 1025 1025 // increase counter for view cells in front of plane 1026 1026 for (frontIt = frontViewCells.begin(); frontIt != frontIt_end; ++frontIt) 1027 1027 { 1028 1028 if (*frontIt != intersect) … … 1036 1036 intersect = NULL; 1037 1037 // decrease counter for view cells on back side of plane 1038 1038 for (backIt = backViewCells.begin(); backIt != backIt_end; ++backIt) 1039 1039 { 1040 1040 if (*backIt != intersect) 1041 1041 { 1042 1042 intersect = *backIt; 1043 sumBalancedViewCells -= 1 ;1043 sumBalancedViewCells -= 1.0f; 1044 1044 } 1045 1045 } 1046 1046 1047 val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells); 1047 val += sBalancedViewCellsFactor * fabs(sumBalancedViewCells) / 1048 (float)(frontViewCells.size() + backViewCells.size()); 1048 1049 } 1049 1050 -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
r305 r306 436 436 @returns number of polygons 437 437 */ 438 int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent = NULL);438 int AddMesh2Polygons(Mesh *mesh, PolygonContainer &polys, Intersectable *parent); 439 439 440 440 /** A ray is cast possible intersecting the tree. … … 545 545 static float sBalancedViewCellsFactor; 546 546 static float sVerticalSplitsFactor; 547 static float sLargestPolyAreaFactor; 547 548 548 549 private:
Note: See TracChangeset
for help on using the changeset viewer.