Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkImageSerializer.h"
00019
00020 #include "mitkImageWriter.h"
00021 #include <Poco/Path.h>
00022
00023 MITK_REGISTER_SERIALIZER(ImageSerializer)
00024
00025 mitk::ImageSerializer::ImageSerializer()
00026 {
00027 }
00028
00029 mitk::ImageSerializer::~ImageSerializer()
00030 {
00031 }
00032
00033 std::string mitk::ImageSerializer::Serialize()
00034 {
00035 const Image* image = dynamic_cast<const Image*>( m_Data.GetPointer() );
00036 if (!image)
00037 {
00038 MITK_ERROR << " Object at " << (const void*) this->m_Data
00039 << " is not an mitk::Image. Cannot serialize as image.";
00040 return "";
00041 }
00042
00043 std::string filename( this->GetUniqueFilenameInWorkingDirectory() );
00044 std::cout << "creating file " << filename << " in " << m_WorkingDirectory << std::endl;
00045 filename += "_";
00046 filename += m_FilenameHint;
00047
00048 std::string fullname(m_WorkingDirectory);
00049 fullname += Poco::Path::separator();
00050 fullname += filename;
00051
00052 try
00053 {
00054 ImageWriter::Pointer writer = ImageWriter::New();
00055 writer->SetFileName( fullname );
00056 writer->SetExtension(".pic");
00057 writer->SetInput( const_cast<Image*>(image) );
00058 writer->Write();
00059 fullname = writer->GetFileName();
00060 }
00061 catch (std::exception& e)
00062 {
00063 MITK_ERROR << " Error serializing object at " << (const void*) this->m_Data
00064 << " to "
00065 << fullname
00066 << ": "
00067 << e.what();
00068 return "";
00069 }
00070 return Poco::Path(fullname).getFileName();
00071 }