SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Box2d.hpp
Go to the documentation of this file.
1 /*
2  * Copyright(c):
3  * Signal Image and Communications (SIC) Department
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * - University of Poitiers, France http://www.univ-poitiers.fr
6  * - XLIM Institute UMR CNRS 7252 http://www.xlim.fr/
7  *
8  * and
9  *
10  * D2 Fluid, Thermic and Combustion
11  * - University of Poitiers, France http://www.univ-poitiers.fr
12  * - PPRIME Institute - UPR CNRS 3346 http://www.pprime.fr
13  * - ISAE-ENSMA http://www.ensma.fr
14  *
15  * Contributor(s):
16  * The SLIP team,
17  * Benoit Tremblais <tremblais_AT_sic.univ-poitiers.fr>,
18  * Laurent David <laurent.david_AT_lea.univ-poitiers.fr>,
19  * Ludovic Chatellier <ludovic.chatellier_AT_univ-poitiers.fr>,
20  * Lionel Thomas <lionel.thomas_AT_univ-poitiers.fr>,
21  * Denis Arrivault <arrivault_AT_sic.univ-poitiers.fr>,
22  * Julien Dombre <julien.dombre_AT_univ-poitiers.fr>.
23  *
24  * Description:
25  * The Simple Library of Image Processing (SLIP) is a new image processing
26  * library. It is written in the C++ language following as much as possible
27  * the ISO/ANSI C++ standard. It is consequently compatible with any system
28  * satisfying the ANSI C++ complience. It works on different Unix , Linux ,
29  * Mircrosoft Windows and Mac OS X plateforms. SLIP is a research library that
30  * was created by the Signal, Image and Communications (SIC) departement of
31  * the XLIM, UMR 7252 CNRS Institute in collaboration with the Fluids, Thermic
32  * and Combustion departement of the P', UPR 3346 CNRS Institute of the
33  * University of Poitiers.
34  *
35  * The SLIP Library source code has been registered to the APP (French Agency
36  * for the Protection of Programs) by the University of Poitiers and CNRS,
37  * under registration number IDDN.FR.001.300034.000.S.P.2010.000.21000.
38 
39  * http://www.sic.sp2mi.univ-poitiers.fr/slip/
40  *
41  * This software is governed by the CeCILL-C license under French law and
42  * abiding by the rules of distribution of free software. You can use,
43  * modify and/ or redistribute the software under the terms of the CeCILL-C
44  * license as circulated by CEA, CNRS and INRIA at the following URL
45  * http://www.cecill.info.
46  * As a counterpart to the access to the source code and rights to copy,
47  * modify and redistribute granted by the license, users are provided only
48  * with a limited warranty and the software's author, the holder of the
49  * economic rights, and the successive licensors have only limited
50  * liability.
51  *
52  * In this respect, the user's attention is drawn to the risks associated
53  * with loading, using, modifying and/or developing or reproducing the
54  * software by the user in light of its specific status of free software,
55  * that may mean that it is complicated to manipulate, and that also
56  * therefore means that it is reserved for developers and experienced
57  * professionals having in-depth computer knowledge. Users are therefore
58  * encouraged to load and test the software's suitability as regards their
59  * requirements in conditions enabling the security of their systems and/or
60  * data to be ensured and, more generally, to use and operate it in the
61  * same conditions as regards security.
62  *
63  * The fact that you are presently reading this means that you have had
64  * knowledge of the CeCILL-C license and that you accept its terms.
65  */
66 
67 
68 
75 #ifndef SLIP_BOX2D_HPP
76 #define SLIP_BOX2D_HPP
77 
78 #include <iostream>
79 #include <cassert>
80 #include <string>
81 #include "Box.hpp"
82 #include "Point2d.hpp"
83 #include "DPoint2d.hpp"
84 
85 #include <boost/serialization/access.hpp>
86 #include <boost/serialization/split_member.hpp>
87 #include <boost/serialization/version.hpp>
88 
89 namespace slip
90 {
91 
92 
115  template <typename CoordType>
116  class Box2d: public Box<CoordType,2>
117  {
118  public :
119  typedef Box2d<CoordType> self;
121 
130  Box2d();
131 
137  Box2d(const Point<CoordType,2>& p1,
138  const Point<CoordType,2>& p2);
139 
147  Box2d(const CoordType& x11,
148  const CoordType& x12,
149  const CoordType& x21,
150  const CoordType& x22);
151 
158  Box2d(const CoordType& xc,
159  const CoordType& yc,
160  const CoordType& w);
161 
167  Box2d(const Point<CoordType,2>& pc,
168  const CoordType& w);
169 
176  Box2d(const Point<CoordType,2>& pc,
177  const CoordType& w1,
178  const CoordType& w2);
179 
200  const Point<CoordType,2>& upper_left() const;
201 
202 
217  const Point<CoordType,2>& bottom_right() const;
218 
227  void set_coord(const CoordType& x11,
228  const CoordType& x12,
229  const CoordType& x21,
230  const CoordType& x22);
238  std::string name() const;
239 
244  CoordType area() const;
245 
250  CoordType width() const;
251 
256  CoordType height() const;
257 
258  private:
259  friend class boost::serialization::access;
260  template<class Archive>
261  void save(Archive & ar, const unsigned int version) const
262  {
263  ar & boost::serialization::base_object<slip::Box<CoordType,2> >(*this);
264  }
265  template<class Archive>
266  void load(Archive & ar, const unsigned int version)
267  {
268  ar & boost::serialization::base_object<slip::Box<CoordType,2> >(*this);
269  }
270  BOOST_SERIALIZATION_SPLIT_MEMBER()
271  };
272 }//slip::
273 
274 namespace slip
275 {
276  template<typename CoordType>
277  inline
279  Box<CoordType,2>()
280  {}
281 
282  template<typename CoordType>
283  inline
285  const Point<CoordType,2>& p2):
286  Box<CoordType,2>(p1,p2)
287  {}
288 
289  template<typename CoordType>
290  inline
291  Box2d<CoordType>::Box2d(const CoordType& x11,
292  const CoordType& x12,
293  const CoordType& x21,
294  const CoordType& x22):
295  Box<CoordType,2>(Point2d<CoordType>(x11,x12),Point2d<CoordType>(x21,x22))
296  {}
297 
298  template<typename CoordType>
299  inline
300  Box2d<CoordType>::Box2d(const CoordType& xc,
301  const CoordType& yc,
302  const CoordType& w):
303  Box<CoordType,2>(Point2d<CoordType>(xc-w,yc-w),Point2d<CoordType>(xc+w,yc+w))
304  {}
305 
306  template<typename CoordType>
307  inline
309  const CoordType& w):
310  Box<CoordType,2>(Point2d<CoordType>(pc[0]-w,pc[1]-w),Point2d<CoordType>(pc[0]+w,pc[1]+w))
311  {}
312 
313 
314  template<typename CoordType>
315  inline
317  const CoordType& w1,
318  const CoordType& w2):
319  Box<CoordType,2>(Point2d<CoordType>(pc[0]-w1,pc[1]-w2),Point2d<CoordType>(pc[0]+w1,pc[1]+w2))
320  {}
321 
322 
323  template<typename CoordType>
324  inline
326 
327  template<typename CoordType>
328  inline
330 
331  template<typename CoordType>
332  inline
333  const Point<CoordType,2>& Box2d<CoordType>::upper_left() const {return this->p1_;}
334 
335 
336  template<typename CoordType>
337  inline
339 
340  template<typename CoordType>
341  inline
343 
344  template<typename CoordType>
345  inline
346  const Point<CoordType,2>& Box2d<CoordType>::bottom_right() const {return this->p2_;}
347 
348 
349  template<typename CoordType>
350  inline
351  void Box2d<CoordType>::set_coord(const CoordType& x11,
352  const CoordType& x12,
353  const CoordType& x21,
354  const CoordType& x22)
355  {
356  this->p1_[0] = x11;
357  this->p1_[1] = x12;
358  this->p2_[0] = x21;
359  this->p2_[1] = x22;
360  }
361 
362  template<typename T>
363  inline
364  std::string
365  Box2d<T>::name() const {return "Box2d";}
366 
367 
368  template<typename CoordType>
369  inline
370  CoordType Box2d<CoordType>::area() const {return width() * height();}
371 
372  template<typename CoordType>
373  inline
374  CoordType Box2d<CoordType>::width() const {return (this->p2_[1] - this->p1_[1]+1);}
375 
376  template<typename CoordType>
377  inline
378  CoordType Box2d<CoordType>::height() const {return (this->p2_[0] - this->p1_[0]+1);}
379 
380 }//slip::
381 
382 #endif //SLIP_BOX2D_HPP
void set_coord(const CoordType &x11, const CoordType &x12, const CoordType &x21, const CoordType &x22)
Mutator of the coordinates of the Box2d.
Definition: Box2d.hpp:351
Provides a class to modelize the difference of slip::Point2d.
CoordType height() const
compute the height of the Box2d.
Definition: Box2d.hpp:378
Box2d()
Constructs a Box2d.
Definition: Box2d.hpp:278
CoordType width() const
compute the width of the Box2d.
Definition: Box2d.hpp:374
Provides an abstract class to manipulate nd box.
Point< CoordType, 2 > & upper_left()
Accessor/Mutator of the upper_left point (p1) of Box2d.
Definition: Box2d.hpp:329
This is a Box2d class, a specialized version of slip::Box<CoordType,DIM> with DIM = 2...
Definition: Box2d.hpp:116
This is a point2d class, a specialized version of Point<CoordType,DIM> with DIM = 2...
Definition: Array2d.hpp:132
CoordType area() const
compute the area of the Box2d.
Definition: Box2d.hpp:370
Point< CoordType, 2 > & bottom_right()
Accessor/Mutator of the bottom_right point (p2) of Box2d.
Definition: Box2d.hpp:342
Define an abstract Box structure.
Definition: Box.hpp:98
Provides a class to modelize 2d points.
std::string name() const
Returns the name of the class.
Definition: Box2d.hpp:365
Box< CoordType, 2 > base
Definition: Box2d.hpp:120