diff --git a/Modules/DiffusionImaging/CMakeLists.txt b/Modules/DiffusionImaging/CMakeLists.txt index e3a55b3ec3..7a8080a8f3 100644 --- a/Modules/DiffusionImaging/CMakeLists.txt +++ b/Modules/DiffusionImaging/CMakeLists.txt @@ -1,26 +1,26 @@ FIND_PACKAGE(ITK) IF(ITK_GDCM_DIR) INCLUDE(${ITK_GDCM_DIR}/GDCMConfig.cmake) IF(GDCM_MAJOR_VERSION EQUAL 2) ADD_DEFINITIONS(-DGDCM2) SET(ITK_USES_GDCM2 1) ENDIF(GDCM_MAJOR_VERSION EQUAL 2) ENDIF(ITK_GDCM_DIR) MITK_CREATE_MODULE( MitkDiffusionImaging SUBPROJECTS MITK-DTI - INCLUDE_DIRS IODataStructures Reconstruction Tractography Rendering Algorithms DicomImport Interactions IODataStructures/DiffusionWeightedImages IODataStructures/QBallImages IODataStructures/TensorImages IODataStructures/FiberBundle IODataStructures/PlanarFigureComposite IODataStructures/TbssImages ${CMAKE_CURRENT_BINARY_DIR} + INCLUDE_DIRS IODataStructures Reconstruction Tractography Rendering Algorithms DicomImport Interactions IODataStructures/DiffusionWeightedImages IODataStructures/QBallImages IODataStructures/TensorImages IODataStructures/FiberBundle IODataStructures/FiberBundleX IODataStructures/PlanarFigureComposite IODataStructures/TbssImages ${CMAKE_CURRENT_BINARY_DIR} DEPENDS MitkExt SceneSerializationBase QmitkExt PACKAGE_DEPENDS Boost ) MITK_USE_MODULE(MitkDiffusionImaging) if(MitkDiffusionImaging_IS_ENABLED) file(DOWNLOAD http://mitk.org/download/data/FibertrackingLUT.tar.gz ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/FibertrackingLUT.tar.gz TIMEOUT 10) execute_process(COMMAND cmake -E chdir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} tar xzf FibertrackingLUT.tar.gz) endif() ADD_SUBDIRECTORY(Testing) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mitkDiffusionImagingConfigure.h.in ${CMAKE_CURRENT_BINARY_DIR}/mitkDiffusionImagingConfigure.h) diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.cpp b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.cpp new file mode 100644 index 0000000000..ca6be3dc2d --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.cpp @@ -0,0 +1,238 @@ +/*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ + Version: $Revision: 21975 $ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ + + +#include "mitkFiberBundleX.h" + +#include +#include + +// baptize array names +const char* mitk::FiberBundleX::COLORCODING_ORIENTATION_BASED = "Color_Orient"; +const char* mitk::FiberBundleX::COLORCODING_FA_BASED = "Color_FA"; + + +mitk::FiberBundleX::FiberBundleX() +{ + + + +} + +mitk::FiberBundleX::~FiberBundleX() +{ + +} + +/* === main input method ==== + * set computed fibers from tractography algorithms + */ +void mitk::FiberBundleX::SetFibers(vtkSmartPointer fiberPD) +{ + m_FiberStructureData = fiberPD; +} + + +/* === main output method === + * return fiberbundle as vtkPolyData + * Depending on processing of input fibers, this method returns + * the latest processed fibers. + */ +vtkPolyData* mitk::FiberBundleX::GetFibers() +{ + return m_FiberStructureData; +} + + + + +/*============================================== + *++++ PROCESSING WITH FIBER INFORMATION +++++++ + =============================================*/ + +void mitk::FiberBundleX::DoColorCodingOrientationbased() +{ + //===== FOR WRITING A TEST ======================== + // colorT size == tupelComponents * tupelElements + // compare color results + // to cover this code 100% also polydata needed, where colorarray already exists + // + one fiber with exactly 1 point + // + one fiber with 0 points + //================================================= + + /* === decide which polydata to choose === + ** ALL REDESIGNED + */ + + bool hasFiberDataColor = false; + + // check if color array in original fiber dataset is valid + if ( m_FiberStructureData != NULL ) + { + if ( m_FiberStructureData->GetPointData()->HasArray(COLORCODING_ORIENTATION_BASED) && + m_FiberStructureData->GetNumberOfPoints() == + m_FiberStructureData->GetPointData()->GetArray(COLORCODING_ORIENTATION_BASED)->GetNumberOfTuples() ) + { + hasFiberDataColor = true; + } + + } else { + MITK_INFO << "NO FIBERS FROM TRACTOGRAPHY PASSED TO mitkFiberBundleX yet!! no colorcoding can be processed!"; + hasFiberDataColor = true; // "true" will return later on + } + + /* make sure that processing colorcoding is only called when necessary */ + if (hasFiberDataColor) + return; + + /* Finally, execute color calculation */ + vtkPoints* extrPoints = m_FiberStructureData->GetPoints(); + int numOfPoints = extrPoints->GetNumberOfPoints(); + + //colors and alpha value for each single point, RGBA = 4 components + unsigned char rgba[4] = {0,0,0,0}; + int componentSize = sizeof(rgba); + + vtkUnsignedCharArray *colorsT = vtkUnsignedCharArray::New(); + colorsT->Allocate(numOfPoints * componentSize); + colorsT->SetNumberOfComponents(componentSize); + colorsT->SetName(COLORCODING_ORIENTATION_BASED); + + /* catch case: fiber consists of only 1 point */ + if (numOfPoints > 1) + { + + for (int i=0; i 0) + { + /* The color value of the current point is influenced by the previous point and next point. */ + vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(i)[0], extrPoints->GetPoint(i)[1],extrPoints->GetPoint(i)[2]); + vnl_vector_fixed< double, 3 > nextPntvtk(extrPoints->GetPoint(i+1)[0], extrPoints->GetPoint(i+1)[1], extrPoints->GetPoint(i+1)[2]); + vnl_vector_fixed< double, 3 > prevPntvtk(extrPoints->GetPoint(i-1)[0], extrPoints->GetPoint(i-1)[1], extrPoints->GetPoint(i-1)[2]); + + vnl_vector_fixed< double, 3 > diff1; + diff1 = currentPntvtk - nextPntvtk; + diff1.normalize(); + + vnl_vector_fixed< double, 3 > diff2; + diff2 = currentPntvtk - prevPntvtk; + diff2.normalize(); + + vnl_vector_fixed< double, 3 > diff; + diff = (diff1 - diff2) / 2.0; + + rgba[0] = (unsigned char) (255.0 * std::abs(diff[0])); + rgba[1] = (unsigned char) (255.0 * std::abs(diff[1])); + rgba[2] = (unsigned char) (255.0 * std::abs(diff[2])); + rgba[3] = (unsigned char) (255.0); + + + } else if (i==0) { + /* First point has no previous point, therefore only diff1 is taken */ + + vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(i)[0], extrPoints->GetPoint(i)[1],extrPoints->GetPoint(i)[2]); + vnl_vector_fixed< double, 3 > nextPntvtk(extrPoints->GetPoint(i+1)[0], extrPoints->GetPoint(i+1)[1], extrPoints->GetPoint(i+1)[2]); + + vnl_vector_fixed< double, 3 > diff1; + diff1 = currentPntvtk - nextPntvtk; + diff1.normalize(); + + rgba[0] = (unsigned char) (255.0 * std::abs(diff1[0])); + rgba[1] = (unsigned char) (255.0 * std::abs(diff1[1])); + rgba[2] = (unsigned char) (255.0 * std::abs(diff1[2])); + rgba[3] = (unsigned char) (255.0); + + } else if (i==numOfPoints-1) { + /* Last point has no next point, therefore only diff2 is taken */ + vnl_vector_fixed< double, 3 > currentPntvtk(extrPoints->GetPoint(i)[0], extrPoints->GetPoint(i)[1],extrPoints->GetPoint(i)[2]); + vnl_vector_fixed< double, 3 > prevPntvtk(extrPoints->GetPoint(i-1)[0], extrPoints->GetPoint(i-1)[1], extrPoints->GetPoint(i-1)[2]); + + vnl_vector_fixed< double, 3 > diff2; + diff2 = currentPntvtk - prevPntvtk; + diff2.normalize(); + + rgba[0] = (unsigned char) (255.0 * std::abs(diff2[0])); + rgba[1] = (unsigned char) (255.0 * std::abs(diff2[1])); + rgba[2] = (unsigned char) (255.0 * std::abs(diff2[2])); + rgba[3] = (unsigned char) (255.0); + + } + + colorsT->InsertTupleValue(i, rgba); + } //end for loop + + } else if (numOfPoints == 1) { + /* Fiber consists of 1 point only, color that point as you wish :) */ + colorsT->InsertTupleValue(0, rgba); + + } else { + MITK_INFO << "Fiber with 0 points detected... please check your tractography algorithm!" ; + } + + + m_FiberStructureData->GetPointData()->AddArray(colorsT); + + //mini test, shall be ported to MITK TESTINGS! + if (colorsT->GetSize() != numOfPoints*componentSize) { + MITK_INFO << "ALLOCATION ERROR IN INITIATING COLOR ARRAY"; + } + + +//===== clean memory ===== + colorsT->Delete(); + +//======================== +} + +////private repairMechanism for orientationbased colorcoding +//bool mitk::FiberBundleX::doSelfHealingColorOrient(vtkPolyData* healMe) +//{ +// bool hasHealingSucceeded = false; +// MITK_INFO << "FiberBundleX self repair mechanism is called, but not yet implemented"; +//// check type of healMe +// if (healMe == m_ImportedFiberData) +// { +// //todo +// } +// +// return hasHealingSucceeded; +//} + +/* ESSENTIAL IMPLEMENTATION OF SUPERCLASS METHODS */ +void mitk::FiberBundleX::UpdateOutputInformation() +{ + +} +void mitk::FiberBundleX::SetRequestedRegionToLargestPossibleRegion() +{ + +} +bool mitk::FiberBundleX::RequestedRegionIsOutsideOfTheBufferedRegion() +{ + return false; +} +bool mitk::FiberBundleX::VerifyRequestedRegion() +{ + return true; +} +void mitk::FiberBundleX::SetRequestedRegion( itk::DataObject *data ) +{ + +} \ No newline at end of file diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.h b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.h new file mode 100644 index 0000000000..2d30f5a06d --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleX.h @@ -0,0 +1,105 @@ + +/*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Module: $RCSfile$ + Language: C++ + Date: $Date$ + Version: $Revision: 11989 $ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ + + +#ifndef _MITK_FiberBundleX_H +#define _MITK_FiberBundleX_H + +//includes for MITK datastructure +#include "mitkBaseData.h" +#include "MitkDiffusionImagingExports.h" + + +//includes storing fiberdata +#include //may be replaced by class precompile argument +#include // may be replaced by class +#include // my be replaced by class + + +namespace mitk { + + /** + * \brief Base Class for Fiber Bundles; */ + class MitkDiffusionImaging_EXPORT FiberBundleX : public BaseData + { + public: + + // names of certain arrays (e.g colorcodings, etc.) + static const char* COLORCODING_ORIENTATION_BASED; + static const char* COLORCODING_FA_BASED; + + /* friend classes wanna access typedefs + ContainerPointType, ContainerTractType, ContainerType */ + friend class FiberBundleXWriter; + friend class FiberBundleXReader; + + + // ======virtual methods must have====== + virtual void UpdateOutputInformation(); + virtual void SetRequestedRegionToLargestPossibleRegion(); + virtual bool RequestedRegionIsOutsideOfTheBufferedRegion(); + virtual bool VerifyRequestedRegion(); + virtual void SetRequestedRegion( itk::DataObject *data ); + //======================================= + + mitkClassMacro( FiberBundleX, BaseData ); + itkNewMacro( Self ); + + // import fiber result from tractography algorithms + void SetFibers(vtkSmartPointer); + + + // return processed fibers + vtkPolyData* GetFibers(); + + // return vertex polydata + vtkPolyData* GetVertices(); + + void DoColorCodingOrientationbased(); + + + protected: + FiberBundleX(); + virtual ~FiberBundleX(); + + private: + +//// ====TODO==================================== +// bool doSelfHealingColorOrient( vtkPolyData* ); +//// ============================================ + + // The following polydata variables are used for fiber- and pointbased representation of the tractography results. As VTK suggests, one vtkPolyData is used to manage vertices and the other for polylines. + // FiberPolyData stores all brain fibers using polylines (in world coordinates) + // this variable hosts the smoothed fiber data, this data we generate, therefore a smartpointer structure is recommended +// vtkSmartPointer m_FiberPolyData; is depricated +// + // this variable hosts the original fiber data, no smartpointer needed because who or whatever passes this data to FiberBundleX should use vtkSmartPointer structure + + vtkPolyData* m_FiberStructureData; + + // VertexPolyData stores all original points as vertices computed by tracking algorithms + vtkSmartPointer m_VertexPolyData; + + + + }; + +} // namespace mitk + +#endif /* _MITK_FiberBundleX_H */ diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXIOFactory.cpp b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXIOFactory.cpp new file mode 100644 index 0000000000..cd06406779 --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXIOFactory.cpp @@ -0,0 +1,54 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2007-12-11 14:46:19 +0100 (Di, 11 Dez 2007) $ +Version: $Revision: 6607 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "mitkFiberBundleXIOFactory.h" +#include "mitkIOAdapter.h" +#include "mitkFiberBundleXReader.h" + +#include "itkVersion.h" + +//NOTE>umbenennen in FBReaderType + + +namespace mitk +{ + +FiberBundleXIOFactory::FiberBundleXIOFactory() +{ + typedef FiberBundleXReader FiberBundleXReaderType; + this->RegisterOverride("mitkIOAdapter", //beibehalten + "mitkFiberBundleXReader", //umbenennen + "Fiber Bundle IO", //angezeigter name + 1, + itk::CreateObjectFunction >::New()); +} + +FiberBundleXIOFactory::~FiberBundleXIOFactory() +{ +} + +const char* FiberBundleXIOFactory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} + +const char* FiberBundleXIOFactory::GetDescription() const +{ + return "FibreBundleIOFactory, allows the loading of FibreBundles"; +} + +} // end namespace mitk diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXIOFactory.h b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXIOFactory.h new file mode 100644 index 0000000000..ddc03926d5 --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXIOFactory.h @@ -0,0 +1,76 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-05-13 18:06:46 +0200 (Mi, 13 Mai 2009) $ +Version: $Revision: 6590 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#ifndef __MITK_FIBER_BUNDLEX_IO_FACTORY_H_HEADER__ +#define __MITK_FIBER_BUNDLEX_IO_FACTORY_H_HEADER__ + +#ifdef _MSC_VER +#pragma warning ( disable : 4786 ) +#endif + +#include "itkObjectFactoryBase.h" +#include "mitkBaseData.h" +#include "MitkDiffusionImagingExports.h" + +//NOTE>umbenennen in internal FiberBundleIOFactory + + +namespace mitk +{ +//##Documentation +//## @brief Create instances of NrrdQBallImageReader objects using an object factory. +//## +//## @ingroup IO +class MitkDiffusionImaging_EXPORT FiberBundleXIOFactory : public itk::ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef FiberBundleXIOFactory 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 FiberBundleXIOFactory* FactoryNew() { return new FiberBundleXIOFactory;} + /** Run-time type information (and related methods). */ + itkTypeMacro(FiberBundleXIOFactory, ObjectFactoryBase); + + /** Register one factory of this type */ + static void RegisterOneFactory(void) + { + FiberBundleXIOFactory::Pointer FiberBundleXIOFactory = FiberBundleXIOFactory::New(); + ObjectFactoryBase::RegisterFactory(FiberBundleXIOFactory); + } + +protected: + FiberBundleXIOFactory(); + ~FiberBundleXIOFactory(); + +private: + FiberBundleXIOFactory(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + + +} // end namespace mitk + +#endif // __MITK_FIBER_BUNDLE_IO_FACTORY_H_HEADER__ diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXReader.cpp b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXReader.cpp new file mode 100644 index 0000000000..af9a8b5f33 --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXReader.cpp @@ -0,0 +1,385 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ +Version: $Revision: 18127 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "mitkFiberBundleXReader.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char* mitk::FiberBundleXReader::XML_GEOMETRY = "geometry"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_XX = "xx"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_XY = "xy"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_XZ = "xz"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_YX = "yx"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_YY = "yy"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_YZ = "yz"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_ZX = "zx"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_ZY = "zy"; + +const char* mitk::FiberBundleXReader::XML_MATRIX_ZZ = "zz"; + +const char* mitk::FiberBundleXReader::XML_ORIGIN_X = "origin_x"; + +const char* mitk::FiberBundleXReader::XML_ORIGIN_Y = "origin_y"; + +const char* mitk::FiberBundleXReader::XML_ORIGIN_Z = "origin_z"; + +const char* mitk::FiberBundleXReader::XML_SPACING_X = "spacing_x"; + +const char* mitk::FiberBundleXReader::XML_SPACING_Y = "spacing_y"; + +const char* mitk::FiberBundleXReader::XML_SPACING_Z = "spacing_z"; + +const char* mitk::FiberBundleXReader::XML_SIZE_X = "size_x"; + +const char* mitk::FiberBundleXReader::XML_SIZE_Y = "size_y"; + +const char* mitk::FiberBundleXReader::XML_SIZE_Z = "size_z"; + +const char* mitk::FiberBundleXReader::XML_FIBER_BUNDLE = "fiber_bundle"; + +const char* mitk::FiberBundleXReader::XML_FIBER = "fiber"; + +const char* mitk::FiberBundleXReader::XML_PARTICLE = "particle"; + +const char* mitk::FiberBundleXReader::XML_ID = "id"; + +const char* mitk::FiberBundleXReader::XML_POS_X = "pos_x"; + +const char* mitk::FiberBundleXReader::XML_POS_Y = "pos_y"; + +const char* mitk::FiberBundleXReader::XML_POS_Z = "pos_z"; + +const char* mitk::FiberBundleXReader::XML_NUM_FIBERS = "num_fibers"; + +const char* mitk::FiberBundleXReader::XML_NUM_PARTICLES = "num_particles"; + +const char* mitk::FiberBundleXReader::XML_FIBER_BUNDLE_FILE = "fiber_bundle_file" ; + +const char* mitk::FiberBundleXReader::XML_FILE_VERSION = "file_version" ; + +const char* mitk::FiberBundleXReader::VERSION_STRING = "0.1" ; + +namespace mitk +{ + + void FiberBundleXReader + ::GenerateData() + { + MITK_INFO << "Reading fiber bundle"; + if ( ( ! m_OutputCache ) ) + { + Superclass::SetNumberOfRequiredOutputs(0); + this->GenerateOutputInformation(); + } + + if (!m_OutputCache) + { + itkWarningMacro("Tree cache is empty!"); + } + + + Superclass::SetNumberOfRequiredOutputs(1); + Superclass::SetNthOutput(0, m_OutputCache.GetPointer()); + } + + void FiberBundleXReader::GenerateOutputInformation() + { + m_OutputCache = OutputType::New(); + +// std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); +// ext = itksys::SystemTools::LowerCase(ext); + + if ( m_FileName == "") + { + + } +// else if (ext == ".fib") +// { +// try +// { +// TiXmlDocument doc( m_FileName ); +// doc.LoadFile(); +// +// TiXmlHandle hDoc(&doc); +// TiXmlElement* pElem; +// TiXmlHandle hRoot(0); +// +// pElem = hDoc.FirstChildElement().Element(); +// +// // save this for later +// hRoot = TiXmlHandle(pElem); +// +// pElem = hRoot.FirstChildElement(FiberBundleXReader::XML_GEOMETRY).Element(); +// +// // read geometry +// mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); +// +// // read origin +// mitk::Point3D origin; +// double temp = 0; +// pElem->Attribute(FiberBundleXReader::XML_ORIGIN_X, &temp); +// origin[0] = temp; +// pElem->Attribute(FiberBundleXReader::XML_ORIGIN_Y, &temp); +// origin[1] = temp; +// pElem->Attribute(FiberBundleXReader::XML_ORIGIN_Z, &temp); +// origin[2] = temp; +// geometry->SetOrigin(origin); +// +// // read spacing +// float spacing[3]; +// pElem->Attribute(FiberBundleXReader::XML_SPACING_X, &temp); +// spacing[0] = temp; +// pElem->Attribute(FiberBundleXReader::XML_SPACING_Y, &temp); +// spacing[1] = temp; +// pElem->Attribute(FiberBundleXReader::XML_SPACING_Z, &temp); +// spacing[2] = temp; +// geometry->SetSpacing(spacing); +// +// // read transform +// vtkMatrix4x4* m = vtkMatrix4x4::New(); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_XX, &temp); +// m->SetElement(0,0,temp); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_XY, &temp); +// m->SetElement(1,0,temp); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_XZ, &temp); +// m->SetElement(2,0,temp); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_YX, &temp); +// m->SetElement(0,1,temp); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_YY, &temp); +// m->SetElement(1,1,temp); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_YZ, &temp); +// m->SetElement(2,1,temp); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_ZX, &temp); +// m->SetElement(0,2,temp); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_ZY, &temp); +// m->SetElement(1,2,temp); +// pElem->Attribute(FiberBundleXReader::XML_MATRIX_ZZ, &temp); +// m->SetElement(2,2,temp); +// +// m->SetElement(0,3,origin[0]); +// m->SetElement(1,3,origin[1]); +// m->SetElement(2,3,origin[2]); +// m->SetElement(3,3,1); +// geometry->SetIndexToWorldTransformByVtkMatrix(m); +// +// // read bounds +// float bounds[] = {0, 0, 0, 0, 0, 0}; +// pElem->Attribute(FiberBundleXReader::XML_SIZE_X, &temp); +// bounds[1] = temp; +// pElem->Attribute(FiberBundleXReader::XML_SIZE_Y, &temp); +// bounds[3] = temp; +// pElem->Attribute(FiberBundleXReader::XML_SIZE_Z, &temp); +// bounds[5] = temp; +// geometry->SetFloatBounds(bounds); +// +// // read bounds +// float bounds2[] = {0, 0, 0}; +// bounds2[0] = bounds[1]; +// bounds2[1] = bounds[3]; +// bounds2[2] = bounds[5]; +// m_OutputCache->SetBounds(bounds2); +// +// geometry->SetImageGeometry(true); +// m_OutputCache->SetGeometry(geometry); +// +// // generate tract container +// ContainerType::Pointer tractContainer = ContainerType::New(); +// +// int fiberID = 0; +// pElem = hRoot.FirstChildElement(FiberBundleXReader::XML_FIBER_BUNDLE).FirstChild().Element(); +// for( pElem; pElem; pElem=pElem->NextSiblingElement()) +// { +// TiXmlElement* pElem2 = pElem->FirstChildElement(); +// ContainerTractType::Pointer tract = ContainerTractType::New(); +// for( pElem2; pElem2; pElem2=pElem2->NextSiblingElement()) +// { +// ContainerPointType point; +// pElem2->Attribute(FiberBundleXReader::XML_POS_X, &temp); +// point[0] = temp; +// pElem2->Attribute(FiberBundleXReader::XML_POS_Y, &temp); +// point[1] = temp; +// pElem2->Attribute(FiberBundleXReader::XML_POS_Z, &temp); +// point[2] = temp; +// +// tract->InsertElement(tract->Size(), point); +// +// } +// pElem->Attribute(FiberBundleXReader::XML_ID, &fiberID); +// tractContainer->CreateIndex(fiberID); +// tractContainer->SetElement(fiberID, tract); +// +// } +// m_OutputCache->addTractContainer(tractContainer); +// m_OutputCache->initFiberGroup(); +// +// MITK_INFO << "Fiber bundle read"; +// } +// catch(...) +// { +// MITK_INFO << "Could not read file "; +// } +// } +// else if (ext == ".vfib") +// { +// // generate tract container +// ContainerType::Pointer tractContainer = ContainerType::New(); +// mitk::Geometry3D::Pointer geometry = mitk::Geometry3D::New(); +// +// ///We create a Generic Reader to test de .vtk/ +// vtkDataReader *chooser=vtkDataReader::New(); +// chooser->SetFileName(m_FileName.c_str() ); +// if( chooser->IsFilePolyData()) +// { +// vtkPolyDataReader *reader = vtkPolyDataReader::New(); +// reader->SetFileName( m_FileName.c_str() ); +// reader->Update(); +// +// if ( reader->GetOutput() != NULL ) +// { +// vtkPolyData* output = reader->GetOutput(); +// output->ComputeBounds(); +// double bounds[3]; +// output->GetBounds(bounds); +// double center[3]; +// output->GetCenter(center); +// Point3D origin; +// origin.SetElement(0, -center[0]); +// origin.SetElement(1, -center[1]); +// origin.SetElement(2, -center[2]); +// MITK_INFO << origin; +// +// mitk::Surface::Pointer surf = mitk::Surface::New(); +// surf->SetVtkPolyData(output); +// mitk::Geometry3D* geom = surf->GetGeometry(); +// //geom->SetOrigin(origin); +// geom->SetImageGeometry(true); +// m_OutputCache->SetBounds(bounds); +// m_OutputCache->SetGeometry(geom); +// vtkCellArray* cells = output->GetLines(); +// +// cells->InitTraversal(); +// +// for (int i=0; iGetNumberOfCells(); i++) +// { +// ContainerTractType::Pointer tract = ContainerTractType::New(); +// vtkCell* cell = output->GetCell(i); +// int p = cell->GetNumberOfPoints(); +// vtkPoints* points = cell->GetPoints(); +// for (int j=0; jGetPoint(j, p); +// ContainerPointType point; +// point[0] = p[0]; +// point[1] = p[1]; +// point[2] = p[2]; +// tract->InsertElement(tract->Size(), point); +// } +// tractContainer->InsertElement(i, tract); +// } +// } +// reader->Delete(); +// } +// chooser->Delete(); +// +// m_OutputCache->addTractContainer(tractContainer); +// m_OutputCache->initFiberGroup(); +// MITK_INFO << "Fiber bundle read"; +// } + } + + void FiberBundleXReader::Update() + { + this->GenerateData(); + } + + const char* FiberBundleXReader + ::GetFileName() const + { + return m_FileName.c_str(); + } + + + void FiberBundleXReader + ::SetFileName(const char* aFileName) + { + m_FileName = aFileName; + } + + + const char* FiberBundleXReader + ::GetFilePrefix() const + { + return m_FilePrefix.c_str(); + } + + + void FiberBundleXReader + ::SetFilePrefix(const char* aFilePrefix) + { + m_FilePrefix = aFilePrefix; + } + + + 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); + + + return false; + } + +} //namespace MITK diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXReader.h b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXReader.h new file mode 100644 index 0000000000..e2a5c10ba5 --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXReader.h @@ -0,0 +1,143 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ +Version: $Revision: 18127 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef __mitkFiberBundleXReader_h +#define __mitkFiberBundleXReader_h + +#include "mitkCommon.h" +#include "itkVectorContainer.h" +#include "mitkFileReader.h" +#include "mitkFiberBundleX.h" +#include "itkSlowPolyLineParametricPath.h" + +//NOTE>umbenennen in FiberBundleXSource + +namespace mitk +{ + + /** \brief + */ + + class FiberBundleXReader : public FileReader, public BaseProcess + { + public: + + /** Types for the standardized TractContainer **/ + /* direct linked includes of mitkFiberBundleX DataStructure */ + + typedef mitk::FiberBundleX OutputType; + + mitkClassMacro( FiberBundleXReader, BaseProcess ); + itkNewMacro(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); + +// itkGetMacro(GroupFiberBundleX, FiberGroupType::Pointer); +// itkGetMacro(TractContainer, ContainerType::Pointer); + + virtual void Update(); + + + static const char* XML_GEOMETRY; + + static const char* XML_MATRIX_XX; + + static const char* XML_MATRIX_XY; + + static const char* XML_MATRIX_XZ; + + static const char* XML_MATRIX_YX; + + static const char* XML_MATRIX_YY; + + static const char* XML_MATRIX_YZ; + + static const char* XML_MATRIX_ZX; + + static const char* XML_MATRIX_ZY; + + static const char* XML_MATRIX_ZZ; + + static const char* XML_ORIGIN_X; + + static const char* XML_ORIGIN_Y; + + static const char* XML_ORIGIN_Z; + + static const char* XML_SPACING_X; + + static const char* XML_SPACING_Y; + + static const char* XML_SPACING_Z; + + static const char* XML_SIZE_X; + + static const char* XML_SIZE_Y; + + static const char* XML_SIZE_Z; + + static const char* XML_FIBER_BUNDLE; + + static const char* XML_FIBER; + + static const char* XML_PARTICLE; + + static const char* XML_ID; + + static const char* XML_POS_X; + + static const char* XML_POS_Y; + + static const char* XML_POS_Z; + + static const char* VERSION_STRING; + + static const char* XML_FIBER_BUNDLE_FILE; + + static const char* XML_FILE_VERSION; + + static const char* XML_NUM_FIBERS; + + static const char* XML_NUM_PARTICLES; + + 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; + + + private: + void operator=(const Self&); //purposely not implemented + }; + +} //namespace MITK + +#endif // __mitkFiberBundleXReader_h diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSerializer.cpp b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSerializer.cpp new file mode 100644 index 0000000000..d6fcb8896d --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSerializer.cpp @@ -0,0 +1,75 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "mitkFiberBundleXSerializer.h" +#include "mitkFiberBundleX.h" +#include "mitkFiberBundleXWriter.h" + +#include + + +MITK_REGISTER_SERIALIZER(FiberBundleXSerializer) + + +mitk::FiberBundleXSerializer::FiberBundleXSerializer() +{ +} + + +mitk::FiberBundleXSerializer::~FiberBundleXSerializer() +{ +} + + +std::string mitk::FiberBundleXSerializer::Serialize() +{ + const FiberBundleX* fb = dynamic_cast( m_Data.GetPointer() ); + if (fb == NULL) + { + MITK_ERROR << " Object at " << (const void*) this->m_Data + << " is not an mitk::FiberBundleX. Cannot serialize as FiberBundleX."; + return ""; + } + + std::string filename( this->GetUniqueFilenameInWorkingDirectory() ); + filename += "_"; + filename += m_FilenameHint; + filename += ".fib"; + + std::string fullname(m_WorkingDirectory); + fullname += "/"; + fullname += itksys::SystemTools::ConvertToOutputPath(filename.c_str()); + + try + { + FiberBundleXWriter::Pointer writer = FiberBundleXWriter::New(); + writer->SetFileName(fullname); + writer->SetInputFiberBundleX(const_cast(fb)); + 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/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSerializer.h b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSerializer.h new file mode 100644 index 0000000000..48521f2421 --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSerializer.h @@ -0,0 +1,40 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date$ +Version: $Revision: 1.12 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef mitkFiberBundleXSerializer_h_included +#define mitkFiberBundleXSerializer_h_included + +#include "MitkDiffusionImagingExports.h" +#include "mitkBaseDataSerializer.h" + +namespace mitk +{ +/** + \brief Serializes mitk::Surface for mitk::SceneIO +*/ +class MitkDiffusionImaging_EXPORT FiberBundleXSerializer : public BaseDataSerializer +{ + public: + mitkClassMacro( FiberBundleXSerializer, BaseDataSerializer ); + itkNewMacro(Self); + virtual std::string Serialize(); + protected: + FiberBundleXSerializer(); + virtual ~FiberBundleXSerializer(); +}; +} // namespace +#endif diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSource.cpp b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSource.cpp new file mode 100644 index 0000000000..0c780e249f --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSource.cpp @@ -0,0 +1,35 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12 Mai 2009) $ +Version: $Revision: 17179 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + + +#include "mitkQBallImageSource.h" + + +mitk::QBallImageSource::QBallImageSource() +{ + // Create the output. We use static_cast<> here because we know the default + // output must be of type TOutputImage + OutputImageType::Pointer output + = static_cast(this->MakeOutput(0).GetPointer()); + Superclass::SetNumberOfRequiredOutputs(1); + Superclass::SetNthOutput(0, output.GetPointer()); +} + +mitk::QBallImageSource::DataObjectPointer mitk::QBallImageSource::MakeOutput( unsigned int /*idx*/ ) +{ + return static_cast(OutputImageType::New().GetPointer()); +} diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSource.h b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSource.h new file mode 100644 index 0000000000..ce50970b88 --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXSource.h @@ -0,0 +1,52 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12 Mai 2009) $ +Version: $Revision: 17179 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + + +#ifndef QBallImageSource_H_HEADER_INCLUDED_C1E7D6EC +#define QBallImageSource_H_HEADER_INCLUDED_C1E7D6EC + +#include "mitkImageSource.h" +#include "mitkQBallImage.h" + +//NOTE>umbenennen .. ableiten von DataSource + + +namespace mitk { + +class QBallImageSource : public ImageSource +{ +public: + + typedef mitk::QBallImage OutputImageType; + typedef OutputImageType::Pointer OutputImagePointer; + typedef SlicedData::RegionType OutputImageRegionType; + typedef itk::DataObject::Pointer DataObjectPointer; + + mitkClassMacro(QBallImageSource,ImageSource); + itkNewMacro(Self); + + virtual DataObjectPointer MakeOutput(unsigned int idx); + +protected: + QBallImageSource(); + virtual ~QBallImageSource() {} + +}; + +} // namespace mitk + +#endif /* QBallImageSource_H_HEADER_INCLUDED_C1E7D6EC */ diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriter.cpp b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriter.cpp new file mode 100644 index 0000000000..c6d31cad5d --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriter.cpp @@ -0,0 +1,227 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2008-12-10 18:05:13 +0100 (Mi, 10 Dez 2008) $ +Version: $Revision: 15922 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "mitkFiberBundleXWriter.h" +#include + +const char* mitk::FiberBundleXWriter::XML_GEOMETRY = "geometry"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_XX = "xx"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_XY = "xy"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_XZ = "xz"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_YX = "yx"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_YY = "yy"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_YZ = "yz"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_ZX = "zx"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_ZY = "zy"; + +const char* mitk::FiberBundleXWriter::XML_MATRIX_ZZ = "zz"; + +const char* mitk::FiberBundleXWriter::XML_ORIGIN_X = "origin_x"; + +const char* mitk::FiberBundleXWriter::XML_ORIGIN_Y = "origin_y"; + +const char* mitk::FiberBundleXWriter::XML_ORIGIN_Z = "origin_z"; + +const char* mitk::FiberBundleXWriter::XML_SPACING_X = "spacing_x"; + +const char* mitk::FiberBundleXWriter::XML_SPACING_Y = "spacing_y"; + +const char* mitk::FiberBundleXWriter::XML_SPACING_Z = "spacing_z"; + +const char* mitk::FiberBundleXWriter::XML_SIZE_X = "size_x"; + +const char* mitk::FiberBundleXWriter::XML_SIZE_Y = "size_y"; + +const char* mitk::FiberBundleXWriter::XML_SIZE_Z = "size_z"; + +const char* mitk::FiberBundleXWriter::XML_FIBER_BUNDLE = "fiber_bundle"; + +const char* mitk::FiberBundleXWriter::XML_FIBER = "fiber"; + +const char* mitk::FiberBundleXWriter::XML_PARTICLE = "particle"; + +const char* mitk::FiberBundleXWriter::XML_ID = "id"; + +const char* mitk::FiberBundleXWriter::XML_POS_X = "pos_x"; + +const char* mitk::FiberBundleXWriter::XML_POS_Y = "pos_y"; + +const char* mitk::FiberBundleXWriter::XML_POS_Z = "pos_z"; + +const char* mitk::FiberBundleXWriter::XML_NUM_FIBERS = "num_fibers"; + +const char* mitk::FiberBundleXWriter::XML_NUM_PARTICLES = "num_particles"; + +const char* mitk::FiberBundleXWriter::XML_FIBER_BUNDLE_FILE = "fiber_bundle_file" ; + +const char* mitk::FiberBundleXWriter::XML_FILE_VERSION = "file_version" ; + +const char* mitk::FiberBundleXWriter::VERSION_STRING = "0.1" ; + +const char* mitk::FiberBundleXWriter::ASCII_FILE = "ascii_file" ; + +const char* mitk::FiberBundleXWriter::FILE_NAME = "file_name" ; + +mitk::FiberBundleXWriter::FiberBundleXWriter() + : m_FileName(""), m_FilePrefix(""), m_FilePattern(""), m_Success(false) +{ + this->SetNumberOfRequiredInputs( 1 ); +} + + +mitk::FiberBundleXWriter::~FiberBundleXWriter() +{} + + +void mitk::FiberBundleXWriter::GenerateData() +{ + MITK_INFO << "Writing fiber bundle"; + m_Success = false; + InputType* input = this->GetInput(); + if (input == NULL) + { + itkWarningMacro(<<"Sorry, input to FiberBundleXWriter is NULL!"); + return; + } + if ( m_FileName == "" ) + { + itkWarningMacro( << "Sorry, filename has not been set!" ); + return ; + } + +// std::string ext = itksys::SystemTools::GetFilenameLastExtension(m_FileName); +// ext = itksys::SystemTools::LowerCase(ext); + +// if (ext == ".fib") +// { +// /* direct linked includes of mitkFiberBundleX DataStructure */ +// +// mitk::Geometry3D* geometry = input->GetGeometry(); +// +// TiXmlDocument documentXML; +// TiXmlDeclaration* declXML = new TiXmlDeclaration( "1.0", "", "" ); // TODO what to write here? encoding? etc.... +// documentXML.LinkEndChild( declXML ); +// +// TiXmlElement* mainXML = new TiXmlElement(mitk::FiberBundleXWriter::XML_FIBER_BUNDLE_FILE); +// mainXML->SetAttribute(mitk::FiberBundleXWriter::XML_FILE_VERSION, mitk::FiberBundleXWriter::VERSION_STRING); +// documentXML.LinkEndChild(mainXML); +// +// TiXmlElement* geometryXML = new TiXmlElement(mitk::FiberBundleXWriter::XML_GEOMETRY); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_XX, geometry->GetMatrixColumn(0)[0]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_XY, geometry->GetMatrixColumn(0)[1]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_XZ, geometry->GetMatrixColumn(0)[2]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_YX, geometry->GetMatrixColumn(1)[0]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_YY, geometry->GetMatrixColumn(1)[1]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_YZ, geometry->GetMatrixColumn(1)[2]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_ZX, geometry->GetMatrixColumn(2)[0]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_ZY, geometry->GetMatrixColumn(2)[1]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_MATRIX_ZZ, geometry->GetMatrixColumn(2)[2]); +// +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_ORIGIN_X, geometry->GetOrigin()[0]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_ORIGIN_Y, geometry->GetOrigin()[1]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_ORIGIN_Z, geometry->GetOrigin()[2]); +// +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_SPACING_X, geometry->GetSpacing()[0]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_SPACING_Y, geometry->GetSpacing()[1]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_SPACING_Z, geometry->GetSpacing()[2]); +// +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_SIZE_X, input->GetBounds()[0]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_SIZE_Y, input->GetBounds()[1]); +// geometryXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_SIZE_Z, input->GetBounds()[2]); +// +// mainXML->LinkEndChild(geometryXML); +// +// TiXmlElement* FiberBundleXXML = new TiXmlElement(mitk::FiberBundleXWriter::XML_FIBER_BUNDLE); +// FiberBundleXXML->SetAttribute(mitk::FiberBundleXWriter::XML_NUM_FIBERS, tractContainer->size()); +// int numParticles = 0; +// for (int i=0; iSize(); i++) +// { +// ContainerTractType::Pointer tract = tractContainer->GetElement(i); +// TiXmlElement* fiberXML = new TiXmlElement(mitk::FiberBundleXWriter::XML_FIBER); +// fiberXML->SetAttribute(mitk::FiberBundleXWriter::XML_ID, i); +// fiberXML->SetAttribute(mitk::FiberBundleXWriter::XML_NUM_PARTICLES, tract->Size()); +// numParticles += tract->Size(); +// for (int j=0; jSize(); j++) +// { +// TiXmlElement* particleXML = new TiXmlElement(mitk::FiberBundleXWriter::XML_PARTICLE); +// ContainerPointType p = tract->GetElement(j); +// particleXML->SetAttribute(mitk::FiberBundleXWriter::XML_ID, j); +// particleXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_POS_X, p[0]); +// particleXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_POS_Y, p[1]); +// particleXML->SetDoubleAttribute(mitk::FiberBundleXWriter::XML_POS_Z, p[2]); +// fiberXML->LinkEndChild(particleXML); +// } +// FiberBundleXXML->LinkEndChild(fiberXML); +// } +// FiberBundleXXML->SetAttribute(mitk::FiberBundleXWriter::XML_NUM_PARTICLES, numParticles); +// mainXML->LinkEndChild(FiberBundleXXML); +// +// documentXML.SaveFile( m_FileName ); +// +// m_Success = true; +// +// MITK_INFO << "Fiber bundle written"; +// +// }else if (ext == ".vfib" || ext == ".vtk") { +// vtkPolyDataWriter* writer = vtkPolyDataWriter::New(); +// writer->SetInput(input->GeneratePolydata()); +// writer->SetFileName(m_FileName.c_str()); +// writer->SetFileTypeToASCII(); +// writer->Write(); +// +// m_Success = true; +// MITK_INFO << "Fiber bundle written as polydata"; +// } + +} + + +void mitk::FiberBundleXWriter::SetInputFiberBundleX( InputType* diffVolumes ) +{ + this->ProcessObject::SetNthInput( 0, diffVolumes ); +} + + +mitk::FiberBundleX* mitk::FiberBundleXWriter::GetInput() +{ + if ( this->GetNumberOfInputs() < 1 ) + { + return NULL; + } + else + { + return dynamic_cast ( this->ProcessObject::GetInput( 0 ) ); + } +} + + +std::vector mitk::FiberBundleXWriter::GetPossibleFileExtensions() +{ + std::vector possibleFileExtensions; + possibleFileExtensions.push_back(".fib"); + possibleFileExtensions.push_back(".vfib"); + possibleFileExtensions.push_back(".vtk"); + return possibleFileExtensions; +} diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriter.h b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriter.h new file mode 100644 index 0000000000..84a248080b --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriter.h @@ -0,0 +1,216 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2008-08-27 17:18:46 +0200 (Mi, 27 Aug 2008) $ +Version: $Revision: 15096 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef __mitkFiberBundleXWriter_h +#define __mitkFiberBundleXWriter_h + +#include +#include +#include "mitkFiberBundleX.h" +#include + + +namespace mitk +{ + +/** + * Writes fiber bundles to a file + * @ingroup Process + */ +class FiberBundleXWriter : public mitk::FileWriterWithInformation +{ +public: + + mitkClassMacro( FiberBundleXWriter, mitk::FileWriterWithInformation ); + + //mitkWriterMacro; + + virtual void Write() + { + if ( this->GetInput() == NULL ) + { + itkExceptionMacro(<<"Write:Please specify an input!"); + return; + } + /* Fill in image information.*/ + this->UpdateOutputInformation(); + (*(this->GetInputs().begin()))->SetRequestedRegionToLargestPossibleRegion(); + this->PropagateRequestedRegion(NULL); + this->UpdateOutputData(NULL); + } + + virtual void Update() + { + Write(); + } + + itkNewMacro( Self ); + + typedef mitk::FiberBundleX InputType; + + /** + * 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 input object for the filter. + * @param input the diffusion volumes to write to file. + */ + void SetInputFiberBundleX( InputType* input ); + + /** + * @returns the 0'th input object of the filter. + */ + InputType* GetInput(); + + /** + * Returns false if an error happened during writing + */ + itkGetMacro( Success, bool ); + + /** + * @return possible file extensions for the data type associated with the writer + */ + virtual std::vector GetPossibleFileExtensions(); + + // FileWriterWithInformation methods + virtual const char * GetDefaultFilename() { return "FiberBundleX.fib"; } + virtual const char * GetFileDialogPattern() { return "Fiber Bundle (*.fib *.vfib *.vtk)"; } + virtual const char * GetDefaultExtension() { return ".fib"; } + virtual bool CanWriteBaseDataType(BaseData::Pointer data) { return (dynamic_cast(data.GetPointer()) != NULL); }; + virtual void DoWrite(BaseData::Pointer data) { + if (CanWriteBaseDataType(data)) { + this->SetInputFiberBundleX(dynamic_cast(data.GetPointer())); + this->Update(); + } + }; + + static const char* XML_GEOMETRY; + + static const char* XML_MATRIX_XX; + + static const char* XML_MATRIX_XY; + + static const char* XML_MATRIX_XZ; + + static const char* XML_MATRIX_YX; + + static const char* XML_MATRIX_YY; + + static const char* XML_MATRIX_YZ; + + static const char* XML_MATRIX_ZX; + + static const char* XML_MATRIX_ZY; + + static const char* XML_MATRIX_ZZ; + + static const char* XML_ORIGIN_X; + + static const char* XML_ORIGIN_Y; + + static const char* XML_ORIGIN_Z; + + static const char* XML_SPACING_X; + + static const char* XML_SPACING_Y; + + static const char* XML_SPACING_Z; + + static const char* XML_SIZE_X; + + static const char* XML_SIZE_Y; + + static const char* XML_SIZE_Z; + + static const char* XML_FIBER_BUNDLE; + + static const char* XML_FIBER; + + static const char* XML_PARTICLE; + + static const char* XML_ID; + + static const char* XML_POS_X; + + static const char* XML_POS_Y; + + static const char* XML_POS_Z; + + static const char* VERSION_STRING; + + static const char* XML_FIBER_BUNDLE_FILE; + + static const char* XML_FILE_VERSION; + + static const char* XML_NUM_FIBERS; + + static const char* XML_NUM_PARTICLES; + + static const char* ASCII_FILE; + + static const char* FILE_NAME; + +protected: + + FiberBundleXWriter(); + + virtual ~FiberBundleXWriter(); + + virtual void GenerateData(); + + std::string m_FileName; + + std::string m_FilePrefix; + + std::string m_FilePattern; + + bool m_Success; + +}; + + +} // end of namespace mitk + +#endif //__mitkFiberBundleXWriter_h diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriterFactory.cpp b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriterFactory.cpp new file mode 100644 index 0000000000..6ed861cec4 --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriterFactory.cpp @@ -0,0 +1,76 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2007-12-11 14:46:19 +0100 (Di, 11 Dez 2007) $ +Version: $Revision: 11215 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "mitkFiberBundleXWriterFactory.h" + +#include "itkCreateObjectFunction.h" +#include "itkVersion.h" + +#include "mitkFiberBundleXWriter.h" + +namespace mitk +{ + +template +class CreateFiberBundleXWriter : public itk::CreateObjectFunctionBase +{ +public: + + /** Standard class typedefs. */ + typedef CreateFiberBundleXWriter 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: + CreateFiberBundleXWriter() {} + ~CreateFiberBundleXWriter() {} + +private: + CreateFiberBundleXWriter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented +}; + +FiberBundleXWriterFactory::FiberBundleXWriterFactory() +{ + this->RegisterOverride("IOWriter", + "FiberBundleXWriter", + "FiberBundleX Writer", + 1, + mitk::CreateFiberBundleXWriter< mitk::FiberBundleXWriter >::New()); +} + +FiberBundleXWriterFactory::~FiberBundleXWriterFactory() +{ +} + +const char* FiberBundleXWriterFactory::GetITKSourceVersion() const +{ + return ITK_SOURCE_VERSION; +} + +const char* FiberBundleXWriterFactory::GetDescription() const +{ + return "FiberBundleXWriterFactory"; +} + +} // end namespace mitk diff --git a/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriterFactory.h b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriterFactory.h new file mode 100644 index 0000000000..b27282ea90 --- /dev/null +++ b/Modules/DiffusionImaging/IODataStructures/FiberBundleX/mitkFiberBundleXWriterFactory.h @@ -0,0 +1,68 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-05-13 18:06:46 +0200 (Mi, 13 Mai 2009) $ +Version: $Revision: 11215 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef FIBERBUNDLEX_WRITERFACTORY_H_HEADER_INCLUDED +#define FIBERBUNDLEX_WRITERFACTORY_H_HEADER_INCLUDED + +#include "itkObjectFactoryBase.h" +#include "mitkBaseData.h" +#include "MitkDiffusionImagingExports.h" + +namespace mitk +{ + +class MitkDiffusionImaging_EXPORT FiberBundleXWriterFactory : public itk::ObjectFactoryBase +{ +public: + + mitkClassMacro( mitk::FiberBundleXWriterFactory, 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 */ + static void RegisterOneFactory(void) + { + static bool IsRegistered = false; + if ( !IsRegistered ) + { + FiberBundleXWriterFactory::Pointer ugVtkWriterFactory = FiberBundleXWriterFactory::New(); + ObjectFactoryBase::RegisterFactory( ugVtkWriterFactory ); + IsRegistered = true; + } + } + +protected: + FiberBundleXWriterFactory(); + ~FiberBundleXWriterFactory(); + +private: + FiberBundleXWriterFactory(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + +}; + +} // end namespace mitk + +#endif // FiberBundleX_WRITERFACTORY_H_HEADER_INCLUDED + + + diff --git a/Modules/DiffusionImaging/IODataStructures/mitkDiffusionImagingObjectFactory.cpp b/Modules/DiffusionImaging/IODataStructures/mitkDiffusionImagingObjectFactory.cpp index f948f7a89a..fc6a4739ac 100644 --- a/Modules/DiffusionImaging/IODataStructures/mitkDiffusionImagingObjectFactory.cpp +++ b/Modules/DiffusionImaging/IODataStructures/mitkDiffusionImagingObjectFactory.cpp @@ -1,280 +1,305 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-06-18 15:59:04 +0200 (Do, 18 Jun 2009) $ Version: $Revision: 16916 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkDiffusionImagingObjectFactory.h" #include "mitkProperties.h" #include "mitkBaseRenderer.h" #include "mitkDataNode.h" #include "mitkNrrdDiffusionImageIOFactory.h" #include "mitkNrrdDiffusionImageWriterFactory.h" #include "mitkNrrdDiffusionImageWriter.h" #include "mitkDiffusionImage.h" #include "mitkNrrdQBallImageIOFactory.h" #include "mitkNrrdQBallImageWriterFactory.h" #include "mitkNrrdQBallImageWriter.h" #include "mitkNrrdTensorImageIOFactory.h" #include "mitkNrrdTensorImageWriterFactory.h" #include "mitkNrrdTensorImageWriter.h" #include "mitkCompositeMapper.h" #include "mitkDiffusionImageMapper.h" #include "mitkGPUVolumeMapper3D.h" #include "mitkVolumeDataVtkMapper3D.h" +//====depricated fiberstructure===== #include "mitkFiberBundle.h" #include "mitkFiberBundleMapper3D.h" - #include "mitkFiberBundleIOFactory.h" #include "mitkFiberBundleWriterFactory.h" #include "mitkFiberBundleWriter.h" +//================================== + +//modernized fiberbundle datastrucutre +#include "mitkFiberBundleX.h" +#include "mitkFiberBundleXIOFactory.h" +#include "mitkFiberBundleXWriterFactory.h" +#include "mitkFiberBundleXWriter.h" +#include "mitkFiberBundleXMapper3D.h" #include "mitkNrrdTbssImageIOFactory.h" #include "mitkNrrdTbssImageWriterFactory.h" #include "mitkNrrdTbssImageWriter.h" typedef short DiffusionPixelType; typedef char TbssRoiPixelType; typedef mitk::DiffusionImage DiffusionImageShort; typedef std::multimap MultimapType; mitk::DiffusionImagingObjectFactory::DiffusionImagingObjectFactory(bool /*registerSelf*/) :CoreObjectFactoryBase() { static bool alreadyDone = false; if (!alreadyDone) { MITK_INFO << "DiffusionImagingObjectFactory c'tor" << std::endl; RegisterIOFactories(); mitk::NrrdDiffusionImageIOFactory::RegisterOneFactory(); mitk::NrrdQBallImageIOFactory::RegisterOneFactory(); mitk::NrrdTensorImageIOFactory::RegisterOneFactory(); mitk::FiberBundleIOFactory::RegisterOneFactory(); mitk::NrrdTbssImageIOFactory::RegisterOneFactory(); - + mitk::FiberBundleXIOFactory::RegisterOneFactory(); //modernized + + mitk::NrrdDiffusionImageWriterFactory::RegisterOneFactory(); mitk::NrrdQBallImageWriterFactory::RegisterOneFactory(); mitk::NrrdTensorImageWriterFactory::RegisterOneFactory(); mitk::FiberBundleWriterFactory::RegisterOneFactory(); mitk::NrrdTbssImageWriterFactory::RegisterOneFactory(); + mitk::FiberBundleXWriterFactory::RegisterOneFactory();//modernized m_FileWriters.push_back( NrrdDiffusionImageWriter::New().GetPointer() ); m_FileWriters.push_back( NrrdQBallImageWriter::New().GetPointer() ); m_FileWriters.push_back( NrrdTensorImageWriter::New().GetPointer() ); m_FileWriters.push_back( mitk::FiberBundleWriter::New().GetPointer() ); m_FileWriters.push_back( NrrdTbssImageWriter::New().GetPointer() ); - + m_FileWriters.push_back( mitk::FiberBundleXWriter::New().GetPointer() );//modernized + mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory(this); CreateFileExtensionsMap(); alreadyDone = true; } } mitk::Mapper::Pointer mitk::DiffusionImagingObjectFactory::CreateMapper(mitk::DataNode* node, MapperSlotId id) { mitk::Mapper::Pointer newMapper=NULL; if ( id == mitk::BaseRenderer::Standard2D ) { std::string classname("QBallImage"); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::CompositeMapper::New(); newMapper->SetDataNode(node); node->SetMapper(3, ((CompositeMapper*)newMapper.GetPointer())->GetImageMapper()); } classname = "TensorImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::CompositeMapper::New(); newMapper->SetDataNode(node); node->SetMapper(3, ((CompositeMapper*)newMapper.GetPointer())->GetImageMapper()); } classname = "DiffusionImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::DiffusionImageMapper::New(); newMapper->SetDataNode(node); } mitk::Mapper::Pointer newMapper=NULL; classname = "TbssImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::ImageMapperGL2D::New(); newMapper->SetDataNode(node); } } else if ( id == mitk::BaseRenderer::Standard3D ) { std::string classname("QBallImage"); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::GPUVolumeMapper3D::New(); newMapper->SetDataNode(node); } classname = "TensorImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::GPUVolumeMapper3D::New(); newMapper->SetDataNode(node); } classname = "DiffusionImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::GPUVolumeMapper3D::New(); newMapper->SetDataNode(node); } classname = "FiberBundle"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::FiberBundleMapper3D::New(); newMapper->SetDataNode(node); } + + classname = "FiberBundleX"; + if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) + { + newMapper = mitk::FiberBundleXMapper3D::New(); + newMapper->SetDataNode(node); + } classname = "TbssImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { newMapper = mitk::VolumeDataVtkMapper3D::New(); newMapper->SetDataNode(node); } } return newMapper; } void mitk::DiffusionImagingObjectFactory::SetDefaultProperties(mitk::DataNode* node) { std::string classname = "QBallImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::CompositeMapper::SetDefaultProperties(node); mitk::GPUVolumeMapper3D::SetDefaultProperties(node); } classname = "TensorImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::CompositeMapper::SetDefaultProperties(node); mitk::GPUVolumeMapper3D::SetDefaultProperties(node); } classname = "DiffusionImage"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::DiffusionImageMapper::SetDefaultProperties(node); mitk::GPUVolumeMapper3D::SetDefaultProperties(node); } classname = "FiberBundle"; if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::FiberBundleMapper3D::SetDefaultProperties(node); } + + classname = "FiberBundleX"; + if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) + { + mitk::FiberBundleMapper3D::SetDefaultProperties(node); + } classname = "TbssImage"; std::string n = node->GetData()->GetNameOfClass(); if(node->GetData() && classname.compare(node->GetData()->GetNameOfClass())==0) { mitk::ImageMapperGL2D::SetDefaultProperties(node); mitk::VolumeDataVtkMapper3D::SetDefaultProperties(node); } } const char* mitk::DiffusionImagingObjectFactory::GetFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_FileExtensionsMap, fileExtension); return fileExtension.c_str(); }; mitk::CoreObjectFactoryBase::MultimapType mitk::DiffusionImagingObjectFactory::GetFileExtensionsMap() { return m_FileExtensionsMap; } const char* mitk::DiffusionImagingObjectFactory::GetSaveFileExtensions() { std::string fileExtension; this->CreateFileExtensions(m_SaveFileExtensionsMap, fileExtension); return fileExtension.c_str(); }; mitk::CoreObjectFactoryBase::MultimapType mitk::DiffusionImagingObjectFactory::GetSaveFileExtensionsMap() { return m_SaveFileExtensionsMap; } void mitk::DiffusionImagingObjectFactory::CreateFileExtensionsMap() { m_FileExtensionsMap.insert(std::pair("*.dwi", "Diffusion Weighted Images")); m_FileExtensionsMap.insert(std::pair("*.hdwi", "Diffusion Weighted Images")); m_FileExtensionsMap.insert(std::pair("*.nii", "Diffusion Weighted Images for FSL")); m_FileExtensionsMap.insert(std::pair("*.fsl", "Diffusion Weighted Images for FSL")); m_FileExtensionsMap.insert(std::pair("*.fslgz", "Diffusion Weighted Images for FSL")); m_FileExtensionsMap.insert(std::pair("*.qbi", "Q-Ball Images")); m_FileExtensionsMap.insert(std::pair("*.hqbi", "Q-Ball Images")); m_FileExtensionsMap.insert(std::pair("*.dti", "Tensor Images")); m_FileExtensionsMap.insert(std::pair("*.hdti", "Tensor Images")); m_FileExtensionsMap.insert(std::pair("*.fib", "Fiber Bundle")); m_FileExtensionsMap.insert(std::pair("*.vfib", "Fiber Bundle Polydata")); m_FileExtensionsMap.insert(std::pair("*.vtk", "Fiber Bundle Polydata")); m_FileExtensionsMap.insert(std::pair("*.tbss", "TBSS data")); m_SaveFileExtensionsMap.insert(std::pair("*.dwi", "Diffusion Weighted Images")); m_SaveFileExtensionsMap.insert(std::pair("*.hdwi", "Diffusion Weighted Images")); m_SaveFileExtensionsMap.insert(std::pair("*.nii", "Diffusion Weighted Images for FSL")); m_SaveFileExtensionsMap.insert(std::pair("*.fsl", "Diffusion Weighted Images for FSL")); m_SaveFileExtensionsMap.insert(std::pair("*.fslgz", "Diffusion Weighted Images for FSL")); m_SaveFileExtensionsMap.insert(std::pair("*.qbi", "Q-Ball Images")); m_SaveFileExtensionsMap.insert(std::pair("*.hqbi", "Q-Ball Images")); m_SaveFileExtensionsMap.insert(std::pair("*.dti", "Tensor Images")); m_SaveFileExtensionsMap.insert(std::pair("*.hdti", "Tensor Images")); m_SaveFileExtensionsMap.insert(std::pair("*.fib", "Fiber Bundle")); m_SaveFileExtensionsMap.insert(std::pair("*.vfib", "Fiber Bundle Polydata")); m_SaveFileExtensionsMap.insert(std::pair("*.vtk", "Fiber Bundle Polydata")); m_SaveFileExtensionsMap.insert(std::pair("*.tbss", "TBSS data")); } void mitk::DiffusionImagingObjectFactory::RegisterIOFactories() { } void RegisterDiffusionImagingObjectFactory() { static bool oneDiffusionImagingObjectFactoryRegistered = false; if ( ! oneDiffusionImagingObjectFactoryRegistered ) { MITK_INFO << "Registering DiffusionImagingObjectFactory..." << std::endl; mitk::CoreObjectFactory::GetInstance()->RegisterExtraFactory(mitk::DiffusionImagingObjectFactory::New()); oneDiffusionImagingObjectFactoryRegistered = true; } } diff --git a/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.cpp b/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.cpp new file mode 100644 index 0000000000..d92cf9c348 --- /dev/null +++ b/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.cpp @@ -0,0 +1,171 @@ +/*========================================================================= + + Program: Medical Imaging & Interaction Toolkit + Language: C++ + Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12 Mai 2009) $ + Version: $Revision: 17179 $ + + Copyright (c) German Cancer Research Center, Division of Medical and + Biological Informatics. All rights reserved. + See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + + =========================================================================*/ + + + +#include "mitkFiberBundleXMapper3D.h" + +#include +#include +#include + + +#include +#include +#include + +//not essential for mapper +#include + +mitk::FiberBundleXMapper3D::FiberBundleXMapper3D() +: m_FiberMapperGLSP(vtkSmartPointer::New()), + m_FiberMapperGLWP(vtkOpenGLPolyDataMapper::New()), + m_FiberActorSP(vtkSmartPointer::New()), + m_FiberActorWP(vtkActor::New()), + m_FiberAssembly(vtkPropAssembly::New()) +{ + +} + + +mitk::FiberBundleXMapper3D::~FiberBundleXMapper3D() +{ + m_FiberAssembly->Delete(); +} + + +const mitk::FiberBundleX* mitk::FiberBundleXMapper3D::GetInput() +{ + return static_cast ( GetData() ); +} + + +/* + This method is called once the mapper gets new input, + for UI rotation or changes in colorcoding this method is NOT called + */ +void mitk::FiberBundleXMapper3D::GenerateData() +{ + //=====timer measurement==== + QTime myTimer; + myTimer.start(); + //========================== + + mitk::FiberBundleX::Pointer FBX = dynamic_cast< mitk::FiberBundleX* > (this->GetData()); + vtkPolyData* FiberData = FBX->GetFibers(); + + m_FiberMapperGLSP->SetInput(FiberData); +// m_FiberMapperGLWP->SetInput(FiberData); + + + if ( FiberData->GetPointData()->GetNumberOfArrays() > 0 ) + { + if ( FiberData->GetPointData()->HasArray(FiberBundleX::COLORCODING_ORIENTATION_BASED) ) + { + m_FiberMapperGLSP->SelectColorArray(FiberBundleX::COLORCODING_ORIENTATION_BASED); +// m_FiberMapperGLWP->SelectColorArray(FiberBundleX::COLORCODING_ORIENTATION_BASED); + } else { +// iterate through polydata array and take the first best -but valid- array + + //===ToDo=== + //check of componentsize as well, if it is not RGB or RGBA (ie. size 3 or 4), then check if it is a scalar + // if scalar then create lookuptable for that. + } + + m_FiberMapperGLSP->ScalarVisibilityOn(); +// m_FiberMapperGLWP->ScalarVisibilityOn(); + m_FiberMapperGLSP->SetScalarModeToUsePointFieldData(); +// m_FiberMapperGLWP->SetScalarModeToUsePointFieldData(); + } + + + m_FiberActorSP->SetMapper(m_FiberMapperGLSP); +// m_FiberActorWP->SetMapper(m_FiberMapperGLWP); + + m_FiberActorSP->GetProperty()->SetOpacity(1.0); +// m_FiberActorWP->GetProperty()->SetOpacity(1.0); + + m_FiberAssembly->AddPart(m_FiberActorSP); + + //====timer measurement======== + MITK_INFO << "Execution Time GenerateData() (nmiliseconds): " << myTimer.elapsed(); + //============================= + +} + + + +void mitk::FiberBundleXMapper3D::GenerateDataForRenderer( mitk::BaseRenderer *renderer ) +{ + //ToDo do update checks +} + + +void mitk::FiberBundleXMapper3D::SetDefaultProperties(mitk::DataNode* node, mitk::BaseRenderer* renderer, bool overwrite) +{ + //MITK_INFO << "FiberBundleMapper3D SetDefault Properties(...)"; +// node->AddProperty( "DisplayChannel", mitk::IntProperty::New( true ), renderer, overwrite ); +// node->AddProperty( "LineWidth", mitk::IntProperty::New( true ), renderer, overwrite ); +// node->AddProperty( "ColorCoding", mitk::IntProperty::New( 0 ), renderer, overwrite); +// node->AddProperty( "VertexOpacity_1", mitk::BoolProperty::New( false ), renderer, overwrite); +// node->AddProperty( "Set_FA_VertexAlpha", mitk::BoolProperty::New( false ), renderer, overwrite); +// node->AddProperty( "pointSize", mitk::FloatProperty::New(0.5), renderer, overwrite); +// node->AddProperty( "setShading", mitk::IntProperty::New(1), renderer, overwrite); +// node->AddProperty( "Xmove", mitk::IntProperty::New( 0 ), renderer, overwrite); +// node->AddProperty( "Ymove", mitk::IntProperty::New( 0 ), renderer, overwrite); +// node->AddProperty( "Zmove", mitk::IntProperty::New( 0 ), renderer, overwrite); +// node->AddProperty( "RepPoints", mitk::BoolProperty::New( false ), renderer, overwrite); +// node->AddProperty( "TubeSides", mitk::IntProperty::New( 8 ), renderer, overwrite); +// node->AddProperty( "TubeRadius", mitk::FloatProperty::New( 0.15 ), renderer, overwrite); +// node->AddProperty( "TubeOpacity", mitk::FloatProperty::New( 1.0 ), renderer, overwrite); + + node->AddProperty( "pickable", mitk::BoolProperty::New( true ), renderer, overwrite); + + Superclass::SetDefaultProperties(node, renderer, overwrite); + + + +} + +vtkProp* mitk::FiberBundleXMapper3D::GetVtkProp(mitk::BaseRenderer *renderer) +{ + + return m_FiberAssembly; + +} + +void mitk::FiberBundleXMapper3D::ApplyProperties(mitk::BaseRenderer* renderer) +{ + // MITK_INFO << "FiberBundleMapper3D ApplyProperties(renderer)"; +} + +void mitk::FiberBundleXMapper3D::UpdateVtkObjects() +{ + // MITK_INFO << "FiberBundleMapper3D UpdateVtkObjects()"; + + +} + +void mitk::FiberBundleXMapper3D::SetVtkMapperImmediateModeRendering(vtkMapper *) +{ + + + +} + + + diff --git a/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.h b/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.h new file mode 100644 index 0000000000..19103ea0f1 --- /dev/null +++ b/Modules/DiffusionImaging/Rendering/mitkFiberBundleXMapper3D.h @@ -0,0 +1,85 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12 Mai 2009) $ +Version: $Revision: 17179 $ + +Copyright (c) German Cancer Research Center, Division of Medical and +Biological Informatics. All rights reserved. +See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. + +This software is distributed WITHOUT ANY WARRANTY; without even +the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + + +#ifndef FiberBundleXMapper3D_H_HEADER_INCLUDED +#define FiberBundleXMapper3D_H_HEADER_INCLUDED + +#include //?? necessary +#include +#include +#include + +#include +#include +#include + + + +class vtkPropAssembly; + + + + +namespace mitk { + + //##Documentation + //## @brief Mapper for FiberBundleX + //## @ingroup Mapper + + class MitkDiffusionImaging_EXPORT FiberBundleXMapper3D : public VtkMapper3D + { + public: + + mitkClassMacro(FiberBundleXMapper3D, VtkMapper3D); + itkNewMacro(Self); + + //========== essential implementation for 3D mapper ======== + const FiberBundleX* GetInput(); + virtual vtkProp *GetVtkProp(mitk::BaseRenderer *renderer); //looks like depricated.. should be replaced bz GetViewProp() + static void SetDefaultProperties(DataNode* node, BaseRenderer* renderer = NULL, bool overwrite = false ); + virtual void ApplyProperties(mitk::BaseRenderer* renderer); + static void SetVtkMapperImmediateModeRendering(vtkMapper *mapper); + virtual void GenerateDataForRenderer(mitk::BaseRenderer* renderer); + virtual void GenerateData(); + //========================================================= + + protected: + + FiberBundleXMapper3D(); + virtual ~FiberBundleXMapper3D(); + + void UpdateVtkObjects(); //?? + + vtkSmartPointer m_FiberMapperGLSP; + vtkOpenGLPolyDataMapper* m_FiberMapperGLWP; + + vtkSmartPointer m_FiberActorSP; + vtkActor* m_FiberActorWP; + + vtkPropAssembly* m_FiberAssembly; + + + }; + +} // end namespace mitk + + + + +#endif /* FiberBundleXMapper3D_H_HEADER_INCLUDED */ + diff --git a/Modules/DiffusionImaging/files.cmake b/Modules/DiffusionImaging/files.cmake index ad2529cc2e..817c2ad931 100644 --- a/Modules/DiffusionImaging/files.cmake +++ b/Modules/DiffusionImaging/files.cmake @@ -1,122 +1,143 @@ SET(CPP_FILES # DicomImport DicomImport/mitkDicomDiffusionImageReader.cpp DicomImport/mitkGroupDiffusionHeadersFilter.cpp DicomImport/mitkDicomDiffusionImageHeaderReader.cpp DicomImport/mitkGEDicomDiffusionImageHeaderReader.cpp DicomImport/mitkPhilipsDicomDiffusionImageHeaderReader.cpp DicomImport/mitkSiemensDicomDiffusionImageHeaderReader.cpp DicomImport/mitkSiemensMosaicDicomDiffusionImageHeaderReader.cpp # DataStructures IODataStructures/mitkDiffusionImagingObjectFactory.cpp # DataStructures -> DWI IODataStructures/DiffusionWeightedImages/mitkDiffusionImageHeaderInformation.cpp IODataStructures/DiffusionWeightedImages/mitkDiffusionImageSource.cpp IODataStructures/DiffusionWeightedImages/mitkNrrdDiffusionImageReader.cpp IODataStructures/DiffusionWeightedImages/mitkNrrdDiffusionImageWriter.cpp IODataStructures/DiffusionWeightedImages/mitkNrrdDiffusionImageIOFactory.cpp IODataStructures/DiffusionWeightedImages/mitkNrrdDiffusionImageWriterFactory.cpp IODataStructures/DiffusionWeightedImages/mitkDiffusionImageSerializer.cpp # DataStructures -> QBall IODataStructures/QBallImages/mitkQBallImageSource.cpp IODataStructures/QBallImages/mitkNrrdQBallImageReader.cpp IODataStructures/QBallImages/mitkNrrdQBallImageWriter.cpp IODataStructures/QBallImages/mitkNrrdQBallImageIOFactory.cpp IODataStructures/QBallImages/mitkNrrdQBallImageWriterFactory.cpp IODataStructures/QBallImages/mitkQBallImage.cpp IODataStructures/QBallImages/mitkQBallImageSerializer.cpp # DataStructures -> Tensor IODataStructures/TensorImages/mitkTensorImageSource.cpp IODataStructures/TensorImages/mitkNrrdTensorImageReader.cpp IODataStructures/TensorImages/mitkNrrdTensorImageWriter.cpp IODataStructures/TensorImages/mitkNrrdTensorImageIOFactory.cpp IODataStructures/TensorImages/mitkNrrdTensorImageWriterFactory.cpp IODataStructures/TensorImages/mitkTensorImage.cpp IODataStructures/TensorImages/mitkTensorImageSerializer.cpp # DataStructures -> FiberBundle IODataStructures/FiberBundle/mitkFiberBundle.cpp IODataStructures/FiberBundle/mitkFiberBundleWriter.cpp IODataStructures/FiberBundle/mitkFiberBundleReader.cpp IODataStructures/FiberBundle/mitkFiberBundleIOFactory.cpp IODataStructures/FiberBundle/mitkFiberBundleWriterFactory.cpp IODataStructures/FiberBundle/mitkFiberBundleSerializer.cpp IODataStructures/FiberBundle/mitkParticle.cpp IODataStructures/FiberBundle/mitkParticleGrid.cpp +# DataStructures -> FiberBundleX + IODataStructures/FiberBundleX/mitkFiberBundleX.cpp + IODataStructures/FiberBundleX/mitkFiberBundleXWriter.cpp + IODataStructures/FiberBundleX/mitkFiberBundleXReader.cpp + IODataStructures/FiberBundleX/mitkFiberBundleXIOFactory.cpp + IODataStructures/FiberBundleX/mitkFiberBundleXWriterFactory.cpp + IODataStructures/FiberBundleX/mitkFiberBundleXSerializer.cpp + + # DataStructures -> PlanarFigureComposite IODataStructures/PlanarFigureComposite/mitkPlanarFigureComposite.cpp # DataStructures -> Tbss IODataStructures/TbssImages/mitkTbssImageSource.cpp IODataStructures/TbssImages/mitkNrrdTbssImageReader.cpp IODataStructures/TbssImages/mitkNrrdTbssImageIOFactory.cpp IODataStructures/TbssImages/mitkTbssImage.cpp IODataStructures/TbssImages/mitkNrrdTbssImageWriter.cpp IODataStructures/TbssImages/mitkNrrdTbssImageWriterFactory.cpp # Rendering Rendering/vtkMaskedProgrammableGlyphFilter.cpp Rendering/mitkCompositeMapper.cpp Rendering/mitkVectorImageVtkGlyphMapper3D.cpp Rendering/vtkOdfSource.cxx Rendering/vtkThickPlane.cxx Rendering/mitkOdfNormalizationMethodProperty.cpp Rendering/mitkOdfScaleByProperty.cpp Rendering/mitkFiberBundleMapper3D.cpp - - # Interactions + Rendering/mitkFiberBundleXMapper3D.cpp + +# Interactions Interactions/mitkFiberBundleInteractor.cpp # Algorithms ) SET(H_FILES # Rendering Rendering/mitkDiffusionImageMapper.h Rendering/mitkOdfVtkMapper2D.h + Rendering/mitkFiberBundleMapper3D.h + Rendering/mitkFiberBundleXMapper3D.h # Reconstruction Reconstruction/itkDiffusionQballReconstructionImageFilter.h Reconstruction/mitkTeemDiffusionTensor3DReconstructionImageFilter.h Reconstruction/itkAnalyticalDiffusionQballReconstructionImageFilter.h Reconstruction/itkPointShell.h Reconstruction/itkOrientationDistributionFunction.h # IO Datastructures IODataStructures/DiffusionWeightedImages/mitkDiffusionImage.h IODataStructures/FiberBundle/itkSlowPolyLineParametricPath.h IODataStructures/TbssImages/mitkTbssImage.h + # DataStructures -> FiberBundleX + IODataStructures/FiberBundleX/mitkFiberBundleX.h + IODataStructures/FiberBundleX/mitkFiberBundleXWriter.h + IODataStructures/FiberBundleX/mitkFiberBundleXReader.h + IODataStructures/FiberBundleX/mitkFiberBundleXIOFactory.h + IODataStructures/FiberBundleX/mitkFiberBundleXWriterFactory.h + IODataStructures/FiberBundleX/mitkFiberBundleXSerializer.h + + # Tractography Tractography/itkGlobalTractographyFilter.h # Algorithms Algorithms/itkDiffusionQballGeneralizedFaImageFilter.h Algorithms/itkDiffusionQballPrepareVisualizationImageFilter.h Algorithms/itkTensorDerivedMeasurementsFilter.h Algorithms/itkBrainMaskExtractionImageFilter.h Algorithms/itkB0ImageExtractionImageFilter.h Algorithms/itkTensorImageToDiffusionImageFilter.h Algorithms/itkTensorToL2NormImageFilter.h Algorithms/itkTractsToProbabilityImageFilter.h Algorithms/itkTractsToDWIImageFilter.h Algorithms/itkTractsToFiberEndingsImageFilter.h Algorithms/itkGaussianInterpolateImageFunction.h ) SET( TOOL_FILES ) IF(WIN32) ENDIF(WIN32) #MITK_MULTIPLEX_PICTYPE( Algorithms/mitkImageRegistrationMethod-TYPE.cpp )