17 #define RAPIDXML_NO_EXCEPTIONS
18 #include <boost/foreach.hpp>
19 #include <boost/lexical_cast.hpp>
20 #include <itkImageFileWriter.h>
21 #include <itkImageFileReader.h>
25 template<
class ScalarType >
32 template<
class ScalarType >
41 int NPoints = 2*m_NumGradients;
42 m_GradientDirections.clear();
44 m_NumBaseline = NPoints/20;
50 for (
unsigned int i=0; i<m_NumBaseline; i++)
51 m_GradientDirections.push_back(g);
56 vnl_vector<double> theta; theta.set_size(NPoints);
57 vnl_vector<double> phi; phi.set_size(NPoints);
58 double C = sqrt(4*
M_PI);
61 for(
int i=0; i<NPoints; i++)
63 theta(i) = acos(-1.0+2.0*i/(NPoints-1.0)) -
M_PI / 2.0;
64 if( i>0 && i<NPoints-1)
66 phi(i) = (phi(i-1) + C /
67 sqrt(NPoints*(1-(-1.0+2.0*i/(NPoints-1.0))*(-1.0+2.0*i/(NPoints-1.0)))));
71 for(
int i=0; i<NPoints; i++)
76 g[0] = cos(theta(i)) * cos(phi(i));
77 g[1] = cos(theta(i)) * sin(phi(i));
78 m_GradientDirections.push_back(g);
84 std::vector< int > result;
85 for(
unsigned int i=0; i<this->m_GradientDirections.size(); i++)
86 if (m_GradientDirections.at(i).GetNorm()<0.0001)
93 for(
unsigned int i=0; i<this->m_GradientDirections.size(); i++)
94 if (m_GradientDirections.at(i).GetNorm()<0.0001)
101 if (m_GradientDirections.size()>idx && m_GradientDirections.at(idx).GetNorm()<0.0001)
108 return m_NumGradients;
113 return m_NumBaseline;
118 return m_GradientDirections.size();
123 return m_GradientDirections;
128 return m_GradientDirections.at(i);
133 m_NumGradients = numGradients;
134 GenerateGradientHalfShell();
139 m_GradientDirections = gradientList;
142 for(
unsigned int i=0; i<this->m_GradientDirections.size(); i++)
144 if (m_GradientDirections.at(i).GetNorm()>0.0001)
155 m_GradientDirections.clear();
157 for(
unsigned int i=0; i<gradientList->Size(); i++)
160 g[0] = gradientList->at(i)[0];
161 g[1] = gradientList->at(i)[1];
162 g[2] = gradientList->at(i)[2];
163 m_GradientDirections.push_back(g);
165 if (m_GradientDirections.at(i).GetNorm()>0.0001)
172 template<
class ScalarType >
177 if(
".ffp"!=filename.substr(filename.size()-4, 4))
180 const std::string& locale =
"C";
181 const std::string& currLocale = setlocale( LC_ALL, NULL );
183 if ( locale.compare(currLocale)!=0 )
187 setlocale(LC_ALL, locale.c_str());
191 MITK_INFO <<
"Could not set locale " << locale;
195 boost::property_tree::ptree parameters;
198 parameters.put(
"fiberfox.fibers.distribution", m_FiberGen.m_Distribution);
199 parameters.put(
"fiberfox.fibers.variance", m_FiberGen.m_Variance);
200 parameters.put(
"fiberfox.fibers.density", m_FiberGen.m_Density);
201 parameters.put(
"fiberfox.fibers.spline.sampling", m_FiberGen.m_Sampling);
202 parameters.put(
"fiberfox.fibers.spline.tension", m_FiberGen.m_Tension);
203 parameters.put(
"fiberfox.fibers.spline.continuity", m_FiberGen.m_Continuity);
204 parameters.put(
"fiberfox.fibers.spline.bias", m_FiberGen.m_Bias);
205 parameters.put(
"fiberfox.fibers.rotation.x", m_FiberGen.m_Rotation[0]);
206 parameters.put(
"fiberfox.fibers.rotation.y", m_FiberGen.m_Rotation[1]);
207 parameters.put(
"fiberfox.fibers.rotation.z", m_FiberGen.m_Rotation[2]);
208 parameters.put(
"fiberfox.fibers.translation.x", m_FiberGen.m_Translation[0]);
209 parameters.put(
"fiberfox.fibers.translation.y", m_FiberGen.m_Translation[1]);
210 parameters.put(
"fiberfox.fibers.translation.z", m_FiberGen.m_Translation[2]);
211 parameters.put(
"fiberfox.fibers.scale.x", m_FiberGen.m_Scale[0]);
212 parameters.put(
"fiberfox.fibers.scale.y", m_FiberGen.m_Scale[1]);
213 parameters.put(
"fiberfox.fibers.scale.z", m_FiberGen.m_Scale[2]);
216 parameters.put(
"fiberfox.image.basic.size.x", m_SignalGen.m_ImageRegion.GetSize(0));
217 parameters.put(
"fiberfox.image.basic.size.y", m_SignalGen.m_ImageRegion.GetSize(1));
218 parameters.put(
"fiberfox.image.basic.size.z", m_SignalGen.m_ImageRegion.GetSize(2));
219 parameters.put(
"fiberfox.image.basic.spacing.x", m_SignalGen.m_ImageSpacing[0]);
220 parameters.put(
"fiberfox.image.basic.spacing.y", m_SignalGen.m_ImageSpacing[1]);
221 parameters.put(
"fiberfox.image.basic.spacing.z", m_SignalGen.m_ImageSpacing[2]);
222 parameters.put(
"fiberfox.image.basic.origin.x", m_SignalGen.m_ImageOrigin[0]);
223 parameters.put(
"fiberfox.image.basic.origin.y", m_SignalGen.m_ImageOrigin[1]);
224 parameters.put(
"fiberfox.image.basic.origin.z", m_SignalGen.m_ImageOrigin[2]);
225 parameters.put(
"fiberfox.image.basic.direction.1", m_SignalGen.m_ImageDirection[0][0]);
226 parameters.put(
"fiberfox.image.basic.direction.2", m_SignalGen.m_ImageDirection[0][1]);
227 parameters.put(
"fiberfox.image.basic.direction.3", m_SignalGen.m_ImageDirection[0][2]);
228 parameters.put(
"fiberfox.image.basic.direction.4", m_SignalGen.m_ImageDirection[1][0]);
229 parameters.put(
"fiberfox.image.basic.direction.5", m_SignalGen.m_ImageDirection[1][1]);
230 parameters.put(
"fiberfox.image.basic.direction.6", m_SignalGen.m_ImageDirection[1][2]);
231 parameters.put(
"fiberfox.image.basic.direction.7", m_SignalGen.m_ImageDirection[2][0]);
232 parameters.put(
"fiberfox.image.basic.direction.8", m_SignalGen.m_ImageDirection[2][1]);
233 parameters.put(
"fiberfox.image.basic.direction.9", m_SignalGen.m_ImageDirection[2][2]);
234 parameters.put(
"fiberfox.image.basic.numgradients", m_SignalGen.GetNumWeightedVolumes());
235 for(
unsigned int i=0; i<this->m_SignalGen.GetNumVolumes(); i++)
237 parameters.put(
"fiberfox.image.gradients."+boost::lexical_cast<string>(i)+
".x", m_SignalGen.GetGradientDirection(i)[0]);
238 parameters.put(
"fiberfox.image.gradients."+boost::lexical_cast<string>(i)+
".y", m_SignalGen.GetGradientDirection(i)[1]);
239 parameters.put(
"fiberfox.image.gradients."+boost::lexical_cast<string>(i)+
".z", m_SignalGen.GetGradientDirection(i)[2]);
242 parameters.put(
"fiberfox.image.acquisitiontype", m_SignalGen.m_AcquisitionType);
243 parameters.put(
"fiberfox.image.coilsensitivityprofile", m_SignalGen.m_CoilSensitivityProfile);
244 parameters.put(
"fiberfox.image.numberofcoils", m_SignalGen.m_NumberOfCoils);
245 parameters.put(
"fiberfox.image.reversephase", m_SignalGen.m_ReversePhase);
246 parameters.put(
"fiberfox.image.partialfourier", m_SignalGen.m_PartialFourier);
247 parameters.put(
"fiberfox.image.noisevariance", m_SignalGen.m_NoiseVariance);
248 parameters.put(
"fiberfox.image.trep", m_SignalGen.m_tRep);
249 parameters.put(
"fiberfox.image.signalScale", m_SignalGen.m_SignalScale);
250 parameters.put(
"fiberfox.image.tEcho", m_SignalGen.m_tEcho);
251 parameters.put(
"fiberfox.image.tLine", m_SignalGen.m_tLine);
252 parameters.put(
"fiberfox.image.tInhom", m_SignalGen.m_tInhom);
253 parameters.put(
"fiberfox.image.bvalue", m_SignalGen.m_Bvalue);
254 parameters.put(
"fiberfox.image.simulatekspace", m_SignalGen.m_SimulateKspaceAcquisition);
255 parameters.put(
"fiberfox.image.axonRadius", m_SignalGen.m_AxonRadius);
256 parameters.put(
"fiberfox.image.doSimulateRelaxation", m_SignalGen.m_DoSimulateRelaxation);
257 parameters.put(
"fiberfox.image.doDisablePartialVolume", m_SignalGen.m_DoDisablePartialVolume);
258 parameters.put(
"fiberfox.image.artifacts.spikesnum", m_SignalGen.m_Spikes);
259 parameters.put(
"fiberfox.image.artifacts.spikesscale", m_SignalGen.m_SpikeAmplitude);
260 parameters.put(
"fiberfox.image.artifacts.kspaceLineOffset", m_SignalGen.m_KspaceLineOffset);
261 parameters.put(
"fiberfox.image.artifacts.eddyStrength", m_SignalGen.m_EddyStrength);
262 parameters.put(
"fiberfox.image.artifacts.eddyTau", m_SignalGen.m_Tau);
263 parameters.put(
"fiberfox.image.artifacts.aliasingfactor", m_SignalGen.m_CroppingFactor);
264 parameters.put(
"fiberfox.image.artifacts.addringing", m_SignalGen.m_DoAddGibbsRinging);
265 parameters.put(
"fiberfox.image.artifacts.doAddMotion", m_SignalGen.m_DoAddMotion);
266 parameters.put(
"fiberfox.image.artifacts.randomMotion", m_SignalGen.m_DoRandomizeMotion);
267 parameters.put(
"fiberfox.image.artifacts.translation0", m_SignalGen.m_Translation[0]);
268 parameters.put(
"fiberfox.image.artifacts.translation1", m_SignalGen.m_Translation[1]);
269 parameters.put(
"fiberfox.image.artifacts.translation2", m_SignalGen.m_Translation[2]);
270 parameters.put(
"fiberfox.image.artifacts.rotation0", m_SignalGen.m_Rotation[0]);
271 parameters.put(
"fiberfox.image.artifacts.rotation1", m_SignalGen.m_Rotation[1]);
272 parameters.put(
"fiberfox.image.artifacts.rotation2", m_SignalGen.m_Rotation[2]);
273 parameters.put(
"fiberfox.image.artifacts.motionvolumes", m_Misc.m_MotionVolumesBox);
274 parameters.put(
"fiberfox.image.artifacts.addnoise", m_Misc.m_CheckAddNoiseBox);
275 parameters.put(
"fiberfox.image.artifacts.addghosts", m_Misc.m_CheckAddGhostsBox);
276 parameters.put(
"fiberfox.image.artifacts.addaliasing", m_Misc.m_CheckAddAliasingBox);
277 parameters.put(
"fiberfox.image.artifacts.addspikes", m_Misc.m_CheckAddSpikesBox);
278 parameters.put(
"fiberfox.image.artifacts.addeddycurrents", m_Misc.m_CheckAddEddyCurrentsBox);
279 parameters.put(
"fiberfox.image.artifacts.doAddDistortions", m_Misc.m_CheckAddDistortionsBox);
280 parameters.put(
"fiberfox.image.outputvolumefractions", m_Misc.m_CheckOutputVolumeFractionsBox);
281 parameters.put(
"fiberfox.image.showadvanced", m_Misc.m_CheckAdvancedSignalOptionsBox);
282 parameters.put(
"fiberfox.image.signalmodelstring", m_Misc.m_SignalModelString);
283 parameters.put(
"fiberfox.image.artifactmodelstring", m_Misc.m_ArtifactModelString);
284 parameters.put(
"fiberfox.image.outpath", m_Misc.m_OutputPath);
285 parameters.put(
"fiberfox.fibers.realtime", m_Misc.m_CheckRealTimeFibersBox);
286 parameters.put(
"fiberfox.fibers.showadvanced", m_Misc.m_CheckAdvancedFiberOptionsBox);
287 parameters.put(
"fiberfox.fibers.constantradius", m_Misc.m_CheckConstantRadiusBox);
288 parameters.put(
"fiberfox.fibers.includeFiducials", m_Misc.m_CheckIncludeFiducialsBox);
290 if (m_NoiseModel!=NULL)
292 parameters.put(
"fiberfox.image.artifacts.noisevariance", m_NoiseModel->GetNoiseVariance());
294 parameters.put(
"fiberfox.image.artifacts.noisetype",
"rice");
296 parameters.put(
"fiberfox.image.artifacts.noisetype",
"chisquare");
299 for (
int i=0; i<m_FiberModelList.size()+m_NonFiberModelList.size(); i++)
302 if (i<m_FiberModelList.size())
304 signalModel = m_FiberModelList.at(i);
305 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".type",
"fiber");
309 signalModel = m_NonFiberModelList.at(i-m_FiberModelList.size());
310 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".type",
"non-fiber");
316 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".model",
"stick");
317 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".d", model->
GetDiffusivity());
318 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t2", model->
GetT2());
319 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t1", model->
GetT1());
324 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".model",
"tensor");
325 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".d1", model->
GetDiffusivity1());
326 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".d2", model->
GetDiffusivity2());
327 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".d3", model->
GetDiffusivity3());
328 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t2", model->
GetT2());
329 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t1", model->
GetT1());
334 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".model",
"prototype");
335 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".minFA", model->
GetFaRange().first);
336 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".maxFA", model->
GetFaRange().second);
337 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".minADC", model->
GetAdcRange().first);
338 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".maxADC", model->
GetAdcRange().second);
339 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".maxNumSamples", model->
GetMaxNumKernels());
340 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".numSamples", model->
GetNumberOfKernels());
342 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".numCoeffs", (shOrder*shOrder + shOrder + 2)/2 + shOrder);
347 for (
unsigned int k=0; k<coeffs.size(); k++)
348 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".kernels."+boost::lexical_cast<string>(j)+
".coeffs."+boost::lexical_cast<string>(k), coeffs[k]);
349 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".kernels."+boost::lexical_cast<string>(j)+
".B0", model->
GetBaselineSignal(j));
355 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".model",
"ball");
356 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".d", model->
GetDiffusivity());
357 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t2", model->
GetT2());
358 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t1", model->
GetT1());
363 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".model",
"astrosticks");
364 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".d", model->
GetDiffusivity());
365 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t2", model->
GetT2());
366 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t1", model->
GetT1());
367 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".randomize", model->
GetRandomizeSticks());
372 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".model",
"dot");
373 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t2", model->
GetT2());
374 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".t1", model->
GetT1());
377 if (signalModel!=NULL)
379 parameters.put(
"fiberfox.image.compartments."+boost::lexical_cast<string>(i)+
".ID", signalModel->
m_CompartmentId);
385 writer->SetFileName(filename+
"_VOLUME"+boost::lexical_cast<string>(signalModel->
m_CompartmentId)+
".nrrd");
388 MITK_INFO <<
"Volume fraction image for compartment "+boost::lexical_cast<
string>(signalModel->
m_CompartmentId)+
" saved.";
397 boost::property_tree::xml_writer_settings<std::string> writerSettings(
' ', 2);
398 boost::property_tree::xml_parser::write_xml(filename, parameters, std::locale(), writerSettings);
402 writer->SetFileName(filename+
"_FMAP.nrrd");
403 writer->SetInput(m_SignalGen.m_FrequencyMap);
412 writer->SetFileName(filename+
"_MASK.nrrd");
413 writer->SetInput(m_SignalGen.m_MaskImage);
421 setlocale(LC_ALL, currLocale.c_str());
425 template<
class ScalarType >
426 template<
class ParameterType >
431 return v.second.get<ParameterType>(tag);
437 mitkThrow() <<
"Parameter file corrupted. Essential tag is missing: '" << tag <<
"'";
439 if (tag!=
"artifacts.noisetype")
441 MITK_INFO <<
"Tag '" << tag <<
"' not found. Using default value '" << defaultValue <<
"'.";
442 m_MissingTags +=
"\n- ";
443 m_MissingTags += tag;
449 template<
class ScalarType >
453 if(filename.empty()) {
return; }
455 const std::string& locale =
"C";
456 const std::string& currLocale = setlocale( LC_ALL, NULL );
458 if ( locale.compare(currLocale)!=0 )
462 setlocale(LC_ALL, locale.c_str());
466 MITK_INFO <<
"Could not set locale " << locale;
471 boost::property_tree::ptree parameterTree;
472 boost::property_tree::xml_parser::read_xml( filename, parameterTree );
475 m_FiberModelList.clear();
476 m_NonFiberModelList.clear();
477 if (m_NoiseModel) { m_NoiseModel =
nullptr; }
479 BOOST_FOREACH( boost::property_tree::ptree::value_type
const& v1, parameterTree.get_child(
"fiberfox") )
481 if( v1.first ==
"fibers" )
483 m_Misc.m_CheckRealTimeFibersBox = ReadVal<bool>(v1,
"realtime", m_Misc.m_CheckRealTimeFibersBox);
484 m_Misc.m_CheckAdvancedFiberOptionsBox = ReadVal<bool>(v1,
"showadvanced", m_Misc.m_CheckAdvancedFiberOptionsBox);
485 m_Misc.m_CheckConstantRadiusBox = ReadVal<bool>(v1,
"constantradius", m_Misc.m_CheckConstantRadiusBox);
486 m_Misc.m_CheckIncludeFiducialsBox = ReadVal<bool>(v1,
"includeFiducials", m_Misc.m_CheckIncludeFiducialsBox);
488 switch (ReadVal<unsigned int>(v1,
"distribution", 0))
499 m_FiberGen.m_Variance = ReadVal<double>(v1,
"variance", m_FiberGen.m_Variance);
500 m_FiberGen.m_Density = ReadVal<unsigned int>(v1,
"density", m_FiberGen.m_Density);
501 m_FiberGen.m_Sampling = ReadVal<double>(v1,
"spline.sampling", m_FiberGen.m_Sampling);
502 m_FiberGen.m_Tension = ReadVal<double>(v1,
"spline.tension", m_FiberGen.m_Tension);
503 m_FiberGen.m_Continuity = ReadVal<double>(v1,
"spline.continuity", m_FiberGen.m_Continuity);
504 m_FiberGen.m_Bias = ReadVal<double>(v1,
"spline.bias", m_FiberGen.m_Bias);
505 m_FiberGen.m_Rotation[0] = ReadVal<double>(v1,
"rotation.x", m_FiberGen.m_Rotation[0]);
506 m_FiberGen.m_Rotation[1] = ReadVal<double>(v1,
"rotation.y", m_FiberGen.m_Rotation[1]);
507 m_FiberGen.m_Rotation[2] = ReadVal<double>(v1,
"rotation.z", m_FiberGen.m_Rotation[2]);
508 m_FiberGen.m_Translation[0] = ReadVal<double>(v1,
"translation.x", m_FiberGen.m_Translation[0]);
509 m_FiberGen.m_Translation[1] = ReadVal<double>(v1,
"translation.y", m_FiberGen.m_Translation[1]);
510 m_FiberGen.m_Translation[2] = ReadVal<double>(v1,
"translation.z", m_FiberGen.m_Translation[2]);
511 m_FiberGen.m_Scale[0] = ReadVal<double>(v1,
"scale.x", m_FiberGen.m_Scale[0]);
512 m_FiberGen.m_Scale[1] = ReadVal<double>(v1,
"scale.y", m_FiberGen.m_Scale[1]);
513 m_FiberGen.m_Scale[2] = ReadVal<double>(v1,
"scale.z", m_FiberGen.m_Scale[2]);
515 else if ( v1.first ==
"image" )
517 m_Misc.m_SignalModelString = ReadVal<string>(v1,
"signalmodelstring", m_Misc.m_SignalModelString);
518 m_Misc.m_ArtifactModelString = ReadVal<string>(v1,
"artifactmodelstring", m_Misc.m_ArtifactModelString);
519 m_Misc.m_OutputPath = ReadVal<string>(v1,
"outpath", m_Misc.m_OutputPath);
520 m_Misc.m_CheckOutputVolumeFractionsBox = ReadVal<bool>(v1,
"outputvolumefractions", m_Misc.m_CheckOutputVolumeFractionsBox);
521 m_Misc.m_CheckAdvancedSignalOptionsBox = ReadVal<bool>(v1,
"showadvanced", m_Misc.m_CheckAdvancedSignalOptionsBox);
522 m_Misc.m_CheckAddDistortionsBox = ReadVal<bool>(v1,
"artifacts.doAddDistortions", m_Misc.m_CheckAddDistortionsBox);
523 m_Misc.m_CheckAddNoiseBox = ReadVal<bool>(v1,
"artifacts.addnoise", m_Misc.m_CheckAddNoiseBox);
524 m_Misc.m_CheckAddGhostsBox = ReadVal<bool>(v1,
"artifacts.addghosts", m_Misc.m_CheckAddGhostsBox);
525 m_Misc.m_CheckAddAliasingBox = ReadVal<bool>(v1,
"artifacts.addaliasing", m_Misc.m_CheckAddAliasingBox);
526 m_Misc.m_CheckAddSpikesBox = ReadVal<bool>(v1,
"artifacts.addspikes", m_Misc.m_CheckAddSpikesBox);
527 m_Misc.m_CheckAddEddyCurrentsBox = ReadVal<bool>(v1,
"artifacts.addeddycurrents", m_Misc.m_CheckAddEddyCurrentsBox);
529 m_SignalGen.m_ImageRegion.SetSize(0, ReadVal<int>(v1,
"basic.size.x",m_SignalGen.m_ImageRegion.GetSize(0)));
530 m_SignalGen.m_ImageRegion.SetSize(1, ReadVal<int>(v1,
"basic.size.y",m_SignalGen.m_ImageRegion.GetSize(1)));
531 m_SignalGen.m_ImageRegion.SetSize(2, ReadVal<int>(v1,
"basic.size.z",m_SignalGen.m_ImageRegion.GetSize(2)));
532 m_SignalGen.m_ImageSpacing[0] = ReadVal<double>(v1,
"basic.spacing.x",m_SignalGen.m_ImageSpacing[0]);
533 m_SignalGen.m_ImageSpacing[1] = ReadVal<double>(v1,
"basic.spacing.y",m_SignalGen.m_ImageSpacing[1]);
534 m_SignalGen.m_ImageSpacing[2] = ReadVal<double>(v1,
"basic.spacing.z",m_SignalGen.m_ImageSpacing[2]);
535 m_SignalGen.m_ImageOrigin[0] = ReadVal<double>(v1,
"basic.origin.x",m_SignalGen.m_ImageOrigin[0]);
536 m_SignalGen.m_ImageOrigin[1] = ReadVal<double>(v1,
"basic.origin.y",m_SignalGen.m_ImageOrigin[1]);
537 m_SignalGen.m_ImageOrigin[2] = ReadVal<double>(v1,
"basic.origin.z",m_SignalGen.m_ImageOrigin[2]);
538 m_SignalGen.m_ImageDirection[0][0] = ReadVal<double>(v1,
"basic.direction.1",m_SignalGen.m_ImageDirection[0][0]);
539 m_SignalGen.m_ImageDirection[0][1] = ReadVal<double>(v1,
"basic.direction.2",m_SignalGen.m_ImageDirection[0][1]);
540 m_SignalGen.m_ImageDirection[0][2] = ReadVal<double>(v1,
"basic.direction.3",m_SignalGen.m_ImageDirection[0][2]);
541 m_SignalGen.m_ImageDirection[1][0] = ReadVal<double>(v1,
"basic.direction.4",m_SignalGen.m_ImageDirection[1][0]);
542 m_SignalGen.m_ImageDirection[1][1] = ReadVal<double>(v1,
"basic.direction.5",m_SignalGen.m_ImageDirection[1][1]);
543 m_SignalGen.m_ImageDirection[1][2] = ReadVal<double>(v1,
"basic.direction.6",m_SignalGen.m_ImageDirection[1][2]);
544 m_SignalGen.m_ImageDirection[2][0] = ReadVal<double>(v1,
"basic.direction.7",m_SignalGen.m_ImageDirection[2][0]);
545 m_SignalGen.m_ImageDirection[2][1] = ReadVal<double>(v1,
"basic.direction.8",m_SignalGen.m_ImageDirection[2][1]);
546 m_SignalGen.m_ImageDirection[2][2] = ReadVal<double>(v1,
"basic.direction.9",m_SignalGen.m_ImageDirection[2][2]);
549 ReadVal<int>(v1,
"acquisitiontype", m_SignalGen.m_AcquisitionType);
551 ReadVal<int>(v1,
"coilsensitivityprofile", m_SignalGen.m_CoilSensitivityProfile);
552 m_SignalGen.m_NumberOfCoils = ReadVal<int>(v1,
"numberofcoils", m_SignalGen.m_NumberOfCoils);
553 m_SignalGen.m_ReversePhase = ReadVal<bool>(v1,
"reversephase", m_SignalGen.m_ReversePhase);
554 m_SignalGen.m_PartialFourier = ReadVal<double>(v1,
"partialfourier", m_SignalGen.m_PartialFourier);
555 m_SignalGen.m_NoiseVariance = ReadVal<double>(v1,
"noisevariance", m_SignalGen.m_NoiseVariance);
556 m_SignalGen.m_tRep = ReadVal<double>(v1,
"trep", m_SignalGen.m_tRep);
557 m_SignalGen.m_SignalScale = ReadVal<double>(v1,
"signalScale", m_SignalGen.m_SignalScale);
558 m_SignalGen.m_tEcho = ReadVal<double>(v1,
"tEcho", m_SignalGen.m_tEcho);
559 m_SignalGen.m_tLine = ReadVal<double>(v1,
"tLine", m_SignalGen.m_tLine);
560 m_SignalGen.m_tInhom = ReadVal<double>(v1,
"tInhom", m_SignalGen.m_tInhom);
561 m_SignalGen.m_Bvalue = ReadVal<double>(v1,
"bvalue", m_SignalGen.m_Bvalue);
562 m_SignalGen.m_SimulateKspaceAcquisition = ReadVal<bool>(v1,
"simulatekspace", m_SignalGen.m_SimulateKspaceAcquisition);
564 m_SignalGen.m_AxonRadius = ReadVal<double>(v1,
"axonRadius", m_SignalGen.m_AxonRadius);
565 m_SignalGen.m_Spikes = ReadVal<unsigned int>(v1,
"artifacts.spikesnum", m_SignalGen.m_Spikes);
566 m_SignalGen.m_SpikeAmplitude = ReadVal<double>(v1,
"artifacts.spikesscale", m_SignalGen.m_SpikeAmplitude);
567 m_SignalGen.m_KspaceLineOffset = ReadVal<double>(v1,
"artifacts.kspaceLineOffset", m_SignalGen.m_KspaceLineOffset);
568 m_SignalGen.m_EddyStrength = ReadVal<double>(v1,
"artifacts.eddyStrength", m_SignalGen.m_EddyStrength);
569 m_SignalGen.m_Tau = ReadVal<double>(v1,
"artifacts.eddyTau", m_SignalGen.m_Tau);
570 m_SignalGen.m_CroppingFactor = ReadVal<double>(v1,
"artifacts.aliasingfactor", m_SignalGen.m_CroppingFactor);
571 m_SignalGen.m_DoAddGibbsRinging = ReadVal<bool>(v1,
"artifacts.addringing", m_SignalGen.m_DoAddGibbsRinging);
572 m_SignalGen.m_DoSimulateRelaxation = ReadVal<bool>(v1,
"doSimulateRelaxation", m_SignalGen.m_DoSimulateRelaxation);
573 m_SignalGen.m_DoDisablePartialVolume = ReadVal<bool>(v1,
"doDisablePartialVolume", m_SignalGen.m_DoDisablePartialVolume);
574 m_SignalGen.m_DoAddMotion = ReadVal<bool>(v1,
"artifacts.doAddMotion", m_SignalGen.m_DoAddMotion);
575 m_SignalGen.m_DoRandomizeMotion = ReadVal<bool>(v1,
"artifacts.randomMotion", m_SignalGen.m_DoRandomizeMotion);
576 m_SignalGen.m_Translation[0] = ReadVal<double>(v1,
"artifacts.translation0", m_SignalGen.m_Translation[0]);
577 m_SignalGen.m_Translation[1] = ReadVal<double>(v1,
"artifacts.translation1", m_SignalGen.m_Translation[1]);
578 m_SignalGen.m_Translation[2] = ReadVal<double>(v1,
"artifacts.translation2", m_SignalGen.m_Translation[2]);
579 m_SignalGen.m_Rotation[0] = ReadVal<double>(v1,
"artifacts.rotation0", m_SignalGen.m_Rotation[0]);
580 m_SignalGen.m_Rotation[1] = ReadVal<double>(v1,
"artifacts.rotation1", m_SignalGen.m_Rotation[1]);
581 m_SignalGen.m_Rotation[2] = ReadVal<double>(v1,
"artifacts.rotation2", m_SignalGen.m_Rotation[2]);
586 BOOST_FOREACH( boost::property_tree::ptree::value_type
const& v2, v1.second.get_child(
"gradients") )
589 g[0] = ReadVal<double>(v2,
"x",0);
590 g[1] = ReadVal<double>(v2,
"y",0);
591 g[2] = ReadVal<double>(v2,
"z",0);
592 gradients.push_back(g);
594 m_SignalGen.SetGradienDirections(gradients);
597 m_Misc.m_MotionVolumesBox = ReadVal<string>(v1,
"artifacts.motionvolumes", m_Misc.m_MotionVolumesBox);
598 m_SignalGen.m_MotionVolumes.clear();
600 if ( m_Misc.m_MotionVolumesBox ==
"random" )
602 for (
size_t i=0; i < m_SignalGen.GetNumVolumes(); ++i )
604 m_SignalGen.m_MotionVolumes.push_back(
bool( rand()%2 ) );
606 MITK_DEBUG <<
"mitkFiberfoxParameters.cpp: Case m_Misc.m_MotionVolumesBox == \"random\".";
608 else if ( ! m_Misc.m_MotionVolumesBox.empty() )
610 stringstream stream( m_Misc.m_MotionVolumesBox );
611 std::vector<int> numbers;
613 while( stream >> nummer )
617 numbers.push_back( nummer );
621 if( *(std::min_element( numbers.begin(), numbers.end() )) < 0
622 && *(std::max_element( numbers.begin(), numbers.end() )) <= 0 )
624 for (
size_t i=0; i<m_SignalGen.GetNumVolumes(); ++i )
626 m_SignalGen.m_MotionVolumes.push_back(
true );
629 for(
auto iter = std::begin( numbers ); iter != std::end( numbers ); ++iter )
631 if ( -(*iter) < m_SignalGen.GetNumVolumes() && -(*iter) >= 0 )
633 m_SignalGen.m_MotionVolumes.at( -(*iter) ) =
false;
636 MITK_DEBUG <<
"mitkFiberfoxParameters.cpp: Case list of negative numbers.";
639 else if( *(std::min_element( numbers.begin(), numbers.end() )) >= 0
640 && *(std::max_element( numbers.begin(), numbers.end() )) >= 0 )
642 for (
size_t i=0; i<m_SignalGen.GetNumVolumes(); ++i )
644 m_SignalGen.m_MotionVolumes.push_back(
false );
647 for(
auto iter = std::begin( numbers ); iter != std::end( numbers ); ++iter )
649 if ( *iter < m_SignalGen.GetNumVolumes() && *iter >= 0 )
651 m_SignalGen.m_MotionVolumes.at( *iter ) =
true;
654 MITK_DEBUG <<
"mitkFiberfoxParameters.cpp: Case list of positive numbers.";
658 MITK_WARN <<
"mitkFiberfoxParameters.cpp: Inconsistent list of numbers in m_MotionVolumesBox.";
664 MITK_WARN <<
"mitkFiberfoxParameters.cpp: Cannot make sense of string in m_MotionVolumesBox.";
671 if (ReadVal<string>(v1,
"artifacts.noisetype",
"")==
"rice")
673 m_NoiseModel = std::make_shared< mitk::RicianNoiseModel<ScalarType> >();
674 m_NoiseModel->SetNoiseVariance(ReadVal<double>(v1,
"artifacts.noisevariance",m_NoiseModel->GetNoiseVariance()));
679 MITK_DEBUG <<
"mitkFiberfoxParameters.cpp: caught some error while trying m_NoiseModel->SetNoiseVariance()";
685 if (ReadVal<string>(v1,
"artifacts.noisetype",
"")==
"chisquare")
687 m_NoiseModel = std::make_shared< mitk::ChiSquareNoiseModel<ScalarType> >();
688 m_NoiseModel->SetNoiseVariance(ReadVal<double>(v1,
"artifacts.noisevariance",m_NoiseModel->GetNoiseVariance()));
693 MITK_DEBUG <<
"mitkFiberfoxParameters.cpp: caught some error while trying m_NoiseModel->SetNoiseVariance()";
698 BOOST_FOREACH( boost::property_tree::ptree::value_type
const& v2, v1.second.get_child(
"compartments") )
702 std::string model = ReadVal<std::string>(v2,
"model",
"",
true);
707 model->
SetT2(ReadVal<double>(v2,
"t2",model->
GetT2()));
708 model->
SetT1(ReadVal<double>(v2,
"t1",model->
GetT1()));
710 if (ReadVal<string>(v2,
"type",
"",
true)==
"fiber")
711 m_FiberModelList.push_back(model);
712 else if (ReadVal<string>(v2,
"type",
"",
true)==
"non-fiber")
713 m_NonFiberModelList.push_back(model);
716 else if (model==
"tensor")
722 model->
SetT2(ReadVal<double>(v2,
"t2",model->
GetT2()));
723 model->
SetT1(ReadVal<double>(v2,
"t1",model->
GetT1()));
725 if (ReadVal<string>(v2,
"type",
"",
true)==
"fiber")
726 m_FiberModelList.push_back(model);
727 else if (ReadVal<string>(v2,
"type",
"",
true)==
"non-fiber")
728 m_NonFiberModelList.push_back(model);
731 else if (model==
"ball")
735 model->
SetT2(ReadVal<double>(v2,
"t2",model->
GetT2()));
736 model->
SetT1(ReadVal<double>(v2,
"t1",model->
GetT1()));
738 if (ReadVal<string>(v2,
"type",
"",
true)==
"fiber")
739 m_FiberModelList.push_back(model);
740 else if (ReadVal<string>(v2,
"type",
"",
true)==
"non-fiber")
741 m_NonFiberModelList.push_back(model);
744 else if (model==
"astrosticks")
748 model->
SetT2(ReadVal<double>(v2,
"t2",model->
GetT2()));
749 model->
SetT1(ReadVal<double>(v2,
"t1",model->
GetT1()));
752 if (ReadVal<string>(v2,
"type",
"",
true)==
"fiber")
753 m_FiberModelList.push_back(model);
754 else if (ReadVal<string>(v2,
"type",
"",
true)==
"non-fiber")
755 m_NonFiberModelList.push_back(model);
758 else if (model==
"dot")
761 model->
SetT2(ReadVal<double>(v2,
"t2",model->
GetT2()));
762 model->
SetT1(ReadVal<double>(v2,
"t1",model->
GetT1()));
764 if (ReadVal<string>(v2,
"type",
"",
true)==
"fiber")
765 m_FiberModelList.push_back(model);
766 else if (ReadVal<string>(v2,
"type",
"",
true)==
"non-fiber")
767 m_NonFiberModelList.push_back(model);
770 else if (model==
"prototype")
777 unsigned int numCoeffs = ReadVal<unsigned int>(v2,
"numCoeffs",0,
true);
778 unsigned int numSamples = ReadVal<unsigned int>(v2,
"numSamples",0,
true);
780 for (
unsigned int j=0; j<numSamples; j++)
782 vnl_vector< double > coeffs(numCoeffs);
783 for (
unsigned int k=0; k<numCoeffs; k++)
785 coeffs[k] = ReadVal<double>(v2,
"kernels."+boost::lexical_cast<
string>(j)+
".coeffs."+boost::lexical_cast<string>(k),0,
true);
787 model->
SetShCoefficients( coeffs, ReadVal<double>(v2,
"kernels."+boost::lexical_cast<string>(j)+
".B0",0,
true) );
790 if (ReadVal<string>(v2,
"type",
"",
true)==
"fiber")
791 { m_FiberModelList.push_back(model); }
792 else if (ReadVal<string>(v2,
"type",
"",
true)==
"non-fiber")
793 { m_NonFiberModelList.push_back(model); }
798 if (signalModel!=NULL)
804 reader->SetFileName(filename+
"_VOLUME"+ReadVal<string>(v2,
"ID",
"")+
".nrrd");
825 reader->SetFileName(filename+
"_FMAP.nrrd");
827 m_SignalGen.m_FrequencyMap = reader->GetOutput();
838 reader->SetFileName(filename+
"_MASK.nrrd");
840 m_SignalGen.m_MaskImage = reader->GetOutput();
848 setlocale(LC_ALL, currLocale.c_str());
851 template<
class ScalarType >
bool SetShCoefficients(vnl_vector< double > shCoefficients, double b0)
ParameterType ReadVal(boost::property_tree::ptree::value_type const &v, std::string tag, ParameterType defaultValue, bool essential=false)
itk::SmartPointer< Self > Pointer
unsigned int m_CompartmentId
GUI flag. Which compartment is this model assigned to?
void SetFaRange(double min, double max)
Generates diffusion measurement employing a second rank tensor model: e^(-bg^TDg) ...
void SetDiffusivity(double D)
void SetGradienDirections(GradientListType gradientList)
void SaveParameters(string filename)
Save image generation parameters to .ffp file.
Generates constant direction independent signal.
itk::Vector< double, 3 > GradientType
std::vector< GradientType > GradientListType
unsigned int GetNumberOfKernels()
Generates direction independent diffusion measurement employing a scalar diffusion constant d: e^(-bd...
unsigned int GetMaxNumKernels()
void SetAdcRange(double min, double max)
Abstract class for diffusion signal models.
bool GetRandomizeSticks()
void SetDiffusivity3(double d3)
double GetBaselineSignal(int index)
unsigned int GetFirstBaselineIndex()
Returns index of first non-diffusion-weighted image volume.
void GenerateGradientHalfShell()
Generates half shell of gradient directions (with m_NumGradients non-zero directions) ...
std::vector< int > GetBaselineIndices()
Returns list of nun-diffusion-weighted image volume indices.
unsigned int GetNumBaselineVolumes()
Get number of non-diffusion-weighted image volumes.
The spherical harmonic representation of a prototype diffusion weighted MR signal is used to obtain t...
unsigned int GetShOrder()
std::pair< double, double > GetFaRange()
virtual void SetGradientList(GradientListType gradientList)=0
void SetDiffusivity(double diffusivity)
Scalar diffusion constant.
std::pair< double, double > GetAdcRange()
void SetDiffusivity1(double d1)
static const std::string filename
GradientListType GetGradientDirections()
Return gradient direction container.
void PrintSelf()
Print parameters to stdout.
void SetDiffusivity(double diffusivity)
Scalar diffusion constant.
Implementation of noise following a chi-squared distribution.
void SetNumWeightedVolumes(int numGradients)
Automaticall calls GenerateGradientHalfShell() afterwards.
void SetDiffusivity2(double d2)
Generates the diffusion signal using an idealised cylinder with zero radius: e^(-bd(ng)²) ...
unsigned int GetNumWeightedVolumes()
Get number of diffusion-weighted image volumes.
bool IsBaselineIndex(unsigned int idx)
Checks if image volume with given index is non-diffusion-weighted volume or not.
Implementation of noise following a rician distribution.
void SetMaxNumKernels(unsigned int max)
ItkDoubleImgType::Pointer GetVolumeFractionImage()
void LoadParameters(string filename)
Load image generation parameters from .ffp file.
Generates the diffusion signal using a collection of idealised cylinder with zero radius: e^(-bd(ng)²...
vnl_vector< double > GetCoefficients(int listIndex)
unsigned int GetNumVolumes()
Get number of baseline and diffusion-weighted image volumes.
void SetRandomizeSticks(bool randomize=true)
Random stick configuration in each voxel.
GradientType GetGradientDirection(unsigned int i)
void SetVolumeFractionImage(ItkDoubleImgType::Pointer img)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.