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