diff --git a/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundleX/mitkFiberBundleXReader.cpp b/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundleX/mitkFiberBundleXReader.cpp index 22b31f140b..cda259ab09 100644 --- a/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundleX/mitkFiberBundleXReader.cpp +++ b/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundleX/mitkFiberBundleXReader.cpp @@ -1,176 +1,108 @@ /*=================================================================== 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 "mitkFiberBundleXReader.h" #include #include #include #include #include #include #include #include #include #include #include +#include -namespace mitk -{ -void FiberBundleXReader -::GenerateData() +mitk::FiberBundleXReader::FiberBundleXReader() + :mitk::AbstractFileReader() { - if ( ( ! m_OutputCache ) ) - { - Superclass::SetNumberOfRequiredOutputs(0); - this->GenerateOutputInformation(); - } - - if (!m_OutputCache) - { - itkWarningMacro("Output cache is empty!"); - } - + std::string category = "Fiber Bundle File"; + mitk::CustomMimeType customMimeType; + customMimeType.SetCategory(category); + customMimeType.AddExtension("fib"); + customMimeType.AddExtension("trk"); + customMimeType.AddExtension("vtk"); - Superclass::SetNumberOfRequiredOutputs(1); - Superclass::SetNthOutput(0, m_OutputCache.GetPointer()); -} - -void FiberBundleXReader::GenerateOutputInformation() -{ - try - { - const std::string& locale = "C"; - const std::string& currLocale = setlocale( LC_ALL, NULL ); - setlocale(LC_ALL, locale.c_str()); - - std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); - ext = itksys::SystemTools::LowerCase(ext); - - if (ext==".trk") - { - m_OutputCache = OutputType::New(); - TrackVisFiberReader reader; - reader.open(m_FileName); - reader.read(m_OutputCache); - return; - } - - vtkSmartPointer chooser=vtkSmartPointer::New(); - chooser->SetFileName(m_FileName.c_str() ); - if( chooser->IsFilePolyData()) - { - vtkSmartPointer reader = vtkSmartPointer::New(); - reader->SetFileName( m_FileName.c_str() ); - reader->Update(); - - if ( reader->GetOutput() != NULL ) - { - vtkSmartPointer fiberPolyData = reader->GetOutput(); - m_OutputCache = OutputType::New(fiberPolyData); - } - } - setlocale(LC_ALL, currLocale.c_str()); - MITK_INFO << "Fiber bundle read"; - } - catch(...) - { - throw; - } -} + this->SetDescription(category); + this->SetMimeType(customMimeType); -void FiberBundleXReader::Update() -{ - this->GenerateData(); + m_ServiceReg = this->RegisterService(); } -const char* FiberBundleXReader -::GetFileName() const +mitk::FiberBundleXReader::FiberBundleXReader(const FiberBundleXReader &other) + :mitk::AbstractFileReader(other) { - return m_FileName.c_str(); } - -void FiberBundleXReader -::SetFileName(const char* aFileName) +mitk::FiberBundleXReader * mitk::FiberBundleXReader::Clone() const { - m_FileName = aFileName; + return new FiberBundleXReader(*this); } -const char* FiberBundleXReader -::GetFilePrefix() const +std::vector > mitk::FiberBundleXReader::Read() { - return m_FilePrefix.c_str(); -} + std::vector > result; + try + { + const std::string& locale = "C"; + const std::string& currLocale = setlocale( LC_ALL, NULL ); + setlocale(LC_ALL, locale.c_str()); -void FiberBundleXReader -::SetFilePrefix(const char* aFilePrefix) -{ - m_FilePrefix = aFilePrefix; -} + std::string filename = this->GetInputLocation(); - -const char* FiberBundleXReader -::GetFilePattern() const -{ - return m_FilePattern.c_str(); -} - - -void FiberBundleXReader -::SetFilePattern(const char* aFilePattern) -{ - m_FilePattern = aFilePattern; -} - - -bool FiberBundleXReader -::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 == ".fib" || ext == ".trk") + if (ext==".trk") { - return true; + FiberBundleX::Pointer image = FiberBundleX::New(); + TrackVisFiberReader reader; + reader.open(this->GetInputLocation().c_str()); + reader.read(image.GetPointer()); + result.push_back(image.GetPointer()); + return result; } - return false; -} - -BaseDataSource::DataObjectPointer FiberBundleXReader::MakeOutput(const DataObjectIdentifierType &name) -{ - itkDebugMacro("MakeOutput(" << name << ")"); - if( this->IsIndexedOutputName(name) ) + vtkSmartPointer chooser=vtkSmartPointer::New(); + chooser->SetFileName( this->GetInputLocation().c_str() ); + if( chooser->IsFilePolyData()) { - return this->MakeOutput( this->MakeIndexFromOutputName(name) ); + vtkSmartPointer reader = vtkSmartPointer::New(); + reader->SetFileName( this->GetInputLocation().c_str() ); + reader->Update(); + + if ( reader->GetOutput() != NULL ) + { + vtkSmartPointer fiberPolyData = reader->GetOutput(); + FiberBundleX::Pointer image = FiberBundleX::New(fiberPolyData); + result.push_back(image.GetPointer()); + return result; + } } - return static_cast(OutputType::New().GetPointer()); + setlocale(LC_ALL, currLocale.c_str()); + MITK_INFO << "Fiber bundle read"; + } + catch(...) + { + throw; + } + return result; } - -BaseDataSource::DataObjectPointer FiberBundleXReader::MakeOutput(DataObjectPointerArraySizeType /*idx*/) -{ - return OutputType::New().GetPointer(); -} - -} //namespace MITK diff --git a/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundleX/mitkFiberBundleXReader.h b/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundleX/mitkFiberBundleXReader.h index e05e54afe2..386fdad556 100644 --- a/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundleX/mitkFiberBundleXReader.h +++ b/Modules/DiffusionImaging/FiberTracking/IODataStructures/FiberBundleX/mitkFiberBundleXReader.h @@ -1,77 +1,52 @@ /*=================================================================== 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 __mitkFiberBundleXReader_h #define __mitkFiberBundleXReader_h #include #include #include #include -#include + +#include namespace mitk { /** \brief */ - class MitkFiberTracking_EXPORT FiberBundleXReader : public FileReader, public BaseDataSource + class FiberBundleXReader : public AbstractFileReader { public: - /** Types for the standardized TractContainer **/ - /* direct linked includes of mitkFiberBundleX DataStructure */ - - typedef mitk::FiberBundleX OutputType; - - mitkClassMacro( FiberBundleXReader, BaseDataSource ) - itkFactorylessNewMacro(Self) - itkCloneMacro(Self) - - const char* GetFileName() const; - void SetFileName(const char* aFileName); - const char* GetFilePrefix() const; - void SetFilePrefix(const char* aFilePrefix); - const char* GetFilePattern() const; - void SetFilePattern(const char* aFilePattern); - - static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern); - - virtual void Update(); + FiberBundleXReader(); + virtual ~FiberBundleXReader(){} + FiberBundleXReader(const FiberBundleXReader& other); + virtual FiberBundleXReader * Clone() const; - BaseDataSource::DataObjectPointer MakeOutput(const DataObjectIdentifierType &name); - BaseDataSource::DataObjectPointer MakeOutput( DataObjectPointerArraySizeType idx); - - protected: - - /** Does the real work. */ - virtual void GenerateData(); - virtual void GenerateOutputInformation(); - - OutputType::Pointer m_OutputCache; - - std::string m_FileName; - std::string m_FilePrefix; - std::string m_FilePattern; + using mitk::AbstractFileReader::Read; + virtual std::vector > Read(); private: - void operator=(const Self&); //purposely not implemented + + us::ServiceRegistration m_ServiceReg; }; } //namespace MITK #endif // __mitkFiberBundleXReader_h