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