34 #ifndef CARTODATA_VOLUME_VOLUMEBASE_D_OPERATORS_H 35 #define CARTODATA_VOLUME_VOLUMEBASE_D_OPERATORS_H 51 namespace volumebaseinternal {
57 template <typename T, bool is_scalar = DataTypeTraits<T>::is_scalar>
62 throw std::logic_error(
"Member function min() is only enabled for " 63 "volumes of scalar. Try to use the non-member function " 64 "carto::min(Volume<T>) instead." );
69 throw std::logic_error(
"Member function max() is only enabled for " 70 "volumes of scalar. Try to use the non-member function " 71 "carto::max(Volume<T>) instead." );
77 throw std::logic_error(
"Member function sum() is only enabled for " 78 "volumes of scalar. Try to use the non-member function " 79 "carto::sum(Volume<T>) instead." );
84 template <typename T, bool has_bool_conversion = DataTypeTraits<T>::has_bool_conversion>
89 throw std::logic_error(
"Member function all() is only enabled for " 90 "volumes of types that support boolean conversion. Try to use the " 91 "non-member function carto::all(Volume<T>) instead." );
96 throw std::logic_error(
"Member function any() is only enabled for " 97 "volumes of that support boolean conversion. Try to use the " 98 "non-member function carto::any(Volume<T>) instead." );
103 template <
typename T>
124 template <
typename T>
142 template <
typename T>
149 template <
typename T>
156 template <
typename T>
163 template <
typename T>
170 template <
typename T>
177 template <
typename T>
190 template <
typename T>
197 template <
typename T>
206 template <
typename T>
214 std::vector<int> sz = ref->getSize();
215 std::vector<int> vsz = this->getSize();
218 int vnd = vsz.size();
220 std::vector<int> dmin( nd, 0 ), dmax( nd, 0 );
221 std::vector<int> ppos( nd, 0 );
222 std::vector<bool> is_inside( nd,
true );
225 for( dim=nd - 1; dim>=0; --dim )
230 dmin[dim] = pos[dim];
233 dmax[dim] = vsz[dim] + dmin[dim];
241 is_inside[dim] = (dmin[dim] == 0 );
243 is_inside[dim] = is_inside[dim] && is_inside[dim + 1];
251 for( i=0; i<dmin[0]; ++i )
254 ref->at( ppos ) = value;
256 for( i=dmax[0]; i<sz[0]; ++i )
259 ref->at( ppos ) = value;
264 for( i=0; i<sz[0]; ++i )
267 ref->at( ppos ) = value;
273 while( ppos[dim] >= sz[dim] )
284 for( ; dim > 0; --dim )
286 is_inside[dim] = ( dim < nd - 1 ? is_inside[dim + 1] : true );
287 is_inside[dim] = is_inside[dim] && ( ppos[dim] >= dmin[dim] )
288 && ( ppos[dim] < dmax[dim] );
297 template <
typename T>
301 return ::carto::copy<T,T>( *this );
304 template <
typename T>
305 template <
typename OUTP>
309 return ::carto::copy<OUTP,T>( *this );
312 template <
typename T>
316 return ::carto::deepcopy<T,T>( *this );
319 template <
typename T>
320 template <
typename OUTP>
324 return ::carto::deepcopy<OUTP,T>( *this );
327 template <
typename T>
331 return ::carto::copyStructure<T,T>( *this );
334 template <
typename T>
335 template <
typename OUTP>
339 return ::carto::copyStructure<OUTP,T>( *this );
342 template <
typename T>
343 template <
typename OUTP>
347 return ::carto::deepcopy<OUTP,T>( *this );
356 template <
typename T,
typename U>
364 template <
typename T,
typename U>
372 template <
typename T,
typename U>
380 template <
typename T,
typename U>
388 template <
typename T,
typename U>
396 template <
typename T,
typename U>
406 template <
typename T,
typename U>
414 template <
typename T,
typename U>
422 template <
typename T,
typename U>
430 template <
typename T,
typename U>
438 template <
typename T,
typename U>
446 template <
typename T,
typename U>
456 template <
typename T,
typename U>
464 template <
typename T,
typename U>
472 template <
typename T,
typename U>
480 template <
typename T,
typename U>
488 template <
typename T,
typename U>
496 template <
typename T,
typename U>
510 template <
typename T>
517 template <
typename T>
524 template <
typename T>
534 template <
typename T,
typename U>
542 template <
typename T,
typename U>
550 template <
typename T,
typename U>
558 template <
typename T,
typename U>
566 template <
typename T,
typename U>
574 template <
typename T,
typename U>
582 template <
typename T,
typename U>
590 template <
typename T,
typename U>
598 template <
typename T,
typename U>
606 template <
typename T,
typename U>
616 template <
typename T,
typename U>
624 template <
typename T,
typename U>
632 template <
typename T,
typename U>
640 template <
typename T,
typename U>
650 template <
typename T,
typename U>
658 template <
typename T,
typename U>
666 template <
typename T,
typename U>
674 template <
typename T,
typename U>
682 template <
typename T,
typename U>
690 template <
typename T,
typename U>
698 template <
typename T,
typename U>
706 template <
typename T,
typename U>
714 template <
typename T,
typename U>
722 template <
typename T,
typename U>
736 template <
typename T,
typename U>
743 template <
typename T,
typename U>
750 template <
typename T,
typename U>
757 template <
typename T,
typename U>
764 template <
typename T,
typename U>
771 template <
typename T,
typename U>
778 template <
typename T,
typename U>
785 template <
typename T,
typename U>
794 template <
typename T,
typename U>
801 template <
typename T,
typename U>
808 template <
typename T,
typename U>
815 template <
typename T,
typename U>
822 template <
typename T,
typename U>
829 template <
typename T,
typename U>
836 template <
typename T,
typename U>
843 template <
typename T,
typename U>
854 template <
typename T>
863 template <
typename T>
870 template <
typename T>
879 template <
typename T>
888 #endif // CARTODATA_VOLUME_VOLUMEBASE_D_OPERATORS_H carto::Volume< T > operator--(carto::Volume< T > &vol, int)
carto::Volume< bool > operator!(const carto::Volume< T > &vol)
Volume< T > & selfApply(Volume< T > &vol, UnaryFunction func)
Apply a function to all the elements of a volume (in place version)
static bool any(const Volume< T > &vol)
VoxelRGB operator/(const VoxelRGB &aa, const uint8_t &bb)
static bool all(const Volume< T > &)
bool any(const Volume< T > &vol)
Returns true if at least one value compares to true.
carto::Volume< bool > operator>=(const carto::Volume< T > &vol, const U &value)
T max(const Volume< T > &vol)
Returns the maximum value of the volume.
static DataTypeTraits< T >::LongType sum(const Volume< T > &vol)
carto::Volume< bool > operator &&(const carto::Volume< T > &vol, const U &value)
VoxelRGB operator+(const VoxelRGB &aa, const VoxelRGB &bb)
DataTypeTraits< T >::LongType sum(const Volume< T > &vol)
Returns the sum of the volume values.
carto::Volume< bool > operator>(const carto::Volume< T > &vol, const U &value)
static T max(const Volume< T > &)
carto::Volume< T > operator~(const carto::Volume< T > &vol)
static bool all(const Volume< T > &vol)
T min(const Volume< T > &vol)
Returns the minimum value of the volume.
VoxelRGB operator*(const VoxelRGB &aa, const uint8_t &bb)
carto::Volume< bool > operator==(const carto::Volume< T > &vol, const U &value)
void fill(const T &value)
Fills the volume with a given value.
carto::Volume< T > & operator &=(carto::Volume< T > &vol, const U &value)
carto::Volume< typename carto::volumeutil::modulus< T, U >::result_type > operator%(const carto::Volume< T > &vol, const U &value)
carto::Volume< typename carto::volumeutil::bitwise_xor< T, U >::result_type > operator^(const carto::Volume< T > &vol, const U &value)
void fillBorder(const T &value)
Fill border with a constant value.
carto::Volume< T > & operator%=(carto::Volume< T > &vol, const U &value)
carto::Volume< bool > operator!=(const carto::Volume< T > &vol, const U &value)
static T max(const Volume< T > &vol)
carto::Volume< typename carto::volumeutil::bitwise_or< T, U >::result_type > operator|(const carto::Volume< T > &vol, const U &value)
carto::Volume< T > & operator^=(carto::Volume< T > &vol, const U &value)
Volume< T > copyStructure() const
Copy the full data structure without copying the actual data.
carto::Volume< bool > operator||(const carto::Volume< T > &vol, const U &value)
carto::Volume< T > & operator*=(carto::Volume< T > &vol, const U &value)
carto::Volume< T > & operator+=(carto::Volume< T > &vol, const U &value)
carto::Volume< T > & operator-=(carto::Volume< T > &vol, const U &value)
bool all(const Volume< T > &vol)
Returns true if all values compare to true.
static T min(const Volume< T > &)
Volume< T > copy() const
Create a volume of same dimension and copy the data.
carto::Volume< typename carto::volumeutil::bitwise_and< T, U >::result_type > operator &(const carto::Volume< T > &vol, const U &value)
static T min(const Volume< T > &vol)
VoxelRGB operator-(const VoxelRGB &aa, const VoxelRGB &bb)
Volume< OUTP > & applyTowards(const Volume< T > &vol, Volume< OUTP > &dst, UnaryFunction func)
Apply a function to all the elements of a volume (already allocated output version) ...
Volume< typename UnaryFunction::result_type > apply(const Volume< T > &vol, UnaryFunction func)
Used by the actual Volume and VolumeRef operators It allows to keep the loops in one place and to spe...
Volume< T > deepcopy() const
Copy the full data structure.
Volume< T > & operator=(const Volume< T > &other)
static bool any(const Volume< T > &)
DataTypeTraits< T >::LongType sum() const
To avoid overflow, the biggest possible type (intmax_t, uintmax_t, double...) is used for computation...
bool any() const
True if at least one value compares to true.
bool all() const
True if all values compare to true.
carto::Volume< T > operator++(carto::Volume< T > &vol, int)
carto::Volume< T > & operator|=(carto::Volume< T > &vol, const U &value)
std::vector< int > Position
static DataTypeTraits< T >::LongType sum(const Volume< T > &)
carto::Volume< T > & operator/=(carto::Volume< T > &vol, const U &value)