Skip to content
Snippets Groups Projects
Commit ed1205a7 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

simpler access to df

parent c745646a
No related branches found
No related tags found
1 merge request!2020convolution computation more compact
......@@ -75,11 +75,10 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* df) const
ASSERT(df->rank() == 1);
const Scale& axis = df->axis(0);
// Construct source vector from original intensity map
std::vector<double> source_vector = df->flatVector();
size_t n = source_vector.size();
const size_t n = df->size();
if (n < 2)
return; // No convolution for sets of zero or one element
// Construct kernel vector from resolution function
ASSERT(axis.size() == n);
double step_size = std::abs(axis.binCenter(0) - axis.binCenter(n - 1)) / (n - 1);
......@@ -89,7 +88,7 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* df) const
kernel.push_back(getIntegratedPDF1d(axis.binCenter(index) - mid_value, step_size));
// Calculate convolution
std::vector<double> result;
Convolve().fftconvolve(source_vector, kernel, result);
Convolve().fftconvolve(df->flatVector(), kernel, result);
// Truncate negative values that can arise because of finite precision of Fourier Transform
for (double& e : result)
e = std::max(0.0, e);
......@@ -103,18 +102,10 @@ void ConvolutionDetectorResolution::apply2dConvolution(Datafield* df) const
ASSERT(df->rank() == 2);
const Scale& X = df->axis(0);
const Scale& Y = df->axis(1);
size_t nx = X.size();
size_t ny = Y.size();
ASSERT(nx > 1);
ASSERT(ny > 1);
// Construct source vector array from original intensity map
std::vector<double> raw_source_vector = df->flatVector();
std::vector<std::vector<double>> source;
size_t raw_data_size = raw_source_vector.size();
ASSERT(raw_data_size == nx * ny);
for (auto it = raw_source_vector.begin(); it != raw_source_vector.end(); it += ny)
source.emplace_back(std::vector<double>(it, it + ny));
const size_t nx = X.size();
const size_t ny = Y.size();
if (nx < 2 && ny < 2)
return;
// Construct kernel vector from resolution function
std::vector<std::vector<double>> kernel;
......@@ -135,7 +126,7 @@ void ConvolutionDetectorResolution::apply2dConvolution(Datafield* df) const
}
// Calculate convolution
std::vector<std::vector<double>> result;
Convolve().fftconvolve(source, kernel, result);
Convolve().fftconvolve(df->values2D(), kernel, result);
// Populate intensity map with results
std::vector<double> result_vector;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment