SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Block3d.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_BLOCK3D_HPP
76 #define SLIP_BLOCK3D_HPP
77 
78 #include <iostream>
79 #include <iterator>
80 #include <cassert>
81 #include <cstddef>
82 #include <string>
83 #include "Block2d.hpp"
84 
85 
86 #include <boost/serialization/access.hpp>
87 #include <boost/serialization/split_member.hpp>
88 #include <boost/serialization/string.hpp>
89 #include <boost/serialization/complex.hpp>
90 #include <boost/serialization/version.hpp>
91 
92 namespace slip
93 {
94 
95 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
96 struct block3d;
97 
98 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
99 std::ostream& operator<<(std::ostream & out,const slip::block3d<T,NP,NR,NC>& b);
100 
101 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
103 
104 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
106 
107 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
108 bool operator<(const slip::block3d<T,NP,NR,NC>& x, const slip::block3d<T,NP,NR,NC>& y);
109 
110 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
112 
113 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
114 bool operator<=(const slip::block3d<T,NP,NR,NC>& x, const slip::block3d<T,NP,NR,NC>& y);
115 
116 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
118 
138 template <typename T, std::size_t NP, std::size_t NR, std::size_t NC>
139 struct block3d
140 {
141  typedef T value_type;
142  typedef value_type* pointer;
143  typedef const value_type* const_pointer;
145  typedef const value_type& const_reference;
146 
147  typedef ptrdiff_t difference_type;
148  typedef std::size_t size_type;
149 
150  typedef pointer iterator;
152 
153  typedef std::reverse_iterator<iterator> reverse_iterator;
154  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
155 
156  //default iterator_category of the container
158 
159  //constants
160  static const std::size_t SIZE = NP * NR * NC;
161  static const std::size_t DIM = 3;
162 
163 
164  iterator begin();
165  iterator end();
166 
167  const_iterator begin() const;
168  const_iterator end() const;
169 
172 
175 
180  void fill(const T& val);
181 
186  void fill(const T* val);
187 
192 
198  friend std::ostream& operator<< <>(std::ostream & out,const slip::block3d<T,NP,NR,NC>& b);
199 
207  friend bool operator== <>(const slip::block3d<T,NP,NR,NC>& x, const slip::block3d<T,NP,NR,NC>& y);
208 
216  friend bool operator!= <>(const slip::block3d<T,NP,NR,NC>& x, const slip::block3d<T,NP,NR,NC>& y);
217 
225  friend bool operator< <>(const slip::block3d<T,NP,NR,NC>& x, const slip::block3d<T,NP,NR,NC>& y);
226 
234  friend bool operator> <>(const slip::block3d<T,NP,NR,NC>& x, const slip::block3d<T,NP,NR,NC>& y);
235 
243  friend bool operator<= <>(const slip::block3d<T,NP,NR,NC>& x, const slip::block3d<T,NP,NR,NC>& y);
244 
252  friend bool operator>= <>(const slip::block3d<T,NP,NR,NC>& x, const slip::block3d<T,NP,NR,NC>& y);
253 
254 
261  slip::block2d<T,NR, NC>& operator[](const std::size_t i);
262 
269  const slip::block2d<T,NR, NC>& operator[](const std::size_t i) const;
270 
271 
282  T* operator()(const std::size_t i,
283  const std::size_t j);
294  const T* operator()(const std::size_t i,
295  const std::size_t j) const;
296 
309  T& operator()(const std::size_t i,
310  const std::size_t j,
311  const std::size_t k);
324  const T& operator()(const std::size_t i,
325  const std::size_t j,
326  const std::size_t k) const;
327 
335  std::string name() const { return "block3d";}
336 
338  static std::size_t dim() {return SIZE;}
340  static std::size_t dim1() {return NP;}
342  static std::size_t dim2() {return NR;}
344  static std::size_t dim3() {return NC;}
346  static std::size_t size() {return SIZE;}
348  static std::size_t size_max() {return SIZE;}
350  static bool empty(){return SIZE == 0;}
351 
356  void swap(block3d<T,NP,NR,NC>& M);
357 
359  //void print() const;
360 
362 
363 
364 private:
366  template<class Archive>
367  void save(Archive & ar, const unsigned int version) const
368  {
369  ar & data;
370  }
371  template<class Archive>
372  void load(Archive & ar, const unsigned int version)
373  {
374  ar & data;
375  }
376 
377  BOOST_SERIALIZATION_SPLIT_MEMBER()
378 };
379 }//slip::
380 
381 namespace slip
382 {
383  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
384  inline
386  {
387  return data[0].begin();
388  }
389 
390  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
391  inline
393  {
394  return data[NP-1].end();
395  }
396 
397  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
398  inline
399  const T* block3d<T,NP,NR,NC>::begin() const
400  {
401  return data[0].begin();
402  }
403 
404  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
405  inline
406  const T* block3d<T,NP,NR,NC>::end() const
407  {
408  return data[NP-1].end();
409  }
410 
411 
412  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
413  inline
414  std::reverse_iterator<T*> block3d<T,NP,NR,NC>::rbegin()
415  {
416  return std::reverse_iterator<T*>(end());
417  }
418 
419  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
420  inline
421  std::reverse_iterator<T*> block3d<T,NP,NR,NC>::rend()
422  {
423  return std::reverse_iterator<T*>(begin());
424  }
425 
426  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
427  inline
428  std::reverse_iterator<const T*> block3d<T,NP,NR,NC>::rbegin() const
429  {
430  return std::reverse_iterator<const T*>(end());
431  }
432 
433  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
434  inline
435  std::reverse_iterator<const T*> block3d<T,NP,NR,NC>::rend() const
436  {
437  return std::reverse_iterator<const T*>(begin());
438  }
439 
440  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
441  inline
443  {
444  assert(i < NP);
445  return data[i];
446  }
447 
448  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
449  inline
450  const block2d<T,NR,NC>& block3d<T,NP,NR,NC>::operator[](const std::size_t i) const
451  {
452  assert(i < NP);
453  return data[i];
454  }
456  /* @{ */
457  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
458  inline
459  std::ostream& operator<<(std::ostream & out,const block3d<T,NP,NR,NC>& b)
460  {
461 
462  for(std::size_t i = 0; i < NP; ++i)
463  {
464  out << std::endl << "------------PLAN "<<i<<" ---------------" << std::endl<<b.data[i];
465  }
466 
467  return out;
468  }
469 /* @} */
471  /* @{ */
472  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
473  inline
475 {
476  assert(x.dim()==y.dim());
477  for(std::size_t n = 0; n < NP; ++n)
478  {
479  if( x[n] != y[n])
480  return false;
481  }
482  return true;
483 }
484 
485 
486  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
487  inline
489 {
490  assert(x.dim()==y.dim());
491  for(std::size_t n = 0; n < NP; ++n)
492  {
493  if( x[n] == y[n])
494  return false;
495  }
496  return true;
497 }
498 /* @} */
500  /* @{ */
501  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
502  inline
503 bool operator<(const block3d<T,NP,NR,NC>& x, const block3d<T,NP,NR,NC>& y)
504 {
505  assert(x.dim()==y.dim());
506  for(std::size_t n = 0; n < NP; ++n)
507  {
508  if( x[n] >= y[n])
509  return false;
510  }
511  return true;
512 }
513 
514 
515  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
516  inline
518 {
519  assert(x.dim()==y.dim());
520  for(std::size_t n = 0; n < NP; ++n)
521  {
522  if( x[n] <= y[n])
523  return false;
524  }
525  return true;
526 }
527 
528 
529  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
530  inline
531 bool operator<=(const block3d<T,NP,NR,NC>& x, const block3d<T,NP,NR,NC>& y)
532 {
533  assert(x.dim()==y.dim());
534  for(std::size_t n = 0; n < NP; ++n)
535  {
536  if( x[n] > y[n])
537  return false;
538  }
539  return true;
540 }
541 
542 
543  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
544  inline
546 {
547  assert(x.dim()==y.dim());
548  for(std::size_t n = 0; n < NP; ++n)
549  {
550  if( x[n] < y[n])
551  return false;
552  }
553  return true;
554 }
555 /* @} */
556  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
557  inline
558  T* block3d<T,NP,NR,NC>::operator()(const std::size_t i,
559  const std::size_t j)
560  {
561  assert(i < NP);
562  assert(j < NR);
563  return data[i][j];
564  }
565 
566  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
567  inline
568  const T* block3d<T,NP,NR,NC>::operator()(const std::size_t i,
569  const std::size_t j) const
570  {
571  assert(i < NP);
572  assert(j < NR);
573  return data[i][j];
574  }
575 
576 
577  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
578  inline
579  T& block3d<T,NP,NR,NC>::operator()(const std::size_t i,
580  const std::size_t j,
581  const std::size_t k)
582  {
583  assert(i < NP);
584  assert(j < NR);
585  assert(k < NC);
586  return data[i][j][k];
587  }
588 
589  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
590  inline
591  const T& block3d<T,NP,NR,NC>::operator()(const std::size_t i,
592  const std::size_t j,
593  const std::size_t k) const
594  {
595  assert(i < NP);
596  assert(j < NR);
597  assert(k < NC);
598  return data[i * NC * NR + j * NC + k];
599  }
600 
601  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
602  inline
603  void block3d<T,NP,NR,NC>::fill(const T& val)
604  {
605  for(std::size_t i = 0; i < NP; ++i){
606  data[i].fill(val);
607  }
608  }
609 
610 
611  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
612  inline
613  void block3d<T,NP,NR,NC>::fill(const T* val)
614  {
615  for(std::size_t i = 0; i < NP; ++i){
616  data[i].fill(&val[i*NR*NC]);
617  }
618  }
619 
620 
621  template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
622  inline
624  {
625  std::swap_ranges(begin(),end(),M.begin());
626  }
627 
628 
629  // template<typename T,std::size_t NP, std::size_t NR, std::size_t NC>
630 // inline
631 // void block3d<T,NP,NR,NC>::print() const
632 // {
633 // for(std::size_t i = 0; i < NP; ++i)
634 // {
635 // std::cout << std::endl << "------------PLAN "<<i<<" ---------------" << std::endl;
636 // data[i].print() ;
637 // }
638 // }
639 
640 }//slip::
641 
642 #endif //SLIP_BLOCK3D_HPP
bool operator!=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1448
const value_type * const_pointer
Definition: Block3d.hpp:143
slip::block2d< T, NR, NC > data[NP]
Prints the elements of the block3d on the standard output.
Definition: Block3d.hpp:361
static std::size_t size_max()
Returns the maximal size (number of elements) of the block3d.
Definition: Block3d.hpp:348
static const std::size_t DIM
Definition: Block3d.hpp:161
value_type & reference
Definition: Block3d.hpp:144
iterator end()
Definition: Block3d.hpp:392
static std::size_t dim3()
Returns the third dimension of the block3d (number of columns)
Definition: Block3d.hpp:344
This is a two-dimensional static and generic container. This container statisfies the BidirectionnalC...
Definition: Block2d.hpp:124
Provides a class to manipulate 2d static and generic arrays.
reverse_iterator rbegin()
Definition: Block3d.hpp:414
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: Block3d.hpp:154
void swap(block3d< T, NP, NR, NC > &M)
Swaps the contents of two block3d.
Definition: Block3d.hpp:623
const_pointer const_iterator
Definition: Block3d.hpp:151
value_type * pointer
Definition: Block3d.hpp:142
std::string name() const
Returns the name of the class.
Definition: Block3d.hpp:335
bool operator>(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1469
T * operator()(const std::size_t i, const std::size_t j)
Returns a reference to the element at the i'th plan, the j'th row and the k'th column.
Definition: Block3d.hpp:558
void fill(const T &val)
Init the block3d filled it with val value.
Definition: Block3d.hpp:603
pointer iterator
Definition: Block3d.hpp:150
friend class boost::serialization::access
Definition: Block3d.hpp:365
slip::block2d< T, NR, NC > & operator[](const std::size_t i)
Returns a pointer to the i'th plan of the block3d.
Definition: Block3d.hpp:442
std::random_access_iterator3d_tag iterator_category
Definition: Block3d.hpp:157
static std::size_t dim2()
Returns the second dimension of the block3d (number of rows)
Definition: Block3d.hpp:342
std::reverse_iterator< iterator > reverse_iterator
Definition: Block3d.hpp:153
This a three-dimensional static and generic container. This container statisfies the BidirectionnalCo...
Definition: Block3d.hpp:96
static bool empty()
Returns true if the block3d size is 0.
Definition: Block3d.hpp:350
static std::size_t size()
Returns the size (number of elements) of the block3d.
Definition: Block3d.hpp:346
ptrdiff_t difference_type
Definition: Block3d.hpp:147
reverse_iterator rend()
Definition: Block3d.hpp:421
static std::size_t dim1()
Returns the first dimension of the block3d (number of plans)
Definition: Block3d.hpp:340
iterator begin()
Definition: Block3d.hpp:385
std::size_t size_type
Definition: Block3d.hpp:148
const value_type & const_reference
Definition: Block3d.hpp:145
static const std::size_t SIZE
Definition: Block3d.hpp:160
static std::size_t dim()
Returns the dimension of the block3d.
Definition: Block3d.hpp:338
bool operator==(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1439
bool operator>=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1485