xc
Array3dBoxConstRef.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Array3dBoxConstRef.h
22 
23 #ifndef ARRAY3DBOXCONSTREF_H
24 #define ARRAY3DBOXCONSTREF_H
25 
26 #include "Array3dBoxRefBase.h"
27 #include "Array3dRange.h"
28 
29 
31 //
33 template <class ARRAY_3D>
35  {
36  const ARRAY_3D &ttz;
37  public:
38  typedef typename ARRAY_3D::const_reference const_reference;
39 
40  explicit Array3dBoxConstRef(const ARRAY_3D &t,const size_t &iLayer=1,const size_t &f= 1,const size_t &c= 1);
41  Array3dBoxConstRef(const ARRAY_3D &t,const Array3dRange &rango);
42  Array3dBoxConstRef(const ARRAY_3D &t,const RangoIndice &layer_range,const RangoIndice &row_range,const RangoIndice &column_range);
43  Array3dBoxConstRef(const ARRAY_3D &t,const size_t &iLayer,const RangoIndice &row_range,const RangoIndice &column_range);
44  Array3dBoxConstRef(const ARRAY_3D &t,const RangoIndice &layer_range,const size_t &iRow,const RangoIndice &column_range);
45  Array3dBoxConstRef(const ARRAY_3D &t,const RangoIndice &layer_range,const RangoIndice &row_range,const size_t &iCol);
46  Array3dBoxConstRef(const ARRAY_3D &t,const size_t &iLayer,const size_t &iRow,const RangoIndice &column_range);
47  Array3dBoxConstRef(const ARRAY_3D &t,const size_t iLayer,const RangoIndice &row_range,const size_t &iCol);
48  Array3dBoxConstRef(const ARRAY_3D &t,const RangoIndice &layer_range,const size_t &iRow,const size_t &iCol);
49  inline virtual ~Array3dBoxConstRef(void) {}
50  inline virtual const_reference operator()(size_t iLayer=1,size_t iRow=1,size_t iCol=1) const
51  { return ttz(iLayer+offset_cp,iRow+offset_f,iCol+offset_c); }
52  };
53 
54 template<class ARRAY_3D>
55 Array3dBoxConstRef<ARRAY_3D>::Array3dBoxConstRef(const ARRAY_3D &t,const size_t &iLayer,const size_t &f,const size_t &c)
56  : Array3dBoxRefBase(iLayer,f,c,t.getNumberOfLayers(),t.getNumberOfRows(),t.getNumberOfColumns()),ttz(t) {}
57 
58 template<class ARRAY_3D>
60  : Array3dBoxRefBase(clip(rango,t)),ttz(t) {}
61 
62 template<class ARRAY_3D>
63 Array3dBoxConstRef<ARRAY_3D>::Array3dBoxConstRef(const ARRAY_3D &t,const RangoIndice &layer_range,const RangoIndice &row_range,const RangoIndice &column_range)
64  : Array3dBoxRefBase(clip(layer_range,t.getNumberOfLayers()),clip(row_range,t.getNumberOfRows()),clip(column_range,t.getNumberOfColumns())),ttz(t) {}
65 
66 template<class ARRAY_3D>
67 Array3dBoxConstRef<ARRAY_3D>::Array3dBoxConstRef(const ARRAY_3D &t,const size_t &iLayer,const RangoIndice &row_range,const RangoIndice &column_range)
68  : Array3dBoxRefBase(iLayer,clip(row_range,t.getNumberOfRows()),clip(column_range,t.getNumberOfColumns())),ttz(t)
69  {
70  if(iLayer>t.getNumberOfLayers())
71  std::clog << "Aviso; layer index: " << iLayer
72  << " out of range in array with ranges: "
73  << Array3dRange(ttz) << std::endl;
74  }
75 
76 template<class ARRAY_3D>
77 Array3dBoxConstRef<ARRAY_3D>::Array3dBoxConstRef(const ARRAY_3D &t,const RangoIndice &layer_range,const size_t &iRow,const RangoIndice &column_range)
78  : Array3dBoxRefBase(clip(layer_range,t.getNumberOfLayers()),iRow,clip(column_range,t.getNumberOfColumns())),ttz(t)
79  {
80  if(iRow>t.getNumberOfRows())
81  std::clog << "Aviso; row index: " << iRow
82  << " out of range in array with ranges: "
83  << Array3dRange(ttz) << std::endl;
84  }
85 
86 template<class ARRAY_3D>
87 Array3dBoxConstRef<ARRAY_3D>::Array3dBoxConstRef(const ARRAY_3D &t,const RangoIndice &layer_range,const RangoIndice &row_range,const size_t &iCol)
88  : Array3dBoxRefBase(clip(layer_range,t.getNumberOfLayers()),clip(row_range,t.getNumberOfRows()),iCol),ttz(t)
89  {
90  if(iCol>t.getNumberOfColumns())
91  std::clog << "Aviso; column index: " << iCol
92  << " out of range in array with ranges: "
93  << Array3dRange(ttz) << std::endl;
94  }
95 
96 template<class ARRAY_3D>
97 Array3dBoxConstRef<ARRAY_3D>::Array3dBoxConstRef(const ARRAY_3D &t,const size_t &iLayer,const size_t &iRow,const RangoIndice &column_range)
98  : Array3dBoxRefBase(iLayer,iRow,clip(column_range,t.getNumberOfColumns())),ttz(t)
99  {
100  if(iLayer>t.getNumberOfLayers())
101  std::clog << "Aviso; layer index: " << iLayer
102  << " out of range in array with ranges: "
103  << Array3dRange(ttz) << std::endl;
104  if(iRow>t.getNumberOfRows())
105  std::clog << "Aviso; row index: " << iRow
106  << " out of range in array with ranges: "
107  << Array3dRange(ttz) << std::endl;
108  }
109 
110 template<class ARRAY_3D>
111 Array3dBoxConstRef<ARRAY_3D>::Array3dBoxConstRef(const ARRAY_3D &t,const size_t iLayer,const RangoIndice &row_range,const size_t &iCol)
112  : Array3dBoxRefBase(iLayer,clip(row_range,t.getNumberOfRows()),iCol),ttz(t)
113  {
114  if(iLayer>t.getNumberOfLayers())
115  std::clog << "Aviso; layer index: " << iLayer
116  << " out of range in array with ranges: "
117  << Array3dRange(ttz) << std::endl;
118  if(iCol>t.getNumberOfColumns())
119  std::clog << "Aviso; column index: " << iCol
120  << " out of range in array with ranges: "
121  << Array3dRange(ttz) << std::endl;
122  }
123 
124 template<class ARRAY_3D>
125 Array3dBoxConstRef<ARRAY_3D>::Array3dBoxConstRef(const ARRAY_3D &t,const RangoIndice &layer_range,const size_t &iRow,const size_t &iCol)
126  : Array3dBoxRefBase(clip(layer_range,t.getNumberOfLayers()),iRow,iCol),ttz(t)
127  {
128  if(iRow>t.getNumberOfRows())
129  std::clog << "Aviso; row index: " << iRow
130  << " out of range in array with ranges: "
131  << Array3dRange(ttz) << std::endl;
132  if(iCol>t.getNumberOfColumns())
133  std::clog << "Aviso; column index: " << iCol
134  << " out of range in array with ranges: "
135  << Array3dRange(ttz) << std::endl;
136  }
137 
138 template <class ARRAY_3D>
139 inline std::ostream &operator<<(std::ostream &os,const Array3dBoxConstRef<ARRAY_3D> &c)
140  {
141  PrintArray3d(c,os);
142  return os;
143  }
144 
145 template <class ARRAY_3D, class TRF>
146 const Array3dBoxConstRef<ARRAY_3D> &transform(const Array3dBoxConstRef<ARRAY_3D> &box,const TRF &trf)
147  {
148  static Array3dBoxConstRef<ARRAY_3D> retval;
149  retval= box;
150  const size_t n_layers= box.getNumberOfLayers();
151  const size_t n_rows= box.getNumberOfRows();
152  const size_t n_columns= box.getNumberOfColumns();
153  for(size_t k=1;k<=n_layers;k++) //For each layer.
154  for(size_t i=1;i<=n_rows;i++) //For each row.
155  for(size_t j=1;j<=n_columns;j++) //For each column.
156  retval(i,j,k)= Transform(box(i,j,k));
157  return retval;
158  }
159 
160 
161 #endif
size_t offset_cp
Offset layer.
Definition: Array3dBoxRefBase.h:40
size_t n_layers
number of layers.
Definition: Array3dBoxRefBase.h:37
size_t offset_c
Offset column.
Definition: Array3dBoxRefBase.h:42
size_t offset_f
Offset row.
Definition: Array3dBoxRefBase.h:41
Referencia a una "sub array 3D".
Definition: Array3dBoxConstRef.h:34
Indices that define a block of an array.
Definition: Array3dBoxRefBase.h:34
size_t n_columns
number of columns.
Definition: Array3dBoxRefBase.h:39
size_t n_rows
number of rows.
Definition: Array3dBoxRefBase.h:38
Rangos de variación de tres índices, se emplea en BoxConstRef.
Definition: Array3dRange.h:32
Rango de variación de un índice, se emplea en BoxConstRef.
Definition: RangoIndice.h:30