Commit 41ffcc27 authored by Erik Karlsson's avatar Erik Karlsson

Added support for h = 0.0

parent 1e82a67c
...@@ -126,11 +126,13 @@ class DistAbs ...@@ -126,11 +126,13 @@ class DistAbs
{ {
static inline WT f(double dist, const float *h, WT fixed_point_mult) static inline WT f(double dist, const float *h, WT fixed_point_mult)
{ {
double w = std::exp(-dist*dist / (h[0]*h[0] * pixelInfo<T>::channels));
if (std::isnan(w)) w = 1.0; // Handle h = 0.0
static const double WEIGHT_THRESHOLD = 0.001; static const double WEIGHT_THRESHOLD = 0.001;
WT weight = (WT)round(fixed_point_mult * WT weight = (WT)round(fixed_point_mult * w);
std::exp(-dist*dist / (h[0]*h[0] * pixelInfo<T>::channels))); if (weight < WEIGHT_THRESHOLD * fixed_point_mult) weight = 0;
if (weight < WEIGHT_THRESHOLD * fixed_point_mult)
weight = 0;
return weight; return weight;
} }
}; };
...@@ -167,7 +169,8 @@ public: ...@@ -167,7 +169,8 @@ public:
}; };
template <typename T, typename WT> template <typename T, typename WT>
static inline WT calcWeight(double dist, const float *h, int fixed_point_mult) static inline WT calcWeight(double dist, const float *h,
typename pixelInfo<WT>::sampleType fixed_point_mult)
{ {
return calcWeight_<T, WT>::f(dist, h, fixed_point_mult); return calcWeight_<T, WT>::f(dist, h, fixed_point_mult);
} }
...@@ -243,20 +246,22 @@ class DistSquared ...@@ -243,20 +246,22 @@ class DistSquared
template <typename T, typename WT> struct calcWeight_ template <typename T, typename WT> struct calcWeight_
{ {
static inline WT f(double dist, const float *h, int fixed_point_mult) static inline WT f(double dist, const float *h, WT fixed_point_mult)
{ {
double w = std::exp(-dist / (h[0]*h[0] * pixelInfo<T>::channels));
if (std::isnan(w)) w = 1.0; // Handle h = 0.0
static const double WEIGHT_THRESHOLD = 0.001; static const double WEIGHT_THRESHOLD = 0.001;
WT weight = (WT)round(fixed_point_mult * WT weight = (WT)round(fixed_point_mult * w);
std::exp(-dist / (h[0]*h[0] * pixelInfo<T>::channels))); if (weight < WEIGHT_THRESHOLD * fixed_point_mult) weight = 0;
if (weight < WEIGHT_THRESHOLD * fixed_point_mult)
weight = 0;
return weight; return weight;
} }
}; };
template <typename T, typename ET, int n> struct calcWeight_<T, Vec<ET, n> > template <typename T, typename ET, int n> struct calcWeight_<T, Vec<ET, n> >
{ {
static inline Vec<ET, n> f(double dist, const float *h, int fixed_point_mult) static inline Vec<ET, n> f(double dist, const float *h, ET fixed_point_mult)
{ {
Vec<ET, n> res; Vec<ET, n> res;
for (int i=0; i<n; i++) for (int i=0; i<n; i++)
...@@ -286,7 +291,8 @@ public: ...@@ -286,7 +291,8 @@ public:
}; };
template <typename T, typename WT> template <typename T, typename WT>
static inline WT calcWeight(double dist, const float *h, int fixed_point_mult) static inline WT calcWeight(double dist, const float *h,
typename pixelInfo<WT>::sampleType fixed_point_mult)
{ {
return calcWeight_<T, WT>::f(dist, h, fixed_point_mult); return calcWeight_<T, WT>::f(dist, h, fixed_point_mult);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment