diff --git a/Modules/DiffusionImaging/DiffusionCore/CMakeLists.txt b/Modules/DiffusionImaging/DiffusionCore/CMakeLists.txt index b0ee596bbe..1629e3cd19 100644 --- a/Modules/DiffusionImaging/DiffusionCore/CMakeLists.txt +++ b/Modules/DiffusionImaging/DiffusionCore/CMakeLists.txt @@ -1,19 +1,19 @@ # With apple gcc 4.2.1 the following waring leads to an build error if boost is enabled if(APPLE) mitkFunctionCheckCAndCXXCompilerFlags("-Wno-error=empty-body" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() MITK_CREATE_MODULE( SUBPROJECTS MITK-DTI - INCLUDE_DIRS Algorithms Algorithms/Reconstruction Algorithms/Registration Algorithms/Reconstruction/MultishellProcessing DicomImport IODataStructures/DiffusionWeightedImages IODataStructures/QBallImages IODataStructures/TensorImages IODataStructures Rendering ${CMAKE_CURRENT_BINARY_DIR} + INCLUDE_DIRS Algorithms Algorithms/Reconstruction Algorithms/Registration Algorithms/Reconstruction/MultishellProcessing DicomImport IODataStructures/DiffusionWeightedImages IODataStructures/Properties IODataStructures/QBallImages IODataStructures/TensorImages IODataStructures Rendering ${CMAKE_CURRENT_BINARY_DIR} DEPENDS MitkMapperExt MitkPlanarFigure MitkImageExtraction MitkSceneSerializationBase MitkDICOMReader PACKAGE_DEPENDS VTK|vtkFiltersProgrammable ITK|ITKDistanceMap+ITKRegistrationCommon+ITKLabelVoting+ITKVTK Boost ITK|ITKMetricsv4+ITKRegistrationMethodsv4 WARNINGS_AS_ERRORS ) if(MSVC) mitkFunctionCheckCAndCXXCompilerFlags("/wd4005" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) endif() add_subdirectory(Testing) diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapProperty.cpp b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapProperty.cpp new file mode 100644 index 0000000000..3e364ab6e7 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapProperty.cpp @@ -0,0 +1,103 @@ +/*=================================================================== + +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 "mitkBValueMapProperty.h" + +mitk::BValueMapProperty::BValueMapProperty() + : m_BValueMap() +{ +} + +mitk::BValueMapProperty::BValueMapProperty(const BValueMapProperty& other) + : mitk::BaseProperty(other) +{ + m_BValueMap = other.GetBValueMap(); +} + +mitk::BValueMapProperty::BValueMapProperty(const BValueMap& bValueMap) +{ + m_BValueMap = bValueMap; +} + +mitk::BValueMapProperty::~BValueMapProperty() +{ +} + +const mitk::BValueMapProperty::BValueMap & mitk::BValueMapProperty::GetBValueMap() const +{ + return m_BValueMap; +} + +void mitk::BValueMapProperty::SetBValueMap(const BValueMap & map) +{ + this->m_BValueMap = map; +} + +bool mitk::BValueMapProperty::IsEqual(const BaseProperty& property) const +{ + return this->m_BValueMap == static_cast(property).m_BValueMap; +} + +bool mitk::BValueMapProperty::Assign(const BaseProperty& property) +{ + this->m_BValueMap = static_cast(property).m_BValueMap; + return true; +} + +mitk::BValueMapProperty::BValueMap mitk::BValueMapProperty::CreateBValueMap(const mitk::BValueMapProperty::GradientDirectionsContainerType * gdc, float referenceBValue) +{ + mitk::BValueMapProperty::BValueMap map; + + mitk::BValueMapProperty::GradientDirectionsContainerType::ConstIterator gdcit; + for( gdcit = gdc->Begin(); gdcit != gdc->End(); ++gdcit) + { + float keyBValue = mitk::BValueMapProperty::GetBValueOfGradientDirection(gdcit.Index(),referenceBValue, gdc); + map[keyBValue].push_back(gdcit.Index()); + } + + return map; +} + + +float mitk::BValueMapProperty::GetBValueOfGradientDirection(unsigned int i, float referenceBValue, const mitk::BValueMapProperty::GradientDirectionsContainerType * gdc) +{ + if(i > gdc->Size()-1) + return -1; + + if(gdc->ElementAt(i).one_norm() <= 0.0) + { + return 0; + } + else + { + double twonorm = gdc->ElementAt(i).two_norm(); + double bval = referenceBValue*twonorm*twonorm; + + if (bval<0) + bval = ceil(bval - 0.5); + else + bval = floor(bval + 0.5); + + return bval; + } +} + +itk::LightObject::Pointer mitk::BValueMapProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + result->UnRegister(); + return result; +} diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapProperty.h b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapProperty.h new file mode 100644 index 0000000000..6fee11e8e3 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapProperty.h @@ -0,0 +1,74 @@ +/*=================================================================== + +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 MITKBVALUEMAPPROPERTY_H +#define MITKBVALUEMAPPROPERTY_H + +#include "mitkBaseProperty.h" +#include +#include + +#include +#include +#include +namespace mitk +{ + + /** This property will store the b value map */ + + class MitkDiffusionCore_EXPORT BValueMapProperty : public mitk::BaseProperty + { + public: + /** + * \brief The BValueMap contains seperated IndicesVectors for each b value (index for GradientDirectionContainer) + * key := b value + * value := indicesVector + */ + typedef std::map< unsigned int , std::vector< unsigned int > > BValueMap; + typedef unsigned int IndexType; + typedef vnl_vector_fixed< double, 3 > ValueType; + typedef ValueType GradientDirectionType; + typedef itk::VectorContainer< IndexType, GradientDirectionType > GradientDirectionsContainerType; + mitkClassMacro(BValueMapProperty, BaseProperty) + + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + mitkNewMacro1Param(BValueMapProperty, const BValueMapProperty&) + mitkNewMacro1Param(BValueMapProperty, const BValueMap&) + + const BValueMap & GetBValueMap() const; + void SetBValueMap(const BValueMap & map); + + static BValueMap CreateBValueMap(const GradientDirectionsContainerType * gdc, float referenceBValue); + static float GetBValueOfGradientDirection(unsigned int i, float referenceBValue, const GradientDirectionsContainerType *gdc); + protected: + + BValueMapProperty(); + ~BValueMapProperty(); + + BValueMapProperty(const BValueMapProperty& other); + BValueMapProperty(const BValueMap& bValueMap); + + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty & property); + + BValueMap m_BValueMap; + + virtual itk::LightObject::Pointer InternalClone() const; + }; +} +#endif diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapPropertySerializer.cpp b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapPropertySerializer.cpp new file mode 100644 index 0000000000..f406a883e3 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkBValueMapPropertySerializer.cpp @@ -0,0 +1,131 @@ +/*=================================================================== + +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 mitkBValueMapPropertySerializer_h_included +#define mitkBValueMapPropertySerializer_h_included + +#include "mitkBasePropertySerializer.h" + +#include "mitkBValueMapProperty.h" + +#include + +namespace mitk +{ + +class MitkDiffusionCore_EXPORT BValueMapPropertySerializer : public BasePropertySerializer +{ + +protected: + + + void split(const std::string &s, char delim, std::vector &elems) { + std::stringstream ss(s); + std::string item; + while (std::getline(ss, item, delim)) { + elems.push_back(std::atoi(item.c_str())); + } + } + + std::vector split(const std::string &s, char delim) { + std::vector elems; + split(s, delim, elems); + return elems; + } + +public: + + mitkClassMacro( BValueMapPropertySerializer, BasePropertySerializer ) + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + virtual TiXmlElement* Serialize() + { + if (const BValueMapProperty* prop = dynamic_cast(m_Property.GetPointer())) + { + + BValueMapProperty::BValueMap map = prop->GetBValueMap(); + + if(map.empty()) return NULL; + + BValueMapProperty::BValueMap::const_iterator it = map.begin(); + BValueMapProperty::BValueMap::const_iterator end = map.end(); + + TiXmlElement* element = new TiXmlElement("bvaluemap"); + + + + while (it != end) { + TiXmlElement* child = new TiXmlElement("entry"); + { + std::stringstream ss; + ss << it->first; + child->SetAttribute("key", ss.str()); + } + + { + std::stringstream ss; + for(unsigned int i = 0 ; i < it->second.size(); i++) + { + + ss << it->second[i] << ","; + } + child->SetAttribute("value", ss.str()); + } + element->InsertEndChild(*child); + ++it; + } + + return element; + } + else return NULL; + } + + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + BValueMapProperty::BValueMap map; + + TiXmlElement* entry = element->FirstChildElement( "entry" )->ToElement(); + while(entry != NULL){ + + std::string key, value; + entry->QueryStringAttribute("key",&key); + entry->QueryStringAttribute("value",&value); + + std::vector indices = split(value.c_str(), ','); + + map[std::atoi(key.c_str())] = indices; + entry = entry->NextSiblingElement( "entry" ); + } + + return BValueMapProperty::New(map).GetPointer(); + } + +protected: + + BValueMapPropertySerializer(){} + virtual ~BValueMapPropertySerializer() {} +}; + +} // namespace + +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(BValueMapPropertySerializer) + +#endif diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkDiffusionPropertyHelper.cpp b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkDiffusionPropertyHelper.cpp new file mode 100644 index 0000000000..b1b0af9b03 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkDiffusionPropertyHelper.cpp @@ -0,0 +1,387 @@ +/*=================================================================== + +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 "mitkDiffusionPropertyHelper.h" +#include +#include +#include +#include + +const std::string mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME = "meta.GradientDirections"; +const std::string mitk::DiffusionPropertyHelper::ORIGINALGRADIENTCONTAINERPROPERTYNAME = "meta.OriginalGradientDirections"; +const std::string mitk::DiffusionPropertyHelper::MEASUREMENTFRAMEPROPERTYNAME = "meta.MeasurementFrame"; +const std::string mitk::DiffusionPropertyHelper::REFERENCEBVALUEPROPERTYNAME = "meta.ReferenceBValue"; +const std::string mitk::DiffusionPropertyHelper::BVALUEMAPPROPERTYNAME = "BValueMap"; + +mitk::DiffusionPropertyHelper::DiffusionPropertyHelper() +{ +} + +mitk::DiffusionPropertyHelper::DiffusionPropertyHelper( mitk::Image* inputImage) + : m_Image( inputImage ) +{ + // Update props +} + +mitk::DiffusionPropertyHelper::~DiffusionPropertyHelper() +{ +} + +mitk::DiffusionPropertyHelper::GradientDirectionsContainerType::Pointer + mitk::DiffusionPropertyHelper::CalcAveragedDirectionSet(double precision, GradientDirectionsContainerType::Pointer directions) +{ + // save old and construct new direction container + GradientDirectionsContainerType::Pointer newDirections = GradientDirectionsContainerType::New(); + + // fill new direction container + for(GradientDirectionsContainerType::ConstIterator gdcitOld = directions->Begin(); + gdcitOld != directions->End(); ++gdcitOld) + { + // already exists? + bool found = false; + for(GradientDirectionsContainerType::ConstIterator gdcitNew = newDirections->Begin(); + gdcitNew != newDirections->End(); ++gdcitNew) + { + if(AreAlike(gdcitNew.Value(), gdcitOld.Value(), precision)) + { + found = true; + break; + } + } + + // if not found, add it to new container + if(!found) + { + newDirections->push_back(gdcitOld.Value()); + } + } + + return newDirections; +} + +void mitk::DiffusionPropertyHelper::AverageRedundantGradients(double precision) +{ + + mitk::GradientDirectionsProperty* DirectionsProperty = static_cast( m_Image->GetProperty(mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer() ); + GradientDirectionsContainerType::Pointer oldDirs = DirectionsProperty->GetGradientDirectionsContainer(); + + GradientDirectionsContainerType::Pointer newDirs = + CalcAveragedDirectionSet(precision, oldDirs); + + // if sizes equal, we do not need to do anything in this function + if(oldDirs->size() == newDirs->size()) + return; + + // new image + ImageType::Pointer oldImage = ImageType::New(); + mitk::CastToItkImage( m_Image, oldImage); + ImageType::Pointer newITKImage = ImageType::New(); + newITKImage->SetSpacing( oldImage->GetSpacing() ); // Set the image spacing + newITKImage->SetOrigin( oldImage->GetOrigin() ); // Set the image origin + newITKImage->SetDirection( oldImage->GetDirection() ); // Set the image direction + newITKImage->SetLargestPossibleRegion( oldImage->GetLargestPossibleRegion() ); + newITKImage->SetVectorLength( newDirs->size() ); + newITKImage->SetBufferedRegion( oldImage->GetLargestPossibleRegion() ); + newITKImage->Allocate(); + + // average image data that corresponds to identical directions + itk::ImageRegionIterator< ImageType > newIt(newITKImage, newITKImage->GetLargestPossibleRegion()); + newIt.GoToBegin(); + itk::ImageRegionIterator< ImageType > oldIt(oldImage, oldImage->GetLargestPossibleRegion()); + oldIt.GoToBegin(); + + // initial new value of voxel + ImageType::PixelType newVec; + newVec.SetSize(newDirs->size()); + newVec.AllocateElements(newDirs->size()); + + // find which gradients should be averaged + GradientDirectionsContainerType::Pointer oldDirections = oldDirs; + std::vector > dirIndices; + for(GradientDirectionsContainerType::ConstIterator gdcitNew = newDirs->Begin(); + gdcitNew != newDirs->End(); ++gdcitNew) + { + dirIndices.push_back(std::vector(0)); + for(GradientDirectionsContainerType::ConstIterator gdcitOld = oldDirs->Begin(); + gdcitOld != oldDirections->End(); ++gdcitOld) + { + if(AreAlike(gdcitNew.Value(), gdcitOld.Value(), precision)) + { + //MITK_INFO << gdcitNew.Value() << " " << gdcitOld.Value(); + dirIndices[gdcitNew.Index()].push_back(gdcitOld.Index()); + } + } + } + + //int ind1 = -1; + while(!newIt.IsAtEnd()) + { + + // progress + //typename ImageType::IndexType ind = newIt.GetIndex(); + //ind1 = ind.m_Index[2]; + + // init new vector with zeros + newVec.Fill(0.0); + + // the old voxel value with duplicates + ImageType::PixelType oldVec = oldIt.Get(); + + for(unsigned int i=0; iSetProperty( mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str(), mitk::GradientDirectionsProperty::New( newDirs ) ); + m_Image->SetProperty( mitk::DiffusionPropertyHelper::ORIGINALGRADIENTCONTAINERPROPERTYNAME.c_str(), mitk::GradientDirectionsProperty::New( newDirs ) ); + ApplyMeasurementFrame(); + UpdateBValueMap(); + std::cout << std::endl; +} + +void mitk::DiffusionPropertyHelper::ApplyMeasurementFrame() +{ + + if( m_Image->GetProperty(mitk::DiffusionPropertyHelper::ORIGINALGRADIENTCONTAINERPROPERTYNAME.c_str()).IsNull() ) + { + return; + } + + GradientDirectionsContainerType::Pointer originalDirections = static_cast( m_Image->GetProperty(mitk::DiffusionPropertyHelper::ORIGINALGRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer())->GetGradientDirectionsContainer(); + + MeasurementFrameType measurementFrame = static_cast( m_Image->GetProperty(mitk::DiffusionPropertyHelper::MEASUREMENTFRAMEPROPERTYNAME.c_str()).GetPointer() )->GetMeasurementFrame(); + + GradientDirectionsContainerType::Pointer directions = GradientDirectionsContainerType::New(); + + if( originalDirections.IsNull() || ( originalDirections->size() == 0 ) ) + { + // original direction container was not set + return; + } + + GradientDirectionsContainerType::Pointer direction = GradientDirectionsContainerType::New(); + int c = 0; + for(GradientDirectionsContainerType::ConstIterator gdcit = originalDirections->Begin(); + gdcit != originalDirections->End(); ++gdcit) + { + vnl_vector vec = gdcit.Value(); + vec = vec.pre_multiply(measurementFrame); + directions->InsertElement(c, vec); + c++; + } + + m_Image->SetProperty( mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str(), mitk::GradientDirectionsProperty::New( directions ) ); +} + +void mitk::DiffusionPropertyHelper::UpdateBValueMap() +{ + BValueMapType b_ValueMap; + + if(m_Image->GetProperty(mitk::DiffusionPropertyHelper::BVALUEMAPPROPERTYNAME.c_str()).IsNull()) + { + } + else + { + b_ValueMap = static_cast(m_Image->GetProperty(mitk::DiffusionPropertyHelper::BVALUEMAPPROPERTYNAME.c_str()).GetPointer() )->GetBValueMap(); + } + + if(!b_ValueMap.empty()) + { + b_ValueMap.clear(); + } + + if( m_Image->GetProperty(mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str()).IsNotNull() ) + { + GradientDirectionsContainerType::Pointer directions = static_cast( m_Image->GetProperty(mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer() )->GetGradientDirectionsContainer(); + + GradientDirectionsContainerType::ConstIterator gdcit; + for( gdcit = directions->Begin(); gdcit != directions->End(); ++gdcit) + { + b_ValueMap[GetB_Value(gdcit.Index())].push_back(gdcit.Index()); + } + } + + m_Image->SetProperty( mitk::DiffusionPropertyHelper::BVALUEMAPPROPERTYNAME.c_str(), mitk::BValueMapProperty::New( b_ValueMap ) ); +} + +bool mitk::DiffusionPropertyHelper::AreAlike(GradientDirectionType g1, + GradientDirectionType g2, + double precision) +{ + GradientDirectionType diff = g1 - g2; + GradientDirectionType diff2 = g1 + g2; + return diff.two_norm() < precision || diff2.two_norm() < precision; +} + +float mitk::DiffusionPropertyHelper::GetB_Value(unsigned int i) +{ + GradientDirectionsContainerType::Pointer directions = static_cast( m_Image->GetProperty(mitk::DiffusionPropertyHelper::GRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer() )->GetGradientDirectionsContainer(); + + float b_value = static_cast(m_Image->GetProperty(mitk::DiffusionPropertyHelper::REFERENCEBVALUEPROPERTYNAME.c_str()).GetPointer() )->GetValue(); + + if(i > directions->Size()-1) + return -1; + + if(directions->ElementAt(i).one_norm() <= 0.0) + { + return 0; + } + else + { + double twonorm = directions->ElementAt(i).two_norm(); + double bval = b_value*twonorm*twonorm; + + if (bval<0) + bval = ceil(bval - 0.5); + else + bval = floor(bval + 0.5); + + return bval; + } +} + +void mitk::DiffusionPropertyHelper::InitializeImage() +{ + this->ApplyMeasurementFrame(); + this->UpdateBValueMap(); + + // initialize missing properties +} + + +bool mitk::DiffusionPropertyHelper::IsDiffusionWeightedImage(const mitk::Image * image) +{ + bool isDiffusionWeightedImage( true ); + + if( image == NULL ) + { + isDiffusionWeightedImage = false; + } + + if( isDiffusionWeightedImage ) + { + mitk::FloatProperty::Pointer referenceBValue = dynamic_cast(image->GetProperty(REFERENCEBVALUEPROPERTYNAME.c_str()).GetPointer()); + + if( referenceBValue.IsNull() ) + { + isDiffusionWeightedImage = false; + } + + } + + unsigned int gradientDirections( 0 ); + if( isDiffusionWeightedImage ) + { + mitk::GradientDirectionsProperty::Pointer gradientDirectionsProperty = dynamic_cast(image->GetProperty(GRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer()); + + if( gradientDirectionsProperty.IsNull() ) + { + isDiffusionWeightedImage = false; + } + else + { + gradientDirections = gradientDirectionsProperty->GetGradientDirectionsContainer()->size(); + } + } + + if( isDiffusionWeightedImage ) + { + unsigned int components = image->GetPixelType().GetNumberOfComponents(); + + if( components != gradientDirections ) + { + isDiffusionWeightedImage = false; + } + } + + return isDiffusionWeightedImage; +} + +const mitk::DiffusionPropertyHelper::BValueMapType & mitk::DiffusionPropertyHelper::GetBValueMap(const mitk::Image *image) +{ + return dynamic_cast(image->GetProperty(BVALUEMAPPROPERTYNAME.c_str()).GetPointer())->GetBValueMap(); +} + +float mitk::DiffusionPropertyHelper::GetReferenceBValue(const mitk::Image *image) +{ + return dynamic_cast(image->GetProperty(REFERENCEBVALUEPROPERTYNAME.c_str()).GetPointer())->GetValue(); +} + +const mitk::DiffusionPropertyHelper::MeasurementFrameType & mitk::DiffusionPropertyHelper::GetMeasurementFrame(const mitk::Image *image) +{ + return dynamic_cast(image->GetProperty(MEASUREMENTFRAMEPROPERTYNAME.c_str()).GetPointer())->GetMeasurementFrame(); +} + +mitk::DiffusionPropertyHelper::GradientDirectionsContainerType::Pointer mitk::DiffusionPropertyHelper::GetOriginalGradientContainer(const mitk::Image *image) +{ + return dynamic_cast(image->GetProperty(ORIGINALGRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer())->GetGradientDirectionsContainer(); +} + +mitk::DiffusionPropertyHelper::GradientDirectionsContainerType::Pointer mitk::DiffusionPropertyHelper::GetGradientContainer(const mitk::Image *image) +{ + return dynamic_cast(image->GetProperty(GRADIENTCONTAINERPROPERTYNAME.c_str()).GetPointer())->GetGradientDirectionsContainer(); +} + +bool mitk::DiffusionPropertyHelper::IsDiffusionWeightedImage() const +{ + return IsDiffusionWeightedImage(m_Image); +} + +const mitk::DiffusionPropertyHelper::BValueMapType &mitk::DiffusionPropertyHelper::GetBValueMap() const +{ + return GetBValueMap(m_Image); +} + +float mitk::DiffusionPropertyHelper::GetReferenceBValue() const +{ + return GetReferenceBValue(m_Image); +} + +const mitk::DiffusionPropertyHelper::MeasurementFrameType & mitk::DiffusionPropertyHelper::GetMeasurementFrame() const +{ + return GetMeasurementFrame(m_Image); +} + +mitk::DiffusionPropertyHelper::GradientDirectionsContainerType::Pointer mitk::DiffusionPropertyHelper::GetOriginalGradientContainer() const +{ + return GetOriginalGradientContainer(m_Image); +} + +mitk::DiffusionPropertyHelper::GradientDirectionsContainerType::Pointer mitk::DiffusionPropertyHelper::GetGradientContainer() const +{ + return GetGradientContainer(m_Image); +} diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkDiffusionPropertyHelper.h b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkDiffusionPropertyHelper.h new file mode 100644 index 0000000000..0e599e2950 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkDiffusionPropertyHelper.h @@ -0,0 +1,128 @@ +/*=================================================================== + +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 MITKDIFFUSIONPROPERTYHELPER_H +#define MITKDIFFUSIONPROPERTYHELPER_H + +#include + +#include +#include +#include +#include + +namespace mitk +{ + /** \brief Helper class for mitk::Images containing diffusion weighted data + * + * This class takes a pointer to a mitk::Image containing diffusion weighted information and provides + * functions to manipulate the diffusion meta-data. Will log an error if required information is + * missing. + */ + + class MitkDiffusionCore_EXPORT DiffusionPropertyHelper + { + public: + + typedef short DiffusionPixelType; + + typedef mitk::BValueMapProperty::BValueMap BValueMapType; + typedef GradientDirectionsProperty::GradientDirectionType GradientDirectionType; + typedef GradientDirectionsProperty::GradientDirectionsContainerType GradientDirectionsContainerType; + typedef mitk::MeasurementFrameProperty::MeasurementFrameType MeasurementFrameType; + typedef itk::VectorImage< DiffusionPixelType, 3> ImageType; + + static const std::string GRADIENTCONTAINERPROPERTYNAME; + static const std::string ORIGINALGRADIENTCONTAINERPROPERTYNAME; + static const std::string MEASUREMENTFRAMEPROPERTYNAME; + static const std::string REFERENCEBVALUEPROPERTYNAME; + static const std::string BVALUEMAPPROPERTYNAME; + + /// Public constructor, takes a mitk::Image pointer as argument + DiffusionPropertyHelper( mitk::Image* inputImage ); + ~DiffusionPropertyHelper(); + + /** \brief Decide whether a provided image is a valid diffusion weighted image + * + * An image will be considered a valid diffusion weighted image if the following are true + * - It has a reference b value + * - It has a gradient directions property + * - The number of gradients directions matches the number of components of the image + * + * This does not guarantee that the data is sensible or accurate, it just verfies that it + * meets the formal requirements to possibly be a valid diffusion weighted image. + */ + static bool IsDiffusionWeightedImage(const mitk::Image *); + + /// Convenience method to get the BValueMap + static const BValueMapType & GetBValueMap(const mitk::Image *); + /// Convenience method to get the BValue + static float GetReferenceBValue(const mitk::Image *); + /// Convenience method to get the measurement frame + static const MeasurementFrameType & GetMeasurementFrame(const mitk::Image *); + /// Convenience method to get the original gradient directions + static GradientDirectionsContainerType::Pointer GetOriginalGradientContainer(const mitk::Image *); + /// Convenience method to get the gradient directions + static GradientDirectionsContainerType::Pointer GetGradientContainer(const mitk::Image *); + + const BValueMapType & GetBValueMap() const; + float GetReferenceBValue() const; + const MeasurementFrameType & GetMeasurementFrame() const; + GradientDirectionsContainerType::Pointer GetOriginalGradientContainer() const; + GradientDirectionsContainerType::Pointer GetGradientContainer() const; + + bool IsDiffusionWeightedImage() const; + + void AverageRedundantGradients(double precision); + + /** \brief Make certain the owned image is up to date with all necessary properties + * + * This function will generate the B Value map and copy all properties to the owned image. + */ + void InitializeImage(); + + GradientDirectionsContainerType::Pointer CalcAveragedDirectionSet(double precision, GradientDirectionsContainerType::Pointer directions); + + protected: + + DiffusionPropertyHelper(); + + /** + * \brief Apply the previouse set MeasurementFrame to all gradients in the GradientsDirectionContainer (m_Directions) + * + * \warning first set the MeasurementFrame + */ + void ApplyMeasurementFrame(); + + /** + * \brief Update the BValueMap (m_B_ValueMap) using the current gradient directions (m_Directions) + * + * \warning Have to be called after each manipulation on the GradientDirectionContainer + * !especially after manipulation of the m_Directions (GetDirections()) container via pointer access! + */ + void UpdateBValueMap(); + + /// Determines whether gradients can be considered to be equal + bool AreAlike(GradientDirectionType g1, GradientDirectionType g2, double precision); + + /// Get the b value belonging to an index + float GetB_Value(unsigned int i); + + mitk::Image* m_Image; + + }; +} +#endif diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsProperty.cpp b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsProperty.cpp new file mode 100644 index 0000000000..1ef0d3e495 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsProperty.cpp @@ -0,0 +1,83 @@ +/*=================================================================== + +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 "mitkGradientDirectionsProperty.h" + +mitk::GradientDirectionsProperty::GradientDirectionsProperty() +{ + m_GradientDirectionsContainer = mitk::GradientDirectionsProperty::GradientDirectionsContainerType::New(); +} + +mitk::GradientDirectionsProperty::GradientDirectionsProperty(const GradientDirectionsProperty& other) + : mitk::BaseProperty(other) +{ + m_GradientDirectionsContainer = other.GetGradientDirectionsContainer(); +} + +mitk::GradientDirectionsProperty::GradientDirectionsProperty(const GradientDirectionsContainerType::Pointer gradientDirectionsContainer) +{ + m_GradientDirectionsContainer = gradientDirectionsContainer; +} + +mitk::GradientDirectionsProperty::GradientDirectionsProperty(const AlternativeGradientDirectionsContainerType gradientDirectionsContainer) +{ + m_GradientDirectionsContainer = mitk::GradientDirectionsProperty::GradientDirectionsContainerType::New(); + for(unsigned int index(0); index < gradientDirectionsContainer.size(); index++) + { + GradientDirectionType newDirection = gradientDirectionsContainer.at(index).GetVnlVector(); + m_GradientDirectionsContainer->InsertElement( index, newDirection); + } +} + +mitk::GradientDirectionsProperty::~GradientDirectionsProperty() +{ +} + +const mitk::GradientDirectionsProperty::GradientDirectionsContainerType::Pointer mitk::GradientDirectionsProperty::GetGradientDirectionsContainer() const +{ + return m_GradientDirectionsContainer; +} + +bool mitk::GradientDirectionsProperty::IsEqual(const BaseProperty& property) const +{ + + GradientDirectionsContainerType::Pointer lhs = this->m_GradientDirectionsContainer; + GradientDirectionsContainerType::Pointer rhs = static_cast(property).m_GradientDirectionsContainer; + + if(lhs->Size() != rhs->Size()) return false; + + GradientDirectionsContainerType::Iterator lhsit = lhs->Begin(); + GradientDirectionsContainerType::Iterator rhsit = rhs->Begin(); + + bool equal = true; + for(unsigned int i = 0 ; i < lhs->Size(); i++, ++lhsit, ++rhsit) + equal |= lhsit.Value() == rhsit.Value(); + + return equal; +} + +bool mitk::GradientDirectionsProperty::Assign(const BaseProperty& property) +{ + this->m_GradientDirectionsContainer = static_cast(property).m_GradientDirectionsContainer; + return true; +} + +itk::LightObject::Pointer mitk::GradientDirectionsProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + result->UnRegister(); + return result; +} diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsProperty.h b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsProperty.h new file mode 100644 index 0000000000..4fb765388a --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsProperty.h @@ -0,0 +1,68 @@ +/*=================================================================== + +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 MITKGRADIENTDIRECTIONSPROPERTY_H +#define MITKGRADIENTDIRECTIONSPROPERTY_H + +#include "mitkBaseProperty.h" +#include +#include +#include + +#include + +namespace mitk +{ + + /** This property will store the gradients directions and the original gradient directions */ + class MitkDiffusionCore_EXPORT GradientDirectionsProperty : public mitk::BaseProperty + { + public: + typedef unsigned int IndexType; + typedef vnl_vector_fixed< double, 3 > ValueType; + typedef ValueType GradientDirectionType; + typedef itk::VectorContainer< IndexType, GradientDirectionType > GradientDirectionsContainerType; + typedef std::vector< itk::Vector > AlternativeGradientDirectionsContainerType; + + mitkClassMacro(GradientDirectionsProperty, BaseProperty) + + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + mitkNewMacro1Param(GradientDirectionsProperty, const GradientDirectionsProperty&); + mitkNewMacro1Param(GradientDirectionsProperty, const GradientDirectionsContainerType::Pointer); + mitkNewMacro1Param(GradientDirectionsProperty, const AlternativeGradientDirectionsContainerType ); + + const GradientDirectionsContainerType::Pointer GetGradientDirectionsContainer() const; + + protected: + + GradientDirectionsProperty(); + ~GradientDirectionsProperty(); + + GradientDirectionsProperty(const GradientDirectionsProperty& other); + GradientDirectionsProperty(const GradientDirectionsContainerType::Pointer gradientDirectionsContainer); + GradientDirectionsProperty(const AlternativeGradientDirectionsContainerType gradientDirectionsContainer); + + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty & property); + + GradientDirectionsContainerType::Pointer m_GradientDirectionsContainer; + + virtual itk::LightObject::Pointer InternalClone() const; + }; +} +#endif diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsPropertySerializer.cpp b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsPropertySerializer.cpp new file mode 100644 index 0000000000..4c540ff733 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkGradientDirectionsPropertySerializer.cpp @@ -0,0 +1,106 @@ +/*=================================================================== + +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 mitkGradientDirectionPropertySerializer_h_included +#define mitkGradientDirectionPropertySerializer_h_included + +#include "mitkBasePropertySerializer.h" + +#include "mitkGradientDirectionsProperty.h" + +#include "MitkDiffusionCoreExports.h" + +namespace mitk +{ + +class MitkDiffusionCore_EXPORT GradientDirectionsPropertySerializer : public BasePropertySerializer +{ + public: + + mitkClassMacro( GradientDirectionsPropertySerializer, BasePropertySerializer ) + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + virtual TiXmlElement* Serialize() + { + if (const GradientDirectionsProperty* prop = dynamic_cast(m_Property.GetPointer())) + { + + typedef mitk::GradientDirectionsProperty::GradientDirectionsContainerType GradientDirectionsContainerType; + GradientDirectionsContainerType::Pointer gdc = prop->GetGradientDirectionsContainer().GetPointer(); + + if(gdc.IsNull() || gdc->Size() == 0) return NULL; + + + GradientDirectionsContainerType::Iterator it = gdc->Begin(); + GradientDirectionsContainerType::Iterator end = gdc->End(); + + TiXmlElement* element = new TiXmlElement("gradientdirections"); + + while (it != end) { + TiXmlElement* child = new TiXmlElement("entry"); + std::stringstream ss; + ss << it.Value(); + child->SetAttribute("value", ss.str()); + element->InsertEndChild(*child); + + ++it; + } + + return element; + } + else return NULL; + } + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + mitk::GradientDirectionsProperty::GradientDirectionsContainerType::Pointer gdc; + gdc = mitk::GradientDirectionsProperty::GradientDirectionsContainerType::New(); + + TiXmlElement* entry = element->FirstChildElement( "entry" )->ToElement(); + while(entry != NULL){ + + std::stringstream ss; + std::string value; + + entry->QueryStringAttribute("value",&value); + ss << value; + + vnl_vector_fixed vector; + vector.read_ascii(ss); + + gdc->push_back(vector); + + entry = entry->NextSiblingElement( "entry" ); + } + + return GradientDirectionsProperty::New(gdc).GetPointer(); + } + + protected: + + GradientDirectionsPropertySerializer() {} + virtual ~GradientDirectionsPropertySerializer() {} +}; + +} // namespace + +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(GradientDirectionsPropertySerializer) + +#endif diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFrameProperty.cpp b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFrameProperty.cpp new file mode 100644 index 0000000000..dea5153be0 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFrameProperty.cpp @@ -0,0 +1,65 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkMeasurementFrameProperty.h" + +mitk::MeasurementFrameProperty::MeasurementFrameProperty() + : m_MeasurementFrame() +{ +} + +mitk::MeasurementFrameProperty::MeasurementFrameProperty(const MeasurementFrameProperty& other) + : mitk::BaseProperty(other) +{ + m_MeasurementFrame = other.GetMeasurementFrame(); +} + +mitk::MeasurementFrameProperty::MeasurementFrameProperty(const MeasurementFrameType& measurementFrame) +{ + m_MeasurementFrame = measurementFrame; +} + +mitk::MeasurementFrameProperty::~MeasurementFrameProperty() +{ +} + +const mitk::MeasurementFrameProperty::MeasurementFrameType & mitk::MeasurementFrameProperty::GetMeasurementFrame() const +{ + return m_MeasurementFrame; +} + +void mitk::MeasurementFrameProperty::SetMeasurementFrame(const MeasurementFrameType & frame) +{ + m_MeasurementFrame = frame; +} + +bool mitk::MeasurementFrameProperty::IsEqual(const BaseProperty& property) const +{ + return this->m_MeasurementFrame == static_cast(property).m_MeasurementFrame; +} + +bool mitk::MeasurementFrameProperty::Assign(const BaseProperty& property) +{ + this->m_MeasurementFrame = static_cast(property).m_MeasurementFrame; + return true; +} + +itk::LightObject::Pointer mitk::MeasurementFrameProperty::InternalClone() const +{ + itk::LightObject::Pointer result(new Self(*this)); + result->UnRegister(); + return result; +} diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFrameProperty.h b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFrameProperty.h new file mode 100644 index 0000000000..c892bba7a3 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFrameProperty.h @@ -0,0 +1,60 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKMEASUREMENTFRAMEPROPERTY_H +#define MITKMEASUREMENTFRAMEPROPERTY_H + +#include "mitkBaseProperty.h" +#include + +#include + +namespace mitk +{ + + /** This property will store the measurement frame */ + class MitkDiffusionCore_EXPORT MeasurementFrameProperty : public mitk::BaseProperty + { + public: + typedef vnl_matrix_fixed< double, 3, 3 > MeasurementFrameType; + mitkClassMacro(MeasurementFrameProperty, BaseProperty) + + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + mitkNewMacro1Param(MeasurementFrameProperty, const MeasurementFrameProperty&); + mitkNewMacro1Param(MeasurementFrameProperty, const MeasurementFrameType&); + + const MeasurementFrameType &GetMeasurementFrame() const; + void SetMeasurementFrame(const MeasurementFrameType & frame); + + protected: + + MeasurementFrameProperty(); + ~MeasurementFrameProperty(); + + MeasurementFrameProperty(const MeasurementFrameProperty& other); + MeasurementFrameProperty(const MeasurementFrameType& measurementFrame); + + virtual bool IsEqual(const BaseProperty& property) const; + virtual bool Assign(const BaseProperty & property); + + MeasurementFrameType m_MeasurementFrame; + + virtual itk::LightObject::Pointer InternalClone() const; + }; +} +#endif diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFramePropertySerializer.cpp b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFramePropertySerializer.cpp new file mode 100644 index 0000000000..60c17f8f59 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkMeasurementFramePropertySerializer.cpp @@ -0,0 +1,89 @@ +/*=================================================================== + +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 mitkMeasurementFramePropertySerializer_h_included +#define mitkMeasurementFramePropertySerializer_h_included + +#include "mitkBasePropertySerializer.h" + +#include "mitkMeasurementFrameProperty.h" + +#include + +namespace mitk +{ + +class MitkDiffusionCore_EXPORT MeasurementFramePropertySerializer : public BasePropertySerializer +{ + public: + + mitkClassMacro( MeasurementFramePropertySerializer, BasePropertySerializer ) + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + virtual TiXmlElement* Serialize() + { + if (const MeasurementFrameProperty* prop = dynamic_cast(m_Property.GetPointer())) + { + + typedef mitk::MeasurementFrameProperty::MeasurementFrameType MeasurementFrameType; + const MeasurementFrameType & mft = prop->GetMeasurementFrame(); + + if(mft.is_zero()) return NULL; + + TiXmlElement* element = new TiXmlElement("measurementframe"); + + TiXmlElement* child = new TiXmlElement("entry"); + std::stringstream ss; + ss << mft; + child->SetAttribute("value", ss.str()); + element->InsertEndChild(*child); + + return element; + } + else return NULL; + } + + virtual BaseProperty::Pointer Deserialize(TiXmlElement* element) + { + if (!element) return NULL; + + TiXmlElement* entry = element->FirstChildElement( "entry" )->ToElement(); + + std::stringstream ss; + std::string value; + + entry->QueryStringAttribute("value",&value); + ss << value; + + MeasurementFrameProperty::MeasurementFrameType matrix; + matrix.read_ascii(ss); + + return MeasurementFrameProperty::New(matrix).GetPointer(); + } + + protected: + + MeasurementFramePropertySerializer() {} + virtual ~MeasurementFramePropertySerializer() {} +}; + +} // namespace + +// important to put this into the GLOBAL namespace (because it starts with 'namespace mitk') +MITK_REGISTER_SERIALIZER(MeasurementFramePropertySerializer) + +#endif diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkNodePredicateIsDWI.cpp b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkNodePredicateIsDWI.cpp new file mode 100644 index 0000000000..7afb4abc04 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkNodePredicateIsDWI.cpp @@ -0,0 +1,39 @@ +/*=================================================================== + +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 "mitkNodePredicateIsDWI.h" +#include "mitkDataNode.h" +#include + +mitk::NodePredicateIsDWI::NodePredicateIsDWI() +: NodePredicateBase() +{ +} + +mitk::NodePredicateIsDWI::~NodePredicateIsDWI() +{ +} + + +bool mitk::NodePredicateIsDWI::CheckNode(const mitk::DataNode* node) const +{ + if (node == NULL) + throw std::invalid_argument("NodePredicateIsDWI: invalid node"); + + mitk::Image* image = dynamic_cast(node->GetData()); + + return mitk::DiffusionPropertyHelper::IsDiffusionWeightedImage( image ); +} diff --git a/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkNodePredicateIsDWI.h b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkNodePredicateIsDWI.h new file mode 100644 index 0000000000..7ca6f29d70 --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/IODataStructures/Properties/mitkNodePredicateIsDWI.h @@ -0,0 +1,56 @@ +/*=================================================================== + +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 MITKNODEPREDICATEISDWI_H_HEADER_INCLUDED_ +#define MITKNODEPREDICATEISDWI_H_HEADER_INCLUDED_ + +#include + +#include "mitkNodePredicateBase.h" +#include "mitkBaseProperty.h" +#include "mitkBaseData.h" + +namespace mitk { + + /**Documentation + * @brief Predicate that evaluates whether a given node contains a diffusion weighted image + * @ingroup DataStorage + */ + + class MitkDiffusionCore_EXPORT NodePredicateIsDWI : public NodePredicateBase + { + public: + mitkClassMacro(NodePredicateIsDWI, NodePredicateBase); + itkFactorylessNewMacro(NodePredicateIsDWI) + + //##Documentation + //## @brief Standard Destructor + virtual ~NodePredicateIsDWI(); + + //##Documentation + //## @brief Checks, if the node's data contains a property that is equal to m_ValidProperty + virtual bool CheckNode(const mitk::DataNode* node) const; + + protected: + //##Documentation + //## @brief Constructor to check for a named property + NodePredicateIsDWI(); + }; + +} // namespace mitk + +#endif /* MITKNODEPREDICATEISDWI_H_HEADER_INCLUDED_ */ diff --git a/Modules/DiffusionImaging/DiffusionCore/files.cmake b/Modules/DiffusionImaging/DiffusionCore/files.cmake index f9995fbe3d..d5ad2057eb 100644 --- a/Modules/DiffusionImaging/DiffusionCore/files.cmake +++ b/Modules/DiffusionImaging/DiffusionCore/files.cmake @@ -1,138 +1,150 @@ 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 DicomImport/mitkDiffusionDICOMFileReader.cpp DicomImport/mitkDiffusionHeaderDICOMFileReader.cpp DicomImport/mitkDiffusionHeaderSiemensDICOMFileReader.cpp DicomImport/mitkDiffusionHeaderSiemensDICOMFileHelper.cpp DicomImport/mitkDiffusionHeaderSiemensMosaicDICOMFileReader.cpp DicomImport/mitkDiffusionHeaderGEDICOMFileReader.cpp DicomImport/mitkDiffusionHeaderPhilipsDICOMFileReader.cpp # DataStructures -> DWI IODataStructures/DiffusionWeightedImages/mitkDiffusionImageHeaderInformation.cpp IODataStructures/DiffusionWeightedImages/mitkDiffusionImageSource.cpp IODataStructures/DiffusionWeightedImages/mitkImageToDiffusionImageSource.cpp IODataStructures/DiffusionWeightedImages/mitkDiffusionImageCorrectionFilter.cpp + # Properties + IODataStructures/Properties/mitkBValueMapProperty.cpp + IODataStructures/Properties/mitkGradientDirectionsProperty.cpp + IODataStructures/Properties/mitkMeasurementFrameProperty.cpp + IODataStructures/Properties/mitkDiffusionPropertyHelper.cpp + IODataStructures/Properties/mitkNodePredicateIsDWI.cpp + + # Serializer + IODataStructures/Properties/mitkBValueMapPropertySerializer.cpp + IODataStructures/Properties/mitkGradientDirectionsPropertySerializer.cpp + IODataStructures/Properties/mitkMeasurementFramePropertySerializer.cpp + # DataStructures -> QBall IODataStructures/QBallImages/mitkQBallImageSource.cpp IODataStructures/QBallImages/mitkQBallImage.cpp # DataStructures -> Tensor IODataStructures/TensorImages/mitkTensorImage.cpp Rendering/vtkMaskedProgrammableGlyphFilter.cpp Rendering/mitkVectorImageVtkGlyphMapper3D.cpp Rendering/vtkOdfSource.cxx Rendering/vtkThickPlane.cxx Rendering/mitkOdfNormalizationMethodProperty.cpp Rendering/mitkOdfScaleByProperty.cpp # Algorithms Algorithms/mitkPartialVolumeAnalysisHistogramCalculator.cpp Algorithms/mitkPartialVolumeAnalysisClusteringCalculator.cpp Algorithms/itkDwiGradientLengthCorrectionFilter.cpp Algorithms/itkElectrostaticRepulsionDiffusionGradientReductionFilter.h # Registration Algorithms & Co. Algorithms/Registration/mitkRegistrationWrapper.cpp Algorithms/Registration/mitkPyramidImageRegistrationMethod.cpp # Algorithms/Registration/mitkRegistrationMethodITK4.cpp # MultishellProcessing Algorithms/Reconstruction/MultishellProcessing/itkADCAverageFunctor.cpp Algorithms/Reconstruction/MultishellProcessing/itkADCFitFunctor.cpp Algorithms/Reconstruction/MultishellProcessing/itkKurtosisFitFunctor.cpp Algorithms/Reconstruction/MultishellProcessing/itkBiExpFitFunctor.cpp # Function Collection mitkDiffusionFunctionCollection.cpp ) set(H_FILES # function Collection mitkDiffusionFunctionCollection.h # Rendering Rendering/mitkDiffusionImageMapper.h Rendering/mitkOdfVtkMapper2D.h # Reconstruction Algorithms/Reconstruction/itkDiffusionQballReconstructionImageFilter.h Algorithms/Reconstruction/mitkTeemDiffusionTensor3DReconstructionImageFilter.h Algorithms/Reconstruction/itkAnalyticalDiffusionQballReconstructionImageFilter.h Algorithms/Reconstruction/itkDiffusionMultiShellQballReconstructionImageFilter.h Algorithms/Reconstruction/itkPointShell.h Algorithms/Reconstruction/itkOrientationDistributionFunction.h Algorithms/Reconstruction/itkDiffusionIntravoxelIncoherentMotionReconstructionImageFilter.h # MultishellProcessing Algorithms/Reconstruction/MultishellProcessing/itkRadialMultishellToSingleshellImageFilter.h Algorithms/Reconstruction/MultishellProcessing/itkDWIVoxelFunctor.h Algorithms/Reconstruction/MultishellProcessing/itkADCAverageFunctor.h Algorithms/Reconstruction/MultishellProcessing/itkKurtosisFitFunctor.h Algorithms/Reconstruction/MultishellProcessing/itkBiExpFitFunctor.h Algorithms/Reconstruction/MultishellProcessing/itkADCFitFunctor.h # IO Datastructures IODataStructures/DiffusionWeightedImages/mitkDiffusionImage.h # Algorithms Algorithms/itkDiffusionQballGeneralizedFaImageFilter.h Algorithms/itkDiffusionQballPrepareVisualizationImageFilter.h Algorithms/itkTensorDerivedMeasurementsFilter.h Algorithms/itkBrainMaskExtractionImageFilter.h Algorithms/itkB0ImageExtractionImageFilter.h Algorithms/itkB0ImageExtractionToSeparateImageFilter.h Algorithms/itkTensorImageToDiffusionImageFilter.h Algorithms/itkTensorToL2NormImageFilter.h Algorithms/itkGaussianInterpolateImageFunction.h Algorithms/mitkPartialVolumeAnalysisHistogramCalculator.h Algorithms/mitkPartialVolumeAnalysisClusteringCalculator.h Algorithms/itkDiffusionTensorPrincipalDirectionImageFilter.h Algorithms/itkCartesianToPolarVectorImageFilter.h Algorithms/itkPolarToCartesianVectorImageFilter.h Algorithms/itkDistanceMapFilter.h Algorithms/itkProjectionFilter.h Algorithms/itkResidualImageFilter.h Algorithms/itkExtractChannelFromRgbaImageFilter.h Algorithms/itkTensorReconstructionWithEigenvalueCorrectionFilter.h Algorithms/itkMergeDiffusionImagesFilter.h Algorithms/itkDwiPhantomGenerationFilter.h Algorithms/itkFiniteDiffOdfMaximaExtractionFilter.h Algorithms/itkMrtrixPeakImageConverter.h Algorithms/itkFslPeakImageConverter.h Algorithms/itkShCoefficientImageImporter.h Algorithms/itkShCoefficientImageExporter.h Algorithms/itkOdfMaximaExtractionFilter.h Algorithms/itkResampleDwiImageFilter.h Algorithms/itkDwiGradientLengthCorrectionFilter.h Algorithms/itkAdcImageFilter.h Algorithms/itkDwiNormilzationFilter.h Algorithms/itkSplitDWImageFilter.h Algorithms/itkRemoveDwiChannelFilter.h Algorithms/itkExtractDwiChannelFilter.h Algorithms/Registration/mitkDWIHeadMotionCorrectionFilter.h Algorithms/mitkDiffusionImageToDiffusionImageFilter.h Algorithms/itkNonLocalMeansDenoisingFilter.h Algorithms/itkVectorImageToImageFilter.h ) set( TOOL_FILES )