Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
September 2007
- 7 participants
- 135 discussions
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-25 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Update memory managment for run_images.
* mln/core/rle_image.hh,
* mln/core/sparse_image.hh: Move the data allocation to the insert
method.
---
rle_image.hh | 6 ++----
sparse_image.hh | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)
Index: trunk/milena/mln/core/rle_image.hh
===================================================================
--- trunk/milena/mln/core/rle_image.hh (revision 1168)
+++ trunk/milena/mln/core/rle_image.hh (revision 1169)
@@ -125,10 +125,6 @@
template <typename P, typename T>
rle_image<P, T>::rle_image()
{
- // FIXME : ambiguity between empty constructor and constructor
- // which allocate data_
-
- // this->data_ = new internal::data_< rle_image<I,T> >();
}
template <typename P, typename T>
@@ -149,6 +145,8 @@
void
rle_image<P, T>::insert(const P& p, unsigned len, T value)
{
+ if (!this->has_data())
+ this->data_ = new internal::data_< rle_image<P,T> >();
this->data_->domain_.insert(p, len);
this->data_->values_.push_back(value);
}
Index: trunk/milena/mln/core/sparse_image.hh
===================================================================
--- trunk/milena/mln/core/sparse_image.hh (revision 1168)
+++ trunk/milena/mln/core/sparse_image.hh (revision 1169)
@@ -121,10 +121,6 @@
template <typename P, typename T>
sparse_image<P, T>::sparse_image()
{
- // FIXME : ambiguity between empty constructor and constructor
- // which allocate data_
-
- // this->data_ = new internal::data_< sparse_image<I,T> >();
}
template <typename P, typename T>
@@ -146,6 +142,8 @@
sparse_image<P, T>::insert(const P& p, unsigned len,
const std::vector<T>& value)
{
+ if (!this->has_data())
+ this->data_ = new internal::data_< sparse_image<P,T> >();
this->data_->domain_.insert(p, len);
this->data_->values_.push_back(value);
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-25 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add interpolation features for quaternions.
* mln/value/quat.hh: Update.
---
quat.hh | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 84 insertions(+), 1 deletion(-)
Index: trunk/milena/mln/value/quat.hh
===================================================================
--- trunk/milena/mln/value/quat.hh (revision 1167)
+++ trunk/milena/mln/value/quat.hh (revision 1168)
@@ -112,8 +112,25 @@
bool about_equal(const T& f, const T& q);
bool about_equal(const quat& p, const quat& q);
+ // Misc.
- // meths and procs bodies...
+ bool interpol_ok(const quat& p, const quat& q, float h);
+
+ // Linear Quaternion Interpolation.
+
+ quat lerp(const quat& p, const quat& q, float h);
+
+ // Spherical Linear Quaternion Interpolation.
+
+ quat slerp(const quat& p, const quat& q, float h);
+
+ quat slerp_2(const quat& p, const quat& q, float h);
+
+ quat slerp_3(const quat& p, const quat& q, float h);
+
+ quat slerp_4(const quat& p, const quat& q, float h);
+
+ quat slerp_5(const quat& p, const quat& q, float h);
# ifndef MLN_INCLUDE_ONLY
@@ -337,6 +354,72 @@
return about_equal<float>(norm::l2(p - q), 0);
}
+ // Misc.
+
+ bool interpol_ok(const quat& p, const quat& q, float h)
+ {
+ return
+ p.is_unit() &&
+ q.is_unit() &&
+ h >= 0 &&
+ h <= 1;
+ }
+
+
+ // Linear Quaternion Interpolation.
+
+ quat lerp(const quat& p, const quat& q, float h)
+ {
+ assert(interpol_ok(p, q, h));
+ return (1 - h) * p + h * q;
+ }
+
+
+ // Spherical Linear Quaternion Interpolation.
+
+ quat slerp(const quat& p, const quat& q, float h)
+ {
+ assert(interpol_ok(p, q, h));
+ float omega = acos(p.sprod(q));
+ return
+ about_equal(omega, 0.f) ?
+ lerp(p, q, h) :
+ quat((sin((1-h)*omega) * p + sin(h*omega) * q) / sin(omega));
+ }
+
+ quat slerp_2(const quat& p, const quat& q, float h)
+ {
+ assert(interpol_ok(p, q, h));
+ quat tmp = p * pow(p.conj() * q, h);
+ assert(about_equal(tmp, slerp(p, q, h)));
+ return tmp;
+ }
+
+ quat slerp_3(const quat& p, const quat& q, float h)
+ {
+ assert(interpol_ok(p, q, h));
+ quat tmp = pow(p * q.conj(), 1 - h) * q;
+ assert(about_equal(tmp, slerp(p, q, h)));
+ return tmp;
+ }
+
+ quat slerp_4(const quat& p, const quat& q, float h)
+ {
+ assert(interpol_ok(p, q, h));
+ quat tmp = pow(q * p.conj(), h) * p;
+ assert(about_equal(tmp, slerp(p, q, h)));
+ return tmp;
+ }
+
+ quat slerp_5(const quat& p, const quat& q, float h)
+ {
+ assert(interpol_ok(p, q, h));
+ quat tmp = q * pow(q.conj() * p, 1 - h);
+ assert(about_equal(tmp, slerp(p, q, h)));
+ return tmp;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::value
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-24 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Sparse_image fix.
* mln/core/sparse_image.hh: Fix.
---
sparse_image.hh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: trunk/milena/mln/core/sparse_image.hh
===================================================================
--- trunk/milena/mln/core/sparse_image.hh (revision 1166)
+++ trunk/milena/mln/core/sparse_image.hh (revision 1167)
@@ -124,7 +124,7 @@
// FIXME : ambiguity between empty constructor and constructor
// which allocate data_
- // this->data_ = new internal::data_< rle_image<I,T> >();
+ // this->data_ = new internal::data_< sparse_image<I,T> >();
}
template <typename P, typename T>
1
0
24 Sep '07
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-24 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Rotation is always centered at 0 and should work in 3d.
* mln/fun/x2x/rotation.hh: Update.
* tests/fun_x2x_rotation.cc: Update.
---
mln/fun/x2x/rotation.hh | 70 ++++++++++++++++++++++++++++------------------
tests/fun_x2x_rotation.cc | 4 --
2 files changed, 44 insertions(+), 30 deletions(-)
Index: trunk/milena/tests/fun_x2x_rotation.cc
===================================================================
--- trunk/milena/tests/fun_x2x_rotation.cc (revision 1165)
+++ trunk/milena/tests/fun_x2x_rotation.cc (revision 1166)
@@ -48,11 +48,9 @@
image2d_b<int_u8> lena = io::pgm::load("../img/lena.pgm");
image2d_b<int_u8> out(lena.domain());
- const float row = (float)(geom::max_row(lena) - geom::min_row(lena)) / 2;
- const float col = (float)(geom::max_col(lena) - geom::min_col(lena)) / 2;
interpolated<image2d_b<int_u8> > inter(lena);
- fun::x2x::rotation<2,float> rot1(3.1416, make::vec(row,col));
+ fun::x2x::rotation<2,float> rot1(0.1);
image2d_b<int_u8>::fwd_piter p(out.domain());
Index: trunk/milena/mln/fun/x2x/rotation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/rotation.hh (revision 1165)
+++ trunk/milena/mln/fun/x2x/rotation.hh (revision 1166)
@@ -60,18 +60,18 @@
typedef rotation<n,C> invert;
rotation();
- rotation(const float alpha, const metal::vec<n,C>& t);
+ rotation(float alpha, unsigned dir = 2);
result operator()(const metal::vec<n,C>& v) const;
invert inv() const;
- void set_t(const metal::vec<n,C>& t);
- void set_alpha(const float alpha);
+ void set_alpha(float alpha);
+ void set_dir(unsigned dir);
protected:
float alpha_;
- metal::vec<n,C> t_;
+ unsigned dir_;
metal::mat<n + 1,n + 1,C> m_;
};
@@ -81,28 +81,31 @@
template <unsigned n, typename C>
rotation<n,C>::rotation()
{
- t_ = make::vec<n,C>(0);
m_ = metal::mat<n+1,n+1,C>::Id;
}
template <unsigned n, typename C>
- rotation<n,C>::rotation(const float alpha, const metal::vec<n,C>& t)
+ rotation<n,C>::rotation(float alpha, unsigned dir)
:alpha_(alpha),
- t_(t)
+ dir_(dir)
{
const float cos_a = cos(alpha_);
const float sin_a = sin(alpha_);
- const float c_1 = 1 - cos_a;
- const float coord1 = c_1 * t[0] + sin_a * t[1];
- const float coord2 = t[1] * c_1 - sin_a * t[0];
+ const metal::vec<4,float> vec = make::vec(cos_a, -sin_a, sin_a, cos_a);
m_ = metal::mat<n+1,n+1,C>::Id;
- m_(0,2) = coord1;
- m_(1,2) = coord2;
- m_(0,0) = cos_a;
- m_(0,1) = -sin_a;
- m_(1,0) = sin_a;
- m_(1,1) = cos_a;
+ unsigned k = 0;
+ for (unsigned i = 0; i <= n; ++i)
+ {
+ if (i == dir)
+ continue;
+ for (unsigned j = 0; j <= n; ++j)
+ {
+ if (j == dir)
+ continue;
+ m_(i, j) = vec[k++];
+ }
+ }
}
template <unsigned n, typename C>
@@ -127,23 +130,14 @@
rotation<n,C>
rotation<n,C>::inv() const
{
- typename rotation::invert res(-alpha_, t_);
+ typename rotation::invert res(-alpha_, dir_);
return res;
}
template <unsigned n, typename C>
void
- rotation<n,C>::set_t(const metal::vec<n,C>& t)
- {
- t_ = t;
- for (unsigned i = 0; i < n; ++i)
- m_(i,n) = t_[i];
- }
-
- template <unsigned n, typename C>
- void
- rotation<n,C>::set_alpha(const float alpha)
+ rotation<n,C>::set_alpha(float alpha)
{
const float cos_a = cos(alpha);
const float sin_a = sin(alpha);
@@ -156,6 +150,28 @@
m_(1,1) = cos_a;
}
+ template <unsigned n, typename C>
+ void
+ rotation<n,C>::set_dir(unsigned dir)
+ {
+ const float cos_a = cos(alpha_);
+ const float sin_a = sin(alpha_);
+ const metal::vec<4,float> vec(cos_a, -sin_a, sin_a, cos_a);
+
+ m_ = metal::mat<n+1,n+1,C>::Id;
+ unsigned k = 0;
+ for (unsigned i = 0; i <= n; ++i)
+ {
+ if (i == dir)
+ continue;
+ for (unsigned j = 0; j <= n; ++j)
+ {
+ if (j == dir)
+ continue;
+ m_(i, j) = vec[k++];
+ }
+ }
+ }
# endif // ! MLN_INCLUDE_ONLY
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-24 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Add graph in sandbox.
* graph.hh: New.
* graph.hxx: New.
* main.cc: Update for graph.
* test_debug_iota_3d.cc: Update.
---
graph.hh | 78 +++++++++++++++++++++++++++++++++++++++++
graph.hxx | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++
main.cc | 57 ++++++------------------------
test_debug_iota_3d.cc | 2 -
4 files changed, 185 insertions(+), 46 deletions(-)
Index: trunk/milena/sandbox/duhamel/graph.hh
===================================================================
--- trunk/milena/sandbox/duhamel/graph.hh (revision 0)
+++ trunk/milena/sandbox/duhamel/graph.hh (revision 1165)
@@ -0,0 +1,78 @@
+// 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.
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_GRAPH_HH
+# define MLN_GRAPH_HH
+
+# include <cstddef>
+# include <iostream>
+# include <vector>
+# include <map>
+# include <mln/core/concept/object.hh>
+
+namespace mln
+{
+ namespace util
+ {
+
+ template<typename N, typename E = void>
+ class Graph
+ {
+ public:
+ typedef struct s_node
+ {
+ std::vector<unsigned> links;
+ } s_node;
+
+ typedef struct s_edge
+ {
+ unsigned node1;
+ unsigned node2;
+ } s_edge;
+
+ Graph () {}
+ Graph (unsigned nb_node, unsigned nb_link) :
+ nb_node_ (nb_node), nb_link_ (nb_link) {}
+ ~Graph () {}
+ void add_node ();
+ void add_edge (unsigned n1, unsigned n2);
+ void coherce ();
+ void print ();
+// void coherence () const;
+ private:
+ unsigned nb_node_;
+ unsigned nb_link_;
+ std::vector<s_node*> nodes_;
+ std::vector<s_edge*> links_;
+ };
+
+ } // end of util
+} // end of mln
+
+#include "graph.hxx"
+
+#endif // MLN_GRAPH_HH
Index: trunk/milena/sandbox/duhamel/graph.hxx
===================================================================
--- trunk/milena/sandbox/duhamel/graph.hxx (revision 0)
+++ trunk/milena/sandbox/duhamel/graph.hxx (revision 1165)
@@ -0,0 +1,94 @@
+#ifndef MLN_GRAPH_HXX
+# define MLN_GRAPH_HXX
+
+# include "graph.hh"
+
+namespace mln
+{
+
+ namespace util
+ {
+
+ template<typename N, typename E>
+ inline
+ void
+ Graph<N, E>::add_node ()
+ {
+ nodes_.push_back (new s_node);
+ ++nb_node_;
+ }
+
+ template<typename N, typename E>
+ inline
+ void
+ Graph<N, E>::add_edge (unsigned n1, unsigned n2)
+ {
+ mln_precondition(n1 < this->nb_node_);
+ mln_precondition(n2 < this->nb_node_);
+
+ s_edge* edge;
+
+ edge = new s_edge;
+ edge->node1 = n1;
+ edge->node2 = n2;
+ links_.push_back (edge);
+ ++nb_link_;
+ nodes_[n1]->links.push_back (n2);
+ }
+
+ template<typename N, typename E>
+ inline
+ void
+ Graph<N, E>::coherce ()
+ {
+ mln_precondition(nodes_.size () == this->nb_node_);
+ mln_precondition(links_.size () == this->nb_link_);
+ typename std::vector<s_node*>::const_iterator it = nodes_.begin ();
+ for (; it != nodes_.end (); ++it)
+ {
+ typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ for (; it2 != (*it)->links.end (); ++it2)
+ mln_precondition((*it2) < nb_node_);
+ }
+
+ typename std::vector<s_edge*>::const_iterator it3 = links_.begin ();
+ for (; it3 != links_.end (); ++it3)
+ {
+ mln_precondition((*it3)->node1 < nb_node_);
+ mln_precondition((*it3)->node2 < nb_node_);
+ }
+ }
+
+ template<typename N, typename E>
+ inline
+ void
+ Graph<N, E>::print ()
+ {
+ std::cout << "nodes :"
+ << std::endl;
+
+ typename std::vector<s_node*>::const_iterator it = nodes_.begin ();
+ int i = 0;
+ for (; it != nodes_.end (); ++it, ++i)
+ {
+ std::cout << "node number = "
+ << i
+ << " nbh : ";
+ typename std::vector<unsigned>::const_iterator it2 = (*it)->links.begin ();
+ for (; it2 != (*it)->links.end (); ++it2, ++i)
+ {
+ std::cout << (*it2)
+ << " ";
+ }
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ }
+
+
+
+ } // end of util
+
+} // end of mln
+
+#endif // MLN_GRAPH_HXX
Index: trunk/milena/sandbox/duhamel/main.cc
===================================================================
--- trunk/milena/sandbox/duhamel/main.cc (revision 1164)
+++ trunk/milena/sandbox/duhamel/main.cc (revision 1165)
@@ -1,54 +1,21 @@
-#include <mln/core/image2d_b.hh>
-#include <mln/value/int_u8.hh>
-#include <mln/debug/println.hh>
-
-
-#include <mln/geom/nrows.hh>
-#include <mln/geom/ncols.hh>
-
-#include <mln/level/fill.hh>
-
-#include <mln/debug/println_with_border.hh>
-
-#include "paste.hh"
-#include "fill.hh"
-
-//#include "level.hh"
-//#include "labeling.hh"
-
-#include <mln/core/image2d_b.hh>
-#include <mln/core/neighb2d.hh>
-#include <mln/value/int_u8.hh>
-#include <mln/pw/all.hh>
-
-#include <mln/io/pgm/load.hh>
-#include <mln/io/pgm/save.hh>
-#include <mln/labeling/foreground.hh>
-#include <mln/debug/println_with_border.hh>
-
+#include "graph.hh"
using namespace mln;
-int main (void)
+int
+main (void)
{
- image2d_b<value::int_u8> i1(3, 3);
-// Neighborhood<value::int_u8> nbh;
-
-// labeling::level (i1, 3, nbh,2);
-// image2d_b<int> i2(3, 3);
-// mln::sparse_image<mln::point2d, int> sparse;
-// mln::sparse_image<mln::point2d, int> sparse2;
-// mln::rle_image<mln::point2d, int> rle1;
-// mln::rle_image<mln::point2d, int> rle2;
-
+ mln::util::Graph<void> g (0,0);
-// level::fill_opt2(i1, 8);
+ g.add_node ();
+ g.add_node ();
+ g.add_node ();
+ g.add_edge (0,1);
+ g.coherce ();
+ g.print ();
-// debug::println_with_border(i1);
+// image2d_b<int> out (5, 5, 1);
-// level::paste(rle1, rle2);
-// level::fill(sparse, 42);
-// debug::println_with_border(i2);
+ // debug::println_with_border (out);
- return (0);
}
Index: trunk/milena/sandbox/duhamel/test_debug_iota_3d.cc
===================================================================
--- trunk/milena/sandbox/duhamel/test_debug_iota_3d.cc (revision 1164)
+++ trunk/milena/sandbox/duhamel/test_debug_iota_3d.cc (revision 1165)
@@ -43,7 +43,7 @@
main (void)
{
- image3d_b<bool> ima(2,3,3,1);
+ image3d_b<bool> ima(5,4,3,1);
debug::iota (ima);
debug::println_with_border(ima);
1
0
24 Sep '07
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-24 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Change images inheritance, and memory managment.
* mln/core/decorated_image.hh: Remove super_ typedef.
* mln/core/interpolated.hh: Inherit from identity morpher. Add memory
managment.
* mln/core/rle_image.hh,
* mln/core/sparse_image.hh,
* mln/core/internal/run_image.hh: Inherit from image_primary, move
domain_ attribute to the descendants classes rle_images and
sparse_image. Add memory managment to rle and sparse images.
* mln/core/safe.hh: Inherit from identity morpher. Add memory
managment.
* mln/value/stack.hh: Inherit from value morpher.
---
core/decorated_image.hh | 7 ----
core/internal/run_image.hh | 26 ----------------
core/interpolated.hh | 72 +++++++++++++++++++++++++++++----------------
core/rle_image.hh | 66 +++++++++++++++++++++++++++++++++++------
core/safe.hh | 62 ++++++++++++++++++++++++++++++--------
core/sparse_image.hh | 68 ++++++++++++++++++++++++++++++++++--------
value/stack.hh | 42 +++++---------------------
7 files changed, 217 insertions(+), 126 deletions(-)
Index: trunk/milena/mln/core/decorated_image.hh
===================================================================
--- trunk/milena/mln/core/decorated_image.hh (revision 1163)
+++ trunk/milena/mln/core/decorated_image.hh (revision 1164)
@@ -76,16 +76,13 @@
public internal::decorated_image_impl_< I, decorated_image<I,D> >,
public internal::image_identity_morpher_< I, mln_pset(I), decorated_image<I,D> >
{
+ public:
typedef decorated_image<I, D> self_;
typedef internal::decorated_image_impl_< I, self_ > impl_;
- typedef internal::image_identity_morpher_< I, mln_pset(I), self_ > super_;
/// Return type of read-write access.
typedef typename internal::morpher_lvalue_<I>::ret lvalue;
- public:
-
-
/// Ctors
decorated_image();
decorated_image(I& ima, const D& deco);
@@ -110,8 +107,6 @@
/// Give the decoration.
D& decoration();
- protected:
- using super_::data_;
};
Index: trunk/milena/mln/core/internal/run_image.hh
===================================================================
--- trunk/milena/mln/core/internal/run_image.hh (revision 1163)
+++ trunk/milena/mln/core/internal/run_image.hh (revision 1164)
@@ -50,20 +50,9 @@
* Parameter \c E is the Exact type of the image.
*/
template <typename P, typename E>
- class run_image_ : public image_base_<run_pset_<P>, E>
+ class run_image_ : public internal::image_primary_< internal::run_pset_<P>, E >
{
- public:
- typedef run_pset_<P> pset;
- typedef mln_psite(pset) psite;
-
- /// Give the definition domain.
- const pset& domain() const;
- /// Test if \p p is valid.
- bool owns_(const psite& site) const;
protected:
- /// domain of the image
- pset domain_;
-
run_image_();
};
@@ -74,19 +63,6 @@
{
}
- template <typename P, typename E>
- const typename run_image_<P, E>::pset&
- run_image_<P, E>::domain() const
- {
- return domain_;
- }
-
- template <typename P, typename E>
- bool
- run_image_<P, E>::owns_(const typename run_image_<P, E>::psite& site) const
- {
- return domain_.has(site);
- }
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace internal
Index: trunk/milena/mln/core/rle_image.hh
===================================================================
--- trunk/milena/mln/core/rle_image.hh (revision 1163)
+++ trunk/milena/mln/core/rle_image.hh (revision 1164)
@@ -34,6 +34,7 @@
*/
# include <mln/core/internal/run_image.hh>
+# include <mln/core/internal/run_pset.hh>
# include <mln/core/internal/run_psite.hh>
# include <mln/value/set.hh>
# include <vector>
@@ -41,6 +42,26 @@
namespace mln
{
+ // Fwd decl.
+ template <typename P, typename T> struct rle_image;
+
+ namespace internal
+ {
+
+ template <typename P, typename T>
+ struct data_< rle_image<P,T> >
+ {
+ data_();
+
+ /// Image values.
+ std::vector<T> values_;
+
+ /// domain of the image
+ run_pset_<P> domain_;
+ };
+
+ } // end of namespace mln::internal
+
/*! \brief RLE image.
*
*
@@ -57,6 +78,7 @@
typedef const T rvalue;
typedef internal::run_psite<P> psite;
typedef mln::value::set<T> vset;
+ typedef internal::run_pset_<P> pset;
/// Skeleton.
@@ -80,24 +102,40 @@
/// Give the set of values of the image.
const vset& values() const;
- protected:
- /// Image values.
- std::vector<T> values_;
+ /// Give the definition domain.
+ const pset& domain() const;
+
};
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< rle_image<I,S> >
+
+ template <typename P, typename T>
+ data_< rle_image<P,T> >::data_()
+ {
+ }
+
+ } // end of namespace mln::internal
+
template <typename P, typename T>
rle_image<P, T>::rle_image()
{
+ // FIXME : ambiguity between empty constructor and constructor
+ // which allocate data_
+
+ // this->data_ = new internal::data_< rle_image<I,T> >();
}
template <typename P, typename T>
bool
rle_image<P, T>::has_data() const
{
- return values_.size() != 0;
+ return this->data_->values_.size() != 0;
}
template <typename P, typename T>
@@ -111,8 +149,8 @@
void
rle_image<P, T>::insert(const P& p, unsigned len, T value)
{
- this->domain_.insert(p, len);
- values_.push_back(value);
+ this->data_->domain_.insert(p, len);
+ this->data_->values_.push_back(value);
}
template <typename P, typename T>
@@ -121,8 +159,8 @@
const
{
mln_precondition(this->has_data() &&
- site.pset_pos_() < values_.size());
- return values_[site.pset_pos_()];
+ site.pset_pos_() < this->data_->values_.size());
+ return this->data_->values_[site.pset_pos_()];
}
template <typename P, typename T>
@@ -130,9 +168,17 @@
rle_image<P, T>::operator() (const typename rle_image<P, T>::psite& site)
{
mln_precondition(this->has_data() &&
- site.pset_pos_() < values_.size());
- return values_[site.pset_pos_()];
+ site.pset_pos_() < this->data_->values_.size());
+ return this->data_->values_[site.pset_pos_()];
}
+
+ template <typename P, typename T>
+ const typename rle_image<P, T>::pset&
+ rle_image<P, T>::domain() const
+ {
+ return this->data_->domain_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/core/interpolated.hh
===================================================================
--- trunk/milena/mln/core/interpolated.hh (revision 1163)
+++ trunk/milena/mln/core/interpolated.hh (revision 1164)
@@ -35,18 +35,34 @@
# include <cmath>
-# include <mln/core/concept/image.hh>
+# include <mln/core/internal/image_identity_morpher.hh>
# include <mln/metal/vec.hh>
namespace mln
{
+ // Fwd decl.
+ template <typename I> struct interpolated;
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< interpolated<I> >
+ {
+ data_(I& ima);
+
+ I ima_;
+ };
+
+ } // end of namespace mln::internal
+
/*! \brief FIXME
*
*/
template <typename I>
- struct interpolated : public mln::internal::image_base_< mln_pset(I), interpolated<I> >
+ struct interpolated : public mln::internal::image_identity_morpher_< I, mln_pset(I), interpolated<I> >
{
/// Point_Site associated type.
typedef mln_psite(I) psite;
@@ -68,8 +84,9 @@
typedef interpolated< tag::image_<I> > skeleton;
- /// Constructor.
+ /// Constructors.
interpolated(I& ima);
+ interpolated();
/// Test if this image has been initialized.
@@ -81,9 +98,6 @@
/// Test if a pixel value is accessible at \p v.
bool owns_(const mln::metal::vec<I::point::dim, float>& v) const;
- /// Give the definition domain.
- const mln_pset(I)& domain() const;
-
/// Read-only access of pixel value at point site \p p.
mln_rvalue(I) operator()(const psite& p) const;
@@ -96,33 +110,48 @@
/// Give the set of values of the image.
const vset& values() const;
-
- protected:
- I& ima_;
};
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< interpolated<I,S> >
+
template <typename I>
- interpolated<I>::interpolated(I& ima)
+ data_< interpolated<I> >::data_(I& ima)
: ima_(ima)
{
+ }
+
+ } // end of namespace mln::internal
+
+ template <typename I>
+ interpolated<I>::interpolated(I& ima)
+ {
mln_precondition(ima.has_data());
+ this->data_ = new internal::data_< interpolated<I> >(ima);
+ }
+
+ template <typename I>
+ interpolated<I>::interpolated()
+ {
}
template <typename I>
bool interpolated<I>::has_data() const
{
- mln_invariant(ima_.has_data());
+ mln_invariant(this->data_->ima_.has_data());
return true;
}
template <typename I>
bool interpolated<I>::owns_(const psite& p) const
{
- return ima_.owns_(p);
+ return this->data_->ima_.owns_(p);
}
template <typename I>
@@ -131,29 +160,22 @@
mln_point(I) p;
for (unsigned i = 0; i < I::point::dim; ++i)
p[i] = static_cast<int>(round(v[i]));
- return ima_.owns_(p);
- }
-
- template <typename I>
- const mln_pset(I)&
- interpolated<I>::domain() const
- {
- return ima_.domain();
+ return this->data_->ima_.owns_(p);
}
template <typename I>
mln_rvalue(I)
interpolated<I>::operator()(const psite& p) const
{
- mln_precondition(ima_.owns_(p));
- return ima_(p);
+ mln_precondition(this->data_->ima_.owns_(p));
+ return this->data_->ima_(p);
}
template <typename I>
mln_lvalue(I)
interpolated<I>::operator()(const psite& p)
{
- return ima_(p);
+ return this->data_->ima_(p);
}
template <typename I>
@@ -163,8 +185,8 @@
mln_point(I) p;
for (unsigned i = 0; i < I::point::dim; ++i)
p[i] = static_cast<int>(round(v[i]));
- mln_assertion(ima_.owns_(p));
- return ima_(p);
+ mln_assertion(this->data_->ima_.owns_(p));
+ return this->data_->ima_(p);
}
template <typename I>
Index: trunk/milena/mln/core/safe.hh
===================================================================
--- trunk/milena/mln/core/safe.hh (revision 1163)
+++ trunk/milena/mln/core/safe.hh (revision 1164)
@@ -28,24 +28,43 @@
#ifndef MLN_CORE_SAFE_HH
# define MLN_CORE_SAFE_HH
-# include <mln/core/internal/image_adaptor.hh>
+# include <mln/core/internal/image_identity_morpher.hh>
namespace mln
{
+ // Fwd decl.
+ template <typename I> struct safe_image;
+
+ namespace internal
+ {
+
+ template <typename I>
+ struct data_< safe_image<I> >
+ {
+ data_(I& ima, const mln_value(I)& default_value);
+
+ I ima_;
+ mln_value(I) default_value_;
+ };
+
+ } // end of namespace mln::internal
+
+
// FIXME: Doc!
template <typename I>
- class safe_image : public internal::image_adaptor_< I, safe_image<I> >
+ class safe_image : public internal::image_identity_morpher_< I, mln_pset(I), safe_image<I> >
{
- typedef internal::image_adaptor_< I, safe_image<I> > super_;
+ typedef internal::image_identity_morpher_< I, mln_pset(I), safe_image<I> > super_;
public:
/// Skeleton.
typedef safe_image< tag::image_<I> > skeleton;
safe_image(I& ima, const mln_value(I)& default_value);
+ safe_image();
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
@@ -54,9 +73,6 @@
/// Const promotion via convertion.
operator safe_image<const I>() const;
-
- protected:
- mln_value(I) default_value_;
};
@@ -73,12 +89,30 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< safe_image<I,S> >
+
+ template <typename I>
+ data_< safe_image<I> >::data_(I& ima, const mln_value(I)& default_value)
+ : ima_(ima),
+ default_value_(default_value)
+ {
+ }
+
+ } // end of namespace mln::internal
+
// safe_image<I>
template <typename I>
safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value)
- : super_(ima),
- default_value_(default_value)
+ {
+ this->data_ = new internal::data_< safe_image<I> >(ima, default_value);
+ }
+
+ template <typename I>
+ safe_image<I>::safe_image()
{
}
@@ -87,8 +121,8 @@
safe_image<I>::operator()(const mln_psite(I)& p) const
{
if (! this->owns_(p))
- return default_value_;
- return this->adaptee_(p);
+ return this->data_->default_value_;
+ return this->data_->ima_(p);
}
template <typename I>
@@ -97,15 +131,15 @@
{
static mln_value(I) forget_it_;
if (! this->owns_(p))
- // so default_value_ is returned but cannot be modified
- return forget_it_ = default_value_;
- return this->adaptee_(p);
+ // so data_->default_value_ is returned but cannot be modified
+ return forget_it_ = this->data_->default_value_;
+ return this->data_->ima_(p);
}
template <typename I>
safe_image<I>::operator safe_image<const I>() const
{
- safe_image<const I> tmp(this->adaptee_, default_value_);
+ safe_image<const I> tmp(this->data_->ima_, this->data_->default_value_);
return tmp;
}
Index: trunk/milena/mln/core/sparse_image.hh
===================================================================
--- trunk/milena/mln/core/sparse_image.hh (revision 1163)
+++ trunk/milena/mln/core/sparse_image.hh (revision 1164)
@@ -34,6 +34,7 @@
*/
# include <mln/core/internal/run_image.hh>
+# include <mln/core/internal/run_pset.hh>
# include <mln/core/internal/run_psite.hh>
# include <mln/value/set.hh>
# include <vector>
@@ -41,6 +42,25 @@
namespace mln
{
+ // Fwd decl.
+ template <typename P, typename T> struct sparse_image;
+
+ namespace internal
+ {
+
+ template <typename P, typename T>
+ struct data_< sparse_image<P,T> >
+ {
+ data_();
+
+ /// Image values.
+ std::vector< std::vector<T> > values_;
+ /// domain of the image
+ run_pset_<P> domain_;
+ };
+
+ } // end of namespace mln::internal
+
/*! \brief Sparse image.
*
*
@@ -57,7 +77,7 @@
typedef const T rvalue;
typedef internal::run_psite<P> psite;
typedef mln::value::set<T> vset;
-
+ typedef internal::run_pset_<P> pset;
/// Skeleton.
typedef sparse_image< tag::psite_<P>, tag::value_<T> > skeleton;
@@ -80,23 +100,38 @@
/// Give the set of values of the image.
const vset& values() const;
- protected:
- /// Image values.
- std::vector< std::vector<value> > values_;
+ /// Give the definition domain.
+ const pset& domain() const;
};
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ // internal::data_< sparse_image<I,S> >
+
+ template <typename P, typename T>
+ data_< sparse_image<P,T> >::data_()
+ {
+ }
+
+ } // end of namespace mln::internal
+
template <typename P, typename T>
sparse_image<P, T>::sparse_image()
{
+ // FIXME : ambiguity between empty constructor and constructor
+ // which allocate data_
+
+ // this->data_ = new internal::data_< rle_image<I,T> >();
}
template <typename P, typename T>
bool
sparse_image<P, T>::has_data() const
{
- return values_.size() != 0;
+ return this->data_->values_.size() != 0;
}
template <typename P, typename T>
@@ -111,8 +146,8 @@
sparse_image<P, T>::insert(const P& p, unsigned len,
const std::vector<T>& value)
{
- this->domain_.insert(p, len);
- values_.push_back(value);
+ this->data_->domain_.insert(p, len);
+ this->data_->values_.push_back(value);
}
template <typename P, typename T>
@@ -121,9 +156,9 @@
(const typename sparse_image<P, T>::psite& site) const
{
mln_precondition(this->has_data() &&
- site.pset_pos_() < values_.size() &&
- site.index_() < values_[site.pset_pos_()].size());
- return values_[site.pset_pos_()][site.index_()];
+ site.pset_pos_() < this->data_->values_.size() &&
+ site.index_() < this->data_->values_[site.pset_pos_()].size());
+ return this->data_->values_[site.pset_pos_()][site.index_()];
}
template <typename P, typename T>
@@ -132,9 +167,16 @@
(const typename sparse_image<P,T>::psite& site)
{
mln_precondition(this->has_data() &&
- site.pset_pos_() < values_.size() &&
- site.index_() < values_[site.pset_pos_()].size());
- return values_[site.pset_pos_()][site.index_()];
+ site.pset_pos_() < this->data_->values_.size() &&
+ site.index_() < this->data_->values_[site.pset_pos_()].size());
+ return this->data_->values_[site.pset_pos_()][site.index_()];
+ }
+
+ template <typename P, typename T>
+ const typename sparse_image<P, T>::pset&
+ sparse_image<P, T>::domain() const
+ {
+ return this->data_->domain_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: trunk/milena/mln/value/stack.hh
===================================================================
--- trunk/milena/mln/value/stack.hh (revision 1163)
+++ trunk/milena/mln/value/stack.hh (revision 1164)
@@ -33,7 +33,7 @@
* \brief Definition of an image class FIXME
*/
-# include <mln/core/internal/image_base.hh>
+# include <mln/core/internal/image_value_morpher.hh>
# include <mln/metal/vec.hh>
# include <mln/value/set.hh>
@@ -59,6 +59,7 @@
public:
data_(const metal::vec<n,I>& imas);
metal::vec<n,I> imas_;
+ I& ima_;
};
}
@@ -97,10 +98,8 @@
*
*/
template <unsigned n, typename I>
- struct stack_image : public mln::internal::image_base_< mln_pset(I), stack_image<n,I> >
+ struct stack_image : public mln::internal::image_value_morpher_< I, stack_image<n,I> >
{
- typedef mln::internal::image_base_< mln_pset(I), stack_image<n,I> > parent;
-
/// Point_Site associated type.
typedef mln_psite(I) psite;
@@ -132,12 +131,6 @@
/// Test if this image has been initialized.
bool has_data() const;
- /// Test if a pixel value is accessible at \p p.
- bool owns_(const psite& p) const;
-
- /// Give the definition domain.
- const mln_pset(I)& domain() const;
-
/// Read-only access of pixel value at point site \p p.
rvalue operator()(const psite& p) const;
value read_(const psite& p) const;
@@ -148,8 +141,6 @@
/// Give the set of values of the image.
const vset& values() const;
-
- using parent::data_;
};
@@ -173,7 +164,8 @@
template <unsigned n, typename I>
data_< value::stack_image<n,I> >::data_(const metal::vec<n,I>& imas)
- : imas_(imas)
+ : imas_(imas),
+ ima_(imas_[0])
{
}
@@ -192,7 +184,7 @@
template <unsigned n, typename I>
stack_image<n,I>::stack_image(const metal::vec<n,I>& imas)
{
- data_ = new mln::internal::data_< stack_image<n, I> >(imas);
+ this->data_ = new mln::internal::data_< stack_image<n, I> >(imas);
for (unsigned i = 0; i < n; ++i)
{
mln_precondition(imas[i].has_data());
@@ -203,34 +195,18 @@
bool stack_image<n,I>::has_data() const
{
for (unsigned i = 0; i < n; ++i)
- mln_invariant(data_->imas_[i].has_data());
- return true;
- }
-
- template <unsigned n, typename I>
- bool stack_image<n,I>::owns_(const psite& p) const
- {
- for (unsigned i = 0; i < n; ++i)
- if (! data_->imas_[i].owns_(p))
- return false;
+ mln_invariant(this->data_->imas_[i].has_data());
return true;
}
template <unsigned n, typename I>
- const mln_pset(I)&
- stack_image<n,I>::domain() const
- {
- return data_->imas_[0].domain();
- }
-
- template <unsigned n, typename I>
metal::vec<n, mln_value(I)>
stack_image<n,I>::read_(const psite& p) const
{
mln_precondition(this->owns_(p));
metal::vec<n, mln_value(I)> tmp;
for (unsigned i = 0; i < n; ++i)
- tmp[i] = data_->imas_[i].operator()(p);
+ tmp[i] = this->data_->imas_[i].operator()(p);
return tmp;
}
@@ -248,7 +224,7 @@
mln_precondition(this->owns_(p));
// FIXME!!!
for (unsigned i = 0; i < n; ++i)
- data_->imas_[i].operator()(p) = v[i];
+ this->data_->imas_[i].operator()(p) = v[i];
}
template <unsigned n, typename I>
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-24 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add rotation and fix for translation.
* mln/fun/x2x/rotation.hh: New.
* mln/fun/x2x/translation.hh: Fix.
* mln/metal/mat.hh: Fix, declarations.
* tests/fun_x2x_rotation.cc: New.
* tests/fun_x2x_translation.cc: Fix.
---
mln/fun/x2x/rotation.hh | 170 +++++++++++++++++++++++++++++++++++++++++++
mln/fun/x2x/translation.hh | 4 -
mln/metal/mat.hh | 79 +++++++++++++++++++
tests/fun_x2x_rotation.cc | 68 +++++++++++++++++
tests/fun_x2x_translation.cc | 1
5 files changed, 319 insertions(+), 3 deletions(-)
Index: trunk/milena/tests/fun_x2x_translation.cc
===================================================================
--- trunk/milena/tests/fun_x2x_translation.cc (revision 1162)
+++ trunk/milena/tests/fun_x2x_translation.cc (revision 1163)
@@ -50,4 +50,5 @@
std::cout << vec1 << std::endl;
std::cout << tr1(vec1) << std::endl;
+ std::cout << tr1.inv()(vec1) << std::endl;
}
Index: trunk/milena/tests/fun_x2x_rotation.cc
===================================================================
--- trunk/milena/tests/fun_x2x_rotation.cc (revision 0)
+++ trunk/milena/tests/fun_x2x_rotation.cc (revision 1163)
@@ -0,0 +1,68 @@
+// 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/image2d_b.cc
+ *
+ * \brief Tests on mln::image2d_b.
+ */
+
+
+#include <iostream>
+#include <mln/fun/x2x/rotation.hh>
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/pgm/load.hh>
+#include <mln/io/pgm/save.hh>
+#include <mln/core/interpolated.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d_b<int_u8> lena = io::pgm::load("../img/lena.pgm");
+ image2d_b<int_u8> out(lena.domain());
+
+ const float row = (float)(geom::max_row(lena) - geom::min_row(lena)) / 2;
+ const float col = (float)(geom::max_col(lena) - geom::min_col(lena)) / 2;
+ interpolated<image2d_b<int_u8> > inter(lena);
+
+ fun::x2x::rotation<2,float> rot1(3.1416, make::vec(row,col));
+
+ image2d_b<int_u8>::fwd_piter p(out.domain());
+
+ for_all(p)
+ {
+ metal::vec<2,float> v = rot1.inv()((point2d::vec_t)(point2d)p);
+ if (inter.owns_(v))
+ out(p) = inter(v);
+ else
+ out(p) = 255;
+ }
+ io::pgm::save(out, "out.pgm");
+}
Index: trunk/milena/mln/fun/x2x/translation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/translation.hh (revision 1162)
+++ trunk/milena/mln/fun/x2x/translation.hh (revision 1163)
@@ -56,7 +56,7 @@
enum {dim = n};
typedef metal::vec<n,C> result;
- typedef metal::vec<n,C> invert;
+ typedef translation<n,C> invert;
translation();
translation(const metal::vec<n,C>& t);
@@ -102,7 +102,7 @@
}
template <unsigned n, typename C>
- metal::vec<n,C>
+ translation<n,C>
translation<n,C>::inv() const
{
typename translation::invert res(-t_);
Index: trunk/milena/mln/fun/x2x/rotation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/rotation.hh (revision 0)
+++ trunk/milena/mln/fun/x2x/rotation.hh (revision 1163)
@@ -0,0 +1,170 @@
+// 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_FUN_X2X_ROTATION_HH
+# define MLN_FUN_X2X_ROTATION_HH
+
+/*! \file mln/fun/x2x/rotation.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/metal/vec.hh>
+# include <mln/metal/mat.hh>
+# include <cmath>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace x2x
+ {
+
+ // FIXME: Doc!
+
+ template <unsigned n, typename C>
+ struct rotation : public Function_x2x< rotation<n,C> >
+ {
+
+ enum {dim = n};
+
+ typedef metal::vec<n,C> result;
+ typedef rotation<n,C> invert;
+
+ rotation();
+ rotation(const float alpha, const metal::vec<n,C>& t);
+
+ result operator()(const metal::vec<n,C>& v) const;
+ invert inv() const;
+
+ void set_t(const metal::vec<n,C>& t);
+ void set_alpha(const float alpha);
+
+ protected:
+
+ float alpha_;
+ metal::vec<n,C> t_;
+ metal::mat<n + 1,n + 1,C> m_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n, typename C>
+ rotation<n,C>::rotation()
+ {
+ t_ = make::vec<n,C>(0);
+ m_ = metal::mat<n+1,n+1,C>::Id;
+ }
+
+ template <unsigned n, typename C>
+ rotation<n,C>::rotation(const float alpha, const metal::vec<n,C>& t)
+ :alpha_(alpha),
+ t_(t)
+ {
+ const float cos_a = cos(alpha_);
+ const float sin_a = sin(alpha_);
+ const float c_1 = 1 - cos_a;
+ const float coord1 = c_1 * t[0] + sin_a * t[1];
+ const float coord2 = t[1] * c_1 - sin_a * t[0];
+
+ m_ = metal::mat<n+1,n+1,C>::Id;
+ m_(0,2) = coord1;
+ m_(1,2) = coord2;
+ m_(0,0) = cos_a;
+ m_(0,1) = -sin_a;
+ m_(1,0) = sin_a;
+ m_(1,1) = cos_a;
+ }
+
+ template <unsigned n, typename C>
+ metal::vec<n,C>
+ rotation<n,C>::operator()(const metal::vec<n,C>& v) const
+ {
+ metal::mat<n+1,1,C> hmg;
+ metal::mat<n+1,1,C> tmp;
+ metal::vec<n,C> res;
+
+ for (unsigned i = 0; i < n; ++i)
+ hmg(i,0) = v[i];
+ hmg(n,0) = 1;
+ tmp = m_ * hmg;
+ mln_assertion(tmp(n,0) == 1);
+ for (unsigned i = 0; i < n; ++i)
+ res[i] = tmp(i,0);
+ return res;
+ }
+
+ template <unsigned n, typename C>
+ rotation<n,C>
+ rotation<n,C>::inv() const
+ {
+ typename rotation::invert res(-alpha_, t_);
+
+ return res;
+ }
+
+ template <unsigned n, typename C>
+ void
+ rotation<n,C>::set_t(const metal::vec<n,C>& t)
+ {
+ t_ = t;
+ for (unsigned i = 0; i < n; ++i)
+ m_(i,n) = t_[i];
+ }
+
+ template <unsigned n, typename C>
+ void
+ rotation<n,C>::set_alpha(const float alpha)
+ {
+ const float cos_a = cos(alpha);
+ const float sin_a = sin(alpha);
+
+ alpha_ = alpha;
+
+ m_(0,0) = cos_a;
+ m_(0,1) = -sin_a;
+ m_(1,0) = sin_a;
+ m_(1,1) = cos_a;
+ }
+
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::x2x
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_X2X_ROTATION_HH
Index: trunk/milena/mln/metal/mat.hh
===================================================================
--- trunk/milena/mln/metal/mat.hh (revision 1162)
+++ trunk/milena/mln/metal/mat.hh (revision 1163)
@@ -74,6 +74,83 @@
T data_[n][m];
};
+ // eq
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ bool
+ operator==(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ bool
+ operator!=(const mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
+
+ // +
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,T>&
+ operator+=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,typename binary_arith_trait<T,U>::ret>
+ operator+(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
+
+ // -
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,T>&
+ operator-=(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,typename binary_arith_trait<T,U>::ret>
+ operator-(mat<n,m,T>& lhs, const mat<n,m,U>& rhs);
+
+ template <unsigned n, unsigned m, typename T>
+ mat<n,m,T>
+ operator-(const mat<n,m,T>& lhs);
+
+ // *
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,T>&
+ operator*=(mat<n,m,T>& lhs, const U& scalar);
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,typename binary_arith_trait<T,U>::ret>
+ operator*(mat<n,m,T>& lhs, const U& scalar);
+
+ template <unsigned n, unsigned m, unsigned o, typename T, typename U>
+ mat<n,m,T>&
+ operator*=(mat<n,o,T>& lhs, mat<o,m,U>& rhs);
+
+ template <unsigned n, unsigned m, unsigned o, typename T, typename U>
+ mat<n,m,typename binary_arith_trait<T,U>::ret>
+ operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs);
+
+ // /
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,T>
+ operator/=(mat<n,m,T>& lhs, const U& scalar);
+
+ template <unsigned n, unsigned m, typename T, typename U>
+ mat<n,m,typename binary_arith_trait<T,U>::ret>
+ operator/(mat<n,m,T>& lhs, const U& scalar);
+
+ // <<
+
+ template <unsigned n, unsigned m, typename T>
+ std::ostream&
+ operator<<(std::ostream& ostr, const mat<n,m,T>& v);
+
+ template <unsigned n, unsigned m>
+ std::ostream&
+ operator<<(std::ostream& ostr, const mat<n,m,unsigned char>& v);
+
+ template <unsigned n, unsigned m>
+ std::ostream&
+ operator<<(std::ostream& ostr, const mat<n,m,signed char>& v);
+
+
# ifndef MLN_INCLUDE_ONLY
template <unsigned n, unsigned m, typename T>
@@ -246,7 +323,7 @@
}
template <unsigned n, unsigned m, unsigned o, typename T, typename U>
mat<n,m,typename binary_arith_trait<T,U>::ret>
- operator*(mat<n,o,T>& lhs, mat<o,m,U>& rhs)
+ operator*(const mat<n,o,T>& lhs, const mat<o,m,U>& rhs)
{
mat<n,m,typename binary_arith_trait<T,U>::ret> tmp;
for (unsigned i = 0; i < n; ++i)
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Augment initialization mechanism.
New initialization mechanism.
* mln/core/init.hh: New.
* mln/tag/init.hh: New.
* mln/core/clone.hh: Update; now call init.
* mln/core/internal/image_base.hh (init_): Remove; obsolete.
Now in mln/core/init.hh.
* mln/core/internal/image_morpher.hh (init_): Inactivate.
(init_): New version so that priority is lowered and ambiguity
suppressed.
Update.
* mln/core/image_if.hh
(pset, psite, self_, super_, data_): Remove; obsolete.
(init_): Overload method.
(init_): New overload in impl::.
* mln/core/image1d_b.hh,
* mln/core/image2d_b.hh,
* mln/core/image3d_b.hh,
* mln/core/sub_image.hh (init_): New overload in impl::.
(init_with): Rename as...
(init_): ...these.
Renaming in skeleton tags.
* mln/tag/skeleton.hh (<name>): Rename as...
(<name>_): ...these.
* mln/trait/ch_value.hh,
* mln/pw/image.hh,
* mln/core/decorated_image.hh,
* mln/core/image_if.hh,
* mln/core/rle_image.hh,
* mln/core/interpolated.hh,
* mln/core/image2d_b.hh,
* mln/core/cast_image.hh,
* mln/core/safe.hh,
* mln/core/pset_if.hh,
* mln/core/sub_image.hh,
* mln/core/sparse_image.hh,
* mln/core/t_image.hh,
* mln/core/image1d_b.hh,
* mln/core/image3d_b.hh,
* mln/value/props.hh,
* mln/value/stack.hh,
* tests/image2d_b.cc,
* tests/image_if.cc: Update.
Misc.
* mln/core/pset_if.hh (pset_f): New ctor.
(pset_): Unqualify.
(predicate): New.
* mln/metal/vec.hh (super_): Change to protected.
* mln/value/quat.hh (super_): New.
(data_): Make use Explicit.
mln/core/cast_image.hh | 2
mln/core/clone.hh | 3
mln/core/decorated_image.hh | 2
mln/core/image1d_b.hh | 43 ++++++++++-
mln/core/image2d_b.hh | 34 +++------
mln/core/image3d_b.hh | 43 ++++++++++-
mln/core/image_if.hh | 80 +++++++++++++++-------
mln/core/init.hh | 134 +++++++++++++++++++++++++++++++++++++
mln/core/internal/image_base.hh | 15 ----
mln/core/internal/image_morpher.hh | 57 +++++++++++++++
mln/core/interpolated.hh | 2
mln/core/pset_if.hh | 22 +++++-
mln/core/rle_image.hh | 2
mln/core/safe.hh | 2
mln/core/sparse_image.hh | 2
mln/core/sub_image.hh | 11 +--
mln/core/t_image.hh | 2
mln/metal/vec.hh | 2
mln/pw/image.hh | 2
mln/tag/init.hh | 54 ++++++++++++++
mln/tag/skeleton.hh | 12 +--
mln/trait/ch_value.hh | 14 +--
mln/value/props.hh | 1
mln/value/quat.hh | 3
mln/value/stack.hh | 2
tests/image2d_b.cc | 2
tests/image_if.cc | 19 ++++-
27 files changed, 466 insertions(+), 101 deletions(-)
Index: tests/image2d_b.cc
--- tests/image2d_b.cc (revision 1161)
+++ tests/image2d_b.cc (working copy)
@@ -33,6 +33,8 @@
#include <mln/core/image2d_b.hh>
#include <mln/geom/size2d.hh>
+#include <mln/core/init.hh>
+
int main()
{
Index: tests/image_if.cc
--- tests/image_if.cc (revision 1161)
+++ tests/image_if.cc (working copy)
@@ -40,7 +40,24 @@
{
using namespace mln;
- image2d_b<int> ima(8, 8);
+ typedef image2d_b<int> I;
+ I ima(8, 8);
// debug::println(ima | fun::p2b::chess);
mln_assertion((ima | fun::p2b::chess).npoints() = 32);
+
+ {
+ typedef image_if<I, fun::p2b::chess_t> II;
+ II ima_ref = ima | fun::p2b::chess;
+ debug::println(ima_ref);
+ {
+ II ima_ref_;
+ ima_ref_ = ima_ref;
+ debug::println(ima_ref_);
+ }
+ {
+ II ima_;
+ init(ima_, ima_ref);
+ debug::println(ima_);
+ }
+ }
}
Index: mln/trait/ch_value.hh
--- mln/trait/ch_value.hh (revision 1161)
+++ mln/trait/ch_value.hh (working copy)
@@ -59,35 +59,35 @@
template < template <class> class M, typename I,
typename V >
- struct ch_value_< M< tag::image<I> >, V >
+ struct ch_value_< M< tag::image_<I> >, V >
{
typedef M< mln_ch_value(I, V) > ret;
};
template < template <class> class M, typename T,
typename V >
- struct ch_value_< M< tag::value<T> >, V >
+ struct ch_value_< M< tag::value_<T> >, V >
{
typedef M< V > ret;
};
template < template <class, class> class M, typename T, typename I,
typename V >
- struct ch_value_< M< tag::value<T>, tag::image<I> >, V >
+ struct ch_value_< M< tag::value_<T>, tag::image_<I> >, V >
{
typedef mln_ch_value(I, V) ret;
};
template < template <class, class> class M, typename P, typename T,
typename V >
- struct ch_value_< M< tag::psite<P>, tag::value<T> >, V >
+ struct ch_value_< M< tag::psite_<P>, tag::value_<T> >, V >
{
typedef M< P, V > ret;
};
template < template <unsigned, class> class M, unsigned n, typename I,
typename V >
- struct ch_value_< M< n, tag::image<I> >, V > // For mln::value::stack_image<n,I> !
+ struct ch_value_< M< n, tag::image_<I> >, V > // For mln::value::stack_image<n,I> !
{
typedef metal::vec<n, V> value;
typedef mln_ch_value(I, value) ret;
@@ -95,14 +95,14 @@
template < template <class, class> class M, typename I, typename S,
typename V >
- struct ch_value_< M< tag::image<I>, tag::pset<S> >, V >
+ struct ch_value_< M< tag::image_<I>, tag::pset_<S> >, V >
{
typedef M< mln_ch_value(I, V), S > ret;
};
template < template <class, class> class M, typename F, typename S,
typename V >
- struct ch_value_< M< tag::function<F>, tag::pset<S> >, V >
+ struct ch_value_< M< tag::function_<F>, tag::pset_<S> >, V >
{
typedef typename S::mesh mesh;
typedef typename image_from_mesh< mesh, V >::ret ret; // FIXME: from_psite instead? coord=int!?
Index: mln/pw/image.hh
--- mln/pw/image.hh (revision 1161)
+++ mln/pw/image.hh (working copy)
@@ -81,7 +81,7 @@
struct image : public internal::image_primary_< S, image<F,S> >
{
/// Skeleton.
- typedef image< tag::function<F>, tag::pset<S> > skeleton;
+ typedef image< tag::function_<F>, tag::pset_<S> > skeleton;
/// Value associated type.
Index: mln/core/decorated_image.hh
--- mln/core/decorated_image.hh (revision 1161)
+++ mln/core/decorated_image.hh (working copy)
@@ -97,7 +97,7 @@
typedef mln_vset(I) vset;
/// Skeleton.
- typedef decorated_image< tag::image<I>, tag::data<D> > skeleton;
+ typedef decorated_image< tag::image_<I>, tag::data_<D> > skeleton;
mln_value(I) read_(const mln_psite(I)& p) const;
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 1161)
+++ mln/core/image_if.hh (working copy)
@@ -68,16 +68,8 @@
pset_if<mln_pset(I),F>,
image_if<I,F> >
{
-
-
/// Skeleton.
- typedef image_if< tag::image<I>, tag::function<F> > skeleton;
-
- /// Point_Site associated type.
- typedef pset_if<mln_pset(I), F> pset;
-
- /// Psite type.
- typedef mln_psite(pset) psite;
+ typedef image_if< tag::image_<I>, tag::function_<F> > skeleton;
/// Constructor from an image \p ima and a predicate \p f.
image_if(I& ima, const F& f);
@@ -85,25 +77,20 @@
/// Constructor without argument.
image_if();
+ /// Initialization.
+ void init_(I& ima, const F& f);
+
+ /// Initialization.
+ void init_(I& ima, const pset_if<mln_pset(I), F>& pset);
+
/// Test if a pixel value is accessible at \p p.
bool owns_(const mln_psite(I)& p) const;
/// Give the definition domain.
- const pset& domain() const;
+ const pset_if<mln_pset(I), F>& domain() const;
/// Const promotion via convertion.
operator image_if<const I, F>() const;
-
-
- protected:
-
- /// Self type.
- typedef image_if<I,F> self_;
-
- /// Super type.
- typedef internal::image_base_< pset_if<mln_pset(I), F>, image_if<I,F> > super_;
-
- using super_::data_;
};
@@ -137,11 +124,39 @@
# ifndef MLN_INCLUDE_ONLY
- namespace internal
+ // impl::init_
+
+ namespace impl
+ {
+
+ template <typename I, typename F>
+ void init_(tag::function_t, F& f, const image_if<I,F>& model)
+ {
+ f = model.domain().predicate();
+ }
+
+ template <typename I, typename F, typename J>
+ void init_(tag::image_t, image_if<I,F>& target, const J& model)
{
+ I ima;
+ init_(tag::image, ima, model);
+ F f;
+ init_(tag::function, f, model);
+ target.init_(ima, f);
+ // Alternative code:
+ // pset_if<mln_pset(I), F> pset;
+ // init_(tag::domain, pset, model);
+ // target.init_(ima, pset);
+ }
+
+ } // end of namespace mln::impl
+
// internal::data_< image_if<I,S> >
+ namespace internal
+ {
+
template <typename I, typename F>
data_< image_if<I,F> >::data_(I& ima, const F& f)
: ima_(ima),
@@ -168,10 +183,26 @@
template <typename I, typename F>
image_if<I,F>::image_if(I& ima, const F& f)
{
+ init_(ima, f);
+ }
+
+ template <typename I, typename F>
+ void
+ image_if<I,F>::init_(I& ima, const F& f)
+ {
+ mln_precondition(! this->has_data());
this->data_ = new internal::data_< image_if<I,F> >(ima, f);
}
template <typename I, typename F>
+ void
+ image_if<I,F>::init_(I& ima, const pset_if<mln_pset(I), F>& pset)
+ {
+ mln_precondition(! this->has_data());
+ this->data_ = new internal::data_< image_if<I,F> >(ima, pset);
+ }
+
+ template <typename I, typename F>
image_if<I,F>::operator image_if<const I, F>() const
{
image_if<const I, F> tmp(this->data_->ima_, this->data_->pset_);
@@ -182,19 +213,18 @@
bool
image_if<I,F>::owns_(const mln_psite(I)& p) const
{
- return data_->pset_.has(p);
+ return this->data_->pset_.has(p);
}
template <typename I, typename F>
const pset_if<mln_pset(I), F>&
image_if<I,F>::domain() const
{
- return data_->pset_;
+ return this->data_->pset_;
}
-
// Operators.
template <typename I, typename F>
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 1161)
+++ mln/core/internal/image_base.hh (working copy)
@@ -55,18 +55,6 @@
} // end of namespace mln::internal
- namespace impl
- {
-
- /// Declaration of the general image initialization routine.
- template <typename I, typename J>
- void init_(Image<I>& target, const Image<J>& model);
-
- // FIXME: Say more about it!
-
- } // end of namespace mln::impl
-
-
namespace internal
{
@@ -265,4 +253,7 @@
} // end of namespace mln
+# include <mln/core/init.hh>
+
+
#endif // ! MLN_CORE_INTERNAL_IMAGE_BASE_HH
Index: mln/core/internal/image_morpher.hh
--- mln/core/internal/image_morpher.hh (revision 1161)
+++ mln/core/internal/image_morpher.hh (working copy)
@@ -76,9 +76,36 @@
image_morpher_();
};
+ } // end of namespace mln::internal
+
+
+
+ namespace impl
+ {
+
+ // Default is delegation for morphers.
+
+// template <typename Subject, typename T,
+// typename I, typename S, typename E>
+// void init_(Subject s, T& target,
+// const internal::image_morpher_<I,S,E>& model);
+
+// FIXME: Lines above have been inactivated because they are either
+// prioritary or ambiguous.
+
+ template <typename Subject, typename T,
+ typename J>
+ void init_(Subject s, T& target, const Image<J>& model);
+
+ } // end of namespace mln::impl
+
+
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
template <typename I, typename S, typename E>
image_morpher_<I,S,E>::image_morpher_()
{
@@ -115,10 +142,36 @@
this->delegatee_()->has_data();
}
-# endif // ! MLN_INCLUDE_ONLY
-
} // end of namespace mln::internal
+ namespace impl
+ {
+
+// template <typename Subject, typename T,
+// typename I, typename S, typename E>
+// void init_(Subject s, T& target,
+// const internal::image_morpher_<I,S,E>& model)
+// {
+// // FIXME: Precondition.
+// init_(s, target, * model.delegatee_());
+// }
+
+ template <typename Subject, typename T,
+ typename J>
+ void init_(Subject s, T& target,
+ const Image<J>& model_)
+ {
+ // FIXME: Precondition.
+ // FIXME: Properly check that J is an internal::image_morpher_.
+ const J& model = exact(model_);
+ init_(s, target, * model.delegatee_());
+ }
+
+ } // end of namespace mln::impl
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
} // end of namespace mln
Index: mln/core/rle_image.hh
--- mln/core/rle_image.hh (revision 1161)
+++ mln/core/rle_image.hh (working copy)
@@ -60,7 +60,7 @@
/// Skeleton.
- typedef rle_image< tag::psite<P>, tag::value<T> > skeleton;
+ typedef rle_image< tag::psite_<P>, tag::value_<T> > skeleton;
rle_image();
Index: mln/core/interpolated.hh
--- mln/core/interpolated.hh (revision 1161)
+++ mln/core/interpolated.hh (working copy)
@@ -65,7 +65,7 @@
/// Skeleton.
- typedef interpolated< tag::image<I> > skeleton;
+ typedef interpolated< tag::image_<I> > skeleton;
/// Constructor.
Index: mln/core/init.hh
--- mln/core/init.hh (revision 0)
+++ mln/core/init.hh (revision 0)
@@ -0,0 +1,134 @@
+// 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_INIT_HH
+# define MLN_CORE_INIT_HH
+
+/*! \file mln/core/init.hh
+ *
+ * \brief Initialization of an image from another one.
+ */
+
+# include <mln/tag/init.hh>
+
+# include <mln/core/concept/image.hh>
+# include <mln/geom/bbox.hh>
+# include <mln/border/get.hh>
+
+
+
+namespace mln
+{
+
+ /*! Initialize the image \p target with data extracted from image \p model.
+ *
+ * \param[in, out] target The image to be initialized.
+ * \param[in] model The image to provide data for the initialization.
+ *
+ * \pre (not target.has_data) and model.has_data
+ */
+ template <typename I, typename J>
+ void init(Image<I>& target, const Image<J>& model);
+
+
+
+ // Fwd decl.
+
+ namespace impl
+ {
+
+ template <typename Subject, typename T, typename M>
+ void init_(Subject, T& target, const Object<M>& model);
+
+ // Easy and final versions.
+
+ template <typename B, typename I>
+ void init_(tag::bbox_t, B& b, const Image<I>& ima);
+
+ template <typename I>
+ void init_(tag::border_t, unsigned& bdr, const Image<I>& ima);
+
+ template <typename I>
+ void init_(tag::domain_t, mln_pset(I)& pset, const Image<I>& ima);
+
+ } // end of namespace mln::impl
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename Subject, typename T, typename M>
+ void init_(Subject, T&, const Object<M>&)
+ {
+ struct ERROR err_; // FIXME: Explicit msg.
+ }
+
+ // Easy impl.
+
+ template <typename B, typename I>
+ void init_(tag::bbox_t, B& b, const Image<I>& ima)
+ {
+ b = geom::bbox(ima);
+ }
+
+ template <typename I>
+ void init_(tag::border_t, unsigned& bdr, const Image<I>& ima)
+ {
+ bdr = border::get(ima);
+ }
+
+ template <typename I>
+ void init_(tag::domain_t, mln_pset(I)& pset, const Image<I>& ima)
+ {
+ pset = exact(ima).domain();
+ }
+
+ } // end of namespace mln::impl
+
+
+ // Facade.
+
+ template <typename I, typename J>
+ void init(Image<I>& target, const Image<J>& model)
+ {
+ mln_precondition(! exact(target).has_data());
+ mln_precondition(exact(model).has_data());
+
+ impl::init_(tag::image, exact(target), exact(model));
+
+ mln_postcondition(exact(target).has_data());
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INIT_HH
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1161)
+++ mln/core/image2d_b.hh (working copy)
@@ -40,9 +40,7 @@
# include <mln/value/set.hh>
# include <mln/fun/i2v/all.hh>
# include <mln/core/line_piter.hh>
-# include <mln/border/get.hh>
-# include <mln/debug/println.hh>
-# include <mln/geom/bbox.hh>
+
// FIXME:
@@ -127,7 +125,7 @@
/// Skeleton.
- typedef image2d_b< tag::value<T> > skeleton;
+ typedef image2d_b< tag::value_<T> > skeleton;
/// Value_Set associated type.
@@ -145,6 +143,7 @@
/// 3).
image2d_b(const box2d& b, unsigned bdr = border::thickness);
+
/// Initialize an empty image.
void init_(const box2d& b, unsigned bdr = border::thickness);
@@ -203,7 +202,7 @@
{
template <typename T, typename J>
- void init_(image2d_b<T>& target, const J& model);
+ void init_(tag::image_t, mln::image2d_b<T>& target, const J& model);
} // end of namespace mln::impl
@@ -217,24 +216,19 @@
namespace impl
{
-// void init(tag::border, unsigned b, const image2d_b<T>& model)
-// {
-// b = model.border();
-// }
+ template <typename T>
+ void init_(tag::border_t, unsigned& b, const image2d_b<T>& model)
+ {
+ b = model.border();
+ }
template <typename T, typename J>
- void init_(image2d_b<T>& target, const J& model)
+ void init_(tag::image_t, image2d_b<T>& target, const J& model)
{
- box2d b = geom::bbox(model);
- unsigned bdr = border::get(model);
-
- // FIXME
-
-// box2d b;
-// init(tag::bbox, b, model);
-// unsigned bdr;
-// init(tag::border, bdr, model);
-
+ box2d b;
+ init_(tag::bbox, b, model);
+ unsigned bdr;
+ init_(tag::border, bdr, model);
target.init_(b, bdr);
}
Index: mln/core/cast_image.hh
--- mln/core/cast_image.hh (revision 1161)
+++ mln/core/cast_image.hh (working copy)
@@ -81,7 +81,7 @@
/// Skeleton.
- typedef cast_image_< tag::value<T>, tag::image<I> > skeleton;
+ typedef cast_image_< tag::value_<T>, tag::image_<I> > skeleton;
/// Constructor.
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 1161)
+++ mln/core/safe.hh (working copy)
@@ -43,7 +43,7 @@
public:
/// Skeleton.
- typedef safe_image< tag::image<I> > skeleton;
+ typedef safe_image< tag::image_<I> > skeleton;
safe_image(I& ima, const mln_value(I)& default_value);
Index: mln/core/pset_if.hh
--- mln/core/pset_if.hh (revision 1161)
+++ mln/core/pset_if.hh (working copy)
@@ -80,9 +80,12 @@
typedef internal::fixme bkd_piter;
- /// Constructor without argument.
+ /// Constructor with a point set \p pset and a predicate \p f.
pset_if(const S& pset, const F& f);
+ /// Constructor without argument.
+ pset_if();
+
/// Test if \p p belongs to the subset.
bool has(const psite& p) const;
@@ -99,9 +102,12 @@
/// Test predicate on point site \p p.
bool pred(const psite& p) const;
+ /// Give the predicate function.
+ const F& predicate() const;
+
protected:
- const S& pset_;
+ S pset_;
F f_;
};
@@ -156,6 +162,18 @@
{
}
+ template <typename S, typename F>
+ pset_if<S,F>::pset_if()
+ {
+ }
+
+ template <typename S, typename F>
+ const F&
+ pset_if<S,F>::predicate() const
+ {
+ return f_;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/sub_image.hh
--- mln/core/sub_image.hh (revision 1161)
+++ mln/core/sub_image.hh (working copy)
@@ -62,7 +62,7 @@
struct sub_image : public internal::image_domain_morpher_< I, S, sub_image<I,S> >
{
/// Skeleton.
- typedef sub_image< tag::image<I>, tag::pset<S> > skeleton;
+ typedef sub_image< tag::image_<I>, tag::pset_<S> > skeleton;
/// Constructor without argument.
sub_image();
@@ -95,7 +95,7 @@
{
template <typename I, typename S, typename J>
- void init_(sub_image<I,S>& target, const J& model);
+ void init_(tag::image_t, sub_image<I,S>& target, const J& model);
} // end of namespace mln::impl
@@ -109,11 +109,12 @@
{
template <typename I, typename S, typename J>
- void init_(sub_image<I,S>& target, const J& model)
+ void init_(tag::image_t, sub_image<I,S>& target, const J& model)
{
I ima;
- init_(ima, model); // rec
- S pset = model.domain();
+ init_(tag::image, ima, model);
+ S pset;
+ init_(tag::domain, pset, model);
target.init_(ima, pset);
}
Index: mln/core/sparse_image.hh
--- mln/core/sparse_image.hh (revision 1161)
+++ mln/core/sparse_image.hh (working copy)
@@ -60,7 +60,7 @@
/// Skeleton.
- typedef sparse_image< tag::psite<P>, tag::value<T> > skeleton;
+ typedef sparse_image< tag::psite_<P>, tag::value_<T> > skeleton;
sparse_image();
Index: mln/core/clone.hh
--- mln/core/clone.hh (revision 1161)
+++ mln/core/clone.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/init.hh>
# include <mln/level/fill.hh>
@@ -58,7 +59,7 @@
{
// FIXME: Add a static check that mln_concrete(I) actually *is* concrete...
mln_concrete(I) tmp;
- impl::init_(tmp, exact(model));
+ init(tmp, model);
level::fill(tmp, model);
return tmp;
}
Index: mln/core/t_image.hh
--- mln/core/t_image.hh (revision 1161)
+++ mln/core/t_image.hh (working copy)
@@ -50,7 +50,7 @@
struct t_image : public internal::image_adaptor_< I, t_image<I> >
{
/// Skeleton.
- typedef t_image< tag::image<I> > skeleton;
+ typedef t_image< tag::image_<I> > skeleton;
/// Test if a pixel value is accessible at \p p.
bool owns_(const mln_point(I)& p) const;
Index: mln/core/image1d_b.hh
--- mln/core/image1d_b.hh (revision 1161)
+++ mln/core/image1d_b.hh (working copy)
@@ -125,7 +125,7 @@
/// Skeleton.
- typedef image1d_b< tag::value<T> > skeleton;
+ typedef image1d_b< tag::value_<T> > skeleton;
/// Value_Set associated type.
@@ -144,7 +144,7 @@
/// Initialize an empty image.
- void init_with(const box1d& b, unsigned bdr = border::thickness);
+ void init_(const box1d& b, unsigned bdr = border::thickness);
/// Test if \p p is valid.
@@ -197,9 +197,42 @@
};
+ namespace impl
+ {
+
+ template <typename T, typename J>
+ void init_(tag::image_t, mln::image1d_b<T>& target, const J& model);
+
+ } // end of namespace mln::impl
+
+
# ifndef MLN_INCLUDE_ONLY
+ // impl::init_
+
+ namespace impl
+ {
+
+ template <typename T>
+ void init_(tag::border_t, unsigned& b, const image1d_b<T>& model)
+ {
+ b = model.border();
+ }
+
+ template <typename T, typename J>
+ void init_(tag::image_t, image1d_b<T>& target, const J& model)
+ {
+ box1d b;
+ init_(tag::bbox, b, model);
+ unsigned bdr;
+ init_(tag::border, bdr, model);
+ target.init_(b, bdr);
+ }
+
+ } // end of namespace mln::impl
+
+
// internal::data_< image1d_b<T> >
namespace internal
@@ -265,19 +298,19 @@
template <typename T>
image1d_b<T>::image1d_b(const box1d& b, unsigned bdr)
{
- init_with(b, bdr);
+ init_(b, bdr);
}
template <typename T>
image1d_b<T>::image1d_b(unsigned ninds, unsigned bdr)
{
mln_precondition(ninds != 0);
- init_with(make::box1d(ninds), bdr);
+ init_(make::box1d(ninds), bdr);
}
template <typename T>
void
- image1d_b<T>::init_with(const box1d& b, unsigned bdr)
+ image1d_b<T>::init_(const box1d& b, unsigned bdr)
{
mln_precondition(! this->has_data());
this->data_ = new internal::data_< image1d_b<T> >(b, bdr);
Index: mln/core/image3d_b.hh
--- mln/core/image3d_b.hh (revision 1161)
+++ mln/core/image3d_b.hh (working copy)
@@ -127,7 +127,7 @@
/// Skeleton.
- typedef image3d_b< tag::value<T> > skeleton;
+ typedef image3d_b< tag::value_<T> > skeleton;
/// Value_Set associated type.
@@ -147,7 +147,7 @@
/// Initialize an empty image.
- void init_with(const box3d& b, unsigned bdr = border::thickness);
+ void init_(const box3d& b, unsigned bdr = border::thickness);
/// Test if \p p is valid.
@@ -203,9 +203,42 @@
};
+ namespace impl
+ {
+
+ template <typename T, typename J>
+ void init_(tag::image_t, mln::image3d_b<T>& target, const J& model);
+
+ } // end of namespace mln::impl
+
+
# ifndef MLN_INCLUDE_ONLY
+ // impl::init_
+
+ namespace impl
+ {
+
+ template <typename T>
+ void init_(tag::border_t, unsigned& b, const image3d_b<T>& model)
+ {
+ b = model.border();
+ }
+
+ template <typename T, typename J>
+ void init_(tag::image_t, image3d_b<T>& target, const J& model)
+ {
+ box3d b;
+ init_(tag::bbox, b, model);
+ unsigned bdr;
+ init_(tag::border, bdr, model);
+ target.init_(b, bdr);
+ }
+
+ } // end of namespace mln::impl
+
+
// internal::data_< image3d_b<T> >
namespace internal
@@ -300,18 +333,18 @@
template <typename T>
image3d_b<T>::image3d_b(const box3d& b, unsigned bdr)
{
- init_with(b, bdr);
+ init_(b, bdr);
}
template <typename T>
image3d_b<T>::image3d_b(int nslis, int nrows, int ncols, unsigned bdr)
{
- init_with(make::box3d(nslis, nrows, ncols), bdr);
+ init_(make::box3d(nslis, nrows, ncols), bdr);
}
template <typename T>
void
- image3d_b<T>::init_with(const box3d& b, unsigned bdr)
+ image3d_b<T>::init_(const box3d& b, unsigned bdr)
{
mln_precondition(! this->has_data());
this->data_ = new internal::data_< image3d_b<T> >(b, bdr);
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1161)
+++ mln/metal/vec.hh (working copy)
@@ -116,6 +116,8 @@
class vec : public internal::vec_base_<n, T>
{
typedef internal::vec_base_<n, T> super;
+
+ protected:
using super::data_;
public:
Index: mln/tag/init.hh
--- mln/tag/init.hh (revision 0)
+++ mln/tag/init.hh (revision 0)
@@ -0,0 +1,54 @@
+// 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_TAG_INIT_HH
+# define MLN_CORE_TAG_INIT_HH
+
+/*! \file mln/core/tag/init.hh
+ *
+ * \brief Definition of tags used in the mln::init mechanism.
+ */
+
+
+namespace mln
+{
+
+ namespace tag
+ {
+
+ struct image_t {} image;
+ struct domain_t {} domain;
+ struct bbox_t {} bbox;
+ struct border_t {} border;
+ struct function_t {} function;
+
+ } // end of namespace mln::tag
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_TAG_INIT_HH
Index: mln/tag/skeleton.hh
--- mln/tag/skeleton.hh (revision 1161)
+++ mln/tag/skeleton.hh (working copy)
@@ -42,12 +42,12 @@
{
// With param.
- template <typename I> struct image { typedef I param; };
- template <typename V> struct value { typedef V param; };
- template <typename P> struct psite { typedef P param; };
- template <typename S> struct pset { typedef S param; };
- template <typename D> struct data { typedef D param; };
- template <typename F> struct function { typedef F param; };
+ template <typename I> struct image_ { typedef I param; };
+ template <typename V> struct value_ { typedef V param; };
+ template <typename P> struct psite_ { typedef P param; };
+ template <typename S> struct pset_ { typedef S param; };
+ template <typename D> struct data_ { typedef D param; };
+ template <typename F> struct function_ { typedef F param; };
// With value.
template <unsigned u> struct unsigned_ { enum { value = u }; };
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1161)
+++ mln/value/props.hh (working copy)
@@ -229,7 +229,6 @@
// records
- template <>
template <unsigned n, typename T>
struct props<metal::vec<n,T> >
{
Index: mln/value/stack.hh
--- mln/value/stack.hh (revision 1161)
+++ mln/value/stack.hh (working copy)
@@ -121,7 +121,7 @@
/// Skeleton.
- typedef stack_image< n, tag::image<I> > skeleton;
+ typedef stack_image< n, tag::image_<I> > skeleton;
/// Constructor.
Index: mln/value/quat.hh
--- mln/value/quat.hh (revision 1161)
+++ mln/value/quat.hh (working copy)
@@ -42,6 +42,9 @@
class quat : public metal::vec<4, float>
{
+ typedef metal::vec<4, float> super_;
+ using super_::data_;
+
public:
// ctors
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-24 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Add translation.
* mln/core/concept/function.hh: Add Function_x2x.
* mln/fun/internal/selector.hh: Add comment.
* mln/fun/x2x/translation.hh: New.
* mln/fun/x2x: New.
* mln/metal/mat.hh: Add identity.
* tests/fun_x2x_translation.cc: New.
---
mln/core/concept/function.hh | 23 +++++++
mln/fun/internal/selector.hh | 2
mln/fun/x2x/translation.hh | 132 +++++++++++++++++++++++++++++++++++++++++++
mln/metal/mat.hh | 17 +++++
tests/fun_x2x_translation.cc | 53 +++++++++++++++++
5 files changed, 227 insertions(+)
Index: trunk/milena/tests/fun_x2x_translation.cc
===================================================================
--- trunk/milena/tests/fun_x2x_translation.cc (revision 0)
+++ trunk/milena/tests/fun_x2x_translation.cc (revision 1161)
@@ -0,0 +1,53 @@
+// 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/image2d_b.cc
+ *
+ * \brief Tests on mln::image2d_b.
+ */
+
+
+#include <iostream>
+#include <mln/fun/x2x/translation.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ float
+ a = 2.3,
+ b = 0,
+ c = 2.9;
+
+ metal::vec<3,float> vec1 = make::vec(a, b, c);
+ fun::x2x::translation<3,float> tr1(make::vec<3,float>(1.6));
+
+ std::cout << vec1 << std::endl;
+ std::cout << tr1(vec1) << std::endl;
+}
Index: trunk/milena/mln/fun/x2x/translation.hh
===================================================================
--- trunk/milena/mln/fun/x2x/translation.hh (revision 0)
+++ trunk/milena/mln/fun/x2x/translation.hh (revision 1161)
@@ -0,0 +1,132 @@
+// 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_FUN_X2X_TRANSLATION_HH
+# define MLN_FUN_X2X_TRANSLATION_HH
+
+/*! \file mln/fun/x2x/translation.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/metal/vec.hh>
+# include <mln/metal/mat.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace x2x
+ {
+
+ // FIXME: Doc!
+
+ template <unsigned n, typename C>
+ struct translation : public Function_x2x< translation<n,C> >
+ {
+
+ enum {dim = n};
+
+ typedef metal::vec<n,C> result;
+ typedef metal::vec<n,C> invert;
+
+ translation();
+ translation(const metal::vec<n,C>& t);
+
+ result operator()(const metal::vec<n,C>& v) const;
+ invert inv() const;
+
+ void set_t(const metal::vec<n,C>& t);
+
+ protected:
+
+ metal::vec<n,C> t_;
+ metal::mat<n + 1,n + 1,C> m_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <unsigned n, typename C>
+ translation<n,C>::translation()
+ {
+ t_ = make::vec<n,C>(0);
+ m_ = metal::mat<n+1,n+1,C>::Id;
+ }
+
+ template <unsigned n, typename C>
+ translation<n,C>::translation(const metal::vec<n,C>& t)
+ :t_(t)
+ {
+ m_ = metal::mat<n+1,n+1,C>::Id;
+ for (unsigned i = 0; i < n; ++i)
+ m_(i,n) = t_[i];
+ }
+
+ template <unsigned n, typename C>
+ metal::vec<n,C>
+ translation<n,C>::operator()(const metal::vec<n,C>& v) const
+ {
+ typename translation::result res;
+ for (unsigned i = 0; i < n; ++i)
+ res[i] = v[i] + t_[i];
+ return res;
+ }
+
+ template <unsigned n, typename C>
+ metal::vec<n,C>
+ translation<n,C>::inv() const
+ {
+ typename translation::invert res(-t_);
+
+ return res;
+ }
+
+ template <unsigned n, typename C>
+ void
+ translation<n,C>::set_t(const metal::vec<n,C>& t)
+ {
+ t_ = t;
+ for (unsigned i = 0; i < n; ++i)
+ m_(i,n) = t_[i];
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::x2x
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_X2X_TRANSLATION_HH
Index: trunk/milena/mln/fun/internal/selector.hh
===================================================================
--- trunk/milena/mln/fun/internal/selector.hh (revision 1160)
+++ trunk/milena/mln/fun/internal/selector.hh (revision 1161)
@@ -56,6 +56,8 @@
// | |
// + -- Function_i2v |
// | |
+ // + -- Function_x2x |
+ // | |
// + -- Function_p2v |
// | |
// + -- Function_p2b -- +
Index: trunk/milena/mln/core/concept/function.hh
===================================================================
--- trunk/milena/mln/core/concept/function.hh (revision 1160)
+++ trunk/milena/mln/core/concept/function.hh (revision 1161)
@@ -138,6 +138,18 @@
};
+ // Vector -> Vector.
+
+ /// Base class for implementation of function-objects from vector to
+ /// vector.
+ template <typename E>
+ struct Function_x2x : public Function_v2v<E>
+ {
+ protected:
+ Function_x2x();
+ Function_x2x(const Function_x2x&);
+ };
+
# ifndef MLN_INCLUDE_ONLY
@@ -221,6 +233,17 @@
{
}
+ template <typename E>
+ Function_x2x<E>::Function_x2x()
+ {
+ }
+
+ template <typename E>
+ Function_x2x<E>::Function_x2x(const Function_x2x<E>& rhs)
+ : Function_v2v<E>(rhs)
+ {
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: trunk/milena/mln/metal/mat.hh
===================================================================
--- trunk/milena/mln/metal/mat.hh (revision 1160)
+++ trunk/milena/mln/metal/mat.hh (revision 1161)
@@ -48,6 +48,7 @@
typedef T value_type;
enum {N = n, M = m};
+ static const mat<n,m,T> Id;
mat()
{
@@ -67,6 +68,8 @@
unsigned size() const;
+ static mat identity();
+
private:
T data_[n][m];
};
@@ -74,6 +77,20 @@
# ifndef MLN_INCLUDE_ONLY
template <unsigned n, unsigned m, typename T>
+ const mat<n,m,T> mat<n,m,T>::Id = mat<n,m,T>::identity();
+
+ template <unsigned n, unsigned m, typename T>
+ mat<n,m,T> mat<n,m,T>::identity()
+ {
+ mat<n,m,T> id;
+
+ for (unsigned i = 0; i < n; ++i)
+ for (unsigned j = 0; j < m; ++j)
+ id.data_[i][j] = (i == j);
+ return id;
+ }
+
+ template <unsigned n, unsigned m, typename T>
template <typename U>
mat<n,m,T>::mat(const mat<n,m,U>& rhs)
{
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-24 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add image_identity_morpher.
* mln/core/internal/image_identity_morpher.hh: New.
---
image_identity_morpher.hh | 140 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 140 insertions(+)
Index: trunk/milena/mln/core/internal/image_identity_morpher.hh
===================================================================
--- trunk/milena/mln/core/internal/image_identity_morpher.hh (revision 0)
+++ trunk/milena/mln/core/internal/image_identity_morpher.hh (revision 1160)
@@ -0,0 +1,140 @@
+// 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_INTERNAL_IMAGE_IDENTITY_MORPHER_HH
+# define MLN_CORE_INTERNAL_IMAGE_IDENTITY_MORPHER_HH
+
+/*! \file mln/core/internal/image_identity_morpher.hh
+ *
+ * \brief Definition of a base class for image morphers w.r.t. identity.
+ */
+
+# include <mln/core/internal/image_morpher.hh>
+
+
+namespace mln
+{
+
+ namespace internal
+ {
+
+
+ /*! \brief A base class for image morphers w.r.t. identity.
+ *
+ * Parameter \p S is a point set type.
+ *
+ * \internal
+ */
+ template <typename I, typename S, typename E>
+ class image_identity_morpher_ : public image_morpher_<I, S, E>
+ {
+ public:
+
+ /// Value_Set associated type.
+ typedef mln_vset(I) vset;
+
+ /// Value associated type.
+ typedef mln_value(I) value;
+
+ /// Return type of read-only access.
+ typedef mln_rvalue(I) rvalue;
+
+ /// Return type of read-write access.
+ typedef typename internal::morpher_lvalue_<I>::ret lvalue;
+
+
+ /// Give the set of values.
+ const vset& values() const;
+
+ /// Read-only access of pixel value at point site \p p.
+ rvalue operator()(const mln_psite(S)& p) const;
+
+ /// Read-write access of pixel value at point site \p p.
+ lvalue operator()(const mln_psite(S)& p);
+
+ const mln_pset(I)& domain() const;
+ bool owns_(const mln_psite(I)& p) const;
+
+ protected:
+ image_identity_morpher_();
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename S, typename E>
+ image_identity_morpher_<I,S,E>::image_identity_morpher_()
+ {
+ }
+
+ template <typename I, typename S, typename E>
+ const mln_vset(I)&
+ image_identity_morpher_<I,S,E>::values() const
+ {
+ mln_precondition(this->delegatee_() != 0);
+ return this->delegatee_()->values();
+ }
+
+ template <typename I, typename S, typename E>
+ mln_rvalue(I)
+ image_identity_morpher_<I,S,E>::operator()(const mln_psite(S)& p) const
+ {
+ mln_precondition(this->delegatee_() != 0);
+ return this->delegatee_()->operator()(p);
+ }
+
+ template <typename I, typename S, typename E>
+ typename image_identity_morpher_<I,S,E>::lvalue
+ image_identity_morpher_<I,S,E>::operator()(const mln_psite(S)& p)
+ {
+ mln_precondition(this->delegatee_() != 0);
+ return this->delegatee_()->operator()(p);
+ }
+
+ template <typename I, typename S, typename E>
+ const mln_pset(I)&
+ image_identity_morpher_<I,S,E>::domain() const
+ {
+ mln_precondition(this->delegatee_() != 0);
+ return this->delegatee_()->domain();
+ }
+
+ template <typename I, typename S, typename E>
+ bool
+ image_identity_morpher_<I,S,E>::owns_(const mln_psite(I)& p) const
+ {
+ mln_precondition(this->delegatee_() != 0);
+ return this->delegatee_()->owns_(p);
+ }
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::internal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_IMAGE_IDENTITY_MORPHER_HH
1
0