cartodata  4.7.0
volumeref.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_VOLUMEREF_H
35 #define CARTODATA_VOLUME_VOLUMEREF_H
36 
37 //--- cartodata --------------------------------------------------------------
42 //--- soma-io ----------------------------------------------------------------
44 //--- cartobase --------------------------------------------------------------
45 #include <cartobase/smart/rcptr.h>
47 //----------------------------------------------------------------------------
48 #include <iostream>
49 
50 #define CARTO_VOLUME_AUTO_DEREFERENCE
51 
52 namespace carto {
53 
54 //============================================================================
55 // V O L U M E R E F
56 //============================================================================
61  template <typename T>
62  class VolumeRef: public rc_ptr<Volume<T> >
63  {
64  public:
65  //========================================================================
66  // CONSTRUCTORS
67  //========================================================================
68  VolumeRef();
69  VolumeRef( Volume<T>* x );
70  VolumeRef( const rc_ptr<Volume<T> > & x );
71  virtual ~VolumeRef();
72 
74  {
75  return *(this->get());
76  }
77 
78  const Volume<T>& operator* () const
79  {
80  return *(this->get());
81  }
82 
83  //========================================================================
84  // TYPES
85  //========================================================================
86  typedef T datatype;
87 
88 #ifdef CARTO_VOLUME_AUTO_DEREFERENCE
89 
90  public:
91  //========================================================================
92  // TYPES
93  //========================================================================
95  typedef typename Volume<T>::Position Position;
96  typedef typename Volume<T>::iterator iterator;
98 
99  //========================================================================
100  // CONSTRUCTORS
101  //========================================================================
102  explicit VolumeRef( int sizeX, int sizeY = 1, int sizeZ = 1,
103  int sizeT = 1,
104  const AllocatorContext& allocatorContext
105  = AllocatorContext(),
106  bool allocated = true );
107  explicit VolumeRef( const Position4Di & size,
108  const AllocatorContext& allocatorContext
109  = AllocatorContext(),
110  bool allocated = true );
111  explicit VolumeRef( int sizeX, int sizeY, int sizeZ,
112  int sizeT, int bordersize,
113  const AllocatorContext& allocatorContext
114  = AllocatorContext(),
115  bool allocated = true );
116  explicit VolumeRef( const Position4Di & size, int bordersize,
117  const AllocatorContext& allocatorContext
118  = AllocatorContext(),
119  bool allocated = true );
120  explicit VolumeRef( int sizeX, int sizeY, int sizeZ, int sizeT,
121  const Position4Di & border,
122  const AllocatorContext& allocatorContext
123  = AllocatorContext(),
124  bool allocated = true );
125  explicit VolumeRef( const Position4Di & size,
126  const Position4Di & border,
127  const AllocatorContext& allocatorContext
128  = AllocatorContext(),
129  bool allocated = true );
130  explicit VolumeRef( rc_ptr<Volume<T> > other,
131  const Position4Di & pos,
132  const Position4Di & size = Position4Di( -1, -1, -1, -1 ),
133  const AllocatorContext & allocContext = AllocatorContext() );
134  explicit VolumeRef( rc_ptr<Volume<T> > other,
135  const Position & pos,
136  const Position & size = Position(),
137  const AllocatorContext & allocContext
138  = AllocatorContext() );
139 
140  //========================================================================
141  // VOLUME PROXY
142  //========================================================================
143  std::vector<int> getSize() const;
144  int getSizeX() const;
145  int getSizeY() const;
146  int getSizeZ() const;
147  int getSizeT() const;
148  const PropertySet& header() const;
149  PropertySet& header();
150  const PropertySet& getPropertySet() const
151  __attribute__((__deprecated__("use header() instead")));
153  __attribute__((__deprecated__("use header() instead")));
154  std::vector<float> getVoxelSize() const;
155 
156  virtual void copyHeaderFrom( const PropertySet & other );
157  virtual void copyHeaderFrom( const Object & other );
158 
159  //========================================================================
160  // ITERATORS
161  //========================================================================
162  iterator begin();
163  iterator end();
164  const_iterator begin() const;
165  const_iterator end() const;
166 
167  //========================================================================
168  // ACCESSORS
169  //========================================================================
170  const T& operator()( long x, long y = 0, long z = 0, long t = 0 ) const;
171  T& operator() ( long x, long y = 0, long z = 0, long t = 0 );
172  const T& at( long x, long y = 0, long z = 0, long t = 0 ) const;
173  T& at( long x, long y = 0, long z = 0, long t = 0 );
174  const T& operator() ( const Position4Di & position ) const;
175  T& operator() ( const Position4Di & position );
176  const T& at( const Position4Di & position ) const;
177  T& at( const Position4Di & position );
178  const T& operator() ( const Position & position ) const;
179  T& operator() ( const Position & position );
180  const T& at( const Position & position ) const;
181  T& at( const Position & position );
182 
183  //========================================================================
184  // INIT / ALLOCATION
185  //========================================================================
186  virtual void initialize();
187  const AllocatorContext & allocatorContext() const;
188  void allocate();
189  virtual void reallocate( int sizeX = 1, int sizeY = 1, int sizeZ = 1,
190  int sizeT = 1, bool keepcontents = false,
191  const AllocatorContext& allocatorContext
192  = AllocatorContext(), bool allocate = true );
193 #if 0
194  virtual void reallocate( const Position4Di & size,
195  bool keepcontents = false,
196  const AllocatorContext& allocatorContext
197  = AllocatorContext(), bool allocate = true );
198 #endif
199 
200  //========================================================================
201  // COPY / VIEW
202  //========================================================================
203  VolumeRef<T> copy() const;
204  template <typename OUTP>
205  VolumeRef<OUTP> copy() const;
206 
207  VolumeRef<T> deepcopy() const;
208  template <typename OUTP>
209  VolumeRef<OUTP> deepcopy() const;
210 
211  VolumeRef<T> copyStructure() const;
212  template <typename OUTP>
214 
215  template <typename OUTP>
216  operator VolumeRef<OUTP>() const;
217 
218  int getLevelsCount() const;
219  int refLevel(const int level) const;
220  rc_ptr<Volume<T> > refVolume() const;
221  rc_ptr<Volume<T> > refVolumeAtLevel(const int level) const;
222  void setRefVolume(const rc_ptr<Volume<T> > & refvol);
223  const Position4Di posInRefVolume() const;
224  typename Volume<T>::Position posInRefVolumeAtLevel(const int level) const;
225 
226  void setPosInRefVolume(const Position4Di & pos);
227  void setPosInRefVolume(const typename Volume<T>::Position & pos);
228 
229  std::vector<int> getBorders() const;
230  std::vector<size_t> getStrides() const;
231 
232  //========================================================================
233  // BOOL
234  //========================================================================
236  bool all() const;
238  bool any() const;
239  // /// Implicit cast to bool
240  // /// returns all()
241  // operator bool() const;
242  T min() const;
243  T max() const;
246  typename DataTypeTraits<T>::LongType sum() const;
247 
248  //========================================================================
249  // FILL / REPLACE
250  //========================================================================
252  void fill( const T & value );
253  VolumeRef<T> & operator= ( const T & value );
254 
255 #endif // CARTO_VOLUME_AUTO_DEREFERENCE
256 
257  //========================================================================
258  // SPECIAL VOLUMEREF METHODS
259  //========================================================================
260  VolumeRef<T> view( const Position4Di & pos, const Position4Di & size );
261  const VolumeRef<T> view( const Position4Di & pos, const Position4Di & size ) const;
262  }; // class VolumeRef
263 
264 //============================================================================
265 // UTILITIES
266 //============================================================================
267 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
268 
269  template <typename T>
271  {
272  public:
273  static std::string objectType()
274  { return "VolumeRef"; }
275  static std::string dataType()
276  { return DataTypeCode<T>::dataType(); }
277  static std::string name()
278  {
279  return std::string("VolumeRef of ") + DataTypeCode< T >::name();
280  }
281  };
282 
283  template <typename T>
284  class Creator<VolumeRef<T> >
285  {
286  public:
287  static VolumeRef<T>* create( Object, const AllocatorContext &, Object );
288  static void setup( VolumeRef<T> &, Object, const AllocatorContext &, Object );
289  };
290 
291 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES
292 
293 //============================================================================
294 // STREAM
295 //============================================================================
296 
297 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
298 
299  template <typename T>
300  std::ostream & operator<< ( const carto::VolumeOStream & out,
301  const carto::rc_ptr<carto::VolumeRef<T> > & volume );
302 
303 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES
304 
318  template <typename T>
319  std::ostream & operator<< ( std::ostream & out,
320  const carto::rc_ptr<carto::Volume<T> > & volume );
321 
323  template <typename T>
324  void displayRefVolumes(const carto::VolumeRef<T> & vol);
325 } // namespace carto
326 
327 
328 #endif // CARTODATA_VOLUME_VOLUMEREF_H
Volume< T > & operator*()
Definition: volumeref.h:73
N-D Volume main class.
std::string dataType()
VolumeRef< T > deepcopy() const
rc_ptr< Volume< T > > refVolumeAtLevel(const int level) const
virtual void reallocate(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1, bool keepcontents=false, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocate=true)
VolumeRef< T > copyStructure() const
virtual void initialize()
STL namespace.
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
Definition: volumebase.h:146
void setRefVolume(const rc_ptr< Volume< T > > &refvol)
int refLevel(const int level) const
Convenient handle for a Volume - this is normally the entry point for all volumes handling...
std::ostream & operator<<(std::ostream &out, const VoxelValue< T, C > &aa)
std::string name()
int getLevelsCount() const
bool any() const
True if at least one value compares to true.
VolumeRef< T > view(const Position4Di &pos, const Position4Di &size)
class __attribute__((__deprecated__("Use Volume, which now manages views, instead."))) VolumeView
View into a Volume.
Definition: volumeview.h:46
const T & at(long x, long y=0, long z=0, long t=0) const
const PropertySet & header() const
Volume< T >::iterator iterator
Definition: volumeref.h:96
std::vector< float > getVoxelSize() const
void fill(const T &value)
Fills the volume with a given value.
Volume< T >::const_iterator const_iterator
Definition: volumeref.h:97
static std::string objectType()
Definition: volumeref.h:273
VolumeRef< T > & operator=(const T &value)
VolumeRef< T > copy() const
void setPosInRefVolume(const Position4Di &pos)
Volume< T >::Position4Di Position4Di
Definition: volumeref.h:94
Volume< T >::Position Position
Definition: volumeref.h:95
const Position4Di posInRefVolume() const
void displayRefVolumes(const Volume< T > &vol)
Display information about volumes hierarchy.
std::vector< int > getSize() const
rc_ptr< Volume< T > > refVolume() const
Volume< T >::Position posInRefVolumeAtLevel(const int level) const
std::vector< size_t > getStrides() const
blitz::Array< T, Volume< T >::DIM_MAX >::iterator iterator
Definition: volumebase.h:145
virtual void copyHeaderFrom(const PropertySet &other)
DataTypeTraits< T >::LongType sum() const
To avoid overflow, the biggest possible type (intmax_t, uintmax_t, double...) is used for computation...
bool all() const
True if all values compare to true.
const PropertySet & getPropertySet() const __attribute__((__deprecated__("use header() instead")))
const AllocatorContext & allocatorContext() const
std::vector< int > getBorders() const
std::vector< int > Position
Definition: volumebase.h:131