Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPlanarFigureCompositeWriter.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 <itksys/SystemTools.hxx>
19 #include <mitkAbstractFileWriter.h>
20 #include <mitkCustomMimeType.h>
22 #include <boost/property_tree/ptree.hpp>
23 #define RAPIDXML_NO_EXCEPTIONS
24 #include <boost/property_tree/xml_parser.hpp>
26 
28  : mitk::AbstractFileWriter(mitk::PlanarFigureComposite::GetStaticNameOfClass(), mitk::DiffusionIOMimeTypes::PLANARFIGURECOMPOSITE_MIMETYPE(), "Planar Figure Composite Writer")
29 {
31 }
32 
34  :mitk::AbstractFileWriter(other)
35 {}
36 
38 {}
39 
41 {
42  return new mitk::PlanarFigureCompositeWriter(*this);
43 }
44 
46 {
47 
48  std::ostream* out;
49  std::ofstream outStream;
50 
51  if( this->GetOutputStream() )
52  {
53  out = this->GetOutputStream();
54  }else{
55  outStream.open( this->GetOutputLocation().c_str() );
56  out = &outStream;
57  }
58 
59  if ( !out->good() )
60  {
61  mitkThrow() << "Stream not good.";
62  }
63 
64  try
65  {
66  const std::string& locale = "C";
67  const std::string& currLocale = setlocale( LC_ALL, NULL );
68  setlocale(LC_ALL, locale.c_str());
69 
70  std::locale previousLocale(out->getloc());
71  std::locale I("C");
72  out->imbue(I);
73 
74  std::string filename = this->GetOutputLocation().c_str();
75 
76  mitk::PlanarFigureComposite::ConstPointer input = dynamic_cast<const mitk::PlanarFigureComposite*>(this->GetInput());
77  std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation().c_str());
78 
79  boost::property_tree::ptree type;
80  type.put("comptype", input->getOperationType());
81  boost::property_tree::xml_writer_settings<std::string> writerSettings(' ', 2);
82  boost::property_tree::xml_parser::write_xml(filename, type, std::locale(), writerSettings);
83 
84  setlocale(LC_ALL, currLocale.c_str());
85  }
86  catch(...)
87  {
88  throw;
89  }
90 }
DataCollection - Class to facilitate loading/accessing structured data.
static const std::string filename
#define mitkThrow()
static const char * GetStaticNameOfClass()
virtual void Write() override
Write the base data to the specified location or output stream.
us::ServiceRegistration< IFileWriter > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Base class for writing mitk::BaseData objects to files or streams.
virtual PlanarFigureCompositeWriter * Clone() const override