$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
component_info.hh
1 // Copyright (C) 2009, 2010, 2011, 2013 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef SCRIBO_CORE_COMPONENT_INFO_HH
28 # define SCRIBO_CORE_COMPONENT_INFO_HH
29 
33 
34 
35 # include <mln/core/alias/box2d.hh>
36 # include <mln/core/alias/point2d.hh>
37 # include <mln/util/object_id.hh>
38 
39 # include <scribo/core/component_features_data.hh>
40 # include <scribo/core/concept/serializable.hh>
41 # include <scribo/core/tag/component.hh>
42 # include <scribo/core/tag/line.hh>
43 
44 namespace scribo
45 {
46 
47  // Forward declarations.
48  template <typename L> class component_set;
49 
58 
59 
63  template <typename L>
64  class component_info : public Serializable<component_info<L> >
65  {
67 
68  public:
71  const mln::box2d& bbox,
72  const mln::point2d& mass_center,
73  unsigned card,
75 
76  component_id_t id() const;
77  const mln::box2d& bbox() const;
78  const mln::point2d& mass_center() const;
79 
80  // The number of pixels in this component.
81  unsigned card() const;
82 
83 
84  bool has_features() const;
85  void update_features(const component_features_data& features);
86 
87  const component_features_data& features() const;
88 
89 
90  component::Tag tag() const;
91  void update_tag(component::Tag tag);
92 
93  component::Type type() const;
94  void update_type(component::Type type);
95 
96  bool is_valid() const;
97 
98  protected:
99  component_id_t id_;
100  mln::box2d bbox_;
101  mln::point2d mass_center_;
102  unsigned card_;
103 
104  component_features_data features_;
105 
106  component::Tag tag_;
107  component::Type type_;
108  };
109 
110 
111 
112  template <typename L>
113  std::ostream&
114  operator<<(std::ostream& ostr, const component_info<L>& info);
115 
116  template <typename L>
117  bool
118  operator==(const component_info<L>& lhs, const component_info<L>& rhs);
119 
120 
121 # ifndef MLN_INCLUDE_ONLY
122 
123 
124  template <typename L>
126  : id_(0), tag_(component::Ignored), type_(component::Undefined)
127  {
128 
129  }
130 
131 
132  template <typename L>
133  component_info<L>::component_info(const component_id_t& id,
134  const mln::box2d& bbox,
135  const mln::point2d& mass_center,
136  unsigned card,
137  component::Type type)
138  : id_(id), bbox_(bbox), mass_center_(mass_center), card_(card),
139  type_(type)
140  {
141  if (!bbox.is_valid())
142  tag_ = component::Ignored;
143  else
144  tag_ = component::None;
145  }
146 
147 
148  template <typename L>
149  typename component_info<L>::component_id_t
150  component_info<L>::id() const
151  {
152  return id_;
153  }
154 
155 
156  template <typename L>
157  const mln::box2d&
159  {
160  return bbox_;
161  }
162 
163 
164  template <typename L>
165  const mln::point2d&
166  component_info<L>::mass_center() const
167  {
168  return mass_center_;
169  }
170 
171  template <typename L>
172  unsigned
173  component_info<L>::card() const
174  {
175  return card_;
176  }
177 
178  template <typename L>
179  bool
180  component_info<L>::has_features() const
181  {
182  return features_.valid;
183  }
184 
185  template <typename L>
186  void
187  component_info<L>::update_features(const component_features_data& features)
188  {
189  features_ = features;
190  }
191 
192  template <typename L>
193  const component_features_data&
194  component_info<L>::features() const
195  {
196  return features_;
197  }
198 
199  template <typename L>
201  component_info<L>::tag() const
202  {
203  return tag_;
204  }
205 
206 
207  template <typename L>
208  void
209  component_info<L>::update_tag(component::Tag tag)
210  {
211  tag_ = tag;
212  }
213 
214 
215  template <typename L>
217  component_info<L>::type() const
218  {
219  return type_;
220  }
221 
222 
223  template <typename L>
224  void
225  component_info<L>::update_type(component::Type type)
226  {
227  type_ = type;
228  }
229 
230 
231  template <typename L>
232  bool
233  component_info<L>::is_valid() const
234  {
235  return tag_ != component::Ignored && bbox_.is_valid();
236  }
237 
238 
239 
240  template <typename L>
241  std::ostream&
242  operator<<(std::ostream& ostr, const component_info<L>& info)
243  {
244  ostr << "component_info("
245  << "id=" << info.id()
246  << ", bbox=" << info.bbox()
247  << ", mass_center=" << info.mass_center()
248  << ", card=" << info.card()
249  << ", tag=" << info.tag();
250 
251  if (info.features().valid)
252  ostr << ", features=" << info.features();
253  else
254  ostr << ", features=none";
255 
256  ostr << ")" << std::endl;
257 
258  return ostr;
259  }
260 
261  template <typename L>
262  bool
263  operator==(const component_info<L>& lhs, const component_info<L>& rhs)
264  {
265 
266  return
267  lhs.id() == rhs.id()
268  && lhs.bbox() == rhs.bbox()
269  && lhs.mass_center() == rhs.mass_center()
270  && lhs.card() == rhs.card()
271  && (lhs.has_features() == rhs.has_features()
272  || (lhs.has_features()
273  && rhs.has_features()
274  && lhs.features() == rhs.features()))
275  && lhs.tag() == rhs.tag()
276  && lhs.type() == rhs.type();
277  }
278 
279 # endif // ! MLN_INCLUDE_ONLY
280 
281 
282 } // end of namespace scribo
283 
284 
285 #endif // ! SCRIBO_CORE_COMPONENT_INFO_HH