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