19 #include "DWISingleVoxelSimulatorCLP.h" 27 main (
int argc,
char const* argv[])
32 typedef itk::VectorImage<float, 3> OutputImageType;
33 OutputImageType::Pointer outputImage;
34 typedef itk::Image<float, 3> B0ImageType;
37 GeneratorType::Pointer dwiGenerator = GeneratorType::New();
40 dwiGenerator->SetDiffusionParameterValues(_DiffusionParameters);
42 dwiGenerator->SetDebug(_DebugArg.isSet());
44 && _OutputMSDFile==
"" && _OutputRTOFile==
"",
"need to set output dwi/odf/eap/peak/rto/msd");
45 dwiGenerator->SetIsOutputDWI(_OutputDWIFile!=
"");
46 dwiGenerator->SetIsOutputEAP(_OutputEAPFile!=
"");
47 dwiGenerator->SetIsOutputODF(_OutputODFFile!=
"");
48 dwiGenerator->SetIsOutputRTO(_OutputRTOFile!=
"");
49 dwiGenerator->SetIsOutputMSD(_OutputMSDFile!=
"");
51 if ( _SNRArg.isSet() )
52 dwiGenerator->SetSNR( _SNR );
53 if (_NoiseSigmaArg.isSet())
54 dwiGenerator->SetNoiseSigma( _NoiseSigma );
55 utlGlobalException(_SNRArg.isSet() && _NoiseSigmaArg.isSet(),
"Only one of these is allowed: --snr or --noisesigma");
59 dwiGenerator->GetSamplingSchemeQSpace()->SetTau(_Tau);
60 dwiGenerator->GetSamplingSchemeRSpace()->SetTau(_Tau);
63 utlGlobalException(!_QSpaceOrientationsArg.isSet() && !_RSpaceOrientationsArg.isSet(),
"no gradient files in Q space and R space");
65 GeneratorType::STDVectorPointer bvec(
new GeneratorType::STDVectorType());
66 GeneratorType::STDVectorPointer rvec(
new GeneratorType::STDVectorType());
68 if (_QSpaceOrientationsArg.isSet())
70 utlGlobalException(!_BValuesArg.isSet() && !_BFileArg.isSet(),
"need to set --bvalues or --bfile");
71 utlGlobalException(_BValuesArg.isSet() && _BFileArg.isSet(),
"Only one of these is allowed: --bvalues or --bfile");
73 if (_BValuesArg.isSet())
75 if (_BFileArg.isSet())
80 if (bvec->size()>0 && qMatrix->Rows()>0 && bvec->size()!=qMatrix->Rows())
82 dwiGenerator->GetSamplingSchemeQSpace()->SetOrientationsCartesian( qMatrix );
83 dwiGenerator->GetSamplingSchemeQSpace()->SetBVector(bvec);
86 if (_RSpaceOrientationsArg.isSet())
88 utlGlobalException(!_RValuesArg.isSet() && !_RFileArg.isSet(),
"need to set --rvalues or --rfile");
89 utlGlobalException(_RValuesArg.isSet() && _RFileArg.isSet(),
"Only one of these is allowed: --rvalues or --rfile");
91 if (_RValuesArg.isSet())
93 if (_RFileArg.isSet())
98 if (rvec->size()>0 && rMatrix->Rows()>0 && rvec->size()!=rMatrix->Rows())
100 dwiGenerator->GetSamplingSchemeRSpace()->SetOrientationsCartesian( rMatrix );
101 dwiGenerator->GetSamplingSchemeRSpace()->SetRadiusVector(rvec);
104 if (_B0ScaleArg.isSet())
105 dwiGenerator->SetB0Scale(_B0Scale);
107 if (_ModelType==
"TENSOR_SPHERICAL")
108 dwiGenerator->SetModelType(GeneratorType::SYMMETRICAL_TENSOR_IN_SPHERICAL_COORDS);
109 else if (_ModelType==
"TENSOR_CARTESIAN")
110 dwiGenerator->SetModelType(GeneratorType::SYMMETRICAL_TENSOR_IN_CARTESIAN_COORDS);
111 else if (_ModelType==
"CYLINDER_SPHERICAL")
112 dwiGenerator->SetModelType(GeneratorType::CYLINDER_SPHERICAL_MODEL);
114 if (_RandomType==
"FIXED")
115 dwiGenerator->SetRandomType(GeneratorType::FIXED);
116 else if (_RandomType==
"UNIFORM")
118 dwiGenerator->SetRandomType(GeneratorType::UNIFORM);
119 utlSAGlobalException(_TessellationOrder>0 && _ElecNumber>0).msg(
"only one of --elecnumber and --tessorder can be set");
120 if (_TessellationOrder>0)
121 dwiGenerator->SetUniformFromTessellation(_TessellationOrder);
123 dwiGenerator->SetUniformFromElectrostaticEnergy(_ElecNumber);
127 OutputImageType::SizeType size;
128 for (
int i = 0; i < 3; i += 1 )
130 dwiGenerator->SetOutputSize(size);
132 if (_MaxNumberOfPeaks>0)
134 dwiGenerator->SetMaxNumberOfPeaks(_MaxNumberOfPeaks);
138 dwiGenerator->Update();
143 if (_OutputDWIFile!=
"")
145 std::cout <<
"Writing DWI data ... " << std::endl;
146 outputImage = dwiGenerator->GetDWIImage();
147 if (_OutputDWIType!=
"4D")
150 DWIWriterType::Pointer writer = DWIWriterType::New();
151 writer->SetInput(outputImage);
152 if (_OutputDWIType==
"EACHSHELL")
153 writer->SetOutputEachShell(
true);
154 writer->SetSamplingSchemeQSpace(dwiGenerator->GetSamplingSchemeQSpace());
156 std::string outputFile_noext, outputFile_ext;
158 writer->SetConfigurationFile(outputFile_noext +
".txt");
159 writer->SetBFile(outputFile_noext +
"_b.txt");
160 writer->SetOrientationFile(outputFile_noext+
"_grad.txt");
161 writer->SetDWIFile(outputFile_noext +
".nii.gz");
166 itk::SaveImage<OutputImageType>(outputImage, _OutputDWIFile);
169 if ( _B0FileArg.isSet() )
170 itk::SaveImage<B0ImageType>(dwiGenerator->GetB0Image(), _B0File);
173 if (_OutputEAPFile!=
"")
175 std::cout <<
"Writing EAP data ... " << std::endl;
176 outputImage = dwiGenerator->GetEAPImage();
178 itk::SaveImage<OutputImageType>(outputImage, _OutputEAPFile);
181 if (_OutputODFFile!=
"")
183 std::cout <<
"Writing ODF data ... " << std::endl;
184 outputImage = dwiGenerator->GetODFImage();
186 itk::SaveImage<OutputImageType>(outputImage, _OutputODFFile);
189 if (_OutputPeakFile!=
"")
191 std::cout <<
"Writing Peak data ... " << std::endl;
193 outputImage = dwiGenerator->GetPeakImage();
195 itk::SaveImage<OutputImageType>(outputImage, _OutputPeakFile);
bool IsImageEmpty(const SmartPointer< ImageType > &image)
void MatchBVectorAndGradientMatrix(const T &br, std::vector< T > &vec, const NDArray< T, 2 > &grad)
#define utlException(cond, expout)
#define utlSAGlobalException(expr)
static PeakType GetPeakType(const std::string &str)
#define utlGlobalException(cond, expout)
write gradient file, b values and DWI files (with optional index file)
Generate DWI data with the same diffusion parameter set for all voxels. If random mode is used...
void ReadVector(const std::string &vectorStr, std::vector< T > &vec, const char *cc=" ")
void GetFileExtension(const std::string &fileNameAbsolute, std::string &ext, std::string &fileNoExt)
int main(int argc, char const *argv[])
Simulate DWI data with fixed single voxel configuration.