12 #include <boost/array.hpp> 13 #include <boost/type_traits.hpp> 16 #include "aims/vector/vector.h" 72 template <
typename T >
76 {
return x*x+y*y+z*z; }
148 template <
typename TContainer1,
typename TContainer2 >
149 typename boost::disable_if_c<
150 is_container<typename TContainer1::value_type>::value &&
151 is_container<typename TContainer2::value_type>::value
155 const TContainer1 & c1,
165 template <
typename TContainer1,
typename TContainer2 >
166 typename boost::enable_if_c<
167 is_container<typename TContainer1::value_type>::value &&
168 is_container<typename TContainer2::value_type>::value
172 const TContainer1 & c1,
180 typename TContainer1::const_iterator iC1 = c1.begin();
181 typename TContainer2::iterator iC2 = c2.begin();
182 for (; iC1 != c1.end(); ++iC1, ++iC2)
184 _allocate_sameSize<typename TContainer1::value_type, typename TContainer2::value_type>(*iC1, *iC2);
198 template <
typename TContainer1,
typename TContainer2 >
202 const TContainer1 & c1,
205 { detail::_allocate_sameSize<TContainer1, TContainer2>(c1,c2); }
240 template <
typename TPrecision,
typename TVector3D >
243 diff2(
const TVector3D &v1,
const TVector3D &v2)
244 {
return static_cast<TPrecision
>(
norm2(v1[0]-v2[0], v1[1]-v2[1], v1[2]-v2[2])); }
247 template <
typename TPrecision,
typename TVector3D >
250 diff(
const TVector3D &v1,
const TVector3D &v2)
251 {
return static_cast<TPrecision
>(
std::sqrt(diff2<double>(v1,v2))); }
256 template <
typename TVector3D,
typename TPrecision >
257 typename boost::enable_if_c<
258 is_3DVector<TVector3D>::value
260 operator()(
const TVector3D &v1,
const TVector3D &v2, TPrecision &res)
const 261 { res = diff2<TPrecision>(v1,v2); }
268 template <
typename TVector3D,
typename TPrecision >
269 void operator()(
const TVector3D &v1,
const TVector3D &v2, TPrecision &res)
const 270 { res = diff<TPrecision>(v1,v2); }
274 template <
typename TVector3D >
277 void operator()(
const TVector3D &v1,
const TVector3D &v2, TVector3D & res)
const 288 template <
typename TRes,
typename TIterator >
289 void mean(TIterator begin, TIterator end, TRes & res);
297 template <
typename TRes,
typename TCollection >
298 void centroid(
const TCollection & c, TRes & res)
299 __attribute__((__deprecated__(
"use mean() instead")));
301 template <
typename TRes,
typename TCollection >
304 mean(c.begin(), c.end(), res);
309 template <
typename TPo
int,
typename TPo
intCollection >
310 void stdev(
const TPointCollection & c, TPoint & res);
315 template <
typename T1,
typename T2 >
319 if (x >= 0)
return (y >= 0);
320 else return (y <= 0);
326 template <
typename T1,
typename T2 >
328 {
return (y >= 0 ? x : -x); }
332 template <
typename T >
335 static char *s =
new char[1024];
337 va_start(vl, format);
338 vsprintf(s, format, vl);
344 template <
typename T >
348 {
return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
360 template <
typename TIndexCollection >
361 std::vector<std::list<std::size_t> >
367 template <
typename TIterator >
371 {
return &*i < &*j; }
377 template <
typename T1,
typename T2 >
380 bool operator()(
const std::pair<T1,T2> & p1,
const std::pair<T1,T2> & p2)
const 381 {
return p1.second < p2.second; }
387 template <
typename T1,
typename T2 >
390 bool operator()(
const std::pair<T1,T2> & p1,
const std::pair<T1,T2> & p2)
const 391 {
return p1.second > p2.second; }
397 template <
typename T1,
typename T2 >
400 inline T1
operator()(std::pair<T1, T2>
const & p)
const {
return p.first; }
406 template <
typename T >
407 inline std::size_t
max_index(T x0, T x1, T x2);
412 template <
typename T >
413 inline std::size_t
min_index(T x0, T x1, T x2);
418 template <
typename T >
423 template <
typename TPrec >
426 template <
typename T, std::
size_t D >
437 template <
typename T >
443 template <
typename T >
444 inline int log2(T n);
449 template <
typename T >
450 inline T
exp2(
unsigned int n);
455 template <
typename T >
462 template <
typename T >
485 #endif //_MISCUTILS_H_ Returns first value of pair.
void stdev(const TPointCollection &c, TPoint &res)
TPrec norm2(const numeric_array< T, D > &a, prec< TPrec >)
Return the squared euclidean norm of a.
std::vector< std::list< std::size_t > > invertIndices(const std::vector< TIndexCollection > &c)
Invert an index array.
void sqrt(const TImage &in, TImage &out)
TPrecision diff2(const TVector3D &v1, const TVector3D &v2)
Computes the squared Euclidean distance between two vectors.
TPrecision diff(const TVector3D &v1, const TVector3D &v2)
Computes the Euclidean distance between two vectors.
bool operator()(const std::pair< T1, T2 > &p1, const std::pair< T1, T2 > &p2) const
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.
TAccumulationPoint centroid(const TPointCollection &c)
void operator()(const TVector3D &v1, const TVector3D &v2, TVector3D &res) const
bool operator()(TIterator i, TIterator j) const
std::size_t max_index(T x0, T x1, T x2)
Returns i0, where X_i0 is the greatesstructt of all Xi's.
numeric_array< T, D > size(const Box< T, D > &box)
Return the size of a box.
A policy label to indicate that radian range is [0; PI[.
T lower_dyadic(T n)
Return the greater power of two inferior or equal to n.
bool operator()(const T &x, const T &y) const
bool same_sign(const T1 &x, const T2 &y)
Return true iff both arguments have same sign.
T1 operator()(std::pair< T1, T2 > const &p) const
boost::enable_if_c< is_container< typename TContainer1::value_type >::value &&is_container< typename TContainer2::value_type >::value >::type _allocate_sameSize(const TContainer1 &c1, TContainer2 &c2)
void operator()(const TVector3D &v1, const TVector3D &v2, TPrecision &res) const
operator< on the address in memory of the pointed object
Computes the Euclidean distance between two vectors.
t_bsprec mean(const TImage &im)
Returns the mean of the intensities of the input image.
operator< on the second member of a pair.
int log2(T n)
Returns the largest m so that n >= 2^m.
char * sprintf(T format,...)
T operator()()
Return current value.
void allocate_sameSize(const TContainer1 &c1, TContainer2 &c2)
A simple function to allocate a container so that its size matches the size of a second container...
bool is_dyadic(T n)
Returns true if argument is of the form 2^m, m>=1.
This file contains all the material a library user should need to use template expressions.
bool operator()(const std::pair< T1, T2 > &p1, const std::pair< T1, T2 > &p2) const
Incrementor(T i0)
Initialize with value.
A class which returns a value that is increased everytime it is returned.
Normalize a vector with its Euclidean norm.
Computes the squared Euclidean distance between two vectors.
operator> on the second member of a pair.
T1 sign(T1 x, T2 y)
Change the sign of x if y < 0.
T exp2(unsigned int n)
Returns 2^n.
A dummy class used to pass a precision type for computations to some functions.
std::size_t min_index(T x0, T x1, T x2)
Returns i0, where X_i0 is the smallest of all Xi's.
boost::enable_if_c< is_3DVector< TVector3D >::value >::type operator()(const TVector3D &v1, const TVector3D &v2, TPrecision &res) const
TPrec dist2(const numeric_array< T1, D > &v1, const numeric_array< T2, D > &v2, prec< TPrec >)
Return the squared Euclidean distance between two vectors, computed with a precision given as the fir...
A policy label to indicate that radian range is ]-PI; PI].
bool is_nan(const numeric_array< T, D > &a)
Check that numeric_array does not contain any NAN TODO: Actually, is_nan should be a functor...