Medical Imaging Interaction Toolkit  2018.4.99-87d68d9f
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
15 #include "mitkIOUtil.h"
16 
17 #include <itksys/SystemTools.hxx>
18 
19 MITK_REGISTER_SERIALIZER(ExampleDataStructureSerializer)
20 
22 {
23 }
24 
26 {
27 }
28 
30 {
31  const ExampleDataStructure *exData = dynamic_cast<const ExampleDataStructure *>(m_Data.GetPointer());
32  if (exData == nullptr)
33  {
34  MITK_ERROR << " Object at " << (const void *)this->m_Data
35  << " is not an mitk::ExampleDataStructure. Cannot serialize as ExampleDataStructure.";
36  return "";
37  }
38 
39  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
40  filename += "_";
41  filename += m_FilenameHint;
42  filename += ".txt";
43 
44  std::string fullname(m_WorkingDirectory);
45  fullname += "/";
46  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
47 
48  try
49  {
50  mitk::IOUtil::Save(exData, fullname);
51  }
52  catch ( const std::exception &e )
53  {
54  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
55  << e.what();
56  return "";
57  }
58  return filename;
59 }
#define MITK_REGISTER_SERIALIZER(classname)
#define MITK_ERROR
Definition: mitkLogMacros.h:20
std::string GetUniqueFilenameInWorkingDirectory()
DataCollection - Class to facilitate loading/accessing structured data.
BaseData::ConstPointer m_Data
std::string Serialize() override
Serializes given BaseData object.
Serializes mitk::ExampleDataStructure for mitk::SceneIO.
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:774