Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkLabelSetImageSurfaceStampFilter.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include "mitkImageAccessByItk.h"
20 #include "mitkImageCast.h"
21 
22 #include <mitkLabelSetImage.h>
23 #include <mitkLabelSetImage.h>
24 #include <mitkSurface.h>
26 
27 mitk::LabelSetImageSurfaceStampFilter::LabelSetImageSurfaceStampFilter()
28 {
29  this->SetNumberOfIndexedInputs(1);
30  this->SetNumberOfRequiredInputs(1);
31 }
32 
33 mitk::LabelSetImageSurfaceStampFilter::~LabelSetImageSurfaceStampFilter()
34 {
35 }
36 
37 void mitk::LabelSetImageSurfaceStampFilter::GenerateData()
38 {
39  // GenerateOutputInformation();
40  this->SetNthOutput(0, this->GetInput(0));
41 
42  mitk::Image::Pointer inputImage = this->GetInput(0);
43 
44  if (m_Surface.IsNull())
45  {
46  MITK_ERROR << "Input surface is NULL.";
47  return;
48  }
49 
51  surfaceToImageFilter->MakeOutputBinaryOn();
52  surfaceToImageFilter->SetInput(m_Surface);
53  surfaceToImageFilter->SetImage(inputImage);
54  surfaceToImageFilter->Update();
55  mitk::Image::Pointer resultImage = surfaceToImageFilter->GetOutput();
56 
57  AccessByItk_1(inputImage, ItkImageProcessing, resultImage);
58  inputImage->DisconnectPipeline();
59 }
60 
61 template <typename TPixel, unsigned int VImageDimension>
62 void mitk::LabelSetImageSurfaceStampFilter::ItkImageProcessing(itk::Image<TPixel, VImageDimension> *itkImage,
63  mitk::Image::Pointer resultImage)
64 {
65  typedef itk::Image<TPixel, VImageDimension> ImageType;
66  mitk::LabelSetImage::Pointer LabelSetInputImage = dynamic_cast<LabelSetImage *>(GetInput());
67  try
68  {
69  typename ImageType::Pointer itkResultImage = ImageType::New();
70  mitk::CastToItkImage(resultImage, itkResultImage);
71 
72  typedef itk::ImageRegionConstIterator<ImageType> SourceIteratorType;
73  typedef itk::ImageRegionIterator<ImageType> TargetIteratorType;
74 
75  SourceIteratorType sourceIter(itkResultImage, itkResultImage->GetLargestPossibleRegion());
76  sourceIter.GoToBegin();
77 
78  TargetIteratorType targetIter(itkImage, itkImage->GetLargestPossibleRegion());
79  targetIter.GoToBegin();
80 
81  int activeLabel = (LabelSetInputImage->GetActiveLabel(LabelSetInputImage->GetActiveLayer()))->GetValue();
82 
83  while (!sourceIter.IsAtEnd())
84  {
85  int sourceValue = static_cast<int>(sourceIter.Get());
86  int targetValue = static_cast<int>(targetIter.Get());
87 
88  if ((sourceValue != 0) &&
89  (m_ForceOverwrite ||
90  !LabelSetInputImage->GetLabel(targetValue)->GetLocked())) // skip exterior and locked labels
91  {
92  targetIter.Set(activeLabel);
93  }
94  ++sourceIter;
95  ++targetIter;
96  }
97  }
98  catch (itk::ExceptionObject &e)
99  {
100  mitkThrow() << e.GetDescription();
101  }
102  this->Modified();
103 }
104 
105 void mitk::LabelSetImageSurfaceStampFilter::GenerateOutputInformation()
106 {
107  mitk::Image::Pointer inputImage = (mitk::Image *)this->GetInput();
108  mitk::Image::Pointer output = this->GetOutput();
109  itkDebugMacro(<< "GenerateOutputInformation()");
110  if (inputImage.IsNull())
111  return;
112 }
itk::SmartPointer< Self > Pointer
#define MITK_ERROR
Definition: mitkLogMacros.h:24
#define AccessByItk_1(mitkImage, itkImageTypeFunction, arg1)
map::core::discrete::Elements< 3 >::InternalImageType ImageType
#define mitkThrow()
Image class for storing images.
Definition: mitkImage.h:76
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 itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.