Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSimulationSerializer.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 "mitkSimulation.h"
19 #include <mitkIOUtil.h>
20 
21 MITK_REGISTER_SERIALIZER(SimulationSerializer)
22 
24 {
25 }
26 
28 {
29 }
30 
32 {
33  const Simulation* simulation = dynamic_cast<const Simulation*>(m_Data.GetPointer());
34 
35  if (simulation == NULL)
36  {
37  MITK_ERROR << " Invalid simulation object cannot be serialized!";
38  return "";
39  }
40 
41  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
42  filename += "_" + m_FilenameHint + ".scn";
43 
44  std::string fullPath = m_WorkingDirectory;
45  fullPath += "/" + filename;
46 
47  try
48  {
49  IOUtil::Save(const_cast<Simulation*>(simulation), fullPath);
50  }
51  catch (const std::exception& e)
52  {
53  MITK_ERROR << " Error serializing simulation object to " << fullPath << ": " << e.what();
54  return "";
55  }
56 
57  return filename;
58 }
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.
static const std::string filename
std::string Serialize() override
Serializes given BaseData object.