Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include "mitkImageAccessByItk.h"
16 #include "mitkImageCast.h"
17 
18 #include <mitkLabelSetImage.h>
19 #include <mitkLabelSetImage.h>
20 #include <mitkSurface.h>
22 
23 mitk::LabelSetImageSurfaceStampFilter::LabelSetImageSurfaceStampFilter() : m_ForceOverwrite(false)
24 {
25  this->SetNumberOfIndexedInputs(1);
26  this->SetNumberOfRequiredInputs(1);
27 }
28 
29 mitk::LabelSetImageSurfaceStampFilter::~LabelSetImageSurfaceStampFilter()
30 {
31 }
32 
33 void mitk::LabelSetImageSurfaceStampFilter::GenerateData()
34 {
35  // GenerateOutputInformation();
36  this->SetNthOutput(0, this->GetInput(0));
37 
38  mitk::Image::Pointer inputImage = this->GetInput(0);
39 
40  if (m_Surface.IsNull())
41  {
42  MITK_ERROR << "Input surface is nullptr.";
43  return;
44  }
45 
47  surfaceToImageFilter->MakeOutputBinaryOn();
48  surfaceToImageFilter->SetInput(m_Surface);
49  surfaceToImageFilter->SetImage(inputImage);
50  surfaceToImageFilter->Update();
51  mitk::Image::Pointer resultImage = surfaceToImageFilter->GetOutput();
52 
53  AccessByItk_1(inputImage, ItkImageProcessing, resultImage);
54  inputImage->DisconnectPipeline();
55 }
56 
57 template <typename TPixel, unsigned int VImageDimension>
58 void mitk::LabelSetImageSurfaceStampFilter::ItkImageProcessing(itk::Image<TPixel, VImageDimension> *itkImage,
59  mitk::Image::Pointer resultImage)
60 {
61  typedef itk::Image<TPixel, VImageDimension> ImageType;
62  mitk::LabelSetImage::Pointer LabelSetInputImage = dynamic_cast<LabelSetImage *>(GetInput());
63  try
64  {
65  typename ImageType::Pointer itkResultImage = ImageType::New();
66  mitk::CastToItkImage(resultImage, itkResultImage);
67 
68  typedef itk::ImageRegionConstIterator<ImageType> SourceIteratorType;
69  typedef itk::ImageRegionIterator<ImageType> TargetIteratorType;
70 
71  SourceIteratorType sourceIter(itkResultImage, itkResultImage->GetLargestPossibleRegion());
72  sourceIter.GoToBegin();
73 
74  TargetIteratorType targetIter(itkImage, itkImage->GetLargestPossibleRegion());
75  targetIter.GoToBegin();
76 
77  int activeLabel = (LabelSetInputImage->GetActiveLabel(LabelSetInputImage->GetActiveLayer()))->GetValue();
78 
79  while (!sourceIter.IsAtEnd())
80  {
81  auto sourceValue = static_cast<int>(sourceIter.Get());
82  auto targetValue = static_cast<int>(targetIter.Get());
83 
84  if ((sourceValue != 0) &&
85  (m_ForceOverwrite ||
86  !LabelSetInputImage->GetLabel(targetValue)->GetLocked())) // skip exterior and locked labels
87  {
88  targetIter.Set(activeLabel);
89  }
90  ++sourceIter;
91  ++targetIter;
92  }
93  }
94  catch (itk::ExceptionObject &e)
95  {
96  mitkThrow() << e.GetDescription();
97  }
98  this->Modified();
99 }
100 
101 void mitk::LabelSetImageSurfaceStampFilter::GenerateOutputInformation()
102 {
103  mitk::Image::Pointer inputImage = (mitk::Image *)this->GetInput();
104  mitk::Image::Pointer output = this->GetOutput();
105  itkDebugMacro(<< "GenerateOutputInformation()");
106  if (inputImage.IsNull())
107  return;
108 }
itk::Image< unsigned char, 3 > ImageType
#define MITK_ERROR
Definition: mitkLogMacros.h:20
#define AccessByItk_1(mitkImage, itkImageTypeFunction, arg1)
#define mitkThrow()
Image class for storing images.
Definition: mitkImage.h:72
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
OutputType * GetOutput()
Get the output data of this image source object.