|
@@ -10,7 +10,7 @@ namespace mri {
|
|
std::vector<double> &mag_cos) {
|
|
std::vector<double> &mag_cos) {
|
|
mag_sin.resize(total_samples_);
|
|
mag_sin.resize(total_samples_);
|
|
mag_cos.resize(total_samples_);
|
|
mag_cos.resize(total_samples_);
|
|
- for (long i = 0; i < total_samples_; ++i) {
|
|
|
|
|
|
+ for (unsigned long i = 0; i < total_samples_; ++i) {
|
|
mag_sin[i] = 0.0;
|
|
mag_sin[i] = 0.0;
|
|
mag_cos[i] = 0.0;
|
|
mag_cos[i] = 0.0;
|
|
double time = timesteps_[i];
|
|
double time = timesteps_[i];
|
|
@@ -41,7 +41,7 @@ namespace mri {
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
void GeneratorRF::EvaluateSignal(std::vector<double> &signal_rf) {
|
|
void GeneratorRF::EvaluateSignal(std::vector<double> &signal_rf) {
|
|
signal_rf.resize(total_samples_);
|
|
signal_rf.resize(total_samples_);
|
|
- for (long i = 0; i < total_samples_; ++i) {
|
|
|
|
|
|
+ for (unsigned long i = 0; i < total_samples_; ++i) {
|
|
signal_rf[i] = 0.0;
|
|
signal_rf[i] = 0.0;
|
|
double time = timesteps_[i];
|
|
double time = timesteps_[i];
|
|
for (unsigned int voxel = 0; voxel < voxel_num_; ++voxel) {
|
|
for (unsigned int voxel = 0; voxel < voxel_num_; ++voxel) {
|
|
@@ -74,37 +74,93 @@ namespace mri {
|
|
T2s_decays_norm_.clear();
|
|
T2s_decays_norm_.clear();
|
|
amplitudes_.resize(voxel_num_);
|
|
amplitudes_.resize(voxel_num_);
|
|
T2s_decays_norm_.resize(voxel_num_);
|
|
T2s_decays_norm_.resize(voxel_num_);
|
|
- std::cout << "#";
|
|
|
|
for (double &:amplitudes_){
|
|
for (double &:amplitudes_){
|
|
amp = rand(om);
|
|
amp = rand(om);
|
|
- std::cout << amp << "\t";
|
|
|
|
}
|
|
}
|
|
for (double &decay:T2s_decays_norm_){
|
|
for (double &decay:T2s_decays_norm_){
|
|
decay = rand(om);
|
|
decay = rand(om);
|
|
- std::cout << decay << "\t";
|
|
|
|
}
|
|
}
|
|
- std::cout<<std::endl;
|
|
|
|
};
|
|
};
|
|
-
|
|
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
void GeneratorRF::SetAmplitudes(std::vector<double> amplitudes){
|
|
void GeneratorRF::SetAmplitudes(std::vector<double> amplitudes){
|
|
if (amplitudes.size() != voxel_num_)
|
|
if (amplitudes.size() != voxel_num_)
|
|
- throw std::invalid_argument("Number of amplitudes do not fit number of voxels");
|
|
|
|
|
|
+ throw std::invalid_argument
|
|
|
|
+ ("Number of amplitudes do not fit number of voxels");
|
|
amplitudes_ = amplitudes;
|
|
amplitudes_ = amplitudes;
|
|
};
|
|
};
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
|
|
+ void GeneratorRF::SetBase(const std::vector<double> &mag_sin,
|
|
|
|
+ const std::vector<double> &mag_cos){
|
|
|
|
+ if ((mag_sin.size() != mag_cos.size())
|
|
|
|
+ ||
|
|
|
|
+ (mag_sin.size() != total_samples_)) {
|
|
|
|
+ throw std::invalid_argument
|
|
|
|
+ ("Base signal size does not fit settings of the fitness signal.");
|
|
|
|
+ }
|
|
|
|
+ base_mag_sin_.resize(total_samples_);
|
|
|
|
+ base_mag_cos_.resize(total_samples_);
|
|
|
|
+ for (unsigned long i = 0; i<total_samples_; ++i) {
|
|
|
|
+ base_mag_sin_[i] = mag_sin[i];
|
|
|
|
+ base_mag_cos_[i] = mag_cos[i];
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
void GeneratorRF::SetT2sDecaysNorm(std::vector<double> T2s_decays_norm){
|
|
void GeneratorRF::SetT2sDecaysNorm(std::vector<double> T2s_decays_norm){
|
|
T2s_decays_norm_ = T2s_decays_norm;
|
|
T2s_decays_norm_ = T2s_decays_norm;
|
|
};
|
|
};
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
|
|
+ // amplitudes -> values[:size/2]
|
|
|
|
+ // T2s_decays_norm -> values[size/2:]
|
|
|
|
+ void GeneratorRF::SetVoxels(const std::vector<double> &values) {
|
|
|
|
+ for (unsigned int i = 0; i < voxel_num_; ++i) {
|
|
|
|
+ amplitudes_[i] = values[i];
|
|
|
|
+ T2s_decays_norm_[i] = values[i+voxel_num_];
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // amplitudes -> values[:size/2]
|
|
|
|
+ // T2s_decays_norm -> values[size/2:]
|
|
|
|
+ void GeneratorRF::GetVoxels(std::vector<double> &values) {
|
|
|
|
+ values.resize(2 * voxel_num_);
|
|
|
|
+ for (unsigned int i = 0; i < voxel_num_; ++i) {
|
|
|
|
+ values[i] = amplitudes_[i];
|
|
|
|
+ values[i+voxel_num_] = T2s_decays_norm_[i];
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ double GeneratorRF::TryFit(const std::vector<double> &values) {
|
|
|
|
+ SetVoxels(values);
|
|
|
|
+ std::vector<double> mag_sin, mag_cos;
|
|
|
|
+ EvaluateDemodulated(mag_sin, mag_cos);
|
|
|
|
+ double diff = 0.0;
|
|
|
|
+ for (unsigned long i = 0; i < mag_sin.size(); ++i) {
|
|
|
|
+ // diff += std::abs((base_mag_sin_[i] - mag_sin[i]));
|
|
|
|
+ // diff += std::abs((base_mag_cos_[i] - mag_cos[i]));
|
|
|
|
+
|
|
|
|
+ diff += std::abs((base_mag_sin_[i] - mag_sin[i])/mag_sin[i]);
|
|
|
|
+ diff += std::abs((base_mag_cos_[i] - mag_cos[i])/mag_cos[i]);
|
|
|
|
+
|
|
|
|
+ diff += std::abs(base_mag_sin_[i]/base_mag_cos_[i] - mag_sin[i]/mag_cos[i]);
|
|
|
|
+ }
|
|
|
|
+ return diff;
|
|
|
|
+ };
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
|
|
+ // ********************************************************************** //
|
|
// period is set in milliseconds (ms)
|
|
// period is set in milliseconds (ms)
|
|
- void GeneratorRF::SetTimer(long total_periods, double period_ms,
|
|
|
|
|
|
+ void GeneratorRF::InitTimer(unsigned long total_periods, double period_ms,
|
|
int samples_per_period) {
|
|
int samples_per_period) {
|
|
total_periods_ = total_periods;
|
|
total_periods_ = total_periods;
|
|
period_ms_ = period_ms;
|
|
period_ms_ = period_ms;
|
|
@@ -113,7 +169,7 @@ namespace mri {
|
|
total_samples_ = total_periods * samples_per_period;
|
|
total_samples_ = total_periods * samples_per_period;
|
|
timesteps_.resize(total_samples_);
|
|
timesteps_.resize(total_samples_);
|
|
double a_timestep = period_ms/samples_per_period;
|
|
double a_timestep = period_ms/samples_per_period;
|
|
- for (long i = 0; i < total_samples_; ++i) {
|
|
|
|
|
|
+ for (unsigned long i = 0; i < total_samples_; ++i) {
|
|
timesteps_[i] = i*a_timestep;
|
|
timesteps_[i] = i*a_timestep;
|
|
}
|
|
}
|
|
// for (double step: timesteps_) std::cout << step<<' ';
|
|
// for (double step: timesteps_) std::cout << step<<' ';
|
|
@@ -123,12 +179,14 @@ namespace mri {
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
// ********************************************************************** //
|
|
- void GeneratorRF::SetVoxels(double voxel_num, double phase_init,
|
|
|
|
|
|
+ void GeneratorRF::InitVoxels(unsigned int voxel_num, double phase_init,
|
|
double phase_range, double T2s_scale) {
|
|
double phase_range, double T2s_scale) {
|
|
T2s_scale_ = T2s_scale;
|
|
T2s_scale_ = T2s_scale;
|
|
if (voxel_num < 2)
|
|
if (voxel_num < 2)
|
|
throw std::invalid_argument("We need at least two voxels for phase gradient");
|
|
throw std::invalid_argument("We need at least two voxels for phase gradient");
|
|
voxel_num_ = voxel_num;
|
|
voxel_num_ = voxel_num;
|
|
|
|
+ amplitudes_.resize(voxel_num_);
|
|
|
|
+ T2s_decays_norm_.resize(voxel_num_);
|
|
phase_init_ = phase_init;
|
|
phase_init_ = phase_init;
|
|
phase_range_ = phase_range;
|
|
phase_range_ = phase_range;
|
|
double phase_step = phase_range_/(voxel_num_ - 1);
|
|
double phase_step = phase_range_/(voxel_num_ - 1);
|