$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
group_info.hh
1 // Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // 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 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef SCRIBO_CORE_GROUP_INFO_HH
27 # define SCRIBO_CORE_GROUP_INFO_HH
28 
32 
33 # include <mln/util/array.hh>
34 
35 # include <mln/accu/shape/bbox.hh>
36 
37 # include <scribo/core/object_links.hh>
38 # include <scribo/core/component_set.hh>
39 
40 # include <scribo/core/internal/sort_comp_ids.hh>
41 # include <scribo/core/concept/serializable.hh>
42 
43 
44 namespace scribo
45 {
46 
47  using namespace mln;
48 
49  class group_info
50  {
51  public:
52  group_info();
53  group_info(unsigned id, const mln::util::array<component_id_t>& comps,
54  unsigned pixel_area, const box2d& bbox);
55  // used for incremental construction (xml loading).
56  group_info(unsigned id, unsigned pixel_area, const box2d& bbox,
57  bool valid = false);
58 
59  const mln::util::array<component_id_t>& component_ids() const;
60 
61  // Used for incremental construction (xml loading)
62  mln::util::array<component_id_t>& component_ids_();
63 
64  bool is_valid() const;
65  void invalidate();
66 
67  unsigned card() const;
68  unsigned id() const;
69  unsigned pixel_area() const;
70  const box2d& bbox() const;
71 
72  // Merge rhs with this group_info and invalidate rhs afterwards.
73  void merge(group_info& rhs);
74 
75  private:
76  unsigned id_;
78  bool valid_;
79  unsigned pixel_area_;
80  box2d bbox_;
81  };
82 
83  bool operator==(const group_info& lhs, const group_info& rhs);
84 
85 # ifndef MLN_INCLUDE_ONLY
86 
87 
88  inline
89  group_info::group_info()
90  : valid_(false)
91  {
92  }
93 
94  inline
95  group_info::group_info(unsigned id, const mln::util::array<component_id_t>& comps,
96  unsigned pixel_area, const box2d& bbox)
97  : id_(id), comps_(comps), valid_(true),
98  pixel_area_(pixel_area), bbox_(bbox)
99  {
100  }
101 
102  inline
103  group_info::group_info(unsigned id, unsigned pixel_area, const box2d& bbox, bool valid)
104  : id_(id), valid_(valid),
105  pixel_area_(pixel_area), bbox_(bbox)
106  {
107  }
108 
109  inline
111  group_info::component_ids() const
112  {
113  return comps_;
114  }
115 
116  inline
118  group_info::component_ids_()
119  {
120  return comps_;
121  }
122 
123  inline
124  bool group_info::is_valid() const
125  {
126  return valid_;
127  }
128 
129  inline
130  void
131  group_info::invalidate()
132  {
133  valid_ = false;
134  }
135 
136  inline
137  unsigned
138  group_info::card() const
139  {
140  return comps_.nelements();
141  }
142 
143  inline
144  unsigned
145  group_info::id() const
146  {
147  return id_;
148  }
149 
150  inline
151  unsigned
152  group_info::pixel_area() const
153  {
154  return pixel_area_;
155  }
156 
157  inline
158  const box2d&
159  group_info::bbox() const
160  {
161  return bbox_;
162  }
163 
164  inline
165  void
166  group_info::merge(group_info& rhs)
167  {
168  comps_.append(rhs.component_ids());
169  pixel_area_ += rhs.pixel_area();
170 
171  // Update bbox.
173  baccu.take(bbox_);
174  baccu.take(rhs.bbox());
175  bbox_ = baccu.to_result();
176 
177  rhs.invalidate();
178  }
179 
180  inline
181  std::ostream&
182  operator<<(std::ostream& ostr, const group_info& group_info)
183  {
184  ostr << "group_info[";
185 
186  ostr << "id=" << group_info.id() << ", "
187  << "valid=" << group_info.is_valid() << ", "
188  << "pixel_area=" << group_info.pixel_area() << ", "
189  << "bbox=" << group_info.bbox() << ", "
190  << "component_ids=" << group_info.component_ids();
191 
192  ostr << "]";
193 
194  return ostr;
195  }
196 
197  inline
198  bool
199  operator==(const group_info& lhs, const group_info& rhs)
200  {
201  return
202  lhs.id() == rhs.id()
203  && lhs.component_ids() == rhs.component_ids()
204  && lhs.is_valid() == rhs.is_valid()
205  && lhs.pixel_area() == rhs.pixel_area()
206  && lhs.bbox() == rhs.bbox();
207  }
208 
209 
210 # endif // ! MLN_INCLUDE_ONLY
211 
212 
213 } // end of namespace scribo
214 
215 
216 #endif // ! SCRIBO_CORE_GROUP_INFO_HH