Commit ab372419 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

Move h_vec and h_mat in mln/ from core/ to algebra/.

	* mln/core/h_vec.hh,
	* mln/core/h_mat.hh: Rename as...
	* mln/algebra/h_vec.hh,
	* mln/algebra/h_mat.hh: ...these.
	Update.
	
	* tests/core/h_vec.cc,
	* tests/algebra/vec2.cc,
	* tests/algebra/mat.cc,
	* mln/core/point.hh,
	* mln/metal/vec.hh,
	* mln/fun/x2x/composed.hh,
	* mln/fun/x2x/translation.hh,
	* mln/fun/x2x/rotation.hh,
	* mln/fun/internal/x2x_linear_impl.hh,
	* mln/algebra/vec.hh: Update.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/branches/cleanup-2008@2178 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 6c12812f
2008-09-04 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Move h_vec and h_mat in mln/ from core/ to algebra/.
* mln/core/h_vec.hh,
* mln/core/h_mat.hh: Rename as...
* mln/algebra/h_vec.hh,
* mln/algebra/h_mat.hh: ...these.
Update.
* tests/core/h_vec.cc,
* tests/algebra/vec2.cc,
* tests/algebra/mat.cc,
* mln/core/point.hh,
* mln/metal/vec.hh,
* mln/fun/x2x/composed.hh,
* mln/fun/x2x/translation.hh,
* mln/fun/x2x/rotation.hh,
* mln/fun/internal/x2x_linear_impl.hh,
* mln/algebra/vec.hh: Update.
2008-09-04 Thierry Geraud <thierry.geraud@lrde.epita.fr>
 
Move some remaining core types in appropriate directories.
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -25,12 +25,14 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_CORE_H_MAT_HH
# define MLN_CORE_H_MAT_HH
#ifndef MLN_ALGEBRA_H_MAT_HH
# define MLN_ALGEBRA_H_MAT_HH
/*! \file mln/core/h_mat.hh
/*! \file mln/algebra/h_mat.hh
*
* \brief Definition of a matrix with homogeneous coordinates.
*
* \todo Add traits.
*/
# include <mln/algebra/mat.hh>
......@@ -39,44 +41,49 @@
namespace mln
{
/*! \brief N-Dimensional matrix with homogeneous coordinates.
*
*/
template <unsigned d, typename T>
struct h_mat : public algebra::mat<d+1, d+1, T>
namespace algebra
{
/// Dimension is the 'natural' one (3 for 3D), not the one of the vector (dim + 1)
enum { N = d,
M = d,
dim = d * d };
/// Constructor without argument.
h_mat();
/// Constructor with the underlying matrix.
h_mat(const algebra::mat<d+1, d+1, T>& x);
};
/*! \brief N-Dimensional matrix with homogeneous coordinates.
*
*/
template <unsigned d, typename T>
struct h_mat : public mat<d+1, d+1, T>
{
/// Dimension is the 'natural' one (3 for 3D), not the one of the vector (dim + 1)
enum { N = d,
M = d,
dim = d * d };
/// Constructor without argument.
h_mat();
/// Constructor with the underlying matrix.
h_mat(const mat<d+1, d+1, T>& x);
};
# ifndef MLN_INCLUDE_ONLY
template <unsigned d, typename T>
inline
h_mat<d,T>::h_mat()
: algebra::mat<d+1, d+1, T>(algebra::mat<d+1, d+1, T>::Id)
{
}
template <unsigned d, typename T>
inline
h_mat<d,T>::h_mat()
: mat<d+1, d+1, T>(mat<d+1, d+1, T>::Id)
{
}
template <unsigned d, typename T>
inline
h_mat<d,T>::h_mat(const algebra::mat<d+1, d+1, T>& x)
: algebra::mat<d+1, d+1, T>(x)
{
}
template <unsigned d, typename T>
inline
h_mat<d,T>::h_mat(const mat<d+1, d+1, T>& x)
: mat<d+1, d+1, T>(x)
{
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::algebra
} // end of namespace mln
#endif // ! MLN_CORE_H_MAT_HH
#endif // ! MLN_ALGEBRA_H_MAT_HH
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_CORE_H_VEC_HH
# define MLN_CORE_H_VEC_HH
#ifndef MLN_ALGEBRA_H_VEC_HH
# define MLN_ALGEBRA_H_VEC_HH
/*! \file mln/core/h_vec.hh
/*! \file mln/algebra/h_vec.hh
*
* \brief Definition of a vector with homogeneous coordinates.
*/
......@@ -36,12 +36,14 @@
# include <mln/algebra/vec.hh>
# include <mln/literal/one.hh>
namespace mln
{
// Fwd decl.
template <unsigned d, typename C> struct h_vec;
// Forward declaration.
namespace algebra {
template <unsigned d, typename C> struct h_vec;
}
namespace trait
......@@ -51,10 +53,10 @@ namespace mln
template < template <class> class Name,
unsigned d, typename C >
struct set_precise_unary_< Name, h_vec<d, C> >
struct set_precise_unary_< Name, algebra::h_vec<d, C> >
{
typedef mln_trait_unary(Name, C) V;
typedef h_vec<d, V> ret;
typedef algebra::h_vec<d, V> ret;
};
// For binary traits.
......@@ -63,111 +65,118 @@ namespace mln
unsigned d, typename C,
typename Q >
struct set_precise_binary_< Name,
h_vec<d, C>, h_vec<d, Q> >
algebra::h_vec<d, C>, algebra::h_vec<d, Q> >
{
typedef mln_trait_binary(Name, C, Q) V;
typedef h_vec<d, V> ret;
typedef algebra::h_vec<d, V> ret;
};
template < template <class, class> class Name,
unsigned d, typename C,
typename S >
struct set_precise_binary_< Name,
h_vec<d, C>, mln::value::scalar_<S> >
algebra::h_vec<d, C>, mln::value::scalar_<S> >
{
typedef mln_trait_binary(Name, C, S) V;
typedef h_vec<d, V> ret;
typedef algebra::h_vec<d, V> ret;
};
} // end of namespace mln::trait
/*! \brief N-Dimensional vector with homogeneous coordinates.
*
*/
template <unsigned d, typename C>
struct h_vec : public algebra::vec<d + 1, C>
namespace algebra
{
/// Dimension is the 'natural' one (3 for 3D), not the one of the vector (dim + 1).
enum { dim = d };
/// Constructor without argument.
h_vec();
/// Constructor with the underlying vector.
h_vec(const algebra::vec<d+1, C>& other);
h_vec& operator=(const algebra::vec<d+1, C>& rhs);
/*! \brief N-Dimensional vector with homogeneous coordinates.
*
*/
template <unsigned d, typename C>
struct h_vec : public vec<d + 1, C>
{
/// Dimension is the 'natural' one (3 for 3D), not the one of the vector (dim + 1).
enum { dim = d };
/// Back to the natural (non-homogeneous) space.
algebra::vec<d,C> to_vec() const;
};
/// Constructor without argument.
h_vec();
/// Constructor with the underlying vector.
h_vec(const vec<d+1, C>& other);
h_vec& operator=(const vec<d+1, C>& rhs);
/// Back to the natural (non-homogeneous) space.
vec<d,C> to_vec() const;
};
# ifndef MLN_INCLUDE_ONLY
template <unsigned d, typename C>
inline
h_vec<d,C>::h_vec()
{
/* Safety measure: set the last component to the unit (1). This
way, converting an unitialized h_vec to a vector won't trigger
division-by-zero errors if this last component were randomly
initialized to 0. */
this->data_[d] = literal::one;
}
template <unsigned d, typename C>
inline
h_vec<d,C>::h_vec(const algebra::vec<d+1, C>& other)
: algebra::vec<d+1, C>(other)
{
}
# ifndef MLN_INCLUDE_ONLY
template <unsigned d, typename C>
inline
h_vec<d,C>& h_vec<d,C>::operator=(const algebra::vec<d+1, C>& rhs)
{
if (& rhs == this)
return *this;
this->algebra::vec<d+1, C>::operator=(rhs);
return *this;
}
template <unsigned d, typename C>
inline
h_vec<d,C>::h_vec()
{
/* Safety measure: set the last component to the unit (1). This
way, converting an unitialized h_vec to a vector won't trigger
division-by-zero errors if this last component were randomly
initialized to 0. */
this->data_[d] = literal::one;
}
namespace algebra
{
template <unsigned d, typename C>
inline
h_vec<d,C>::h_vec(const vec<d+1, C>& other)
: vec<d+1, C>(other)
{
}
// Immersion of a vector in its homogeneous space.
template <unsigned n, typename T>
template <unsigned d, typename C>
inline
h_vec<n, T> vec<n,T>::to_h_vec() const
h_vec<d,C>& h_vec<d,C>::operator=(const vec<d+1, C>& rhs)
{
h_vec<n, T> tmp;
for (unsigned i = 0; i < n; ++i)
tmp[i] = this->data_[i];
tmp[n] = literal::one;
return tmp;
if (& rhs == this)
return *this;
this->vec<d+1, C>::operator=(rhs);
return *this;
}
} // end of namespace mln::algebra
namespace algebra
{
// Immersion of a vector in its homogeneous space.
template <unsigned n, typename T>
inline
h_vec<n, T> vec<n,T>::to_h_vec() const
{
h_vec<n, T> tmp;
for (unsigned i = 0; i < n; ++i)
tmp[i] = this->data_[i];
tmp[n] = literal::one;
return tmp;
}
template <unsigned d, typename C>
inline
algebra::vec<d,C> h_vec<d,C>::to_vec() const
{
const C w = this->data_[d];
mln_assertion(w != 0);
} // end of namespace mln::algebra
algebra::vec<d,C> tmp;
for (unsigned i = 0; i < d; ++i)
tmp[i] = this->data_[i] / w;
return tmp;
}
template <unsigned d, typename C>
inline
vec<d,C> h_vec<d,C>::to_vec() const
{
const C w = this->data_[d];
mln_assertion(w != 0);
vec<d,C> tmp;
for (unsigned i = 0; i < d; ++i)
tmp[i] = this->data_[i] / w;
return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::algebra
} // end of namespace mln
#endif // ! MLN_CORE_H_VEC_HH
#endif // ! MLN_ALGEBRA_H_VEC_HH
......@@ -197,7 +197,7 @@ namespace mln
// Immersion of the vector into its homogeneous space.
h_vec<n, T> to_h_vec() const;
algebra::h_vec<n, T> to_h_vec() const;
const T& operator[](unsigned i) const;
......
......@@ -42,7 +42,7 @@
# include <mln/metal/is_not.hh>
# include <mln/algebra/vec.hh>
# include <mln/metal/converts_to.hh>
# include <mln/core/h_vec.hh>
# include <mln/algebra/h_vec.hh>
# include <mln/util/yes.hh>
......@@ -69,7 +69,7 @@ namespace mln
struct point_to_
{
typedef algebra::vec<G::dim, C> metal_vec;
typedef mln::h_vec<G::dim, C> h_vec;
typedef mln::algebra::h_vec<G::dim, C> h_vec;
};
} // end of namespace mln::internal
......@@ -174,7 +174,7 @@ namespace mln
const algebra::vec<G::dim, C>& to_vec() const;
/// Transform to point in homogene coordinate system.
h_vec<G::dim, C> to_h_vec() const;
algebra::h_vec<G::dim, C> to_h_vec() const;
/// Point with all coordinates set to the maximum value.
static const point<G,C>& plus_infty();
......@@ -394,9 +394,9 @@ namespace mln
template <typename G, typename C>
inline
h_vec<G::dim, C> point<G,C>::to_h_vec() const
algebra::h_vec<G::dim, C> point<G,C>::to_h_vec() const
{
h_vec<G::dim, C> tmp;
algebra::h_vec<G::dim, C> tmp;
for (unsigned i = 0; i < dim; ++i)
tmp[i] = coord_[i];
tmp[G::dim] = 1;
......
......@@ -34,8 +34,8 @@
*/
# include <mln/core/concept/function.hh>
# include <mln/core/h_mat.hh>
# include <mln/core/h_vec.hh>
# include <mln/algebra/h_mat.hh>
# include <mln/algebra/h_vec.hh>
namespace mln
{
......@@ -54,11 +54,11 @@ namespace mln
typedef V argument;
typedef V result;
typedef typename V::coord coord;
typedef h_mat<dim, coord> matrix;
typedef algebra::h_mat<dim, coord> matrix;
V operator()(const V& x) const
{
h_vec<dim, coord> tmp = m_ * x.to_h_vec();
algebra::h_vec<dim, coord> tmp = m_ * x.to_h_vec();
return tmp.to_vec();
}
......
......@@ -38,7 +38,7 @@
# include <mln/algebra/vec.hh>
# include <mln/metal/is.hh>
# include <mln/metal/bexpr.hh>
# include <mln/core/h_mat.hh>
# include <mln/algebra/h_mat.hh>
namespace mln
......
......@@ -100,7 +100,7 @@ namespace mln
dir_(dir)
{
mln_precondition(dir == 2 || n == 3);
this->m_ = h_mat<n,C>::Id;
this->m_ = algebra::h_mat<n,C>::Id;
update();
}
......
......@@ -36,7 +36,7 @@
# include <mln/core/concept/function.hh>
# include <mln/fun/internal/x2x_linear_impl.hh>
# include <mln/algebra/vec.hh>
# include <mln/core/h_mat.hh>
# include <mln/algebra/h_mat.hh>
# include <mln/fun/i2v/all.hh>
namespace mln
......@@ -97,7 +97,7 @@ namespace mln
translation<n,C>::translation(const algebra::vec<n,C>& t)
:t_(t)
{
this->m_ = h_mat<n,C>::Id;
this->m_ = algebra::h_mat<n,C>::Id;
this->update();
}
......
......@@ -191,7 +191,7 @@ namespace mln
// Immersion of the vector into its homogeneous space.
h_vec<n, T> to_h_vec() const;
algebra::h_vec<n, T> to_h_vec() const;
const T& operator[](unsigned i) const;
......
......@@ -34,7 +34,7 @@
#include <iostream>
#include <mln/fun/i2v/all_to.hh>
#include <mln/algebra/mat.hh>
#include <mln/core/h_mat.hh>
#include <mln/algebra/h_mat.hh>
......@@ -45,9 +45,9 @@ int main()
algebra::mat<1,3,float> m1(all_to(4.));
algebra::mat<2,2,float> m2 = algebra::mat<2,2,float>::Id;
h_mat<1,float> hm1(m2);
h_mat<2,float> hm2;
h_mat<3,float> hm3(all_to(1.5));
algebra::h_mat<1,float> hm1(m2);
algebra::h_mat<2,float> hm2;
algebra::h_mat<3,float> hm3(all_to(1.5));
algebra::mat<4,4,float> m4 = hm3;
......@@ -59,7 +59,7 @@ int main()
std::cout << "hm3 = " << hm3 << ";" << std::endl;
{
h_mat<2,float> m, m2;
algebra::h_mat<2,float> m, m2;
m = m2;
// FIXME: Test *many* => runs ok...
}
......
......@@ -34,7 +34,7 @@
#include <iostream>
#include <mln/fun/i2v/all_to.hh>
#include <mln/algebra/vec.hh>
#include <mln/core/h_vec.hh>
#include <mln/algebra/h_vec.hh>
......@@ -45,10 +45,10 @@ int main()
algebra::vec<1,float> v1(all_to(4.));
algebra::vec<2,float> v2 = make::vec(6., 2.8);
h_vec<1,float> hv1;
h_vec<2,float> hv2 = v2.to_h_vec(); // Immersion into homogeneous.
algebra::h_vec<1,float> hv1;
algebra::h_vec<2,float> hv2 = v2.to_h_vec(); // Immersion into homogeneous.
h_vec<3,float> hv3(all_to(1.5));
algebra::h_vec<3,float> hv3(all_to(1.5));
hv3 += make::vec(0., 0., 0., 0.5);
......
// Copyright (C) 2007 EPITA Research and Development Laboratory
// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
......@@ -27,10 +27,10 @@
/*! \file tests/h_vec.cc
*
* \brief Tests on mln::h_vec.
* \brief Tests on mln::algebra::h_vec.
*/
#include <mln/core/h_vec.hh>
#include <mln/algebra/h_vec.hh>
#include <mln/core/alias/point3d.hh>
using namespace mln;
......@@ -40,12 +40,12 @@ void run_in_3d(const algebra::vec<3, int>&)
{
}
void run_in_3d_h(const h_vec<3, int>&)
void run_in_3d_h(const algebra::h_vec<3, int>&)
{
}
void foo(const mln::h_vec<3,float>&)
void foo(const mln::algebra::h_vec<3,float>&)
{
}
......@@ -54,9 +54,9 @@ int main()
{
algebra::vec<3, int> x;
h_vec<3, int> w = x.to_h_vec();
algebra::h_vec<3, int> w = x.to_h_vec();
typedef h_vec<3, int> p3d;
typedef algebra::h_vec<3, int> p3d;
p3d p;
run_in_3d(p.to_vec());
......@@ -66,7 +66,7 @@ int main()
{
algebra::vec<3,float> v;
h_vec<3,float> w(v.to_h_vec());
algebra::h_vec<3,float> w(v.to_h_vec());
w = v.to_h_vec();
foo(v.to_h_vec());
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment