Changeset 478 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
- Timestamp:
- 12/22/05 18:32:39 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
r475 r478 1148 1148 if (!data.mPolygons->empty()) 1149 1149 { 1150 Polygon3 *nextPoly = (*data.mPolygons)[(int)RandomValue(0, (int)data.mPolygons->size() - 1)]; 1150 Polygon3 *nextPoly = 1151 (*data.mPolygons)[(int)RandomValue(0, (Real)((int)data.mPolygons->size() - 1))]; 1151 1152 return nextPoly->GetSupportingPlane(); 1152 1153 } … … 1175 1176 } 1176 1177 1178 1179 Plane3 BspTree::ChooseCandidatePlane(const BoundedRayContainer &rays) const 1180 { return Plane3(); 1181 /*const int candidateIdx = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 1182 1183 const Vector3 minPt = rays[candidateIdx].ExtrapOrigin(); 1184 const Vector3 maxPt = rays[candidateIdx].ExtrapTermination(); 1185 1186 const Vector3 pt = (maxPt + minPt) * 0.5; 1187 const Vector3 normal = Normalize(rays[candidateIdx].mRay->GetDir()); 1188 1189 return Plane3(normal, pt);*/ 1190 } 1191 1192 Plane3 BspTree::ChooseCandidatePlane2(const BoundedRayContainer &rays) const 1193 { return Plane3(); 1194 /*Vector3 pt[3]; 1195 1196 int idx[3]; 1197 int cmaxT = 0; 1198 int cminT = 0; 1199 bool chooseMin = false; 1200 1201 for (int j = 0; j < 3; ++ j) 1202 { 1203 idx[j] = (int)RandomValue(0, (Real)((int)rays.size() * 2 - 1)); 1204 1205 if (idx[j] >= (int)rays.size()) 1206 { 1207 idx[j] -= (int)rays.size(); 1208 1209 chooseMin = (cminT < 2); 1210 } 1211 else 1212 chooseMin = (cmaxT < 2); 1213 1214 RayInfo rayInf = rays[idx[j]]; 1215 pt[j] = chooseMin ? rayInf.ExtrapOrigin() : rayInf.ExtrapTermination(); 1216 } 1217 1218 return Plane3(pt[0], pt[1], pt[2]);*/ 1219 } 1220 1221 Plane3 BspTree::ChooseCandidatePlane3(const BoundedRayContainer &rays) const 1222 { return Plane3();/* 1223 Vector3 pt[3]; 1224 1225 int idx1 = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 1226 int idx2 = (int)RandomValue(0, (Real)((int)rays.size() - 1)); 1227 1228 // check if rays different 1229 if (idx1 == idx2) 1230 idx2 = (idx2 + 1) % (int)rays.size(); 1231 1232 const RayInfo ray1 = rays[idx1]; 1233 const RayInfo ray2 = rays[idx2]; 1234 1235 // normal vector of the plane parallel to both lines 1236 const Vector3 norm = Normalize(CrossProd(ray1.mRay->GetDir(), ray2.mRay->GetDir())); 1237 1238 // vector from line 1 to line 2 1239 const Vector3 vd = (ray2.ExtrapOrigin() - ray1.ExtrapOrigin()); 1240 1241 // project vector on normal to get distance 1242 const float dist = DotProd(vd, norm); 1243 1244 // point on plane lies halfway between the two planes 1245 const Vector3 planePt = ray1.ExtrapOrigin() + norm * dist * 0.5; 1246 1247 return Plane3(norm, planePt);*/ 1248 } 1249 1250 1177 1251 Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf, BspTraversalData &data) 1178 1252 { 1179 1253 float lowestCost = MAX_FLOAT; 1180 1254 Plane3 bestPlane; 1255 // intermediate plane 1181 1256 Plane3 plane; 1182 1257 1183 int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 1184 1185 int candidateIdx = limit - 1; 1186 1258 const int limit = Min((int)data.mPolygons->size(), mMaxPolyCandidates); 1259 int maxIdx = (int)data.mPolygons->size(); 1260 1187 1261 for (int i = 0; i < limit; ++ i) 1188 1262 { 1189 candidateIdx = GetNextCandidateIdx(candidateIdx, *data.mPolygons); 1263 // assure that no index is taken twice 1264 const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx)); 1265 //Debug << "current Idx: " << maxIdx << " cand idx " << candidateIdx << endl; 1190 1266 1191 1267 Polygon3 *poly = (*data.mPolygons)[candidateIdx]; 1268 1269 // swap candidate to the end to avoid testing same plane 1270 std::swap((*data.mPolygons)[maxIdx], (*data.mPolygons)[candidateIdx]); 1271 1272 //Polygon3 *poly = (*data.mPolygons)[(int)RandomValue(0, (int)polys.size() - 1)]; 1273 1192 1274 // evaluate current candidate 1193 1275 const float candidateCost = … … 1201 1283 } 1202 1284 1203 //Debug << "lowest: " << lowestCost << endl;1204 1205 1285 //-- choose candidate planes extracted from rays 1206 // we currently use two methods 1207 // 1) take 3 ray endpoints, where two are minimum and one a maximum 1208 // point or the other way round 1209 // 2) take plane normal as plane normal and the midpoint of the ray. 1210 // PROBLEM: does not resemble any point where visibility is likely to change 1211 const BoundedRayContainer *rays = data.mRays; 1212 1213 for (int i = 0; i < mMaxRayCandidates / 2; ++ i) 1214 { 1215 candidateIdx = (int)RandomValue(0, (int)rays->size() - 1); 1216 BoundedRay *bRay = (*rays)[candidateIdx]; 1217 1218 Ray *ray = bRay->mRay; 1219 1220 const Vector3 minPt = ray->Extrap(bRay->mMinT); 1221 const Vector3 maxPt = ray->Extrap(bRay->mMaxT); 1222 1223 const Vector3 pt = (maxPt + minPt) * 0.5; 1224 1225 const Vector3 normal = ray->GetDir(); 1226 1227 plane = Plane3(normal, pt); 1228 1286 //-- different methods are available 1287 for (int i = 0; i < mMaxRayCandidates; ++ i) 1288 { 1289 plane = ChooseCandidatePlane3(*data.mRays); 1229 1290 const float candidateCost = SplitPlaneCost(plane, data); 1230 1291 1231 1292 if (candidateCost < lowestCost) 1232 1293 { 1233 bestPlane = plane; 1234 1294 bestPlane = plane; 1235 1295 lowestCost = candidateCost; 1236 1296 } 1237 1297 } 1238 1239 //Debug << "lowest: " << lowestCost << endl;1240 for (int i = 0; i < mMaxRayCandidates / 2; ++ i)1241 {1242 Vector3 pt[3];1243 int idx[3];1244 int cmaxT = 0;1245 int cminT = 0;1246 bool chooseMin = false;1247 1248 for (int j = 0; j < 3; j ++)1249 {1250 idx[j] = (int)RandomValue(0, (int)rays->size() * 2 - 1);1251 1252 if (idx[j] >= (int)rays->size())1253 {1254 idx[j] -= (int)rays->size();1255 1256 chooseMin = (cminT < 2);1257 }1258 else1259 chooseMin = (cmaxT < 2);1260 1261 BoundedRay *bRay = (*rays)[idx[j]];1262 pt[j] = chooseMin ? bRay->mRay->Extrap(bRay->mMinT) :1263 bRay->mRay->Extrap(bRay->mMaxT);1264 }1265 1266 plane = Plane3(pt[0], pt[1], pt[2]);1267 1268 const float candidateCost = SplitPlaneCost(plane, data);1269 1270 if (candidateCost < lowestCost)1271 {1272 //Debug << "choose ray plane 2: " << candidateCost << endl;1273 bestPlane = plane;1274 1275 lowestCost = candidateCost;1276 }1277 }1278 1298 1279 1299 #ifdef _DEBUG 1280 1300 Debug << "plane lowest cost: " << lowestCost << endl; 1281 1301 #endif 1302 1282 1303 return bestPlane; 1283 1304 } 1284 1305 1285 int BspTree::GetNextCandidateIdx(int currentIdx, PolygonContainer &polys)1286 {1287 const int candidateIdx = (int)RandomValue(0, currentIdx --);1288 1289 // swap candidates to avoid testing same plane 2 times1290 std::swap(polys[currentIdx], polys[candidateIdx]);1291 1292 return currentIdx;1293 //return (int)RandomValue(0, (int)polys.size() - 1);1294 }1295 1306 1296 1307 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane, … … 1331 1342 limit = (int)polys.size(); 1332 1343 } 1333 1334 1344 1335 1345 for (int i = 0; i < limit; ++ i) 1336 1346 { 1337 const int testIdx = useRand ? (int)RandomValue(0, limit - 1) : i;1347 const int testIdx = useRand ? (int)RandomValue(0, (Real)(limit - 1)) : i; 1338 1348 1339 1349 Polygon3 *poly = polys[testIdx];
Note: See TracChangeset
for help on using the changeset viewer.