Medical Imaging Interaction Toolkit  2018.4.99-3e3f1a6e
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 (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 
15 
16 #include <itksys/SystemTools.hxx>
17 
18 MITK_REGISTER_SERIALIZER(ContourModelSetSerializer)
19 
21 {
22 }
23 
25 {
26 }
27 
29 {
30  const auto *contourSet = dynamic_cast<const ContourModelSet *>(m_Data.GetPointer());
31  if (!contourSet)
32  {
33  MITK_ERROR << " Object at " << (const void *)this->m_Data
34  << " is not an mitk::ContourModelSet. Cannot serialize as contour model set.";
35  return "";
36  }
37 
38  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
39  filename += "_";
40  filename += m_FilenameHint;
41  filename += ".cnt_set";
42 
43  std::string fullname(m_WorkingDirectory);
44  fullname += "/";
45  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
46 
47  try
48  {
49  ContourModelSetWriter writer;
50  writer.SetOutputLocation(fullname);
51  writer.SetInput(contourSet);
52  writer.Write();
53  }
54  catch ( const std::exception &e )
55  {
56  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
57  << e.what();
58  return "";
59  }
60 
61  return filename;
62 }
#define MITK_REGISTER_SERIALIZER(classname)
void SetInput(const BaseData *data) override
Set the input data for writing.
#define MITK_ERROR
Definition: mitkLogMacros.h:20
std::string GetUniqueFilenameInWorkingDirectory()
DataCollection - Class to facilitate loading/accessing structured data.
BaseData::ConstPointer m_Data
void SetOutputLocation(const std::string &location) override
Set the output location.
void Write() override
Write the base data to the specified location or output stream.
std::string Serialize() override
Serializes given BaseData object.
XML-based writer for mitk::ContourModelSet.