Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkManualSegmentationToSurfaceFilter.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 <vtkImageShiftScale.h>
20 #include <vtkSmartPointer.h>
21 
22 #include "mitkProgressBar.h"
23 
25 {
26  m_MedianFilter3D = false;
32  m_Interpolation = false;
33  m_InterpolationX = 1.0f;
34  m_InterpolationY = 1.0f;
35  m_InterpolationZ = 1.0f;
36 };
37 
39 
41 {
42  mitk::Surface *surface = this->GetOutput();
43  mitk::Image *image = (mitk::Image *)GetInput();
44  mitk::Image::RegionType outputRegion = image->GetRequestedRegion();
45 
46  int tstart = outputRegion.GetIndex(3);
47  int tmax = tstart + outputRegion.GetSize(3); // GetSize()==1 - will aber 0 haben, wenn nicht zeitaufgeloest
48 
49  ScalarType thresholdExpanded = this->m_Threshold;
50 
51  if ((tmax - tstart) > 0)
52  {
53  ProgressBar::GetInstance()->AddStepsToDo(7 * (tmax - tstart));
54  }
55  else
56  {
58  }
59 
60  for (int t = tstart; t < tmax; ++t)
61  {
62  vtkSmartPointer<vtkImageData> vtkimage = image->GetVtkImageData(t);
63 
64  // Median -->smooth 3D
65  MITK_INFO << (m_MedianFilter3D ? "Applying median..." : "No median filtering");
66  if (m_MedianFilter3D)
67  {
68  vtkImageMedian3D *median = vtkImageMedian3D::New();
69  median->SetInputData(vtkimage); // RC++ (VTK < 5.0)
70  median->SetKernelSize(m_MedianKernelSizeX, m_MedianKernelSizeY, m_MedianKernelSizeZ); // Std: 3x3x3
71  median->ReleaseDataFlagOn();
72  median->UpdateInformation();
73  median->Update();
74  vtkimage = median->GetOutput(); //->Out
75  median->Delete();
76  }
78 
79  // Interpolate image spacing
80  MITK_INFO << (m_Interpolation ? "Resampling..." : "No resampling");
81  if (m_Interpolation)
82  {
83  vtkImageResample *imageresample = vtkImageResample::New();
84  imageresample->SetInputData(vtkimage);
85 
86  // Set Spacing Manual to 1mm in each direction (Original spacing is lost during image processing)
87  imageresample->SetAxisOutputSpacing(0, m_InterpolationX);
88  imageresample->SetAxisOutputSpacing(1, m_InterpolationY);
89  imageresample->SetAxisOutputSpacing(2, m_InterpolationZ);
90  imageresample->UpdateInformation();
91  imageresample->Update();
92  vtkimage = imageresample->GetOutput(); //->Output
93  imageresample->Delete();
94  }
96 
97  MITK_INFO << (m_UseGaussianImageSmooth ? "Applying gaussian smoothing..." : "No gaussian smoothing");
98  if (m_UseGaussianImageSmooth) // gauss
99  {
100  vtkImageShiftScale *scalefilter = vtkImageShiftScale::New();
101  scalefilter->SetScale(100);
102  scalefilter->SetInputData(vtkimage);
103  scalefilter->Update();
104 
105  vtkImageGaussianSmooth *gaussian = vtkImageGaussianSmooth::New();
106  gaussian->SetInputConnection(scalefilter->GetOutputPort());
107  gaussian->SetDimensionality(3);
108  gaussian->SetRadiusFactor(0.49);
109  gaussian->SetStandardDeviation(m_GaussianStandardDeviation);
110  gaussian->ReleaseDataFlagOn();
111  gaussian->UpdateInformation();
112  gaussian->Update();
113 
114  vtkimage = scalefilter->GetOutput();
115 
116  double range[2];
117  vtkimage->GetScalarRange(range);
118 
119  MITK_DEBUG << "Current scalar max is: " << range[1];
120  if (range[1] != 0) // too little slices, image smoothing eliminates all segmentation pixels
121  {
122  vtkimage = gaussian->GetOutput(); //->Out
123  }
124  else
125  {
126  MITK_INFO << "Smoothing removes all pixels of the segmentation. Use unsmoothed result";
127  }
128  gaussian->Delete();
129  scalefilter->Delete();
130  }
132 
133  // Create surface for t-Slice
134  CreateSurface(t, vtkimage, surface, thresholdExpanded);
136  }
137 
138  MITK_INFO << "Updating Time Geometry to ensure right timely displaying";
139  // Fixing wrong time geometry
140  TimeGeometry *surfaceTG = surface->GetTimeGeometry();
141  ProportionalTimeGeometry *surfacePTG = dynamic_cast<ProportionalTimeGeometry *>(surfaceTG);
142  TimeGeometry *imageTG = image->GetTimeGeometry();
143  ProportionalTimeGeometry *imagePTG = dynamic_cast<ProportionalTimeGeometry *>(imageTG);
144  // Requires ProportionalTimeGeometries to work. May not be available for all steps.
145  assert(surfacePTG != nullptr);
146  assert(imagePTG != nullptr);
147  if ((surfacePTG != nullptr) && (imagePTG != nullptr))
148  {
149  TimePointType firstTime = imagePTG->GetFirstTimePoint();
150  TimePointType duration = imagePTG->GetStepDuration();
151  surfacePTG->SetFirstTimePoint(firstTime);
152  surfacePTG->SetStepDuration(duration);
153  MITK_INFO << "First Time Point: " << firstTime << " Duration: " << duration;
154  }
155 };
156 
158 {
159  m_MedianKernelSizeX = x;
160  m_MedianKernelSizeY = y;
161  m_MedianKernelSizeZ = z;
162 }
163 
165 {
166  m_InterpolationX = x;
167  m_InterpolationY = y;
168  m_InterpolationZ = z;
169 }
void Progress(unsigned int steps=1)
Sets the current amount of progress to current progress + steps.
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
virtual void SetStepDuration(TimePointType _arg)
#define MITK_INFO
Definition: mitkLogMacros.h:22
virtual const RegionType & GetRequestedRegion() const
double ScalarType
#define MITK_DEBUG
Definition: mitkLogMacros.h:26
virtual vtkImageData * GetVtkImageData(int t=0, int n=0)
Get a volume at a specific time t of channel n as a vtkImageData.
Definition: mitkImage.cpp:221
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
Definition: mitkBaseData.h:52
virtual TimePointType GetFirstTimePoint() const
static ProgressBar * GetInstance()
static method to get the GUI dependent ProgressBar-instance so the methods for steps to do and progre...
virtual TimePointType GetStepDuration() const
virtual void SetInterpolation(bool _arg)
itk::ImageRegion< RegionDimension > RegionType
Image class for storing images.
Definition: mitkImage.h:76
mitk::ScalarType TimePointType
virtual void SetFirstTimePoint(TimePointType _arg)
void AddStepsToDo(unsigned int steps)
Adds steps to totalSteps.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.