Commit 39c60202 authored by Roland Levillain's avatar Roland Levillain
Browse files

Add actual complex-based psite and pset and give new names to

	faces-related entities.

	* mln/core/complex_psite.hh: Rename as...
	* mln/core/faces_psite.hh: ...this.
	(mln::complex_psite<P, N, D>): Turn into...
	(mln::faces_psite<N, D, P>): ...this.
	* mln/core/p_complex.hh: Rename as...
	* mln/core/p_faces.hh: ...this.
	(mln::p_complex<P, N, D>): Turn into...
	(mln::p_faces<N, D, P>): ...this.
	* mln/core/complex_psite.hh, mln/core/p_complex.hh: New.
	* tests/core/complex.cc: Exercise the variants of
	mln::complex<D>::nfaces().
	* tests/core/p_complex.cc: Rename as...
	* tests/core/complex_image.cc: ...this.
	Exercise mln::p_complex, mln::complex_psite, and mln::faces_psite.
	* tests/core/Makefile.am (check_PROGRAMS):
	s/p_complex/complex_image/.
	(p_complex_SOURCES): Likewise.
	Rename as...
	(complex_image_SOURCES): ...this.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@2128 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent b487e18c
2008-08-07 Roland Levillain <roland@lrde.epita.fr>
Add actual complex-based psite and pset and give new names to
faces-related entities.
* mln/core/complex_psite.hh: Rename as...
* mln/core/faces_psite.hh: ...this.
(mln::complex_psite<P, N, D>): Turn into...
(mln::faces_psite<N, D, P>): ...this.
* mln/core/p_complex.hh: Rename as...
* mln/core/p_faces.hh: ...this.
(mln::p_complex<P, N, D>): Turn into...
(mln::p_faces<N, D, P>): ...this.
* mln/core/complex_psite.hh, mln/core/p_complex.hh: New.
* tests/core/complex.cc: Exercise the variants of
mln::complex<D>::nfaces().
* tests/core/p_complex.cc: Rename as...
* tests/core/complex_image.cc: ...this.
Exercise mln::p_complex, mln::complex_psite, and mln::faces_psite.
* tests/core/Makefile.am (check_PROGRAMS):
s/p_complex/complex_image/.
(p_complex_SOURCES): Likewise.
Rename as...
(complex_image_SOURCES): ...this.
2008-08-07 Roland Levillain <roland@lrde.epita.fr>
Add a dimension-agnostic face handle.
......
......@@ -38,21 +38,16 @@
namespace mln
{
/* FIXME: Write also a complex_psite where N is dynamic, and can be
changed? */
/* FIXME: Get rid of P? */
/* FIXME: Currently, P and N are free variables; we might want to
relate them, e.g., have P::dim == N. Or even get rid of P. */
/// \brief Point site associated to a mln::complex_image.
/// \brief Point site associated to a mln::p_complex.
///
/// \arg \p D The dimension of the complex this psite belongs to.
/// \arg \p P The type of point associated to this psite.
/// \arg \p N The dimension of the face associated to this psite.
/// \arg \p D The dimention of the complex this psite belongs to.
template <typename P, unsigned N, unsigned D>
class complex_psite : public Point_Site< complex_psite<P, N, D> >
template <unsigned D, typename P>
class complex_psite : public Point_Site< complex_psite<D, P> >
{
typedef complex_psite<P, N, D> self_;
typedef complex_psite<D, P> self_;
typedef Point_Site<self_> super_;
public:
......@@ -65,7 +60,7 @@ namespace mln
/// Construction and assignment.
/// \{
complex_psite();
complex_psite(const face_handle<N, D>& face);
complex_psite(const any_face_handle<D>& face);
complex_psite(const self_& rhs);
self_& operator= (const self_& rhs);
/// \}
......@@ -82,7 +77,7 @@ namespace mln
/// \}
/// Return the face handle of this point site.
face_handle<N, D> face() const;
any_face_handle<D> face() const;
/// Return the complex on which this site is built.
const complex<D>& cplx() const;
......@@ -91,7 +86,7 @@ namespace mln
private:
/// The handle of the face this psite is pointing towards.
face_handle<N, D> face_;
any_face_handle<D> face_;
// FIXME: Actually, this is a dummy value!
point p_;
};
......@@ -106,10 +101,10 @@ namespace mln
///
/// \pre Arguments \a lhs and \a rhs must belong to the same
/// mln::complex.
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
bool
operator==(const complex_psite<P, N, D>& lhs,
const complex_psite<P, N, D>& rhs);
operator==(const complex_psite<D, P>& lhs,
const complex_psite<D, P>& rhs);
/// \brief Is \a lhs ``less'' than \a rhs?
///
......@@ -117,51 +112,45 @@ namespace mln
///
/// \pre Arguments \a lhs and \a rhs must belong to the same
/// mln::complex.
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
bool
operator< (const complex_psite<P, N, D>& lhs,
const complex_psite<P, N, D>& rhs);
operator< (const complex_psite<D, P>& lhs,
const complex_psite<D, P>& rhs);
/// \}
# ifndef MLN_INCLUDE_ONLY
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
complex_psite<P, N, D>::complex_psite()
complex_psite<D, P>::complex_psite()
: super_(),
// Dummy initializations.
face_(), p_()
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
complex_psite<P, N, D>::complex_psite(const face_handle<N, D>& face)
complex_psite<D, P>::complex_psite(const any_face_handle<D>& face)
: super_(),
face_(face), p_()
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
complex_psite<P, N, D>::complex_psite(const complex_psite<P, N, D>& rhs)
complex_psite<D, P>::complex_psite(const complex_psite<D, P>& rhs)
: super_(rhs),
face_(rhs.face_), p_()
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
complex_psite<P, N, D>&
complex_psite<P, N, D>::operator= (const complex_psite<P, N, D>& rhs)
complex_psite<D, P>&
complex_psite<D, P>::operator= (const complex_psite<D, P>& rhs)
{
if (&rhs == this)
return *this;
......@@ -169,52 +158,52 @@ namespace mln
return *this;
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
bool
complex_psite<P, N, D>::is_valid() const
complex_psite<D, P>::is_valid() const
{
return face.is_valid();
return face_.is_valid();
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
const complex_psite<P, N, D>&
complex_psite<P, N, D>::to_psite() const
const complex_psite<D, P>&
complex_psite<D, P>::to_psite() const
{
return *this;
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
const P&
complex_psite<P, N, D>::to_point() const
complex_psite<D, P>::to_point() const
{
// FIXME: Dummy value.
return p_;
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
mln_coord(P)
complex_psite<P, N, D>::operator[](unsigned i) const
complex_psite<D, P>::operator[](unsigned i) const
{
mln_precondition(is_valid());
return to_point()[i];
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
face_handle<N, D>
complex_psite<P, N, D>::face() const
any_face_handle<D>
complex_psite<D, P>::face() const
{
return face_;
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
const complex<D>&
complex_psite<P, N, D>::cplx() const
complex_psite<D, P>::cplx() const
{
return face_.cplx();
}
......@@ -223,19 +212,19 @@ namespace mln
| Comparisons. |
`--------------*/
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
bool
operator==(const complex_psite<P, N, D>& lhs,
const complex_psite<P, N, D>& rhs)
operator==(const complex_psite<D, P>& lhs,
const complex_psite<D, P>& rhs)
{
mln_precondition(&lhs.cplx() == &rhs.cplx());
return lhs.face() == rhs.face();
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
bool
operator< (const complex_psite<P, N, D>& lhs,
const complex_psite<P, N, D>& rhs)
operator< (const complex_psite<D, P>& lhs,
const complex_psite<D, P>& rhs)
{
mln_precondition(&lhs.cplx() == &rhs.cplx());
return lhs.face() < rhs.face();
......
// Copyright (C) 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.
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef MLN_CORE_FACES_PSITE_HH
# define MLN_CORE_FACES_PSITE_HH
/// \file mln/core/faces_psite.hh
/// \brief Definition of a point site based on the n-faces of a
/// complex.
# include <mln/core/concept/point_site.hh>
# include <mln/core/complex.hh>
namespace mln
{
/* FIXME: Currently, P and N are free variables; we might want to
relate them, e.g., have P::dim == N. Or even get rid of P. */
/// \brief Point site associated to a mln::p_faces.
///
/// \arg \p N The dimension of the face associated to this psite.
/// \arg \p D The dimension of the complex this psite belongs to.
/// \arg \p P The type of point associated to this psite.
template <unsigned N, unsigned D, typename P>
class faces_psite : public Point_Site< faces_psite<N, D, P> >
{
typedef faces_psite<N, D, P> self_;
typedef Point_Site<self_> super_;
public:
typedef mln_mesh(P) mesh;
enum { dim = P::dim };
typedef P point;
typedef mln_dpoint(P) dpoint;
typedef mln_coord(P) coord;
/// Construction and assignment.
/// \{
faces_psite();
faces_psite(const face_handle<N, D>& face);
faces_psite(const self_& rhs);
self_& operator= (const self_& rhs);
/// \}
/// Access to psite.
const self_& to_psite() const;
/* FIXME: Should be removed as soon as ``point sets'' become
``site sets''. */
/// Access to point.
/// \{
const point& to_point() const;
coord operator[](unsigned face) const;
/// \}
/// Return the face handle of this point site.
face_handle<N, D> face() const;
/// Return the complex on which this site is built.
const complex<D>& cplx() const;
/// Is this psite valid?
bool is_valid() const;
private:
/// The handle of the face this psite is pointing towards.
face_handle<N, D> face_;
// FIXME: Actually, this is a dummy value!
point p_;
};
/// Comparison of two instances of mln::faces_psite.
/// \{
/* FIXME: Shouldn't those comparisons be part of a much general
mechanism? */
/// \brief Is \a lhs equal to \a rhs?
///
/// \pre Arguments \a lhs and \a rhs must belong to the same
/// mln::complex.
template <unsigned N, unsigned D, typename P>
bool
operator==(const faces_psite<N, D, P>& lhs,
const faces_psite<N, D, P>& rhs);
/// \brief Is \a lhs ``less'' than \a rhs?
///
/// This comparison is required by algorithms sorting psites.
///
/// \pre Arguments \a lhs and \a rhs must belong to the same
/// mln::complex.
template <unsigned N, unsigned D, typename P>
bool
operator< (const faces_psite<N, D, P>& lhs,
const faces_psite<N, D, P>& rhs);
/// \}
# ifndef MLN_INCLUDE_ONLY
template <unsigned N, unsigned D, typename P>
inline
faces_psite<N, D, P>::faces_psite()
: super_(),
// Dummy initializations.
face_(), p_()
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
}
template <unsigned N, unsigned D, typename P>
inline
faces_psite<N, D, P>::faces_psite(const face_handle<N, D>& face)
: super_(),
face_(face), p_()
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
}
template <unsigned N, unsigned D, typename P>
inline
faces_psite<N, D, P>::faces_psite(const faces_psite<N, D, P>& rhs)
: super_(rhs),
face_(rhs.face_), p_()
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
}
template <unsigned N, unsigned D, typename P>
inline
faces_psite<N, D, P>&
faces_psite<N, D, P>::operator= (const faces_psite<N, D, P>& rhs)
{
if (&rhs == this)
return *this;
face_ = rhs.face_;
return *this;
}
template <unsigned N, unsigned D, typename P>
inline
bool
faces_psite<N, D, P>::is_valid() const
{
return face_.is_valid();
}
template <unsigned N, unsigned D, typename P>
inline
const faces_psite<N, D, P>&
faces_psite<N, D, P>::to_psite() const
{
return *this;
}
template <unsigned N, unsigned D, typename P>
inline
const P&
faces_psite<N, D, P>::to_point() const
{
// FIXME: Dummy value.
return p_;
}
template <unsigned N, unsigned D, typename P>
inline
mln_coord(P)
faces_psite<N, D, P>::operator[](unsigned i) const
{
mln_precondition(is_valid());
return to_point()[i];
}
template <unsigned N, unsigned D, typename P>
inline
face_handle<N, D>
faces_psite<N, D, P>::face() const
{
return face_;
}
template <unsigned N, unsigned D, typename P>
inline
const complex<D>&
faces_psite<N, D, P>::cplx() const
{
return face_.cplx();
}
/*--------------.
| Comparisons. |
`--------------*/
template <unsigned N, unsigned D, typename P>
bool
operator==(const faces_psite<N, D, P>& lhs,
const faces_psite<N, D, P>& rhs)
{
mln_precondition(&lhs.cplx() == &rhs.cplx());
return lhs.face() == rhs.face();
}
template <unsigned N, unsigned D, typename P>
bool
operator< (const faces_psite<N, D, P>& lhs,
const faces_psite<N, D, P>& rhs)
{
mln_precondition(&lhs.cplx() == &rhs.cplx());
return lhs.face() < rhs.face();
}
# endif // ! MLN_INCLUDE_ONLY
} // end of mln
#endif // MLN_CORE_FACES_PSITE_HH
......@@ -43,12 +43,23 @@
namespace mln
{
/// A complex psite set based on a complex of dimension \p D (a \p
/// D-complex).
template<typename P, unsigned N, unsigned D>
// FIXME: Rename as p_faces.
/* FIXME: For compatibility reasons with mln::Point_Set, a point
type \P is attached to this complex-based pset (but it is not
used actually). We should either:
- use it, and make it mandatory (good solution for the moment);
- use it, and make it optional (better solution, but implies
changes in mln::Point_Set;
- remove it (easy and bad solution). */
/// A complex psite set based on a the \N-faces of a complex of
/// dimension \p D (a \p D-complex).
template <unsigned D, typename P>
struct p_complex
: public internal::point_set_base_< complex_psite<P, N, D>,
p_complex<P, N, D> >
: public internal::point_set_base_< complex_psite<D, P>,
p_complex<D, P> >
{
/// \brief Construct a complex psite set from a complex.
///
......@@ -59,7 +70,7 @@ namespace mln
p_complex (const complex<D>& cplx);
/// Point_Site associated type.
typedef complex_psite<P, N, D> psite;
typedef complex_psite<D, P> psite;
// FIXME: Fake.
typedef void fwd_piter;
......@@ -94,9 +105,9 @@ namespace mln
///
/// Two mln::p_complex's are considered equal if they share the
/// same complex.
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
bool
operator==(const p_complex<P, N, D>& lhs, const p_complex<P, N, D>& rhs);
operator==(const p_complex<D, P>& lhs, const p_complex<D, P>& rhs);
/// \brief Inclusion of a mln::p_complex in another one.
///
......@@ -106,23 +117,20 @@ namespace mln
///
/// \todo Refine this later, when we are able to express subcomplex
/// relations.
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
bool
operator<=(const p_complex<P, N, D>& lhs, const p_complex<P, N, D>& rhs);
operator<=(const p_complex<D, P>& lhs, const p_complex<D, P>& rhs);
# ifndef MLN_INCLUDE_ONLY
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
p_complex<P, N, D>::p_complex(const complex<D>& cplx)
p_complex<D, P>::p_complex(const complex<D>& cplx)
// Create a deep, managed copy of CPLX.
: cplx_(new complex<D>(cplx))
{
// Ensure N is compatible with D.
metal::bool_< N <= D >::check();
// FIXME: Dummy initialization.
accu::bbox<P> a;
for (unsigned i = 0; i < npoints(); ++i)
......@@ -130,35 +138,35 @@ namespace mln
bb_ = a.to_result();
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
std::size_t
p_complex<P, N, D>::npoints() const
p_complex<D, P>::npoints() const
{
return nfaces();
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
std::size_t
p_complex<P, N, D>::nfaces() const
p_complex<D, P>::nfaces() const
{
return this->cplx_->template nfaces<N>();
return cplx_->nfaces();
}
template <typename P, unsigned N, unsigned D>
template <unsigned D, typename P>
inline
const box_<P>&
p_complex<P, N, D<