Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkNrrdTbssRoiImageWriter.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 
17 #ifndef __mitkNrrdTbssRoiImageWriter__cpp
18 #define __mitkNrrdTbssRoiImageWriter__cpp
19 
21 #include "itkMetaDataDictionary.h"
22 #include "itkMetaDataObject.h"
23 #include "itkNrrdImageIO.h"
24 //#include "itkNiftiImageIO.h"
25 #include "itkImageFileWriter.h"
26 #include "itksys/SystemTools.hxx"
27 
28 #include <iostream>
29 #include <fstream>
30 
31 
33  : m_FileName(""), m_FilePrefix(""), m_FilePattern(""), m_Success(false)
34 {
35  this->SetNumberOfRequiredInputs( 1 );
36 }
37 
38 
40 {}
41 
43 {
44  m_Success = false;
45  InputType* input = this->GetInput();
46 
47  if (input == nullptr)
48  {
49  itkWarningMacro(<<"Sorry, input to NrrdTbssImageWriter is NULL!")
50  return;
51  }
52  if ( m_FileName == "" )
53  {
54  itkWarningMacro( << "Sorry, filename has not been set!" )
55  return ;
56  }
57 
58 
59  char keybuffer[512];
60  char valbuffer[512];
61 
62  std::vector< itk::Index<3> > roi = input->GetRoi();
63 
64  auto it = roi.begin();
65 
66  int i=0;
67  while(it != roi.end())
68  {
69  itk::Index<3> ix = *it;
70 
71  sprintf( keybuffer, "ROI_index_%04d", i );
72  sprintf( valbuffer, "%ld %ld %ld", ix[0],ix[1],ix[2]);
73 
74  std::cout << valbuffer << std::endl;
75 
76  //input->GetImage()->GetMetaDataDictionary();
77 
78  itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(), std::string(keybuffer), std::string(valbuffer));
79 
80  it++;
81  ++i;
82  }
83 
84  std::string structure = input->GetStructure();
85  itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(), "structure", structure);
86 
87  typedef itk::Image<unsigned char,3> ImageType;
88  ImageType::Pointer img = input->GetImage();
89 
91  io->SetFileType( itk::ImageIOBase::Binary );
92  io->UseCompressionOn();
93 
94 
95  typedef itk::ImageFileWriter<ImageType> WriterType;
96  WriterType::Pointer nrrdWriter = WriterType::New();
97  nrrdWriter->UseInputMetaDataDictionaryOn();
98  nrrdWriter->SetInput( img );
99  nrrdWriter->SetImageIO(io);
100  nrrdWriter->SetFileName(m_FileName);
101  // nrrdWriter->UseCompressionOn();
102  nrrdWriter->SetImageIO(io);
103  try
104  {
105  nrrdWriter->Update();
106  }
107  catch (itk::ExceptionObject e)
108  {
109  std::cout << e << std::endl;
110  }
111 
112  m_Success = true;
113 }
114 
115 
117 {
118  this->ProcessObject::SetNthInput( 0, tbssVol );
119 }
120 
121 
123 {
124  if ( this->GetNumberOfInputs() < 1 )
125  {
126  return nullptr;
127  }
128  else
129  {
130  return dynamic_cast<InputType*> ( this->ProcessObject::GetInput( 0 ) );
131  }
132 }
133 
134 
136 {
137  std::vector<std::string> possibleFileExtensions;
138  possibleFileExtensions.push_back(".roi");
139  return possibleFileExtensions;
140 }
141 
143 {
145 }
146 
147 #endif //__mitkNrrdTbssRoiImageWriter__cpp
itk::SmartPointer< Self > Pointer
this class encapsulates diffusion volumes (vectorimages not yet supported by mitkImage) ...
virtual std::vector< std::string > GetPossibleFileExtensions() override
std::string GetSupportedBaseData() const override
ImageType::Pointer GetImage()
virtual std::string GetStructure()
map::core::discrete::Elements< 3 >::InternalImageType ImageType
static const char * GetStaticNameOfClass()
Definition: mitkImage.h:88
std::vector< itk::Index< 3 > > GetRoi()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.