17 #ifndef __mitkDiffusionImageNrrdReaderService_cpp
18 #define __mitkDiffusionImageNrrdReaderService_cpp
33 #include <itkImageRegionIterator.h>
34 #include <itkMetaDataObject.h>
35 #include "itksys/SystemTools.hxx"
36 #include "itkImageFileReader.h"
37 #include "itkMetaDataObject.h"
38 #include "itkNrrdImageIO.h"
76 std::vector<itk::SmartPointer<mitk::BaseData> >
80 std::vector<itk::SmartPointer<mitk::BaseData> > result;
101 throw itk::ImageFileReaderException(__FILE__, __LINE__,
"Sorry, the filename to be read is empty!");
109 MITK_INFO <<
"DiffusionImageNrrdReaderService: reading image information";
113 ext = itksys::SystemTools::LowerCase( ext );
115 if (ext ==
".hdwi" || ext ==
".dwi" || ext ==
".nrrd")
117 typedef itk::ImageFileReader<VectorImageType> FileReaderType;
121 reader->SetImageIO(io);
123 itkVectorImage = reader->GetOutput();
133 if (ext ==
".hdwi" || ext ==
".dwi" || ext ==
".nrrd")
136 itk::MetaDataDictionary imgMetaDictionary = itkVectorImage->GetMetaDataDictionary();
137 std::vector<std::string> imgMetaKeys = imgMetaDictionary.GetKeys();
138 std::vector<std::string>::const_iterator itKey = imgMetaKeys.begin();
139 std::string metaString;
143 int numberOfImages = 0;
144 int numberOfGradientImages = 0;
146 double xx, xy, xz, yx, yy, yz, zx, zy, zz;
148 for (; itKey != imgMetaKeys.end(); itKey ++)
152 itk::ExposeMetaData<std::string> (imgMetaDictionary, *itKey, metaString);
153 if (itKey->find(
"DWMRI_gradient") != std::string::npos)
155 sscanf(metaString.c_str(),
"%lf %lf %lf\n", &x, &y, &z);
156 vect3d[0] = x; vect3d[1] = y; vect3d[2] = z;
157 DiffusionVectors->InsertElement( numberOfImages, vect3d );
160 if (vect3d[0] == 0.0 &&
166 ++numberOfGradientImages;;
168 else if (itKey->find(
"DWMRI_b-value") != std::string::npos)
171 BValue = atof(metaString.c_str());
173 else if (itKey->find(
"measurement frame") != std::string::npos)
175 sscanf(metaString.c_str(),
" ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) ( %lf , %lf , %lf ) \n", &xx, &xy, &xz, &yx, &yy, &yz, &zx, &zy, &zz);
177 if (xx>10e-10 || xy>10e-10 || xz>10e-10 ||
178 yx>10e-10 || yy>10e-10 || yz>10e-10 ||
179 zx>10e-10 || zy>10e-10 || zz>10e-10 )
181 MeasurementFrame(0,0) = xx;
182 MeasurementFrame(0,1) = xy;
183 MeasurementFrame(0,2) = xz;
184 MeasurementFrame(1,0) = yx;
185 MeasurementFrame(1,1) = yy;
186 MeasurementFrame(1,2) = yz;
187 MeasurementFrame(2,0) = zx;
188 MeasurementFrame(2,1) = zy;
189 MeasurementFrame(2,2) = zz;
193 MeasurementFrame(0,0) = 1;
194 MeasurementFrame(0,1) = 0;
195 MeasurementFrame(0,2) = 0;
196 MeasurementFrame(1,0) = 0;
197 MeasurementFrame(1,1) = 1;
198 MeasurementFrame(1,2) = 0;
199 MeasurementFrame(2,0) = 0;
200 MeasurementFrame(2,1) = 0;
201 MeasurementFrame(2,2) = 1;
208 MITK_INFO <<
"BValue not specified in header file";
230 catch(std::exception& e)
232 MITK_INFO <<
"Std::Exception while reading file!!";
234 throw itk::ImageFileReaderException(__FILE__, __LINE__, e.what());
238 MITK_INFO <<
"Exception while reading file!!";
239 throw itk::ImageFileReaderException(__FILE__, __LINE__,
"Sorry, an error occurred while reading the requested vessel tree file!");
static const std::string REFERENCEBVALUEPROPERTYNAME
itk::SmartPointer< Self > Pointer
std::map< unsigned int, std::vector< unsigned int > > BValueMap
The BValueMap contains seperated IndicesVectors for each b value (index for GradientDirectionContaine...
static BValueMap CreateBValueMap(const GradientDirectionsContainerType *gdc, float referenceBValue)
DataCollection - Class to facilitate loading/accessing structured data.
mitk::DiffusionPropertyHelper::GradientDirectionType GradientDirectionType
virtual std::vector< itk::SmartPointer< BaseData > > Read() override
Reads a path or stream and creates a list of BaseData objects.
DiffusionImageNrrdReaderService()
itk::TimeStamp m_CacheTime
Image::Pointer GrabItkImageMemory(itk::SmartPointer< ItkOutputImageType > &itkimage, mitk::Image *mitkImage=nullptr, const BaseGeometry *geometry=nullptr, bool update=true)
Grabs the memory of an itk::Image (with a specific type) and puts it into an mitk::Image.The memory is managed by the mitk::Image after calling this function. The itk::Image remains valid until the mitk::Image decides to free the memory.
static const std::string MEASUREMENTFRAMEPROPERTYNAME
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
us::ServiceRegistration< IFileReader > RegisterService(us::ModuleContext *context=us::GetModuleContext())
Convenience class to temporarily change the current locale.
const CustomMimeType * GetMimeType() const
mitk::DiffusionPropertyHelper::MeasurementFrameType MeasurementFrameType
OutputType::Pointer m_OutputCache
Base class for creating mitk::BaseData objects from files or streams.
std::string GetExtension(const std::string &path) const
Provides the first matching extension.
virtual std::string GetInputLocation() const override
Get the current input location.
static const std::string GRADIENTCONTAINERPROPERTYNAME
static const std::string BVALUEMAPPROPERTYNAME
virtual ~DiffusionImageNrrdReaderService()
static const std::string ORIGINALGRADIENTCONTAINERPROPERTYNAME
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.