SLIP  1.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Block4d.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 
74 #ifndef SLIP_BLOCK4D_HPP
75 #define SLIP_BLOCK4D_HPP
76 
77 #include <iostream>
78 #include <iterator>
79 #include <cassert>
80 #include <cstddef>
81 #include <string>
82 #include "iterator_types.hpp"
83 #include "Block3d.hpp"
84 #include <boost/serialization/access.hpp>
85 #include <boost/serialization/split_member.hpp>
86 #include <boost/serialization/string.hpp>
87 #include <boost/serialization/complex.hpp>
88 #include <boost/serialization/version.hpp>
89 
90 namespace slip
91 {
92 
93 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
94 struct block4d;
95 
96 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
97 std::ostream& operator<<(std::ostream & out,const slip::block4d<T,NS,NP,NR,NC>& b);
98 
99 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
101 
102 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
104 
105 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
106 bool operator<(const slip::block4d<T,NS,NP,NR,NC>& x, const slip::block4d<T,NS,NP,NR,NC>& y);
107 
108 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
110 
111 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
112 bool operator<=(const slip::block4d<T,NS,NP,NR,NC>& x, const slip::block4d<T,NS,NP,NR,NC>& y);
113 
114 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
116 
138 template <typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
139 struct block4d
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 
148 
149  typedef ptrdiff_t difference_type;
150  typedef std::size_t size_type;
151 
152  typedef pointer iterator;
154 
155  typedef std::reverse_iterator<iterator> reverse_iterator;
156  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
157 
158  //default iterator_category of the container
160 
161  //constants
162  static const std::size_t SIZE = NS * NP * NR * NC;
163  static const std::size_t DIM = 4;
164 
165 
166  iterator begin();
167  iterator end();
168 
169  const_iterator begin() const;
170  const_iterator end() const;
171 
174 
177 
182  void fill(const T& val);
183 
188  void fill(const T* val);
189 
194 
200  friend std::ostream& operator<< <>(std::ostream & out,const self& b);
201 
209  friend bool operator== <>(const self& x, const self& y);
210 
218  friend bool operator!= <>(const self& x, const self& y);
219 
227  friend bool operator< <>(const self& x, const self& y);
228 
236  friend bool operator> <>(const self& x, const self& y);
237 
245  friend bool operator<= <>(const self& x, const self& y);
246 
254  friend bool operator>= <>(const self& x, const self& y);
255 
256 
263  slip::block3d<T,NP,NR,NC> & operator[](const std::size_t i);
264 
271  const slip::block3d<T,NP,NR,NC> & operator[](const std::size_t i) const;
272 
273 
286  T* operator()(const std::size_t l, const std::size_t i,
287  const std::size_t j);
300  const T* operator()(const std::size_t l, const std::size_t i,
301  const std::size_t j) const;
302 
317  T & operator()(const std::size_t l, const std::size_t i,
318  const std::size_t j,
319  const std::size_t k);
334  const T & operator()(const std::size_t l, const std::size_t i,
335  const std::size_t j,
336  const std::size_t k) const;
337 
345  std::string name() const { return "block4d";}
346 
348  static std::size_t dim() {return SIZE;}
350  static std::size_t dim1() {return NS;}
352  static std::size_t dim2() {return NP;}
354  static std::size_t dim3() {return NR;}
356  static std::size_t dim4() {return NC;}
358  static std::size_t size() {return SIZE;}
360  static std::size_t size_max() {return SIZE;}
362  static bool empty(){return SIZE == 0;}
363 
368  void swap(self& M);
369 
371 
372  private:
374  template<class Archive>
375  void save(Archive & ar, const unsigned int version) const
376  {
377  ar & data;
378  }
379  template<class Archive>
380  void load(Archive & ar, const unsigned int version)
381  {
382  ar & data;
383  }
384 
385  BOOST_SERIALIZATION_SPLIT_MEMBER()
386 
387 };
388 }//slip::
389 
390 namespace slip
391 {
392 template<typename T, std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
393 inline
395 {
396  return data[0].begin();
397 }
398 
399 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
400 inline
402 {
403  return data[NS-1].end();
404 }
405 
406 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
407 inline
409 {
410  return data[0].begin();
411 }
412 
413 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
414 inline
416 {
417  return data[NS-1].end();
418 }
419 
420 
421 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
422 inline
423 std::reverse_iterator<T*> block4d<T,NS,NP,NR,NC>::rbegin()
424 {
425  return std::reverse_iterator<T*>(end());
426 }
427 
428 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
429 inline
430 std::reverse_iterator<T*> block4d<T,NS,NP,NR,NC>::rend()
431 {
432  return std::reverse_iterator<T*>(begin());
433 }
434 
435 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
436 inline
437 std::reverse_iterator<const T*> block4d<T,NS,NP,NR,NC>::rbegin() const
438 {
439  return std::reverse_iterator<const T*>(end());
440 }
441 
442 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
443 inline
444 std::reverse_iterator<const T*> block4d<T,NS,NP,NR,NC>::rend() const
445 {
446  return std::reverse_iterator<const T*>(begin());
447 }
448 
449 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
450 inline
452 {
453  assert(i < NP);
454  return data[i];
455 }
456 
457 template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
458 inline
460 {
461  assert(i < NP);
462  return data[i];
463 }
465 /* @{ */
466  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
467  inline
468  std::ostream& operator<<(std::ostream & out,const block4d<T,NS,NP,NR,NC>& b)
469  {
470 
471  for(std::size_t i = 0; i < NS; ++i)
472  {
473  out << std::endl << "############### SLAB "<<i<<" ######################" << std::endl<< b.data[i];
474  }
475 
476  return out;
477  }
478  /* @} */
480  /* @{ */
481  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
482  inline
484  {
485  assert(x.dim()==y.dim());
486  for(std::size_t n = 0; n < NS; ++n)
487  {
488  if( x[n] != y[n])
489  return false;
490  }
491  return true;
492  }
493 
494 
495  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
496  inline
498  {
499  assert(x.dim()==y.dim());
500  for(std::size_t n = 0; n < NS; ++n)
501  {
502  if( x[n] == y[n])
503  return false;
504  }
505  return true;
506  }
507  /* @} */
509  /* @{ */
510  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
511  inline
512  bool operator<(const block4d<T,NS,NP,NR,NC>& x, const block4d<T,NS,NP,NR,NC>& y)
513  {
514  assert(x.dim()==y.dim());
515  for(std::size_t n = 0; n < NS; ++n)
516  {
517  if( x[n] >= y[n])
518  return false;
519  }
520  return true;
521  }
522 
523 
524  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
525  inline
527  {
528  assert(x.dim()==y.dim());
529  for(std::size_t n = 0; n < NS; ++n)
530  {
531  if( x[n] <= y[n])
532  return false;
533  }
534  return true;
535  }
536 
537 
538  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
539  inline
540  bool operator<=(const block4d<T,NS,NP,NR,NC>& x, const block4d<T,NS,NP,NR,NC>& y)
541  {
542  assert(x.dim()==y.dim());
543  for(std::size_t n = 0; n < NS; ++n)
544  {
545  if( x[n] > y[n])
546  return false;
547  }
548  return true;
549  }
550 
551 
552  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
553  inline
555  {
556  assert(x.dim()==y.dim());
557  for(std::size_t n = 0; n < NS; ++n)
558  {
559  if( x[n] < y[n])
560  return false;
561  }
562  return true;
563  }
564  /* @} */
565  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
566  inline
567  T* block4d<T,NS,NP,NR,NC>::operator()(const std::size_t l, const std::size_t i,
568  const std::size_t j)
569  {
570  assert(l < NS);
571  assert(i < NP);
572  assert(j < NR);
573  return data[l][i][j];
574  }
575 
576  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
577  inline
578  const T* block4d<T,NS,NP,NR,NC>::operator()(const std::size_t l, const std::size_t i,
579  const std::size_t j) const
580  {
581  assert(l < NS);
582  assert(i < NP);
583  assert(j < NR);
584  return data[l][i][j];
585  }
586 
587 
588  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
589  inline
590  T & block4d<T,NS,NP,NR,NC>::operator()(const std::size_t l, const std::size_t i,
591  const std::size_t j,
592  const std::size_t k)
593  {
594  assert(l < NS);
595  assert(i < NP);
596  assert(j < NR);
597  assert(k < NC);
598  return data[l][i][j][k];
599  }
600 
601  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
602  inline
603  const T & block4d<T,NS,NP,NR,NC>::operator()(const std::size_t l, const std::size_t i,
604  const std::size_t j,
605  const std::size_t k) const
606  {
607  assert(l < NS);
608  assert(i < NP);
609  assert(j < NR);
610  assert(k < NC);
611  return data[l * NC * NR * NP + i * NC * NR + j * NC + k];
612  //return data[l][i][j][k];
613  }
614 
615  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
616  inline
617  void block4d<T,NS,NP,NR,NC>::fill(const T& val)
618  {
619  for(std::size_t i = 0; i < NS; ++i){
620  data[i].fill(val);
621  }
622  }
623 
624 
625  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
626  inline
627  void block4d<T,NS,NP,NR,NC>::fill(const T* val)
628  {
629  for(std::size_t i = 0; i < NS; ++i){
630  data[i].fill(&val[i*NP*NR*NC]);
631  }
632  }
633 
634 
635  template<typename T,std::size_t NS, std::size_t NP, std::size_t NR, std::size_t NC>
636  inline
638  {
639  std::swap_ranges(begin(),end(),M.begin());
640  }
641 
642 
643 }//slip::
644 
645 #endif //SLIP_BLOCK4D_HPP
iterator end()
Definition: Block4d.hpp:401
bool operator!=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1448
Provides a class to manipulate 3d static and generic arrays.
std::reverse_iterator< iterator > reverse_iterator
Definition: Block4d.hpp:155
friend class boost::serialization::access
Definition: Block4d.hpp:373
slip::block3d< T, NP, NR, NC > data[NS]
Definition: Block4d.hpp:370
value_type & reference
Definition: Block4d.hpp:144
std::string name() const
Returns the name of the class.
Definition: Block4d.hpp:345
const value_type * const_pointer
Definition: Block4d.hpp:143
ptrdiff_t difference_type
Definition: Block4d.hpp:149
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: Block4d.hpp:156
Provides a class to tag SLIP iterators.
static std::size_t dim1()
Returns the first dimension of the block4d (number of slabs)
Definition: Block4d.hpp:350
const_pointer const_iterator
Definition: Block4d.hpp:153
This a four-dimensional static and generic container. This container statisfies the BidirectionnalCon...
Definition: Block4d.hpp:94
static std::size_t dim()
Returns the dimension of the block4d.
Definition: Block4d.hpp:348
bool operator>(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1469
void fill(const T &val)
Init the block4d filled it with val value.
Definition: Block4d.hpp:617
static std::size_t size()
Returns the size (number of elements) of the block4d.
Definition: Block4d.hpp:358
reverse_iterator rbegin()
Definition: Block4d.hpp:423
static std::size_t dim3()
Returns the third dimension of the block4d (number of rows)
Definition: Block4d.hpp:354
pointer iterator
Definition: Block4d.hpp:152
static const std::size_t DIM
Definition: Block4d.hpp:163
T * operator()(const std::size_t l, const std::size_t i, const std::size_t j)
Returns a pointer at the first element of the l'th slab, the i'th plan and the j'th row...
Definition: Block4d.hpp:567
iterator begin()
Definition: Block4d.hpp:394
slip::block3d< T, NP, NR, NC > & operator[](const std::size_t i)
Returns a reference to the i'th slab of the block4d.
Definition: Block4d.hpp:451
value_type * pointer
Definition: Block4d.hpp:142
static std::size_t dim4()
Returns the fourth dimension of the block4d (number of columns)
Definition: Block4d.hpp:356
static std::size_t size_max()
Returns the maximal size (number of elements) of the block4d.
Definition: Block4d.hpp:360
This a three-dimensional static and generic container. This container statisfies the BidirectionnalCo...
Definition: Block3d.hpp:96
std::size_t size_type
Definition: Block4d.hpp:150
void swap(self &M)
Swaps the contents of two block4d.
Definition: Block4d.hpp:637
static const std::size_t SIZE
Definition: Block4d.hpp:162
static bool empty()
Returns true if the block4d size is 0.
Definition: Block4d.hpp:362
reverse_iterator rend()
Definition: Block4d.hpp:430
static std::size_t dim2()
Returns the second dimension of the block4d (number of plans)
Definition: Block4d.hpp:352
bool operator==(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1439
const value_type & const_reference
Definition: Block4d.hpp:145
bool operator>=(const Array< T > &x, const Array< T > &y)
Definition: Array.hpp:1485
std::random_access_iterator4d_tag iterator_category
Definition: Block4d.hpp:159