------------------------------------------------------------------------------
| 1266 | |
| 1267 | //------------------------------------------------------------------------------ |
| 1268 | double vtkCellPicker::IntersectImageWithLine(const double p1[3], const double p2[3], double t1, |
| 1269 | double t2, vtkProp3D* prop, vtkImageMapper3D* imageMapper) |
| 1270 | { |
| 1271 | // Get the image information |
| 1272 | vtkImageData* data = imageMapper->GetInput(); |
| 1273 | int extent[6]; |
| 1274 | data->GetExtent(extent); |
| 1275 | |
| 1276 | // Get the plane equation for the slice |
| 1277 | double normal[4]; |
| 1278 | imageMapper->GetSlicePlaneInDataCoords(prop->GetMatrix(), normal); |
| 1279 | |
| 1280 | // Point the normal towards camera |
| 1281 | if (normal[0] * (p1[0] - p2[0]) + normal[1] * (p1[1] - p2[1]) + normal[2] * (p1[2] - p2[2]) < 0) |
| 1282 | { |
| 1283 | normal[0] = -normal[0]; |
| 1284 | normal[1] = -normal[1]; |
| 1285 | normal[2] = -normal[2]; |
| 1286 | normal[3] = -normal[3]; |
| 1287 | } |
| 1288 | |
| 1289 | // And convert plane eqn to structured coords |
| 1290 | double xnormal[4]; |
| 1291 | data->TransformPhysicalPlaneToContinuousIndex(normal, xnormal); |
| 1292 | |
| 1293 | // Also convert ray to structured coords |
| 1294 | double x1[3], x2[3]; |
| 1295 | data->TransformPhysicalPointToContinuousIndex(p1, x1); |
| 1296 | data->TransformPhysicalPointToContinuousIndex(p2, x2); |
| 1297 | |
| 1298 | // Get the bounds to discover any cropping that has been applied |
| 1299 | double bounds[6]; |
| 1300 | imageMapper->GetIndexBounds(bounds); |
| 1301 | |
| 1302 | // Clip the ray with the extent |
| 1303 | int planeId, plane2Id; |
| 1304 | double tMin, tMax; |
| 1305 | if (!vtkBox::IntersectWithLine(bounds, x1, x2, tMin, tMax, nullptr, nullptr, planeId, plane2Id)) |
| 1306 | { |
| 1307 | return VTK_DOUBLE_MAX; |
| 1308 | } |
| 1309 | |
| 1310 | if (tMin != tMax) |
| 1311 | { |
| 1312 | // Intersect the ray with the slice plane |
| 1313 | double w1 = vtkMath::Dot(x1, xnormal) + xnormal[3]; |
| 1314 | double w2 = vtkMath::Dot(x2, xnormal) + xnormal[3]; |
| 1315 | if (w1 * w2 > VTKCELLPICKER_VOXEL_TOL) |
| 1316 | { |
| 1317 | return VTK_DOUBLE_MAX; |
| 1318 | } |
| 1319 | if (w1 * w2 < 0) |
| 1320 | { |
| 1321 | tMin = w1 / (w1 - w2); |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | // Make sure that intersection is within clipping planes |
no test coverage detected