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 "mitkSurfaceSerializer.h" 00019 00020 #include "mitkSurfaceVtkWriter.h" 00021 00022 #include <vtkXMLPolyDataWriter.h> 00023 #include "Poco/Path.h" 00024 00025 MITK_REGISTER_SERIALIZER(SurfaceSerializer) 00026 00027 mitk::SurfaceSerializer::SurfaceSerializer() 00028 { 00029 } 00030 00031 mitk::SurfaceSerializer::~SurfaceSerializer() 00032 { 00033 } 00034 00035 std::string mitk::SurfaceSerializer::Serialize() 00036 { 00037 const Surface* surface = dynamic_cast<const Surface*>( m_Data.GetPointer() ); 00038 if (!surface) 00039 { 00040 MITK_ERROR << " Object at " << (const void*) this->m_Data 00041 << " is not an mitk::Surface. Cannot serialize as surface."; 00042 return ""; 00043 } 00044 00045 std::string filename( this->GetUniqueFilenameInWorkingDirectory() ); 00046 filename += "_"; 00047 filename += m_FilenameHint; 00048 filename += ".vtp"; 00049 00050 std::string fullname(m_WorkingDirectory); 00051 fullname += Poco::Path::separator(); 00052 fullname += filename; 00053 00054 try 00055 { 00056 SurfaceVtkWriter<vtkXMLPolyDataWriter>::Pointer writer = SurfaceVtkWriter<vtkXMLPolyDataWriter>::New(); 00057 writer->SetFileName( fullname ); 00058 //writer->SetExtension(".vtp"); 00059 writer->SetInput( const_cast<Surface*>( surface ) ); 00060 writer->Write(); 00061 } 00062 catch (std::exception& e) 00063 { 00064 MITK_ERROR << " Error serializing object at " << (const void*) this->m_Data 00065 << " to " 00066 << fullname 00067 << ": " 00068 << e.what(); 00069 return ""; 00070 } 00071 00072 return filename; 00073 } 00074