28 #include <itkImageRegionIterator.h>
29 #include <itkImageSliceIteratorWithIndex.h>
37 m_CreateUndoInformation(false)
39 MITK_WARN <<
"Class is deprecated! Use mitkVtkImageOverwrite instead.";
66 if (input.IsNull() || slice.IsNull())
69 switch (m_SliceDimension)
86 if (slice->GetDimension() < 2 || input->GetDimension() > 4 ||
87 slice->GetDimension(0) != input->GetDimension(m_Dimension0) ||
88 slice->GetDimension(1) != input->GetDimension(m_Dimension1) ||
89 m_SliceIndex >= input->GetDimension(m_SliceDimension))
91 itkExceptionMacro(
"Slice and image dimensions differ or slice index is too large. Sorry, cannot work like this.");
95 if (input->GetDimension() == 4)
98 timeSelector->SetInput(input);
99 timeSelector->SetTimeNr(m_TimeStep);
100 timeSelector->UpdateLargestPossibleRegion();
101 input3D = timeSelector->GetOutput();
104 if (m_SliceDifferenceImage.IsNull() || m_SliceDifferenceImage->GetDimension(0) != m_SliceImage->GetDimension(0) ||
105 m_SliceDifferenceImage->GetDimension(1) != m_SliceImage->GetDimension(1))
108 mitk::PixelType pixelType(mitk::MakeScalarPixelType<short signed int>());
109 m_SliceDifferenceImage->Initialize(pixelType, 2, m_SliceImage->GetDimensions());
121 interpolator->
SetChangedSlice(m_SliceDifferenceImage, m_SliceDimension, m_SliceIndex, m_TimeStep);
124 if (m_CreateUndoInformation)
129 const_cast<Image *>(input.GetPointer()),
130 m_SliceDifferenceImage,
135 const_cast<Image *>(input.GetPointer()),
136 m_SliceDifferenceImage,
140 undoOp->SetFactor(-1.0);
145 this->EventDescription(m_SliceDimension, m_SliceIndex, m_TimeStep));
160 #define myMITKOverwriteSliceImageFilterAccessByItk(mitkImage, itkImageTypeFunction, pixeltype, dimension, itkimage2) \
161 if (typeId == MapPixelComponentType<pixeltype>::value) \
164 typedef itk::Image<pixeltype, dimension> ImageType; \
165 typedef mitk::ImageToItk<ImageType> ImageToItkType; \
166 itk::SmartPointer<ImageToItkType> imagetoitk = ImageToItkType::New(); \
167 const mitk::Image *constImage = mitkImage; \
168 mitk::Image *nonConstImage = const_cast<mitk::Image *>(constImage); \
169 nonConstImage->Update(); \
170 imagetoitk->SetInput(nonConstImage); \
171 imagetoitk->Update(); \
172 itkImageTypeFunction(imagetoitk->GetOutput(), itkimage2); \
176 #define myMITKOverwriteSliceImageFilterAccessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension, itkimage2) \
179 myMITKOverwriteSliceImageFilterAccessByItk( \
181 itkImageTypeFunction, \
184 itkimage2) else myMITKOverwriteSliceImageFilterAccessByItk(mitkImage, \
185 itkImageTypeFunction, \
188 itkimage2) else myMITKOverwriteSliceImageFilterAccessByItk(mitkImage, itkImageTypeFunction, int, dimension, itkimage2) else myMITKOverwriteSliceImageFilterAccessByItk(mitkImage, itkImageTypeFunction, unsigned int, dimension, itkimage2) else myMITKOverwriteSliceImageFilterAccessByItk(mitkImage, \
189 itkImageTypeFunction, \
192 itkimage2) else myMITKOverwriteSliceImageFilterAccessByItk(mitkImage, itkImageTypeFunction, unsigned short, dimension, itkimage2) else myMITKOverwriteSliceImageFilterAccessByItk(mitkImage, \
193 itkImageTypeFunction, \
196 itkimage2) else myMITKOverwriteSliceImageFilterAccessByItk(mitkImage, \
197 itkImageTypeFunction, \
204 template <
typename TPixel,
unsigned int VImageDimension>
207 const int typeId = m_SliceImage->GetPixelType().GetComponentType();
212 template <
typename TPixel1,
unsigned int VImageDimension1,
typename TPixel2,
unsigned int VImageDimension2>
214 itk::Image<TPixel2, VImageDimension2> *outputImage)
216 typedef itk::Image<TPixel1, VImageDimension1> SliceImageType;
217 typedef itk::Image<short signed int, VImageDimension1> DiffImageType;
218 typedef itk::Image<TPixel2, VImageDimension2> VolumeImageType;
220 typedef itk::ImageSliceIteratorWithIndex<VolumeImageType> OutputSliceIteratorType;
221 typedef itk::ImageRegionConstIterator<SliceImageType> InputSliceIteratorType;
222 typedef itk::ImageRegionIterator<DiffImageType> DiffSliceIteratorType;
224 typename VolumeImageType::RegionType sliceInVolumeRegion;
226 sliceInVolumeRegion = outputImage->GetLargestPossibleRegion();
227 sliceInVolumeRegion.SetSize(m_SliceDimension, 1);
228 sliceInVolumeRegion.SetIndex(m_SliceDimension, m_SliceIndex);
230 OutputSliceIteratorType outputIterator(outputImage, sliceInVolumeRegion);
231 outputIterator.SetFirstDirection(m_Dimension0);
232 outputIterator.SetSecondDirection(m_Dimension1);
234 InputSliceIteratorType inputIterator(inputImage, inputImage->GetLargestPossibleRegion());
238 DiffSliceIteratorType diffIterator(diffImage, diffImage->GetLargestPossibleRegion());
241 outputIterator.GoToBegin();
242 inputIterator.GoToBegin();
243 diffIterator.GoToBegin();
244 while (!outputIterator.IsAtEnd())
246 while (!outputIterator.IsAtEndOfSlice())
248 while (!outputIterator.IsAtEndOfLine())
250 diffIterator.Set(static_cast<short signed int>(inputIterator.Get() -
251 outputIterator.Get()));
252 outputIterator.Set((TPixel2)inputIterator.Get());
257 outputIterator.NextLine();
259 outputIterator.NextSlice();
264 unsigned int sliceIndex,
265 unsigned int timeStep)
269 s <<
"Changed slice (";
271 switch (sliceDimension)
285 s <<
" " << sliceIndex <<
" " << timeStep <<
")";
void ItkImageProcessing(const itk::Image< TPixel1, VImageDimension1 > *itkImage1, itk::Image< TPixel2, VImageDimension2 > *itkImage2)
Operation, that holds information about some image difference.
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
void SetChangedSlice(const Image *sliceDiff, unsigned int sliceDimension, unsigned int sliceIndex, unsigned int timeStep)
Update after changing a single slice.
Generates interpolations of 2D slices.
Constants for most interaction classes, due to the generic StateMachines.
void BlockModified(bool)
Block reaction to an images Modified() events.
#define myMITKOverwriteSliceImageFilterAccessAllTypesByItk(mitkImage, itkImageTypeFunction, dimension, itkimage2)
static DiffImageApplier * GetInstanceForUndo()
std::string EventDescription(unsigned int sliceDimension, unsigned int sliceIndex, unsigned int timeStep)
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
static SegmentationInterpolationController * InterpolatorForImage(const Image *)
Find interpolator for a given image.
InputImageType * GetInput(void)
virtual ~OverwriteSliceImageFilter()
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
virtual bool SetOperationEvent(UndoStackItem *stackItem)=0
static UndoModel * GetCurrentUndoModel()
gives access to the currently used UndoModel Introduced to access special functions of more specific ...
static void IncCurrObjectEventId()
Increases the current ObjectEventId For example if a button click generates operations the ObjectEven...
void ItkImageSwitch(itk::Image< TPixel, VImageDimension > *image)
OverwriteSliceImageFilter()
Represents a pair of operations: undo and the according redo.
Class for defining the data type of pixels.