
Index: ChangeLog =================================================================== --- ChangeLog (revision 644) +++ ChangeLog (working copy) @@ -1,5 +1,20 @@ 2006-10-16 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> + Add binary value type plus update image hierarchy plugs. + + * oln/value/tags.hh: New. + * oln/value/bin.hh: New. + * oln/value/all.hh: New. + * oln/core/abstract/image/type/hierarchy.hh (case_): Rely on value + tags. + (case_): Overload to handle other value types. + (include): Update. + * oln/value/greylevel.hh (greylevel_): New conversion operator. + (gl1): Remove; now replaced by value::bin. + * oln/Makefile.am: Update. + +2006-10-16 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> + Add grey-level types. * tests/grey.cc: New. Index: oln/core/abstract/image/type/hierarchy.hh =================================================================== --- oln/core/abstract/image/type/hierarchy.hh (revision 644) +++ oln/core/abstract/image/type/hierarchy.hh (working copy) @@ -30,7 +30,7 @@ # include <oln/core/abstract/image.hh> # include <oln/core/abstract/image/hierarchies.hh> -# include <xtd/valtraits.hh> +# include <oln/value/tags.hh> /* Image ``type'' hierarchy (summary). @@ -93,34 +93,50 @@ namespace oln { - /// Switch on on the grid dimension. + /// Switch on the value type. /// \{ - // ----------------------------------------------- // - // Cases where the value type is an builtin type. // - // ----------------------------------------------- // + // ------------------------------------- // + // Cases where the value type is known. // + // ------------------------------------- // /// Binary case. template <typename E> struct case_< image_hierarchy_wrt_type, E, 1 > : - where_< xtd_is_binary(oln_type_of(E, value)) > + where_< value::is_binary<oln_type_of(E, value)> > { // Definition of the super class corresponding to this case. typedef abstract::binary_image<E> ret; }; - /// Grey-level case. + /// Color case. template <typename E> struct case_< image_hierarchy_wrt_type, E, 2 > : - where_< mlc::or_list_< mlc::eq_<oln_type_of(E, value), char>, - mlc::eq_<oln_type_of(E, value), signed char>, - mlc::eq_<oln_type_of(E, value), unsigned char> > > + where_< value::is_color<oln_type_of(E, value)> > { // Definition of the super class corresponding to this case. + typedef abstract::color_image<E> ret; + }; + + /// Grey-level case. + template <typename E> + struct case_< image_hierarchy_wrt_type, E, 3 > : + where_< value::is_grey_level<oln_type_of(E, value)> > + { + // Definition of the super class corresponding to this case. typedef abstract::grey_level_image<E> ret; }; + /// Label case. + template <typename E> + struct case_< image_hierarchy_wrt_type, E, 4 > : + where_< value::is_label<oln_type_of(E, value)> > + { + // Definition of the super class corresponding to this case. + typedef abstract::label_image<E> ret; + }; + // -------------- // // Default case. // // -------------- // Index: oln/Makefile.am =================================================================== --- oln/Makefile.am (revision 644) +++ oln/Makefile.am (working copy) @@ -152,8 +152,10 @@ morpher/tags.hh \ morpher/thru_fun.hh \ \ + value/all.hh \ value/default.hh \ value/greylevel.hh \ + value/tags.hh \ \ basics1d.hh \ basics2d.hh \ Index: oln/value/bin.hh =================================================================== --- oln/value/bin.hh (revision 0) +++ oln/value/bin.hh (revision 0) @@ -0,0 +1,110 @@ +// Copyright (C) 2006 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 OLN_CORE_VALUE_BIN_HH +# define OLN_CORE_VALUE_BIN_HH + +# include <mlc/bexpr.hh> +# include <xtd/optraits.hh> +# include <xtd/valtraits.hh> +# include <oln/value/greylevel.hh> + + +namespace oln +{ + + namespace value + { + + typedef greylevel_<1> bin; + + + // Binary ops. + bin operator and(bin lhs, bin rhs); + bin operator or(bin lhs, bin rhs); + bin operator xor(bin lhs, bin rhs); + + // Unary ops. + bin operator not(bin val); + + +# ifndef OLN_INCLUDE_ONLY + + bin operator and(bin lhs, bin rhs) + { + return bin(bool(lhs) and bool(rhs)); + } + + bin operator or(bin lhs, bin rhs) + { + return bin(bool(lhs) or bool(rhs)); + } + + bin operator xor(bin lhs, bin rhs) + { + return bin(bool(lhs) xor bool(rhs)); + } + + bin operator not(bin val) + { + return bin(not bool(val)); + } + +# endif + + } // end of namespace oln::value + +} // end of namespace oln + + + +namespace xtd +{ + + using oln::value::bin; + + + // Logical traits. + + template <> struct set_trait_< op_land, bin, bin > { typedef bin ret; }; + template <> struct set_trait_< op_land, bool, bin > { typedef bin ret; }; + template <> struct set_trait_< op_land, bin, bool > { typedef bin ret; }; + + template <> struct set_trait_< op_lor, bin, bin > { typedef bin ret; }; + template <> struct set_trait_< op_lor, bool, bin > { typedef bin ret; }; + template <> struct set_trait_< op_lor, bin, bool > { typedef bin ret; }; + + template <> struct set_trait_< op_lxor, bin, bin > { typedef bin ret; }; + template <> struct set_trait_< op_lxor, bool, bin > { typedef bin ret; }; + template <> struct set_trait_< op_lxor, bin, bool > { typedef bin ret; }; + + template <> struct set_trait_< op_lnot, bin > { typedef bin ret; }; + +} // end of namespace xtd + + +#endif // ! OLN_CORE_VALUE_BIN_HH Index: oln/value/all.hh =================================================================== --- oln/value/all.hh (revision 0) +++ oln/value/all.hh (revision 0) @@ -0,0 +1,41 @@ +// Copyright (C) 2006 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 OLN_VALUE_ALL_HH +# define OLN_VALUE_ALL_HH + + +# include <oln/value/tags.hh> + +# include <oln/value/greylevel.hh> +# include <oln/value/bin.hh> +# include <oln/value/default.hh> + +# include <oln/color/rgb.hh> + + +#endif // ! OLN_VALUE_ALL_HH Index: oln/value/greylevel.hh =================================================================== --- oln/value/greylevel.hh (revision 644) +++ oln/value/greylevel.hh (working copy) @@ -30,10 +30,12 @@ # include <iostream> # include <mlc/contract.hh> +# include <mlc/bexpr.hh> # include <xtd/optraits.hh> # include <oln/core/abstract/value.hh> + namespace oln { @@ -71,11 +73,14 @@ greylevel_(); /// Ctor. - explicit greylevel_(typename internal::encoding<nbits>::ret val); + explicit greylevel_(const typename internal::encoding<nbits>::ret& val); /// Access to std type. typename internal::encoding<nbits>::ret value() const; + /// Op encoding_t. + operator typename internal::encoding<nbits>::ret() const; + /// Op greylevel. operator greylevel() const; @@ -96,7 +101,6 @@ /// Aliases. - typedef greylevel_<1> gl1; typedef greylevel_<8> gl8; typedef greylevel_<16> gl16; typedef greylevel_<32> gl32; @@ -183,7 +187,7 @@ } template <unsigned nbits> - greylevel_<nbits>::greylevel_(typename internal::encoding<nbits>::ret val) + greylevel_<nbits>::greylevel_(const typename internal::encoding<nbits>::ret& val) : val_(val) { } @@ -203,6 +207,12 @@ } template <unsigned nbits> + greylevel_<nbits>::operator typename internal::encoding<nbits>::ret() const + { + return val_; + } + + template <unsigned nbits> bool greylevel_<nbits>::operator<(const greylevel_<nbits>& rhs) const { return val_ < rhs.val_; Index: oln/value/tags.hh =================================================================== --- oln/value/tags.hh (revision 0) +++ oln/value/tags.hh (revision 0) @@ -0,0 +1,105 @@ +// Copyright (C) 2006 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 OLN_VALUE_TAGS_HH +# define OLN_VALUE_TAGS_HH + +# include <mlc/bexpr.hh> + + +namespace oln +{ + + + namespace color + { + template <typename T> class rgb_; + } // end of namespace oln::color + + + namespace value + { + + // Color trait. + + template <typename T> + struct is_color : public mlc::bexpr_<false> + { + }; + + template <typename T> + struct is_color < color::rgb_<T> > : public mlc::bexpr_<true> {}; + + + // Grey-level trait. + + template <typename T> + struct is_grey_level : public mlc::bexpr_<false> + {}; + + template <unsigned nbits> + class greylevel_; + + template <unsigned nbits> + struct is_grey_level < greylevel_<nbits> > : public mlc::bexpr_<true> {}; + + class greylevel; + + template <> + struct is_grey_level < greylevel > : public mlc::bexpr_<true> {}; + + + // Binary trait. + + template <typename T> + struct is_binary : public mlc::bexpr_<false> + { + }; + + template <> + struct is_binary < bool > : public mlc::bexpr_<true> {}; + + typedef greylevel_<1> bin; + + template <> + struct is_binary < bin > : public mlc::bexpr_<true> {}; + + + // Label trait. + + template <typename T> + struct is_label : public mlc::bexpr_<false> + { + }; + + + } // end of namespace oln::value + +} // end of namespace oln + + +#endif // ! OLN_VALUE_TAGS_HH