Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkContourModelSetSerializer.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 
19 
20 #include <itksys/SystemTools.hxx>
21 
22 MITK_REGISTER_SERIALIZER(ContourModelSetSerializer)
23 
25 {
26 }
27 
29 {
30 }
31 
33 {
34  const ContourModelSet *contourSet = dynamic_cast<const ContourModelSet *>(m_Data.GetPointer());
35  if (!contourSet)
36  {
37  MITK_ERROR << " Object at " << (const void *)this->m_Data
38  << " is not an mitk::ContourModelSet. Cannot serialize as contour model set.";
39  return "";
40  }
41 
42  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
43  filename += "_";
44  filename += m_FilenameHint;
45  filename += ".cnt_set";
46 
47  std::string fullname(m_WorkingDirectory);
48  fullname += "/";
49  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
50 
51  try
52  {
53  ContourModelSetWriter writer;
54  writer.SetOutputLocation(fullname);
55  writer.SetInput(const_cast<ContourModelSet *>(contourSet));
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 }
#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 SetOutputLocation(const std::string &location) override
Set the output location.
virtual void Write() override
Write the base data to the specified location or output stream.
virtual std::string Serialize() override
Serializes given BaseData object.
XML-based writer for mitk::ContourModelSet.