Changeset 1281 for GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
- Timestamp:
- 08/24/06 22:23:33 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1279 r1281 906 906 tPoint[2] = pforg[2] + pfdir[2] * dist; 907 907 908 return mFaceParents[hittriangle] ;908 return mFaceParents[hittriangle].mObject; 909 909 } 910 910 } … … 1013 1013 1014 1014 1015 int 1016 Preprocessor::ProcessRay( 1017 Vector3 &viewPoint, 1018 Vector3 &direction, 1019 Intersectable *objectA, 1020 Vector3 &pointA, 1021 Vector3 &normalA, 1022 Intersectable *objectB, 1023 Vector3 &pointB, 1024 Vector3 &normalB, 1025 const float probability, 1026 VssRayContainer &vssRays, 1027 const AxisAlignedBox3 &box 1028 ) 1029 { 1030 int hits=0; 1031 1032 if (objectA == NULL && objectB == NULL) 1033 return 0; 1034 1035 AxisAlignedBox3 sbox = box; 1036 sbox.Enlarge(Vector3(-Limits::Small)); 1037 1038 1039 if (!sbox.IsInside(viewPoint)) 1040 return 0; 1041 1042 if (objectA == NULL) { 1043 // compute intersection with the scene bounding box 1044 static Ray ray; 1045 SetupRay(ray, viewPoint, direction); 1046 1047 float tmin, tmax; 1048 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 1049 pointA = ray.Extrap(tmax); 1050 else 1051 return 0; 1052 } else { 1053 if (mDetectEmptyViewSpace) 1054 if (DotProd(normalA, direction) >= 0) { 1055 // discard the sample 1056 return 0; 1057 } 1058 } 1059 1060 if (objectB == NULL) { 1061 // compute intersection with the scene bounding box 1062 static Ray ray; 1063 SetupRay(ray, viewPoint, -direction); 1064 1065 float tmin, tmax; 1066 if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax) 1067 pointB = ray.Extrap(tmax); 1068 else 1069 return 0; 1070 } else { 1071 if (mDetectEmptyViewSpace) 1072 if (DotProd(normalB, direction) <= 0) { 1073 // discard the sample 1074 return 0; 1075 } 1076 } 1077 1078 VssRay *vssRay = NULL; 1079 bool validSample = (objectA != objectB); 1080 if (validSample) { 1081 if (objectA) { 1082 vssRay = new VssRay(pointB, 1083 pointA, 1084 objectB, 1085 objectA, 1086 mPass, 1087 probability 1088 ); 1089 vssRays.push_back(vssRay); 1090 hits ++; 1091 } 1092 1093 if (objectB) { 1094 vssRay = new VssRay(pointA, 1095 pointB, 1096 objectA, 1097 objectB, 1098 mPass, 1099 probability 1100 ); 1101 vssRays.push_back(vssRay); 1102 hits ++; 1103 } 1104 } 1105 1106 return hits; 1107 } 1108 1109 void 1110 Preprocessor::CastRays16(const int index, 1111 SimpleRayContainer &rays, 1112 VssRayContainer &vssRays, 1113 const AxisAlignedBox3 &sbox) 1114 { 1115 int i; 1116 int num = 16; 1117 1118 if (mRayCastMethod == INTEL_RAYCASTER) { 1119 #ifdef GTP_INTERNAL 1120 1121 int forward_hit_triangles[16]; 1122 float forward_dist[16]; 1123 1124 int backward_hit_triangles[16]; 1125 float backward_dist[16]; 1126 1127 Vector3 min = sbox.Min(); 1128 Vector3 max = sbox.Max(); 1129 1130 for (i=0; i < num; i++) { 1131 mlrtaStoreRayAS16(&rays[index + i].mOrigin.x, 1132 &rays[index + i].mDirection.x, 1133 i); 1134 } 1135 1136 1137 mlrtaTraverseGroupAS16(&min.x, 1138 &max.x, 1139 forward_hit_triangles, 1140 forward_dist); 1141 1142 for (i=0; i < num; i++) { 1143 Vector3 dir = -rays[index+i].mDirection; 1144 mlrtaStoreRayAS16(&rays[index+i].mOrigin.x, 1145 &dir.x, 1146 i); 1147 } 1148 1149 1150 mlrtaTraverseGroupAS16(&min.x, 1151 &max.x, 1152 backward_hit_triangles, 1153 backward_dist); 1154 1155 1156 for (i=0; i < num; i++) { 1157 Intersectable *objectA = NULL, *objectB = NULL; 1158 Vector3 pointA, pointB; 1159 Vector3 normalA, normalB; 1160 if (forward_hit_triangles[i] !=-1 ) { 1161 objectA = mFaceParents[forward_hit_triangles[i]].mObject; 1162 // Get the normal of that face 1163 Mesh *mesh = ((MeshInstance *)objectA)->GetMesh(); 1164 normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal; 1165 //-rays[index+i].mDirection; // $$ temporary 1166 pointA = rays[index+i].Extrap(forward_dist[i]); 1167 } 1168 1169 if (backward_hit_triangles[i]!=-1) { 1170 objectB = mFaceParents[backward_hit_triangles[i]].mObject; 1171 Mesh *mesh = ((MeshInstance *)objectB)->GetMesh(); 1172 1173 normalB = mesh->GetFacePlane(mFaceParents[backward_hit_triangles[i]].mFaceIndex).mNormal; 1174 1175 // normalB = rays[index+i].mDirection; // $$ temporary 1176 pointB = rays[index+i].Extrap(-backward_dist[i]); 1177 } 1178 1179 ProcessRay(rays[index+i].mOrigin, 1180 rays[index+i].mDirection, 1181 objectA, pointA, normalA, 1182 objectB, pointB, normalB, 1183 rays[index+i].mPdf, 1184 vssRays, 1185 sbox 1186 ); 1187 } 1188 #endif 1189 } else { 1190 1191 for (i=index; i < index + num; i++) { 1192 CastRay(rays[i].mOrigin, 1193 rays[i].mDirection, 1194 rays[i].mPdf, 1195 vssRays, 1196 sbox); 1197 } 1198 } 1199 1200 } 1201 1202 void 1203 Preprocessor::CastRays( 1204 SimpleRayContainer &rays, 1205 VssRayContainer &vssRays 1206 ) 1207 { 1208 long t1 = GetTime(); 1209 for (int i=0; i < rays.size(); ) { 1210 if (i + 16 < rays.size()) { 1211 CastRays16( 1212 i, 1213 rays, 1214 vssRays, 1215 mViewCellsManager->GetViewSpaceBox()); 1216 i += 16; 1217 } else { 1218 CastRay(rays[i].mOrigin, 1219 rays[i].mDirection, 1220 rays[i].mPdf, 1221 vssRays, 1222 mViewCellsManager->GetViewSpaceBox()); 1223 i++; 1224 } 1225 if (i % 10000 == 0) 1226 cout<<"."; 1227 } 1228 1229 long t2 = GetTime(); 1230 1231 cout<<2*rays.size()/(1e3*TimeDiff(t1, t2))<<"M rays/s"<<endl; 1232 } 1233 1015 1234 int Preprocessor::CastRay( 1016 1235 const Vector3 &viewPoint,
Note: See TracChangeset
for help on using the changeset viewer.