15 #pragma warning ( disable : 4786 ) 19 #define ITK_LEAN_AND_MEAN 24 #include "DWISimulatorCLP.h" 25 #include "itkImageFileWriter.h" 26 #include "itkVectorImage.h" 32 main(
int argc,
char *argv[])
38 typedef itk::VectorImage<float, 3> OutputImageType;
39 OutputImageType::Pointer outputImage;
41 typedef itk::Image<float, 3> ScalarImageType;
42 ScalarImageType::Pointer outputScalarImage;
46 GeneratorType::Pointer dwiGenerator = GeneratorType::New();
48 dwiGenerator->SetDebug(_DebugArg.isSet());
51 dwiGenerator->SetFileName( _ParameterFile );
53 && _OutputMSDFile==
"" && _OutputRTOFile==
"",
"need to set output dwi/odf/eap/peak/rto/msd");
54 dwiGenerator->SetIsOutputDWI(_OutputDWIFile!=
"");
55 dwiGenerator->SetIsOutputEAP(_OutputEAPFile!=
"");
56 dwiGenerator->SetIsOutputODF(_OutputODFFile!=
"");
57 dwiGenerator->SetIsOutputRTO(_OutputRTOFile!=
"");
58 dwiGenerator->SetIsOutputMSD(_OutputMSDFile!=
"");
59 if (_MaxNumberOfPeaks>0)
61 dwiGenerator->SetMaxNumberOfPeaks(_MaxNumberOfPeaks);
65 if ( _SNRArg.isSet() )
66 dwiGenerator->SetSNR( _SNR );
67 if (_NoiseSigmaArg.isSet())
68 dwiGenerator->SetNoiseSigma( _NoiseSigma );
70 utlGlobalException(_SNRArg.isSet() && _NoiseSigmaArg.isSet(),
"Only one of these is allowed: --snr or --noisesigma");
72 dwiGenerator->GetSamplingSchemeQSpace()->SetTau(_Tau);
73 dwiGenerator->GetSamplingSchemeRSpace()->SetTau(_Tau);
75 utlGlobalException(!_QSpaceOrientationsArg.isSet() && !_RSpaceOrientationsArg.isSet(),
"no gradient files in Q space and R space");
77 GeneratorType::STDVectorPointer bvec(
new GeneratorType::STDVectorType());
78 GeneratorType::STDVectorPointer rvec(
new GeneratorType::STDVectorType());
80 if (_QSpaceOrientationsArg.isSet())
82 utlGlobalException(!_BValuesArg.isSet() && !_BFileArg.isSet(),
"need to set --bvalues or --bfile");
83 utlGlobalException(_BValuesArg.isSet() && _BFileArg.isSet(),
"Only one of these is allowed: --bvalues or --bfile");
85 if (_BValuesArg.isSet())
87 if (_BFileArg.isSet())
92 utlGlobalException(_BFileArg.isSet() && _QSpaceOrientationsArg.isSet() && bvec->size()!=qMatrix->Rows(),
"The size in --bfile and --qorientations are not the same");
94 if (bvec->size()>0 && qMatrix->Rows()>0 && bvec->size()!=qMatrix->Rows())
96 dwiGenerator->GetSamplingSchemeQSpace()->SetOrientationsCartesian( qMatrix );
97 dwiGenerator->GetSamplingSchemeQSpace()->SetBVector(bvec);
100 if (_RSpaceOrientationsArg.isSet())
102 utlGlobalException(!_RValuesArg.isSet() && !_RFileArg.isSet(),
"need to set --rvalues or --rfile");
103 utlGlobalException(_RValuesArg.isSet() && _RFileArg.isSet(),
"Only one of these is allowed: --rvalues or --rfile");
105 if (_RValuesArg.isSet())
107 if (_RFileArg.isSet())
112 utlGlobalException(_RFileArg.isSet() && _RSpaceOrientationsArg.isSet() && rvec->size()!=rMatrix->Rows(),
"The size in --rfile and --rorientations are not the same");
114 if (rvec->size()>0 && rMatrix->Rows()>0 && rvec->size()!=rMatrix->Rows())
116 dwiGenerator->GetSamplingSchemeRSpace()->SetOrientationsCartesian( rMatrix );
117 dwiGenerator->GetSamplingSchemeRSpace()->SetRadiusVector(rvec);
121 if (_BackgroundDiffusionParametersArg.isSet())
122 dwiGenerator->SetBackgroundDiffusionParameterValues(_BackgroundDiffusionParameters);
125 GeneratorType::CylinderModelPointer cylinder = GeneratorType::CylinderModelType::New();
126 cylinder->SetLength(_CylinderParameters[0]);
127 cylinder->SetRadius(_CylinderParameters[1]);
128 cylinder->SetD0(_CylinderParameters[2]);
129 dwiGenerator->SetCylinderModel(cylinder);
131 dwiGenerator->Update();
136 if (_OutputDWIFile!=
"")
138 std::cout <<
"Writing DWI data ... " << std::endl;
139 outputImage = dwiGenerator->GetDWIImage();
140 if (_OutputDWIType!=
"4D")
143 DWIWriterType::Pointer writer = DWIWriterType::New();
144 writer->SetInput(outputImage);
145 if (_OutputDWIType==
"EACHSHELL")
146 writer->SetOutputEachShell(
true);
147 writer->SetSamplingSchemeQSpace(dwiGenerator->GetSamplingSchemeQSpace());
149 std::string outputFile_noext, outputFile_ext;
151 writer->SetConfigurationFile(outputFile_noext +
".txt");
152 writer->SetBFile(outputFile_noext +
"_b.txt");
153 writer->SetOrientationFile(outputFile_noext+
"_grad.txt");
154 writer->SetDWIFile(outputFile_noext +
".nii.gz");
159 itk::SaveImage<OutputImageType>(outputImage, _OutputDWIFile);
162 if ( _B0FileArg.isSet() )
163 itk::SaveImage<ScalarImageType>(dwiGenerator->GetB0Image(), _B0File);
166 if (_OutputEAPFile!=
"")
168 std::cout <<
"Writing EAP data ... " << std::endl;
169 outputImage = dwiGenerator->GetEAPImage();
171 itk::SaveImage<OutputImageType>(outputImage, _OutputEAPFile);
174 if (_OutputODFFile!=
"")
176 std::cout <<
"Writing ODF data ... " << std::endl;
177 outputImage = dwiGenerator->GetODFImage();
179 itk::SaveImage<OutputImageType>(outputImage, _OutputODFFile);
182 if (_OutputPeakFile!=
"")
184 std::cout <<
"Writing Peak data ... " << std::endl;
186 outputImage = dwiGenerator->GetPeakImage();
188 itk::SaveImage<OutputImageType>(outputImage, _OutputPeakFile);
191 if (_OutputRTOFile!=
"")
193 std::cout <<
"Writing RTO data ... " << std::endl;
194 outputScalarImage = dwiGenerator->GetRTOImage();
196 itk::SaveImage<ScalarImageType>(outputScalarImage, _OutputRTOFile);
199 if (_OutputMSDFile!=
"")
201 std::cout <<
"Writing MSD data ... " << std::endl;
202 outputScalarImage = dwiGenerator->GetMSDImage();
204 itk::SaveImage<ScalarImageType>(outputScalarImage, _OutputMSDFile);
helper functions specifically used in dmritool
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)
void ReadVector(const std::string &vectorStr, std::vector< T > &vec, const char *cc=" ")
Generate DWI data based on provided parameter file.
int main(int argc, char *argv[])
void GetFileExtension(const std::string &fileNameAbsolute, std::string &ext, std::string &fileNoExt)