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