| 62 | } |
| 63 | |
| 64 | void BoundingObjectCutter::GenerateOutputInformation() |
| 65 | { |
| 66 | mitk::Image::Pointer output = this->GetOutput(); |
| 67 | if ((output->IsInitialized()) && (output->GetPipelineMTime() <= m_TimeOfHeaderInitialization.GetMTime())) |
| 68 | return; |
| 69 | |
| 70 | mitk::Image::Pointer input = this->GetInput(); |
| 71 | |
| 72 | if (input.IsNull()) |
| 73 | { |
| 74 | mitkThrow() << "Input is not a mitk::Image"; |
| 75 | } |
| 76 | itkDebugMacro(<< "GenerateOutputInformation()"); |
| 77 | unsigned int dimension = input->GetDimension(); |
| 78 | |
| 79 | if (dimension < 3) |
| 80 | { |
| 81 | mitkThrow() << "ImageCropper cannot handle 1D or 2D Objects."; |
| 82 | } |
| 83 | |
| 84 | if ((m_BoundingObject.IsNull()) || (m_BoundingObject->GetTimeGeometry()->CountTimeSteps() == 0)) |
| 85 | return; |
| 86 | |
| 87 | mitk::BaseGeometry *boGeometry = m_BoundingObject->GetGeometry(); |
| 88 | mitk::BaseGeometry *inputImageGeometry = input->GetSlicedGeometry(); |
| 89 | // calculate bounding box of bounding-object relative to the geometry |
| 90 | // of the input image. The result is in pixel coordinates of the input |
| 91 | // image (because the m_IndexToWorldTransform includes the spacing). |
| 92 | mitk::BoundingBox::Pointer boBoxRelativeToImage = |
| 93 | boGeometry->CalculateBoundingBoxRelativeToTransform(inputImageGeometry->GetIndexToWorldTransform()); |
| 94 | |
| 95 | // PART I: initialize input requested region. We do this already here (and not |
| 96 | // later when GenerateInputRequestedRegion() is called), because we |
| 97 | // also need the information to setup the output. |
| 98 | |
| 99 | // pre-initialize input-requested-region to largest-possible-region |
| 100 | // and correct time-region; spatial part will be cropped by |
| 101 | // bounding-box of bounding-object below |
| 102 | m_InputRequestedRegion = input->GetLargestPossibleRegion(); |
| 103 | |
| 104 | // build region out of bounding-box of bounding-object |
| 105 | mitk::SlicedData::IndexType index = m_InputRequestedRegion.GetIndex(); // init times and channels |
| 106 | mitk::BoundingBox::PointType min = boBoxRelativeToImage->GetMinimum(); |
| 107 | index[0] = (mitk::SlicedData::IndexType::IndexValueType)(std::ceil(min[0])); |
| 108 | index[1] = (mitk::SlicedData::IndexType::IndexValueType)(std::ceil(min[1])); |
| 109 | index[2] = (mitk::SlicedData::IndexType::IndexValueType)(std::ceil(min[2])); |
| 110 | |
| 111 | mitk::SlicedData::SizeType size = m_InputRequestedRegion.GetSize(); // init times and channels |
| 112 | mitk::BoundingBox::PointType max = boBoxRelativeToImage->GetMaximum(); |
| 113 | size[0] = (mitk::SlicedData::SizeType::SizeValueType)(std::ceil(max[0]) - index[0]); |
| 114 | size[1] = (mitk::SlicedData::SizeType::SizeValueType)(std::ceil(max[1]) - index[1]); |
| 115 | size[2] = (mitk::SlicedData::SizeType::SizeValueType)(std::ceil(max[2]) - index[2]); |
| 116 | |
| 117 | mitk::SlicedData::RegionType boRegion(index, size); |
| 118 | |
| 119 | if (m_UseWholeInputRegion == false) |
| 120 | { |
| 121 | // crop input-requested-region with region of bounding-object |
nothing calls this directly
no test coverage detected