diff --git a/Modules/IOExt/Internal/mitkIOExtActivator.cpp b/Modules/IOExt/Internal/mitkIOExtActivator.cpp index d9af19f4c3..89ceb04ef9 100644 --- a/Modules/IOExt/Internal/mitkIOExtActivator.cpp +++ b/Modules/IOExt/Internal/mitkIOExtActivator.cpp @@ -1,34 +1,36 @@ /*=================================================================== 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 "mitkIOExtActivator.h" #include "mitkSceneFileReader.h" +#include "mitkVtkUnstructuredGridReader.h" namespace mitk { void IOExtActivator::Load(us::ModuleContext*) { m_SceneReader.reset(new SceneFileReader()); + m_VtkUnstructuredGridReader.reset(new VtkUnstructuredGridReader()); } void IOExtActivator::Unload(us::ModuleContext*) { } } US_EXPORT_MODULE_ACTIVATOR(mitk::IOExtActivator) diff --git a/Modules/IOExt/Internal/mitkIOExtActivator.h b/Modules/IOExt/Internal/mitkIOExtActivator.h index 87662f7be8..835c33cd1a 100644 --- a/Modules/IOExt/Internal/mitkIOExtActivator.h +++ b/Modules/IOExt/Internal/mitkIOExtActivator.h @@ -1,42 +1,43 @@ /*=================================================================== 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 MITKIOEXTACTIVATOR_H #define MITKIOEXTACTIVATOR_H #include #include namespace mitk { struct IFileReader; class IOExtActivator : public us::ModuleActivator { public: void Load(us::ModuleContext*context); void Unload(us::ModuleContext* context); private: std::auto_ptr m_SceneReader; + std::auto_ptr m_VtkUnstructuredGridReader; }; } #endif // MITKIOEXTACTIVATOR_H diff --git a/Modules/IOExt/Internal/mitkIOExtObjectFactory.cpp b/Modules/IOExt/Internal/mitkIOExtObjectFactory.cpp index 429ee09f5f..9db6582fc8 100644 --- a/Modules/IOExt/Internal/mitkIOExtObjectFactory.cpp +++ b/Modules/IOExt/Internal/mitkIOExtObjectFactory.cpp @@ -1,197 +1,193 @@ /*=================================================================== 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 "mitkIOExtObjectFactory.h" #include "mitkCoreObjectFactory.h" #include "mitkParRecFileIOFactory.h" #include "mitkObjFileIOFactory.h" -#include "mitkVtkUnstructuredGridIOFactory.h" #include "mitkStlVolumeTimeSeriesIOFactory.h" #include "mitkVtkVolumeTimeSeriesIOFactory.h" #include "mitkUnstructuredGridVtkWriterFactory.h" #include "mitkUnstructuredGridVtkWriter.h" #include "mitkMeshMapper2D.h" #include "mitkMeshVtkMapper3D.h" #include "mitkMesh.h" #include "mitkGPUVolumeMapper3D.h" #include "mitkUnstructuredGridMapper2D.h" #include "mitkUnstructuredGridVtkMapper3D.h" #include "mitkVtkGLMapperWrapper.h" #include #include #include mitk::IOExtObjectFactory::IOExtObjectFactory() : CoreObjectFactoryBase() , m_ParRecFileIOFactory(ParRecFileIOFactory::New().GetPointer()) , m_ObjFileIOFactory(ObjFileIOFactory::New().GetPointer()) - , m_VtkUnstructuredGridIOFactory(VtkUnstructuredGridIOFactory::New().GetPointer()) , m_StlVolumeTimeSeriesIOFactory(StlVolumeTimeSeriesIOFactory::New().GetPointer()) , m_VtkVolumeTimeSeriesIOFactory(VtkVolumeTimeSeriesIOFactory::New().GetPointer()) , m_UnstructuredGridVtkWriterFactory(UnstructuredGridVtkWriterFactory::New().GetPointer()) { static bool alreadyDone = false; if (!alreadyDone) { MITK_DEBUG << "IOExtObjectFactory c'tor" << std::endl; itk::ObjectFactoryBase::RegisterFactory( m_ParRecFileIOFactory ); itk::ObjectFactoryBase::RegisterFactory( m_ObjFileIOFactory ); - itk::ObjectFactoryBase::RegisterFactory( m_VtkUnstructuredGridIOFactory ); itk::ObjectFactoryBase::RegisterFactory( m_StlVolumeTimeSeriesIOFactory ); itk::ObjectFactoryBase::RegisterFactory( m_VtkVolumeTimeSeriesIOFactory ); itk::ObjectFactoryBase::RegisterFactory( m_UnstructuredGridVtkWriterFactory ); m_FileWriters.push_back(mitk::UnstructuredGridVtkWriter::New().GetPointer()); m_FileWriters.push_back(mitk::UnstructuredGridVtkWriter::New().GetPointer()); m_FileWriters.push_back(mitk::UnstructuredGridVtkWriter::New().GetPointer()); CreateFileExtensionsMap(); alreadyDone = true; } } mitk::IOExtObjectFactory::~IOExtObjectFactory() { itk::ObjectFactoryBase::UnRegisterFactory( m_ParRecFileIOFactory ); itk::ObjectFactoryBase::UnRegisterFactory( m_ObjFileIOFactory ); - itk::ObjectFactoryBase::UnRegisterFactory( m_VtkUnstructuredGridIOFactory ); itk::ObjectFactoryBase::UnRegisterFactory( m_StlVolumeTimeSeriesIOFactory ); itk::ObjectFactoryBase::UnRegisterFactory( m_VtkVolumeTimeSeriesIOFactory ); itk::ObjectFactoryBase::UnRegisterFactory( m_UnstructuredGridVtkWriterFactory ); } mitk::Mapper::Pointer mitk::IOExtObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; mitk::BaseData *data = node->GetData(); if ( id == mitk::BaseRenderer::Standard2D ) { if((dynamic_cast(data)!=NULL)) { newMapper = mitk::MeshMapper2D::New(); newMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::VtkGLMapperWrapper::New(mitk::UnstructuredGridMapper2D::New().GetPointer()); newMapper->SetDataNode(node); } } else if ( id == mitk::BaseRenderer::Standard3D ) { if((dynamic_cast(data) != NULL)) { newMapper = mitk::GPUVolumeMapper3D::New(); newMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::MeshVtkMapper3D::New(); newMapper->SetDataNode(node); } else if((dynamic_cast(data)!=NULL)) { newMapper = mitk::UnstructuredGridVtkMapper3D::New(); newMapper->SetDataNode(node); } } return newMapper; } void mitk::IOExtObjectFactory::SetDefaultProperties(mitk::DataNode* node) { if(node==NULL) return; mitk::DataNode::Pointer nodePointer = node; mitk::Image::Pointer image = dynamic_cast(node->GetData()); if(image.IsNotNull() && image->IsInitialized()) { mitk::GPUVolumeMapper3D::SetDefaultProperties(node); } if (dynamic_cast(node->GetData())) { mitk::UnstructuredGridVtkMapper3D::SetDefaultProperties(node); } } const char* mitk::IOExtObjectFactory::GetFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_FileExtensionsMap, fileExtension); return fileExtension.c_str(); } mitk::CoreObjectFactoryBase::MultimapType mitk::IOExtObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } mitk::CoreObjectFactoryBase::MultimapType mitk::IOExtObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::IOExtObjectFactory::CreateFileExtensionsMap() { m_FileExtensionsMap.insert(std::pair("*.vtu", "VTK Unstructured Grid")); m_FileExtensionsMap.insert(std::pair("*.vtk", "VTK Unstructured Grid")); m_FileExtensionsMap.insert(std::pair("*.pvtu", "VTK Unstructured Grid")); m_FileExtensionsMap.insert(std::pair("*.obj", "Surfaces")); m_SaveFileExtensionsMap.insert(std::pair("*.pvtu", "VTK Parallel XML Unstructured Grid")); m_SaveFileExtensionsMap.insert(std::pair("*.vtu", "VTK XML Unstructured Grid")); m_SaveFileExtensionsMap.insert(std::pair("*.vtk", "VTK Legacy Unstructured Grid")); } const char* mitk::IOExtObjectFactory::GetSaveFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); } struct RegisterIOExtObjectFactory { RegisterIOExtObjectFactory() : m_Factory( mitk::IOExtObjectFactory::New() ) { mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory( m_Factory ); } ~RegisterIOExtObjectFactory() { mitk::CoreObjectFactory::GetInstance()->UnRegisterExtraFactory( m_Factory ); } mitk::IOExtObjectFactory::Pointer m_Factory; }; static RegisterIOExtObjectFactory registerIOExtObjectFactory; diff --git a/Modules/IOExt/Internal/mitkVtkUnstructuredGridIOFactory.cpp b/Modules/IOExt/Internal/mitkVtkUnstructuredGridIOFactory.cpp deleted file mode 100644 index 89382e368e..0000000000 --- a/Modules/IOExt/Internal/mitkVtkUnstructuredGridIOFactory.cpp +++ /dev/null @@ -1,49 +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 "mitkVtkUnstructuredGridIOFactory.h" -#include "mitkIOAdapter.h" -#include "mitkVtkUnstructuredGridReader.h" - -#include "itkVersion.h" - - -namespace mitk -{ -VtkUnstructuredGridIOFactory::VtkUnstructuredGridIOFactory() -{ - this->RegisterOverride("mitkIOAdapter", - "mitkVtkUnstructuredGridReader", - "mitk Vtk UnstructuredGrid IO", - 1, - itk::CreateObjectFunction >::New()); -} - -VtkUnstructuredGridIOFactory::~VtkUnstructuredGridIOFactory() -{ -} - -const char* VtkUnstructuredGridIOFactory::GetITKSourceVersion() const -{ - return ITK_SOURCE_VERSION; -} - -const char* VtkUnstructuredGridIOFactory::GetDescription() const -{ - return "VtkUnstructuredGrid IO Factory, allows the loading of Vtk files containing unstructured grid data"; -} - -} // end namespace mitk diff --git a/Modules/IOExt/Internal/mitkVtkUnstructuredGridIOFactory.h b/Modules/IOExt/Internal/mitkVtkUnstructuredGridIOFactory.h deleted file mode 100644 index 7040c63f71..0000000000 --- a/Modules/IOExt/Internal/mitkVtkUnstructuredGridIOFactory.h +++ /dev/null @@ -1,73 +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 __MITK_VTK_UNSTRUCTURED_GRID_IO_FACTORY_H_HEADER__ -#define __MITK_VTK_UNSTRUCTURED_GRID_IO_FACTORY_H_HEADER__ - -#ifdef _MSC_VER -#pragma warning ( disable : 4786 ) -#endif - -#include "itkObjectFactoryBase.h" -#include "mitkBaseData.h" - -namespace mitk -{ -//##Documentation -//## @brief Create instances of VtkUnstructuredGridReader objects using an object factory. -//## -class VtkUnstructuredGridIOFactory : public itk::ObjectFactoryBase -{ -public: - /** Standard class typedefs. */ - typedef VtkUnstructuredGridIOFactory 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 VtkUnstructuredGridIOFactory* FactoryNew() { return new VtkUnstructuredGridIOFactory;} - /** Run-time type information (and related methods). */ - itkTypeMacro(VtkUnstructuredGridIOFactory, ObjectFactoryBase); - - /** - * Register one factory of this type - * \deprecatedSince{2013_09} - */ - DEPRECATED(static void RegisterOneFactory(void)) - { - VtkUnstructuredGridIOFactory::Pointer VtkUnstructuredGridIOFactory = VtkUnstructuredGridIOFactory::New(); - ObjectFactoryBase::RegisterFactory(VtkUnstructuredGridIOFactory); - } - -protected: - VtkUnstructuredGridIOFactory(); - ~VtkUnstructuredGridIOFactory(); - -private: - VtkUnstructuredGridIOFactory(const Self&); //purposely not implemented - void operator=(const Self&); //purposely not implemented - -}; - - -} // end namespace mitk - -#endif // __MITK_VTK_UNSTRUCTURED_GRID_IO_FACTORY_H_HEADER__ diff --git a/Modules/IOExt/Internal/mitkVtkUnstructuredGridReader.cpp b/Modules/IOExt/Internal/mitkVtkUnstructuredGridReader.cpp index ad44d57d63..4e20dab271 100644 --- a/Modules/IOExt/Internal/mitkVtkUnstructuredGridReader.cpp +++ b/Modules/IOExt/Internal/mitkVtkUnstructuredGridReader.cpp @@ -1,122 +1,91 @@ /*=================================================================== 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 "mitkVtkUnstructuredGridReader.h" #include #include #include #include #include +#include +#include mitk::VtkUnstructuredGridReader::VtkUnstructuredGridReader() -: m_FileName("") + : AbstractFileReader() { + CustomMimeType mimeType(IOMimeTypes::DEFAULT_BASE_NAME() + ".vtu"); + mimeType.SetComment("Vtk Unstructured Grid Files"); + mimeType.SetCategory("Vtk Unstructured Grid"); + mimeType.AddExtension("vtu"); + mimeType.AddExtension("vtk"); + + this->SetDescription("Vtk Unstructured Grid Files"); + this->SetMimeType(mimeType); + + this->RegisterService(); } mitk::VtkUnstructuredGridReader::~VtkUnstructuredGridReader() -{ -} +{} -void mitk::VtkUnstructuredGridReader::GenerateData() +std::vector< itk::SmartPointer > mitk::VtkUnstructuredGridReader::Read() { - if( m_FileName != "") + MITK_INFO << "Loading " << " as vtk unstructured grid"; + std::vector< itk::SmartPointer > result; + MITK_INFO << this->GetLocalFileName(); + std::string ext = itksys::SystemTools::GetFilenameLastExtension(GetLocalFileName().c_str()); + ext = itksys::SystemTools::LowerCase(ext); + if (ext == ".vtk") { - bool success = false; - MITK_INFO << "Loading " << m_FileName << " as vtk unstructured grid" << std::endl; - - std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); - ext = itksys::SystemTools::LowerCase(ext); - if (ext == ".vtk") + vtkDataReader *chooser = vtkDataReader::New(); + chooser->SetFileName(GetLocalFileName().c_str() ); + if( chooser->IsFileUnstructuredGrid()) { - ///We create a Generic Reader to test de .vtk/ - vtkDataReader *chooser=vtkDataReader::New(); - chooser->SetFileName(m_FileName.c_str() ); - if( chooser->IsFileUnstructuredGrid()) - { - ///UnstructuredGrid/ - itkDebugMacro( << "UnstructuredGrid" ); - vtkUnstructuredGridReader *reader = vtkUnstructuredGridReader::New(); - reader->SetFileName( m_FileName.c_str() ); - reader->Update(); + vtkUnstructuredGridReader* reader = vtkUnstructuredGridReader::New(); + reader->SetFileName( GetLocalFileName().c_str() ); + reader->Update(); - if ( reader->GetOutput() != NULL ) - { - mitk::UnstructuredGrid::Pointer output = this->GetOutput(); - output->SetVtkUnstructuredGrid( reader->GetOutput() ); - success = true; - } - reader->Delete(); - } - } - else if (ext == ".vtu") - { - vtkXMLUnstructuredGridReader *reader=vtkXMLUnstructuredGridReader::New(); - if( reader->CanReadFile(m_FileName.c_str()) ) + if ( reader->GetOutput() != NULL ) { - ///UnstructuredGrid/ - itkDebugMacro( << "XMLUnstructuredGrid" ); - reader->SetFileName( m_FileName.c_str() ); - reader->Update(); - - if ( reader->GetOutput() != NULL ) - { - mitk::UnstructuredGrid::Pointer output = this->GetOutput(); - output->SetVtkUnstructuredGrid( reader->GetOutput() ); - success = true; - } - reader->Delete(); + mitk::UnstructuredGrid::Pointer grid = mitk::UnstructuredGrid::New(); + grid->SetVtkUnstructuredGrid( reader->GetOutput() ); + result.push_back( grid.GetPointer() ); } - } - if(!success) - { - itkExceptionMacro( << " ... sorry, this .vtk format is not supported yet." ); + reader->Delete(); } } -} - -bool mitk::VtkUnstructuredGridReader::CanReadFile(const std::string filename, const std::string /*filePrefix*/, const std::string /*filePattern*/) -{ - // First check the extension - if( filename == "" ) - return false; - - std::string ext = itksys::SystemTools::GetFilenameLastExtension(filename); - ext = itksys::SystemTools::LowerCase(ext); - if (ext == ".vtk") + else if (ext == ".vtu") { - vtkDataReader *chooser=vtkDataReader::New(); - chooser->SetFileName(filename.c_str() ); - if(!chooser->IsFileUnstructuredGrid()) + vtkXMLUnstructuredGridReader* reader = vtkXMLUnstructuredGridReader::New(); + reader->SetFileName(GetLocalFileName().c_str() ); + reader->Update(); + + if ( reader->GetOutput() != NULL ) { - chooser->Delete(); - return false; + mitk::UnstructuredGrid::Pointer grid = mitk::UnstructuredGrid::New(); + grid->SetVtkUnstructuredGrid( reader->GetOutput() ); + result.push_back( grid.GetPointer() ); } + reader->Delete(); } - else if (ext == ".vtu") - { - vtkXMLUnstructuredGridReader *chooser=vtkXMLUnstructuredGridReader::New(); - if(!chooser->CanReadFile(filename.c_str())) - { - chooser->Delete(); - return false; - } - } - else - return false; + return result; +} - return true; +mitk::VtkUnstructuredGridReader* mitk::VtkUnstructuredGridReader::Clone() const +{ + return new mitk::VtkUnstructuredGridReader(*this); } diff --git a/Modules/IOExt/Internal/mitkVtkUnstructuredGridReader.h b/Modules/IOExt/Internal/mitkVtkUnstructuredGridReader.h index b382340111..04eec0e8c9 100644 --- a/Modules/IOExt/Internal/mitkVtkUnstructuredGridReader.h +++ b/Modules/IOExt/Internal/mitkVtkUnstructuredGridReader.h @@ -1,58 +1,41 @@ /*=================================================================== 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 VtkUnstructuredGridReader_H_HEADER_INCLUDED #define VtkUnstructuredGridReader_H_HEADER_INCLUDED -#include "mitkCommon.h" -#include "mitkUnstructuredGridSource.h" +#include namespace mitk { //##Documentation //## @brief Reader to read unstructured grid files in vtk-format -class VtkUnstructuredGridReader : public UnstructuredGridSource +class VtkUnstructuredGridReader : public AbstractFileReader { public: - mitkClassMacro(VtkUnstructuredGridReader, UnstructuredGridSource); - /** Method for creation through the object factory. */ - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) + VtkUnstructuredGridReader(); + virtual ~VtkUnstructuredGridReader(); - itkSetStringMacro(FileName); - itkGetStringMacro(FileName); - - itkSetStringMacro(FilePrefix); - itkGetStringMacro(FilePrefix); - - itkSetStringMacro(FilePattern); - itkGetStringMacro(FilePattern); - - static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern); + using AbstractFileReader::Read; + virtual std::vector< itk::SmartPointer > Read(); protected: - virtual void GenerateData(); - - VtkUnstructuredGridReader(); - - ~VtkUnstructuredGridReader(); - - std::string m_FileName, m_FilePrefix, m_FilePattern; + virtual VtkUnstructuredGridReader* Clone() const; }; } // namespace mitk #endif /* VtkUnstructuredGridReader_H_HEADER_INCLUDED */ diff --git a/Modules/IOExt/files.cmake b/Modules/IOExt/files.cmake index 05ac7aa15d..d3fabf5151 100644 --- a/Modules/IOExt/files.cmake +++ b/Modules/IOExt/files.cmake @@ -1,17 +1,16 @@ set(CPP_FILES Internal/mitkIOExtActivator.cpp Internal/mitkIOExtObjectFactory.cpp Internal/mitkObjFileIOFactory.cpp Internal/mitkObjFileReader.cpp Internal/mitkParRecFileIOFactory.cpp Internal/mitkParRecFileReader.cpp Internal/mitkSceneFileReader.cpp Internal/mitkStlVolumeTimeSeriesIOFactory.cpp Internal/mitkStlVolumeTimeSeriesReader.cpp Internal/mitkUnstructuredGridVtkWriter.cpp Internal/mitkUnstructuredGridVtkWriterFactory.cpp - Internal/mitkVtkUnstructuredGridIOFactory.cpp Internal/mitkVtkUnstructuredGridReader.cpp Internal/mitkVtkVolumeTimeSeriesIOFactory.cpp Internal/mitkVtkVolumeTimeSeriesReader.cpp )