Olena-patches
Threads by month
- ----- 2025 -----
- 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
November 2012
- 4 participants
- 83 discussions
* mln/accu/stat/median_few.hh,
* mln/world/kn/internal/hqueue.hh: Move...
* mln/world/kn/accu/median_few.hh,
* mln/world/kn/hqueue.hh: ... here.
---
milena/ChangeLog | 10 ++
milena/mln/accu/stat/median_few.hh | 147 ----------------------------
milena/mln/world/kn/accu/median_few.hh | 152 +++++++++++++++++++++++++++++
milena/mln/world/kn/hqueue.hh | 160 +++++++++++++++++++++++++++++++
milena/mln/world/kn/internal/hqueue.hh | 165 --------------------------------
5 files changed, 322 insertions(+), 312 deletions(-)
delete mode 100644 milena/mln/accu/stat/median_few.hh
create mode 100644 milena/mln/world/kn/accu/median_few.hh
create mode 100644 milena/mln/world/kn/hqueue.hh
delete mode 100644 milena/mln/world/kn/internal/hqueue.hh
diff --git a/milena/ChangeLog b/milena/ChangeLog
index addbfff..b3bc9f7 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,15 @@
2012-11-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Move files to proper directories.
+
+ * mln/accu/stat/median_few.hh,
+ * mln/world/kn/internal/hqueue.hh: Move...
+
+ * mln/world/kn/accu/median_few.hh,
+ * mln/world/kn/hqueue.hh: ... here.
+
+2012-11-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Revamp Code.
* mln/world/k1/immerse_with.hh,
diff --git a/milena/mln/accu/stat/median_few.hh b/milena/mln/accu/stat/median_few.hh
deleted file mode 100644
index dd3c16f..0000000
--- a/milena/mln/accu/stat/median_few.hh
+++ /dev/null
@@ -1,147 +0,0 @@
-// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
-//
-// This file is part of Olena.
-//
-// Olena is free software: you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation, version 2 of the License.
-//
-// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
-//
-// As a special exception, you may use this file as part of a free
-// software project 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_ACCU_STAT_MEDIAN_FEW_HH
-# define MLN_ACCU_STAT_MEDIAN_FEW_HH
-
-/// \file
-///
-/// \brief Define a median accumulator class to be used with few
-/// values.
-
-# include <iostream>
-# include <vector>
-# include <algorithm>
-
-# include <mln/trait/routine/mean.hh>
-# include <mln/accu/internal/base.hh>
-
-
-namespace mln
-{
-
- namespace accu
- {
-
- namespace stat
- {
-
- /// \brief Define a median accumulator class to be used with few
- /// values.
- template <typename T,
- typename R = mln_trait_routine_mean(2,T) >
- struct median_few
- : public mln::accu::internal::base< R, median_few<T,R> >
- {
- typedef T argument;
- typedef R result;
-
- median_few();
-
- void reserve(unsigned n);
- void init();
-
- void take(const argument& v);
- void take(const median_few<T,R>& other);
- // nota bene: no possible untake with this accumulator
-
- result to_result() const;
-
- bool is_valid() const;
-
- protected:
-
- mutable std::vector<argument> v_;
- };
-
-
-# ifndef MLN_INCLUDE_ONLY
-
- template <typename T, typename R>
- median_few<T,R>::median_few()
- {
- init();
- }
-
- template <typename T, typename R>
- void
- median_few<T,R>::reserve(unsigned n)
- {
- v_.reserve(n);
- }
-
- template <typename T, typename R>
- void
- median_few<T,R>::init()
- {
- v_.clear();
- }
-
- template <typename T, typename R>
- void
- median_few<T,R>::take(const argument& v)
- {
- v_.push_back(v);
- }
-
- template <typename T, typename R>
- void
- median_few<T,R>::take(const median_few<T,R>& other)
- {
- v_.insert(v_.end(), other.v_.begin(), other.v_.end());
- }
-
-
- template <typename T, typename R>
- typename median_few<T,R>::result
- median_few<T,R>::to_result() const
- {
- mln_precondition(is_valid());
- std::sort(v_.begin(), v_.end());
- // indices 0 1 2 => size = 3 => mid = 1
- // 0 1 => size = 2 => mid = 0
- unsigned mid = (v_.size() - 1) / 2;
- if (v_.size() % 2)
- return v_[mid];
- else
- return (R(v_[mid]) + R(v_[mid + 1])) / 2;
- }
-
- template <typename T, typename R>
- bool
- median_few<T,R>::is_valid() const
- {
- return v_.size() != 0;
- }
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::accu::stat
-
- } // end of namespace mln::accu
-
-} // end of namespace mln
-
-#endif // ! MLN_ACCU_STAT_MEDIAN_FEW_HH
diff --git a/milena/mln/world/kn/accu/median_few.hh b/milena/mln/world/kn/accu/median_few.hh
new file mode 100644
index 0000000..31dfd68
--- /dev/null
+++ b/milena/mln/world/kn/accu/median_few.hh
@@ -0,0 +1,152 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_WORLD_KN_ACCU_MEDIAN_FEW_HH
+# define MLN_WORLD_KN_ACCU_MEDIAN_FEW_HH
+
+/// \file
+///
+/// \brief Define a median accumulator class to be used with few
+/// values.
+
+# include <iostream>
+# include <vector>
+# include <algorithm>
+
+# include <mln/trait/routine/mean.hh>
+# include <mln/accu/internal/base.hh>
+
+
+namespace mln
+{
+
+ namespace world
+ {
+
+ namespace kn
+ {
+
+ namespace accu
+ {
+
+ /// \brief Define a median accumulator class to be used with few
+ /// values.
+ template <typename T,
+ typename R = mln_trait_routine_mean(2,T) >
+ struct median_few
+ : public mln::accu::internal::base< R, median_few<T,R> >
+ {
+ typedef T argument;
+ typedef R result;
+
+ median_few();
+
+ void reserve(unsigned n);
+ void init();
+
+ void take(const argument& v);
+ void take(const median_few<T,R>& other);
+ // nota bene: no possible untake with this accumulator
+
+ result to_result() const;
+
+ bool is_valid() const;
+
+ protected:
+
+ mutable std::vector<argument> v_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T, typename R>
+ median_few<T,R>::median_few()
+ {
+ init();
+ }
+
+ template <typename T, typename R>
+ void
+ median_few<T,R>::reserve(unsigned n)
+ {
+ v_.reserve(n);
+ }
+
+ template <typename T, typename R>
+ void
+ median_few<T,R>::init()
+ {
+ v_.clear();
+ }
+
+ template <typename T, typename R>
+ void
+ median_few<T,R>::take(const argument& v)
+ {
+ v_.push_back(v);
+ }
+
+ template <typename T, typename R>
+ void
+ median_few<T,R>::take(const median_few<T,R>& other)
+ {
+ v_.insert(v_.end(), other.v_.begin(), other.v_.end());
+ }
+
+
+ template <typename T, typename R>
+ typename median_few<T,R>::result
+ median_few<T,R>::to_result() const
+ {
+ mln_precondition(is_valid());
+ std::sort(v_.begin(), v_.end());
+ // indices 0 1 2 => size = 3 => mid = 1
+ // 0 1 => size = 2 => mid = 0
+ unsigned mid = (v_.size() - 1) / 2;
+ if (v_.size() % 2)
+ return v_[mid];
+ else
+ return (R(v_[mid]) + R(v_[mid + 1])) / 2;
+ }
+
+ template <typename T, typename R>
+ bool
+ median_few<T,R>::is_valid() const
+ {
+ return v_.size() != 0;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::world::kn::accu
+
+ } // end of namespace mln::world::kn
+
+ } // end of namespace mln::world
+
+} // end of namespace mln
+
+#endif // ! MLN_WORLD_KN_ACCU_MEDIAN_FEW_HH
diff --git a/milena/mln/world/kn/hqueue.hh b/milena/mln/world/kn/hqueue.hh
new file mode 100644
index 0000000..dc2b365
--- /dev/null
+++ b/milena/mln/world/kn/hqueue.hh
@@ -0,0 +1,160 @@
+// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project 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_WORLD_KN_HQUEUE_HH
+# define MLN_WORLD_KN_HQUEUE_HH
+
+/// \file
+/// \brief Class for hierarchical queues.
+
+
+# include <iostream>
+# include <vector>
+# include <mln/world/kn/internal/queue.hh>
+
+namespace mln
+{
+
+ namespace world
+ {
+
+ namespace kn
+ {
+
+ /// \internal
+ /// \brief Class for hierarchical queues.
+ template <typename T, typename P>
+ class hqueue
+ {
+ public:
+ hqueue();
+ hqueue(const value::interval<P>& inter);
+ hqueue(const P& first, const P& last);
+
+ unsigned nelements() const;
+
+ bool is_empty() const;
+ bool is_empty_at(const P& bucket) const;
+
+ void push(const T& t, const P& bucket);
+ T pop(const P& bucket);
+
+ // FIXME: add some reserve strategies...
+
+ private:
+ std::vector< internal::queue_<T> > v_;
+ value::interval<P> inter_;
+ unsigned n_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename T, typename P>
+ hqueue<T,P>::hqueue()
+ {
+ n_ = 0;
+ }
+
+ template <typename T, typename P>
+ hqueue<T,P>::hqueue(const value::interval<P>& inter)
+ {
+ v_.resize(inter.nelements());
+ inter_ = inter;
+ n_ = 0;
+ }
+
+ template <typename T, typename P>
+ hqueue<T,P>::hqueue(const P& first, const P& last)
+ {
+ v_.resize(inter_.nelements());
+ inter_ = value::interval<P>(first, last);
+ n_ = 0;
+ }
+
+ template <typename T, typename P>
+ unsigned
+ hqueue<T,P>::nelements() const
+ {
+ return n_;
+ }
+
+ template <typename T, typename P>
+ bool
+ hqueue<T,P>::is_empty_at(const P& bucket) const
+ {
+ unsigned i = inter_.index_of(bucket);
+ mln_precondition(i < v_.size());
+ return v_[i].is_empty();
+ }
+
+ template <typename T, typename P>
+ bool
+ hqueue<T,P>::is_empty() const
+ {
+ return n_ == 0;
+ }
+
+ template <typename T, typename P>
+ void
+ hqueue<T,P>::push(const T& t, const P& bucket)
+ {
+ unsigned i = inter_.index_of(bucket);
+ mln_precondition(i < v_.size());
+ v_[i].push(t);
+ }
+
+ template <typename T, typename P>
+ T
+ hqueue<T,P>::pop(const P& bucket)
+ {
+ mln_precondition(! is_empty_at(bucket));
+ unsigned i = inter_.index_of(bucket);
+ mln_precondition(i < v_.size());
+ return v_[i].pop();
+ }
+
+ // template <typename T, typename P>
+ // std::ostream&
+ // operator<<(std::ostream& ostr, const hqueue<T,P>& q)
+ // {
+ // unsigned n = q.size();
+ // ostr << '(';
+ // for (unsigned i = 0; i < n; ++i)
+ // ostr << q.v_[i] << (i + 1 == n ? "" : ", ");
+ // return ostr << ')';
+ // }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::world::kn
+
+ } // end of namespace mln::world
+
+} // end of namespace mln
+
+#endif // ! MLN_WORLD_KN_HQUEUE_HH
diff --git a/milena/mln/world/kn/internal/hqueue.hh b/milena/mln/world/kn/internal/hqueue.hh
deleted file mode 100644
index fe29376..0000000
--- a/milena/mln/world/kn/internal/hqueue.hh
+++ /dev/null
@@ -1,165 +0,0 @@
-// Copyright (C) 2012 EPITA Research and Development Laboratory (LRDE)
-//
-// This file is part of Olena.
-//
-// Olena is free software: you can redistribute it and/or modify it under
-// the terms of the GNU General Public License as published by the Free
-// Software Foundation, version 2 of the License.
-//
-// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>.
-//
-// As a special exception, you may use this file as part of a free
-// software project 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_WORLD_KN_INTERNAL_HQUEUE_HH
-# define MLN_WORLD_KN_INTERNAL_HQUEUE_HH
-
-/// \file
-/// \brief Class for hierarchical queues.
-
-
-# include <iostream>
-# include <vector>
-# include <mln/world/kn/internal/queue.hh>
-
-namespace mln
-{
-
- namespace world
- {
-
- namespace kn
- {
-
- namespace internal
- {
-
- /// \internal
- /// \brief Class for hierarchical queues.
- template <typename T, typename P>
- class hqueue
- {
- public:
- hqueue();
- hqueue(const value::interval<P>& inter);
- hqueue(const P& first, const P& last);
-
- unsigned nelements() const;
-
- bool is_empty() const;
- bool is_empty_at(const P& bucket) const;
-
- void push(const T& t, const P& bucket);
- T pop(const P& bucket);
-
- // FIXME: add some reserve strategies...
-
- private:
- std::vector< internal::queue_<T> > v_;
- value::interval<P> inter_;
- unsigned n_;
- };
-
-
-# ifndef MLN_INCLUDE_ONLY
-
-
- template <typename T, typename P>
- hqueue<T,P>::hqueue()
- {
- n_ = 0;
- }
-
- template <typename T, typename P>
- hqueue<T,P>::hqueue(const value::interval<P>& inter)
- {
- v_.resize(inter.nelements());
- inter_ = inter;
- n_ = 0;
- }
-
- template <typename T, typename P>
- hqueue<T,P>::hqueue(const P& first, const P& last)
- {
- v_.resize(inter_.nelements());
- inter_ = value::interval<P>(first, last);
- n_ = 0;
- }
-
- template <typename T, typename P>
- unsigned
- hqueue<T,P>::nelements() const
- {
- return n_;
- }
-
- template <typename T, typename P>
- bool
- hqueue<T,P>::is_empty_at(const P& bucket) const
- {
- unsigned i = inter_.index_of(bucket);
- mln_precondition(i < v_.size());
- return v_[i].is_empty();
- }
-
- template <typename T, typename P>
- bool
- hqueue<T,P>::is_empty() const
- {
- return n_ == 0;
- }
-
- template <typename T, typename P>
- void
- hqueue<T,P>::push(const T& t, const P& bucket)
- {
- unsigned i = inter_.index_of(bucket);
- mln_precondition(i < v_.size());
- v_[i].push(t);
- }
-
- template <typename T, typename P>
- T
- hqueue<T,P>::pop(const P& bucket)
- {
- mln_precondition(! is_empty_at(bucket));
- unsigned i = inter_.index_of(bucket);
- mln_precondition(i < v_.size());
- return v_[i].pop();
- }
-
- // template <typename T, typename P>
- // std::ostream&
- // operator<<(std::ostream& ostr, const hqueue<T,P>& q)
- // {
- // unsigned n = q.size();
- // ostr << '(';
- // for (unsigned i = 0; i < n; ++i)
- // ostr << q.v_[i] << (i + 1 == n ? "" : ", ");
- // return ostr << ')';
- // }
-
-
-# endif // ! MLN_INCLUDE_ONLY
-
- } // end of namespace mln::world::kn::internal
-
- } // end of namespace mln::world::kn
-
- } // end of namespace mln::world
-
-} // end of namespace mln
-
-#endif // ! MLN_WORLD_KN_INTERNAL_HQUEUE_HH
--
1.7.2.5
1
0
* mln/world/k1/immerse_with.hh,
* mln/world/k1/un_immerse.hh,
* mln/world/kn/display_enlarged.hh,
* mln/world/kn/fill_0_1_faces_internal_border.hh: Avoid the use of
exact() in preconditions.
* mln/world/kn/accu/max_interval.hh
* mln/world/kn/accu/min_interval.hh: Improve comments.
---
milena/ChangeLog | 13 +++++++++++++
milena/mln/world/k1/immerse_with.hh | 3 ++-
milena/mln/world/k1/un_immerse.hh | 4 ++--
milena/mln/world/kn/accu/max_interval.hh | 6 +++---
milena/mln/world/kn/accu/min_interval.hh | 7 ++++---
milena/mln/world/kn/display_enlarged.hh | 13 +++++++------
.../mln/world/kn/fill_0_1_faces_internal_border.hh | 2 +-
7 files changed, 32 insertions(+), 16 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index d0db77e..addbfff 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2012-11-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Revamp Code.
+
+ * mln/world/k1/immerse_with.hh,
+ * mln/world/k1/un_immerse.hh,
+ * mln/world/kn/display_enlarged.hh,
+ * mln/world/kn/fill_0_1_faces_internal_border.hh: Avoid the use of
+ exact() in preconditions.
+
+ * mln/world/kn/accu/max_interval.hh
+ * mln/world/kn/accu/min_interval.hh: Improve comments.
+
+2012-11-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Make use of safe_cast.
* mln/world/k1/fill_0_from_1_faces.hh,
diff --git a/milena/mln/world/k1/immerse_with.hh b/milena/mln/world/k1/immerse_with.hh
index aa9658b..1e3fd5d 100644
--- a/milena/mln/world/k1/immerse_with.hh
+++ b/milena/mln/world/k1/immerse_with.hh
@@ -125,7 +125,6 @@ namespace mln
const Function_vvvv2v<F4>& f_0faces_)
{
trace::entering("mln::world::k1::immerse_with");
- mln_precondition(exact(ima_).is_valid());
// FIXME: we cannot write that test because we rely on
// safe_convert. So, even though some types may not
@@ -138,6 +137,8 @@ namespace mln
const F2& f_1faces = exact(f_1faces_);
const F4& f_0faces = exact(f_0faces_);
+ mln_precondition(ima.is_valid());
+
mln_ch_value(I,V) output = k1::immerse(ima, new_value_type, default_value);
k1::fill_1_from_2_faces(output, f_1faces);
k1::fill_0_from_1_faces(output, f_0faces);
diff --git a/milena/mln/world/k1/un_immerse.hh b/milena/mln/world/k1/un_immerse.hh
index 767e4f5..8c352ca 100644
--- a/milena/mln/world/k1/un_immerse.hh
+++ b/milena/mln/world/k1/un_immerse.hh
@@ -76,8 +76,8 @@ namespace mln
un_immerse(const Image<I>& ima_, const V& new_value_type)
{
trace::entering("mln::world::k1::un_immerse");
- mln_precondition(exact(ima_).is_valid());
const I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
mln_ch_value(I,V) output = kn::un_immerse(ima, 2, new_value_type);
@@ -91,8 +91,8 @@ namespace mln
un_immerse(const Image<I>& ima_)
{
trace::entering("mln::world::k1::un_immerse");
- mln_precondition(exact(ima_).is_valid());
const I& ima = exact(ima_);
+ mln_precondition(ima.is_valid());
mln_concrete(I) output = kn::un_immerse(ima, 1);
diff --git a/milena/mln/world/kn/accu/max_interval.hh b/milena/mln/world/kn/accu/max_interval.hh
index 8d49932..e53be7e 100644
--- a/milena/mln/world/kn/accu/max_interval.hh
+++ b/milena/mln/world/kn/accu/max_interval.hh
@@ -28,7 +28,7 @@
/// \file
///
-/// \brief Define an accumulator that computes a max on a specific
+/// \brief Maximum accumulator restricted to a specific
/// interval.
# include <mln/core/concept/meta_accumulator.hh>
@@ -78,8 +78,8 @@ namespace mln
namespace accu
{
- /// \brief Minimum accumulator restricted to a specific
- /// interval.
+ /// \brief Maximum accumulator restricted to a specific
+ /// interval.
///
/// The parameter \c T is the type of values.
///
diff --git a/milena/mln/world/kn/accu/min_interval.hh b/milena/mln/world/kn/accu/min_interval.hh
index df6120d..7081a07 100644
--- a/milena/mln/world/kn/accu/min_interval.hh
+++ b/milena/mln/world/kn/accu/min_interval.hh
@@ -28,7 +28,8 @@
/// \file
///
-/// Define an accumulator that computes a min on a specific interval.
+/// \brief An accumulator that computes a min within specific
+/// interval.
# include <mln/accu/internal/base.hh>
# include <mln/core/concept/meta_accumulator.hh>
@@ -76,8 +77,8 @@ namespace mln
namespace accu
{
- /// \brief Minimum accumulator restricted to a specific
- /// interval.
+ /// \brief An accumulator that computes a min within specific
+ /// interval.
/*!
* The parameter \c T is the type of values.
*
diff --git a/milena/mln/world/kn/display_enlarged.hh b/milena/mln/world/kn/display_enlarged.hh
index e1b122a..00e3f24 100644
--- a/milena/mln/world/kn/display_enlarged.hh
+++ b/milena/mln/world/kn/display_enlarged.hh
@@ -89,10 +89,10 @@ namespace mln
{
trace::entering("mln::world::kn::display_enlarged");
- mln_precondition(exact(ima_kn_).is_valid());
+ const I& ima_kn = exact(ima_kn_);
+ mln_precondition(ima_kn.is_valid());
mln_assertion(zoom_ % 2);
- const I& ima_kn = exact(ima_kn_);
int
shift = zoom_ + 1,
mult = shift / 2;
@@ -101,10 +101,11 @@ namespace mln
if (zoom_ == 1)
return duplicate(ima_kn);
- mln_concrete(I) output(make::box2d(ima_kn.domain().pmin().row() * mult,
- ima_kn.domain().pmin().col() * mult,
- ima_kn.domain().pmax().row() * mult,
- ima_kn.domain().pmax().col() * mult));
+ mln_concrete(I)
+ output(make::box2d(ima_kn.domain().pmin().row() * mult,
+ ima_kn.domain().pmin().col() * mult,
+ ima_kn.domain().pmax().row() * mult,
+ ima_kn.domain().pmax().col() * mult));
const mln::def::coord
min_row = geom::min_row(ima_kn),
diff --git a/milena/mln/world/kn/fill_0_1_faces_internal_border.hh b/milena/mln/world/kn/fill_0_1_faces_internal_border.hh
index 915a69a..f991ecb 100644
--- a/milena/mln/world/kn/fill_0_1_faces_internal_border.hh
+++ b/milena/mln/world/kn/fill_0_1_faces_internal_border.hh
@@ -74,8 +74,8 @@ namespace mln
{
trace::entering("mln::world::kn::fill_0_1_faces_internal_border");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
+ mln_precondition(inout.is_valid());
inner_border::fill(inout, v);
--
1.7.2.5
1
0
* mln/world/k1/fill_0_from_1_faces.hh,
* mln/world/k1/fill_1_from_2_faces.hh,
* mln/world/k2/fill_non_primary_from_primary_2_faces.hh,
* mln/world/kn/fill_0_from_1_faces.hh,
* mln/world/kn/fill_0_from_2_faces.hh,
* mln/world/kn/fill_1_from_2_faces.hh,
* mln/world/kn/fill_1_from_aux_2_faces.hh,
* mln/world/kn/fill_2_from_1_faces.hh,
* mln/world/kn/internal/fill_primary_2_faces_from_input.hh,
* mln/world/kn/un_immerse.hh: Here.
* mln/world/kn/safe_cast.hh: Add safe_cast overloads.
---
milena/ChangeLog | 17 +++++
milena/mln/world/k1/fill_0_from_1_faces.hh | 26 +++++----
milena/mln/world/k1/fill_1_from_2_faces.hh | 31 ++++++----
.../k2/fill_non_primary_from_primary_2_faces.hh | 63 +++++++++----------
milena/mln/world/kn/fill_0_from_1_faces.hh | 29 +++++----
milena/mln/world/kn/fill_0_from_2_faces.hh | 26 +++++----
milena/mln/world/kn/fill_1_from_2_faces.hh | 26 +++++----
milena/mln/world/kn/fill_1_from_aux_2_faces.hh | 39 +++++++-----
milena/mln/world/kn/fill_2_from_1_faces.hh | 23 ++++---
.../kn/internal/fill_primary_2_faces_from_input.hh | 13 ++--
milena/mln/world/kn/safe_cast.hh | 64 +++++++++++++++++++-
milena/mln/world/kn/un_immerse.hh | 6 +-
12 files changed, 230 insertions(+), 133 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 6dedd0d..d0db77e 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,20 @@
+2012-11-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Make use of safe_cast.
+
+ * mln/world/k1/fill_0_from_1_faces.hh,
+ * mln/world/k1/fill_1_from_2_faces.hh,
+ * mln/world/k2/fill_non_primary_from_primary_2_faces.hh,
+ * mln/world/kn/fill_0_from_1_faces.hh,
+ * mln/world/kn/fill_0_from_2_faces.hh,
+ * mln/world/kn/fill_1_from_2_faces.hh,
+ * mln/world/kn/fill_1_from_aux_2_faces.hh,
+ * mln/world/kn/fill_2_from_1_faces.hh,
+ * mln/world/kn/internal/fill_primary_2_faces_from_input.hh,
+ * mln/world/kn/un_immerse.hh: Here.
+
+ * mln/world/kn/safe_cast.hh: Add safe_cast overloads.
+
2012-10-31 Guillaume Lazzara <z(a)lrde.epita.fr>
* mln/world/kn/display_enlarged.hh: Fix.
diff --git a/milena/mln/world/k1/fill_0_from_1_faces.hh b/milena/mln/world/k1/fill_0_from_1_faces.hh
index c906461..a0c3179 100644
--- a/milena/mln/world/k1/fill_0_from_1_faces.hh
+++ b/milena/mln/world/k1/fill_0_from_1_faces.hh
@@ -32,6 +32,7 @@
# include <mln/core/alias/point2d.hh>
# include <mln/world/kn/is_0_face.hh>
+# include <mln/world/kn/safe_cast.hh>
# include <mln/world/kn/is_1_face_vertical.hh>
# include <mln/world/kn/is_1_face_horizontal.hh>
@@ -85,15 +86,18 @@ namespace mln
{
trace::entering("mln::world::k1::fill_0_from_1_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
const F& f = exact(f_);
+ mln_precondition(inout.is_valid());
+
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_0_face(p))
- inout(p) = f(inout(p + up), inout(p + left),
- inout(p + right), inout(p + down));
+ inout(p) = kn::safe_cast(f(kn::safe_cast(inout(p + up)),
+ kn::safe_cast(inout(p + left)),
+ kn::safe_cast(inout(p + right)),
+ kn::safe_cast(inout(p + down))));
trace::exiting("mln::world::k1::fill_0_from_1_faces");
}
@@ -103,24 +107,24 @@ namespace mln
{
trace::entering("mln::world::k1::fill_0_from_1_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
+ mln_precondition(inout.is_valid());
- A accu(exact(accu_));
-
+ A accu = exact(accu_);
+ typedef mln_argument(A) arg;
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_0_face(p))
{
if (inout.domain().has(p + up))
- accu.take(inout(p + up));
+ accu.take(kn::safe_cast_to<arg>(inout(p + up)));
if (inout.domain().has(p + left))
- accu.take(inout(p + left));
+ accu.take(kn::safe_cast_to<arg>(inout(p + left)));
if (inout.domain().has(p + right))
- accu.take(inout(p + right));
+ accu.take(kn::safe_cast_to<arg>(inout(p + right)));
if (inout.domain().has(p + down))
- accu.take(inout(p + down));
- inout(p) = accu.to_result();
+ accu.take(kn::safe_cast_to<arg>(inout(p + down)));
+ inout(p) = safe_cast(accu.to_result());
}
trace::exiting("mln::world::k1::fill_0_from_1_faces");
diff --git a/milena/mln/world/k1/fill_1_from_2_faces.hh b/milena/mln/world/k1/fill_1_from_2_faces.hh
index 72922ec..a4873c2 100644
--- a/milena/mln/world/k1/fill_1_from_2_faces.hh
+++ b/milena/mln/world/k1/fill_1_from_2_faces.hh
@@ -34,6 +34,7 @@
# include <mln/world/kn/is_1_face_vertical.hh>
# include <mln/world/kn/is_1_face_horizontal.hh>
# include <mln/world/kn/border/compute_1_faces.hh>
+# include <mln/world/kn/safe_cast.hh>
namespace mln
{
@@ -87,19 +88,21 @@ namespace mln
{
trace::entering("mln::world::k1::fill_1_from_2_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
const F& f = exact(f_);
+ mln_precondition(inout.is_valid());
+
kn::border::compute_1_faces(inout, f);
- mln_box(I) b = inout.domain();
- mln_piter(I) p(b);
+ mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_1_face_vertical(p))
- inout(p) = f(inout(p + left), inout(p + right));
+ inout(p) = kn::safe_cast(f(kn::safe_cast(inout(p + left)),
+ kn::safe_cast(inout(p + right))));
else if (kn::is_1_face_horizontal(p))
- inout(p) = f(inout(p + up), inout(p + down));
+ inout(p) = kn::safe_cast(f(kn::safe_cast(inout(p + up)),
+ kn::safe_cast(inout(p + down))));
trace::exiting("mln::world::k1::fill_1_from_2_faces");
}
@@ -109,29 +112,31 @@ namespace mln
{
trace::entering("mln::world::k1::fill_1_from_2_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
- A accu(exact(accu_));
+ A accu = exact(accu_);
+
+ mln_precondition(inout.is_valid());
+ typedef mln_argument(A) arg;
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_1_face_vertical(p))
{
accu.init();
if (inout.domain().has(p + left))
- accu.take(inout(p + left));
+ accu.take(kn::safe_cast_to<arg>(inout(p + left)));
if (inout.domain().has(p + right))
- accu.take(inout(p + right));
- inout(p) = accu.to_result();
+ accu.take(kn::safe_cast_to<arg>(inout(p + right)));
+ inout(p) = kn::safe_cast(accu.to_result());
}
else if (kn::is_1_face_horizontal(p))
{
accu.init();
if (inout.domain().has(p + up))
- accu.take(inout(p + up));
+ accu.take(kn::safe_cast_to<arg>(inout(p + up)));
if (inout.domain().has(p + down))
- accu.take(inout(p + down));
- inout(p) = accu.to_result();
+ accu.take(kn::safe_cast_to<arg>(inout(p + down)));
+ inout(p) = kn::safe_cast(accu.to_result());
}
trace::exiting("mln::world::k1::fill_1_from_2_faces");
diff --git a/milena/mln/world/k2/fill_non_primary_from_primary_2_faces.hh b/milena/mln/world/k2/fill_non_primary_from_primary_2_faces.hh
index 0f8d71c..f218fd5 100644
--- a/milena/mln/world/k2/fill_non_primary_from_primary_2_faces.hh
+++ b/milena/mln/world/k2/fill_non_primary_from_primary_2_faces.hh
@@ -111,36 +111,33 @@ namespace mln
{
trace::entering("mln::world::k2::fill_non_primary_from_primary_2_faces");
- mln_precondition(exact(ima_).is_valid());
I& ima = exact(ima_);
const F2& f_intermediate = exact(f_intermediate_);
const F4& f_center = exact(f_center_);
- typedef mln_value(I) VI;
- typedef mln_argument(F2) V2;
- typedef mln_argument(F4) V4;
- mln_box(I) b = ima.domain();
- mln_piter(I) p(b);
+ mln_precondition(ima.is_valid());
+
+ mln_piter(I) p(ima.domain());
for_all(p)
if (is_non_primary_2_face_vertical(p))
{
- ima(p) = kn::safe_cast_to<VI>(
- f_intermediate(kn::safe_cast_to<V2>(ima(p + 2 * left)),
- kn::safe_cast_to<V2>(ima(p + 2 * right))));
+ ima(p) = kn::safe_cast(
+ f_intermediate(kn::safe_cast(ima(p + 2 * left)),
+ kn::safe_cast(ima(p + 2 * right))));
}
else if (is_non_primary_2_face_horizontal(p))
{
- ima(p) = kn::safe_cast_to<VI>(
- f_intermediate(kn::safe_cast_to<V2>(ima(p + 2 * up)),
- kn::safe_cast_to<V2>(ima(p + 2 * down))));
+ ima(p) = kn::safe_cast(
+ f_intermediate(kn::safe_cast(ima(p + 2 * up)),
+ kn::safe_cast(ima(p + 2 * down))));
}
else if (is_non_primary_2_face_center(p))
{
- ima(p) = kn::safe_cast_to<VI>(
- f_center(kn::safe_cast_to<V4>(ima(p + 2 * up_left)),
- kn::safe_cast_to<V4>(ima(p + 2 * up_right)),
- kn::safe_cast_to<V4>(ima(p + 2 * down_left)),
- kn::safe_cast_to<V4>(ima(p + 2 * down_right))));
+ ima(p) = kn::safe_cast(
+ f_center(kn::safe_cast(ima(p + 2 * up_left)),
+ kn::safe_cast(ima(p + 2 * up_right)),
+ kn::safe_cast(ima(p + 2 * down_left)),
+ kn::safe_cast(ima(p + 2 * down_right))));
}
trace::exiting("mln::world::k2::fill_non_primary_from_primary_2_faces");
@@ -152,46 +149,44 @@ namespace mln
const Accumulator<A>& accu_)
{
trace::entering("mln::world::k2::fill_non_primary_from_primary_2_faces");
-
- mln_precondition(exact(ima_).is_valid());
I& ima = exact(ima_);
A accu = exact(accu_);
- typedef mln_value(I) VI;
- typedef mln_argument(A) V;
- mln_box(I) b = ima.domain();
- mln_piter(I) p(b);
+ mln_precondition(ima.is_valid());
+
+ typedef mln_argument(A) arg;
+ mln_piter(I) p(ima.domain());
for_all(p)
if (is_non_primary_2_face_vertical(p))
{
accu.init();
if (ima.domain().has(p + 2 * left))
- accu.take(kn::safe_cast_to<V>(ima(p + 2 * left)));
+ accu.take(kn::safe_cast_to<arg>(ima(p + 2 * left)));
if (ima.domain().has(p + 2 * right))
- accu.take(kn::safe_cast_to<V>(ima(p + 2 * right)));
- ima(p) = kn::safe_cast_to<VI>(accu.to_result());
+ accu.take(kn::safe_cast_to<arg>(ima(p + 2 * right)));
+ ima(p) = kn::safe_cast(accu.to_result());
}
else if (is_non_primary_2_face_horizontal(p))
{
accu.init();
if (ima.domain().has(p + 2 * up))
- accu.take(kn::safe_cast_to<V>(ima(p + 2 * up)));
+ accu.take(kn::safe_cast_to<arg>(ima(p + 2 * up)));
if (ima.domain().has(p + 2 * down))
- accu.take(kn::safe_cast_to<V>(ima(p + 2 * down)));
- ima(p) = kn::safe_cast_to<VI>(accu.to_result());
+ accu.take(kn::safe_cast_to<arg>(ima(p + 2 * down)));
+ ima(p) = kn::safe_cast(accu.to_result());
}
else if (is_non_primary_2_face_center(p))
{
accu.init();
if (ima.domain().has(p + 2 * up_left))
- accu.take(kn::safe_cast_to<V>(ima(p + 2 * up_left)));
+ accu.take(kn::safe_cast_to<arg>(ima(p + 2 * up_left)));
if (ima.domain().has(p + 2 * up_right))
- accu.take(kn::safe_cast_to<V>(ima(p + 2 * up_right)));
+ accu.take(kn::safe_cast_to<arg>(ima(p + 2 * up_right)));
if (ima.domain().has(p + 2 * down_left))
- accu.take(kn::safe_cast_to<V>(ima(p + 2 * down_left)));
+ accu.take(kn::safe_cast_to<arg>(ima(p + 2 * down_left)));
if (ima.domain().has(p + 2 * down_right))
- accu.take(kn::safe_cast_to<V>(ima(p + 2 * down_right)));
- ima(p) = kn::safe_cast_to<VI>(accu.to_result());
+ accu.take(kn::safe_cast_to<arg>(ima(p + 2 * down_right)));
+ ima(p) = kn::safe_cast(accu.to_result());
}
trace::exiting("mln::world::k2::fill_non_primary_from_primary_2_faces");
diff --git a/milena/mln/world/kn/fill_0_from_1_faces.hh b/milena/mln/world/kn/fill_0_from_1_faces.hh
index adcea78..188c4a6 100644
--- a/milena/mln/world/kn/fill_0_from_1_faces.hh
+++ b/milena/mln/world/kn/fill_0_from_1_faces.hh
@@ -32,6 +32,7 @@
# include <mln/core/alias/point2d.hh>
# include <mln/world/kn/is_0_face.hh>
+# include <mln/world/kn/safe_cast.hh>
namespace mln
{
@@ -85,26 +86,25 @@ namespace mln
{
trace::entering("mln::world::kn::fill_0_from_1_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
- (void) accu_;
+ mln_precondition(inout.is_valid());
- A accu = A();
- mln_box(I) b = inout.domain();
- mln_piter(I) p(b);
+ A accu = exact(accu_);
+ typedef mln_argument(A) arg;
+ mln_piter(I) p(inout.domain());
for_all(p)
if (is_0_face(p))
{
accu.init();
if (inout.domain().has(p + left))
- accu.take(inout(p + left));
+ accu.take(safe_cast_to<arg>(inout(p + left)));
if (inout.domain().has(p + right))
- accu.take(inout(p + right));
+ accu.take(safe_cast_to<arg>(inout(p + right)));
if (inout.domain().has(p + up))
- accu.take(inout(p + up));
+ accu.take(safe_cast_to<arg>(inout(p + up)));
if (inout.domain().has(p + down))
- accu.take(inout(p + down));
- inout(p) = accu.to_result();
+ accu.take(safe_cast_to<arg>(inout(p + down)));
+ inout(p) = safe_cast(accu.to_result());
}
trace::exiting("mln::world::kn::fill_0_from_1_faces");
@@ -117,15 +117,18 @@ namespace mln
{
trace::entering("mln::world::kn::fill_0_from_1_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
const F& f = exact(f_);
+ mln_precondition(inout.is_valid());
+
mln_piter(I) p(inout.domain());
for_all(p)
if (is_0_face(p))
- inout(p) = f(inout(p + left), inout(p + right),
- inout(p + up), inout(p + down));
+ inout(p) = safe_cast(f(safe_cast(inout(p + left)),
+ safe_cast(inout(p + right)),
+ safe_cast(inout(p + up)),
+ safe_cast(inout(p + down))));
trace::exiting("mln::world::kn::fill_0_from_1_faces");
}
diff --git a/milena/mln/world/kn/fill_0_from_2_faces.hh b/milena/mln/world/kn/fill_0_from_2_faces.hh
index 6e6ee82..7164309 100644
--- a/milena/mln/world/kn/fill_0_from_2_faces.hh
+++ b/milena/mln/world/kn/fill_0_from_2_faces.hh
@@ -32,6 +32,7 @@
# include <mln/core/alias/point2d.hh>
# include <mln/world/kn/is_0_face.hh>
+# include <mln/world/kn/safe_cast.hh>
namespace mln
{
@@ -76,15 +77,18 @@ namespace mln
{
trace::entering("mln::world::kn::fill_0_from_2_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
F& f = exact(f_);
+ mln_precondition(inout.is_valid());
+
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_0_face(p))
- inout(p) = f(inout(p + up_left), inout(p + up_right),
- inout(p + down_left), inout(p + down_right));
+ inout(p) = safe_cast(f(safe_cast(inout(p + up_left)),
+ safe_cast(inout(p + up_right)),
+ safe_cast(inout(p + down_left)),
+ safe_cast(inout(p + down_right))));
trace::exiting("mln::world::kn::fill_0_from_2_faces");
}
@@ -95,25 +99,25 @@ namespace mln
{
trace::entering("mln::world::kn::fill_0_from_2_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
- (void) accu_;
+ mln_precondition(inout.is_valid());
- A accu = A();
+ A accu = exact(accu_);
+ typedef mln_argument(A) arg;
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_0_face(p))
{
accu.init();
if (inout.domain().has(p + up_left))
- accu.take(inout(p + up_left));
+ accu.take(safe_cast_to<arg>(inout(p + up_left)));
if (inout.domain().has(p + up_right))
- accu.take(inout(p + up_right));
+ accu.take(safe_cast_to<arg>(inout(p + up_right)));
if (inout.domain().has(p + down_left))
- accu.take(inout(p + down_left));
+ accu.take(safe_cast_to<arg>(inout(p + down_left)));
if (inout.domain().has(p + down_right))
- accu.take(inout(p + down_right));
- inout(p) = accu.to_result();
+ accu.take(safe_cast_to<arg>(inout(p + down_right)));
+ inout(p) = safe_cast(accu.to_result());
}
trace::exiting("mln::world::kn::fill_0_from_2_faces");
diff --git a/milena/mln/world/kn/fill_1_from_2_faces.hh b/milena/mln/world/kn/fill_1_from_2_faces.hh
index 2177f48..c190347 100644
--- a/milena/mln/world/kn/fill_1_from_2_faces.hh
+++ b/milena/mln/world/kn/fill_1_from_2_faces.hh
@@ -34,6 +34,7 @@
# include <mln/world/kn/is_1_face_vertical.hh>
# include <mln/world/kn/is_1_face_horizontal.hh>
# include <mln/world/kn/border/compute_1_faces.hh>
+# include <mln/world/kn/safe_cast.hh>
namespace mln
{
@@ -87,29 +88,30 @@ namespace mln
{
trace::entering("mln::world::kn::fill_1_from_2_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
+ mln_precondition(inout.is_valid());
- A accu(exact(accu_));
+ A accu = exact(accu_);
+ typedef mln_argument(A) arg;
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_1_face_vertical(p))
{
accu.init();
if (inout.domain().has(p + left))
- accu.take(inout(p + left));
+ accu.take(safe_cast_to<arg>(inout(p + left)));
if (inout.domain().has(p + right))
- accu.take(inout(p + right));
- inout(p) = accu.to_result();
+ accu.take(safe_cast_to<arg>(inout(p + right)));
+ inout(p) = safe_cast(accu.to_result());
}
else if (is_1_face_horizontal(p))
{
accu.init();
if (inout.domain().has(p + up))
- accu.take(inout(p + up));
+ accu.take(safe_cast_to<arg>(inout(p + up)));
if (inout.domain().has(p + down))
- accu.take(inout(p + down));
- inout(p) = accu.to_result();
+ accu.take(safe_cast_to<arg>(inout(p + down)));
+ inout(p) = safe_cast(accu.to_result());
}
trace::exiting("mln::world::kn::fill_1_from_2_faces");
@@ -121,18 +123,20 @@ namespace mln
{
trace::entering("mln::world::kn::fill_1_from_2_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
const F& f = exact(f_);
+ mln_precondition(inout.is_valid());
kn::border::compute_1_faces(inout, f);
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_1_face_vertical(p))
- inout(p) = f(inout(p + left), inout(p + right));
+ inout(p) = safe_cast(f(safe_cast(inout(p + left)),
+ safe_cast(inout(p + right))));
else if (is_1_face_horizontal(p))
- inout(p) = f(inout(p + up), inout(p + down));
+ inout(p) = safe_cast(f(safe_cast(inout(p + up)),
+ safe_cast(inout(p + down))));
trace::exiting("mln::world::kn::fill_1_from_2_faces");
}
diff --git a/milena/mln/world/kn/fill_1_from_aux_2_faces.hh b/milena/mln/world/kn/fill_1_from_aux_2_faces.hh
index 820e78f..d18e3c8 100644
--- a/milena/mln/world/kn/fill_1_from_aux_2_faces.hh
+++ b/milena/mln/world/kn/fill_1_from_aux_2_faces.hh
@@ -35,6 +35,7 @@
# include <mln/world/kn/is_1_face_vertical.hh>
# include <mln/world/kn/is_1_face_horizontal.hh>
# include <mln/world/kn/border/compute_1_faces.hh>
+# include <mln/world/kn/safe_cast.hh>
namespace mln
{
@@ -96,21 +97,24 @@ namespace mln
{
trace::entering("mln::world::kn::fill_1_from_aux_2_faces");
- mln_precondition(exact(inout_).is_valid());
- mln_precondition(exact(aux_).is_valid());
- mln_precondition(exact(inout_).domain() == exact(aux_).domain());
I& inout = exact(inout_);
const J& aux = exact(aux_);
F& f = exact(f_);
+ mln_precondition(inout.is_valid());
+ mln_precondition(aux.is_valid());
+ mln_precondition(inout.domain() == aux.domain());
+
kn::border::compute_1_faces(inout, f);
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_1_face_vertical(p))
- inout(p) = f(aux(p + left), aux(p + right));
+ inout(p) = safe_cast(f(safe_cast(aux(p + left)),
+ safe_cast(aux(p + right))));
else if (kn::is_1_face_horizontal(p))
- inout(p) = f(aux(p + up), aux(p + down));
+ inout(p) = safe_cast(f(safe_cast(aux(p + up)),
+ safe_cast(aux(p + down))));
trace::exiting("mln::world::kn::fill_1_from_aux_2_faces");
}
@@ -122,33 +126,34 @@ namespace mln
{
trace::entering("mln::world::kn::fill_1_from_aux_2_faces");
- mln_precondition(exact(inout_).is_valid());
- mln_precondition(exact(aux_).is_valid());
- mln_precondition(exact(inout_).domain() == exact(aux_).domain());
I& inout = exact(inout_);
const J& aux = exact(aux_);
- A accu(exact(accu_));
- mln_box(I) b = inout.domain();
- mln_piter(I) p(b);
+ mln_precondition(inout.is_valid());
+ mln_precondition(aux.is_valid());
+ mln_precondition(inout.domain() == aux.domain());
+
+ A accu = exact(accu_);
+ typedef mln_argument(A) arg;
+ mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_1_face_vertical(p))
{
accu.init();
if (aux.domain().has(p + left))
- accu.take(aux(p + left));
+ accu.take(safe_cast_to<arg>(aux(p + left)));
if (aux.domain().has(p + right))
- accu.take(aux(p + right));
- inout(p) = accu.to_result();
+ accu.take(safe_cast_to<arg>(aux(p + right)));
+ inout(p) = safe_cast(accu.to_result());
}
else if (kn::is_1_face_horizontal(p))
{
accu.init();
if (aux.domain().has(p + up))
- accu.take(aux(p + up));
+ accu.take(safe_cast_to<arg>(aux(p + up)));
if (aux.domain().has(p + down))
- accu.take(aux(p + down));
- inout(p) = accu.to_result();
+ accu.take(safe_cast_to<arg>(aux(p + down)));
+ inout(p) = safe_cast(accu.to_result());
}
trace::exiting("mln::world::kn::fill_1_from_aux_2_faces");
diff --git a/milena/mln/world/kn/fill_2_from_1_faces.hh b/milena/mln/world/kn/fill_2_from_1_faces.hh
index 097e50f..c38f69f 100644
--- a/milena/mln/world/kn/fill_2_from_1_faces.hh
+++ b/milena/mln/world/kn/fill_2_from_1_faces.hh
@@ -32,6 +32,7 @@
# include <mln/core/alias/point2d.hh>
# include <mln/world/kn/is_2_face.hh>
+# include <mln/world/kn/safe_cast.hh>
namespace mln
{
@@ -83,8 +84,10 @@ namespace mln
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_2_face(p))
- inout(p) = f(inout(p + up), inout(p + left),
- inout(p + right), inout(p + down));
+ inout(p) = safe_cast(f(safe_cast(inout(p + up)),
+ safe_cast(inout(p + left)),
+ safe_cast(inout(p + right)),
+ safe_cast(inout(p + down))));
trace::exiting("mln::world::kn::fill_2_from_1_faces");
}
@@ -95,25 +98,25 @@ namespace mln
{
trace::entering("mln::world::kn::fill_2_from_1_faces");
- mln_precondition(exact(inout_).is_valid());
I& inout = exact(inout_);
- (void) accu_;
+ mln_precondition(inout.is_valid());
- A accu = A();
+ A accu = exact(accu_);
+ typedef mln_argument(A) arg;
mln_piter(I) p(inout.domain());
for_all(p)
if (kn::is_2_face(p))
{
accu.init();
if (inout.domain().has(p + up))
- accu.take(inout(p + up));
+ accu.take(safe_cast_to<arg>(inout(p + up)));
if (inout.domain().has(p + left))
- accu.take(inout(p + left));
+ accu.take(safe_cast_to<arg>(inout(p + left)));
if (inout.domain().has(p + right))
- accu.take(inout(p + right));
+ accu.take(safe_cast_to<arg>(inout(p + right)));
if (inout.domain().has(p + down))
- accu.take(inout(p + down));
- inout(p) = accu.to_result();
+ accu.take(safe_cast_to<arg>(inout(p + down)));
+ inout(p) = safe_cast(accu.to_result());
}
trace::exiting("mln::world::kn::fill_2_from_1_faces");
diff --git a/milena/mln/world/kn/internal/fill_primary_2_faces_from_input.hh b/milena/mln/world/kn/internal/fill_primary_2_faces_from_input.hh
index 6a6e31e..5455a81 100644
--- a/milena/mln/world/kn/internal/fill_primary_2_faces_from_input.hh
+++ b/milena/mln/world/kn/internal/fill_primary_2_faces_from_input.hh
@@ -75,21 +75,20 @@ namespace mln
const unsigned inner_border_thickness)
{
trace::entering("mln::world::kn::internal::fill_primary_2_faces_from_input");
- mlc_equal(mln_site(I), mln_site(J))::check();
- mln_precondition(exact(ima_).is_valid());
- mln_precondition(exact(ima_kn_).is_valid());
- mln_precondition(exact(ima_).domain() <= exact(ima_kn_).domain());
-
I& ima_kn = exact(ima_kn_);
const J& ima = exact(ima_);
+ mlc_equal(mln_site(I), mln_site(J))::check();
+ mln_precondition(ima.is_valid());
+ mln_precondition(ima_kn.is_valid());
+ mln_precondition(ima.domain() <= ima_kn.domain());
+
// Filling Primary 2-Faces
- typedef mln_value(I) V;
mln_piter(J) p(ima.domain());
for_all(p)
{
mln_site(I) pout = internal::immerse_point(p, n, inner_border_thickness);
- ima_kn(pout) = safe_cast_to<V>(ima(p));
+ ima_kn(pout) = safe_cast(ima(p));
}
kn::border::adjust_duplicate_2_faces(ima_kn, 1);
diff --git a/milena/mln/world/kn/safe_cast.hh b/milena/mln/world/kn/safe_cast.hh
index da60265..9d5202d 100644
--- a/milena/mln/world/kn/safe_cast.hh
+++ b/milena/mln/world/kn/safe_cast.hh
@@ -46,12 +46,36 @@ namespace mln
using namespace mln::value;
- /// \brief Safe convertion function for manipulating Kn-immersed
+ // Forward declaration.
+ namespace internal {
+ template <typename Tsrc> struct to_be_casted_t;
+ }
+
+ /*!
+ Use cases:
+
+ int i; float j;
+
+ 1. safe_cast(i, j);
+ 2. j = safe_cast(i);
+ 3. j = safe_cast_to<float>(i);
+ */
+
+ /// \brief Safe conversion function for manipulating Kn-immersed
+ /// images.
+ template <typename Tsrc, typename Tdest>
+ void safe_cast(const Tsrc& src, Tdest& dest);
+
+ /// \brief Safe conversion function for manipulating Kn-immersed
+ /// images.
+ template <typename Tsrc>
+ internal::to_be_casted_t<Tsrc> safe_cast(const Tsrc& src);
+
+ /// \brief Safe conversion function for manipulating Kn-immersed
/// images.
template <typename Tdest, typename Tsrc>
Tdest safe_cast_to(const Tsrc& src);
-
} // end of namespace mln::world::kn
} // end of namespace mln::world
@@ -349,11 +373,45 @@ namespace mln
namespace kn
{
+ namespace internal
+ {
+
+ template <typename Tsrc>
+ struct to_be_casted_t
+ {
+ to_be_casted_t(const Tsrc& src) : src(src) {}
+ Tsrc src;
+
+ template <typename Tdest>
+ operator Tdest const()
+ {
+ Tdest dest;
+ safe_cast_(src, dest);
+ return dest;
+ }
+ };
+
+ } // end of namespace mln::world::kn::internal
+
+
+ template <typename Tsrc>
+ internal::to_be_casted_t<Tsrc> safe_cast(const Tsrc& src)
+ {
+ internal::to_be_casted_t<Tsrc> tmp(src);
+ return tmp;
+ }
+
+ template <typename Tsrc, typename Tdest>
+ void safe_cast(const Tsrc& src, Tdest& dest)
+ {
+ safe_cast_(src, dest);
+ }
+
template <typename Tdest, typename Tsrc>
Tdest safe_cast_to(const Tsrc& src)
{
Tdest dest;
- safe_cast_(src, dest);
+ safe_cast(src, dest);
return dest;
}
diff --git a/milena/mln/world/kn/un_immerse.hh b/milena/mln/world/kn/un_immerse.hh
index ead7132..0d125e8 100644
--- a/milena/mln/world/kn/un_immerse.hh
+++ b/milena/mln/world/kn/un_immerse.hh
@@ -92,8 +92,8 @@ namespace mln
B
domain_K0_from_Kn(const Box<B>& b_, const unsigned n)
{
- mln_precondition(exact(b_).is_valid());
const B& b = exact(b_);
+ mln_precondition(b.is_valid());
return B(un_immerse_point(b.pmin(), n),
un_immerse_point(b.pmax(), n));
}
@@ -109,15 +109,15 @@ namespace mln
const V& new_value_type)
{
trace::entering("mln::world::kn::un_immerse");
- mln_precondition(exact(ima_).is_valid());
const I& ima = exact(ima_);
(void) new_value_type;
+ mln_precondition(ima.is_valid());
mln_ch_value(I,V) output(internal::domain_K0_from_Kn(ima.domain(), n));
mln_piter(I) p(output.domain());
for_all(p)
- output(p) = safe_cast_to<V>(ima(internal::immerse_point(p, n)));
+ output(p) = safe_cast(ima(internal::immerse_point(p, n)));
trace::exiting("mln::world::kn::un_immerse");
return output;
--
1.7.2.5
1
0