Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkWithITKAndVTK.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 #include <itkDiscreteGaussianImageFilter.h>
17 #include <itkImage.h>
18 #include <itksys/SystemTools.hxx>
19 
20 #include <mitkIOUtil.h>
21 #include <mitkImageAccessByItk.h>
22 #include <mitkImageCast.h>
24 
25 #include <vtkImageViewer.h>
26 #include <vtkRenderWindowInteractor.h>
27 
32 int main(int /*argc*/, char **argv)
33 {
34  // MITK: Read a .pic.gz file, e.g. Core/Code/Testing/Data/Pic3D.pic.gz from
35  // disk
36  const char *filename = argv[1];
37 
38  mitk::Image::Pointer mitkImage;
39  try
40  {
41  mitkImage = mitk::IOUtil::LoadImage(filename);
42  }
43  catch (const std::exception &e)
44  {
45  MITK_WARN << "Could not open file " << filename;
46  return EXIT_FAILURE;
47  }
48 
49  // ITK: Image smoothing
50  // Create ITK image, cast from MITK image
51  typedef itk::Image<short, 3> ImageType;
53  mitk::CastToItkImage(mitkImage, itkImage);
54 
55  typedef itk::DiscreteGaussianImageFilter<ImageType, ImageType> FilterType;
57  filter->SetInput(itkImage);
58  filter->SetVariance(2);
59  filter->SetMaximumKernelWidth(5);
60 
61  filter->Update(); // run filter
62 
63  // reimport filtered image data
64  mitk::CastToMitkImage(filter->GetOutput(), mitkImage);
65 
66  // VTK: Show result in renderwindow
67  vtkImageViewer *viewer = vtkImageViewer::New();
68  vtkRenderWindowInteractor *renderWindowInteractor = vtkRenderWindowInteractor::New();
69  viewer->SetupInteractor(renderWindowInteractor);
70  viewer->SetInputData(mitkImage->GetVtkImageData());
71  viewer->Render();
72  viewer->SetColorWindow(255);
73  viewer->SetColorLevel(128);
74  renderWindowInteractor->Start();
75 
76  renderWindowInteractor->Delete();
77  viewer->Delete();
78 
79  return EXIT_SUCCESS;
80 }
int main(int, char **argv)
itk::SmartPointer< Self > Pointer
itk::Image< unsigned char, 3 > ImageType
#define MITK_WARN
Definition: mitkLogMacros.h:23
static const std::string filename
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
Definition: mitkImageCast.h:78
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 mitk::Image::Pointer LoadImage(const std::string &path)
LoadImage Convenience method to load an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:597
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.