cartodata  4.5.0
volumebase_d_inline.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 #ifndef CARTODATA_VOLUME_VOLUMEBASE_D_INLINE_H
35 #define CARTODATA_VOLUME_VOLUMEBASE_D_INLINE_H
36 
37 //--- cartodata --------------------------------------------------------------
39 //--- cartobase --------------------------------------------------------------
41 //----------------------------------------------------------------------------
42 #include <iomanip>
43 
44 namespace carto {
45 
46  template < typename T >
47  inline
48  const T& Volume< T >::at( long x, long y, long z, long t ) const
49  {
50 #ifdef CARTO_USE_BLITZ
51  return _blitz.data()[
52  blitz::dot( _blitz.stride(),
53  blitz::TinyVector<long,4>( x, y, z, t ) ) ];
54 #else
55  return _items[ x + y * _lineoffset + z * _sliceoffset
56  + t * _volumeoffset ];
57 #endif
58  }
59 
60 
61  template < typename T >
62  inline
63  const T& Volume< T >::operator()( long x, long y, long z, long t ) const
64  {
65  return at( x, y, z, t );
66  }
67 
68 
69  template < typename T >
70  inline
71  T& Volume< T >::at( long x, long y, long z, long t )
72  {
73 #ifdef CARTO_USE_BLITZ
74  const blitz::TinyVector<int,4> & stride = _blitz.stride();
75  return _blitz.data()[ x * stride[0] + y * stride[1] + z * stride[2]
76  + t * stride[3] ];
77 #else
78  return _items[ x + y * _lineoffset + z * _sliceoffset
79  + t * _volumeoffset ];
80 #endif
81  }
82 
83 
84  template < typename T >
85  inline
86  T& Volume< T >::operator()( long x, long y, long z, long t )
87  {
88  return at( x, y, z, t );
89  }
90 
91 
92  template < typename T >
93  inline
94  const T& Volume< T >::at( const Position4Di & pos ) const
95  {
96  return at( pos[0], pos[1], pos[2], pos[3] );
97  }
98 
99 
100  template < typename T >
101  inline
102  const T& Volume< T >::operator()( const Position4Di & pos ) const
103  {
104  return at( pos );
105  }
106 
107 
108  template < typename T >
109  inline
110  T& Volume< T >::at( const Position4Di & pos )
111  {
112  return at( pos[0], pos[1], pos[2], pos[3] );
113  }
114 
115 
116  template < typename T >
117  inline
119  {
120  return at( pos );
121  }
122 
123 
124 #ifdef CARTO_USE_BLITZ
125  template < typename T > inline
126  const T & Volume< T >::at( const blitz::TinyVector<int,1> & index ) const
127  {
128  return _blitz( index );
129  }
130 
131  template < typename T > inline
132  T & Volume< T >::at( const blitz::TinyVector<int,1> & index )
133  {
134  return _blitz( index );
135  }
136 
137  template < typename T > inline
138  const T & Volume< T >::at( const blitz::TinyVector<int,2> & index ) const
139  {
140  return _blitz( index );
141  }
142 
143  template < typename T > inline
144  T & Volume< T >::at( const blitz::TinyVector<int,2> & index )
145  {
146  return _blitz( index );
147  }
148 
149  template < typename T > inline
150  const T & Volume< T >::at( const blitz::TinyVector<int,3> & index ) const
151  {
152  return _blitz( index );
153  }
154 
155  template < typename T > inline
156  T & Volume< T >::at( const blitz::TinyVector<int,3> & index )
157  {
158  return _blitz( index );
159  }
160 
161  template < typename T > inline
162  const T & Volume< T >::at( const blitz::TinyVector<int,4> & index ) const
163  {
164  return _blitz( index );
165  }
166 
167  template < typename T > inline
168  T & Volume< T >::at( const blitz::TinyVector<int,4> & index )
169  {
170  return _blitz( index );
171  }
172 
173  template < typename T > inline
174  blitz::Array<T,4>
175  Volume< T >::at( const blitz::RectDomain<4> & subdomain ) const
176  {
177  return _blitz( subdomain );
178  }
179 
180  template < typename T > inline
181  blitz::Array<T,4>
182  Volume< T >::at( const blitz::StridedDomain<4> & subdomain ) const
183  {
184  return _blitz( subdomain );
185  }
186 
187  template < typename T > inline
188  blitz::Array<T,4>
189  Volume< T >::at( const blitz::Range & r0 ) const
190  {
191  return _blitz( r0 );
192  }
193 
194  template < typename T > inline
195  blitz::Array<T,4>
196  Volume< T >::at( const blitz::Range & r0, const blitz::Range & r1 ) const
197  {
198  return _blitz( r0, r1 );
199  }
200 
201  template < typename T > inline
202  blitz::Array<T,4>
203  Volume< T >::at( const blitz::Range & r0, const blitz::Range & r1,
204  const blitz::Range & r2 ) const
205  {
206  return _blitz( r0, r1, r2 );
207  }
208 
209  template < typename T > inline
210  blitz::Array<T,4>
211  Volume< T >::at( const blitz::Range & r0, const blitz::Range & r1,
212  const blitz::Range & r2, const blitz::Range & r3 ) const
213  {
214  return _blitz( r0, r1, r2, r3 );
215  }
216 #endif
217 
218 
219  template <typename T>
221  {
222  return Object::reference( obj.header() );
223  }
224 
225 } // namespace carto
226 
227 template <typename T>
228 inline
229 std::ostream & operator<< ( std::ostream & out,
230  const carto::Volume<T> & volume )
231 {
232  carto::VolumeOStream volumeout( out );
233  return volumeout << volume;
234 }
235 
236 template <typename T>
237 inline
238 std::ostream & operator<< ( const carto::VolumeOStream & out,
239  const carto::Volume<T> & volume )
240 {
241  out.ostream() << "Volume of " << carto::DataTypeCode<T>::dataType() << ": "
242  << volume.getSizeX() << " x "
243  << volume.getSizeY() << " x "
244  << volume.getSizeZ() << " x "
245  << volume.getSizeT() << std::endl;
246 
247  bool hasT = volume.getSizeT() > 1;
248  std::string tB = ( hasT ? "[" : "" );
249  std::string tE = ( hasT ? "]" : "" );
250  std::string tS = ( hasT ? " " : "" );
251  bool hasZ = volume.getSizeZ() > 1;
252  std::string zB = ( hasZ ? "[" : "" );
253  std::string zE = ( hasZ ? "]" : "" );
254  std::string zS = ( hasZ ? " " : "" );
255  bool hasY = volume.getSizeY() > 1;
256  std::string yB = ( hasY ? "[" : "" );
257  std::string yE = ( hasY ? "]" : "" );
258  std::string yS = ( hasY ? " " : "" );
259  bool hasX = volume.getSizeX() > 1;
260  std::string xB = ( hasX ? "[" : "" );
261  std::string xE = ( hasX ? "]" : "" );
262  std::string xS = ( hasX ? " " : "" );
263 
264  for( int t = 0; t < volume.getSizeT(); ++t )
265  {
266  if( hasT ) {
267  if( t < out.maxT() ) {
268  out.ostream() << std::setw(2) << std::left << tB;
269  } else {
270  out.ostream() << std::setw(3) << std::left << "...";
271  break;
272  }
273  }
274  for( int z = 0; z < volume.getSizeZ(); ++z )
275  {
276  if( hasZ ) {
277  if( z < out.maxZ() ) {
278  out.ostream() << std::setw(2) << std::left << zB;
279  } else {
280  out.ostream() << std::setw(3) << std::left << "...";
281  break;
282  }
283  }
284  for( int y = 0; y < volume.getSizeY(); ++y )
285  {
286  if( y < out.maxY() ) {
287  out.ostream() << std::setw(2) << std::left << yB;
288  } else {
289  out.ostream() << std::setw(3) << std::left << "...";
290  break;
291  }
292  for( int x = 0; x < volume.getSizeX(); ++x )
293  {
294  if( x < out.maxX() ) {
295  out.ostream() << std::setw(8) << std::setprecision(6) << std::left
296  << carto::toString( volume( x, y, z, t ) );
297  } else {
298  out.ostream() << std::setw(8) << std::left << "...";
299  break;
300  }
301  }
302  out.ostream() << std::setw(2) << std::left << yE;
303  if( y < volume.getSizeY() - 1 )
304  out.ostream() << std::endl;
305  if( hasZ )
306  out.ostream() << std::setw(2) << std::left << zS;
307  if( hasT )
308  out.ostream() << std::setw(2) << std::left << tS;
309  }
310  if( hasZ )
311  out.ostream() << std::setw(2) << std::left << zE;
312  if( z < volume.getSizeZ() - 1 )
313  out.ostream() << std::endl;
314  if( hasT )
315  out.ostream() << std::setw(2) << std::left << tS;
316  }
317  if( hasT )
318  out.ostream() << std::setw(2) << std::left << tE;
319  if( t < volume.getSizeT() - 1 )
320  out.ostream() << std::endl;
321  }
322 
323  return out.ostream();
324 }
325 
326 #endif // CARTODATA_VOLUME_VOLUMEBASE_D_INLINE_H
4D Volume main class
std::string dataType()
const T & operator()(long x, long y=0, long z=0, long t=0) const
Warning: this operator is not virtual, so may not have the expected result on inherited classes (see ...
int getSizeT() const
Definition: volumeproxy.h:118
std::ostream & operator<<(std::ostream &out, const carto::Volume< T > &volume)
Volumes are printable to standard output streams.
const size_t & maxX() const
static Object reference(T &value)
const PropertySet & header() const
carto::Object getObjectHeader(Headered &h)
std::ostream & ostream() const
int getSizeZ() const
Definition: volumeproxy.h:108
const size_t & maxT() const
int getSizeX() const
Definition: volumeproxy.h:88
const size_t & maxZ() const
const size_t & maxY() const
const T & at(long x, long y=0, long z=0, long t=0) const
std::string toString(const T &object)
int getSizeY() const
Definition: volumeproxy.h:98