SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Point.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 
73 #ifndef SLIP_POINT_HPP
74 #define SLIP_POINT_HPP
75 
76 #include <iostream>
77 #include <cassert>
78 #include <algorithm>
79 #include "Block.hpp"
80 
81 #include <boost/serialization/access.hpp>
82 #include <boost/serialization/split_member.hpp>
83 #include <boost/serialization/complex.hpp>
84 #include <boost/serialization/version.hpp>
85 namespace slip
86 {
87 
88 template <typename CoordType, std::size_t DIM>
89 class DPoint;
90 
91 template <typename CoordType, std::size_t DIM>
92 class Point;
93 
94 template <typename CoordType, std::size_t DIM>
95 std::ostream& operator<<(std::ostream & out, const Point<CoordType,DIM>& p);
96 
108 template <typename CoordType, std::size_t DIM>
109 class Point
110 {
111 public :
112  typedef CoordType value_type;
113  typedef value_type* pointer;
114  typedef const value_type* const_pointer;
116  typedef const value_type& const_reference;
117 
118 
120  typedef Point<CoordType,DIM> self;
121 
122  //default iterator_category of the container
123  typedef std::random_access_iterator_tag iterator_category;
124 
125  static const std::size_t SIZE = DIM;
133  Point();
134 
139  Point(const self& other);
140 
141 
146  Point(const CoordType* array);
147 
160  friend std::ostream& operator<< <>(std::ostream & out, const self& p);
161 
176  self& operator=(const self & other);
177 
178 
191  reference operator[](const std::size_t i);
192 
199  const_reference operator[](const std::size_t i) const;
200 
214  bool operator==(const self& other) const;
215 
223  bool operator!=(const self& other) const;
234  self operator-() const;
235 
236 
248  self& operator+=(const dpoint_type & dp);
249 
257  self operator+(const dpoint_type & dp) const;
258 
259 
267  self& operator-=(const dpoint_type & dp);
268 
269 
277  self operator-(const dpoint_type & dp) const;
278 
286  dpoint_type operator-(const self & other) const;
287 
294  std::size_t dim() const;
295 
300  std::size_t size() const;
301 
306  std::size_t max_size() const;
307 
312  bool empty()const;
313 
314 
315 
319  const block<value_type,DIM>& coord() const;
320 
325 
326 
327 
332  void swap(self& other);
333 
334 protected:
339 
340 
341 
348 
349 protected:
350 friend class boost::serialization::access;
351  template<class Archive>
352  void save(Archive & ar, const unsigned int version) const
353  {
354  ar & coord_;
355  }
356  template<class Archive>
357  void load(Archive & ar, const unsigned int version)
358  {
359  ar & coord_;
360  }
361  BOOST_SERIALIZATION_SPLIT_MEMBER()
362 
363  };
364 }//slip::
365 
366 namespace slip
367 {
368 
369  template<typename CoordType,std::size_t DIM>
370  inline
372  {
373  std::fill_n((this->coord_).begin(),DIM,CoordType());
374  }
375 
376  template<typename CoordType,std::size_t DIM>
377  inline
379  coord_(other.coord_)
380  {}
381 
382  template<typename CoordType,std::size_t DIM>
383  inline
384  Point<CoordType,DIM>::Point(const CoordType* array)
385  {
386  std::copy(array,array+DIM,coord_.begin());
387  }
388 
389  template<typename CoordType,std::size_t DIM>
390  inline
391  std::ostream& operator<<(std::ostream & out,
392  const Point<CoordType,DIM>& p)
393  {
394  out<<p.coord_;
395  return out;
396  }
397 
398 
399  template<typename CoordType,std::size_t DIM>
400  inline
402  {
403  if(this != &other)
404  {
405  this->coord_ = other.coord_;
406  }
407  return *this;
408  }
409 
410 
411  template<typename CoordType,std::size_t DIM>
412  inline
413  CoordType& Point<CoordType,DIM>::operator[](const std::size_t i)
414  {
415  assert(i < DIM);
416  return this->coord_[i];
417  }
418 
419  template<typename CoordType,std::size_t DIM>
420  inline
421  const CoordType& Point<CoordType,DIM>::operator[](const std::size_t i) const
422  {
423  assert(i < DIM);
424  return this->coord_[i];
425  }
426 
427  template<typename CoordType,std::size_t DIM>
428  inline
429  std::size_t Point<CoordType,DIM>::dim() const {return DIM;}
430 
431  template<typename CoordType,std::size_t DIM>
432  inline
433  std::size_t Point<CoordType,DIM>::size() const {return DIM;}
434 
435  template<typename CoordType,std::size_t DIM>
436  inline
437  std::size_t Point<CoordType,DIM>::max_size() const {return DIM;}
438 
439  template<typename CoordType,std::size_t DIM>
440  inline
441  bool Point<CoordType,DIM>::empty()const {return coord_.empty();}
442 
443 
444  template<typename CoordType,std::size_t DIM>
445  inline
447  {
448  return coord_;
449  }
450 
451  template<typename CoordType,std::size_t DIM>
452  inline
454  {
455  return coord_;
456  }
457 
458  template<typename CoordType,std::size_t DIM>
459  inline
461  {
462  (this->coord_).swap(other.coord_);
463  }
464 
465 
466  template<typename CoordType,std::size_t DIM>
467  inline
469  {
470  return this->coord_ == other.coord_;
471  }
472 
473  template<typename CoordType,std::size_t DIM>
474  inline
476  {
477  return this->coord_ != other.coord_;
478  }
479 
480 
481  template<typename CoordType,std::size_t DIM>
482  inline
484  {
486  std::transform(coord_.begin(),coord_.end(),(tmp.coord_).begin(),std::negate<CoordType>());
487  return tmp;
488  }
489 
490  template<typename CoordType,std::size_t DIM>
491  inline
493  {
494 
495  for(std::size_t i = 0; i < DIM; ++i)
496  {
497  this->coord_[i] += dp[i];
498  }
499  return *this;
500  }
501 
502 
503  template<typename CoordType,std::size_t DIM>
504  inline
506  {
507  Point<CoordType,DIM> tmp(*this);
508  tmp+=dp;
509  return tmp;
510  }
511 
512  template<typename CoordType,std::size_t DIM>
513  inline
515  {
516 
517  for(std::size_t i = 0; i < DIM; ++i)
518  {
519  this->coord_[i] -= dp[i];
520  }
521  return *this;
522  }
523 
524  template<typename CoordType,std::size_t DIM>
525  inline
527  {
528  Point<CoordType,DIM> tmp(*this);
529  tmp-=dp;
530  return tmp;
531  }
532 
533  template<typename CoordType,std::size_t DIM>
534  inline
536  {
538  std::transform(coord_.begin(),coord_.end(),(p.coord_).begin(),tmp.begin(),std::minus<CoordType>());
539  return DPoint<CoordType,DIM>(tmp.begin());
540  }
541 
542 }//slip::
543 
544 #endif //SLIP_POINT_HPP
iterator begin()
Returns a read/write iterator that points to the first element in the block. Iteration is done in ord...
Definition: Block.hpp:189
Point()
Default constructor.
Definition: Point.hpp:371
self & operator+=(const dpoint_type &dp)
Assign a Point to this point plus a deplacement.
Definition: Point.hpp:492
std::random_access_iterator_tag iterator_category
Definition: Point.hpp:123
value_type & reference
Definition: Point.hpp:115
DPoint< CoordType, DIM > dpoint_type
Definition: Point.hpp:119
const value_type & const_reference
Definition: Point.hpp:116
const value_type * const_pointer
Definition: Point.hpp:114
block< value_type, DIM > coord_
The coordinates of the point are stored in this block.
Definition: Point.hpp:347
void load(Archive &ar, const unsigned int version)
Definition: Point.hpp:357
const block< value_type, DIM > & coord() const
Return the coordinates of the Point.
Definition: Point.hpp:446
self & operator=(const self &other)
Assign a Point.
Definition: Point.hpp:401
bool operator!=(const self &other) const
compare two Point.
Definition: Point.hpp:475
CoordType value_type
Definition: Point.hpp:112
Define an abstract Point structure.
Definition: Box.hpp:92
self & operator-=(const dpoint_type &dp)
Assign a Point to this point minus a deplacement.
Definition: Point.hpp:514
value_type * pointer
Definition: Point.hpp:113
Provides a class to manipulate 1d static and generic arrays.
static const std::size_t SIZE
Definition: Point.hpp:125
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 save(Archive &ar, const unsigned int version) const
Definition: Point.hpp:352
std::ostream & operator<<(std::ostream &out, const Array< T > &a)
Definition: Array.hpp:1282
reference operator[](const std::size_t i)
Returns the i'th coordinate of the Point.
Definition: Point.hpp:413
std::size_t dim() const
Returns the dimension of the Point.
Definition: Point.hpp:429
self operator-() const
negate all the coordinates of a Point
Definition: Point.hpp:483
bool empty() const
Returns true if dimension of the Point is 0.
Definition: Point.hpp:441
std::size_t max_size() const
Returns the maximal size of the Point.
Definition: Point.hpp:437
bool operator==(const self &other) const
compare two Point.
Definition: Point.hpp:468
self operator+(const dpoint_type &dp) const
translate a point considering the deplacement a dp
Definition: Point.hpp:505
std::size_t size() const
Returns the dimension of the Point.
Definition: Point.hpp:433
void swap(self &other)
Swaps two Point.
Definition: Point.hpp:460