SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DPoint.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_DPOINT_HPP
76 #define SLIP_DPOINT_HPP
77 
78 #include <iostream>
79 #include <cassert>
80 #include <algorithm>
81 #include "Block.hpp"
82 
83 #include <boost/serialization/access.hpp>
84 #include <boost/serialization/split_member.hpp>
85 #include <boost/serialization/complex.hpp>
86 #include <boost/serialization/version.hpp>
87 
88 namespace slip
89 {
90 
91 template <typename CoordType, std::size_t DIM>
92 class DPoint;
93 
94 template <typename CoordType, std::size_t DIM>
95 std::ostream& operator<<(std::ostream & out, const DPoint<CoordType,DIM>& p);
96 
97 
108 template <typename CoordType, std::size_t DIM>
109 class DPoint
110 {
111 public :
112  typedef CoordType value_type;
114  typedef const value_type* const_dpointer;
116  typedef const value_type& const_reference;
117 
118  typedef DPoint<CoordType,DIM> self;
119 
120  //default iterator_category of the container
121  typedef std::random_access_iterator_tag iterator_category;
122 
123 
128 
133  DPoint(const self& other);
134 
135 
140  DPoint(const CoordType* array);
152  friend std::ostream& operator<< <>(std::ostream & out, const self& p);
167  self& operator=(const self & other);
174 
181  reference operator[](const std::size_t i);
182 
189  const_reference operator[](const std::size_t i) const;
190 
205  bool operator==(const self& other) const;
206 
214  bool operator!=(const self& other) const;
215 
228  self operator-() const;
229 
230 
237  self& operator+=(const self& other);
238 
245  self operator+(const self& other) const;
246 
247 
254  self& operator-=(const self& other);
255 
262  self operator-(const self& other) const;
270  std::size_t dim() const;
271 
276  std::size_t size() const;
277 
282  std::size_t max_size() const;
283 
288  bool empty()const;
289 
293  const block<value_type,DIM>& coord() const;
294 
299  void swap(self& other);
300 
301 
302 
303 
304 protected:
309 
313  DPoint();
314 
322 
323  protected:
324 friend class boost::serialization::access;
325  template<class Archive>
326  void save(Archive & ar, const unsigned int version) const
327  {
328  ar & coord_;
329  }
330  template<class Archive>
331  void load(Archive & ar, const unsigned int version)
332  {
333  ar & coord_;
334  }
335  BOOST_SERIALIZATION_SPLIT_MEMBER()
336 
337 
338  };
339 }//slip::
340 
341 namespace slip
342 {
343 
344  template<typename CoordType,std::size_t DIM>
345  inline
347  {}
348 
349  template<typename CoordType,std::size_t DIM>
350  inline
352  coord_(other.coord_)
353  {}
354 
355  template<typename CoordType,std::size_t DIM>
356  inline
357  DPoint<CoordType,DIM>::DPoint(const CoordType* array)
358  {
359  std::copy(array,array+DIM,coord_.begin());
360  }
361 
362  template<typename CoordType,std::size_t DIM>
363  inline
365  {
366  if(this != &other)
367  {
368  this->coord_ = other.coord_;
369  }
370  return *this;
371  }
372 
373 
374  template<typename CoordType,std::size_t DIM>
375  inline
376  CoordType& DPoint<CoordType,DIM>::operator[](const std::size_t i)
377  {
378  assert(i < DIM);
379  return this->coord_[i];
380  }
381 
382  template<typename CoordType,std::size_t DIM>
383  inline
384  const CoordType& DPoint<CoordType,DIM>::operator[](const std::size_t i) const
385  {
386  assert(i < DIM);
387  return this->coord_[i];
388  }
389 
390  template<typename CoordType,std::size_t DIM>
391  inline
392  std::size_t DPoint<CoordType,DIM>::dim() const {return DIM;}
393 
394  template<typename CoordType,std::size_t DIM>
395  inline
396  std::size_t DPoint<CoordType,DIM>::size() const {return DIM;}
397 
398  template<typename CoordType,std::size_t DIM>
399  inline
400  std::size_t DPoint<CoordType,DIM>::max_size() const {return DIM;}
401 
402  template<typename CoordType,std::size_t DIM>
403  inline
404  bool DPoint<CoordType,DIM>::empty()const {return coord_.empty();}
405 
406  template<typename CoordType,std::size_t DIM>
407  inline
409  {
410  return coord_;
411  }
412 
413  template<typename CoordType,std::size_t DIM>
414  inline
416  {
417  (this->coord_).swap(other.coord_);
418  }
419 
420  template<typename CoordType,std::size_t DIM>
421  inline
422  std::ostream& operator<<(std::ostream & out,
423  const DPoint<CoordType,DIM>& p)
424  {
425  out<<p.coord_;
426  return out;
427  }
428 
429  template<typename CoordType,std::size_t DIM>
430  inline
432  {
433  return this->coord_ == other.coord_;
434  }
435 
436  template<typename CoordType,std::size_t DIM>
437  inline
439  {
440  return this->coord_ != other.coord_;
441  }
442 
443  template<typename CoordType,std::size_t DIM>
444  inline
446  {
448  std::transform(coord_.begin(),coord_.end(),(tmp.coord_).begin(),std::negate<CoordType>());
449  return tmp;
450  }
451 
452 
453  template<typename CoordType,std::size_t DIM>
454  inline
456  {
457  for(std::size_t i = 0; i < DIM; ++i)
458  {
459  (this->coord_)[i] += (other.coord_)[i];
460  }
461  return *this;
462  }
463 
464  template<typename CoordType,std::size_t DIM>
465  inline
467  {
468  DPoint<CoordType,DIM> tmp(*this);
469 
470  return tmp+=other;
471  }
472 
473  template<typename CoordType,std::size_t DIM>
474  inline
476  {
477  for(std::size_t i = 0; i < DIM; ++i)
478  {
479  (this->coord_)[i] -= (other.coord_)[i];
480  }
481  return *this;
482  }
483 
484  template<typename CoordType,std::size_t DIM>
485  inline
487  {
488  DPoint<CoordType,DIM> tmp(*this);
489 
490  return tmp-=other;
491  }
492 
493 
494 }//slip::
495 
496 #endif //SLIP_DPOINT_HPP
std::size_t size() const
Returns the dimension of the DPoint.
Definition: DPoint.hpp:396
std::size_t max_size() const
Returns the maximal size of the DPoint.
Definition: DPoint.hpp:400
reference operator[](const std::size_t i)
Returns the i'th coordinate of the DPoint.
Definition: DPoint.hpp:376
const block< value_type, DIM > & coord() const
Return the coordinates of the DPoint.
Definition: DPoint.hpp:408
DPoint()
Default constructor (protected to avoid default construction)
Definition: DPoint.hpp:346
const value_type * const_dpointer
Definition: DPoint.hpp:114
value_type & reference
Definition: DPoint.hpp:115
void save(Archive &ar, const unsigned int version) const
Definition: DPoint.hpp:326
self operator+(const self &other) const
add the coordinates of a two DPoint
Definition: DPoint.hpp:466
Provides a class to manipulate 1d static and generic arrays.
bool empty() const
Returns true if dimension of the DPoint is 0.
Definition: DPoint.hpp:404
value_type * dpointer
Definition: DPoint.hpp:113
std::random_access_iterator_tag iterator_category
Definition: DPoint.hpp:121
std::size_t dim() const
Returns the dimension of the DPoint.
Definition: DPoint.hpp:392
bool operator!=(const self &other) const
compare two DPoint.
Definition: DPoint.hpp:438
Define an abstract DPoint structure.
Definition: Box.hpp:95
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
Definition: copy_ext.hpp:177
void swap(self &other)
Swaps two DPoint.
Definition: DPoint.hpp:415
CoordType value_type
Definition: DPoint.hpp:112
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
Definition: Array.hpp:1282
const value_type & const_reference
Definition: DPoint.hpp:116
block< value_type, DIM > coord_
The coordinates of the dpoint are stored in this block.
Definition: DPoint.hpp:321
self & operator+=(const self &other)
add the coordinates of a DPoint to the DPoint
Definition: DPoint.hpp:455
void load(Archive &ar, const unsigned int version)
Definition: DPoint.hpp:331
self & operator=(const self &other)
Assign a DPoint.
Definition: DPoint.hpp:364
self operator-() const
negate all the coordinates of a DPoint
Definition: DPoint.hpp:445
bool operator==(const self &other) const
compare two DPoint.
Definition: DPoint.hpp:431
self & operator-=(const self &other)
substract the coordinates of a DPoint to the DPoint
Definition: DPoint.hpp:475