Changeset 1292 for GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
- Timestamp:
- 08/28/06 21:13:40 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1291 r1292 24 24 #include "ArchModeler2MLRT.hxx" 25 25 #endif 26 27 #define DEBUG_RAYCAST 0 28 26 29 27 30 namespace GtpVisibilityPreprocessor { … … 454 457 } 455 458 459 460 bool 461 Preprocessor::ConstructViewCells() 462 { 463 // if not already loaded, construct view cells from file 464 if (!mLoadViewCells) { 465 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 466 467 // construct view cells using it's own set of samples 468 mViewCellsManager->Construct(this); 469 470 //-- several visualizations and statistics 471 Debug << "view cells construction finished: " << endl; 472 mViewCellsManager->PrintStatistics(Debug); 473 } 474 return true; 475 } 456 476 457 477 HierarchyManager *Preprocessor::CreateHierarchyManager(const char *name) … … 834 854 835 855 Vector3 pointA, pointB; 836 837 Intersectable *objectA = 838 CastIntelSingleRay(viewPoint, direction, pointA, box); 839 840 // cast ray into other direction 841 Intersectable *objectB = 842 CastIntelSingleRay(viewPoint, -direction, pointB, box); 843 844 const bool validSample = (objectA != objectB); 845 846 if (validSample) 847 { 848 if (objectA) 849 { 850 vssRay = new VssRay(pointB, 851 pointA, 852 objectB, 853 objectA, 854 mPass, 855 probability 856 ); 857 858 vssRays.push_back(vssRay); 859 hits ++; 860 } 861 862 if (objectB) 863 { 864 vssRay = new VssRay(pointA, 865 pointB, 866 objectA, 867 objectB, 868 mPass, 869 probability 870 ); 871 872 vssRays.push_back(vssRay); 873 hits ++; 874 } 875 //Debug << "intel ray: " << *vssRay << endl; 876 } 877 878 //cout << "a"; 879 return hits; 856 Vector3 normalA, normalB; 857 Intersectable *objectA = NULL, *objectB = NULL; 858 float dist; 859 860 int hittriangle; 861 double normal[3]; 862 hittriangle = mlrtaIntersectAS(&viewPoint.x, 863 &direction.x, 864 normal, 865 dist); 866 if (hittriangle !=-1 ) { 867 if (hittriangle >= mFaceParents.size()) 868 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 869 else { 870 objectA = mFaceParents[hittriangle].mObject; 871 normalA = Vector3(normal[0], normal[1], normal[2]); 872 // Get the normal of that face 873 // Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 874 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 875 //-rays[index+i].mDirection; // $$ temporary 876 pointA = viewPoint + direction*dist; 877 } 878 } 879 880 Vector3 dir = -direction; 881 hittriangle = mlrtaIntersectAS(&viewPoint.x, 882 &dir.x, 883 normal, 884 dist); 885 if (hittriangle !=-1 ) { 886 if (hittriangle >= mFaceParents.size()) 887 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 888 else { 889 objectB = mFaceParents[hittriangle].mObject; 890 normalB = Vector3(normal[0], normal[1], normal[2]); 891 // Get the normal of that face 892 // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 893 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 894 //-rays[index+i].mDirection; // $$ temporary 895 pointB = viewPoint + dir*dist; 896 } 897 } 898 899 return ProcessRay(viewPoint, 900 direction, 901 objectA, pointA, normalA, 902 objectB, pointB, normalB, 903 probability, 904 vssRays, 905 box 906 ); 880 907 } 881 908 … … 909 936 910 937 if (hittriangle == -1) 911 {938 { 912 939 static Ray ray; 913 940 SetupRay(ray, viewPoint, direction); 914 941 915 942 float tmin = 0, tmax; 916 943 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 917 {944 { 918 945 tPoint = ray.Extrap(tmax); 919 }920 946 } 947 921 948 return NULL; 922 } 923 else 924 { 949 } 950 else { 951 if (hittriangle >= mFaceParents.size()) { 952 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 953 return NULL; 954 } 955 else { 956 925 957 tPoint[0] = pforg[0] + pfdir[0] * dist; 926 958 tPoint[1] = pforg[1] + pfdir[1] * dist; 927 959 tPoint[2] = pforg[2] + pfdir[2] * dist; 928 960 929 961 return mFaceParents[hittriangle].mObject; 930 } 962 } 963 } 964 931 965 } 932 966 … … 1050 1084 { 1051 1085 int hits=0; 1052 1086 #if DEBUG_RAYCAST 1087 Debug<<"PR "; 1088 #endif 1053 1089 if (objectA == NULL && objectB == NULL) 1054 1090 return 0; 1055 1091 1056 1092 AxisAlignedBox3 sbox = box; 1057 1093 sbox.Enlarge(Vector3(-Limits::Small)); … … 1123 1159 } 1124 1160 } 1125 1161 1162 1126 1163 return hits; 1127 1164 } … … 1135 1172 int i; 1136 1173 int num = 16; 1137 1174 1175 #if DEBUG_RAYCAST 1176 Debug<<"C16 "<<flush; 1177 #endif 1138 1178 if (mRayCastMethod == INTEL_RAYCASTER) { 1139 1179 #ifdef GTP_INTERNAL … … 1144 1184 int backward_hit_triangles[16]; 1145 1185 float backward_dist[16]; 1146 1186 1187 1147 1188 Vector3 min = sbox.Min(); 1148 1189 Vector3 max = sbox.Max(); 1149 1150 1190 for (i=0; i < num; i++) { 1151 1191 mlrtaStoreRayAS16(&rays[index + i].mOrigin.x, … … 1161 1201 1162 1202 for (i=0; i < num; i++) { 1163 Vector3 dir = -rays[index +i].mDirection;1203 Vector3 dir = -rays[index + i].mDirection; 1164 1204 mlrtaStoreRayAS16(&rays[index+i].mOrigin.x, 1165 1205 &dir.x, … … 1174 1214 1175 1215 1216 1176 1217 for (i=0; i < num; i++) { 1177 1218 Intersectable *objectA = NULL, *objectB = NULL; 1178 1219 Vector3 pointA, pointB; 1179 1220 Vector3 normalA, normalB; 1221 1222 1223 1180 1224 if (forward_hit_triangles[i] !=-1 ) { 1181 objectA = mFaceParents[forward_hit_triangles[i]].mObject; 1182 // Get the normal of that face 1183 Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 1184 normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 1185 //-rays[index+i].mDirection; // $$ temporary 1186 pointA = rays[index+i].Extrap(forward_dist[i]); 1225 if (forward_hit_triangles[i] >= mFaceParents.size()) 1226 cerr<<"Warning: traingle index out of range! "<<forward_hit_triangles[i]<<endl; 1227 else { 1228 objectA = mFaceParents[forward_hit_triangles[i]].mObject; 1229 // Get the normal of that face 1230 Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 1231 normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 1232 //-rays[index+i].mDirection; // $$ temporary 1233 pointA = rays[index+i].Extrap(forward_dist[i]); 1234 } 1187 1235 } 1188 1236 1189 1237 if (backward_hit_triangles[i]!=-1) { 1190 objectB = mFaceParents[backward_hit_triangles[i]].mObject; 1191 Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 1192 1193 normalB = mesh->GetFacePlane(mFaceParents[backward_hit_triangles[i]].mFaceIndex).mNormal; 1194 1195 // normalB = rays[index+i].mDirection; // $$ temporary 1196 pointB = rays[index+i].Extrap(-backward_dist[i]); 1197 } 1198 1238 if (backward_hit_triangles[i] >= mFaceParents.size()) 1239 cerr<<"Warning: traingle index out of range! "<<backward_hit_triangles[i]<<endl; 1240 else { 1241 objectB = mFaceParents[backward_hit_triangles[i]].mObject; 1242 Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 1243 1244 normalB = mesh->GetFacePlane(mFaceParents[backward_hit_triangles[i]].mFaceIndex).mNormal; 1245 1246 // normalB = rays[index+i].mDirection; // $$ temporary 1247 pointB = rays[index+i].Extrap(-backward_dist[i]); 1248 } 1249 } 1250 1199 1251 ProcessRay(rays[index+i].mOrigin, 1200 1252 rays[index+i].mDirection, … … 1207 1259 } 1208 1260 #endif 1261 1209 1262 } else { 1210 1263 … … 1217 1270 } 1218 1271 } 1219 1272 #if DEBUG_RAYCAST 1273 Debug<<"C16F\n"<<flush; 1274 #endif 1220 1275 } 1221 1276 … … 1236 1291 i += 16; 1237 1292 } else { 1293 1238 1294 CastRay(rays[i].mOrigin, 1239 1295 rays[i].mDirection, … … 1241 1297 vssRays, 1242 1298 mViewCellsManager->GetViewSpaceBox()); 1299 1243 1300 i++; 1244 1301 } … … 1252 1309 } 1253 1310 1254 1255 int Preprocessor::CastRay( 1256 const Vector3 &viewPoint, 1257 const Vector3 &direction, 1258 const float probability, 1259 VssRayContainer &vssRays, 1260 const AxisAlignedBox3 &box 1261 ) 1262 { 1263 switch (mRayCastMethod) 1311 Intersectable * 1312 Preprocessor::CastSimpleRay( 1313 const Vector3 &viewPoint, 1314 const Vector3 &direction, 1315 const AxisAlignedBox3 &box, 1316 Vector3 &point, 1317 Vector3 &normal 1318 ) 1319 { 1320 Intersectable *result = NULL; 1321 switch (mRayCastMethod) 1322 { 1323 case INTEL_RAYCASTER: { 1324 float dist; 1325 int hittriangle; 1326 double n[3]; 1327 hittriangle = mlrtaIntersectAS(&viewPoint.x, 1328 &direction.x, 1329 n, 1330 dist); 1331 if (hittriangle !=-1 ) { 1332 if (hittriangle >= mFaceParents.size()) 1333 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl; 1334 else { 1335 result = mFaceParents[hittriangle].mObject; 1336 normal = Vector3(n[0], n[1], n[2]); 1337 point = viewPoint + direction*dist; 1338 } 1339 } 1340 break; 1341 } 1342 case INTERNAL_RAYCASTER: 1343 default: { 1344 static Ray ray; 1345 1346 ray.intersections.clear(); 1347 // do not store anything else then intersections at the ray 1348 ray.Init(viewPoint, direction, Ray::LOCAL_RAY); 1349 1350 ray.mFlags &= ~Ray::CULL_BACKFACES; 1351 1352 if (mKdTree->CastRay(ray)) { 1353 result = ray.intersections[0].mObject; 1354 point = ray.Extrap(ray.intersections[0].mT); 1355 normal = ray.intersections[0].mNormal; 1356 } 1357 break; 1358 } 1359 } 1360 return result; 1361 } 1362 1363 int 1364 Preprocessor::CastRay( 1365 const Vector3 &viewPoint, 1366 const Vector3 &direction, 1367 const float probability, 1368 VssRayContainer &vssRays, 1369 const AxisAlignedBox3 &box 1370 ) 1371 { 1372 #if DEBUG_RAYCAST 1373 Debug<<"CR "<<flush; 1374 #endif 1375 switch (mRayCastMethod) 1264 1376 { 1265 1377 case INTEL_RAYCASTER: … … 1269 1381 return CastInternalRay(viewPoint, direction, probability, vssRays, box); 1270 1382 } 1383 #if DEBUG_RAYCAST 1384 Debug<<"CRF "<<flush; 1385 #endif 1271 1386 } 1272 1387
Note: See TracChangeset
for help on using the changeset viewer.