Medical Imaging Interaction Toolkit  2018.4.99-a3d2e8fb
Medical Imaging Interaction Toolkit
mitkPointSetSerializer.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 "mitkPointSetSerializer.h"
14 #include "mitkIOUtil.h"
15 
16 MITK_REGISTER_SERIALIZER(PointSetSerializer)
17 
19 {
20 }
21 
23 {
24 }
25 
27 {
28  const auto *ps = dynamic_cast<const PointSet *>(m_Data.GetPointer());
29  if (ps == nullptr)
30  {
31  MITK_ERROR << " Object at " << (const void *)this->m_Data
32  << " is not an mitk::PointSet. Cannot serialize as pointset.";
33  return "";
34  }
35 
36  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
37  filename += "_";
38  filename += m_FilenameHint;
39  filename += ".mps";
40 
41  std::string fullname(m_WorkingDirectory);
42  fullname += IOUtil::GetDirectorySeparator();
43  fullname += filename;
44 
45  try
46  {
47  IOUtil::Save(ps, fullname);
48  }
49  catch (std::exception &e)
50  {
51  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
52  << e.what();
53  return "";
54  }
55  return filename;
56 }
static char GetDirectorySeparator()
Definition: mitkIOUtil.cpp:369
#define MITK_REGISTER_SERIALIZER(classname)
std::string Serialize() override
Serializes given BaseData object.
#define MITK_ERROR
Definition: mitkLogMacros.h:20
Serializes mitk::Surface for mitk::SceneIO.
std::string GetUniqueFilenameInWorkingDirectory()
DataCollection - Class to facilitate loading/accessing structured data.
BaseData::ConstPointer m_Data
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:75
static void Save(const mitk::BaseData *data, const std::string &path, bool setPathProperty=false)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:774