diff --git a/Modules/ContourModel/Algorithms/mitkContourObjectFactory.cpp b/Modules/ContourModel/Algorithms/mitkContourObjectFactory.cpp index 689bb6fbe0..946071026c 100644 --- a/Modules/ContourModel/Algorithms/mitkContourObjectFactory.cpp +++ b/Modules/ContourModel/Algorithms/mitkContourObjectFactory.cpp @@ -1,178 +1,157 @@ /*=================================================================== 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 "mitkContourObjectFactory.h" #include "mitkProperties.h" #include "mitkBaseRenderer.h" #include "mitkDataNode.h" #include "mitkCoreObjectFactory.h" #include "mitkContourModel.h" #include "mitkContourModelSet.h" -#include "mitkContourModelIOFactory.h" -#include "mitkContourModelWriterFactory.h" #include "mitkContourModelWriter.h" #include "mitkContourModelSetWriter.h" #include "mitkContourModelMapper2D.h" #include "mitkContourModelGLMapper2D.h" #include "mitkContourModelSetGLMapper2D.h" #include "mitkContourModelMapper3D.h" #include "mitkContourModelSetMapper3D.h" mitk::ContourObjectFactory::ContourObjectFactory() : CoreObjectFactoryBase() - , m_ContourModelIOFactory(mitk::ContourModelIOFactory::New().GetPointer()) - , m_ContourModelWriterFactory(mitk::ContourModelWriterFactory::New().GetPointer()) { static bool alreadyDone = false; if (!alreadyDone) { MITK_DEBUG << "ContourObjectFactory c'tor" << std::endl; - itk::ObjectFactoryBase::RegisterFactory( m_ContourModelIOFactory ); - itk::ObjectFactoryBase::RegisterFactory( m_ContourModelWriterFactory ); - - this->m_FileWriters.push_back(mitk::ContourModelWriter::New().GetPointer()); - this->m_FileWriters.push_back(mitk::ContourModelSetWriter::New().GetPointer()); - - CreateFileExtensionsMap(); - alreadyDone = true; } } mitk::ContourObjectFactory::~ContourObjectFactory() { - itk::ObjectFactoryBase::UnRegisterFactory(m_ContourModelIOFactory); - itk::ObjectFactoryBase::UnRegisterFactory(m_ContourModelWriterFactory); } mitk::Mapper::Pointer mitk::ContourObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; if ( id == mitk::BaseRenderer::Standard2D ) { std::string classname("ContourModel"); if( dynamic_cast(node->GetData())!=NULL ) { newMapper = mitk::ContourModelGLMapper2D::New(); newMapper->SetDataNode(node); } else if( dynamic_cast(node->GetData())!=NULL ) { newMapper = mitk::ContourModelSetGLMapper2D::New(); newMapper->SetDataNode(node); } } else if ( id == mitk::BaseRenderer::Standard3D ) { if( dynamic_cast(node->GetData())!=NULL ) { newMapper = mitk::ContourModelMapper3D::New(); newMapper->SetDataNode(node); } else if( dynamic_cast(node->GetData())!=NULL ) { newMapper = mitk::ContourModelSetMapper3D::New(); newMapper->SetDataNode(node); } } return newMapper; } void mitk::ContourObjectFactory::SetDefaultProperties(mitk::DataNode* node) { if(node==NULL) return; mitk::DataNode::Pointer nodePointer = node; if(node->GetData() ==NULL) return; if( dynamic_cast(node->GetData())!=NULL ) { mitk::ContourModelGLMapper2D::SetDefaultProperties(node); mitk::ContourModelMapper3D::SetDefaultProperties(node); } else if( dynamic_cast(node->GetData())!=NULL ) { mitk::ContourModelSetGLMapper2D::SetDefaultProperties(node); mitk::ContourModelSetMapper3D::SetDefaultProperties(node); } } const char* mitk::ContourObjectFactory::GetFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_FileExtensionsMap, fileExtension); return fileExtension.c_str(); }; mitk::CoreObjectFactoryBase::MultimapType mitk::ContourObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } mitk::CoreObjectFactoryBase::MultimapType mitk::ContourObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::ContourObjectFactory::CreateFileExtensionsMap() { - m_SaveFileExtensionsMap.insert(std::pair("*.cnt", "Contour Files")); - - m_FileExtensionsMap.insert(std::pair("*.cnt", "Contour File")); - - m_SaveFileExtensionsMap.insert(std::pair("*.cnt_set", "ContourModelSet Files")); - - m_FileExtensionsMap.insert(std::pair("*.cnt_set", "ContourModelSet File")); } const char* mitk::ContourObjectFactory::GetSaveFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); } void mitk::ContourObjectFactory::RegisterIOFactories() { } struct RegisterContourObjectFactory{ RegisterContourObjectFactory() : m_Factory( mitk::ContourObjectFactory::New() ) { mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory( m_Factory ); } ~RegisterContourObjectFactory() { mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory( m_Factory ); } mitk::ContourObjectFactory::Pointer m_Factory; }; static RegisterContourObjectFactory registerContourObjectFactory; diff --git a/Modules/ContourModel/Algorithms/mitkContourObjectFactory.h b/Modules/ContourModel/Algorithms/mitkContourObjectFactory.h index 59b78b0757..4e66bb3494 100644 --- a/Modules/ContourModel/Algorithms/mitkContourObjectFactory.h +++ b/Modules/ContourModel/Algorithms/mitkContourObjectFactory.h @@ -1,55 +1,54 @@ /*=================================================================== 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 SEGMENTATIONOBJECTFACTORY_H_INCLUDED #define SEGMENTATIONOBJECTFACTORY_H_INCLUDED #include "mitkCoreObjectFactoryBase.h" #include namespace mitk { class MitkContourModel_EXPORT ContourObjectFactory : public CoreObjectFactoryBase { public: mitkClassMacro(ContourObjectFactory,CoreObjectFactoryBase); itkFactorylessNewMacro(Self) itkCloneMacro(Self) virtual Mapper::Pointer CreateMapper(mitk::DataNode* node, MapperSlotId slotId); virtual void SetDefaultProperties(mitk::DataNode* node); virtual const char* GetFileExtensions(); virtual mitk::CoreObjectFactoryBase::MultimapType GetFileExtensionsMap(); virtual const char* GetSaveFileExtensions(); virtual mitk::CoreObjectFactoryBase::MultimapType GetSaveFileExtensionsMap(); /** \deprecatedSince{2013_09} */ DEPRECATED(void RegisterIOFactories()); protected: ContourObjectFactory(); ~ContourObjectFactory(); void CreateFileExtensionsMap(); MultimapType m_FileExtensionsMap; MultimapType m_SaveFileExtensionsMap; private: - itk::ObjectFactoryBase::Pointer m_ContourModelIOFactory; - itk::ObjectFactoryBase::Pointer m_ContourModelWriterFactory; + }; } #endif diff --git a/Modules/ContourModel/DataManagement/mitkContourModel.cpp b/Modules/ContourModel/DataManagement/mitkContourModel.cpp index 47b9ed2558..5adfc9bfbb 100644 --- a/Modules/ContourModel/DataManagement/mitkContourModel.cpp +++ b/Modules/ContourModel/DataManagement/mitkContourModel.cpp @@ -1,709 +1,709 @@ /*=================================================================== 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 #include mitk::ContourModel::ContourModel() : m_UpdateBoundingBox(true) { //set to initial state this->InitializeEmpty(); } mitk::ContourModel::ContourModel(const mitk::ContourModel &other) : mitk::BaseData(other), m_ContourSeries(other.m_ContourSeries), m_lineInterpolation(other.m_lineInterpolation) { m_SelectedVertex = NULL; } mitk::ContourModel::~ContourModel() { m_SelectedVertex = NULL; this->m_ContourSeries.clear();//TODO check destruction } void mitk::ContourModel::AddVertex(mitk::Point3D &vertex, int timestep) { if(!this->IsEmptyTimeStep(timestep) ) { this->AddVertex(vertex, false, timestep); } } void mitk::ContourModel::AddVertex(mitk::Point3D &vertex, bool isControlPoint, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_ContourSeries[timestep]->AddVertex(vertex, isControlPoint); this->InvokeEvent( ContourModelSizeChangeEvent() ); this->Modified();this->m_UpdateBoundingBox = true; } } void mitk::ContourModel::AddVertex(VertexType &vertex, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_ContourSeries[timestep]->AddVertex(vertex); this->InvokeEvent( ContourModelSizeChangeEvent() ); this->Modified();this->m_UpdateBoundingBox = true; } } void mitk::ContourModel::AddVertex(const VertexType* vertex, int timestep) { if(vertex != NULL) { this->m_ContourSeries[timestep]->AddVertex(*const_cast(vertex)); } } void mitk::ContourModel::AddVertexAtFront(mitk::Point3D &vertex, int timestep) { if(!this->IsEmptyTimeStep(timestep) ) { this->AddVertexAtFront(vertex, false, timestep); } } void mitk::ContourModel::AddVertexAtFront(mitk::Point3D &vertex, bool isControlPoint, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_ContourSeries[timestep]->AddVertexAtFront(vertex, isControlPoint); this->InvokeEvent( ContourModelSizeChangeEvent() ); this->Modified(); this->m_UpdateBoundingBox = true; } } void mitk::ContourModel::AddVertexAtFront(VertexType &vertex, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_ContourSeries[timestep]->AddVertexAtFront(vertex); this->InvokeEvent( ContourModelSizeChangeEvent() ); this->Modified(); this->m_UpdateBoundingBox = true; } } bool mitk::ContourModel::SetVertexAt(int pointId, const Point3D &point, unsigned int timestep) { if(!this->IsEmptyTimeStep(timestep)) { if(pointId >= 0 && this->m_ContourSeries[timestep]->GetSize() > pointId) { this->m_ContourSeries[timestep]->SetVertexAt( pointId, point ); this->Modified(); this->m_UpdateBoundingBox = true; return true; } return false; } return false; } bool mitk::ContourModel::SetVertexAt(int pointId, const VertexType *vertex, unsigned int timestep) { if(vertex==NULL) return false; if(!this->IsEmptyTimeStep(timestep)) { if(pointId >= 0 && this->m_ContourSeries[timestep]->GetSize() > pointId) { this->m_ContourSeries[timestep]->SetVertexAt( pointId, vertex ); this->Modified(); this->m_UpdateBoundingBox = true; return true; } return false; } return false; } void mitk::ContourModel::InsertVertexAtIndex(mitk::Point3D &vertex, int index, bool isControlPoint, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { if(index >= 0 && this->m_ContourSeries[timestep]->GetSize() > index) { this->m_ContourSeries[timestep]->InsertVertexAtIndex(vertex, isControlPoint, index); this->InvokeEvent( ContourModelSizeChangeEvent() ); this->Modified(); this->m_UpdateBoundingBox = true; } } } bool mitk::ContourModel::IsEmpty( int timestep) const { if(!this->IsEmptyTimeStep(timestep)) { return this->m_ContourSeries[timestep]->IsEmpty(); } return true; } bool mitk::ContourModel::IsEmpty() const { return this->IsEmpty(0); } int mitk::ContourModel::GetNumberOfVertices( int timestep) const { if(!this->IsEmptyTimeStep(timestep)) { return this->m_ContourSeries[timestep]->GetSize(); } return -1; } const mitk::ContourModel::VertexType* mitk::ContourModel::GetVertexAt(int index, int timestep) const { if(!this->IsEmptyTimeStep(timestep)) { return this->m_ContourSeries[timestep]->GetVertexAt(index); } return NULL; } int mitk::ContourModel::GetIndex(const VertexType *vertex, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { return this->m_ContourSeries[timestep]->GetIndex(vertex); } return -1; } void mitk::ContourModel::Close( int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_ContourSeries[timestep]->Close(); this->InvokeEvent( ContourModelClosedEvent() ); this->Modified();this->m_UpdateBoundingBox = true; } } void mitk::ContourModel::Open( int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_ContourSeries[timestep]->Open(); this->InvokeEvent( ContourModelClosedEvent() ); this->Modified();this->m_UpdateBoundingBox = true; } } void mitk::ContourModel::SetClosed(bool isClosed, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_ContourSeries[timestep]->SetClosed(isClosed); this->InvokeEvent( ContourModelClosedEvent() ); this->Modified();this->m_UpdateBoundingBox = true; } } bool mitk::ContourModel::IsEmptyTimeStep(unsigned int t) const { return (this->m_ContourSeries.size() <= t); } bool mitk::ContourModel::IsNearContour(mitk::Point3D &point, float eps, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { return this->m_ContourSeries[timestep]->IsNearContour(point, eps); } return false; } void mitk::ContourModel::Concatenate(mitk::ContourModel* other, int timestep, bool check) { if(!this->IsEmptyTimeStep(timestep)) { if( !this->m_ContourSeries[timestep]->IsClosed() ) { this->m_ContourSeries[timestep]->Concatenate(other->m_ContourSeries[timestep], check); this->InvokeEvent( ContourModelSizeChangeEvent() ); this->Modified();this->m_UpdateBoundingBox = true; } } } -mitk::ContourModel::VertexIterator mitk::ContourModel::Begin( int timestep) +mitk::ContourModel::VertexIterator mitk::ContourModel::Begin( int timestep) const { return this->IteratorBegin(timestep); } -mitk::ContourModel::VertexIterator mitk::ContourModel::IteratorBegin( int timestep) +mitk::ContourModel::VertexIterator mitk::ContourModel::IteratorBegin( int timestep) const { if(!this->IsEmptyTimeStep(timestep)) { return this->m_ContourSeries[timestep]->IteratorBegin(); } else { mitkThrow() << "No iterator at invalid timestep " << timestep << ". There are only " << this->GetTimeSteps() << " timesteps available."; } } -mitk::ContourModel::VertexIterator mitk::ContourModel::End( int timestep) +mitk::ContourModel::VertexIterator mitk::ContourModel::End( int timestep) const { return this->IteratorEnd(timestep); } -mitk::ContourModel::VertexIterator mitk::ContourModel::IteratorEnd( int timestep) +mitk::ContourModel::VertexIterator mitk::ContourModel::IteratorEnd( int timestep) const { if(!this->IsEmptyTimeStep(timestep)) { return this->m_ContourSeries[timestep]->IteratorEnd(); } else { mitkThrow() << "No iterator at invalid timestep " << timestep << ". There are only " << this->GetTimeSteps() << " timesteps available."; } } -bool mitk::ContourModel::IsClosed( int timestep) +bool mitk::ContourModel::IsClosed( int timestep) const { if(!this->IsEmptyTimeStep(timestep)) { return this->m_ContourSeries[timestep]->IsClosed(); } return false; } bool mitk::ContourModel::SelectVertexAt(mitk::Point3D &point, float eps, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_SelectedVertex = this->m_ContourSeries[timestep]->GetVertexAt(point, eps); } return this->m_SelectedVertex != NULL; } bool mitk::ContourModel::SelectVertexAt(int index, int timestep) { if(!this->IsEmptyTimeStep(timestep) && index >= 0) { return (this->m_SelectedVertex = this->m_ContourSeries[timestep]->GetVertexAt(index)); } return false; } bool mitk::ContourModel::SetControlVertexAt(mitk::Point3D &point, float eps, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { VertexType* vertex = this->m_ContourSeries[timestep]->GetVertexAt(point, eps); if (vertex != NULL) { vertex->IsControlPoint = true; return true; } } return false; } bool mitk::ContourModel::SetControlVertexAt(int index, int timestep) { if(!this->IsEmptyTimeStep(timestep) && index >= 0) { VertexType* vertex = this->m_ContourSeries[timestep]->GetVertexAt(index); if (vertex != NULL) { vertex->IsControlPoint = true; return true; } } return false; } bool mitk::ContourModel::RemoveVertex(const VertexType *vertex, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { if(this->m_ContourSeries[timestep]->RemoveVertex(vertex)) { this->Modified();this->m_UpdateBoundingBox = true; this->InvokeEvent( ContourModelSizeChangeEvent() ); return true; } } return false; } bool mitk::ContourModel::RemoveVertexAt(int index, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { if(this->m_ContourSeries[timestep]->RemoveVertexAt(index)) { this->Modified();this->m_UpdateBoundingBox = true; this->InvokeEvent( ContourModelSizeChangeEvent() ); return true; } } return false; } bool mitk::ContourModel::RemoveVertexAt(mitk::Point3D &point, float eps, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { if(this->m_ContourSeries[timestep]->RemoveVertexAt(point, eps)) { this->Modified();this->m_UpdateBoundingBox = true; this->InvokeEvent( ContourModelSizeChangeEvent() ); return true; } } return false; } void mitk::ContourModel::ShiftSelectedVertex(mitk::Vector3D &translate) { if(this->m_SelectedVertex) { this->ShiftVertex(this->m_SelectedVertex,translate); this->Modified();this->m_UpdateBoundingBox = true; } } void mitk::ContourModel::ShiftContour(mitk::Vector3D &translate, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { VertexListType* vList = this->m_ContourSeries[timestep]->GetVertexList(); VertexIterator it = vList->begin(); VertexIterator end = vList->end(); //shift all vertices while(it != end) { this->ShiftVertex((*it),translate); it++; } this->Modified();this->m_UpdateBoundingBox = true; this->InvokeEvent( ContourModelShiftEvent() ); } } void mitk::ContourModel::ShiftVertex(VertexType* vertex, mitk::Vector3D &vector) { vertex->Coordinates[0] += vector[0]; vertex->Coordinates[1] += vector[1]; vertex->Coordinates[2] += vector[2]; } void mitk::ContourModel::Clear(int timestep) { if(!this->IsEmptyTimeStep(timestep)) { //clear data at timestep this->m_ContourSeries[timestep]->Clear(); this->InitializeEmpty(); this->Modified();this->m_UpdateBoundingBox = true; } } void mitk::ContourModel::Expand(unsigned int timeSteps ) { std::size_t oldSize = this->m_ContourSeries.size(); if( static_cast(timeSteps) > oldSize ) { Superclass::Expand(timeSteps); //insert contours for each new timestep for( std::size_t i = oldSize; i < static_cast(timeSteps); i++) { m_ContourSeries.push_back(mitk::ContourElement::New()); } this->InvokeEvent( ContourModelExpandTimeBoundsEvent() ); } } void mitk::ContourModel::SetRequestedRegionToLargestPossibleRegion () { //no support for regions } bool mitk::ContourModel::RequestedRegionIsOutsideOfTheBufferedRegion () { //no support for regions return false; } bool mitk::ContourModel::VerifyRequestedRegion () { //no support for regions return true; } const mitk::BaseGeometry * mitk::ContourModel::GetUpdatedGeometry (int t) { return Superclass::GetUpdatedGeometry(t); } mitk::BaseGeometry* mitk::ContourModel::GetGeometry (int t)const { return Superclass::GetGeometry(t); } void mitk::ContourModel::SetRequestedRegion( const itk::DataObject* /*data*/) { //no support for regions } void mitk::ContourModel::Clear() { //clear data and set to initial state again this->ClearData(); this->InitializeEmpty(); this->Modified();this->m_UpdateBoundingBox = true; } void mitk::ContourModel::RedistributeControlVertices(int period, int timestep) { if(!this->IsEmptyTimeStep(timestep)) { this->m_ContourSeries[timestep]->RedistributeControlVertices(this->GetSelectedVertex(), period); this->InvokeEvent( ContourModelClosedEvent() ); this->Modified();this->m_UpdateBoundingBox = true; } } void mitk::ContourModel::ClearData() { //call the superclass, this releases the data of BaseData Superclass::ClearData(); //clear out the time resolved contours this->m_ContourSeries.clear(); } void mitk::ContourModel::Initialize() { this->InitializeEmpty(); this->Modified();this->m_UpdateBoundingBox = true; } void mitk::ContourModel::Initialize(mitk::ContourModel &other) { mitk::TimeStepType numberOfTimesteps = other.GetTimeGeometry()->CountTimeSteps(); this->InitializeTimeGeometry(numberOfTimesteps); for(mitk::TimeStepType currentTimestep = 0; currentTimestep < numberOfTimesteps; currentTimestep++) { this->m_ContourSeries.push_back(mitk::ContourElement::New()); this->SetClosed(other.IsClosed(currentTimestep),currentTimestep); } m_SelectedVertex = NULL; this->m_lineInterpolation = other.m_lineInterpolation; this->Modified();this->m_UpdateBoundingBox = true; } void mitk::ContourModel::InitializeEmpty() { //clear data at timesteps this->m_ContourSeries.resize(0); this->m_ContourSeries.push_back(mitk::ContourElement::New()); //set number of timesteps to one this->InitializeTimeGeometry(1); m_SelectedVertex = NULL; this->m_lineInterpolation = ContourModel::LINEAR; } void mitk::ContourModel::UpdateOutputInformation() { if ( this->GetSource() ) { this->GetSource()->UpdateOutputInformation(); } if(this->m_UpdateBoundingBox) { //update the bounds of the geometry according to the stored vertices ScalarType mitkBounds[6]; //calculate the boundingbox at each timestep typedef itk::BoundingBox BoundingBoxType; typedef BoundingBoxType::PointsContainer PointsContainer; int timesteps = this->GetTimeSteps(); //iterate over the timesteps for(int currenTimeStep = 0; currenTimeStep < timesteps; currenTimeStep++) { if( dynamic_cast< mitk::PlaneGeometry* >(this->GetGeometry(currenTimeStep)) ) { //do not update bounds for 2D geometries, as they are unfortunately defined with min bounds 0! return; } else {//we have a 3D geometry -> let's update bounds //only update bounds if the contour was modified if (this->GetMTime() > this->GetGeometry(currenTimeStep)->GetBoundingBox()->GetMTime()) { mitkBounds[0] = 0.0; mitkBounds[1] = 0.0; mitkBounds[2] = 0.0; mitkBounds[3] = 0.0; mitkBounds[4] = 0.0; mitkBounds[5] = 0.0; BoundingBoxType::Pointer boundingBox = BoundingBoxType::New(); PointsContainer::Pointer points = PointsContainer::New(); VertexIterator it = this->IteratorBegin(currenTimeStep); VertexIterator end = this->IteratorEnd(currenTimeStep); //fill the boundingbox with the points while(it != end) { Point3D currentP = (*it)->Coordinates; BoundingBoxType::PointType p; p.CastFrom(currentP); points->InsertElement(points->Size(), p); it++; } //construct the new boundingBox boundingBox->SetPoints(points); boundingBox->ComputeBoundingBox(); BoundingBoxType::BoundsArrayType tmp = boundingBox->GetBounds(); mitkBounds[0] = tmp[0]; mitkBounds[1] = tmp[1]; mitkBounds[2] = tmp[2]; mitkBounds[3] = tmp[3]; mitkBounds[4] = tmp[4]; mitkBounds[5] = tmp[5]; //set boundingBox at current timestep BaseGeometry* geometry3d = this->GetGeometry(currenTimeStep); geometry3d->SetBounds(mitkBounds); } } } this->m_UpdateBoundingBox = false; } GetTimeGeometry()->Update(); } void mitk::ContourModel::ExecuteOperation(mitk::Operation* /*operation*/) { //not supported yet } diff --git a/Modules/ContourModel/DataManagement/mitkContourModel.h b/Modules/ContourModel/DataManagement/mitkContourModel.h index 78a6f9e50f..1c5bde1d11 100644 --- a/Modules/ContourModel/DataManagement/mitkContourModel.h +++ b/Modules/ContourModel/DataManagement/mitkContourModel.h @@ -1,474 +1,474 @@ /*=================================================================== 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 _MITK_CONTOURMODEL_H_ #define _MITK_CONTOURMODEL_H_ #include "mitkCommon.h" #include #include "mitkBaseData.h" #include namespace mitk { /** \brief ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are stored in a mitk::ContourElement is stored for each timestep. The contour line segments are implicitly defined by the given linked vertices. By default two control points are are linked by a straight line.It is possible to add vertices at front and end of the contour and to iterate in both directions. Points are specified containing coordinates and additional (data) information, see mitk::ContourElement. For accessing a specific vertex either an index or a position in 3D Space can be used. The vertices are best accessed by using a VertexIterator. Interaction with the contour is thus available without any mitk interactor class using the api of ContourModel. It is possible to shift single vertices also as shifting the whole contour. A contour can be either open like a single curved line segment or closed. A closed contour can for example represent a jordan curve. \section mitkContourModelDisplayOptions Display Options The default mappers for this data structure are mitk::ContourModelGLMapper2D and mitk::ContourModelMapper3D. See these classes for display options which can can be set via properties. */ class MitkContourModel_EXPORT ContourModel : public BaseData { public: mitkClassMacro(ContourModel, BaseData); itkFactorylessNewMacro(Self) itkCloneMacro(Self) /*+++++++++++++++ typedefs +++++++++++++++++++++++++++++++*/ typedef mitk::ContourElement::VertexType VertexType; typedef mitk::ContourElement::VertexListType VertexListType; typedef mitk::ContourElement::VertexIterator VertexIterator; typedef mitk::ContourElement::ConstVertexIterator ConstVertexIterator; typedef std::vector< mitk::ContourElement::Pointer > ContourModelSeries; /*+++++++++++++++ END typedefs ++++++++++++++++++++++++++++*/ /** \brief Possible interpolation of the line segments between control points */ enum LineSegmentInterpolation{ LINEAR, B_SPLINE }; /*++++++++++++++++ inline methods +++++++++++++++++++++++*/ /** \brief Get the current selected vertex. */ VertexType* GetSelectedVertex() { return this->m_SelectedVertex; } /** \brief Deselect vertex. */ void Deselect() { this->m_SelectedVertex = NULL; } /** \brief Set selected vertex as control point */ void SetSelectedVertexAsControlPoint(bool isControlPoint=true) { if (this->m_SelectedVertex) { m_SelectedVertex->IsControlPoint = isControlPoint; this->Modified(); } } /** \brief Set the interpolation of the line segments between control points. */ void SetLineSegmentInterpolation(LineSegmentInterpolation interpolation) { this->m_lineInterpolation = interpolation; this->Modified(); } /** \brief Get the interpolation of the line segments between control points. */ LineSegmentInterpolation GetLineSegmentInterpolation() { return this->m_lineInterpolation; } /*++++++++++++++++ END inline methods +++++++++++++++++++++++*/ /** \brief Add a vertex to the contour at given timestep. The vertex is added at the end of contour. \param vertex - coordinate representation of a control point \param timestep - the timestep at which the vertex will be add ( default 0) @Note Adding a vertex to a timestep which exceeds the timebounds of the contour will not be added, the TimeGeometry will not be expanded. */ void AddVertex(mitk::Point3D &vertex, int timestep=0); /** \brief Add a vertex to the contour at given timestep. The vertex is added at the end of contour. \param vertex - coordinate representation of a control point \param timestep - the timestep at which the vertex will be add ( default 0) @Note Adding a vertex to a timestep which exceeds the timebounds of the contour will not be added, the TimeGeometry will not be expanded. */ void AddVertex(VertexType &vertex, int timestep=0); /** \brief Add a vertex to the contour at given timestep. The vertex is added at the end of contour. \param vertex - coordinate representation of a control point \param timestep - the timestep at which the vertex will be add ( default 0) @Note Adding a vertex to a timestep which exceeds the timebounds of the contour will not be added, the TimeSlicedGeometry will not be expanded. */ void AddVertex(const VertexType* vertex, int timestep=0); /** \brief Add a vertex to the contour. \param vertex - coordinate representation of a control point \param timestep - the timestep at which the vertex will be add ( default 0) \param isControlPoint - specifies the vertex to be handled in a special way (e.g. control points will be rendered). @Note Adding a vertex to a timestep which exceeds the timebounds of the contour will not be added, the TimeGeometry will not be expanded. */ void AddVertex(mitk::Point3D &vertex, bool isControlPoint, int timestep=0); /** \brief Add a vertex to the contour at given timestep AT THE FRONT of the contour. The vertex is added at the FRONT of contour. \param vertex - coordinate representation of a control point \param timestep - the timestep at which the vertex will be add ( default 0) @Note Adding a vertex to a timestep which exceeds the timebounds of the contour will not be added, the TimeGeometry will not be expanded. */ void AddVertexAtFront(mitk::Point3D &vertex, int timestep=0); /** \brief Add a vertex to the contour at given timestep AT THE FRONT of the contour. The vertex is added at the FRONT of contour. \param vertex - coordinate representation of a control point \param timestep - the timestep at which the vertex will be add ( default 0) @Note Adding a vertex to a timestep which exceeds the timebounds of the contour will not be added, the TimeGeometry will not be expanded. */ void AddVertexAtFront(VertexType &vertex, int timestep=0); /** \brief Add a vertex to the contour at given timestep AT THE FRONT of the contour. \param vertex - coordinate representation of a control point \param timestep - the timestep at which the vertex will be add ( default 0) \param isControlPoint - specifies the vertex to be handled in a special way (e.g. control points will be rendered). @Note Adding a vertex to a timestep which exceeds the timebounds of the contour will not be added, the TimeGeometry will not be expanded. */ void AddVertexAtFront(mitk::Point3D &vertex, bool isControlPoint, int timestep=0); /** \brief Insert a vertex at given index. */ void InsertVertexAtIndex(mitk::Point3D &vertex, int index, bool isControlPoint=false, int timestep=0); /** \brief Set a coordinates for point at given index. */ bool SetVertexAt(int pointId, const mitk::Point3D &point, unsigned int timestep=0); /** \brief Set a coordinates for point at given index. */ bool SetVertexAt(int pointId, const VertexType* vertex, unsigned int timestep=0); /** \brief Return if the contour is closed or not. */ - bool IsClosed( int timestep=0); + bool IsClosed( int timestep=0) const; /** \brief Concatenate two contours. The starting control point of the other will be added at the end of the contour. \pararm timestep - the timestep at which the vertex will be add ( default 0) \pararm check - check for intersections ( default false) */ void Concatenate(mitk::ContourModel* other, int timestep=0, bool check=false); /** \brief Returns a const VertexIterator at the start element of the contour. @throw mitk::Exception if the timestep is invalid. */ - VertexIterator Begin( int timestep=0); + VertexIterator Begin( int timestep=0) const; /** \brief Returns a const VertexIterator at the start element of the contour. @throw mitk::Exception if the timestep is invalid. */ - VertexIterator IteratorBegin( int timestep=0); + VertexIterator IteratorBegin( int timestep=0) const; /** \brief Returns a const VertexIterator at the end element of the contour. @throw mitk::Exception if the timestep is invalid. */ - VertexIterator End( int timestep=0); + VertexIterator End( int timestep=0) const; /** \brief Returns a const VertexIterator at the end element of the contour. @throw mitk::Exception if the timestep is invalid. */ - VertexIterator IteratorEnd( int timestep=0); + VertexIterator IteratorEnd( int timestep=0) const; /** \brief Close the contour. The last control point will be linked with the first point. */ virtual void Close( int timestep=0); /** \brief Set isClosed to false contour. The link between the last control point the first point will be removed. */ virtual void Open( int timestep=0); /** \brief Set closed property to given boolean. false - The link between the last control point the first point will be removed. true - The last control point will be linked with the first point. */ virtual void SetClosed(bool isClosed, int timestep=0); /** \brief Returns the number of vertices at a given timestep. \param timestep - default = 0 */ int GetNumberOfVertices( int timestep=0) const; /** \brief Returns whether the contour model is empty at a given timestep. \pararm timestep - default = 0 */ virtual bool IsEmpty( int timestep) const; /** \brief Returns whether the contour model is empty. */ virtual bool IsEmpty() const; /** \brief Returns the vertex at the index position within the container. */ virtual const VertexType* GetVertexAt(int index, int timestep=0) const; /** \brief Remove a vertex at given timestep within the container. \return index of vertex. -1 if not found. */ int GetIndex(const VertexType* vertex, int timestep=0); /** \brief Check if there isn't something at this timestep. */ virtual bool IsEmptyTimeStep(unsigned int t) const; /** \brief Check if mouse cursor is near the contour. */ virtual bool IsNearContour(mitk::Point3D &point, float eps, int timestep); /** \brief Mark a vertex at an index in the container as selected. */ bool SelectVertexAt(int index, int timestep=0); /** \brief Mark a vertex at an index in the container as control point. */ bool SetControlVertexAt(int index, int timestep=0); /** \brief Mark a vertex at a given position in 3D space. \param point - query point in 3D space \param eps - radius for nearest neighbour search (error bound). \param timestep - search at this timestep @return true = vertex found; false = no vertex found */ bool SelectVertexAt(mitk::Point3D &point, float eps, int timestep=0); /* \pararm point - query point in 3D space \pararm eps - radius for nearest neighbour search (error bound). \pararm timestep - search at this timestep @return true = vertex found; false = no vertex found */ bool SetControlVertexAt(mitk::Point3D &point, float eps, int timestep=0); /** \brief Remove a vertex at given index within the container. @return true = the vertex was successfuly removed; false = wrong index. */ bool RemoveVertexAt(int index, int timestep=0); /** \brief Remove a vertex at given timestep within the container. @return true = the vertex was successfuly removed. */ bool RemoveVertex(const VertexType* vertex, int timestep=0); /** \brief Remove a vertex at a query position in 3D space. The vertex to be removed will be search by nearest neighbour search. Note that possibly no vertex at this position and eps is stored inside the contour. @return true = the vertex was successfuly removed; false = no vertex found. */ bool RemoveVertexAt(mitk::Point3D &point, float eps, int timestep=0); /** \brief Shift the currently selected vertex by a translation vector. \param translate - the translation vector. */ void ShiftSelectedVertex(mitk::Vector3D &translate); /** \brief Shift the whole contour by a translation vector at given timestep. \param translate - the translation vector. \param timestep - at this timestep the contour will be shifted. */ void ShiftContour(mitk::Vector3D &translate, int timestep=0); /** \brief Clear the storage container at given timestep. All control points are removed at timestep. */ virtual void Clear(int timestep); /** \brief Initialize all data objects */ virtual void Initialize(); /** \brief Initialize object with specs of other contour. Note: No data will be copied. */ void Initialize(mitk::ContourModel &other); /*++++++++++++++++++ method inherit from base data +++++++++++++++++++++++++++*/ /** \brief Inherit from base data - no region support available for contourModel objects. */ virtual void SetRequestedRegionToLargestPossibleRegion (); /** \brief Inherit from base data - no region support available for contourModel objects. */ virtual bool RequestedRegionIsOutsideOfTheBufferedRegion (); /** \brief Inherit from base data - no region support available for contourModel objects. */ virtual bool VerifyRequestedRegion (); /** \brief Get the updated geometry with recomputed bounds. */ virtual const mitk::BaseGeometry* GetUpdatedGeometry (int t=0); /** \brief Get the BaseGeometry for timestep t. */ virtual mitk::BaseGeometry* GetGeometry (int t=0) const; /** \brief Inherit from base data - no region support available for contourModel objects. */ virtual void SetRequestedRegion( const itk::DataObject *data); /** \brief Expand the timebounds of the TimeGeometry to given number of timesteps. */ virtual void Expand( unsigned int timeSteps ); /** \brief Update the OutputInformation of a ContourModel object The BoundingBox of the contour will be updated, if necessary. */ virtual void UpdateOutputInformation(); /** \brief Clear the storage container. The object is set to initial state. All control points are removed and the number of timesteps are set to 1. */ virtual void Clear(); /** \brief overwrite if the Data can be called by an Interactor (StateMachine). */ void ExecuteOperation(Operation* operation); /** \brief Redistributes ontrol vertices with a given period (as number of vertices) \param period - the number of vertices between control points. \param timestep - at this timestep all lines will be rebuilt. */ virtual void RedistributeControlVertices(int period, int timestep); protected: mitkCloneMacro(Self); ContourModel(); ContourModel(const mitk::ContourModel &other); virtual ~ContourModel(); //inherit from BaseData. called by Clear() virtual void ClearData(); //inherit from BaseData. Initial state of a contour with no vertices and a single timestep. virtual void InitializeEmpty(); //Shift a vertex void ShiftVertex(VertexType* vertex, mitk::Vector3D &vector); //Storage with time resolved support. ContourModelSeries m_ContourSeries; //The currently selected vertex. VertexType* m_SelectedVertex; //The interpolation of the line segment between control points. LineSegmentInterpolation m_lineInterpolation; //only update the bounding geometry if necessary bool m_UpdateBoundingBox; }; itkEventMacro( ContourModelEvent, itk::AnyEvent ); itkEventMacro( ContourModelShiftEvent, ContourModelEvent ); itkEventMacro( ContourModelSizeChangeEvent, ContourModelEvent ); itkEventMacro( ContourModelAddEvent, ContourModelSizeChangeEvent ); itkEventMacro( ContourModelRemoveEvent, ContourModelSizeChangeEvent ); itkEventMacro( ContourModelExpandTimeBoundsEvent, ContourModelEvent ); itkEventMacro( ContourModelClosedEvent, ContourModelEvent ); } #endif diff --git a/Modules/ContourModel/DataManagement/mitkContourModelSet.cpp b/Modules/ContourModel/DataManagement/mitkContourModelSet.cpp index e782bc11d8..dc8d460770 100644 --- a/Modules/ContourModel/DataManagement/mitkContourModelSet.cpp +++ b/Modules/ContourModel/DataManagement/mitkContourModelSet.cpp @@ -1,214 +1,214 @@ /*=================================================================== 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 #include #include mitk::ContourModelSet::ContourModelSet() : m_Contours(), m_UpdateBoundingBox(true) { this->InitializeEmpty(); } mitk::ContourModelSet::ContourModelSet(const mitk::ContourModelSet &other) : mitk::BaseData(other), m_Contours(other.m_Contours) { this->InitializeTimeGeometry(1); } mitk::ContourModelSet::~ContourModelSet() { this->m_Contours.clear(); } void mitk::ContourModelSet::InitializeEmpty() { this->InitializeTimeGeometry(1); m_Contours.resize(0); } void mitk::ContourModelSet::AddContourModel(mitk::ContourModel &contourModel) { this->m_Contours.push_back(&contourModel); m_UpdateBoundingBox = true; } void mitk::ContourModelSet::AddContourModel(mitk::ContourModel::Pointer contourModel) { this->m_Contours.push_back(contourModel); m_UpdateBoundingBox = true; } -mitk::ContourModel* mitk::ContourModelSet::GetContourModelAt(int index) +mitk::ContourModel* mitk::ContourModelSet::GetContourModelAt(int index) const { if( index >= 0 && static_cast(index) < this->m_Contours.size() ) { return this->m_Contours.at(index).GetPointer(); } else { return NULL; } } bool mitk::ContourModelSet::IsEmpty() const { return this->m_Contours.empty(); } mitk::ContourModelSet::ContourModelListType* mitk::ContourModelSet::GetContourModelList() { return &(this->m_Contours); } bool mitk::ContourModelSet::RemoveContourModel(mitk::ContourModel* contourModel) { ContourModelSetIterator it = this->m_Contours.begin(); ContourModelSetIterator end = this->m_Contours.end(); //search for ContourModel and remove it if exists while(it != end) { if((*it) == contourModel) { this->m_Contours.erase(it); m_UpdateBoundingBox = true; return true; } it++; } return false; } bool mitk::ContourModelSet::RemoveContourModelAt(int index) { if( index >= 0 && static_cast(index) < this->m_Contours.size() ) { this->m_Contours.erase(this->m_Contours.begin()+index); m_UpdateBoundingBox = true; return true; } else { return false; } } void mitk::ContourModelSet::Clear() { this->m_Contours.clear(); m_UpdateBoundingBox = true; } void mitk::ContourModelSet::UpdateOutputInformation() { if ( this->GetSource() ) { this->GetSource()->UpdateOutputInformation(); } if(this->m_UpdateBoundingBox) { //update the bounds of the geometry according to the stored vertices mitk::ScalarType mitkBounds[6]; //calculate the boundingbox at each timestep typedef itk::BoundingBox BoundingBoxType; typedef BoundingBoxType::PointsContainer PointsContainer; int timesteps = this->GetTimeSteps(); //iterate over the timesteps for(int currenTimeStep = 0; currenTimeStep < timesteps; currenTimeStep++) { //only update bounds if the contour was modified if (this->GetMTime() > this->GetGeometry(currenTimeStep)->GetBoundingBox()->GetMTime()) { mitkBounds[0] = 0.0; mitkBounds[1] = 0.0; mitkBounds[2] = 0.0; mitkBounds[3] = 0.0; mitkBounds[4] = 0.0; mitkBounds[5] = 0.0; BoundingBoxType::Pointer boundingBox = BoundingBoxType::New(); PointsContainer::Pointer points = PointsContainer::New(); mitk::ContourModelSet::ContourModelSetIterator contoursIt = this->Begin(); mitk::ContourModelSet::ContourModelSetIterator contoursEnd = this->End(); while(contoursIt!=contoursEnd) { mitk::ContourModel::VertexIterator it = contoursIt->GetPointer()->Begin(currenTimeStep); mitk::ContourModel::VertexIterator end = contoursIt->GetPointer()->End(currenTimeStep); //fill the boundingbox with the points while(it != end) { Point3D currentP = (*it)->Coordinates; BoundingBoxType::PointType p; p.CastFrom(currentP); points->InsertElement(points->Size(), p); it++; } ++contoursIt; } //construct the new boundingBox boundingBox->SetPoints(points); boundingBox->ComputeBoundingBox(); BoundingBoxType::BoundsArrayType tmp = boundingBox->GetBounds(); mitkBounds[0] = tmp[0]; mitkBounds[1] = tmp[1]; mitkBounds[2] = tmp[2]; mitkBounds[3] = tmp[3]; mitkBounds[4] = tmp[4]; mitkBounds[5] = tmp[5]; //set boundingBox at current timestep BaseGeometry* geometry3d = this->GetGeometry(currenTimeStep); geometry3d->SetBounds(mitkBounds); } } this->m_UpdateBoundingBox = false; } GetTimeGeometry()->Update(); } diff --git a/Modules/ContourModel/DataManagement/mitkContourModelSet.h b/Modules/ContourModel/DataManagement/mitkContourModelSet.h index cd157ac34e..e54f7372c6 100644 --- a/Modules/ContourModel/DataManagement/mitkContourModelSet.h +++ b/Modules/ContourModel/DataManagement/mitkContourModelSet.h @@ -1,143 +1,143 @@ /*=================================================================== 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 _mitkContourModelSet_H_ #define _mitkContourModelSet_H_ #include "mitkCommon.h" #include #include "mitkContourModel.h" #include namespace mitk { /** \brief */ class MitkContourModel_EXPORT ContourModelSet : public mitk::BaseData { public: mitkClassMacro(ContourModelSet, mitk::BaseData); itkFactorylessNewMacro(Self) itkCloneMacro(Self) typedef std::deque ContourModelListType; typedef ContourModelListType::iterator ContourModelSetIterator; // start of inline methods /** \brief Return an iterator a the front. */ virtual ContourModelSetIterator Begin() { return this->m_Contours.begin(); } /** \brief Return an iterator a the front. */ virtual ContourModelSetIterator End() { return this->m_Contours.end(); } /** \brief Returns the number of contained contours. */ - virtual int GetSize() + virtual int GetSize() const { return this->m_Contours.size(); } // end of inline methods /** \brief Add a ContourModel to the container. */ virtual void AddContourModel(mitk::ContourModel &contourModel); /** \brief Add a ContourModel to the container. */ virtual void AddContourModel(mitk::ContourModel::Pointer contourModel); /** \brief Returns the ContourModel a given index \param index */ - virtual mitk::ContourModel* GetContourModelAt(int index); + virtual mitk::ContourModel* GetContourModelAt(int index) const; /** \brief Returns the container of the contours. */ ContourModelListType* GetContourModelList(); /** \brief Returns a bool whether the container is empty or not. */ bool IsEmpty() const; /** \brief Remove the given ContourModel from the container if exists. \param ContourModel - the ContourModel to be removed. */ virtual bool RemoveContourModel(mitk::ContourModel* contourModel); /** \brief Remove a ContourModel at given index within the container if exists. \param index - the index where the ContourModel should be removed. */ virtual bool RemoveContourModelAt(int index); /** \brief Clear the storage container. */ virtual void Clear(); //////////////// inherit from mitk::BaseData //////////////////// /* NO support for regions ! */ void SetRequestedRegionToLargestPossibleRegion(){} bool RequestedRegionIsOutsideOfTheBufferedRegion(){return false;} bool VerifyRequestedRegion(){return true;} void SetRequestedRegion(const itk::DataObject* ){} /** \brief Update the OutputInformation of a ContourModel object The BoundingBox of the contour will be updated, if necessary. */ virtual void UpdateOutputInformation(); //////////////// END inherit from mitk::BaseData //////////////////// protected: mitkCloneMacro(Self); ContourModelSet(); ContourModelSet(const mitk::ContourModelSet &other); virtual ~ContourModelSet(); //inherit from BaseData. Initial state with no contours and a single timestep. virtual void InitializeEmpty(); ContourModelListType m_Contours; //only update the bounding geometry if necessary bool m_UpdateBoundingBox; }; } // namespace mitk #endif // _mitkContourModelSet_H_ diff --git a/Modules/ContourModel/IO/mitkContourModelIOFactory.cpp b/Modules/ContourModel/IO/mitkContourModelIOFactory.cpp deleted file mode 100644 index 4c8d2822e3..0000000000 --- a/Modules/ContourModel/IO/mitkContourModelIOFactory.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*=================================================================== - -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 "mitkContourModelIOFactory.h" -#include "mitkIOAdapter.h" -#include "mitkContourModelReader.h" -#include "mitkContourModelSetReader.h" - -#include "itkVersion.h" - - -namespace mitk -{ - ContourModelIOFactory::ContourModelIOFactory() - { - this->RegisterOverride("mitkIOAdapter", - "mitkContourModelReader", - "mitk ContourModel IO", - 1, - itk::CreateObjectFunction >::New()); - - this->RegisterOverride("mitkIOAdapter", - "mitkContourModelSetReader", - "mitk ContourModelSet IO", - 1, - itk::CreateObjectFunction >::New()); - } - - ContourModelIOFactory::~ContourModelIOFactory() - { - } - - const char* ContourModelIOFactory::GetITKSourceVersion() const - { - return ITK_SOURCE_VERSION; - } - - const char* ContourModelIOFactory::GetDescription() const - { - return "ContourModel IO Factory, allows the loading of MITK ContourModels"; - } - -} diff --git a/Modules/ContourModel/IO/mitkContourModelIOFactory.h b/Modules/ContourModel/IO/mitkContourModelIOFactory.h deleted file mode 100644 index 8e723660ad..0000000000 --- a/Modules/ContourModel/IO/mitkContourModelIOFactory.h +++ /dev/null @@ -1,75 +0,0 @@ -/*=================================================================== - -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 __mitkContourModelIOFactory_h -#define __mitkContourModelIOFactory_h - -#ifdef _MSC_VER -#pragma warning ( disable : 4786 ) -#endif - -#include -#include "itkObjectFactoryBase.h" -#include "mitkBaseData.h" - -namespace mitk -{ -//##Documentation -//## @brief Create instances of ContourModelReader objects using an object factory. -//## -//## @ingroup IO -class MitkContourModel_EXPORT ContourModelIOFactory : public itk::ObjectFactoryBase -{ -public: - /** Standard class typedefs. */ - typedef ContourModelIOFactory Self; - typedef itk::ObjectFactoryBase Superclass; - typedef itk::SmartPointer Pointer; - typedef itk::SmartPointer ConstPointer; - - /** Class methods used to interface with the registered factories. */ - virtual const char* GetITKSourceVersion(void) const; - virtual const char* GetDescription(void) const; - - /** Method for class instantiation. */ - itkFactorylessNewMacro(Self); - static ContourModelIOFactory* FactoryNew() { return new ContourModelIOFactory;} - /** Run-time type information (and related methods). */ - itkTypeMacro(ContourModelIOFactory, ObjectFactoryBase); - - /** - * Register one factory of this type - * \deprecatedSince{2013_09} - */ - DEPRECATED(static void RegisterOneFactory(void)) - { - ContourModelIOFactory::Pointer ContourModelIOFactory = ContourModelIOFactory::New(); - ObjectFactoryBase::RegisterFactory(ContourModelIOFactory); - } - -protected: - ContourModelIOFactory(); - ~ContourModelIOFactory(); - -private: - ContourModelIOFactory(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -}; - - -} // end namespace mitk - -#endif diff --git a/Modules/ContourModel/IO/mitkContourModelReader.cpp b/Modules/ContourModel/IO/mitkContourModelReader.cpp index 831b13ebcc..9242064561 100644 --- a/Modules/ContourModel/IO/mitkContourModelReader.cpp +++ b/Modules/ContourModel/IO/mitkContourModelReader.cpp @@ -1,217 +1,160 @@ /*=================================================================== 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 "mitkContourModelReader.h" +#include #include #include #include -mitk::ContourModelReader::ContourModelReader() +mitk::ContourModelReader::ContourModelReader(const mitk::ContourModelReader& other) + : mitk::AbstractFileReader(other) { - m_Success = false; } +mitk::ContourModelReader::ContourModelReader() + : AbstractFileReader() +{ + std::string category = "Contour File"; + mitk::CustomMimeType customMimeType; + customMimeType.SetCategory(category); + customMimeType.AddExtension("cnt"); -mitk::ContourModelReader::~ContourModelReader() -{} + this->SetDescription(category); + this->SetMimeType(customMimeType); + m_ServiceReg = this->RegisterService(); +} -void mitk::ContourModelReader::GenerateData() +mitk::ContourModelReader::~ContourModelReader() { - std::locale::global(std::locale("C")); +} + +std::vector > mitk::ContourModelReader::Read() +{ + std::vector > result; + std::string location = GetInputLocation(); + + std::locale::global(std::locale("C")); - m_Success = false; - if ( m_FileName == "" ) - { - itkWarningMacro( << "Sorry, filename has not been set!" ); - return ; - } - if ( ! this->CanReadFile( m_FileName.c_str() ) ) - { - itkWarningMacro( << "Sorry, can't read file " << m_FileName << "!" ); - return ; - } try{ - TiXmlDocument doc(m_FileName.c_str()); + TiXmlDocument doc(location.c_str()); bool loadOkay = doc.LoadFile(); if (loadOkay) { TiXmlHandle docHandle( &doc ); /*++++ handle n contourModels within data tags ++++*/ - unsigned int contourCounter(0); - for( TiXmlElement* currentContourElement = docHandle.FirstChildElement("contourModel").ToElement(); currentContourElement != NULL; currentContourElement = currentContourElement->NextSiblingElement()) { mitk::ContourModel::Pointer newContourModel = mitk::ContourModel::New(); if(currentContourElement->FirstChildElement("data")->FirstChildElement("timestep") != NULL) { //handle geometry information //TiXmlElement* currentGeometryInfo = currentContourElement->FirstChildElement("head")->FirstChildElement("geometryInformation")->ToElement(); ///////////// NOT SUPPORTED YET //////////////// /*++++ handle n timesteps within timestep tags ++++*/ for( TiXmlElement* currentTimeSeries = currentContourElement->FirstChildElement("data")->FirstChildElement("timestep")->ToElement(); currentTimeSeries != NULL; currentTimeSeries = currentTimeSeries->NextSiblingElement()) { unsigned int currentTimeStep(0); currentTimeStep = atoi(currentTimeSeries->Attribute("n")); this->ReadPoints(newContourModel, currentTimeSeries, currentTimeStep); int isClosed; currentTimeSeries->QueryIntAttribute("isClosed", &isClosed); if( isClosed ) { newContourModel->Close(currentTimeStep); } } /*++++ END handle n timesteps within timestep tags ++++*/ } else { //this should not happen MITK_WARN << "wrong file format!"; //newContourModel = this->ReadPoint(newContourModel, currentContourElement, 0); } newContourModel->UpdateOutputInformation(); - this->SetNthOutput( contourCounter, newContourModel ); - contourCounter++; + result.push_back(dynamic_cast(newContourModel.GetPointer())); } /*++++ END handle n contourModels within data tags ++++*/ } else { MITK_WARN << "XML parser error!"; } }catch(...) - { - MITK_ERROR << "Cannot read contourModel."; - m_Success = false; - } - m_Success = true; + { + MITK_ERROR << "Cannot read contourModel."; + } + + return result; +} + +mitk::ContourModelReader* mitk::ContourModelReader::Clone() const +{ + return new ContourModelReader(*this); } void mitk::ContourModelReader::ReadPoints(mitk::ContourModel::Pointer newContourModel, TiXmlElement* currentTimeSeries, unsigned int currentTimeStep) { //check if the timesteps in contourModel have to be expanded if(currentTimeStep != newContourModel->GetTimeSteps()) { newContourModel->Expand(currentTimeStep+1); } //read all points within controlPoints tag if(currentTimeSeries->FirstChildElement("controlPoints")->FirstChildElement("point") != NULL) { for( TiXmlElement* currentPoint = currentTimeSeries->FirstChildElement("controlPoints")->FirstChildElement("point")->ToElement(); currentPoint != NULL; currentPoint = currentPoint->NextSiblingElement()) { double x(0.0); double y(0.0); double z(0.0); x = atof(currentPoint->FirstChildElement("x")->GetText()); y = atof(currentPoint->FirstChildElement("y")->GetText()); z = atof(currentPoint->FirstChildElement("z")->GetText()); int isActivePoint; currentPoint->QueryIntAttribute("isActive", &isActivePoint); mitk::Point3D point; mitk::FillVector3D(point, x, y, z); newContourModel->AddVertex(point, isActivePoint,currentTimeStep); } } else { //nothing to read } } - -void mitk::ContourModelReader::GenerateOutputInformation() -{ -} - -int mitk::ContourModelReader::CanReadFile ( const char *name ) -{ - std::ifstream in( name ); - bool isGood = in.good(); - in.close(); - return isGood; -} - -bool mitk::ContourModelReader::CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern) -{ - // First check the extension - if( filename == "" ) - { - //MITK_INFO<<"No filename specified."<GetNumberOfOutputs(); - this->SetNumberOfIndexedOutputs( num ); - for ( unsigned int i = prevNum; i < num; ++i ) - { - this->SetNthOutput( i, this->MakeOutput( i ).GetPointer() ); - } -} - - -bool mitk::ContourModelReader::GetSuccess() const -{ - return m_Success; -} diff --git a/Modules/ContourModel/IO/mitkContourModelReader.h b/Modules/ContourModel/IO/mitkContourModelReader.h index 290e40c445..defa7712dd 100644 --- a/Modules/ContourModel/IO/mitkContourModelReader.h +++ b/Modules/ContourModel/IO/mitkContourModelReader.h @@ -1,137 +1,65 @@ /*=================================================================== 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 _MITK_CONTOURMODEL_READER__H_ #define _MITK_CONTOURMODEL_READER__H_ -#include +// MITK +#include +#include +#include #include -#include -#include + + #include #include #include #include namespace mitk { /** * @brief * @ingroup PSIO * @ingroup IO */ -class MitkContourModel_EXPORT ContourModelReader : public ContourModelSource, public FileReader +class ContourModelReader : public mitk::AbstractFileReader { public: + ContourModelReader(const ContourModelReader& other); - mitkClassMacro( ContourModelReader, FileReader ); - - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) - - /** - * @brief Sets the filename of the file to be read - * @param _arg the filename of the point set xml-file - */ - itkSetStringMacro( FileName ); - - /** - * @brief Returns the filename of the point set xml-file. - * @returns the filename of the point set xml-file. - */ - itkGetStringMacro( FileName ); - - /** - * @warning multiple load not (yet) supported - */ - itkSetStringMacro( FilePrefix ); - - /** - * @warning multiple load not (yet) supported - */ - itkGetStringMacro( FilePrefix ); - - /** - * @warning multiple load not (yet) supported - */ - itkSetStringMacro( FilePattern ); - - /** - * @warning multiple load not (yet) supported - */ - itkGetStringMacro( FilePattern ); + ContourModelReader(); - static bool CanReadFile(const std::string filename, const std::string filePrefix, - const std::string filePattern); + virtual ~ContourModelReader(); - /** - * @returns whether the last read attempt was successful or not. - */ - bool GetSuccess() const; + using AbstractFileReader::Read; + virtual std::vector > Read(); protected: - /** - * Constructor - */ - ContourModelReader(); - - /** - * Virtual destructor - */ - virtual ~ContourModelReader(); - - /** - * Actually reads the point sets from the given file - */ - virtual void GenerateData(); - - virtual void ReadPoints(mitk::ContourModel::Pointer newContourModel, - TiXmlElement* currentTimeSeries, unsigned int currentTimeStep); - - /** - * Does nothing in the current implementation - */ - virtual void GenerateOutputInformation(); - - /** - * Resizes the output-objects according to the given number. - * @param num the new number of output objects. - */ - virtual void ResizeOutputs( const unsigned int& num ); - - /** - * Checks if the given file has appropriate - * read access. - * @returns true if the file exists and may be read - * or false otherwise. - */ - virtual int CanReadFile (const char *name); - - - std::string m_FileName; - - std::string m_FilePrefix; + virtual void ReadPoints(mitk::ContourModel::Pointer newContourModel, + TiXmlElement* currentTimeSeries, unsigned int currentTimeStep); - std::string m_FilePattern; +private: - bool m_Success; + ContourModelReader* Clone() const; + us::ServiceRegistration m_ServiceReg; }; } #endif diff --git a/Modules/ContourModel/IO/mitkContourModelSerializer.cpp b/Modules/ContourModel/IO/mitkContourModelSerializer.cpp index d15ef6e14f..605b56af50 100644 --- a/Modules/ContourModel/IO/mitkContourModelSerializer.cpp +++ b/Modules/ContourModel/IO/mitkContourModelSerializer.cpp @@ -1,70 +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(); + ContourModelWriter writer; + writer.SetOutputLocation( 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/mitkContourModelSetReader.cpp b/Modules/ContourModel/IO/mitkContourModelSetReader.cpp index 1d82e1d319..d0b6b551ce 100644 --- a/Modules/ContourModel/IO/mitkContourModelSetReader.cpp +++ b/Modules/ContourModel/IO/mitkContourModelSetReader.cpp @@ -1,171 +1,81 @@ /*=================================================================== 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 "mitkContourModelSetReader.h" #include "mitkContourModelReader.h" +#include #include #include #include -mitk::ContourModelSetReader::ContourModelSetReader() -{ - m_Success = false; -} - - -mitk::ContourModelSetReader::~ContourModelSetReader() -{} - -void mitk::ContourModelSetReader::GenerateData() +mitk::ContourModelSetReader::ContourModelSetReader(const mitk::ContourModelSetReader& other) + : mitk::AbstractFileReader(other) { - std::locale::global(std::locale("C")); - - m_Success = false; - if ( m_FileName == "" ) - { - itkWarningMacro( << "Sorry, filename has not been set!" ); - return ; - } - if ( ! this->CanReadFile( m_FileName.c_str() ) ) - { - itkWarningMacro( << "Sorry, can't read file " << m_FileName << "!" ); - return ; - } - - try{ - mitk::ContourModelSet::Pointer contourSet = mitk::ContourModelSet::New(); - this->SetNthOutput(0,contourSet); - - mitk::ContourModelReader::Pointer reader = mitk::ContourModelReader::New(); - reader->SetFileName( this->GetFileName() ); - reader->Update(); - - for(unsigned int i = 0; i < reader->GetNumberOfOutputs(); ++i) - { - contourSet->AddContourModel( reader->GetOutput(i) ); - } - - }catch(...) - { - MITK_ERROR << "Cannot read contourModel."; - } - m_Success = true; } -void mitk::ContourModelSetReader::ReadPoints(mitk::ContourModel::Pointer newContourModel, - TiXmlElement* currentTimeSeries, unsigned int currentTimeStep) +mitk::ContourModelSetReader::ContourModelSetReader() + : AbstractFileReader() { - //check if the timesteps in contourModel have to be expanded - if(currentTimeStep != newContourModel->GetTimeSteps()) - { - newContourModel->Expand(currentTimeStep+1); - } - - //read all points within controlPoints tag - if(currentTimeSeries->FirstChildElement("controlPoints")->FirstChildElement("point") != NULL) - { - for( TiXmlElement* currentPoint = currentTimeSeries->FirstChildElement("controlPoints")->FirstChildElement("point")->ToElement(); - currentPoint != NULL; currentPoint = currentPoint->NextSiblingElement()) - { + std::string category = "ContourModelSet File"; + CustomMimeType customMimeType; + customMimeType.SetCategory(category); + customMimeType.AddExtension("cnt_set"); - double x(0.0); - double y(0.0); - double z(0.0); - - x = atof(currentPoint->FirstChildElement("x")->GetText()); - y = atof(currentPoint->FirstChildElement("y")->GetText()); - z = atof(currentPoint->FirstChildElement("z")->GetText()); - - int isActivePoint; - currentPoint->QueryIntAttribute("isActive", &isActivePoint); - - mitk::Point3D point; - mitk::FillVector3D(point, x, y, z); - newContourModel->AddVertex(point, isActivePoint,currentTimeStep); - } - } - else - { - //nothing to read - } + this->SetDescription(category); + this->SetMimeType(customMimeType); + m_ServiceReg = this->RegisterService(); } -void mitk::ContourModelSetReader::GenerateOutputInformation() +mitk::ContourModelSetReader::~ContourModelSetReader() { } -int mitk::ContourModelSetReader::CanReadFile ( const char *name ) +std::vector > mitk::ContourModelSetReader::Read() { - std::ifstream in( name ); - bool isGood = in.good(); - in.close(); - return isGood; -} + std::vector > result; + std::vector > internalResult; -bool mitk::ContourModelSetReader::CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern) -{ - // First check the extension - if( filename == "" ) - { - //MITK_INFO<<"No filename specified."<AddContourModel( dynamic_cast(internalResult.at(i).GetPointer()) ); } + result.push_back(dynamic_cast(contourSet.GetPointer())); - return true; -} + }catch(...) + { + MITK_ERROR << "Cannot read contourModel."; + } -void mitk::ContourModelSetReader::ResizeOutputs( const unsigned int& num ) -{ - unsigned int prevNum = this->GetNumberOfOutputs(); - this->SetNumberOfIndexedOutputs( num ); - for ( unsigned int i = prevNum; i < num; ++i ) - { - this->SetNthOutput( i, this->MakeOutput( i ).GetPointer() ); - } + return result; } - -bool mitk::ContourModelSetReader::GetSuccess() const +mitk::ContourModelSetReader* mitk::ContourModelSetReader::Clone() const { - return m_Success; + return new ContourModelSetReader(*this); } diff --git a/Modules/ContourModel/IO/mitkContourModelSetReader.h b/Modules/ContourModel/IO/mitkContourModelSetReader.h index 950f1d2c27..bfa5c332cb 100644 --- a/Modules/ContourModel/IO/mitkContourModelSetReader.h +++ b/Modules/ContourModel/IO/mitkContourModelSetReader.h @@ -1,138 +1,62 @@ /*=================================================================== 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 _MITK_ContourModelSetReader__H_ #define _MITK_ContourModelSetReader__H_ -#include +// MITK +#include +#include +#include #include #include -#include -#include + #include #include #include #include namespace mitk { /** * @brief * @ingroup PSIO * @ingroup IO */ -class MitkContourModel_EXPORT ContourModelSetReader : public ContourModelSetSource, public FileReader +class ContourModelSetReader : public mitk::AbstractFileReader { public: + ContourModelSetReader(const ContourModelSetReader& other); - mitkClassMacro( ContourModelSetReader, FileReader ); - - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) - - /** - * @brief Sets the filename of the file to be read - * @param _arg the filename of the point set xml-file - */ - itkSetStringMacro( FileName ); - - /** - * @brief Returns the filename of the point set xml-file. - * @returns the filename of the point set xml-file. - */ - itkGetStringMacro( FileName ); - - /** - * @warning multiple load not (yet) supported - */ - itkSetStringMacro( FilePrefix ); + ContourModelSetReader(); - /** - * @warning multiple load not (yet) supported - */ - itkGetStringMacro( FilePrefix ); + virtual ~ContourModelSetReader(); - /** - * @warning multiple load not (yet) supported - */ - itkSetStringMacro( FilePattern ); - - /** - * @warning multiple load not (yet) supported - */ - itkGetStringMacro( FilePattern ); - - static bool CanReadFile(const std::string filename, const std::string filePrefix, - const std::string filePattern); - - /** - * @returns whether the last read attempt was successful or not. - */ - bool GetSuccess() const; + using AbstractFileReader::Read; + virtual std::vector > Read(); protected: - /** - * Constructor - */ - ContourModelSetReader(); - - /** - * Virtual destructor - */ - virtual ~ContourModelSetReader(); - - /** - * Actually reads the point sets from the given file - */ - virtual void GenerateData(); - - virtual void ReadPoints(mitk::ContourModel::Pointer newContourModel, - TiXmlElement* currentTimeSeries, unsigned int currentTimeStep); - - /** - * Does nothing in the current implementation - */ - virtual void GenerateOutputInformation(); - - /** - * Resizes the output-objects according to the given number. - * @param num the new number of output objects. - */ - virtual void ResizeOutputs( const unsigned int& num ); - - /** - * Checks if the given file has appropriate - * read access. - * @returns true if the file exists and may be read - * or false otherwise. - */ - virtual int CanReadFile (const char *name); - - - std::string m_FileName; - - std::string m_FilePrefix; - - std::string m_FilePattern; +private: - bool m_Success; + ContourModelSetReader* Clone() const; + us::ServiceRegistration m_ServiceReg; }; } #endif diff --git a/Modules/ContourModel/IO/mitkContourModelSetSerializer.cpp b/Modules/ContourModel/IO/mitkContourModelSetSerializer.cpp index e66d98ec6a..a96866d921 100644 --- a/Modules/ContourModel/IO/mitkContourModelSetSerializer.cpp +++ b/Modules/ContourModel/IO/mitkContourModelSetSerializer.cpp @@ -1,70 +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(); + ContourModelSetWriter writer; + writer.SetOutputLocation( 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/mitkContourModelSetWriter.cpp b/Modules/ContourModel/IO/mitkContourModelSetWriter.cpp index e9f1939dc9..0179b87246 100644 --- a/Modules/ContourModel/IO/mitkContourModelSetWriter.cpp +++ b/Modules/ContourModel/IO/mitkContourModelSetWriter.cpp @@ -1,175 +1,86 @@ /*=================================================================== 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 "mitkContourModelSetWriter.h" #include "mitkContourModelWriter.h" - - +#include mitk::ContourModelSetWriter::ContourModelSetWriter() - : m_FileName(""), m_FilePrefix(""), m_FilePattern("") + : AbstractFileWriter(ContourModelSet::GetStaticNameOfClass()) { - this->SetNumberOfRequiredInputs( 1 ); - this->SetNumberOfIndexedOutputs( 1 ); - this->SetNthOutput( 0, mitk::ContourModel::New().GetPointer() ); - m_Success = false; -} - - - - -mitk::ContourModelSetWriter::~ContourModelSetWriter() -{} - + std::string category = "ContourModelSet File"; + mitk::CustomMimeType customMimeType; + customMimeType.SetCategory(category); + customMimeType.AddExtension("cnt_set"); + this->SetDescription(category); + this->SetMimeType(customMimeType); - -void mitk::ContourModelSetWriter::GenerateData() -{ - //Use regular ContourModel writer to write each contour of the set to a single file. - //Just use a different file extension .cnt_set - - mitk::ContourModelWriter::Pointer writer = mitk::ContourModelWriter::New(); - writer->SetFileName(this->GetFileName()); - - if ( m_FileName == "" ) - { - itkWarningMacro( << "Sorry, filename has not been set! Setting filename to default." ); - m_FileName = GetDefaultFilename(); - } - - InputType::Pointer contourModelSet = this->GetInput(); - - // - // for each contour object set input of writer - // - for ( int i = 0 ; i < contourModelSet->GetSize(); ++i ) - { - mitk::ContourModel* contour = contourModelSet->GetContourModelAt(i); - writer->SetInput( i, contour ); - } - - writer->Update(); - - m_Success = true; - m_MimeType = "application/MITK.ContourModel"; + RegisterService(); } - -void mitk::ContourModelSetWriter::ResizeInputs( const unsigned int& num ) -{ - unsigned int prevNum = this->GetNumberOfInputs(); - this->SetNumberOfIndexedInputs( num ); - for ( unsigned int i = prevNum; i < num; ++i ) - { - this->SetNthInput( i, mitk::ContourModel::New().GetPointer() ); - } -} - - - - -void mitk::ContourModelSetWriter::SetInput( InputType* contourModel ) +mitk::ContourModelSetWriter::ContourModelSetWriter(const mitk::ContourModelSetWriter& other) + : AbstractFileWriter(other) { - this->ProcessObject::SetNthInput( 0, contourModel ); } +mitk::ContourModelSetWriter::~ContourModelSetWriter() +{} - - -void mitk::ContourModelSetWriter::SetInput( const unsigned int& id, InputType* contourModel ) +void mitk::ContourModelSetWriter::Write() { - if ( id >= this->GetNumberOfInputs() ) - this->ResizeInputs( id + 1 ); - this->ProcessObject::SetNthInput( id, contourModel ); -} + std::ostream* out; + std::ofstream outStream; - - -mitk::ContourModelSet* mitk::ContourModelSetWriter::GetInput() -{ - if ( this->GetNumberOfInputs() < 1 ) + if( this->GetOutputStream() ) { - return 0; + out = this->GetOutputStream(); } else { - return dynamic_cast ( this->GetInput( 0 ) ); + outStream.open( this->GetOutputLocation().c_str() ); + out = &outStream; } -} - - - - -mitk::ContourModelSet* mitk::ContourModelSetWriter::GetInput( const unsigned int& num ) -{ - return dynamic_cast ( this->ProcessObject::GetInput( num ) ); -} - + if ( !out->good() ) + { + mitkThrow() << "Stream not good."; + } + //Use regular ContourModel writer to write each contour of the set to a single file. + //Just use a different file extension .cnt_set -bool mitk::ContourModelSetWriter::GetSuccess() const -{ - return m_Success; -} + mitk::ContourModelWriter writer; -std::string mitk::ContourModelSetWriter::GetSupportedBaseData() const -{ - return ContourModelSet::GetStaticNameOfClass(); -} + mitk::ContourModelSet::ConstPointer contourModelSet = dynamic_cast(this->GetInput()); -bool mitk::ContourModelSetWriter::CanWriteDataType( DataNode* input ) -{ - if ( input ) + // + // for each contour object set input of writer + // + for ( int i = 0 ; i < contourModelSet->GetSize(); ++i ) { - mitk::BaseData* data = input->GetData(); - if ( data ) - { - mitk::ContourModel::Pointer contourModel = dynamic_cast( data ); - if( contourModel.IsNotNull() ) - { - //this writer has no "SetDefaultExtension()" - function - m_Extension = ".cnt_set"; - return true; - } - } + const mitk::ContourModel* contour = contourModelSet->GetContourModelAt(i); + writer.SetInput( contour ); + writer.SetOutputStream( this->GetOutputLocation(), out ); + writer.Write(); } - return false; -} - -void mitk::ContourModelSetWriter::SetInput( DataNode* input ) -{ - if( input && CanWriteDataType( input ) ) - this->ProcessObject::SetNthInput( 0, dynamic_cast( input->GetData() ) ); -} -std::vector mitk::ContourModelSetWriter::GetPossibleFileExtensions() -{ - std::vector possibleFileExtensions; - possibleFileExtensions.push_back(".cnt_set"); - return possibleFileExtensions; -} - -std::string mitk::ContourModelSetWriter::GetFileExtension() -{ - return m_Extension; } -std::string mitk::ContourModelSetWriter::GetWritenMIMEType() +mitk::ContourModelSetWriter* mitk::ContourModelSetWriter::Clone() const { - return "application/MITK.ContourModelSet"; + return new ContourModelSetWriter(*this); } diff --git a/Modules/ContourModel/IO/mitkContourModelSetWriter.h b/Modules/ContourModel/IO/mitkContourModelSetWriter.h index 67c76fb9b4..f460e17b47 100644 --- a/Modules/ContourModel/IO/mitkContourModelSetWriter.h +++ b/Modules/ContourModel/IO/mitkContourModelSetWriter.h @@ -1,201 +1,53 @@ /*=================================================================== 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 _MITK_CONTOURMODELSET_WRITER__H_ #define _MITK_CONTOURMODELSET_WRITER__H_ -#include -#include -#include +#include #include #include namespace mitk { /** * @brief XML-based writer for mitk::ContourModelSet * * Uses the regular ContourModel writer to write each contour of the ContourModelSet to a single file. * * @ingroup PSIO * @ingroup Process */ - class MitkContourModel_EXPORT ContourModelSetWriter : public mitk::FileWriterWithInformation + class ContourModelSetWriter : public mitk::AbstractFileWriter { public: - - mitkClassMacro( ContourModelSetWriter, mitk::FileWriter ); - - mitkWriterMacro; - - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) - - typedef mitk::ContourModelSet InputType; - - typedef InputType::Pointer InputTypePointer; - - /** - * Sets the filename of the file to write. - * @param FileName the name of the file to write. - */ - itkSetStringMacro( FileName ); - - /** - * @returns the name of the file to be written to disk. - */ - itkGetStringMacro( FileName ); - - /** - * @warning multiple write not (yet) supported - */ - itkSetStringMacro( FilePrefix ); - - /** - * @warning multiple write not (yet) supported - */ - itkGetStringMacro( FilePrefix ); - - /** - * @warning multiple write not (yet) supported - */ - itkSetStringMacro( FilePattern ); - - /** - * @warning multiple write not (yet) supported - */ - itkGetStringMacro( FilePattern ); - - /** - * Sets the 0'th input object for the filter. - * @param input the first input for the filter. - */ - void SetInput( InputType* input ); - - /** - * Sets the n'th input object for the filter. If num is - * larger than GetNumberOfInputs() the number of inputs is - * resized appropriately. - * @param input the n'th input for the filter. - */ - void SetInput( const unsigned int& num, InputType* input); - - /** - * @returns the 0'th input object of the filter. - */ - ContourModelSet* GetInput(); - - /** - * @param num the index of the desired output object. - * @returns the n'th input object of the filter. - */ - ContourModelSet* GetInput( const unsigned int& num ); - - - /** - * @brief Return the possible file extensions for the data type associated with the writer - */ - virtual std::vector GetPossibleFileExtensions(); - - /** - * @brief Return the extension to be added to the filename. - */ - virtual std::string GetFileExtension(); - - /** - * @brief Check if the Writer can write the Content of the - */ - virtual bool CanWriteDataType( DataNode* ); - - /** - * @brief Return the MimeType of the saved File. - */ - virtual std::string GetWritenMIMEType(); - - using Superclass::SetInput; - - /** - * @brief Set the DataTreenode as Input. Important: The Writer always have a SetInput-Function. - */ - virtual void SetInput( DataNode* ); - - /** - * @returns whether the last write attempt was successful or not. - */ - bool GetSuccess() const; - - std::string GetSupportedBaseData() const; - - /*++++++ FileWriterWithInformation methods +++++++*/ - virtual const char *GetDefaultFilename() { return "ContourModelSet.cnt_set"; } - virtual const char *GetFileDialogPattern() { return "MITK ContourModelSet (*.cnt_set)"; } - virtual const char *GetDefaultExtension() { return ".cnt_set"; } - virtual bool CanWriteBaseDataType(BaseData::Pointer data) { return (dynamic_cast(data.GetPointer()) != NULL); }; - virtual void DoWrite(BaseData::Pointer data) - { - if (this->CanWriteBaseDataType(data)) - { - this->SetInput(dynamic_cast(data.GetPointer())); - this->Update(); - } - } - - protected: - - /** - * Constructor. - */ ContourModelSetWriter(); - - /** - * Virtual destructor. - */ virtual ~ContourModelSetWriter(); + using AbstractFileWriter::Write; + virtual void Write(); - /** - * Writes the XML file - */ - virtual void GenerateData(); - - - /** - * Resizes the number of inputs of the writer. - * The inputs are initialized by empty ContourModels - * @param num the new number of inputs - */ - virtual void ResizeInputs( const unsigned int& num ); - - - std::string m_FileName; - - std::string m_FilePrefix; - - std::string m_FilePattern; - - std::string m_Extension; - - std::string m_MimeType; - - bool m_Success; + protected: + ContourModelSetWriter(const ContourModelSetWriter& other); + virtual mitk::ContourModelSetWriter* Clone() const; }; } #endif diff --git a/Modules/ContourModel/IO/mitkContourModelWriter.cpp b/Modules/ContourModel/IO/mitkContourModelWriter.cpp index 8782ab9bc9..bc9b6adb6d 100644 --- a/Modules/ContourModel/IO/mitkContourModelWriter.cpp +++ b/Modules/ContourModel/IO/mitkContourModelWriter.cpp @@ -1,486 +1,347 @@ /*=================================================================== 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 "mitkContourModelWriter.h" +#include "mitkIOMimeTypes.h" #include "mitkTimeGeometry.h" #include #include #include /* * The xml file will look like: * * * * * * * * * * * * * * * * * * * */ // // Initialization of the xml tags. // const char* mitk::ContourModelWriter::XML_CONTOURMODEL = "contourModel" ; const char* mitk::ContourModelWriter::XML_HEAD = "head" ; const char* mitk::ContourModelWriter::XML_GEOMETRY_INFO = "geometryInfo" ; const char* mitk::ContourModelWriter::XML_DATA = "data"; const char* mitk::ContourModelWriter::XML_TIME_STEP = "timestep"; const char* mitk::ContourModelWriter::XML_CONTROL_POINTS = "controlPoints" ; const char* mitk::ContourModelWriter::XML_POINT = "point" ; const char* mitk::ContourModelWriter::XML_X = "x" ; const char* mitk::ContourModelWriter::XML_Y = "y" ; const char* mitk::ContourModelWriter::XML_Z = "z" ; - mitk::ContourModelWriter::ContourModelWriter() - : m_FileName(""), m_FilePrefix(""), m_FilePattern("") + : AbstractFileWriter(ContourModel::GetStaticNameOfClass()) + , m_IndentDepth(0) + , m_Indent(2) { - this->SetNumberOfRequiredInputs( 1 ); - this->SetNumberOfIndexedOutputs( 1 ); - this->SetNthOutput( 0, mitk::ContourModel::New().GetPointer() ); - m_Indent = 2; - m_IndentDepth = 0; - m_Success = false; -} + std::string category = "Contour File"; + mitk::CustomMimeType customMimeType; + customMimeType.SetCategory(category); + customMimeType.AddExtension("cnt"); + this->SetDescription(category); + this->SetMimeType(customMimeType); + RegisterService(); +} +mitk::ContourModelWriter::ContourModelWriter(const mitk::ContourModelWriter& other) + : AbstractFileWriter(other) + , m_IndentDepth(other.m_IndentDepth) + , m_Indent(other.m_Indent) +{ +} mitk::ContourModelWriter::~ContourModelWriter() {} - - - -void mitk::ContourModelWriter::GenerateData() +void mitk::ContourModelWriter::Write() { - m_Success = false; - m_IndentDepth = 0; + std::ostream* out; + std::ofstream outStream; - // - // Opening the file to write to - // - if ( m_FileName == "" ) - { - itkWarningMacro( << "Sorry, filename has not been set!" ); - return ; - } - std::ofstream out( m_FileName.c_str() ); - if ( !out.good() ) - { - itkExceptionMacro(<< "File " << m_FileName << " could not be opened!"); - itkWarningMacro( << "Sorry, file " << m_FileName << " could not be opened!" ); - out.close(); - return ; - } + if( this->GetOutputStream() ) + { + out = this->GetOutputStream(); + } + else + { + outStream.open( this->GetOutputLocation().c_str() ); + out = &outStream; + } - std::locale previousLocale(out.getloc()); - std::locale I("C"); - out.imbue(I); + if ( !out->good() ) + { + mitkThrow() << "Stream not good."; + } + std::locale previousLocale(out->getloc()); + std::locale I("C"); + out->imbue(I); -/*+++++++++++ Here the actual xml writing begins +++++++++*/ + /*+++++++++++ Here the actual xml writing begins +++++++++*/ /*++++ ++++*/ - WriteXMLHeader( out ); + WriteXMLHeader( *out ); // // for each input object write its xml representation to // the stream // - for ( unsigned int i = 0 ; i < this->GetNumberOfInputs(); ++i ) - { - InputType::Pointer contourModel = this->GetInput( i ); - assert( contourModel.IsNotNull() ); - WriteXML( contourModel.GetPointer(), out ); - } + mitk::ContourModel::ConstPointer contourModel = dynamic_cast(this->GetInput()); + assert( contourModel.IsNotNull() ); + WriteXML( contourModel.GetPointer(), *out ); + out->imbue(previousLocale); - out.imbue(previousLocale); - - if ( !out.good() ) // some error during output + if ( !out->good() ) // some error during output { - out.close(); throw std::ios_base::failure("Some error during contour writing."); } - out.close(); - m_Success = true; - m_MimeType = "application/MITK.ContourModel"; } +mitk::ContourModelWriter*mitk::ContourModelWriter::Clone() const +{ + return new ContourModelWriter(*this); +} - -void mitk::ContourModelWriter::WriteXML( mitk::ContourModel* contourModel, std::ofstream& out ) +void mitk::ContourModelWriter::WriteXML( const mitk::ContourModel* contourModel, std::ostream& out ) { /*++++ ++++*/ WriteStartElement( XML_CONTOURMODEL, out ); /*++++ ++++*/ WriteStartElement( XML_HEAD, out); /*++++ ++++*/ WriteStartElement( XML_GEOMETRY_INFO, out); - WriteGeometryInformation( contourModel->GetTimeGeometry(), out);; + WriteGeometryInformation( contourModel->GetTimeGeometry(), out); /*++++ ++++*/ WriteEndElement( XML_GEOMETRY_INFO, out); /*++++ ++++*/ WriteEndElement( XML_HEAD, out); /*++++ ++++*/ WriteStartElement( XML_DATA, out); unsigned int timecount = contourModel->GetTimeSteps(); for(unsigned int i=0; i< timecount; i++) { /*++++ ++++*/ std::vector at; at.push_back("n"); std::vector val; val.push_back(ConvertToString(i)); at.push_back("isClosed"); val.push_back(ConvertToString(contourModel->IsClosed())); WriteStartElementWithAttribut( XML_TIME_STEP, at, val, out ); /*++++ ++++*/ WriteStartElement(XML_CONTROL_POINTS, out); mitk::ContourModel::VertexIterator it = contourModel->IteratorBegin(); mitk::ContourModel::VertexIterator end = contourModel->IteratorEnd(); while(it != end) { mitk::ContourModel::VertexType* v = *it; /*++++ ++++*/ std::vector attr; attr.push_back("IsControlPoint"); std::vector value; value.push_back(ConvertToString(v->IsControlPoint)); WriteStartElementWithAttribut( XML_POINT, attr, value, out ); /*++++ ++++*/ WriteStartElement( XML_X, out ); WriteCharacterData( ConvertToString(v->Coordinates[0] ).c_str(), out ); /*++++ ++++*/ WriteEndElement( XML_X, out, false ); /*++++ ++++*/ WriteStartElement( XML_Y, out ); WriteCharacterData( ConvertToString( v->Coordinates[1] ).c_str(), out ); /*++++ ++++*/ WriteEndElement( XML_Y, out, false ); /*++++ ++++*/ WriteStartElement( XML_Z, out ); WriteCharacterData( ConvertToString( v->Coordinates[2] ).c_str(), out ); /*++++ ++++*/ WriteEndElement( XML_Z, out, false ); /*++++ ++++*/ WriteEndElement( XML_POINT, out ); it++; } /*++++ ++++*/ WriteEndElement(XML_CONTROL_POINTS, out); /*++++ ++++*/ WriteEndElement( XML_TIME_STEP, out ); } /*++++ ++++*/ WriteEndElement( XML_DATA, out ); /*++++ ++++*/ WriteEndElement( XML_CONTOURMODEL, out ); } - - -void mitk::ContourModelWriter::WriteGeometryInformation( mitk::TimeGeometry* /*geometry*/, std::ofstream& out ) +void mitk::ContourModelWriter::WriteGeometryInformation(const mitk::TimeGeometry* /*geometry*/, std::ostream& out ) { WriteCharacterData("", out); } - - -void mitk::ContourModelWriter::ResizeInputs( const unsigned int& num ) -{ - unsigned int prevNum = this->GetNumberOfInputs(); - this->SetNumberOfIndexedInputs( num ); - for ( unsigned int i = prevNum; i < num; ++i ) - { - this->SetNthInput( i, mitk::ContourModel::New().GetPointer() ); - } -} - - - - -void mitk::ContourModelWriter::SetInput( InputType* contourModel ) -{ - this->ProcessObject::SetNthInput( 0, contourModel ); -} - - - - -void mitk::ContourModelWriter::SetInput( const unsigned int& id, InputType* contourModel ) -{ - if ( id >= this->GetNumberOfInputs() ) - this->ResizeInputs( id + 1 ); - this->ProcessObject::SetNthInput( id, contourModel ); -} - - - -mitk::ContourModel* mitk::ContourModelWriter::GetInput() -{ - if ( this->GetNumberOfInputs() < 1 ) - { - return 0; - } - else - { - return dynamic_cast ( this->GetInput( 0 ) ); - } -} - - - - -mitk::ContourModel* mitk::ContourModelWriter::GetInput( const unsigned int& num ) -{ - return dynamic_cast ( this->ProcessObject::GetInput( num ) ); -} - - - - - template < typename T> std::string mitk::ContourModelWriter::ConvertToString( T value ) { std::ostringstream o; std::locale I("C"); o.imbue(I); if ( o << value ) { return o.str(); } else return "conversion error"; } - - -void mitk::ContourModelWriter::WriteXMLHeader( std::ofstream &file ) +void mitk::ContourModelWriter::WriteXMLHeader( std::ostream &file ) { file << ""; } - - - -void mitk::ContourModelWriter::WriteStartElement( const char *const tag, std::ofstream &file ) +void mitk::ContourModelWriter::WriteStartElement( const char *const tag, std::ostream &file ) { file << std::endl; WriteIndent( file ); file << '<' << tag << '>'; m_IndentDepth++; } - - -void mitk::ContourModelWriter::WriteStartElementWithAttribut( const char *const tag, std::vector attributes, std::vector values, std::ofstream &file ) +void mitk::ContourModelWriter::WriteStartElementWithAttribut( const char *const tag, std::vector attributes, std::vector values, std::ostream &file ) { file << std::endl; WriteIndent( file ); file << '<' << tag; unsigned int attributesSize = attributes.size(); unsigned int valuesSize = values.size(); if( attributesSize == valuesSize){ std::vector::iterator attributesIt = attributes.begin(); std::vector::iterator end = attributes.end(); std::vector::iterator valuesIt = values.begin(); while(attributesIt != end) { file << ' '; WriteCharacterData( *attributesIt, file); file << '=' << '"'; WriteCharacterData( *valuesIt, file); file << '"'; attributesIt++; valuesIt++; } } file << '>'; m_IndentDepth++; } - - - -void mitk::ContourModelWriter::WriteEndElement( const char *const tag, std::ofstream &file, const bool& indent ) +void mitk::ContourModelWriter::WriteEndElement( const char *const tag, std::ostream &file, const bool& indent ) { m_IndentDepth--; if ( indent ) { file << std::endl; WriteIndent( file ); } file << '<' << '/' << tag << '>'; } - - - -void mitk::ContourModelWriter::WriteCharacterData( const char *const data, std::ofstream &file ) +void mitk::ContourModelWriter::WriteCharacterData( const char *const data, std::ostream &file ) { file << data; } - - - -void mitk::ContourModelWriter::WriteStartElement( std::string &tag, std::ofstream &file ) +void mitk::ContourModelWriter::WriteStartElement( std::string &tag, std::ostream &file ) { WriteStartElement( tag.c_str(), file ); } - - - -void mitk::ContourModelWriter::WriteEndElement( std::string &tag, std::ofstream &file, const bool& indent ) +void mitk::ContourModelWriter::WriteEndElement( std::string &tag, std::ostream &file, const bool& indent ) { WriteEndElement( tag.c_str(), file, indent ); } - - - -void mitk::ContourModelWriter::WriteCharacterData( std::string &data, std::ofstream &file ) +void mitk::ContourModelWriter::WriteCharacterData( std::string &data, std::ostream &file ) { WriteCharacterData( data.c_str(), file ); } - - - -void mitk::ContourModelWriter::WriteIndent( std::ofstream& file ) +void mitk::ContourModelWriter::WriteIndent( std::ostream& file ) { std::string spaces( m_IndentDepth * m_Indent, ' ' ); file << spaces.c_str(); } - - - -bool mitk::ContourModelWriter::GetSuccess() const -{ - return m_Success; -} - -std::string mitk::ContourModelWriter::GetSupportedBaseData() const -{ - return ContourModel::GetStaticNameOfClass(); -} - -bool mitk::ContourModelWriter::CanWriteDataType( DataNode* input ) -{ - if ( input ) - { - mitk::BaseData* data = input->GetData(); - if ( data ) - { - mitk::ContourModel::Pointer contourModel = dynamic_cast( data ); - if( contourModel.IsNotNull() ) - { - //this writer has no "SetDefaultExtension()" - function - m_Extension = ".cnt"; - return true; - } - } - } - return false; -} - -void mitk::ContourModelWriter::SetInput( DataNode* input ) -{ - if( input && CanWriteDataType( input ) ) - this->ProcessObject::SetNthInput( 0, dynamic_cast( input->GetData() ) ); -} - -std::string mitk::ContourModelWriter::GetWritenMIMEType() -{ - return m_MimeType; -} - -std::vector mitk::ContourModelWriter::GetPossibleFileExtensions() -{ - std::vector possibleFileExtensions; - possibleFileExtensions.push_back(".cnt"); - return possibleFileExtensions; -} - -std::string mitk::ContourModelWriter::GetFileExtension() -{ - return m_Extension; -} diff --git a/Modules/ContourModel/IO/mitkContourModelWriter.h b/Modules/ContourModel/IO/mitkContourModelWriter.h index 7b7d1ac7d5..2bb98475d7 100644 --- a/Modules/ContourModel/IO/mitkContourModelWriter.h +++ b/Modules/ContourModel/IO/mitkContourModelWriter.h @@ -1,327 +1,180 @@ /*=================================================================== 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 _MITK_CONTOURMODEL_WRITER__H_ #define _MITK_CONTOURMODEL_WRITER__H_ -#include -#include -#include +#include #include //DEPRECATED #include namespace mitk { /** * @brief XML-based writer for mitk::ContourModels * * XML-based writer for mitk::ContourModels. Multiple ContourModels can be written in * a single XML file by simply setting multiple inputs to the filter. * * The xml file will look like: * * * * * * * * * * * * * * * * * * * * * @ingroup PSIO * @ingroup Process */ class TimeSlicedGeometry; -class MitkContourModel_EXPORT ContourModelWriter : public mitk::FileWriterWithInformation +class ContourModelWriter : public mitk::AbstractFileWriter { public: - mitkClassMacro( ContourModelWriter, mitk::FileWriter ); + ContourModelWriter(); + virtual ~ContourModelWriter(); - mitkWriterMacro; - - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) - - typedef mitk::ContourModel InputType; - - typedef InputType::Pointer InputTypePointer; - - /** - * Sets the filename of the file to write. - * @param FileName the name of the file to write. - */ - itkSetStringMacro( FileName ); - - /** - * @returns the name of the file to be written to disk. - */ - itkGetStringMacro( FileName ); - - /** - * @warning multiple write not (yet) supported - */ - itkSetStringMacro( FilePrefix ); - - /** - * @warning multiple write not (yet) supported - */ - itkGetStringMacro( FilePrefix ); - - /** - * @warning multiple write not (yet) supported - */ - itkSetStringMacro( FilePattern ); - - /** - * @warning multiple write not (yet) supported - */ - itkGetStringMacro( FilePattern ); - - /** - * Sets the 0'th input object for the filter. - * @param input the first input for the filter. - */ - void SetInput( InputType* input ); - - /** - * Sets the n'th input object for the filter. If num is - * larger than GetNumberOfInputs() the number of inputs is - * resized appropriately. - * @param input the n'th input for the filter. - */ - void SetInput( const unsigned int& num, InputType* input); - - /** - * @returns the 0'th input object of the filter. - */ - ContourModel* GetInput(); - - /** - * @param num the index of the desired output object. - * @returns the n'th input object of the filter. - */ - ContourModel* GetInput( const unsigned int& num ); - - - /** - * @brief Return the possible file extensions for the data type associated with the writer - */ - virtual std::vector GetPossibleFileExtensions(); - - /** - * @brief Return the extension to be added to the filename. - */ - virtual std::string GetFileExtension(); - - /** - * @brief Check if the Writer can write the Content of the - */ - virtual bool CanWriteDataType( DataNode* ); - - /** - * @brief Return the MimeType of the saved File. - */ - virtual std::string GetWritenMIMEType(); - - using Superclass::SetInput; - - /** - * @brief Set the DataTreenode as Input. Important: The Writer always have a SetInput-Function. - */ - virtual void SetInput( DataNode* ); - - /** - * @returns whether the last write attempt was successful or not. - */ - bool GetSuccess() const; - - std::string GetSupportedBaseData() const; - - /*++++++ FileWriterWithInformation methods +++++++*/ - virtual const char *GetDefaultFilename() { return "ContourModel.cnt"; } - virtual const char *GetFileDialogPattern() { return "MITK ContourModel (*.cnt)"; } - virtual const char *GetDefaultExtension() { return ".cnt"; } - virtual bool CanWriteBaseDataType(BaseData::Pointer data) { return (dynamic_cast(data.GetPointer()) != NULL); }; - virtual void DoWrite(BaseData::Pointer data) - { - if (this->CanWriteBaseDataType(data)) - { - this->SetInput(dynamic_cast(data.GetPointer())); - this->Update(); - } - } + using AbstractFileWriter::Write; + virtual void Write(); protected: - /** - * Constructor. - */ - ContourModelWriter(); - - /** - * Virtual destructor. - */ - virtual ~ContourModelWriter(); - - - /** - * Writes the XML file - */ - virtual void GenerateData(); - - - /** - * Resizes the number of inputs of the writer. - * The inputs are initialized by empty ContourModels - * @param num the new number of inputs - */ - virtual void ResizeInputs( const unsigned int& num ); + ContourModelWriter(const ContourModelWriter& other); + virtual mitk::ContourModelWriter* Clone() const; /** * Converts an arbitrary type to a string. The type has to * support the << operator. This works fine at least for integral * data types as float, int, long etc. * @param value the value to convert * @returns the string representation of value */ template < typename T> std::string ConvertToString( T value ); /** * Writes an XML representation of the given point set to * an outstream. The XML-Header an root node is not included! * @param contourModel the point set to be converted to xml * @param out the stream to write to. */ - void WriteXML( mitk::ContourModel* contourModel, std::ofstream& out ); + void WriteXML( const mitk::ContourModel* contourModel, std::ostream& out ); /** * Writes the geometry information of the TimeGeometry to an outstream. * The root tag is not included. * @param geometry the TimeGeometry of the contour. * @param the stream to write to. */ - void WriteGeometryInformation( mitk::TimeGeometry* geometry, std::ofstream& out ); + void WriteGeometryInformation( const mitk::TimeGeometry* geometry, std::ostream& out ); /** * Writes the geometry information of the TimeGeometry to an outstream. * The root tag is not included. * @param geometry the TimeGeometry of the contour. * @param the stream to write to. * * \deprecatedSince{2013_09} Please use TimeGeometry instead of TimeSlicedGeometry. For more information see http://www.mitk.org/Development/Refactoring%20of%20the%20Geometry%20Classes%20-%20Part%201 */ - DEPRECATED(void WriteGeometryInformation( mitk::TimeSlicedGeometry* geometry, std::ofstream& out )); + DEPRECATED(void WriteGeometryInformation(const mitk::TimeSlicedGeometry* geometry, std::ostream& out )); /** * Writes an standard xml header to the given stream. * @param file the stream in which the header is written. */ - void WriteXMLHeader( std::ofstream &file ); + void WriteXMLHeader( std::ostream &file ); /** Write a start element tag */ - void WriteStartElement( const char *const tag, std::ofstream &file ); + void WriteStartElement( const char *const tag, std::ostream &file ); - void WriteStartElementWithAttribut( const char *const tag, std::vector attributes, std::vector values, std::ofstream &file ); + void WriteStartElementWithAttribut( const char *const tag, std::vector attributes, std::vector values, std::ostream &file ); /** * Write an end element tag * End-Elements following character data should pass indent = false. */ - void WriteEndElement( const char *const tag, std::ofstream &file, const bool& indent = true ); + void WriteEndElement( const char *const tag, std::ostream &file, const bool& indent = true ); /** Write character data inside a tag. */ - void WriteCharacterData( const char *const data, std::ofstream &file ); + void WriteCharacterData( const char *const data, std::ostream &file ); /** Write a start element tag */ - void WriteStartElement( std::string &tag, std::ofstream &file ); + void WriteStartElement( std::string &tag, std::ostream &file ); /** Write an end element tag */ - void WriteEndElement( std::string &tag, std::ofstream &file, const bool& indent = true ); + void WriteEndElement( std::string &tag, std::ostream &file, const bool& indent = true ); /** Write character data inside a tag. */ - void WriteCharacterData( std::string &data, std::ofstream &file ); + void WriteCharacterData( std::string &data, std::ostream &file ); /** Writes empty spaces to the stream according to m_IndentDepth and m_Indent */ - void WriteIndent( std::ofstream& file ); - - std::string m_FileName; - - std::string m_FilePrefix; - - std::string m_FilePattern; - - std::string m_Extension; - - std::string m_MimeType; + void WriteIndent( std::ostream& file ); unsigned int m_IndentDepth; unsigned int m_Indent; - bool m_Success; - - - public: static const char* XML_CONTOURMODEL; static const char* XML_HEAD; static const char* XML_GEOMETRY_INFO; static const char* XML_DATA; static const char* XML_TIME_STEP; static const char* XML_CONTROL_POINTS; static const char* XML_POINT; static const char* XML_X; static const char* XML_Y; static const char* XML_Z; }; } #endif diff --git a/Modules/ContourModel/IO/mitkContourModelWriterFactory.cpp b/Modules/ContourModel/IO/mitkContourModelWriterFactory.cpp deleted file mode 100644 index 1873f28ea5..0000000000 --- a/Modules/ContourModel/IO/mitkContourModelWriterFactory.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/*=================================================================== - -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 "mitkContourModelWriterFactory.h" - -#include "itkCreateObjectFunction.h" -#include "itkVersion.h" - -#include -#include - -namespace mitk -{ - -template -class CreateContourModelWriter : public itk::CreateObjectFunctionBase -{ -public: - - /** Standard class typedefs. */ - typedef CreateContourModelWriter Self; - typedef itk::SmartPointer Pointer; - - /** Methods from itk:LightObject. */ - itkFactorylessNewMacro(Self); - LightObject::Pointer CreateObject() { typename T::Pointer p = T::New(); - p->Register(); - return p.GetPointer(); - } - -protected: - CreateContourModelWriter() {} - ~CreateContourModelWriter() {} - -private: - CreateContourModelWriter(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented -}; - -ContourModelWriterFactory::ContourModelWriterFactory() -{ - this->RegisterOverride("IOWriter", - "ContourModelWriter", - "ContourModel xml writer", - 1, - mitk::CreateContourModelWriter::New()); - - this->RegisterOverride("IOWriter", - "ContourModelSetWriter", - "Writes a set of ContourModel objects.", - 1, - mitk::CreateContourModelWriter::New()); -} - -ContourModelWriterFactory::~ContourModelWriterFactory() -{ -} - -void ContourModelWriterFactory::RegisterOneFactory(void) -{ - if ( GetInstance()->GetReferenceCount() == 1 ) - { - ObjectFactoryBase::RegisterFactory( GetInstance().GetPointer() ); - } -} - -void ContourModelWriterFactory::UnRegisterOneFactory(void) -{ - ObjectFactoryBase::UnRegisterFactory( GetInstance().GetPointer() ); -} - -itk::ObjectFactoryBase::Pointer ContourModelWriterFactory::GetInstance() -{ - static itk::ObjectFactoryBase::Pointer factory(mitk::ContourModelWriterFactory::New().GetPointer()); - return factory; -} - -const char* ContourModelWriterFactory::GetITKSourceVersion() const -{ - return ITK_SOURCE_VERSION; -} - -const char* ContourModelWriterFactory::GetDescription() const -{ - return "ContourModelWriterFactory"; -} - -} // end namespace mitk diff --git a/Modules/ContourModel/IO/mitkContourModelWriterFactory.h b/Modules/ContourModel/IO/mitkContourModelWriterFactory.h deleted file mode 100644 index 5a3ebb2825..0000000000 --- a/Modules/ContourModel/IO/mitkContourModelWriterFactory.h +++ /dev/null @@ -1,63 +0,0 @@ -/*=================================================================== - -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 CONTOURMODELWRITERFACTORY_H_HEADER_INCLUDED -#define CONTOURMODELWRITERFACTORY_H_HEADER_INCLUDED - -#include -#include "itkObjectFactoryBase.h" -#include "mitkBaseData.h" - -namespace mitk -{ - - class MitkContourModel_EXPORT ContourModelWriterFactory : public itk::ObjectFactoryBase - { - public: - - mitkClassMacro( mitk::ContourModelWriterFactory, itk::ObjectFactoryBase ) - - /** Class methods used to interface with the registered factories. */ - virtual const char* GetITKSourceVersion(void) const; - virtual const char* GetDescription(void) const; - - /** Method for class instantiation. */ - itkFactorylessNewMacro(Self); - - /** - * Register one factory of this type - * \deprecatedSince{2013_09} - */ - DEPRECATED(static void RegisterOneFactory(void)); - - /** - * UnRegister one factory of this type - * \deprecatedSince{2013_09} - */ - DEPRECATED(static void UnRegisterOneFactory(void)); - - - protected: - ContourModelWriterFactory(); - ~ContourModelWriterFactory(); - - private: - ContourModelWriterFactory(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - - static itk::ObjectFactoryBase::Pointer GetInstance(); - }; -} -#endif //CONTOURMODELWRITERFACTORY_H_HEADER_INCLUDED diff --git a/Modules/ContourModel/Testing/mitkContourModelIOTest.cpp b/Modules/ContourModel/Testing/mitkContourModelIOTest.cpp index c44ec88997..abfb2dc9bd 100644 --- a/Modules/ContourModel/Testing/mitkContourModelIOTest.cpp +++ b/Modules/ContourModel/Testing/mitkContourModelIOTest.cpp @@ -1,121 +1,109 @@ /*=================================================================== 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 #include "mitkTestingConfig.h" #include #include #include #include -#include +#include static void TestContourModel(mitk::ContourModel* contour, std::string fileName) { - mitk::ContourModelWriter::Pointer writer = mitk::ContourModelWriter::New(); - - writer->SetInput(contour); std::string filename = std::string( MITK_TEST_OUTPUT_DIR ) + fileName; - writer->SetFileName(filename); - writer->Update(); - - MITK_TEST_CONDITION(writer->GetSuccess(),"write file"); - - mitk::ContourModelReader::Pointer reader = mitk::ContourModelReader::New(); - - reader->SetFileName(filename); - - reader->Update(); + mitk::IOUtil::Save(contour, filename); - MITK_TEST_CONDITION(reader->GetSuccess(), "read file"); + std::vector > readerOutput = mitk::IOUtil::Load(filename); - mitk::ContourModel::Pointer contour2 = reader->GetOutput(); + mitk::ContourModel::Pointer contour2 = dynamic_cast(readerOutput.at(0).GetPointer()); MITK_TEST_CONDITION_REQUIRED(contour2.IsNotNull(),"contour is not null"); MITK_TEST_CONDITION_REQUIRED(contour->GetNumberOfVertices() == contour2->GetNumberOfVertices(),"contours have the same number of vertices"); mitk::ContourModel::VertexIterator it = contour2->IteratorBegin(); mitk::ContourModel::VertexIterator end = contour2->IteratorEnd(); mitk::ContourModel::VertexIterator it2 = contour2->IteratorBegin(); bool areEqual = true; while(it != end) { areEqual &= ((*it)->Coordinates == (*it2)->Coordinates); it++; it2++; } MITK_TEST_CONDITION(areEqual, "contours are equal"); } static void TestContourModelIO_OneTimeStep() { mitk::ContourModel::Pointer contour = mitk::ContourModel::New(); mitk::Point3D p; p[0] = p[1] = p[2] = 0; contour->AddVertex(p); mitk::Point3D p2; p2[0] = p2[1] = p2[2] = 1; contour->AddVertex(p2); mitk::Point3D p3; p3[0] = -2; p3[1] = 10; p3[2] = 0; contour->AddVertex(p3); mitk::Point3D p4; p4[0] = -3; p4[1] = 6; p4[2] = -5; contour->AddVertex(p4); TestContourModel(contour.GetPointer(), "/contour.cnt"); } static void TestContourModelIO_EmptyContourModel() { mitk::ContourModel::Pointer contour = mitk::ContourModel::New(); TestContourModel(contour.GetPointer(), "/contourEmpty.cnt"); } int mitkContourModelIOTest(int /*argc*/, char* /*argv*/[]) { MITK_TEST_BEGIN("mitkContourModelIOTest") TestContourModelIO_OneTimeStep(); TestContourModelIO_EmptyContourModel(); MITK_TEST_END() } diff --git a/Modules/ContourModel/files.cmake b/Modules/ContourModel/files.cmake index beeab060ae..89b6f0a7a4 100644 --- a/Modules/ContourModel/files.cmake +++ b/Modules/ContourModel/files.cmake @@ -1,27 +1,26 @@ 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 + mitkContourModelActivator.cpp ) diff --git a/Modules/ContourModel/mitkContourModelActivator.cpp b/Modules/ContourModel/mitkContourModelActivator.cpp new file mode 100644 index 0000000000..2b0ae36bbe --- /dev/null +++ b/Modules/ContourModel/mitkContourModelActivator.cpp @@ -0,0 +1,60 @@ +/*=================================================================== + +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 "mitkContourModelSetReader.h" +#include "mitkContourModelReader.h" +#include "mitkContourModelWriter.h" +#include "mitkContourModelSetWriter.h" + +#include +#include + + +namespace mitk { + +/* + * This is the module activator for the "ContourModel" module. + */ +class ContourModelActivator : public us::ModuleActivator +{ +public: + + void Load(us::ModuleContext* context) + { + m_ContourModelReader = new ContourModelReader(); + m_ContourModelSetReader = new ContourModelSetReader(); + m_ContourModelWriter = new ContourModelWriter(); + m_ContourModelSetWriter = new ContourModelSetWriter(); + } + + void Unload(us::ModuleContext* ) + { + delete m_ContourModelReader; + delete m_ContourModelSetReader; + delete m_ContourModelWriter; + delete m_ContourModelSetWriter; + } + +private: + + mitk::ContourModelReader* m_ContourModelReader; + mitk::ContourModelSetReader* m_ContourModelSetReader; + mitk::ContourModelWriter* m_ContourModelWriter; + mitk::ContourModelSetWriter* m_ContourModelSetWriter; +}; +} + +US_EXPORT_MODULE_ACTIVATOR(mitk::ContourModelActivator) \ No newline at end of file diff --git a/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp b/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp index 3930f10237..b80a1506b4 100644 --- a/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp +++ b/Modules/DicomRT/Testing/mitkRTStructureSetReaderTest.cpp @@ -1,165 +1,158 @@ /*=================================================================== 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 "mitkTestingMacros.h" #include #include "mitkRTStructureSetReader.h" -#include -#include +#include #include class mitkRTStructureSetReaderTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkRTStructureSetReaderTestSuite); // MITK_TEST(TestBody); MITK_TEST(TestStructureSets); CPPUNIT_TEST_SUITE_END(); private: mitk::RTStructureSetReader::Pointer m_rtStructureReader; public: void setUp() { m_rtStructureReader = mitk::RTStructureSetReader::New(); CPPUNIT_ASSERT_MESSAGE("Failed to initialize RTStructureSetReader", m_rtStructureReader.IsNotNull()); } void TestStructureSets() { std::deque contourModelVectorCorrect; std::deque contourModelVectorCorrectSequ; std::deque contourModelVectorTest; std::deque contourModelVectorTestDel; LoadData(contourModelVectorCorrect); contourModelVectorTest = m_rtStructureReader->ReadStructureSet(GetTestDataFilePath("RT/StructureSet/RS.dcm").c_str()); //Deleting all empty contourmodelsets - empty contourmodelsets cant be //saved so we have reference for the comparison for(unsigned int i=0; i(contourModelVectorTest.at(i)->GetData())->GetSize()>0){ contourModelVectorTestDel.push_back(dynamic_cast(contourModelVectorTest.at(i)->GetData())); } } //Loop for ordering the loaded contourmodelsets(contourModelVectorCorrect) for(unsigned int i=0; iGetProperty("name"); for(unsigned int j=0; jGetProperty("name"); if(tmp->GetValueAsString().compare(name->GetValueAsString()) == 0) contourModelVectorCorrectSequ.push_back(contourModelVectorCorrect.at(j)); } } //Testing wheather the two deques are equal bool equal = true; for(unsigned int i=0;iGetSize()!=c2->GetSize()) { MITK_INFO << "Number of ContourModelSets different" << std::endl; return false; } else { for(int i=0;iGetSize();++i) { mitk::ContourModel::Pointer cm1 = c1->GetContourModelAt(i); mitk::ContourModel::Pointer cm2 = c2->GetContourModelAt(i); if(cm1->GetNumberOfVertices()!=cm2->GetNumberOfVertices()) { MITK_INFO << "Number of Vertices different" << std::endl; return false; } else { float ep = 0.001; for(int j=0;jGetNumberOfVertices();++j) { mitk::Point3D p1 = cm1->GetVertexAt(i)->Coordinates; mitk::Point3D p2 = cm2->GetVertexAt(i)->Coordinates; if(abs(p1[0]-p2[0]) > ep || abs(p1[0]-p2[0]) > ep || abs(p1[0]-p2[0]) > ep) { return false; } } } } } return true; } void LoadData(std::deque &r) { - mitk::ContourModelSetReader::Pointer reader = mitk::ContourModelSetReader::New(); + std::vector > readerOutput; - reader->SetFileName(GetTestDataFilePath("RT/StructureSet/BODY.cnt_set")); - reader->Update(); - mitk::ContourModelSet::Pointer cnt_set = reader->GetOutput(); + readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/BODY.cnt_set")); + mitk::ContourModelSet::Pointer cnt_set = dynamic_cast(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("BODY")); r.push_back(cnt_set); - reader->SetFileName(GetTestDataFilePath("RT/StructureSet/Bladder.cnt_set")); - reader->Update(); - cnt_set = reader->GetOutput(); + readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Bladder.cnt_set")); + cnt_set = dynamic_cast(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("Bladder")); r.push_back(cnt_set); - reader->SetFileName(GetTestDataFilePath("RT/StructureSet/Femoral Head Lt.cnt_set")); - reader->Update(); - cnt_set = reader->GetOutput(); + readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Femoral Head Lt.cnt_set")); + cnt_set = dynamic_cast(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head Lt")); r.push_back(cnt_set); - reader->SetFileName(GetTestDataFilePath("RT/StructureSet/Femoral Head RT.cnt_set")); - reader->Update(); - cnt_set = reader->GetOutput(); + readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Femoral Head RT.cnt_set")); + cnt_set = dynamic_cast(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("Femoral Head RT")); r.push_back(cnt_set); - reader->SetFileName(GetTestDataFilePath("RT/StructureSet/PTV.cnt_set")); - reader->Update(); - cnt_set = reader->GetOutput(); + readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/PTV.cnt_set")); + cnt_set = dynamic_cast(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("PTV")); r.push_back(cnt_set); - reader->SetFileName(GetTestDataFilePath("RT/StructureSet/Rectum.cnt_set")); - reader->Update(); - cnt_set = reader->GetOutput(); + readerOutput = mitk::IOUtil::Load(GetTestDataFilePath("RT/StructureSet/Rectum.cnt_set")); + cnt_set = dynamic_cast(readerOutput.at(0).GetPointer()); cnt_set->SetProperty("name", mitk::StringProperty::New("Rectum")); r.push_back(cnt_set); } }; MITK_TEST_SUITE_REGISTRATION(mitkRTStructureSetReader)