Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkContourModelSerializer.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 "mitkContourModelWriter.h"
19 
20 #include <itksys/SystemTools.hxx>
21 
22 MITK_REGISTER_SERIALIZER(ContourModelSerializer)
23 
25 {
26 }
27 
29 {
30 }
31 
33 {
34  const ContourModel *contour = dynamic_cast<const ContourModel *>(m_Data.GetPointer());
35  if (!contour)
36  {
37  MITK_ERROR << " Object at " << (const void *)this->m_Data
38  << " is not an mitk::ContourModel. Cannot serialize as contour model.";
39  return "";
40  }
41 
42  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
43  filename += "_";
44  filename += m_FilenameHint;
45  filename += ".cnt";
46 
47  std::string fullname(m_WorkingDirectory);
48  fullname += "/";
49  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
50 
51  try
52  {
53  ContourModelWriter writer;
54  writer.SetOutputLocation(fullname);
55  writer.SetInput(const_cast<ContourModel *>(contour));
56  writer.Write();
57  }
58  catch (std::exception &e)
59  {
60  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
61  << e.what();
62  return "";
63  }
64 
65  return filename;
66 }
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
#define MITK_REGISTER_SERIALIZER(classname)
virtual void SetInput(const BaseData *data) override
Set the input data for writing.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
static const std::string filename
virtual void Write() override
Write the base data to the specified location or output stream.
virtual void SetOutputLocation(const std::string &location) override
Set the output location.
virtual std::string Serialize() override
Serializes given BaseData object.