diff --git a/Modules/ContourModel/CMakeLists.txt b/Modules/ContourModel/CMakeLists.txt index 6c41d28911..4634c724a4 100644 --- a/Modules/ContourModel/CMakeLists.txt +++ b/Modules/ContourModel/CMakeLists.txt @@ -1,7 +1,7 @@ MITK_CREATE_MODULE( INCLUDE_DIRS Algorithms DataManagement IO Rendering - DEPENDS MitkCore + DEPENDS MitkCore MitkSceneSerializationBase WARNINGS_AS_ERRORS ) add_subdirectory(Testing) diff --git a/Modules/ContourModel/IO/mitkContourModelSerializer.cpp b/Modules/ContourModel/IO/mitkContourModelSerializer.cpp new file mode 100644 index 0000000000..d15ef6e14f --- /dev/null +++ b/Modules/ContourModel/IO/mitkContourModelSerializer.cpp @@ -0,0 +1,70 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkContourModelSerializer.h" +#include "mitkContourModelWriter.h" + +#include + +MITK_REGISTER_SERIALIZER(ContourModelSerializer) + +mitk::ContourModelSerializer::ContourModelSerializer() +{ +} + +mitk::ContourModelSerializer::~ContourModelSerializer() +{ +} + +std::string mitk::ContourModelSerializer::Serialize() +{ + const ContourModel* contour = dynamic_cast( m_Data.GetPointer() ); + if (!contour) + { + MITK_ERROR << " Object at " << (const void*) this->m_Data + << " is not an mitk::ContourModel. Cannot serialize as contour model."; + return ""; + } + + std::string filename( this->GetUniqueFilenameInWorkingDirectory() ); + filename += "_"; + filename += m_FilenameHint; + filename += ".cnt"; + + std::string fullname(m_WorkingDirectory); + fullname += "/"; + fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str()); + + try + { + ContourModelWriter::Pointer writer = ContourModelWriter::New(); + writer->SetFileName( fullname ); + writer->SetInput( const_cast( contour ) ); + writer->Write(); + } + catch (std::exception& e) + { + MITK_ERROR << " Error serializing object at " << (const void*) this->m_Data + << " to " + << fullname + << ": " + << e.what(); + return ""; + } + + return filename; +} + diff --git a/Modules/ContourModel/IO/mitkContourModelSerializer.h b/Modules/ContourModel/IO/mitkContourModelSerializer.h new file mode 100644 index 0000000000..0b42539f46 --- /dev/null +++ b/Modules/ContourModel/IO/mitkContourModelSerializer.h @@ -0,0 +1,46 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKCONTOURMODELSERIALIZER_H +#define MITKCONTOURMODELSERIALIZER_H + +#include +#include + +namespace mitk +{ + +class MitkContourModel_EXPORT ContourModelSerializer : public BaseDataSerializer +{ + +public: + + mitkClassMacro(ContourModelSerializer, BaseDataSerializer); + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + virtual std::string Serialize(); + +protected: + + ContourModelSerializer(); + virtual ~ContourModelSerializer(); +}; + +} + + +#endif // MITKCONTOURMODELSERIALIZER_H diff --git a/Modules/ContourModel/IO/mitkContourModelSetSerializer.cpp b/Modules/ContourModel/IO/mitkContourModelSetSerializer.cpp new file mode 100644 index 0000000000..e66d98ec6a --- /dev/null +++ b/Modules/ContourModel/IO/mitkContourModelSetSerializer.cpp @@ -0,0 +1,70 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkContourModelSetSerializer.h" +#include "mitkContourModelSetWriter.h" + +#include + +MITK_REGISTER_SERIALIZER(ContourModelSetSerializer) + +mitk::ContourModelSetSerializer::ContourModelSetSerializer() +{ +} + +mitk::ContourModelSetSerializer::~ContourModelSetSerializer() +{ +} + +std::string mitk::ContourModelSetSerializer::Serialize() +{ + const ContourModelSet* contourSet = dynamic_cast( m_Data.GetPointer() ); + if (!contourSet) + { + MITK_ERROR << " Object at " << (const void*) this->m_Data + << " is not an mitk::ContourModelSet. Cannot serialize as contour model set."; + return ""; + } + + std::string filename( this->GetUniqueFilenameInWorkingDirectory() ); + filename += "_"; + filename += m_FilenameHint; + filename += ".cnt_set"; + + std::string fullname(m_WorkingDirectory); + fullname += "/"; + fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str()); + + try + { + ContourModelSetWriter::Pointer writer = ContourModelSetWriter::New(); + writer->SetFileName( fullname ); + writer->SetInput( const_cast( contourSet ) ); + writer->Write(); + } + catch (std::exception& e) + { + MITK_ERROR << " Error serializing object at " << (const void*) this->m_Data + << " to " + << fullname + << ": " + << e.what(); + return ""; + } + + return filename; +} + diff --git a/Modules/ContourModel/IO/mitkContourModelSetSerializer.h b/Modules/ContourModel/IO/mitkContourModelSetSerializer.h new file mode 100644 index 0000000000..7bacffc2bb --- /dev/null +++ b/Modules/ContourModel/IO/mitkContourModelSetSerializer.h @@ -0,0 +1,27 @@ +#ifndef MITKCONTOURMODELSETSERIALIZER_H +#define MITKCONTOURMODELSETSERIALIZER_H + +#include +#include + +namespace mitk +{ + +class MitkContourModel_EXPORT ContourModelSetSerializer : public BaseDataSerializer +{ +public: + mitkClassMacro(ContourModelSetSerializer, BaseDataSerializer); + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + virtual std::string Serialize(); + +protected: + + ContourModelSetSerializer(); + virtual ~ContourModelSetSerializer(); +}; + +} + +#endif // MITKCONTOURMODELSETSERIALIZER_H diff --git a/Modules/ContourModel/files.cmake b/Modules/ContourModel/files.cmake index 97e15752f2..beeab060ae 100644 --- a/Modules/ContourModel/files.cmake +++ b/Modules/ContourModel/files.cmake @@ -1,25 +1,27 @@ set(CPP_FILES Algorithms/mitkContourModelSource.cpp Algorithms/mitkContourModelSetSource.cpp Algorithms/mitkContourModelSubDivisionFilter.cpp Algorithms/mitkContourModelToPointSetFilter.cpp Algorithms/mitkContourModelToSurfaceFilter.cpp Algorithms/mitkImageToContourModelFilter.cpp Algorithms/mitkContourObjectFactory.cpp Algorithms/mitkContourModelUtils.cpp DataManagement/mitkContourModel.cpp DataManagement/mitkContourModelSet.cpp DataManagement/mitkContourElement.cpp Rendering/mitkContourModelGLMapper2D.cpp Rendering/mitkContourModelMapper2D.cpp Rendering/mitkContourModelMapper3D.cpp Rendering/mitkContourModelSetMapper3D.cpp Rendering/mitkContourModelSetGLMapper2D.cpp Rendering/mitkContourModelGLMapper2DBase.cpp IO/mitkContourModelIOFactory.cpp + IO/mitkContourModelSerializer.cpp IO/mitkContourModelReader.cpp IO/mitkContourModelWriter.cpp + IO/mitkContourModelSetSerializer.cpp IO/mitkContourModelSetReader.cpp IO/mitkContourModelSetWriter.cpp IO/mitkContourModelWriterFactory.cpp )