Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPlanarFigureSerializer.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 "mitkPlanarFigure.h"
19 #include "mitkPlanarFigureWriter.h"
20 
21 #include <itksys/SystemTools.hxx>
22 
23 MITK_REGISTER_SERIALIZER(PlanarFigureSerializer)
24 
26 {
27 }
28 
30 {
31 }
32 
34 {
35  const PlanarFigure *pf = dynamic_cast<const PlanarFigure *>(m_Data.GetPointer());
36  if (pf == nullptr)
37  {
38  MITK_ERROR << " Object at " << (const void *)this->m_Data
39  << " is not an mitk::PlanarFigure. Cannot serialize as PlanarFigure.";
40  return "";
41  }
42 
43  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
44  filename += "_";
45  filename += m_FilenameHint;
46  filename += ".pf";
47 
48  std::string fullname(m_WorkingDirectory);
49  fullname += "/";
50  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
51 
52  try
53  {
55  writer->SetFileName(fullname);
56  writer->SetInput(const_cast<PlanarFigure *>(pf));
57  writer->Write();
58  }
59  catch (std::exception &e)
60  {
61  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
62  << e.what();
63  return "";
64  }
65  return filename;
66 }
#define MITK_REGISTER_SERIALIZER(classname)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
static const std::string filename
virtual std::string Serialize() override
Serializes given BaseData object.
Base-class for geometric planar (2D) figures, such as lines, circles, rectangles, polygons...
Serializes mitk::Surface for mitk::SceneIO.
static Pointer New()