URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-28 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add homogen vector.
* mln/core/h_vec.hh: New.
* mln/core/point.hh: Know be casted as homogen vector.
* tests/h_vec.cc: New.
---
mln/core/h_vec.hh | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
mln/core/point.hh | 10 ++++++
tests/h_vec.cc | 62 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 155 insertions(+)
Index: trunk/milena/tests/h_vec.cc
===================================================================
--- trunk/milena/tests/h_vec.cc (revision 0)
+++ trunk/milena/tests/h_vec.cc (revision 1190)
@@ -0,0 +1,62 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/h_vec.cc
+ *
+ * \brief Tests on mln::h_vec.
+ */
+
+#include <mln/core/h_vec.hh>
+#include <mln/core/point3d.hh>
+
+using namespace mln;
+
+
+void run_in_3d(const metal::vec<3, int>&)
+{
+}
+
+void run_in_3d_h(const h_vec<3, int>&)
+{
+}
+
+
+int main()
+{
+
+ metal::vec<3, int> x;
+ h_vec<3, int> w = x;
+
+ typedef h_vec<3, int> p3d;
+ p3d p;
+ run_in_3d(p);
+
+ point3d k;
+ run_in_3d(k);
+ run_in_3d_h(k);
+
+}
Index: trunk/milena/mln/core/point.hh
===================================================================
--- trunk/milena/mln/core/point.hh (revision 1189)
+++ trunk/milena/mln/core/point.hh (revision 1190)
@@ -107,6 +107,9 @@
/// Hook to coordinates.
operator metal::vec<M::dim, C>() const;
+ /// Hook to homogene coordinate.
+ operator h_vec<M::dim, C>() const;
+
protected:
metal::vec<M::dim, C> coord_;
};
@@ -172,6 +175,13 @@
return coord_;
}
+ template <typename M, typename C>
+ point_<M,C>::operator h_vec<M::dim, C>() const
+ {
+ return coord_;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/core/h_vec.hh
===================================================================
--- trunk/milena/mln/core/h_vec.hh (revision 0)
+++ trunk/milena/mln/core/h_vec.hh (revision 1190)
@@ -0,0 +1,83 @@
+// Copyright (C) 2007 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// 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
+
+/*! \file mln/core/h_vec.hh
+ *
+ * \brief Definition of the mln::h_vec alias and of its
+ * construction routine.
+ */
+
+# include <mln/metal/vec.hh>
+
+
+namespace mln
+{
+
+
+ template <unsigned dim, typename T>
+ struct h_vec : public metal::vec<dim + 1, T>
+ {
+ h_vec()
+ : metal::vec<dim + 1, T>(make::vec<dim + 1, T>(0))
+ {
+ this->data_[dim] = 1;
+ }
+
+ h_vec(const metal::vec<dim, T>& x);
+
+ operator metal::vec<dim, T>() const;
+ };
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned dim, typename T>
+ h_vec<dim,T>::h_vec(const metal::vec<dim, T>& x)
+ {
+ for (unsigned i = 0; i < dim; ++i)
+ this->data_[i] = x[i];
+ this->data_[dim] = 1;
+ }
+
+ template <unsigned dim, typename T>
+ h_vec<dim,T>::operator metal::vec<dim,T>() const
+ {
+ metal::vec<dim,T> x;
+ for (unsigned i = 0; i < dim; ++i)
+ x[i] = this->data_[i] / this->data_[dim];
+ return x;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+#endif // ! MLN_CORE_H_VEC_HH