Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkImageSerializer.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 #include "mitkImageSerializer.h"
18 #include "mitkIOUtil.h"
19 #include "mitkImage.h"
20 #include <Poco/Path.h>
21 
22 MITK_REGISTER_SERIALIZER(ImageSerializer)
23 
25 {
26 }
27 
29 {
30 }
31 
33 {
34  const Image *image = dynamic_cast<const Image *>(m_Data.GetPointer());
35  if (!image)
36  {
37  MITK_ERROR << " Object at " << (const void *)this->m_Data << " is not an mitk::Image. Cannot serialize as image.";
38  return "";
39  }
40 
41  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
42  std::cout << "creating file " << filename << " in " << m_WorkingDirectory << std::endl;
43  filename += "_";
44  filename += m_FilenameHint;
45 
46  std::string fullname(m_WorkingDirectory);
47  fullname += Poco::Path::separator();
48  fullname += filename + ".nrrd";
49 
50  try
51  {
52  IOUtil::Save(image, fullname);
53  }
54  catch (std::exception &e)
55  {
56  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
57  << e.what();
58  return "";
59  }
60  return Poco::Path(fullname).getFileName(); // + ".pic";
61 }
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:824
#define MITK_REGISTER_SERIALIZER(classname)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
Serializes mitk::Image for mitk::SceneIO.
static const std::string filename
Image class for storing images.
Definition: mitkImage.h:76
virtual std::string Serialize() override
Serializes given BaseData object.