Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkVigraRandomForestClassifierSerializer.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 "mitkIOUtil.h"
20 
21 #include <itksys/SystemTools.hxx>
22 
23 MITK_REGISTER_SERIALIZER(VigraRandomForestClassifierSerializer)
24 
26 {
27 }
28 
30 {
31 }
32 
34 {
35  const mitk::VigraRandomForestClassifier* data = dynamic_cast<const mitk::VigraRandomForestClassifier*>( m_Data.GetPointer() );
36  if (!data)
37  {
38  MITK_ERROR << " Object at " << (const void*) this->m_Data
39  << " is not an mitk::ContourModelSet. Cannot serialize as contour model set.";
40  return "";
41  }
42 
43  std::string filename( this->GetUniqueFilenameInWorkingDirectory() );
44  filename += "_";
45  filename += m_FilenameHint;
46  filename += ".hdf5";
47 
48  std::string fullname(m_WorkingDirectory);
49  fullname += "/";
50  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
51 
52  try
53  {
54  mitk::IOUtil::Save(const_cast<mitk::VigraRandomForestClassifier*>( data ),fullname);
55  }
56  catch (std::exception& e)
57  {
58  MITK_ERROR << " Error serializing object at " << (const void*) this->m_Data
59  << " to "
60  << fullname
61  << ": "
62  << e.what();
63  return "";
64  }
65 
66  return filename;
67 }
68 
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
Definition: mitkIOUtil.cpp:824
#define MITK_REGISTER_SERIALIZER(classname)
#define MITK_ERROR
Definition: mitkLogMacros.h:24
DataCollection - Class to facilitate loading/accessing structured data.
static const std::string filename
virtual std::string Serialize() override
Serializes given BaseData object.