2012-08-19 11:13:58 +02:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Intel License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective icvers.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#ifndef __OPENCV_FAST_NLMEANS_DENOISING_INVOKER_COMMONS_HPP__
|
|
|
|
#define __OPENCV_FAST_NLMEANS_DENOISING_INVOKER_COMMONS_HPP__
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
|
2015-03-25 17:09:53 +01:00
|
|
|
// std::isnan is a part of C++11 and it is not supported in MSVS2010/2012
|
|
|
|
#if defined _MSC_VER && _MSC_VER < 1800 /* MSVC 2013 */
|
|
|
|
#include <float.h>
|
|
|
|
namespace std {
|
|
|
|
template <typename T> bool isnan(T value) { return _isnan(value) != 0; }
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-12 18:45:09 +01:00
|
|
|
template <typename T> struct pixelInfo_
|
2014-02-11 16:08:13 +01:00
|
|
|
{
|
2015-02-12 18:45:09 +01:00
|
|
|
static const int channels = 1;
|
|
|
|
typedef T sampleType;
|
2015-02-12 15:23:28 +01:00
|
|
|
};
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-02-12 18:45:09 +01:00
|
|
|
template <typename ET, int n> struct pixelInfo_<Vec<ET, n> >
|
2014-02-11 16:08:13 +01:00
|
|
|
{
|
2015-02-12 18:45:09 +01:00
|
|
|
static const int channels = n;
|
|
|
|
typedef ET sampleType;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T> struct pixelInfo: public pixelInfo_<T>
|
|
|
|
{
|
2015-03-30 15:28:53 +02:00
|
|
|
typedef typename pixelInfo_<T>::sampleType sampleType;
|
2015-02-12 18:45:09 +01:00
|
|
|
|
|
|
|
static inline sampleType sampleMax()
|
|
|
|
{
|
|
|
|
return std::numeric_limits<sampleType>::max();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline sampleType sampleMin()
|
|
|
|
{
|
|
|
|
return std::numeric_limits<sampleType>::min();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t sampleBytes()
|
|
|
|
{
|
|
|
|
return sizeof(sampleType);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t sampleBits()
|
|
|
|
{
|
|
|
|
return 8*sampleBytes();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-18 14:59:52 +01:00
|
|
|
class DistAbs
|
2015-02-12 18:45:09 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T> struct calcDist_
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(const T a, const T b)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return std::abs((int)(a-b));
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 2> >
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(const Vec<ET, 2> a, const Vec<ET, 2> b)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return std::abs((int)(a[0]-b[0])) + std::abs((int)(a[1]-b[1]));
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 3> >
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(const Vec<ET, 3> a, const Vec<ET, 3> b)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
|
|
|
return
|
2015-03-05 13:36:42 +01:00
|
|
|
std::abs((int)(a[0]-b[0])) +
|
|
|
|
std::abs((int)(a[1]-b[1])) +
|
|
|
|
std::abs((int)(a[2]-b[2]));
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 4> >
|
2015-03-03 01:19:34 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(const Vec<ET, 4> a, const Vec<ET, 4> b)
|
2015-03-03 01:19:34 +01:00
|
|
|
{
|
|
|
|
return
|
2015-03-05 13:36:42 +01:00
|
|
|
std::abs((int)(a[0]-b[0])) +
|
|
|
|
std::abs((int)(a[1]-b[1])) +
|
|
|
|
std::abs((int)(a[2]-b[2])) +
|
|
|
|
std::abs((int)(a[3]-b[3]));
|
2015-03-03 01:19:34 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 17:50:52 +01:00
|
|
|
template <typename T, typename WT> struct calcWeight_
|
|
|
|
{
|
2015-03-06 14:28:43 +01:00
|
|
|
static inline WT f(double dist, const float *h, WT fixed_point_mult)
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
2015-03-06 15:06:11 +01:00
|
|
|
double w = std::exp(-dist*dist / (h[0]*h[0] * pixelInfo<T>::channels));
|
|
|
|
if (std::isnan(w)) w = 1.0; // Handle h = 0.0
|
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
static const double WEIGHT_THRESHOLD = 0.001;
|
2015-03-25 17:09:53 +01:00
|
|
|
WT weight = (WT)cvRound(fixed_point_mult * w);
|
2015-03-06 15:06:11 +01:00
|
|
|
if (weight < WEIGHT_THRESHOLD * fixed_point_mult) weight = 0;
|
|
|
|
|
2015-03-05 17:50:52 +01:00
|
|
|
return weight;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, typename ET, int n> struct calcWeight_<T, Vec<ET, n> >
|
|
|
|
{
|
2015-03-06 14:28:43 +01:00
|
|
|
static inline Vec<ET, n> f(double dist, const float *h, ET fixed_point_mult)
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
|
|
|
Vec<ET, n> res;
|
|
|
|
for (int i=0; i<n; i++)
|
2015-03-06 14:28:43 +01:00
|
|
|
res[i] = calcWeight<T, ET>(dist, &h[i], fixed_point_mult);
|
2015-03-05 17:50:52 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-18 14:59:52 +01:00
|
|
|
public:
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T> static inline int calcDist(const T a, const T b)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return calcDist_<T>::f(a, b);
|
2015-02-12 15:23:28 +01:00
|
|
|
}
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T>
|
|
|
|
static inline int calcDist(const Mat& m, int i1, int j1, int i2, int j2)
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-02-18 14:59:52 +01:00
|
|
|
const T a = m.at<T>(i1, j1);
|
|
|
|
const T b = m.at<T>(i2, j2);
|
2015-03-05 13:36:42 +01:00
|
|
|
return calcDist<T>(a,b);
|
2015-02-12 15:23:28 +01:00
|
|
|
}
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T>
|
|
|
|
static inline int calcUpDownDist(T a_up, T a_down, T b_up, T b_down)
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return calcDist<T>(a_down, b_down) - calcDist<T>(a_up, b_up);
|
2015-02-18 14:59:52 +01:00
|
|
|
};
|
|
|
|
|
2015-03-05 17:50:52 +01:00
|
|
|
template <typename T, typename WT>
|
2015-03-06 15:06:11 +01:00
|
|
|
static inline WT calcWeight(double dist, const float *h,
|
|
|
|
typename pixelInfo<WT>::sampleType fixed_point_mult)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 17:50:52 +01:00
|
|
|
return calcWeight_<T, WT>::f(dist, h, fixed_point_mult);
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T>
|
2015-03-10 01:34:02 +01:00
|
|
|
static inline int maxDist()
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return (int)pixelInfo<T>::sampleMax() * pixelInfo<T>::channels;
|
2015-02-12 15:23:28 +01:00
|
|
|
}
|
|
|
|
};
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-02-18 14:59:52 +01:00
|
|
|
class DistSquared
|
2014-02-11 16:08:13 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T> struct calcDist_
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(const T a, const T b)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return (int)(a-b) * (int)(a-b);
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
};
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 2> >
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(const Vec<ET, 2> a, const Vec<ET, 2> b)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return (int)(a[0]-b[0])*(int)(a[0]-b[0]) + (int)(a[1]-b[1])*(int)(a[1]-b[1]);
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
};
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 3> >
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(const Vec<ET, 3> a, const Vec<ET, 3> b)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
|
|
|
return
|
2015-03-05 13:36:42 +01:00
|
|
|
(int)(a[0]-b[0])*(int)(a[0]-b[0]) +
|
|
|
|
(int)(a[1]-b[1])*(int)(a[1]-b[1]) +
|
|
|
|
(int)(a[2]-b[2])*(int)(a[2]-b[2]);
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename ET> struct calcDist_<Vec<ET, 4> >
|
2015-03-03 01:19:34 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(const Vec<ET, 4> a, const Vec<ET, 4> b)
|
2015-03-03 01:19:34 +01:00
|
|
|
{
|
|
|
|
return
|
2015-03-05 13:36:42 +01:00
|
|
|
(int)(a[0]-b[0])*(int)(a[0]-b[0]) +
|
|
|
|
(int)(a[1]-b[1])*(int)(a[1]-b[1]) +
|
|
|
|
(int)(a[2]-b[2])*(int)(a[2]-b[2]) +
|
|
|
|
(int)(a[3]-b[3])*(int)(a[3]-b[3]);
|
2015-03-03 01:19:34 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T> struct calcUpDownDist_
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(T a_up, T a_down, T b_up, T b_down)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
int A = a_down - b_down;
|
|
|
|
int B = a_up - b_up;
|
2015-02-18 14:59:52 +01:00
|
|
|
return (A-B)*(A+B);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename ET, int n> struct calcUpDownDist_<Vec<ET, n> >
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
typedef Vec<ET, n> T;
|
|
|
|
public:
|
2015-03-05 13:36:42 +01:00
|
|
|
static inline int f(T a_up, T a_down, T b_up, T b_down)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return calcDist<T>(a_down, b_down) - calcDist<T>(a_up, b_up);
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 17:50:52 +01:00
|
|
|
template <typename T, typename WT> struct calcWeight_
|
|
|
|
{
|
2015-03-06 15:06:11 +01:00
|
|
|
static inline WT f(double dist, const float *h, WT fixed_point_mult)
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
2015-03-06 15:06:11 +01:00
|
|
|
double w = std::exp(-dist / (h[0]*h[0] * pixelInfo<T>::channels));
|
|
|
|
if (std::isnan(w)) w = 1.0; // Handle h = 0.0
|
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
static const double WEIGHT_THRESHOLD = 0.001;
|
2015-03-25 17:09:53 +01:00
|
|
|
WT weight = (WT)cvRound(fixed_point_mult * w);
|
2015-03-06 15:06:11 +01:00
|
|
|
if (weight < WEIGHT_THRESHOLD * fixed_point_mult) weight = 0;
|
|
|
|
|
2015-03-05 17:50:52 +01:00
|
|
|
return weight;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T, typename ET, int n> struct calcWeight_<T, Vec<ET, n> >
|
|
|
|
{
|
2015-03-06 15:06:11 +01:00
|
|
|
static inline Vec<ET, n> f(double dist, const float *h, ET fixed_point_mult)
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
|
|
|
Vec<ET, n> res;
|
|
|
|
for (int i=0; i<n; i++)
|
2015-03-06 14:28:43 +01:00
|
|
|
res[i] = calcWeight<T, ET>(dist, &h[i], fixed_point_mult);
|
2015-03-05 17:50:52 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-18 14:59:52 +01:00
|
|
|
public:
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T> static inline int calcDist(const T a, const T b)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return calcDist_<T>::f(a, b);
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T>
|
|
|
|
static inline int calcDist(const Mat& m, int i1, int j1, int i2, int j2)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
|
|
|
const T a = m.at<T>(i1, j1);
|
|
|
|
const T b = m.at<T>(i2, j2);
|
2015-03-05 13:36:42 +01:00
|
|
|
return calcDist<T>(a,b);
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T>
|
|
|
|
static inline int calcUpDownDist(T a_up, T a_down, T b_up, T b_down)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return calcUpDownDist_<T>::f(a_up, a_down, b_up, b_down);
|
2015-02-18 14:59:52 +01:00
|
|
|
};
|
|
|
|
|
2015-03-05 17:50:52 +01:00
|
|
|
template <typename T, typename WT>
|
2015-03-06 15:06:11 +01:00
|
|
|
static inline WT calcWeight(double dist, const float *h,
|
|
|
|
typename pixelInfo<WT>::sampleType fixed_point_mult)
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 17:50:52 +01:00
|
|
|
return calcWeight_<T, WT>::f(dist, h, fixed_point_mult);
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 13:36:42 +01:00
|
|
|
template <typename T>
|
2015-03-10 01:34:02 +01:00
|
|
|
static inline int maxDist()
|
2015-02-18 14:59:52 +01:00
|
|
|
{
|
2015-03-05 13:36:42 +01:00
|
|
|
return (int)pixelInfo<T>::sampleMax() * (int)pixelInfo<T>::sampleMax() *
|
|
|
|
pixelInfo<T>::channels;
|
2015-02-18 14:59:52 +01:00
|
|
|
}
|
2015-02-12 15:23:28 +01:00
|
|
|
};
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-03-05 17:50:52 +01:00
|
|
|
template <typename T, typename IT, typename WT> struct incWithWeight_
|
2014-02-19 15:13:09 +01:00
|
|
|
{
|
2015-03-05 17:50:52 +01:00
|
|
|
static inline void f(IT* estimation, IT* weights_sum, WT weight, T p)
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-03-05 13:55:06 +01:00
|
|
|
estimation[0] += (IT)weight * p;
|
2015-03-05 17:50:52 +01:00
|
|
|
weights_sum[0] += (IT)weight;
|
2015-02-12 15:23:28 +01:00
|
|
|
}
|
|
|
|
};
|
2014-02-19 15:13:09 +01:00
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
template <typename ET, typename IT, typename WT> struct incWithWeight_<Vec<ET, 2>, IT, WT>
|
2014-02-19 15:13:09 +01:00
|
|
|
{
|
2015-03-06 14:28:43 +01:00
|
|
|
static inline void f(IT* estimation, IT* weights_sum, WT weight, Vec<ET, 2> p)
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-03-05 13:55:06 +01:00
|
|
|
estimation[0] += (IT)weight * p[0];
|
|
|
|
estimation[1] += (IT)weight * p[1];
|
2015-03-05 17:50:52 +01:00
|
|
|
weights_sum[0] += (IT)weight;
|
2015-02-12 15:23:28 +01:00
|
|
|
}
|
|
|
|
};
|
2014-02-19 15:13:09 +01:00
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
template <typename ET, typename IT, typename WT> struct incWithWeight_<Vec<ET, 3>, IT, WT>
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-03-06 14:28:43 +01:00
|
|
|
static inline void f(IT* estimation, IT* weights_sum, WT weight, Vec<ET, 3> p)
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-03-05 13:55:06 +01:00
|
|
|
estimation[0] += (IT)weight * p[0];
|
|
|
|
estimation[1] += (IT)weight * p[1];
|
|
|
|
estimation[2] += (IT)weight * p[2];
|
2015-03-05 17:50:52 +01:00
|
|
|
weights_sum[0] += (IT)weight;
|
2015-02-12 15:23:28 +01:00
|
|
|
}
|
|
|
|
};
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
template <typename ET, typename IT, typename WT> struct incWithWeight_<Vec<ET, 4>, IT, WT>
|
2015-03-03 01:19:34 +01:00
|
|
|
{
|
2015-03-06 14:28:43 +01:00
|
|
|
static inline void f(IT* estimation, IT* weights_sum, WT weight, Vec<ET, 4> p)
|
2015-03-03 01:19:34 +01:00
|
|
|
{
|
2015-03-05 13:55:06 +01:00
|
|
|
estimation[0] += (IT)weight * p[0];
|
|
|
|
estimation[1] += (IT)weight * p[1];
|
|
|
|
estimation[2] += (IT)weight * p[2];
|
|
|
|
estimation[3] += (IT)weight * p[3];
|
2015-03-05 17:50:52 +01:00
|
|
|
weights_sum[0] += (IT)weight;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
template <typename ET, typename IT, typename EW> struct incWithWeight_<Vec<ET, 2>, IT, Vec<EW, 2> >
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
2015-03-06 14:28:43 +01:00
|
|
|
static inline void f(IT* estimation, IT* weights_sum, Vec<EW, 2> weight, Vec<ET, 2> p)
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
|
|
|
estimation[0] += (IT)weight[0] * p[0];
|
|
|
|
estimation[1] += (IT)weight[1] * p[1];
|
|
|
|
weights_sum[0] += (IT)weight[0];
|
|
|
|
weights_sum[1] += (IT)weight[1];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
template <typename ET, typename IT, typename EW> struct incWithWeight_<Vec<ET, 3>, IT, Vec<EW, 3> >
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
2015-03-06 14:28:43 +01:00
|
|
|
static inline void f(IT* estimation, IT* weights_sum, Vec<EW, 3> weight, Vec<ET, 3> p)
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
|
|
|
estimation[0] += (IT)weight[0] * p[0];
|
|
|
|
estimation[1] += (IT)weight[1] * p[1];
|
|
|
|
estimation[2] += (IT)weight[2] * p[2];
|
|
|
|
weights_sum[0] += (IT)weight[0];
|
|
|
|
weights_sum[1] += (IT)weight[1];
|
|
|
|
weights_sum[2] += (IT)weight[2];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
template <typename ET, typename IT, typename EW> struct incWithWeight_<Vec<ET, 4>, IT, Vec<EW, 4> >
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
2015-03-06 14:28:43 +01:00
|
|
|
static inline void f(IT* estimation, IT* weights_sum, Vec<EW, 4> weight, Vec<ET, 4> p)
|
2015-03-05 17:50:52 +01:00
|
|
|
{
|
|
|
|
estimation[0] += (IT)weight[0] * p[0];
|
|
|
|
estimation[1] += (IT)weight[1] * p[1];
|
|
|
|
estimation[2] += (IT)weight[2] * p[2];
|
|
|
|
estimation[3] += (IT)weight[3] * p[3];
|
|
|
|
weights_sum[0] += (IT)weight[0];
|
|
|
|
weights_sum[1] += (IT)weight[1];
|
|
|
|
weights_sum[2] += (IT)weight[2];
|
|
|
|
weights_sum[3] += (IT)weight[3];
|
2015-03-03 01:19:34 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-05 17:50:52 +01:00
|
|
|
template <typename T, typename IT, typename WT>
|
2015-03-06 20:43:55 +01:00
|
|
|
static inline void incWithWeight(IT* estimation, IT* weights_sum, WT weight, T p)
|
2014-02-11 16:08:13 +01:00
|
|
|
{
|
2015-03-05 17:50:52 +01:00
|
|
|
return incWithWeight_<T, IT, WT>::f(estimation, weights_sum, weight, p);
|
2012-08-19 11:13:58 +02:00
|
|
|
}
|
|
|
|
|
2015-03-06 14:28:43 +01:00
|
|
|
template <typename IT, typename UIT, int nc, int nw> struct divByWeightsSum_
|
|
|
|
{
|
|
|
|
static inline void f(IT* estimation, IT* weights_sum);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename IT, typename UIT> struct divByWeightsSum_<IT, UIT, 1, 1>
|
|
|
|
{
|
|
|
|
static inline void f(IT* estimation, IT* weights_sum)
|
|
|
|
{
|
|
|
|
estimation[0] = (static_cast<UIT>(estimation[0]) + weights_sum[0]/2) / weights_sum[0];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename IT, typename UIT, int n> struct divByWeightsSum_<IT, UIT, n, 1>
|
|
|
|
{
|
|
|
|
static inline void f(IT* estimation, IT* weights_sum)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < n; i++)
|
|
|
|
estimation[i] = (static_cast<UIT>(estimation[i]) + weights_sum[0]/2) / weights_sum[0];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename IT, typename UIT, int n> struct divByWeightsSum_<IT, UIT, n, n>
|
|
|
|
{
|
|
|
|
static inline void f(IT* estimation, IT* weights_sum)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < n; i++)
|
|
|
|
estimation[i] = (static_cast<UIT>(estimation[i]) + weights_sum[i]/2) / weights_sum[i];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename IT, typename UIT, int nc, int nw>
|
|
|
|
static inline void divByWeightsSum(IT* estimation, IT* weights_sum)
|
|
|
|
{
|
|
|
|
return divByWeightsSum_<IT, UIT, nc, nw>::f(estimation, weights_sum);
|
|
|
|
}
|
|
|
|
|
2015-02-12 15:23:28 +01:00
|
|
|
template <typename T, typename IT> struct saturateCastFromArray_
|
2014-02-11 16:08:13 +01:00
|
|
|
{
|
2015-02-12 18:45:09 +01:00
|
|
|
static inline T f(IT* estimation)
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-02-12 18:45:09 +01:00
|
|
|
return saturate_cast<T>(estimation[0]);
|
2015-02-12 15:23:28 +01:00
|
|
|
}
|
|
|
|
};
|
2012-08-19 11:13:58 +02:00
|
|
|
|
2015-02-12 18:45:09 +01:00
|
|
|
template <typename ET, typename IT> struct saturateCastFromArray_<Vec<ET, 2>, IT>
|
2014-02-19 15:13:09 +01:00
|
|
|
{
|
2015-02-12 18:45:09 +01:00
|
|
|
static inline Vec<ET, 2> f(IT* estimation)
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-02-12 18:45:09 +01:00
|
|
|
Vec<ET, 2> res;
|
|
|
|
res[0] = saturate_cast<ET>(estimation[0]);
|
|
|
|
res[1] = saturate_cast<ET>(estimation[1]);
|
2015-02-12 15:23:28 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
2014-02-19 15:13:09 +01:00
|
|
|
|
2015-02-12 18:45:09 +01:00
|
|
|
template <typename ET, typename IT> struct saturateCastFromArray_<Vec<ET, 3>, IT>
|
2014-02-19 15:13:09 +01:00
|
|
|
{
|
2015-02-12 18:45:09 +01:00
|
|
|
static inline Vec<ET, 3> f(IT* estimation)
|
2015-02-12 15:23:28 +01:00
|
|
|
{
|
2015-02-12 18:45:09 +01:00
|
|
|
Vec<ET, 3> res;
|
|
|
|
res[0] = saturate_cast<ET>(estimation[0]);
|
|
|
|
res[1] = saturate_cast<ET>(estimation[1]);
|
|
|
|
res[2] = saturate_cast<ET>(estimation[2]);
|
2015-02-12 15:23:28 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
2014-02-19 15:13:09 +01:00
|
|
|
|
2015-03-03 01:19:34 +01:00
|
|
|
template <typename ET, typename IT> struct saturateCastFromArray_<Vec<ET, 4>, IT>
|
|
|
|
{
|
|
|
|
static inline Vec<ET, 4> f(IT* estimation)
|
|
|
|
{
|
|
|
|
Vec<ET, 4> res;
|
|
|
|
res[0] = saturate_cast<ET>(estimation[0]);
|
|
|
|
res[1] = saturate_cast<ET>(estimation[1]);
|
|
|
|
res[2] = saturate_cast<ET>(estimation[2]);
|
|
|
|
res[3] = saturate_cast<ET>(estimation[3]);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-12 15:23:28 +01:00
|
|
|
template <typename T, typename IT> static inline T saturateCastFromArray(IT* estimation)
|
2014-02-19 15:13:09 +01:00
|
|
|
{
|
2015-02-12 15:23:28 +01:00
|
|
|
return saturateCastFromArray_<T, IT>::f(estimation);
|
2014-02-19 15:13:09 +01:00
|
|
|
}
|
|
|
|
|
2012-08-19 11:13:58 +02:00
|
|
|
#endif
|