Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
CLPolyToNrrd.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 #ifndef mitkCLPolyToNrrd_cpp
17 #define mitkCLPolyToNrrd_cpp
18 
19 #include "time.h"
20 #include <sstream>
21 
22 #include <mitkIOUtil.h>
23 #include <vtkPolyData.h>
24 #include <vtkCellArray.h>
25 #include <mitkSurface.h>
26 
27 #include "mitkCommandLineParser.h"
28 
30 #include <vtkSmartPointer.h>
31 #include <vtkLinearExtrusionFilter.h>
34 
35 
36 
37 typedef itk::Image< double, 3 > FloatImageType;
38 typedef itk::Image< unsigned char, 3 > MaskImageType;
39 
40 int main(int argc, char* argv[])
41 {
42  mitkCommandLineParser parser;
43  parser.setArgumentPrefix("--", "-");
44  // required params
45  parser.addArgument("polydata", "p", mitkCommandLineParser::InputDirectory, "Input Polydata", "Path to the input VTK polydata", us::Any(), false);
46  parser.addArgument("image", "i", mitkCommandLineParser::OutputDirectory, "Input Image", "Image which defines the dimensions of the Segmentation", us::Any(), false);
47  parser.addArgument("output", "o", mitkCommandLineParser::InputFile, "Output file", "Output files. Two files are create, a .nrrd image and a 3d-vtk.", us::Any(), false);
48  // Miniapp Infos
49  parser.setCategory("Classification Tools");
50  parser.setTitle("2D-Polydata to Nrrd Segmentation");
51  parser.setDescription("Creates a Nrrd segmentation based on a 2d-vtk polydata.");
52  parser.setContributor("MBI");
53 
54  std::map<std::string, us::Any> parsedArgs = parser.parseArguments(argc, argv);
55 
56  if (parsedArgs.size()==0)
57  {
58  return EXIT_FAILURE;
59  }
60  if ( parsedArgs.count("help") || parsedArgs.count("h"))
61  {
62  return EXIT_SUCCESS;
63  }
64 
65  mitk::BaseData::Pointer data = mitk::IOUtil::LoadBaseData(parsedArgs["polydata"].ToString());
66  mitk::Image::Pointer image = mitk::IOUtil::LoadImage(parsedArgs["image"].ToString());
67 
68  //MITK_INFO << data;
69  mitk::Surface::Pointer surf = dynamic_cast<mitk::Surface*>(data.GetPointer());
70  vtkSmartPointer<vtkPolyData> circle = surf->GetVtkPolyData();
71 
72  vtkSmartPointer<vtkLinearExtrusionFilter> extruder =
74 
75  extruder->SetInputData(circle);
76  image->GetGeometry()->GetSpacing()[2];
77  extruder->SetScaleFactor(1.);
78  extruder->SetExtrusionTypeToNormalExtrusion();
79  extruder->SetVector(0, 0, image->GetGeometry()->GetSpacing()[2]);
80  extruder->Update();
81  surf->SetVtkPolyData(extruder->GetOutput());
82 
84  surfaceToImageFilter->MakeOutputBinaryOn();
85  surfaceToImageFilter->SetInput(surf);
86  surfaceToImageFilter->SetImage(image);
87  surfaceToImageFilter->Update();
88  mitk::Image::Pointer resultImage = surfaceToImageFilter->GetOutput();
89 
91  multiFilter->SetInput(resultImage);
92  multiFilter->Update();
93  resultImage = multiFilter->GetOutput();
94 
95  std::string saveAs = parsedArgs["output"].ToString();
96  MITK_INFO << "Save as: " << saveAs;
97  saveAs = saveAs + ".vtk";
98  mitk::IOUtil::SaveSurface(surf.GetPointer(),saveAs);
99 
100  saveAs = parsedArgs["output"].ToString();
101  MITK_INFO << "Save as: " << saveAs;
102  saveAs = saveAs + ".nrrd";
103  mitk::IOUtil::SaveImage(resultImage,saveAs);
104 
105  return 0;
106 }
107 
108 #endif
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
#define MITK_INFO
Definition: mitkLogMacros.h:22
itk::Image< unsigned char, 3 > MaskImageType
void setContributor(std::string contributor)
std::map< std::string, us::Any > parseArguments(const StringContainerType &arguments, bool *ok=nullptr)
static mitk::BaseData::Pointer LoadBaseData(const std::string &path)
Create a BaseData object from the given file.
Definition: mitkIOUtil.cpp:576
static bool SaveSurface(mitk::Surface::Pointer surface, const std::string &path)
SaveSurface Convenience method to save an arbitrary mitkSurface.
Definition: mitkIOUtil.cpp:876
static bool SaveImage(mitk::Image::Pointer image, const std::string &path)
SaveImage Convenience method to save an arbitrary mitkImage.
Definition: mitkIOUtil.cpp:870
void addArgument(const std::string &longarg, const std::string &shortarg, Type type, const std::string &argLabel, const std::string &argHelp=std::string(), const us::Any &defaultValue=us::Any(), bool optional=true, bool ignoreRest=false, bool deprecated=false)
Definition: usAny.h:163
void setCategory(std::string category)
void setArgumentPrefix(const std::string &longPrefix, const std::string &shortPrefix)
itk::Image< double, 3 > FloatImageType
int main(int argc, char *argv[])
void setTitle(std::string title)
void setDescription(std::string description)
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.