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