18 #include <itkAndImageFilter.h>
19 #include <itkNotImageFilter.h>
20 #include <itkOrImageFilter.h>
25 typedef itk::Image<mitk::Label::PixelType, 3>
ImageType;
29 if (segmentation->GetDimension() != 4)
33 imageTimeSelector->SetInput(segmentation);
34 imageTimeSelector->SetTimeNr(static_cast<int>(time));
36 imageTimeSelector->UpdateLargestPossibleRegion();
38 return imageTimeSelector->GetOutput();
52 : m_Type(type), m_SegmentationA(segmentationA), m_SegmentationB(segmentationB), m_Time(time)
54 this->ValidateSegmentations();
66 return this->GetDifference();
69 return this->GetIntersection();
72 return this->GetUnion();
75 mitkThrow() <<
"Unknown boolean operation type '" << m_Type <<
"'!";
85 notFilter->SetInput(input2);
88 andFilter->SetInput1(input1);
89 andFilter->SetInput2(notFilter->GetOutput());
91 andFilter->UpdateLargestPossibleRegion();
94 CastToMitkImage<ImageType>(andFilter->GetOutput(), tempResult);
96 tempResult->DisconnectPipeline();
99 result->InitializeByLabeledImage(tempResult);
110 andFilter->SetInput1(input1);
111 andFilter->SetInput2(input2);
113 andFilter->UpdateLargestPossibleRegion();
116 CastToMitkImage<ImageType>(andFilter->GetOutput(), tempResult);
118 tempResult->DisconnectPipeline();
121 result->InitializeByLabeledImage(tempResult);
132 orFilter->SetInput1(input1);
133 orFilter->SetInput2(input2);
135 orFilter->UpdateLargestPossibleRegion();
138 CastToMitkImage<ImageType>(orFilter->GetOutput(), tempResult);
140 tempResult->DisconnectPipeline();
143 result->InitializeByLabeledImage(tempResult);
150 if (segmentation.IsNull())
153 if (segmentation->GetImageDescriptor()->GetNumberOfChannels() != 1)
154 mitkThrow() <<
"Segmentation has more than one channel!";
156 auto pixelType = segmentation->GetImageDescriptor()->GetChannelDescriptor().GetPixelType();
158 if (pixelType.GetPixelType() != itk::ImageIOBase::SCALAR ||
159 (pixelType.GetComponentType() != itk::ImageIOBase::UCHAR &&
160 pixelType.GetComponentType() != itk::ImageIOBase::USHORT))
161 mitkThrow() <<
"Segmentation is neither of type 'unsigned char' nor type 'unsigned short'!";
163 auto dimension = segmentation->GetDimension();
166 mitkThrow() <<
"Segmentation has more than four dimensions!";
171 mitkThrow() <<
"Expected four-dimensional segmentation!";
173 if (segmentation->GetDimension(3) < m_Time)
174 mitkThrow() <<
"Extent of fourth dimension of segmentation is less than specified time!";
176 else if (dimension < 3)
178 mitkThrow() <<
"Segmentation has less than three dimensions!";
182 void mitk::BooleanOperation::ValidateSegmentations()
const
184 this->ValidateSegmentation(m_SegmentationA);
185 this->ValidateSegmentation(m_SegmentationB);
187 if (m_SegmentationA->GetDimension() != m_SegmentationB->GetDimension())
188 mitkThrow() <<
"Segmentations have different dimensions!";
itk::SmartPointer< Self > Pointer
itk::Image< mitk::Label::PixelType, 3 > ImageType
LabelSetImage::Pointer GetResult() const
static mitk::Image::Pointer Get3DSegmentation(mitk::Image::Pointer segmentation, unsigned int time)
BooleanOperation(Type type, Image::Pointer segmentationA, Image::Pointer segmentationB, unsigned int time=0)
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
static ImageType::Pointer CastTo3DItkImage(mitk::Image::Pointer segmentation, unsigned int time)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.