1 #ifndef TIL_NUMERIC_ARRAY_TOOLS_H 2 #define TIL_NUMERIC_ARRAY_TOOLS_H 16 template <
typename T, std::
size_t D >
17 inline void resize(numeric_array<T,D> &, std::size_t newSize)
18 __attribute__((__deprecated__));
20 template <
typename T, std::
size_t D >
39 template <
typename TCollection >
44 typename TCollection::const_iterator iV = v.begin();
45 for (; iV != v.end(); ++iV)
55 template <
typename T, std::
size_t D >
56 inline std::ostream & operator<<(std::ostream & os, const numeric_array<T,D> & x)
61 template <
typename TPrec,
typename T, std::
size_t D >
64 typedef TPrec prec_type;
66 for (std::size_t i = 0; i < D; ++i)
68 res +=
square(static_cast<prec_type>(a[i]));
76 template <
typename T, std::
size_t D >
83 template <
typename TPrec,
typename T, std::
size_t D >
90 template <
typename T, std::
size_t D >
98 template <
typename TPrec,
typename T1,
typename T2, std::
size_t D >
103 typedef TPrec prec_type;
106 for (std::size_t i = 0; i < D; ++i)
110 res +=
square(static_cast<prec_type>(v1[i]) - static_cast<prec_type>(v2[i]));
118 template <
typename T, std::
size_t D >
127 template <
typename TPrec,
typename T1,
typename T2, std::
size_t D >
136 template <
typename T, std::
size_t D >
144 template <
typename TPrec,
typename T1,
typename T2, std::
size_t D >
148 typedef TPrec prec_type;
150 for (std::size_t i = 0; i < D; ++i) res += static_cast<prec_type>(a1[i]) * static_cast<prec_type>(a2[i]);
157 template <
typename T, std::
size_t D >
165 template <
typename T >
167 cross_line(T a1, T a2, T b1, T b2) {
return a1 * b2 - a2 * b1; }
173 template <
typename TPrec,
typename T1,
typename T2 >
180 cross_line<TPrec>(vec1[1], vec1[2], vec2[1], vec2[2]),
181 cross_line<TPrec>(vec1[2], vec1[0], vec2[2], vec2[0]),
182 cross_line<TPrec>(vec1[0], vec1[1], vec2[0], vec2[1])
189 template <
typename T1,
typename T2 >
195 til::square(cross_line<double>(vec1[1], vec1[2], vec2[1], vec2[2])) +
196 til::square(cross_line<double>(vec1[2], vec1[0], vec2[2], vec2[0])) +
197 til::square(cross_line<double>(vec1[0], vec1[1], vec2[0], vec2[1]))
204 template <
typename T, std::
size_t D >
209 for (std::size_t i = 0; i < D; ++i) res[i] =
std::abs(a[i]);
216 template <
typename T, std::
size_t D >
220 for (std::size_t i = 1; i < D; ++i)
max_helper(res, a[i]);
227 template <
typename T, std::
size_t D >
231 for (std::size_t i = 1; i < D; ++i)
min_helper(res, a[i]);
238 template <
typename T >
245 template <
typename T, std::
size_t D >
256 template <
typename T, std::
size_t D >
258 {
for (std::size_t i = 0; i < D; ++i) vec[i] = -vec[i]; }
263 template <
typename T, std::
size_t D,
typename TNewPrecision>
275 template <
typename T, std::
size_t D >
278 for (std::size_t i = 0; i < D; ++i)
if (
is_nan(a[i]))
return true;
284 template <
typename T >
286 {
return x[0] * y[1] - x[1] * y[0]; }
293 template <
int x,
int y,
int z,
typename TIN,
typename TOUT >
300 if (x) vOut[0] = vIn[0] + x;
301 if (y) vOut[1] = vIn[1] + y;
302 if (z) vOut[2] = vIn[2] + z;
309 template <
typename T >
317 for (
int j = 0; j < 3; ++j)
320 for (
int i = j; i < 3; ++i)
322 mat(i,j) = v[i] * vj;
330 template <
typename T >
339 for (
int j = 0; j < 3; ++j)
342 for (
int i = 0; i < 3; ++i)
344 mat(i,j) = v2[i] * v1j;
void min_helper(T &minx, T x)
Little helper for something often used when looking for a minimum.
numeric_array< TPrec, 3 > cross(const numeric_array< T1, 3 > &vec1, const numeric_array< T2, 3 > &vec2, prec< TPrec >)
Return the cross product of two 3D vectors.
TPrec norm2(const numeric_array< T, D > &a, prec< TPrec >)
Return the squared euclidean norm of a.
boost::enable_if< is_Image< TImage >, typename TImage::value_type >::type min(const TImage &im)
numeric_array< typename change_precision< T, TNewPrecision >::type, D > type
void sqrt(const TImage &in, TImage &out)
std::ostream & stream_collection(std::ostream &os, const TCollection &v)
TPrec dot(const numeric_array< T1, D > &a1, const numeric_array< T2, D > &a2, prec< TPrec >)
Return the dot product of two vectors.
A class to store a 3*3 symetric matrix.
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.
void resize(numeric_array< T, D > &, std::size_t newSize) __attribute__((__deprecated__))
T norm_inf(const numeric_array< T, D > &a)
Return the infinity norm (i.e. max absolute value) of array.
void tdot(numeric_array< T, 3 > const &v, SymMatrix3< T > &mat)
Stores v.v^T in mat.
numeric_array< T, D > abs(const numeric_array< T, D > &a)
Absolute value, element-wise.
TImage::value_type max(const TImage &im)
Returns the maximum intensity of the input image.
TPrec dist(const numeric_array< T1, D > &v1, const numeric_array< T2, D > &v2, prec< TPrec >)
Return the Euclidean distance between two arrays.
void addTo(const numeric_array< TIN, 3 > &vIn, numeric_array< TOUT, 3 > &vOut)
double cross_norm(const numeric_array< T1, 3 > &vec1, const numeric_array< T2, 3 > &vec2)
Return the norm of the cross product of two 3D vectors.
void max_helper(T &maxx, T x)
Little helper for something often used when looking for a maximum.
void square(const TImage &in, TImage &out)
Changing the numerical precision of an object.
A dummy class used to pass a precision type for computations to some functions.
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...
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...