Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkSurfaceSerializer.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 
13 #include "mitkSurfaceSerializer.h"
14 
15 #include "mitkIOUtil.h"
16 
17 MITK_REGISTER_SERIALIZER(SurfaceSerializer)
18 
20 {
21 }
22 
24 {
25 }
26 
28 {
29  const auto *surface = dynamic_cast<const Surface *>(m_Data.GetPointer());
30  if (!surface)
31  {
32  MITK_ERROR << " Object at " << (const void *)this->m_Data
33  << " is not an mitk::Surface. Cannot serialize as surface.";
34  return "";
35  }
36 
37  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
38  filename += "_";
39  filename += m_FilenameHint;
40  filename += ".vtp";
41 
42  std::string fullname(m_WorkingDirectory);
43  fullname += IOUtil::GetDirectorySeparator();
44  fullname += filename;
45 
46  try
47  {
48  IOUtil::Save(surface, fullname);
49  }
50  catch (std::exception &e)
51  {
52  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
53  << e.what();
54  return "";
55  }
56 
57  return filename;
58 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:28
static char GetDirectorySeparator()
Definition: mitkIOUtil.cpp:369
#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.
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:774
Serializes mitk::Surface for mitk::SceneIO.