SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Box.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 
74 #ifndef SLIP_BOX_HPP
75 #define SLIP_BOX_HPP
76 
77 #include <iostream>
78 #include <cassert>
79 #include <algorithm>
80 #include <string>
81 #include <functional>
82 #include "Block.hpp"
83 
84 #include <boost/serialization/access.hpp>
85 #include <boost/serialization/split_member.hpp>
86 #include <boost/serialization/version.hpp>
87 
88 namespace slip
89 {
90 
91 template <typename CoordType, std::size_t DIM>
92 class Point;
93 
94 template <typename CoordType, std::size_t DIM>
95 class DPoint;
96 
97 template <typename CoordType, std::size_t DIM>
98 class Box;
99 
100 template <typename CoordType, std::size_t DIM>
101 std::ostream& operator<<(std::ostream & out, const Box<CoordType,DIM>& b);
102 
103 
119 template <typename CoordType, std::size_t DIM>
120 class Box
121 {
122 public :
123  typedef CoordType value_type;
124  typedef value_type* boxer;
125  typedef const value_type* const_boxer;
127  typedef const value_type& const_reference;
130  typedef Box<CoordType,DIM> self;
131 
132 
133 
138 
142  Box();
143 
148  Box(const self& other);
149 
150 
156  Box(const point_type& p1,
157  const point_type& p2);
158 
165  std::string name() const;
166 
172  bool contains(const point_type& p) const;
173 
174 
181  void translate(const dpoint_type& dp);
182 
183 
189  bool is_consistent() const;
190 
191 
196  void swap(self& other);
197 
202 
208  friend std::ostream& operator<< <>(std::ostream & out, const self& b);
209 
224  self& operator=(const self & other);
238  bool operator==(const self& other) const;
239 
247  bool operator!=(const self& other) const;
251 protected:
252 
253 
262 
263 protected:
264  friend class boost::serialization::access;
265 template<class Archive>
266  void save(Archive & ar, const unsigned int version) const
267  {
268  ar & p1_;
269  ar & p2_;
270  }
271  template<class Archive>
272  void load(Archive & ar, const unsigned int version)
273  {
274  ar & p1_;
275  ar & p2_;
276  }
277  BOOST_SERIALIZATION_SPLIT_MEMBER()
278  };
279  // end of MiscellaneousContainers group
281 }//slip::
282 
283 namespace slip
284 {
285 
286  template<typename CoordType,std::size_t DIM>
287  inline
289  {}
290 
291  template<typename CoordType,std::size_t DIM>
292  inline
294  p1_(other.p1_),p2_(other.p2_)
295  {}
296 
297  template<typename CoordType,std::size_t DIM>
298  inline
300  const Point<CoordType,DIM>& p2):
301  p1_(p1),p2_(p2)
302  {}
303 
304  template<typename CoordType,std::size_t DIM>
305  inline
307  {
308  if(this != &other)
309  {
310  this->p1_ = other.p1_;
311  this->p2_ = other.p2_;
312  }
313  return *this;
314  }
315 
316  template<typename CoordType,std::size_t DIM>
317  inline
318  std::string
319  Box<CoordType,DIM>::name() const {return "Box";}
320 
321  //TO Optimize : double iteration of coord_ !!
322  template<typename CoordType,std::size_t DIM>
323  inline
325  {
326  assert(this->is_consistent());
327  bool inf = std::lexicographical_compare((p.coord()).begin(),(p.coord()).end(),(p1_.coord()).begin(),(p1_.coord()).end(),std::greater_equal<CoordType>());
328  bool sup = std::lexicographical_compare((p.coord()).begin(),(p.coord()).end(),(p2_.coord()).begin(),(p2_.coord()).end(),std::less_equal<CoordType>());
329  return inf && sup;
330  }
331 
332  template<typename CoordType,std::size_t DIM>
333  inline
335  {
336  this->p1_+=dp;
337  this->p2_+=dp;
338  }
339 
340  template<typename CoordType,std::size_t DIM>
341  inline
343  {
344  dpoint_type diff = this->p2_ - this->p1_;
345  typename slip::block<CoordType,DIM>::const_iterator first_negative = std::find_if((diff.coord()).begin(),(diff.coord()).end(), std::bind2nd(std::less<CoordType>(), CoordType(0)));
346  if(first_negative ==(diff.coord()).end())
347  return 1;
348  return 0;
349  }
350 
351 
352  template<typename CoordType,std::size_t DIM>
353  inline
355  {
356  (this->p1_).swap(other.p1_);
357  (this->p2_).swap(other.p2_);
358  }
359 
360  template<typename CoordType,std::size_t DIM>
361  inline
362  std::ostream& operator<<(std::ostream & out, const Box<CoordType,DIM>& b)
363  {
364  out<<"[ "<<b.p1_<<","<<b.p2_<<" ]";
365  return out;
366  }
367 
368  template<typename CoordType,std::size_t DIM>
369  inline
371  {
372  return (this->p1_ == other.p1_) && (this->p2_ == other.p2_);
373  }
374 
375  template<typename CoordType,std::size_t DIM>
376  inline
378  {
379  return (this->p1_ != other.p1_) || (this->p2_ != other.p2_);
380  }
381 
382 
383 }//slip::
384 
385 #endif //SLIP_BOX_HPP
void load(Archive &ar, const unsigned int version)
Definition: Box.hpp:272
point_type p2_
Definition: Box.hpp:261
const value_type & const_reference
Definition: Box.hpp:127
const block< value_type, DIM > & coord() const
Return the coordinates of the DPoint.
Definition: DPoint.hpp:408
value_type * boxer
Definition: Box.hpp:124
bool operator==(const self &other) const
compare two Box.
Definition: Box.hpp:370
const block< value_type, DIM > & coord() const
Return the coordinates of the Point.
Definition: Point.hpp:446
void save(Archive &ar, const unsigned int version) const
Definition: Box.hpp:266
CoordType value_type
Definition: Box.hpp:123
Define an abstract Point structure.
Definition: Box.hpp:92
Provides a class to manipulate 1d static and generic arrays.
Point< CoordType, DIM > point_type
Definition: Box.hpp:128
value_type & reference
Definition: Box.hpp:126
Box()
Default constructor (protected to avoid default construction)
Definition: Box.hpp:288
Define an abstract DPoint structure.
Definition: Box.hpp:95
bool is_consistent() const
verify if the window is consistent, that is to say if the first point p1 has the smaller coordinates ...
Definition: Box.hpp:342
Define an abstract Box structure.
Definition: Box.hpp:98
bool contains(const point_type &p) const
Returns true if the box contains the point p.
Definition: Box.hpp:324
self & operator=(const self &other)
Assign a Box.
Definition: Box.hpp:306
const value_type * const_boxer
Definition: Box.hpp:125
const_pointer const_iterator
Definition: Block.hpp:157
bool operator!=(const self &other) const
compare two Box.
Definition: Box.hpp:377
DPoint< CoordType, DIM > dpoint_type
Definition: Box.hpp:129
void translate(const dpoint_type &dp)
Translate the window along the deplacement dp the dimensions of the window are conserved.
Definition: Box.hpp:334
void swap(self &other)
Swaps two Box.
Definition: Box.hpp:354
std::string name() const
Returns the name of the class.
Definition: Box.hpp:319
point_type p1_
Definition: Box.hpp:257