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