27#ifndef _HUGIN_MATH_HUGIN_MATH_H
28#define _HUGIN_MATH_HUGIN_MATH_H
34#include <vigra/diff2d.hxx>
37 #define M_PI 3.14159265358979323846
41 #define PI 3.14159265358979323846
44#define DEG_TO_RAD( x ) ( (x) * 2.0 * PI / 360.0 )
45#define RAD_TO_DEG( x ) ( (x) * 360.0 / ( 2.0 * PI ) )
57 return (
float)
floor(x+0.5f);
67 return (
int)
floor(x);
138 return x * val.
x +
y * val.
y;
149 return (
other - *
this).squareLength();
173 if (p.x < min.x) p.x = min.x;
174 if (p.x > max.x) p.x = max.x;
175 if (p.y < min.y) p.y = min.y;
176 if (p.y > max.y) p.y = max.y;
194 template <
class InputIterator1,
class InputIterator2>
198 typename InputIterator1::value_type res = 0;
203 res = res + a*a + b*b;
211 template <
class InputIterator1,
class InputIterator2,
class T>
228 template <
class POINT>
231 double dx = p2.x - p1.x;
232 double dy = p2.y - p1.y;
233 double r =
sqrt(dx*dx + dy*dy) / 2.0;
234 double mx = p1.x + dx/2;
235 double my = p1.y + dy/2;
252 return o <<
"( " <<
d.x <<
" " <<
d.y <<
" )";
261inline vigra::Diff2D
operator*(
const vigra::Diff2D &
d,
double scale)
263 return vigra::Diff2D((
int)(
ceil(
d.x * scale)),
264 (
int)(
ceil(
d.y * scale)));
268inline vigra::Rect2D
operator*(
const vigra::Rect2D & r,
double scale)
270 return vigra::Rect2D( (
int)
floor(r.left()*scale),
271 (
int)
floor(r.top()*scale),
272 (
int)
ceil(r.right()*scale),
273 (
int)
ceil(r.bottom()*scale));
std::ostream & operator<<(std::ostream &o, const hugin_utils::TDiff2D< T > &d)
hugin_utils::FDiff2D operator/(const hugin_utils::FDiff2D &lhs, double val)
vigra::Diff2D operator*(const vigra::Diff2D &d, double scale)
namespace for various utils
double euclid_dist(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
calculate squared Euclidean distance between two vectors.
TDiff2D< double > FDiff2D
T sqr_dist(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T res)
calculate squared Euclidean distance between two vectors.
vigra::Rect2D calcCircleROIFromPoints(const POINT &p1, const POINT &p2)
calculate the bounding box of a circle that goes through both points.
T simpleClipPoint(const T &point, const T &min, const T &max)
clip a point to fit int [min, max] does not do a mathematical clipping, just sets p....
int gcd(int a, int b)
function to calculate greated common divisor using Euclidean algorithm both arguments should be >=0
TDiff2D operator+=(TDiff2D rhs)
TDiff2D & operator*=(double val)
bool operator!=(TDiff2D rhs) const
T squareLength() const
Return the square of the length of the vector.
TDiff2D(const vigra::Diff2D &d)
TDiff2D operator+(TDiff2D rhs) const
bool operator==(TDiff2D rhs) const
TDiff2D operator-(TDiff2D rhs) const
T squareDistance(TDiff2D< T > other) const
Return square of the distance to another point.
double operator*(TDiff2D val) const
vigra::Diff2D toDiff2D() const
TDiff2D operator*(double val) const
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.