Changeset 1344 for GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
- Timestamp:
- 09/12/06 17:39:08 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1328 r1344 162 162 Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl; 163 163 Debug << "load polygons as meshes: " << mLoadPolygonsAsMeshes << endl; 164 165 if (mRayCastMethod == 0) 166 cout << "ray cast method: internal" << endl; 167 else 168 cout << "ray cast method: intel" << endl; 164 169 } 165 170 … … 231 236 cout << "number of input files: " << files << endl; 232 237 bool result = false; 238 239 // root for different files 240 mSceneGraph->SetRoot(new SceneGraphNode()); 241 233 242 if (files == 1) { 234 243 … … 245 254 cout << filename << endl; 246 255 247 SceneGraphNode *sroot = mSceneGraph->GetRoot();248 249 256 if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 250 { cout << "here5800" << endl;257 { 251 258 result = parser->ParseFile( 252 259 filename, 253 &sroot,260 mSceneGraph->GetRoot(), 254 261 mLoadPolygonsAsMeshes, 255 262 &mFaceParents); 256 263 } 257 264 else 258 { cout << "here776645" << endl;259 result = parser->ParseFile(filename, &sroot, mLoadPolygonsAsMeshes);265 { 266 result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadPolygonsAsMeshes); 260 267 } 261 cout << "here98809845" << endl;268 262 269 delete parser; 263 270 264 271 } else { 265 // root for different files 266 mSceneGraph->SetRoot(new SceneGraphNode()); 272 267 273 for (int i= 0; i < filenames.size(); i++) { 268 274 if (strstr(filenames[i].c_str(), ".x3d")) … … 271 277 parser = new UnigraphicsParser; 272 278 273 SceneGraphNode *node ;279 SceneGraphNode *node = new SceneGraphNode(); 274 280 bool success; 275 281 276 282 if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) 277 { cout << "here4500" << endl;283 { 278 284 success = parser->ParseFile( 279 285 filename, 280 &node,286 node, 281 287 mLoadPolygonsAsMeshes, 282 288 &mFaceParents); … … 284 290 else 285 291 { 286 cout << "here45" << endl; 287 success = parser->ParseFile(filename, &node, mLoadPolygonsAsMeshes); 292 success = parser->ParseFile(filename, node, mLoadPolygonsAsMeshes); 288 293 } 289 294 290 295 if (success) 291 { cout << "here4509999" << endl;296 { 292 297 mSceneGraph->GetRoot()->mChildren.push_back(node); 293 // at least one file parsed 294 result = true; 298 result = true; // at least one file parsed 295 299 } 296 300 … … 298 302 } 299 303 } 300 cout << "here8888" << endl; 301 304 302 305 if (result) 303 { cout << "here199" << endl;306 { 304 307 // HACK 305 308 if (ADDITIONAL_GEOMETRY_HACK) … … 307 310 308 311 mSceneGraph->AssignObjectIds(); 309 cout << "here99" << endl;312 310 313 int intersectables, faces; 311 314 mSceneGraph->GetStatistics(intersectables, faces); 312 cout << "here999" << endl;315 313 316 cout<<filename<<" parsed successfully."<<endl; 314 317 cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl; … … 316 319 mSceneGraph->CollectObjects(&mObjects); 317 320 mSceneGraph->GetRoot()->UpdateBox(); 318 cout << "here9999" << endl;321 319 322 if (0) 320 323 { … … 369 372 { 370 373 mKdTree = new KdTree; 374 371 375 // add mesh instances of the scene graph to the root of the tree 372 376 KdLeaf *root = (KdLeaf *)mKdTree->GetRoot(); 373 cout << "here3.95" << endl;377 374 378 mSceneGraph->CollectObjects(&root->mObjects); 375 cout << "here3.97" << endl;379 376 380 long startTime = GetTime(); 377 378 381 cout << "building kd tree ... " << endl; 382 379 383 mKdTree->Construct(); 384 380 385 cout << "construction finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs " << endl; 386 381 387 return true; 382 388 } … … 847 853 case INTEL_RAYCASTER: 848 854 #ifdef GTP_INTERNAL 849 cout<<"Ray Cast file: " <<externKdTree<<endl;855 cout<<"Ray Cast file: " << externKdTree << endl; 850 856 return mlrtaLoadAS(externKdTree.c_str()); 851 857 #endif … … 868 874 { 869 875 #ifdef GTP_INTERNAL 876 //cout << "intel ray" << endl; 870 877 VssRay *vssRay = NULL; 871 878 int hits = 0; … … 875 882 Intersectable *objectA = NULL, *objectB = NULL; 876 883 float dist; 877 878 884 double normal[3]; 879 885 880 886 hittriangle = mlrtaIntersectAS(&viewPoint.x, 881 882 883 884 885 if (hittriangle != -1 ) {886 887 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;888 889 objectA = mFaceParents[hittriangle].mObject;890 normalA = Vector3(normal[0], normal[1], normal[2]);891 // Get the normal of that face892 // Mesh *mesh = ((MeshInstance *)objectA)->GetMesh();893 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;894 //-rays[index+i].mDirection; // $$ temporary895 pointA = viewPoint + direction*dist;896 897 } 898 899 887 &direction.x, 888 normal, 889 dist); 890 891 if (hittriangle != -1 ) { 892 if (hittriangle >= mFaceParents.size()) 893 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 894 else { 895 objectA = mFaceParents[hittriangle].mObject; 896 normalA = Vector3(normal[0], normal[1], normal[2]); 897 // Get the normal of that face 898 // Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 899 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 900 //-rays[index+i].mDirection; // $$ temporary 901 pointA = viewPoint + direction*dist; 902 } 903 } 904 905 900 906 Vector3 dir = -direction; 901 907 hittriangle = mlrtaIntersectAS(&viewPoint.x, 902 903 904 905 906 if (hittriangle != -1 ) {907 908 cerr<<"Warning: traingle index out of range! "<<hittriangle<<endl;909 910 objectB = mFaceParents[hittriangle].mObject;911 normalB = Vector3(normal[0], normal[1], normal[2]);912 // Get the normal of that face913 // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh();914 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;915 //-rays[index+i].mDirection; // $$ temporary916 pointB = viewPoint + dir*dist;917 }908 &dir.x, 909 normal, 910 dist); 911 912 if (hittriangle != -1 ) { 913 if (hittriangle >= mFaceParents.size()) 914 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 915 else { 916 objectB = mFaceParents[hittriangle].mObject; 917 normalB = Vector3(normal[0], normal[1], normal[2]); 918 // Get the normal of that face 919 // Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 920 // normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 921 //-rays[index+i].mDirection; // $$ temporary 922 pointB = viewPoint + dir * dist; 923 } 918 924 } 919 925 920 926 return ProcessRay(viewPoint, 921 922 923 924 925 926 927 927 direction, 928 objectA, pointA, normalA, 929 objectB, pointB, normalB, 930 probability, 931 vssRays, 932 box 933 ); 928 934 #else 929 935 return -1; … … 971 977 else { 972 978 if (hittriangle >= mFaceParents.size()) { 973 cerr<<"Warning: tr aingle index out of range! "<<hittriangle<<endl;979 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 974 980 return NULL; 975 981 } … … 989 995 #endif 990 996 991 992 993 997 } 994 998 … … 1002 1006 ) 1003 1007 { 1004 1008 cout << "internal ray" << endl; 1005 1009 int hits = 0; 1006 1010 static Ray ray; … … 1009 1013 1010 1014 // AxisAlignedBox3 box = Union(mKdTree->GetBox(), mViewCellsManager->GetViewSpaceBox()); 1011 1012 1013 1015 AxisAlignedBox3 sbox = box; 1014 1016 sbox.Enlarge(Vector3(-Limits::Small)); … … 1042 1044 } 1043 1045 1044 1045 1046 SetupRay(ray, viewPoint, -direction); 1046 1047 ray.mFlags &= ~Ray::CULL_BACKFACES; … … 1076 1077 ); 1077 1078 vssRays.push_back(vssRay); 1079 //cout << "ray: " << *vssRay << endl; 1078 1080 hits ++; 1079 1081 } … … 1088 1090 ); 1089 1091 vssRays.push_back(vssRay); 1092 //cout << "ray: " << *vssRay << endl; 1090 1093 hits ++; 1091 1094 } … … 1172 1175 ); 1173 1176 vssRays.push_back(vssRay); 1177 //cout << "ray: " << *vssRay << endl; 1174 1178 hits ++; 1175 1179 } … … 1184 1188 ); 1185 1189 vssRays.push_back(vssRay); 1190 //cout << "ray: " << *vssRay << endl; 1186 1191 hits ++; 1187 1192 } … … 1199 1204 { 1200 1205 int i; 1201 int num = 16;1206 const int num = 16; 1202 1207 1203 1208 #if DEBUG_RAYCAST … … 1214 1219 1215 1220 1216 1217 1218 1221 Vector3 min = sbox.Min(); 1219 1222 Vector3 max = sbox.Max(); 1223 1220 1224 for (i=0; i < num; i++) { 1221 1225 mlrtaStoreRayAS16(&rays[index + i].mOrigin.x, … … 1223 1227 i); 1224 1228 } 1225 1226 1229 1227 1230 mlrtaTraverseGroupAS16(&min.x, … … 1237 1240 } 1238 1241 1239 1240 1242 mlrtaTraverseGroupAS16(&min.x, 1241 1243 &max.x, … … 1244 1246 1245 1247 1246 1247 1248 for (i=0; i < num; i++) { 1248 1249 Intersectable *objectA = NULL, *objectB = NULL; … … 1250 1251 Vector3 normalA, normalB; 1251 1252 1252 1253 1254 if (forward_hit_triangles[i] !=-1 ) { 1253 if (forward_hit_triangles[i] != -1 ) { 1255 1254 if (forward_hit_triangles[i] >= mFaceParents.size()) 1256 cerr<<"Warning: tr aingle index out of range! "<<forward_hit_triangles[i]<<endl;1257 else { 1255 cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl; 1256 else { 1258 1257 objectA = mFaceParents[forward_hit_triangles[i]].mObject; 1259 1258 // Get the normal of that face 1260 Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 1261 normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 1259 normalA = objectA->GetNormal(mFaceParents[forward_hit_triangles[i]].mFaceIndex); 1262 1260 //-rays[index+i].mDirection; // $$ temporary 1263 1261 pointA = rays[index+i].Extrap(forward_dist[i]); 1264 1262 } 1265 1263 } 1266 1264 1267 1265 if (backward_hit_triangles[i]!=-1) { 1268 1266 if (backward_hit_triangles[i] >= mFaceParents.size()) 1269 cerr<<"Warning: tr aingleindex out of range! "<<backward_hit_triangles[i]<<endl;1270 else { 1267 cerr<<"Warning: triangle index out of range! "<<backward_hit_triangles[i]<<endl; 1268 else { 1271 1269 objectB = mFaceParents[backward_hit_triangles[i]].mObject; 1272 Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 1273 1274 normalB = mesh->GetFacePlane(mFaceParents[backward_hit_triangles[i]].mFaceIndex).mNormal; 1275 1276 // normalB = rays[index+i].mDirection; // $$ temporary 1270 normalB = objectB->GetNormal(mFaceParents[forward_hit_triangles[i]].mFaceIndex); 1271 1272 // normalB = rays[index+i].mDirection; // $$ temporary 1277 1273 pointB = rays[index+i].Extrap(-backward_dist[i]); 1278 1274 } 1279 1275 } 1280 1276 1281 1277 ProcessRay(rays[index+i].mOrigin, 1282 1278 rays[index+i].mDirection, … … 1288 1284 ); 1289 1285 } 1286 1290 1287 #endif 1291 1288 … … 1312 1309 { 1313 1310 long t1 = GetTime(); 1314 for (int i=0; i < rays.size(); ) { 1315 if (i + 16 < rays.size()) { 1311 1312 for (int i = 0; i < (int)rays.size(); ) { 1313 // method only available for intel raycaster yet 1314 if (i + 16 < (int)rays.size()) { 1315 1316 1316 CastRays16( 1317 1317 i, … … 1321 1321 i += 16; 1322 1322 } else { 1323 1324 1323 CastRay(rays[i].mOrigin, 1325 1324 rays[i].mDirection, … … 1327 1326 vssRays, 1328 1327 mViewCellsManager->GetViewSpaceBox()); 1329 1330 1328 i++; 1331 1329 } … … 1335 1333 1336 1334 long t2 = GetTime(); 1337 1338 1335 cout<<2*rays.size()/(1e3*TimeDiff(t1, t2))<<"M rays/s"<<endl; 1339 1336 } … … 1354 1351 1355 1352 int hittriangle; 1356 1357 1353 1358 1354 #ifdef GTP_INTERNAL … … 1367 1363 if (hittriangle !=-1 ) { 1368 1364 if (hittriangle >= mFaceParents.size()) 1369 cerr<<"Warning: tr aingle index out of range! "<<hittriangle<<endl;1365 cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl; 1370 1366 else { 1371 1367 result = mFaceParents[hittriangle].mObject; … … 1375 1371 } 1376 1372 #else 1377 hittriangle = -1;1373 hittriangle = -1; 1378 1374 #endif 1379 1375 1380 1381 1376 break; 1382 1377 }
Note: See TracChangeset
for help on using the changeset viewer.