Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkTensorImageSerializer.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 #include "mitkTensorImage.h"
20 
21 #include <itksys/SystemTools.hxx>
22 
23 
24 MITK_REGISTER_SERIALIZER(TensorImageSerializer)
25 
26 
28 {
29 }
30 
31 
33 {
34 }
35 
36 
38 {
39  const TensorImage* image = dynamic_cast<const TensorImage*>( m_Data.GetPointer() );
40  if (image == NULL)
41  {
42  MITK_ERROR << " Object at " << (const void*) this->m_Data
43  << " is not an mitk::NrrdTensorImage. Cannot serialize as NrrdTensorImage.";
44  return "";
45  }
46 
47  std::string filename( this->GetUniqueFilenameInWorkingDirectory() );
48  filename += "_";
49  filename += m_FilenameHint;
50  filename += ".dti";
51 
52  std::string fullname(m_WorkingDirectory);
53  fullname += "/";
54  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
55 
56  try
57  {
58  NrrdTensorImageWriter writer;
59  writer.SetOutputLocation(fullname);
60  writer.SetInput(const_cast<TensorImage*>(image));
61  writer.Write();
62  }
63  catch (std::exception& e)
64  {
65  MITK_ERROR << " Error serializing object at " << (const void*) this->m_Data
66  << " to "
67  << fullname
68  << ": "
69  << e.what();
70  return "";
71  }
72  return filename;
73 }
74 
#define MITK_REGISTER_SERIALIZER(classname)
virtual void SetInput(const BaseData *data) override
Set the input data for writing.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
virtual std::string Serialize() override
Serializes given BaseData object.
Serializes mitk::Surface for mitk::SceneIO.
static const std::string filename
virtual void SetOutputLocation(const std::string &location) override
Set the output location.
virtual void Write() override
Write the base data to the specified location or output stream.
this class encapsulates tensor images