Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkExampleDataStructureSerializer.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 
19 #include "mitkIOUtil.h"
20 
21 #include <itksys/SystemTools.hxx>
22 
23 MITK_REGISTER_SERIALIZER(ExampleDataStructureSerializer)
24 
26 {
27 }
28 
30 {
31 }
32 
34 {
35  const ExampleDataStructure *exData = dynamic_cast<const ExampleDataStructure *>(m_Data.GetPointer());
36  if (exData == NULL)
37  {
38  MITK_ERROR << " Object at " << (const void *)this->m_Data
39  << " is not an mitk::ExampleDataStructure. Cannot serialize as ExampleDataStructure.";
40  return "";
41  }
42 
43  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
44  filename += "_";
45  filename += m_FilenameHint;
46  filename += ".txt";
47 
48  std::string fullname(m_WorkingDirectory);
49  fullname += "/";
50  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
51 
52  try
53  {
54  mitk::IOUtil::Save(exData, fullname);
55  }
56  catch (std::exception &e)
57  {
58  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
59  << e.what();
60  return "";
61  }
62  return filename;
63 }
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.
virtual std::string Serialize() override
Serializes given BaseData object.
static const std::string filename
Serializes mitk::ExampleDataStructure for mitk::SceneIO.