31 #ifndef DISTANCEMODEL_H_
32 #define DISTANCEMODEL_H_
36 #include "drain/util/BeanLike.h"
37 #include "drain/imageops/ImageOp.h"
39 #include "drain/UniTuple.h"
53 Bidirectional(T forward=T(), T backward=T()) : forward(this->
at(0)), backward(this->
at(1)) {
54 this->set(forward, backward);
59 this->set(r.forward, r.backward);
89 DistanceElement(
short int di,
short int dj,
const float coeff) :
diff(di,dj), coeff(coeff) {
104 std::ostream & operator<<(std::ostream &ostr,
const DistanceElement & d){
106 ostr << std::showpos << d.diff << std::noshowpos <<
": " << d.coeff;
111 typedef std::vector<DistanceElement> DistanceNeighbourhood;
114 std::ostream & operator<<(std::ostream &ostr,
const DistanceNeighbourhood & chain){
115 for (
const DistanceElement & element: chain){
116 ostr << element <<
'\n';
128 enum PIXEL_ADJACENCY {CONN4=4, CONN8=8, KNIGHT=16};
130 typedef PIXEL_ADJACENCY topol_t;
166 void setRadius(
float horz,
float vert=nan_f,
float horzLeft=nan_f,
float vertUp=nan_f) = 0;
171 horzRadius.set(horz, horzLeft);
172 vertRadius.set(vert, vertUp);
204 void setDecrement(
float horz,
float vert = NAN,
float horzRight = NAN,
float vertUp = NAN) = 0;
207 DistanceElement getElement(
short dx,
short dy,
bool forward=
true)
const = 0;
217 pixelAdjacency.set(topology);
223 pixelAdjacency.set(topology);
234 void createChain(DistanceNeighbourhood & chain, PIXEL_ADJACENCY topology = PIXEL_ADJACENCY::KNIGHT,
bool forward=
true)
const;
237 void createChain(DistanceNeighbourhood & chain,
bool forward=
true)
const {
242 float decrease(
float value,
float coeff)
const = 0;
254 DistanceModel(
const std::string & name,
const std::string & description =
"") :
BeanLike(name, description), horzRadius(11.0, nan_f), vertRadius(nan_f, nan_f) {
256 parameters.link(
"width", horzRadius.tuple(),
"pix").fillArray =
true;
257 parameters.link(
"height", vertRadius.tuple(),
"pix").fillArray =
true;
267 parameters.
copyStruct(dm.getParameters(), dm, *
this);
273 std::string pixelAdjacencyStr;
Something which has a name, a description and possibly some parameters of varying type.
Definition: BeanLike.h:60
Definition: DistanceModel.h:46
Bidirectional(const Bidirectional &r)
Copy constructor.
Definition: DistanceModel.h:58
Bidirectional(T forward=T(), T backward=T())
Default constructor.
Definition: DistanceModel.h:53
Flagger accepting values of enum type E.
Definition: Flags.h:763
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition: ReferenceMap.h:399
const S & at(size_t i) const
Return const reference to element i.
Definition: TupleBase.h:97
Tuple of N elements of type T.
Definition: UniTuple.h:65
Definition: DistanceModel.h:76
const drain::Point2D< short int > diff
A small digital offset, for example {+1,-1} or {-2,+1}.
Definition: DistanceModel.h:83
Base class for linear and exponential distances in rectangular pixel images.
Definition: DistanceModel.h:123
void setRadiusVerbatim(float horz, float vert=nan_f, float horzLeft=nan_f, float vertUp=nan_f)
Simply copies values, does not try to set defaults.
Definition: DistanceModel.h:170
void setTopology(PIXEL_ADJACENCY topology)
Sets the topology of the computation grid: 0=diamond, 1=diagonal, 2=extended (chess knight steps)
Definition: DistanceModel.h:216
DistanceModel(const std::string &name, const std::string &description="")
Base class for digital distance models. Supports 4-, 8- and extended "chess knight" distance.
Definition: DistanceModel.h:254
drain::Bidirectional< float > horzDec
Final decrement or decay per pixel in horizontal direction. Derived from horzRadius; definition varie...
Definition: DistanceModel.h:284
virtual void setRadius(float horz, float vert=nan_f, float horzLeft=nan_f, float vertUp=nan_f)=0
Sets the geometry of the distance model.
float maxCodeValue
Needed internally to get diag decrement larger than horz/vert decrements. (Not used for scaling).
Definition: DistanceModel.h:290
void setMax(float maxCodeValue)
Set maximum (expected) code value. Radii, if given, will set pixel-to-pixel decrements scaled to this...
Definition: DistanceModel.h:143
virtual void updateBean() const override
Called after setParameters()
Definition: DistanceModel.cpp:59
virtual void setDecrement(float horz, float vert=NAN, float horzRight=NAN, float vertUp=NAN)=0
void createChain(DistanceNeighbourhood &chain, PIXEL_ADJACENCY topology=PIXEL_ADJACENCY::KNIGHT, bool forward=true) const
Creates a list of DistanceElements.
Definition: DistanceModel.cpp:83
drain::Bidirectional< float > vertDec
Final decrement or decay per pixel in vertical direction. Derived from vertRadius; definition varies ...
Definition: DistanceModel.h:287
float getMax() const
Returns the maximum (expected) code value.
Definition: DistanceModel.h:149
Definition: DataSelector.cpp:1277