Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkGeometryDataSerializer.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 "mitkGeometry3D.h"
19 #include "mitkGeometryData.h"
20 #include "mitkIOUtil.h"
21 
22 #include <tinyxml.h>
23 
24 MITK_REGISTER_SERIALIZER(GeometryDataSerializer)
25 
27 {
28 }
29 
31 {
32 }
33 
35 {
36  // Verify good input data type
37  const GeometryData *ps = dynamic_cast<const GeometryData *>(m_Data.GetPointer());
38  if (ps == NULL)
39  {
40  MITK_ERROR << " Object at " << (const void *)this->m_Data << " is not an mitk::GeometryData. Cannot serialize...";
41  return "";
42  }
43 
44  // Construct the full filename to store the geometry
45  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
46  filename += "_";
47  filename += m_FilenameHint;
48  filename += ".mitkgeometry";
49 
50  std::string fullname(m_WorkingDirectory);
51  fullname += IOUtil::GetDirectorySeparator();
52  fullname += filename;
53 
54  try
55  {
56  IOUtil::Save(ps, fullname);
57  // in case of success, return only the relative filename part
58  return filename;
59  }
60  catch (const std::exception &e)
61  {
62  MITK_ERROR << "Unable to serialize GeometryData object: " << e.what();
63  }
64 
65  // when failed, return empty string
66  return "";
67 }
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:824
static char GetDirectorySeparator()
Definition: mitkIOUtil.cpp:363
#define MITK_REGISTER_SERIALIZER(classname)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
virtual std::string Serialize() override
Serializes given BaseData object.
DataCollection - Class to facilitate loading/accessing structured data.
static const std::string filename
Serializes mitk::GeometryData for mitk::SceneIO.
Data class only having a BaseGeometry but not containing any specific data.