Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkLabelSetImageSerializer.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 "mitkLabelSetImage.h"
19 
20 #include <itksys/SystemTools.hxx>
21 
22 #include <mitkIOUtil.h>
23 
24 MITK_REGISTER_SERIALIZER(LabelSetImageSerializer)
25 
27 {
28 }
29 
31 {
32 }
33 
35 {
36  const LabelSetImage *image = dynamic_cast<const LabelSetImage *>(m_Data.GetPointer());
37  if (image == NULL)
38  {
39  MITK_ERROR << " Object at " << (const void *)this->m_Data
40  << " is not an mitk::LabelSetImage. Cannot serialize as LabelSetImage.";
41  return "";
42  }
43 
44  std::string filename(this->GetUniqueFilenameInWorkingDirectory());
45  filename += "_";
46  filename += m_FilenameHint;
47  filename += ".nrrd";
48 
49  std::string fullname(m_WorkingDirectory);
50  fullname += "/";
51  fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str());
52 
53  try
54  {
55  mitk::IOUtil::Save(const_cast<LabelSetImage *>(image), fullname);
56  // LabelSetImageWriter::Pointer writer = LabelSetImageWriter::New();
57  // writer->SetFileName(fullname);
58  // writer->SetInput(const_cast<LabelSetImage*>(image));
59  // writer->Write();
60  }
61  catch (std::exception &e)
62  {
63  MITK_ERROR << " Error serializing object at " << (const void *)this->m_Data << " to " << fullname << ": "
64  << e.what();
65  return "";
66  }
67  return filename;
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.
virtual std::string Serialize() override
Serializes given BaseData object.
static const std::string filename
Serializes mitk::LabelSetImage for mitk::SceneIO.
LabelSetImage class for handling labels and layers in a segmentation session.