aimstil  5.0.5
misc_scalar_functions.h
Go to the documentation of this file.
1 #ifndef TIL_MISC_SCALAR_FUNCTIONS_H_
2 #define TIL_MISC_SCALAR_FUNCTIONS_H_
3 
5 
6 namespace til
7 {
9  template < typename T > INLINE const T square(const T &a) { return a*a;}
11  template < typename T > INLINE const T cube(const T &a) { return a*a*a;}
13  template < typename T > INLINE const T max(const T &a, const T &b) { return ((a>b)?a:b);}
15  template < typename T > INLINE const T min(const T &a, const T &b) { return ((a<b)?a:b);}
17  template < typename T > INLINE const T max(const T &a, const T &b, const T &c) { return max(max(a,b),c);}
19  template < typename T > INLINE const T min(const T &a, const T &b, const T &c) { return min(min(a,b),c);}
21  template < typename T > INLINE const T min(const T &a, const T &b, const T &c, const T &d) { return min(min(min(a,b),c),d);}
23  template < typename T >
24  inline const T crop(const T & x, const T & a, const T & b) { return min(max(x, a), b); }
26  template < typename T, typename TInt >
27  inline const T rangecrop(const T & x, TInt dim) { return crop<T>(x, 0, dim-1); }
29  // NB: I commented it out because std::abs should be used instead, it may be faster because working at the bit level.
30  //template < typename T > INLINE const T abs(const T &a) { return max(a, -a); }
32  template < typename T > INLINE double norm(const T &a, const T &b) { return std::sqrt(double(a*a+b*b)); }
34  template < typename T > INLINE double norm(const T &a, const T &b, const T &c) { return std::sqrt(double(a*a+b*b+c*c)); }
35 
36 
37  template < typename T >
38  inline
39  T integer_pow(T x, unsigned int n)
40  {
41  T res = (n%2 ? x : 1);
42  while (n >>= 1)
43  {
44  x *= x;
45  if (n%2)
46  {
47  res *= x;
48  }
49  }
50  return res;
51  }
52 
53 } // namespace til
54 
55 #endif /*MISC_SCALAR_FUNCTIONS_H_*/
56 
boost::enable_if< is_Image< TImage >, typename TImage::value_type >::type min(const TImage &im)
void sqrt(const TImage &in, TImage &out)
Definition: imageArith.h:326
INLINE double norm(const T &a, const T &b)
< Euclidean norm of 2D vector (a, b)
Belongs to package Box Do not include directly, include til/Box.h instead.
Definition: Accumulator.h:10
const T rangecrop(const T &x, TInt dim)
Absolute value of a number.
INLINE const T cube(const T &a)
Max of two numbers.
#define INLINE
Definition: til_common.h:26
TImage::value_type max(const TImage &im)
Returns the maximum intensity of the input image.
const T crop(const T &x, const T &a, const T &b)
Force x into [0, dim-1].
void square(const TImage &in, TImage &out)
Definition: imageArith.h:310
T integer_pow(T x, unsigned int n)