Medical Imaging Interaction Toolkit  2016.11.0
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,
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 "mitkSurfaceSerializer.h"
18 
19 #include "mitkIOUtil.h"
20 
21 MITK_REGISTER_SERIALIZER(SurfaceSerializer)
22 
24 {
25 }
26 
28 {
29 }
30 
32 {
33  const Surface *surface = dynamic_cast<const Surface *>(m_Data.GetPointer());
34  if (!surface)
35  {
36  MITK_ERROR << " Object at " << (const void *)this->m_Data
37  << " is not an mitk::Surface. Cannot serialize as surface.";
38  return "";
39  }
40 
41  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
42  filename += "_";
43  filename += m_FilenameHint;
44  filename += ".vtp";
45 
46  std::string fullname(m_WorkingDirectory);
47  fullname += IOUtil::GetDirectorySeparator();
48  fullname += filename;
49 
50  try
51  {
52  IOUtil::Save(surface, fullname);
53  }
54  catch (std::exception &e)
55  {
56  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
57  << e.what();
58  return "";
59  }
60 
61  return filename;
62 }
Class for storing surfaces (vtkPolyData).
Definition: mitkSurface.h:32
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
DataCollection - Class to facilitate loading/accessing structured data.
virtual std::string Serialize() override
Serializes given BaseData object.
static const std::string filename
Serializes mitk::Surface for mitk::SceneIO.