00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision: 1.12 $ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkPlanarFigureSerializer.h" 00019 #include "mitkPlanarFigure.h" 00020 #include "mitkPlanarFigureWriter.h" 00021 00022 #include <itksys/SystemTools.hxx> 00023 00024 00025 MITK_REGISTER_SERIALIZER(PlanarFigureSerializer) 00026 00027 00028 mitk::PlanarFigureSerializer::PlanarFigureSerializer() 00029 { 00030 } 00031 00032 00033 mitk::PlanarFigureSerializer::~PlanarFigureSerializer() 00034 { 00035 } 00036 00037 00038 std::string mitk::PlanarFigureSerializer::Serialize() 00039 { 00040 const PlanarFigure* pf = dynamic_cast<const PlanarFigure*>( m_Data.GetPointer() ); 00041 if (pf == NULL) 00042 { 00043 MITK_ERROR << " Object at " << (const void*) this->m_Data 00044 << " is not an mitk::PlanarFigure. Cannot serialize as PlanarFigure."; 00045 return ""; 00046 } 00047 00048 std::string filename( this->GetUniqueFilenameInWorkingDirectory() ); 00049 filename += "_"; 00050 filename += m_FilenameHint; 00051 filename += ".pf"; 00052 00053 std::string fullname(m_WorkingDirectory); 00054 fullname += "/"; 00055 fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str()); 00056 00057 try 00058 { 00059 PlanarFigureWriter::Pointer writer = PlanarFigureWriter::New(); 00060 writer->SetFileName(fullname); 00061 writer->SetInput(const_cast<PlanarFigure*>(pf)); 00062 writer->Write(); 00063 } 00064 catch (std::exception& e) 00065 { 00066 MITK_ERROR << " Error serializing object at " << (const void*) this->m_Data 00067 << " to " 00068 << fullname 00069 << ": " 00070 << e.what(); 00071 return ""; 00072 } 00073 return filename; 00074 } 00075