32 #define IMAGE_CONF_H_ "ImageConf 2, 2021/03 Markus.Peura@fmi.fi"
34 #include <drain/image/CoordinatePolicy.h>
37 #include <drain/Caster.h>
38 #include "drain/util/ValueScaling.h"
56 Encoding(
const std::type_info & t =
typeid(
unsigned char)){
117 return caster.typeIsSet();
123 if (t ==
typeid(
bool)){
125 setType(
typeid(
unsigned char));
127 else if (t ==
typeid(std::string)){
130 throw std::runtime_error(
"storage type 'std::string' not applicable to images");
152 return drain::Type::call<drain::typeLimiter<T> >(
caster.
getType());
247 void setOptimalScale(){
252 void setOptimalPhysicalScale(
double min,
double max){
293 double requestPhysicalMax(
double defaultMax =
static_cast<double>(std::numeric_limits<short int>::max()))
const {
298 const std::type_info & t =
getType();
299 if (Type::call<drain::typeIsSmallInt>(t))
300 return scaling.
fwd(Type::call<typeMax, double>(t));
312 double requestPhysicalMin(
double defaultMin =
static_cast<double>(std::numeric_limits<short int>::min()))
const {
317 const std::type_info & t =
getType();
318 if (Type::call<drain::typeIsSmallInt>(t))
319 return scaling.
fwd(Type::call<typeMin, double>(t));
339 ImageConf(
const drain::Type & t=
typeid(
unsigned char),
size_t width=0,
size_t height=0,
size_t imageChannels=1,
size_t alphaChannels=0) :
341 Geometry(width,height ? height : width, imageChannels, alphaChannels)
354 setGeometry(conf.getGeometry());
373 void setCoordinatePolicy(EdgePolicy::index_t xUnderFlowPolicy, EdgePolicy::index_t yUnderFlowPolicy, EdgePolicy::index_t xOverFlowPolicy, EdgePolicy::index_t yOverFlowPolicy){
374 coordinatePolicy.set(xUnderFlowPolicy, yUnderFlowPolicy, xOverFlowPolicy, yOverFlowPolicy);
392 std::ostream & operator<<(std::ostream &ostr,
const ImageConf & conf){
396 ostr << conf.getGeometry();
402 if (s.isScaled() || s.isPhysical()){
403 ostr <<
"*(" << s <<
")";
const std::type_info & getType() const
Returns type_info of the current type.
Definition: Caster.h:144
size_t getElementSize() const
Returns the size of the base type (size of an element, not of element array).
Definition: Caster.h:151
void setType(const std::type_info &t)
Calls setType<T>() for which typeid(T) = t.
Definition: Caster.h:119
Utilities related to std::type_info.
Definition: Type.h:51
Linear scaling and physical range for image intensities.
Definition: ValueScaling.h:64
double getMinPhys() const
Returns the minimum physical value.
Definition: ValueScaling.h:269
bool isPhysical() const
Returns true, physical intensity range has been set.
Definition: ValueScaling.h:281
double fwd(double x) const
Forward scaling: given encoded value x, returns corresponding value (possibly physically meaningful).
Definition: ValueScaling.h:295
virtual const ValueScaling & getScaling() const
Get linear scaling.
Definition: ValueScaling.h:147
void setPhysicalRange(const Range< T > &range)
Sets the supported range for physical values. Does not change scaling or type.
Definition: ValueScaling.h:240
double getMaxPhys() const
Returns the maximum physical value.
Definition: ValueScaling.h:275
const Range< double > & getPhysicalRange() const
Returns a typical or supported range for physical values.
Definition: ValueScaling.h:221
virtual void setScaling(double scale, double offset)
Set linear scaling.
Definition: ValueScaling.h:136
void setOptimalScale(const std::type_info &t)
If storage type is integer, adjust scale such that resolution is maximized.
Definition: ValueScaling.cpp:36
Policies for coordinate underflows and overflows.
Definition: CoordinatePolicy.h:106
Definition: ImageConf.h:51
const Encoding & getEncoding() const
Return type and scaling.
Definition: ImageConf.h:68
bool typeIsSet() const
Get the storage type.
Definition: ImageConf.h:116
double requestPhysicalMin(double defaultMin=static_cast< double >(std::numeric_limits< short int >::min())) const
Returns the actual or guessed minimum physical value,.
Definition: ImageConf.h:312
void setEncoding(const Encoding &e)
Set type and scaling.
Definition: ImageConf.h:83
const std::type_info & getType() const
Linear scaling.
Definition: ImageConf.h:110
double requestPhysicalMax(double defaultMax=static_cast< double >(std::numeric_limits< short int >::max())) const
Returns the actual or guessed maximum physical value,.
Definition: ImageConf.h:293
std::string type
Information of the current type.
Definition: ImageConf.h:103
size_t getElementSize() const
Returns the size in bytes of the storage type (1 for unsigned char, 2 for 16-bit types,...
Definition: ImageConf.h:159
Encoding & getEncoding()
Return type and scaling.
Definition: ImageConf.h:75
Caster caster
In base class(es), mainly for storing storage type. In derived classes, also for value conversions.
Definition: ImageConf.h:97
void setType(const std::type_info &t)
Set storage type.
Definition: ImageConf.h:121
void setPhysicalRange(double min, double max, bool rescale=false)
Sets the supported range for physical values. Does not change scaling or type.
Definition: ImageConf.h:238
T getTypeMax() const
Returns the maximum value supported by the current storage type.
Definition: ImageConf.h:281
void setType()
Convenience.
Definition: ImageConf.h:144
void setPhysicalRange(const Range< double > &range, bool rescale=false)
Sets channel specific scaling instead of shared (image-level) scaling.
Definition: ImageConf.h:229
T getTypeMin() const
Returns the minimum value supported by the current storage type.
Definition: ImageConf.h:267
Definition: Geometry.h:145
Geometry(size_t width=0, size_t height=0, size_t channels=1, size_t alphas=0)
Constructor with dimensions. Channel count is one by default, allowing construction with width and he...
Definition: Geometry.h:159
size_t getChannelCount() const
Set...
Definition: Geometry.h:257
Struct for image (excluding data)
Definition: ImageConf.h:333
void setCoordinatePolicy(const T &policy)
Does not set any CoordinateHandler object.
Definition: ImageConf.h:368
CoordinatePolicy coordinatePolicy
Rules to handle under- and overflows of horizontal and vertical coordinates.
Definition: ImageConf.h:383
Class for ensuring that variable of type D remains within limits of type S.
Definition: TypeUtils.h:653
Definition: DataSelector.cpp:1277