rectangularity.hh 3.32 KB
Newer Older
1
// Copyright (C) 2009, 2013 EPITA Research and Development Laboratory (LRDE)
2
//
3
// This file is part of Olena.
4
//
5
6
7
8
9
// 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,
10
11
12
13
14
// 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
15
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
16
17
//
// As a special exception, you may use this file as part of a free
18
// software project without restriction.  Specifically, if other files
19
// instantiate templates or use macros or inline functions from this
20
21
22
23
24
// 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.
25
26
27
28

#ifndef MLN_ACCU_SITE_SET_RECTANGULARITY_HH
# define MLN_ACCU_SITE_SET_RECTANGULARITY_HH

29
/// \file
30
31
32
33
///
/// Compute the rectangularity of a site set.

# include <mln/accu/internal/couple.hh>
34
# include <mln/accu/shape/bbox.hh>
35
# include <mln/accu/math/count.hh>
36
37
38
39
40
41
42
43
44
45

namespace mln
{

  namespace accu
  {

    namespace site_set
    {

Guillaume Lazzara's avatar
Guillaume Lazzara committed
46
47
48
49
      /// \brief Compute the rectangularity of a site set.
      ///
      /// \ingroup modaccusiteset
      //
50
51
      template <typename P>
      class rectangularity
52
	: public accu::internal::couple<accu::shape::bbox<P>,
53
					accu::math::count<P>,
54
55
56
57
58
59
					float,
					rectangularity<P> >
      {

      public:

60
	typedef accu::internal::couple<accu::shape::bbox<P>,
61
				       accu::math::count<P>,
62
63
64
				       float,
				       rectangularity<P> > super_;

65
	typedef accu::shape::bbox<P> A1;
66
	typedef accu::math::count<P> A2;
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

	typedef float result;

	/// Constructor
	rectangularity();

	/// Return the site set bounding box.
	mln_result(A1) bbox() const;
	/// Return the site set area.
	mln_result(A2) area() const;

	/// Return the rectangularity value.
	result to_result() const;
      };

82

83
84
85
86
87
88
89
90
91
92
93
94
95
# ifndef MLN_INCLUDE_ONLY

      template <typename P>
      inline
      rectangularity<P>::rectangularity()
      {
      }

      template <typename P>
      inline
      mln_result(rectangularity<P>::A1)
      rectangularity<P>::bbox() const
      {
96
97
	mln_precondition(this->a1_.is_valid());
	return this->a1_.to_result();
98
99
100
101
102
103
104
      }

      template <typename P>
      inline
      mln_result(rectangularity<P>::A2)
      rectangularity<P>::area() const
      {
105
106
	mln_precondition(this->a2_.is_valid());
	return this->a2_.to_result();
107
108
109
110
111
112
113
114
115
      }

      template <typename P>
      inline
      mln_result(rectangularity<P>)
      rectangularity<P>::to_result() const
      {
	mln_precondition(this->is_valid());
	// Force division return type.
116
117
	return static_cast<result>
	  (this->a2_.to_result()) / this->a1_.to_result().nsites();
118
119
120
121
122
123
124
125
126
127
128
      }

# endif // ! MLN_INCLUDE_ONLY

    } // end of namespace mln::accu::site_set

  } // end of namespace mln::accu

} // end of namespace mln

#endif // ! MLN_ACCU_SITE_SET_RECTANGULARITY_HH