| 36 | } |
| 37 | |
| 38 | bool ComputeGlobalOrigin(vtkVector3d& origin, const std::vector<vtkImageData*>& images, |
| 39 | vtkMultiProcessController* controller, const int minimumExtent[3]) |
| 40 | { |
| 41 | // First, confirm that spacing is compatible. All images must have the same |
| 42 | // spacing otherwise we cannot pick a valid global origin/extent. |
| 43 | vtkVector3d spacing = |
| 44 | images.empty() ? vtkVector3d(0.0) : vtkVector3d(images.front()->GetSpacing()); |
| 45 | for (auto* image : images) |
| 46 | { |
| 47 | if (image->GetNumberOfPoints() > 0) |
| 48 | { |
| 49 | const vtkVector3d imgSpacing(image->GetSpacing()); |
| 50 | if (spacing != imgSpacing) |
| 51 | { |
| 52 | spacing = vtkVector3d(VTK_DOUBLE_MAX); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | vtkVector3d globalSpacing = AllGather(spacing, controller); |
| 58 | if (!IsSpacingValid(globalSpacing)) |
| 59 | { |
| 60 | vtkLogF(ERROR, "Cannot determine acceptable global spacing."); |
| 61 | return false; |
| 62 | } |
| 63 | |
| 64 | // Compute global bounds to determine the global image origin. |
| 65 | vtkBoundingBox bbox; |
| 66 | for (auto* image : images) |
| 67 | { |
| 68 | bbox.AddBounds(image->GetBounds()); |
| 69 | } |
| 70 | |
| 71 | vtkBoundingBox globalBounds; |
| 72 | controller->AllReduce(bbox, globalBounds); |
| 73 | globalBounds.GetMinPoint(origin.GetData()); |
| 74 | |
| 75 | // globalOrigin is based on the extent set at (0, 0, 0) right now. we need to adjust |
| 76 | // globalOrigin based on minimumExtent though. |
| 77 | for (int cc = 0; cc < 3; ++cc) |
| 78 | { |
| 79 | origin[cc] -= minimumExtent[cc] * spacing[cc]; |
| 80 | } |
| 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | } |
| 86 |
no test coverage detected