Medical Imaging Interaction Toolkit  2018.4.99-c7ee88da
Medical Imaging Interaction Toolkit
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 (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 "mitkContourModelWriter.h"
15 
16 #include <itksys/SystemTools.hxx>
17 
18 MITK_REGISTER_SERIALIZER(ContourModelSerializer)
19 
21 {
22 }
23 
25 {
26 }
27 
29 {
30  const auto *contour = dynamic_cast<const ContourModel *>(m_Data.GetPointer());
31  if (!contour)
32  {
33  MITK_ERROR << " Object at " << (const void *)this->m_Data
34  << " is not an mitk::ContourModel. Cannot serialize as contour model.";
35  return "";
36  }
37 
38  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
39  filename += "_";
40  filename += m_FilenameHint;
41  filename += ".cnt";
42 
43  std::string fullname(m_WorkingDirectory);
44  fullname += "/";
45  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
46 
47  try
48  {
49  ContourModelWriter writer;
50  writer.SetOutputLocation(fullname);
51  writer.SetInput(contour);
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 }
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
#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 Write() override
Write the base data to the specified location or output stream.
void SetOutputLocation(const std::string &location) override
Set the output location.
std::string Serialize() override
Serializes given BaseData object.