forked from BRAINSia/BRAINSTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNRRDDWIConverter.cxx
116 lines (99 loc) · 3.88 KB
/
NRRDDWIConverter.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// Created by Johnson, Hans J on 11/25/16.
//
#include "NRRDDWIConverter.h"
NRRDDWIConverter::NRRDDWIConverter( const DWIConverter::FileNamesContainer & inputFileNames )
: DWIConverter( inputFileNames )
{}
void
NRRDDWIConverter::AddFlagsToDictionary()
{}
Volume4DType::Pointer
NRRDDWIConverter::CreateVolume( VectorVolumeType::Pointer & vector3DVolume )
{
VectorVolumeType::SizeType inputSize = vector3DVolume->GetLargestPossibleRegion().GetSize();
VectorVolumeType::SpacingType inputSpacing = vector3DVolume->GetSpacing();
VectorVolumeType::PointType inputOrigin = vector3DVolume->GetOrigin();
VectorVolumeType::DirectionType inputDirection = vector3DVolume->GetDirection();
Volume4DType::Pointer fourDVolume = Volume4DType::New();
Volume4DType::SizeType volSize;
Volume4DType::SpacingType volSpacing;
Volume4DType::PointType volOrigin;
Volume4DType::DirectionType volDirection;
for ( unsigned int i = 0; i < 3; ++i )
{
volSize[i] = inputSize[i];
volSpacing[i] = inputSpacing[i];
volOrigin[i] = inputOrigin[i];
for ( unsigned int j = 0; j < 3; ++j )
{
volDirection[i][j] = inputDirection[i][j];
}
volDirection[3][i] = 0.0;
volDirection[i][3] = 0.0;
}
volDirection[3][3] = 1.0;
volSpacing[3] = 1.0;
volOrigin[3] = 0.0;
volSize[3] = vector3DVolume->GetNumberOfComponentsPerPixel();
fourDVolume->SetRegions( volSize );
fourDVolume->SetOrigin( volOrigin );
fourDVolume->SetSpacing( volSpacing );
fourDVolume->SetDirection( volDirection );
fourDVolume->Allocate();
const Volume4DType::IndexType::IndexValueType vecLength = vector3DVolume->GetNumberOfComponentsPerPixel();
VectorVolumeType::IndexType vecIndex;
Volume4DType::IndexType volIndex;
// convert from vector image to 4D volume image
for ( volIndex[3] = 0; volIndex[3] < vecLength; ++volIndex[3] )
{
for ( volIndex[2] = 0; volIndex[2] < static_cast< Volume4DType::IndexType::IndexValueType >( inputSize[2] );
++volIndex[2] )
{
vecIndex[2] = volIndex[2];
for ( volIndex[1] = 0; volIndex[1] < static_cast< Volume4DType::IndexType::IndexValueType >( inputSize[1] );
++volIndex[1] )
{
vecIndex[1] = volIndex[1];
for ( volIndex[0] = 0; volIndex[0] < static_cast< Volume4DType::IndexType::IndexValueType >( inputSize[0] );
++volIndex[0] )
{
vecIndex[0] = volIndex[0];
fourDVolume->SetPixel( volIndex, vector3DVolume->GetPixel( vecIndex )[volIndex[3]] );
}
}
}
}
fourDVolume->SetMetaDataDictionary( vector3DVolume->GetMetaDataDictionary() );
return fourDVolume;
}
void
NRRDDWIConverter::LoadFromDisk()
{
const std::string nrrdNRRDFile = m_InputFileNames[0];
VectorVolumeType::Pointer vector3DVolume;
if ( ReadVectorVolume< VectorVolumeType >( vector3DVolume, nrrdNRRDFile, this->m_allowLossyConversion ) !=
EXIT_SUCCESS )
{
itkGenericExceptionMacro( << "ERROR Reading NRRD File : " << nrrdNRRDFile << std::endl; );
}
// Conert vector 3D volume to 4DVolume
Volume4DType::Pointer fourDVolume = CreateVolume( vector3DVolume );
this->m_SlicesPerVolume = fourDVolume->GetLargestPossibleRegion().GetSize()[2];
this->m_NVolume = fourDVolume->GetLargestPossibleRegion().GetSize()[3];
this->m_NSlice = this->m_SlicesPerVolume * this->m_NVolume;
this->m_Volume = FourDToThreeDImage( fourDVolume );
}
void
NRRDDWIConverter::ExtractDWIData()
{
RecoverMeasurementFrame< Volume3DUnwrappedType >( this->m_Volume.GetPointer(), this->m_MeasurementFrame );
RecoverBVectors< Volume3DUnwrappedType >( this->m_Volume.GetPointer(), this->m_DiffusionVectors );
RecoverBValues< Volume3DUnwrappedType >( this->m_Volume.GetPointer(), this->m_DiffusionVectors, this->m_BValues );
readThicknessFromDict();
}
DWIConverter::CommonDicomFieldMapType
NRRDDWIConverter::GetCommonDicomFieldsMap() const
{
return CommonDicomFieldMapType();
}