26#include "boost/iterator/iterator_traits.hpp"
27#include "boost/limits.hpp"
65is_negative(
const unsigned char x)
71is_negative(
const unsigned short x)
77is_negative(
const unsigned int x)
83is_negative(
const unsigned long x)
90template <
class InputIteratorT,
class T2,
class scaleT>
93 const InputIteratorT& begin,
94 const InputIteratorT& end,
97 typedef typename boost::iterator_value<InputIteratorT>::type T1;
100 if (info1.type_id() == info_for_out_type.type_id())
103 scale_factor = scaleT(1);
108 const double data_in_max = *std::max_element(begin, end);
109 double tmp_scale = data_in_max /
static_cast<double>(info_for_out_type.max_value());
110 if (info_for_out_type.signed_type() && info1.signed_type())
112 const double data_in_min = *std::min_element(begin, end);
113 tmp_scale = std::max(tmp_scale, data_in_min /
static_cast<double>(info_for_out_type.min_value()));
120 if (scale_factor == 0 || tmp_scale > scale_factor)
123 scale_factor = scaleT(tmp_scale);
127template <
class OutputIteratorT,
class InputIteratorT,
class scaleT>
130 scaleT& scale_factor,
131 const InputIteratorT& in_begin,
132 const InputIteratorT& in_end)
134 typedef typename boost::iterator_value<OutputIteratorT>::type OutType;
137 if (scale_factor == 0)
140 OutputIteratorT out_iter = out_begin;
141 InputIteratorT in_iter = in_begin;
142 for (; in_iter != in_end; ++in_iter, ++out_iter)
144 *out_iter =
static_cast<OutType
>(0);
150 OutputIteratorT out_iter = out_begin;
151 InputIteratorT in_iter = in_begin;
152 if (!std::numeric_limits<OutType>::is_integer)
154 for (; in_iter != in_end; ++in_iter, ++out_iter)
156 *out_iter =
static_cast<OutType
>(*in_iter / scale_factor);
161 for (; in_iter != in_end; ++in_iter, ++out_iter)
166 if (!std::numeric_limits<OutType>::is_signed && is_negative(*in_iter))
174 *out_iter =
static_cast<OutType
>(
round(*in_iter / scale_factor));
183template <
class IteratorT,
class scaleT>
185convert_range(
const IteratorT& out_begin, scaleT& scale_factor,
const IteratorT& in_begin,
const IteratorT& in_end)
187 scale_factor = scaleT(1);
188 std::copy(in_begin, in_end, out_begin);
This file declares the class stir::NumericInfo.
class NumericInfo<NUMBER> defines properties for the type NUMBER.
Definition NumericInfo.h:68
void convert_range(const OutputIteratorT &out_begin, scaleT &scale_factor, const InputIteratorT &in_begin, const InputIteratorT &in_end)
Converts the data in the input range to the output range (with elements of different types) such that...
Definition convert_range.inl:129
void find_scale_factor(scaleT &scale_factor, const Array< num_dimensions, T1 > &data_in, const NumericInfo< T2 > info_for_out_type)
A function that finds a scale factor to use when converting data to a new type.
Definition convert_array.inl:28
int round(const float x)
Implements rounding of floating point numbers.
Definition round.inl:59
Declaration of the stir::round functions.