Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
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 "mitkContourModelReader.h"
19 #include <fstream>
20 #include <iostream>
21 #include <mitkCustomMimeType.h>
22 #include <mitkLocaleSwitch.h>
23 
25  : mitk::AbstractFileReader(other)
26 {
27 }
28 
30 {
31  std::string category = "ContourModelSet File";
32  CustomMimeType customMimeType;
33  customMimeType.SetCategory(category);
34  customMimeType.AddExtension("cnt_set");
35 
36  this->SetDescription(category);
37  this->SetMimeType(customMimeType);
38 
39  m_ServiceReg = this->RegisterService();
40 }
41 
43 {
44 }
45 
46 std::vector<itk::SmartPointer<mitk::BaseData>> mitk::ContourModelSetReader::Read()
47 {
48  std::vector<itk::SmartPointer<mitk::BaseData>> result;
49  std::vector<itk::SmartPointer<mitk::BaseData>> internalResult;
50 
51  std::string location = GetInputLocation();
52 
53  // Switch the current locale to "C"
54  LocaleSwitch localeSwitch("C");
55 
56  try
57  {
59 
61  reader.SetInput(location);
62  internalResult = reader.Read();
63 
64  for (unsigned int i = 0; i < internalResult.size(); ++i)
65  {
66  contourSet->AddContourModel(dynamic_cast<mitk::ContourModel *>(internalResult.at(i).GetPointer()));
67  }
68  result.push_back(dynamic_cast<mitk::BaseData *>(contourSet.GetPointer()));
69  }
70  catch (...)
71  {
72  MITK_ERROR << "Cannot read contourModel.";
73  }
74 
75  return result;
76 }
77 
78 mitk::ContourModelSetReader *mitk::ContourModelSetReader::Clone() const
79 {
80  return new ContourModelSetReader(*this);
81 }
virtual 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:24
DataCollection - Class to facilitate loading/accessing structured data.
virtual 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.
virtual void SetInput(const std::string &location) override
Set the input location.