Medical Imaging Interaction Toolkit  2018.4.99-e1268d66
Medical Imaging Interaction Toolkit
mitkContourModelSetReader.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 "mitkContourModelReader.h"
15 #include <fstream>
16 #include <iostream>
17 #include <mitkCustomMimeType.h>
18 #include <mitkLocaleSwitch.h>
19 
21  : mitk::AbstractFileReader(other)
22 {
23 }
24 
26 {
27  std::string category = "ContourModelSet File";
28  CustomMimeType customMimeType;
29  customMimeType.SetCategory(category);
30  customMimeType.AddExtension("cnt_set");
31 
32  this->SetDescription(category);
33  this->SetMimeType(customMimeType);
34 
35  m_ServiceReg = this->RegisterService();
36 }
37 
39 {
40 }
41 
42 std::vector<itk::SmartPointer<mitk::BaseData>> mitk::ContourModelSetReader::Read()
43 {
44  std::vector<itk::SmartPointer<mitk::BaseData>> result;
45  std::vector<itk::SmartPointer<mitk::BaseData>> internalResult;
46 
47  std::string location = GetInputLocation();
48 
49  // Switch the current locale to "C"
50  LocaleSwitch localeSwitch("C");
51 
52  try
53  {
55 
57  reader.SetInput(location);
58  internalResult = reader.Read();
59 
60  for (unsigned int i = 0; i < internalResult.size(); ++i)
61  {
62  contourSet->AddContourModel(dynamic_cast<mitk::ContourModel *>(internalResult.at(i).GetPointer()));
63  }
64  result.push_back(dynamic_cast<mitk::BaseData *>(contourSet.GetPointer()));
65  }
66  catch (...)
67  {
68  MITK_ERROR << "Cannot read contourModel.";
69  }
70 
71  return result;
72 }
73 
74 mitk::ContourModelSetReader *mitk::ContourModelSetReader::Clone() const
75 {
76  return new ContourModelSetReader(*this);
77 }
std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
#define MITK_ERROR
Definition: mitkLogMacros.h:20
DataCollection - Class to facilitate loading/accessing structured data.
std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
void SetMimeType(const CustomMimeType &mimeType)
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Convenience class to temporarily change the current locale.
static Pointer New()
void SetDescription(const std::string &description)
void AddExtension(const std::string &extension)
void SetCategory(const std::string &category)
Base class for creating mitk::BaseData objects from files or streams.
std::string GetInputLocation() const override
Get the current input location.
void SetInput(const std::string &location) override
Set the input location.