Skip to content
Snippets Groups Projects

in convolution context, throw -> assert

Merged Wuttke, Joachim requested to merge j.triv3 into main
2 files
+ 23
45
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -17,7 +17,6 @@
#include "Base/Axis/Scale.h"
#include "Base/Util/Assert.h"
#include "Device/Resolution/Convolve.h"
#include <stdexcept>
ConvolutionDetectorResolution::ConvolutionDetectorResolution(cumulative_DF_1d res_function_1d)
: m_rank(1)
@@ -56,23 +55,13 @@ std::vector<const INode*> ConvolutionDetectorResolution::nodeChildren() const
void ConvolutionDetectorResolution::applyDetectorResolution(Datafield* intensity_map) const
{
if (intensity_map->rank() != m_rank) {
throw std::runtime_error(
"ConvolutionDetectorResolution::applyDetectorResolution -> Error! "
"Intensity map must have same dimension as detector resolution function.");
}
switch (m_rank) {
case 1:
ASSERT(intensity_map->rank() == m_rank);
if (m_rank == 1)
apply1dConvolution(intensity_map);
break;
case 2:
else if (m_rank == 2)
apply2dConvolution(intensity_map);
break;
default:
throw std::runtime_error(
"ConvolutionDetectorResolution::applyDetectorResolution -> Error! "
"Class ConvolutionDetectorResolution must be initialized with dimension 1 or 2.");
}
else
ASSERT_NEVER;
}
void ConvolutionDetectorResolution::setResolutionFunction(const IResolutionFunction2D& resFunc)
@@ -82,11 +71,9 @@ void ConvolutionDetectorResolution::setResolutionFunction(const IResolutionFunct
void ConvolutionDetectorResolution::apply1dConvolution(Datafield* intensity_map) const
{
ASSERT(m_res_function_1d == nullptr);
if (intensity_map->rank() != 1)
throw std::runtime_error(
"ConvolutionDetectorResolution::apply1dConvolution -> Error! "
"Number of axes for intensity map does not correspond to the dimension of the map.");
ASSERT(m_res_function_1d);
ASSERT(intensity_map->rank() == 1);
const Scale& axis = intensity_map->axis(0);
// Construct source vector from original intensity map
std::vector<double> source_vector = intensity_map->flatVector();
@@ -94,10 +81,7 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* intensity_map)
if (data_size < 2)
return; // No convolution for sets of zero or one element
// Construct kernel vector from resolution function
if (axis.size() != data_size)
throw std::runtime_error(
"ConvolutionDetectorResolution::apply1dConvolution -> Error! "
"Size of axis for intensity map does not correspond to size of data in the map.");
ASSERT(axis.size() == data_size);
double step_size =
std::abs(axis.binCenter(0) - axis.binCenter(axis.size() - 1)) / (data_size - 1);
double mid_value = axis.binCenter(axis.size() / 2); // because Convolve expects zero at midpoint
@@ -117,10 +101,7 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* intensity_map)
void ConvolutionDetectorResolution::apply2dConvolution(Datafield* intensity_map) const
{
ASSERT(m_res_function_2d);
if (intensity_map->rank() != 2)
throw std::runtime_error(
"ConvolutionDetectorResolution::apply2dConvolution -> Error! "
"Number of axes for intensity map does not correspond to the dimension of the map.");
ASSERT(intensity_map->rank() == 2);
const Scale& axis_1 = intensity_map->axis(0);
const Scale& axis_2 = intensity_map->axis(1);
size_t axis_size_1 = axis_1.size();
@@ -131,10 +112,7 @@ void ConvolutionDetectorResolution::apply2dConvolution(Datafield* intensity_map)
std::vector<double> raw_source_vector = intensity_map->flatVector();
std::vector<std::vector<double>> source;
size_t raw_data_size = raw_source_vector.size();
if (raw_data_size != axis_size_1 * axis_size_2)
throw std::runtime_error(
"ConvolutionDetectorResolution::apply2dConvolution -> Error! "
"Intensity map data size does not match the product of its axes' sizes");
ASSERT(raw_data_size == axis_size_1 * axis_size_2);
for (auto it = raw_source_vector.begin(); it != raw_source_vector.end(); it += axis_size_2) {
std::vector<double> row_vector(it, it + axis_size_2);
source.push_back(row_vector);
Loading