link_single_dmax_base.hh 4.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright (C) 2009 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.

Guillaume Lazzara's avatar
Guillaume Lazzara committed
26
27
#ifndef SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_BASE_HH_
# define SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_BASE_HH_
28
29
30
31
32
33
34
35
36
37
38
39
40

/// \file
///
/// Base class for link functors using center sites and a given max
/// distance.


# include <mln/accu/center.hh>
# include <mln/labeling/compute.hh>
# include <mln/math/abs.hh>
# include <mln/util/array.hh>

# include <scribo/core/macros.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
41
# include <scribo/core/anchors.hh>
42
43
44
45
# include <scribo/core/object_image.hh>
# include <scribo/core/object_links.hh>

# include <scribo/primitive/link/internal/find_link.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
46
# include <scribo/primitive/link/internal/compute_anchor.hh>
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# include <scribo/primitive/link/internal/link_functor_base.hh>

# include <scribo/primitive/link/compute.hh>


namespace scribo
{

  namespace primitive
  {

    namespace link
    {

      namespace internal
      {

	/// \brief Base class for link functors using mass centers and
	/// a given max distance.
	//
	template <typename L, typename E>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
68
	class link_single_dmax_base
69
70
71
	  : public link_functor_base<L, E>
	{
	  typedef link_functor_base<L,E> super_;
Guillaume Lazzara's avatar
Guillaume Lazzara committed
72
	  typedef mln_result(accu::center<mln_psite(L)>) ms_t;
73
74
75
76
77

	public:

	  typedef mln_site(L) P;

Guillaume Lazzara's avatar
Guillaume Lazzara committed
78
	  link_single_dmax_base(const object_image(L)& objects,
79
80
				unsigned neighb_max_distance,
				anchor::Direction direction);
81
82
83
84
85
86


	  bool verify_link_criterion_(unsigned current_object,
				      const P& start_point, const P& p) const;

	  mln_site(L) start_point_(unsigned current_object,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
87
				   anchor::Type anchor);
88
89
90
91
92
93

	  void start_processing_object_(unsigned current_object);

	private:
	  float dmax_;
	  float neighb_max_distance_;
94
	  anchor::Direction direction_;
95
96
97
98
99
100
101
102
	};


# ifndef MLN_INCLUDE_ONLY


	template <typename L, typename E>
	inline
Guillaume Lazzara's avatar
Guillaume Lazzara committed
103
	link_single_dmax_base<L, E>::link_single_dmax_base(
104
	  const object_image(L)& objects,
105
106
	  unsigned neighb_max_distance,
	  anchor::Direction direction)
107
108
109

	  : super_(objects),
	    dmax_(0),
110
111
	    neighb_max_distance_(neighb_max_distance),
	    direction_(direction)
112
113
114
115
116
117
118
	{
	}


	template <typename L, typename E>
	inline
	bool
Guillaume Lazzara's avatar
Guillaume Lazzara committed
119
	link_single_dmax_base<L, E>::verify_link_criterion_(
120
121
122
123
124
125
	  unsigned current_object,
	  const P& start_point,
	  const P& p) const
	{
	  (void) current_object;

126
	  float dist = math::abs(p[direction_] - start_point[direction_]);
127
128
129
130
131
132
133
	  return dist <= dmax_; // Not too far
	}


	template <typename L, typename E>
	inline
	mln_site(L)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
134
135
	link_single_dmax_base<L, E>::start_point_(unsigned current_object,
						  anchor::Type anchor)
136
	{
137
	  return internal::compute_anchor(this->objects_,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
138
					  current_object, anchor);
139
140
141
142
143
144
	}


	template <typename L, typename E>
	inline
	void
Guillaume Lazzara's avatar
Guillaume Lazzara committed
145
	link_single_dmax_base<L, E>::start_processing_object_(
146
147
148
	  unsigned current_object)
	{
	  float
149
150
	    midcol = (this->objects_.bbox(current_object).pmax()[direction_]
		      - this->objects_.bbox(current_object).pmin()[direction_]) / 2;
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
	  dmax_ = midcol + neighb_max_distance_;
	}


# endif // ! MLN_INCLUDE_ONLY


      } // end of namespace scribo::primitive::link::internal

    } // end of namespace scribo::primitive::link

  } // end of namespace scribo::primitive

} // end of namespace scribo


Guillaume Lazzara's avatar
Guillaume Lazzara committed
167
#endif // SCRIBO_PRIMITIVE_LINK_INTERNAL_LINK_SINGLE_DMAX_BASE_HH_