URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-04-07 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Add mln::make::image1d.
* mln/make/image1d.hh: New, create an image1d with a array of values.
* mln/core/image1d.hh: Add include.
---
core/image1d.hh | 1
make/image1d.hh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
Index: trunk/milena/mln/core/image1d.hh
===================================================================
--- trunk/milena/mln/core/image1d.hh (revision 1844)
+++ trunk/milena/mln/core/image1d.hh (revision 1845)
@@ -560,5 +560,6 @@
} // end of namespace mln
+# include <mln/make/image1d.hh>
#endif // ! MLN_CORE_IMAGE1D_HH
Index: trunk/milena/mln/make/image1d.hh
===================================================================
--- trunk/milena/mln/make/image1d.hh (revision 0)
+++ trunk/milena/mln/make/image1d.hh (revision 1845)
@@ -0,0 +1,75 @@
+// 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_MAKE_IMAGE1D_HH
+# define MLN_MAKE_IMAGE1D_HH
+
+/*! \file mln/make/image1d.hh
+ *
+ * \brief Routine to create an mln::image1d.
+ */
+
+# include <mln/core/image1d.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create an image1d from an 1d array of values.
+ *
+ * \param[in] values 1d array.
+ *
+ * \return A 1D image.
+ */
+ template <typename V, unsigned L>
+ mln::image1d<V> image1d(V (&values)[L]);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, unsigned L>
+ inline
+ mln::image1d<V>
+ image1d(V (&values)[L])
+ {
+ mln::image1d<V> tmp(L);
+ for (unsigned ind = 0; ind < L; ++ind)
+ tmp(make::point1d(ind)) = values[ind];
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_IMAGE1D_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Sandbox: ICP: Add file for refactoring.
* sandbox/jardonnet/registration/icp.hh: New file for the refactored version.
icp.hh | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 173 insertions(+)
Index: sandbox/jardonnet/registration/icp.hh
--- sandbox/jardonnet/registration/icp.hh (revision 0)
+++ sandbox/jardonnet/registration/icp.hh (revision 0)
@@ -0,0 +1,173 @@
+// Copyright (C) 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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_REGISTRATION_ICP_HH
+# define MLN_REGISTRATION_ICP_HH
+
+/*! \file mln/registration/icp.hh
+ *
+ * \brief image registration
+ */
+
+# include <mln/algebra/quat.hh>
+# include <mln/algebra/vec.hh>
+# include <mln/make/w_window.hh>
+# include <mln/make/w_window3d.hh>
+
+# include "tools.hh"
+
+# include "cloud.hh"
+# include "quat7.hh"
+# include "projection.hh"
+# include "chamfer.hh"
+
+namespace mln
+{
+
+ namespace registration
+ {
+
+ /*! Registration FIXME : doxy
+ *
+ *
+ */
+ template <typename I, typename J>
+ inline
+ mln_concrete(I)
+ icp(const Image<I>& cloud,
+ const Image<J>& surface);
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename P, typename M>
+ inline
+ p_array<P>
+ icp_(p_array<P>& C,
+ const p_array<P>&,
+ M& map)
+ {
+ trace::entering("registration::impl::icp_");
+
+ unsigned int k;
+ quat7<P::dim> old_qk, qk;
+ float err;
+ //float err_bis;
+ p_array<P> Ck(C), Xk(C); //FIXME: Xk copy C
+
+ algebra::vec<P::dim,float> mu_C = center(C), mu_Xk;
+
+ const float epsilon = 1;//1e-3;
+
+ //// step 1
+ k = 0;
+
+ do {
+
+ //// step 2
+ //projection::fill_Xk(Ck, map, Xk);
+ //projection::de_base(Ck, X, Xk, err_bis);
+ projection::memo(Ck, Xk, map);
+
+ mu_Xk = center(Xk);
+
+ //// step 3
+ old_qk = qk;
+ qk = match(C, mu_C, Xk, mu_Xk);
+
+ //// step 4
+ qk.apply_on(C, Ck); // Ck+1 = qk(C)
+
+ //// err = d(Ck+1,Xk)
+ err = rms(Ck, Xk);
+ std::cout << k << ' ' << err << ' ' << (qk - old_qk).sqr_norm() << std::endl; //plot file
+
+ ++k;
+ } while (k < 3 || (qk - old_qk).sqr_norm() > epsilon);
+
+ trace::exiting("registration::impl::icp_");
+ return Ck;
+ }
+
+ } // end of namespace mln::registration::impl
+
+
+ //Only for 2d and 3d image
+ template <typename I, typename J>
+ inline
+ mln_concrete(I) //FIXME: should return something else ? qk ?
+ icp(const Image<I>& cloud_,
+ const Image<J>& surface_)
+ {
+ trace::entering("registration::icp");
+ mln_precondition(exact(cloud_).has_data());
+ mln_precondition(exact(surface_).has_data());
+
+ //convert to image: time consuming
+ typedef image3d<mln_value(I)> I3d;
+ I3d cloud = convert::to_image_3d(exact(cloud_));
+ const I3d surface = convert::to_image_3d(exact(surface_));
+
+ //build p_arrays.
+ p_array<mln_point(I3d)> c = convert::to_p_array(cloud);
+ p_array<mln_point(I3d)> x = convert::to_p_array(surface);
+
+ //build closest point map
+ //lazy_map<I3d> map(enlarge(bigger(c.bbox(),x.bbox()),50));
+ //lazy_map<I3d> map(1000,1000,50);
+
+ c_point<mln_point(I3d)> fun(x);
+ //Make via function
+ lazy_image< c_point<mln_point(I3d)> > map(fun);
+
+ p_array<mln_point(I3d)> res = impl::icp_(c, x, map);
+
+ //to 2d : projection (FIXME:if 3d)
+ //mln_concrete(I) output = convert::to_image<I>(res)?
+ mln_concrete(I) output(exact(cloud_).domain());
+ for (size_t i = 0; i < res.npoints(); i++)
+ {
+ point2d p(res[i][0], res[i][1]);
+ //FIXME: not necessary if output(res.bbox())
+ if (output.has(p))
+ output(p) = true;
+ }
+
+ trace::exiting("registration::icp");
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::registration
+
+} // end of namespace mln
+
+
+#endif // ! MLN_REGISTRATION_ICP_HH
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
sandbox: Continue documentation about image types and properties.
* sandbox/ballas/doc/image_tours.txt: update documentation.
* sandbox/ballas/doc/draft.txt: New file about the images properties.
draft.txt | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
image_tours.txt | 160 ++++++++++++----------------------
2 files changed, 319 insertions(+), 101 deletions(-)
Index: sandbox/ballas/doc/image_tours.txt
--- sandbox/ballas/doc/image_tours.txt (revision 1839)
+++ sandbox/ballas/doc/image_tours.txt (working copy)
@@ -7,36 +7,36 @@
** Two types of properties
-
-*** Declaratif mode: (find an exemple).
-
+*** Declarative mode: (find an example).
Here, the properties must be define by the image type programmer. They cannot
be deduce from the image associated type. So we can't find the properties by
-introspecting the image type (with introspection).
+introspecting the image type.
declaration definition ..... I check
------- ----------
| | / \
| Props | ----> | Image Type |
-| | \ ___________/
+| | \ __________ /
-------
-*** Automatic mode: (find an exemple).
+*** Automatic mode: (find an example).
Here, we get the image properties from the image associated type
(site, pset...).
- -----------
+ ----------
/ \
- | Image Type | automatic
- and associated -----> Props
- type
- \ ___________/
+ | |
+ | Image Type |
+ | and | automatic -----> Props
+ | associated|
+ | type |
+ \ __________ /
@@ -53,36 +53,29 @@
(ex: dilatation/erosion).
TODO: detail the example.
-*** Implementation inherentence
+*** Implementation inheritance
Milena image types are property driven.
It is possible to get a special behavior (not describe in the Image Concept)
depends on the property define in the property associated for the image
type. So, it is possible to recover some piece of interface depending on the
image type properties.
-For instance an Image2d has the bidimensional, and random value access.
+For instance an Image2d has the bi-dimensional, and random value access.
properties. Hence, Image2d automatically provides a row/column access:
V at(Point2d<T>::coord x, Point2d<T>::coord y).
-
-
*** Difference between a property and its values
-*** Hierarchie of property (scalar/integer)
+*** Hierarchies of property (scalar/integer)
** Implementation of properties in Milena
-* Algorithm and Properties
-
-** Specialization
-
-** Static checking
-
-* Image Properties:
+* List of the image properties:
** global Properties:
+
category: primary,
{ domain_morpher, value_morpher, identity_morpher } < morpher
@@ -176,20 +169,17 @@
** Image nD
-Image on regular grid where grides nodes are points.
-To gain efficienty, Images nD have a virtual borders.
+Image on regular grid where grid nodes are points.
+To gain efficiency, Images nD have a virtual borders.
All these image are templated by T, the image value type.
-*** Image1d<T>
+
+*** Common Associated type//properties between imageND
**** Associated types:
value = T
-site = point1d
-psite = point1d == point_<tick,int>
-pset = box1d
-
**** Properties:
--> global properties
@@ -211,99 +201,56 @@
--> properties related to the pset
access = random
-space = one_d
-size = regular
+size = regular // this a global property
support = aligned
-**** Specific interface:
- FIXME....
+*** Image1d<T>
+
+**** Associated types:
+site = point1d
+psite = point1d == point_<tick,int>
+pset = box1d
+**** Properties:
+space = one_d
+**** Specific interface:
+ FIXME....
*** Image2d<T>
**** Associated types:
-value = T
-
site = point2d
psite = point2d == point_<square,int>
pset = box2d
**** Properties:
---> global properties
-
-category = primary
-border = stored
-neighb: none
-data = raw
-io = read_write
-speed = fastest
-
---> properties related to values
-
-// Depend on T FIXME, where the property are defined??
-kind =
-quant =
-value =
-
---> properties related to the pset
-
-access = random
space = two_d
-size = regular
-support = aligned
+
**** Specific interface:
FIXME....
-
-
*** Image3d<T>
**** Associated types:
value = T
-site = point3d
-psite = point3d == point_<cube,int>
-pset = box3d
-
**** Properties:
---> global properties
-
-category = primary
-border = stored
-neighb: none
-data = raw
-io = read_write
-speed = fastest
-
---> properties related to values
-
-// Depend on T FIXME, where the property are defined??
-kind =
-quant =
-value =
-
---> properties related to the pset
-
-access = random
space = three_d
-size = regular
-support = aligned
**** Specific interface:
FIXME....
-
** Image based on function
The images based on function are templated by F and P, where
@@ -355,32 +302,44 @@
**** Specific interface:
FIXME....
-
-
-
** Run based Encoded image
-All the run based encoded images have their definition domains encoded by ...
-runs. These images types are not morpher types since these do not lie on
-another image type.
-A run is a "continuous" (note this is wrong, cf graph index) set of sites.
-It is define by a site start, and a length.
-All the run based encoded image are templated by P, T where P is a site type
-and T a value type.
-
-
+All the run based encoded images have their definition domains encoded by runs.
+These images types are not morpher types since these do not lie on another
+image type.A run is a "continuous" (note this is wrong, cf graph index) set of
+sites.It is define by a site start, and a length. All the run based encoded
+image are templated by P, T where P is a site type and T a value type.
Note:
type one shot (const)!!!
Do we store the the null value in the rle encoding.
(Do we compress all the images values, or only the image objects...)
Is there any restriction on P and T?
-Can we compress all the image types or only the point wise image type
-(cf the on_the_same_line in the encode algorithm).
How the properties are setted and to which values?
-Depend on the PointWise property ??
+
+*** Criteria needed by images to be encoded in runs
+
+Can we compress all the image types or only the piece wise image type
+(cf the on_the_same_line in the encode algorithm).
+
+Currently, *encode function just work with image based on a **Point** set.
+cf:
+for (unsigned n = 0; same_line && n < dim - 1; ++n)
+ same_line = (p1[n] == p2[n]);
+
+Problem generalization:
+ A p_run take a Site as a parameter.
+ a p_run must be able to be casted into the Site (actually, const Site).
+ The only information that we have in the p_run is a len (integer).
+ So we must be able to refind all the site in the run from the site start,
+and a addition with an integer.
+
+ How do we name this property?
+
+
+
*** RLE Image
@@ -470,7 +429,6 @@
*** Value morpher
-
*** Image_if
???
Index: sandbox/ballas/doc/draft.txt
--- sandbox/ballas/doc/draft.txt (revision 0)
+++ sandbox/ballas/doc/draft.txt (revision 0)
@@ -0,0 +1,260 @@
+-*- outline -*-
+
+* Main image types to keep in mind
+
+- nD image
+
+- Runs image (RLE/ Sparse/ value encoded...
+
+- Image based on a Lut (to define)
+
+- graph image (see with Roland)
+
+
+* New redefinition of the image property
+
+
+** global Properties:
+
+*** Category (cf file milenadoc/tutorial/image_types.txt):
+ category: primary,
+ { domain_morpher, value_morpher, identity_morpher } < morpher
+
+*** Size:
+
+ size: huge,
+ (large,) ?
+ regular
+
+**** Definition
+ The size property give us an indication about the size (in memory) taken by
+the image. Indeed, an image can either huge or regular.
+"huge" means that the image cannot be fully store in the ram.
+"regular" means that the image can be fully store in the ram.
+
+**** Why does this property exist?
+As we can imagine, access to a "huge" image is way slower than accessing
+to "regular" image. Indeed, to access to "huge" image, we first need to load in
+the ram the interesting part of the image from the hard drive.
+
+So, with this property, we can handle huge image in a different way in
+the algorithms. (do inplace modification instead of create a new image for
+instance, forbid the launch algorithm which create temporary image with huge
+image...).
+
+
+
+FIXME define large?
+
+
+
+*** Border/Extended domain:
+
+ border: none,
+ { stored, computed } <some
+
+FIXME: detail the problem, find example...
+
+ The border property will probably change, because more information on
+the border.
+Actually a "border" is more extended domain of the image definition domain,
+than a simple border.
+The idea is an algorithm should have the same behavior for the same image with
+or without an extended domain.
+
+problems:
+If the image has stored data, but a computed border, we can do
+(&ima(p)) if p is include in the image definition domain.
+But we cannot do that if p is include int the image extended domain.
+
+
+
+*** Data
+
+ data: stored,
+ linear < stored
+ raw < linear,
+ computed
+
+**** Definition
+
+ The data property indicates how the image handle the value.
+The value can be either computed (on the fly) or stored.
+We say that a value is stored when we can takes a reference of it (&ima(p))
+Value stored can linear:
+
+ | | |
+ v v v
+ -------- --------- ------------
+| | | | | |
+ -------- --------- ------------
+
+Or they can be stored in a raw way (just in one block):
+
+ |
+ v
+ -----------------------------------
+ | |
+ -----------------------------------
+
+
+**** Note
+computed data property implies that the image type has to be read_only.
+
+
+*** io
+ io: read,
+ write,
+ read_only < read,
+ (write_only < write,) Is it useful?
+ read_write < both read'n write
+
+**** Definition
+
+ Read/write Permissions for *ima(p)*
+ The name is probably bad, because image can also be accessed through
+their value (ex: Run image encoded by value).
+ So, we should change the property name to access site_io/site_access or
+something like that.
+
+
+
+*** Speed
+
+
+ speed: slow,
+ fast,
+ fastest
+
+**** Definition
+
+ Give us information the time needed to access to a value from a site.
+
+ slow: ima(p) is greater than O(1)
+ fast: ima(p) is in O(1)
+ fastest: ima(p) is in O(1)
+ Do we have an extended domain?
+ Can we access to the image value, directly with pointer in this
+case?
+
+
+
+
+
+
+** Properties related to I::value
+
+*** Kind
+
+ kind: color,
+ gray,
+ label,
+ named < label,
+ logic,
+ mvlogic < logic && < label,
+ binary < mvlogic,
+ ternary < mvlogic
+ fuzzy < logic,
+ data,
+ map,
+ distance < map
+ data
+
+*** Quant
+ quant: low,
+ high
+
+*** Value
+ value: scalar,
+ vectorial,
+ structed,
+ pointer
+
+
+** Properties related to I::pset
+
+*** access
+
+ access: random,
+ browsing
+
+Does this property resume psite != site?
+
+
+
+
+*** space
+ space: one_d,
+ two_d,
+ three_d
+
+Do we really need this property
+If we look at the slice morpher, it must know that the input image is in 2d.
+So, the answer tends to be yes.
+
+But in this case, how do we deal with no localized site? Specify the space
+value in localization property.
+Add a new value/property?
+
+*** support
+
+ support: irregular,
+ regular
+ aligned < regular
+
+This property will certainly change.
+
+Support property represent the underlying support of an Image type.
+It can be a grid, (regular, orthogonal, linear, isotrope, anysotrope).
+It can be different from a grid (a mesh?). We also want to know the value of a
+grid "stride (pas)", if this value is different from 1. Mask and convolution
+directly depends on these properties. Most of the filter mask are developed to
+work with grid with a stride of one.
+
+So, here we need to determine two things.
+First, we need to know if the underling support of the image is a grid
+or a mesh. Then, if the image is based on a grid we must provide an access
+to the properties a grid.
+We also have to choose which property of the grid are relevant, and which
+property of the grid are useless.
+
+
+
+
+
+* Property that we need?
+** has(p)
+
+Property that give the complexity of has(p).
+-- O(1) when site = psite
+-- depend on the implementation when site != psite
+
+** localization
+
+ localization: none,
+ space,
+ grid < space,
+ regular_grid < grid
+
+This property should replace the support property.
+
+An image on a no-localized space has this property set to none.
+An image on a localized space (each site can be convert into a site) has
+this property set to space.
+An image on a grid (which is not regular) has its property set to grid.
+Does an image on a grid has always points as site?
+An image based on the base grid (aligned, isotrope/anysotrop, othogonal) has
+this property set to grid.
+
+When this property are set, you can access to new information from the image.
+space -> box
+regular_grid -> deltaX, deltaY of the grid + other grid property??
+
+
+Note: that a site can be localised without being point wise (site are localized
+by vector). Do we need a property to say that the image is composed by point?
+Furthermore, an image can be localized and have its type psite != site.
+Ex: graph image<Point2d, T> We need a new property in order to define if the
+image is localized. Is this property gives us the same information than the
+support property?
+
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-04-03 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Fix documentation and guards in p_image2d.
* mln/core/p_image2d.hh: Fix documentation and guards.
* mln/core/p_image2d_piter.hh: Fix documentation.
---
p_image2d.hh | 10 +++++-----
p_image2d_piter.hh | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
Index: trunk/milena/mln/core/p_image2d.hh
===================================================================
--- trunk/milena/mln/core/p_image2d.hh (revision 1836)
+++ trunk/milena/mln/core/p_image2d.hh (revision 1837)
@@ -25,13 +25,13 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_CORE_P_SET_HH
-# define MLN_CORE_P_SET_HH
+#ifndef MLN_CORE_P_IMAGE2D_HH
+# define MLN_CORE_P_IMAGE2D_HH
-/*! \file mln/core/p_set.hh
+/*! \file mln/core/p_image2d.hh
*
- * \brief Definition of a point set class based on std::set.
+ * \brief Definition of a point set class based on a image of booleans.
*/
# include <mln/core/internal/point_set_base.hh>
@@ -206,4 +206,4 @@
# include <mln/core/p_image2d_piter.hh>
-#endif // ! MLN_CORE_P_SET_HH
+#endif // ! MLN_CORE_P_IMAGE2D_HH
Index: trunk/milena/mln/core/p_image2d_piter.hh
===================================================================
--- trunk/milena/mln/core/p_image2d_piter.hh (revision 1836)
+++ trunk/milena/mln/core/p_image2d_piter.hh (revision 1837)
@@ -29,7 +29,7 @@
# define MLN_CORE_P_IMAGE2D_PITER_HH
/// \file mln/core/p_image2d_piter.hh
-/// \brief Definition of point iterators on mln::p_array.
+/// \brief Definition of point iterators on mln::p_image2d.
# include <mln/core/p_image2d.hh>
# include <mln/core/box_piter.hh>
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2008-04-03 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
A fast point2d set : p_image2d.
* mln/core/p_image2d.hh: The new set.
* mln/core/p_image2d_piter.hh: To iter on it.
* tests/core/p_image2d.cc: some small tests.
---
mln/core/p_image2d.hh | 209 +++++++++++++++++++++++++++++
mln/core/p_image2d_piter.hh | 316 ++++++++++++++++++++++++++++++++++++++++++++
tests/core/p_image2d.cc | 56 +++++++
3 files changed, 581 insertions(+)
Index: trunk/milena/tests/core/p_image2d.cc
===================================================================
--- trunk/milena/tests/core/p_image2d.cc (revision 0)
+++ trunk/milena/tests/core/p_image2d.cc (revision 1836)
@@ -0,0 +1,56 @@
+// 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/core/p_image2d.cc
+ *
+ * \brief Tests on mln::p_image2d.
+ */
+
+#include <mln/core/p_image2d.hh>
+
+int main()
+{
+ using namespace mln;
+
+ p_image2d<point2d> ps(20,20);
+ ps
+ .insert(make::point2d(6, 9))
+ .insert(make::point2d(4, 2))
+ .insert(make::point2d(4, 2))
+ .insert(make::point2d(5, 1));
+ mln_assertion(ps.npoints() == 3);
+
+ ps.remove(make::point2d(5, 1));
+ ps.remove(make::point2d(5, 1));
+
+ ps.remove(make::point2d(6, 9));
+ ps.remove(make::point2d(4, 2));
+
+ mln_assertion(ps.npoints() == 0);
+ mln_assertion(ps.is_empty());
+
+}
Index: trunk/milena/mln/core/p_image2d.hh
===================================================================
--- trunk/milena/mln/core/p_image2d.hh (revision 0)
+++ trunk/milena/mln/core/p_image2d.hh (revision 1836)
@@ -0,0 +1,209 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// 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_P_SET_HH
+# define MLN_CORE_P_SET_HH
+
+
+/*! \file mln/core/p_set.hh
+ *
+ * \brief Definition of a point set class based on std::set.
+ */
+
+# include <mln/core/internal/point_set_base.hh>
+# include <mln/core/box2d.hh>
+# include <mln/core/image2d.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/level/fill.hh>
+# include <mln/core/p_array.hh>
+
+
+namespace mln
+{
+
+
+ // Fwd decls.
+ template <typename P> struct p_image2d_fwd_piter_;
+ template <typename P> struct p_image2d_bkd_piter_;
+
+ template <typename P>
+ class p_image2d : public internal::point_set_base_<P, p_image2d<P> >
+ {
+ public:
+
+ /// Forward Point_Iterator associated type.
+ typedef p_image2d_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef p_image2d_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ p_image2d(int nrows, int ncols);
+ p_image2d(const box2d& b);
+
+ /// Insert a point \p p.
+ p_image2d<P>& insert(const P p);
+ p_image2d<P>& insert(const p_image2d& set);
+
+ /// Remove a point \p p.
+ p_image2d<P>& remove(const P p);
+ p_image2d<P>& remove(const p_image2d& set);
+
+ /// Give the number of points.
+ unsigned npoints() const;
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Test if the set is empty.
+ bool is_empty() const;
+
+ /// Clear this set.
+ void clear();
+
+ /// Hook to the image2d
+ const image2d<bool>& image() const;
+ private:
+ image2d<bool> points_;
+ unsigned npoints_;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ p_image2d<P>::p_image2d(int nrows, int ncols)
+ : points_(nrows, ncols),
+ npoints_(0)
+ {
+
+ level::fill(points_, false);
+ }
+
+ template <typename P>
+ p_image2d<P>::p_image2d(const box2d& b)
+ : points_(b),
+ npoints_(0)
+ {
+ level::fill(points_, false);
+ }
+
+
+ template <typename P>
+ p_image2d<P>&
+ p_image2d<P>::insert(const P p)
+ {
+ if (points_(p) == false)
+ {
+ points_(p) = true;
+ npoints_++;
+ }
+ return *this;
+ }
+
+ template <typename P>
+ p_image2d<P>&
+ p_image2d<P>::insert(const p_image2d& set)
+ {
+ if (set->is_empty())
+ return *this;
+ mln_fwd_piter(image2d<bool>) p(set.points_ | true);
+ for_all(p)
+ if (this->points_.has(p))
+ this->insert(p);
+ return *this;
+ }
+
+ template <typename P>
+ p_image2d<P>&
+ p_image2d<P>::remove(const P p)
+ {
+ if (points_(p) == true)
+ {
+ points_(p) = false;
+ npoints_--;
+ }
+ return *this;
+ }
+
+ template <typename P>
+ p_image2d<P>&
+ p_image2d<P>::remove(const p_image2d& set)
+ {
+ if (this->is_empty() || set->is_empty())
+ return *this;
+ mln_fwd_piter(image2d<bool>) p(set.points_ | true);
+ for_all(p)
+ if (this->points_.has(p))
+ this->remove(p);
+ return *this;
+ }
+
+ template <typename P>
+ unsigned
+ p_image2d<P>::npoints() const
+ {
+ return npoints_;
+ }
+
+ template <typename P>
+ bool
+ p_image2d<P>::has(const P& p) const
+ {
+ return points_(p);
+ }
+
+ template <typename P>
+ bool
+ p_image2d<P>::is_empty() const
+ {
+ return npoints_ == 0;
+ }
+
+ template <typename P>
+ void
+ p_image2d<P>::clear()
+ {
+ level::fill(points_, false);
+ }
+
+ template <typename P>
+ const image2d<bool>&
+ p_image2d<P>::image() const
+ {
+ return points_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+# include <mln/core/p_image2d_piter.hh>
+
+
+#endif // ! MLN_CORE_P_SET_HH
Index: trunk/milena/mln/core/p_image2d_piter.hh
===================================================================
--- trunk/milena/mln/core/p_image2d_piter.hh (revision 0)
+++ trunk/milena/mln/core/p_image2d_piter.hh (revision 1836)
@@ -0,0 +1,316 @@
+// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+//
+// 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_P_IMAGE2D_PITER_HH
+# define MLN_CORE_P_IMAGE2D_PITER_HH
+
+/// \file mln/core/p_image2d_piter.hh
+/// \brief Definition of point iterators on mln::p_array.
+
+# include <mln/core/p_image2d.hh>
+# include <mln/core/box_piter.hh>
+
+
+namespace mln
+{
+
+ /// \brief Forward iterator on points of a p_array<P>.
+ template <typename P>
+ struct p_image2d_fwd_piter_
+ : public internal::point_iterator_base_< P, p_image2d_fwd_piter_<P> >
+ {
+ typedef p_image2d_fwd_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
+ public:
+ /// The associated psite type.
+ typedef P psite;
+
+ /// The associated point type.
+ typedef mln_point(P) point;
+
+ enum { dim = super_::dim };
+
+ /// Coordinate associated type.
+ template <typename S>
+ p_image2d_fwd_piter_(const p_image2d<S>& s);
+
+ /// Reference of the corresponding psite.
+ const psite& to_psite() const;
+
+ /// Reference of the corresponding point.
+ const point& to_point() const;
+
+ /// Read-only access to the \p i-th coordinate.
+ mln_coord(point) operator[](unsigned i) const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convert the iterator into a psite.
+ operator psite() const;
+
+ protected:
+ box_fwd_piter_<P> piter_;
+ const image2d<bool> ima_;
+ };
+
+
+
+ /// \brief Backward iterator on points of a p_array<P>.
+ template <typename P>
+ struct p_image2d_bkd_piter_
+ : public internal::point_iterator_base_< P, p_image2d_bkd_piter_<P> >
+ {
+ typedef p_image2d_bkd_piter_<P> self_;
+ typedef internal::point_iterator_base_< P, self_ > super_;
+ public:
+ /// The associated psite type.
+ typedef P psite;
+
+ /// The associated point type.
+ typedef mln_point(P) point;
+
+ enum { dim = super_::dim };
+
+ /// Coordinate associated type.
+ template <typename S>
+ p_image2d_bkd_piter_(const p_image2d<S>& s);
+
+ /// Reference of the corresponding psite.
+ const psite& to_psite() const;
+
+ /// Reference of the corresponding point.
+ const point& to_point() const;
+
+ /// Read-only access to the \p i-th coordinate.
+ mln_coord(point) operator[](unsigned i) const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convert the iterator into a psite.
+ operator psite() const;
+
+ protected:
+ box_bkd_piter_<P> piter_;
+ image2d<bool> ima_;
+
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ /*------------------------.
+ | p_image2d_fwd_piter_<P>. |
+ `------------------------*/
+
+ template <typename P>
+ template <typename S>
+ inline
+ p_image2d_fwd_piter_<P>::p_image2d_fwd_piter_(const p_image2d<S>& s)
+ : piter_(exact(s).image().domain()),
+ ima_(exact(s).image())
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ inline
+ const P&
+ p_image2d_fwd_piter_<P>::to_psite() const
+ {
+ return piter_.to_psite();
+ }
+
+ template <typename P>
+ inline
+ const mln_point(P)&
+ p_image2d_fwd_piter_<P>::to_point() const
+ {
+ return piter_.to_point();
+ }
+
+ template <typename P>
+ inline
+ mln_coord(mln_point_(P))
+ p_image2d_fwd_piter_<P>::operator[](unsigned i) const
+ {
+ return piter_[i];
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_image2d_fwd_piter_<P>::is_valid() const
+ {
+ return piter_.is_valid();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_image2d_fwd_piter_<P>::invalidate()
+ {
+ return piter_.invalidate();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_image2d_fwd_piter_<P>::start()
+ {
+ piter_.start();
+ while(is_valid() && !ima_(piter_))
+ piter_.next();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_image2d_fwd_piter_<P>::next_()
+ {
+ piter_.next();
+ while(is_valid() && !ima_(piter_))
+ piter_.next();
+ }
+
+ template <typename P>
+ inline
+ p_image2d_fwd_piter_<P>::operator P() const
+ {
+ return P(piter_);
+ }
+
+
+ /*------------------------.
+ | p_image2d_bkd_piter_<P>. |
+ `------------------------*/
+
+ template <typename P>
+ template <typename S>
+ inline
+ p_image2d_bkd_piter_<P>::p_image2d_bkd_piter_(const p_image2d<S>& s)
+ : piter_(exact(s).image().domain()),
+ ima_(exact(s).image())
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ inline
+ const P&
+ p_image2d_bkd_piter_<P>::to_psite() const
+ {
+ return piter_.to_psite();
+ }
+
+ template <typename P>
+ inline
+ const mln_point(P)&
+ p_image2d_bkd_piter_<P>::to_point() const
+ {
+ return piter_.to_point();
+ }
+
+ template <typename P>
+ inline
+ mln_coord(mln_point_(P))
+ p_image2d_bkd_piter_<P>::operator[](unsigned i) const
+ {
+ mln_precondition(is_valid());
+ return piter_[i];
+ }
+
+ template <typename P>
+ inline
+ bool
+ p_image2d_bkd_piter_<P>::is_valid() const
+ {
+ return piter_.is_valid();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_image2d_bkd_piter_<P>::invalidate()
+ {
+ return piter_.invalidate();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_image2d_bkd_piter_<P>::start()
+ {
+ piter_.start();
+ while(is_valid() && !ima_(piter_))
+ piter_.next();
+ }
+
+ template <typename P>
+ inline
+ void
+ p_image2d_bkd_piter_<P>::next_()
+ {
+ piter_.next();
+ while(is_valid() && !ima_(piter_))
+ piter_.next();
+ }
+
+ template <typename P>
+ inline
+ p_image2d_bkd_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return P(piter_);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_P_IMAGE2D_PITER_HH