Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkNrrdTbssImageWriter.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 __mitkNrrdTbssImageWriter__cpp
18 #define __mitkNrrdTbssImageWriter__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 #include "boost/lexical_cast.hpp"
28 
29 #include <iostream>
30 #include <fstream>
31 
32 
34  : m_FileName(""), m_FilePrefix(""), m_FilePattern(""), m_Success(false)
35 {
36  this->SetNumberOfRequiredInputs( 1 );
37 }
38 
40 {}
41 
42 
44 {
45  m_Success = false;
46  InputType* input = this->GetInput();
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 
61 
62 
63 
64 
65  std::string key;
66  std::string val;
67 
68 
69  /* For the case of a tbss image containing data of the patients:
70  Save info about the groups and the type of measurement */
71 
72 
73 
74 
75  std::vector< std::pair <std::string, int> > groups = input->GetGroupInfo();
76  auto it = groups.begin();
77 
78  int i=0;
79  while(it != groups.end())
80  {
81  std::pair<std::string, int> p = *it;
82 
83  key = "Group_index_" + boost::lexical_cast<std::string>(i);
84  val = " " + p.first + " " + boost::lexical_cast<std::string>(p.second);
85  //sprintf( keybuffer, "Group_index_%04d", std::string(i) );
86  // sprintf( valbuffer, "%1d %1d", p.first, p.second);
87 
88  //std::cout << valbuffer << std::endl;
89 
90  //itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),std::string(keybuffer),std::string(valbuffer));
91  itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),key,val);
92  it++;
93  ++i;
94  }
95 
96  key = "Measurement info";
97  val = input->GetMeasurementInfo();
98  itk::EncapsulateMetaData< std::string >(input->GetImage()->GetMetaDataDictionary(),key,val);
99 
100 
101 
102 
103 
104  typedef itk::VectorImage<float,3> ImageType;
105 
107  io->SetFileType( itk::ImageIOBase::Binary );
108  io->UseCompressionOn();
109 
110 
111  typedef itk::ImageFileWriter<ImageType> WriterType;
112  WriterType::Pointer nrrdWriter = WriterType::New();
113  nrrdWriter->UseInputMetaDataDictionaryOn();
114  nrrdWriter->SetInput( img );
115  nrrdWriter->SetImageIO(io);
116  nrrdWriter->SetFileName(m_FileName);
117  nrrdWriter->UseCompressionOn();
118  nrrdWriter->SetImageIO(io);
119  try
120  {
121  nrrdWriter->Update();
122  }
123  catch (itk::ExceptionObject e)
124  {
125  std::cout << e << std::endl;
126  }
127 
128  m_Success = true;
129 }
130 
131 
132 
133 
135 {
136  this->ProcessObject::SetNthInput( 0, tbssVol );
137 }
138 
139 
141 {
142  if ( this->GetNumberOfInputs() < 1 )
143  {
144  return nullptr;
145  }
146  else
147  {
148  return dynamic_cast<InputType*> ( this->ProcessObject::GetInput( 0 ) );
149  }
150 }
151 
152 
154 {
155  std::vector<std::string> possibleFileExtensions;
156  possibleFileExtensions.push_back(".tbss");
157  return possibleFileExtensions;
158 }
159 
161 {
163 }
164 
165 #endif //__mitkNrrdTbssImageWriter__cpp
virtual void GenerateData() override
itk::SmartPointer< Self > Pointer
map::core::discrete::Elements< 3 >::InternalImageType ImageType
static const char * GetStaticNameOfClass()
Definition: mitkImage.h:88
std::string GetMeasurementInfo()
Definition: mitkTbssImage.h:82
ImageType::Pointer GetImage()
Definition: mitkTbssImage.h:50
std::string GetSupportedBaseData() const override
this class encapsulates diffusion volumes (vectorimages not yet supported by mitkImage) ...
Definition: mitkTbssImage.h:34
virtual std::vector< std::string > GetPossibleFileExtensions() override
std::vector< std::pair< std::string, int > > GetGroupInfo()
Definition: mitkTbssImage.h:71
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.