34 #ifndef CARTODATA_VOLUME_VOLUMEBASE_D_OPERATORS_H
35 #define CARTODATA_VOLUME_VOLUMEBASE_D_OPERATORS_H
50 namespace volumebaseinternal {
56 template <typename T, bool is_scalar = DataTypeTraits<T>::is_scalar>
61 throw std::logic_error(
"Member function min() is only enabled for "
62 "volumes of scalar. Try to use the non-member function "
63 "carto::min(Volume<T>) instead." );
68 throw std::logic_error(
"Member function max() is only enabled for "
69 "volumes of scalar. Try to use the non-member function "
70 "carto::max(Volume<T>) instead." );
76 throw std::logic_error(
"Member function sum() is only enabled for "
77 "volumes of scalar. Try to use the non-member function "
78 "carto::sum(Volume<T>) instead." );
83 template <typename T, bool has_bool_conversion = DataTypeTraits<T>::has_bool_conversion>
88 throw std::logic_error(
"Member function all() is only enabled for "
89 "volumes of types that support boolean conversion. Try to use the "
90 "non-member function carto::all(Volume<T>) instead." );
95 throw std::logic_error(
"Member function any() is only enabled for "
96 "volumes of that support boolean conversion. Try to use the "
97 "non-member function carto::any(Volume<T>) instead." );
102 template <
typename T>
123 template <
typename T>
141 template <
typename T>
148 template <
typename T>
155 template <
typename T>
162 template <
typename T>
169 template <
typename T>
176 template <
typename T>
189 template <
typename T>
196 template <
typename T>
205 template <
typename T>
213 std::vector<int> sz =
ref->getSize();
214 std::vector<int> vsz = this->getSize();
217 int vnd = vsz.size();
219 std::vector<int> dmin( nd, 0 ), dmax( nd, 0 );
220 std::vector<int> ppos( nd, 0 );
221 std::vector<bool> is_inside( nd,
true );
224 for( dim=nd - 1; dim>=0; --dim )
229 dmin[dim] = pos[dim];
232 dmax[dim] = vsz[dim] + dmin[dim];
240 is_inside[dim] = (dmin[dim] == 0 );
242 is_inside[dim] = is_inside[dim] && is_inside[dim + 1];
250 for( i=0; i<dmin[0]; ++i )
253 ref->at( ppos ) = value;
255 for( i=dmax[0]; i<sz[0]; ++i )
258 ref->at( ppos ) = value;
263 for( i=0; i<sz[0]; ++i )
266 ref->at( ppos ) = value;
272 while( ppos[dim] >= sz[dim] )
283 for( ; dim > 0; --dim )
285 is_inside[dim] = ( dim < nd - 1 ? is_inside[dim + 1] : true );
286 is_inside[dim] = is_inside[dim] && ( ppos[dim] >= dmin[dim] )
287 && ( ppos[dim] < dmax[dim] );
296 template <
typename T>
300 return ::carto::copy<T,T>( *
this );
303 template <
typename T>
304 template <
typename OUTP>
308 return ::carto::copy<OUTP,T>( *
this );
311 template <
typename T>
315 return ::carto::deepcopy<T,T>( *
this );
318 template <
typename T>
319 template <
typename OUTP>
323 return ::carto::deepcopy<OUTP,T>( *
this );
326 template <
typename T>
330 return ::carto::copyStructure<T,T>( *
this );
333 template <
typename T>
334 template <
typename OUTP>
338 return ::carto::copyStructure<OUTP,T>( *
this );
341 template <
typename T>
342 template <
typename OUTP>
346 return ::carto::deepcopy<OUTP,T>( *
this );
355 template <
typename T,
typename U>
363 template <
typename T,
typename U>
371 template <
typename T,
typename U>
379 template <
typename T,
typename U>
387 template <
typename T,
typename U>
395 template <
typename T,
typename U>
405 template <
typename T,
typename U>
413 template <
typename T,
typename U>
421 template <
typename T,
typename U>
429 template <
typename T,
typename U>
437 template <
typename T,
typename U>
445 template <
typename T,
typename U>
455 template <
typename T,
typename U>
463 template <
typename T,
typename U>
471 template <
typename T,
typename U>
479 template <
typename T,
typename U>
487 template <
typename T,
typename U>
495 template <
typename T,
typename U>
509 template <
typename T>
516 template <
typename T>
523 template <
typename T>
533 template <
typename T,
typename U>
541 template <
typename T,
typename U>
549 template <
typename T,
typename U>
557 template <
typename T,
typename U>
565 template <
typename T,
typename U>
573 template <
typename T,
typename U>
581 template <
typename T,
typename U>
589 template <
typename T,
typename U>
597 template <
typename T,
typename U>
605 template <
typename T,
typename U>
615 template <
typename T,
typename U>
623 template <
typename T,
typename U>
631 template <
typename T,
typename U>
639 template <
typename T,
typename U>
649 template <
typename T,
typename U>
657 template <
typename T,
typename U>
665 template <
typename T,
typename U>
673 template <
typename T,
typename U>
681 template <
typename T,
typename U>
689 template <
typename T,
typename U>
697 template <
typename T,
typename U>
705 template <
typename T,
typename U>
713 template <
typename T,
typename U>
721 template <
typename T,
typename U>
735 template <
typename T,
typename U>
742 template <
typename T,
typename U>
749 template <
typename T,
typename U>
756 template <
typename T,
typename U>
763 template <
typename T,
typename U>
770 template <
typename T,
typename U>
777 template <
typename T,
typename U>
784 template <
typename T,
typename U>
793 template <
typename T,
typename U>
800 template <
typename T,
typename U>
807 template <
typename T,
typename U>
814 template <
typename T,
typename U>
821 template <
typename T,
typename U>
828 template <
typename T,
typename U>
835 template <
typename T,
typename U>
842 template <
typename T,
typename U>
853 template <
typename T>
862 template <
typename T>
869 template <
typename T>
878 template <
typename T>
Volume< T > copyStructure() const
Copy the full data structure without copying the actual data.
std::vector< int > Position
bool all() const
True if all values compare to true.
Volume< T > deepcopy() const
Copy the full data structure.
Volume< T > copy() const
Create a volume of same dimension and copy the data.
Volume< T > & operator=(const Volume< T > &other)
bool any() const
True if at least one value compares to true.
DataTypeTraits< T >::LongType sum() const
To avoid overflow, the biggest possible type (intmax_t, uintmax_t, double...) is used for computation...
void fill(const T &value)
Fills the volume with a given value.
void fillBorder(const T &value)
Fill border with a constant value.
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< T > & selfApply(Volume< T > &vol, UnaryFunction func)
Apply a function to all the elements of a volume (in place version)
Volume< typename UnaryFunction::result_type > apply(const Volume< T > &vol, UnaryFunction func)
Apply a function to all the elements of a volume (create output version)
carto::Volume< T > & operator*=(carto::Volume< T > &vol, const U &value)
carto::Volume< T > & operator^=(carto::Volume< T > &vol, const U &value)
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)
carto::Volume< T > & operator/=(carto::Volume< T > &vol, const U &value)
carto::Volume< bool > operator>=(const carto::Volume< T > &vol, const U &value)
carto::Volume< bool > operator!=(const carto::Volume< T > &vol, const U &value)
VoxelRGB operator/(const VoxelRGB &aa, const uint8_t &bb)
carto::Volume< bool > operator<=(const carto::Volume< T > &vol, const U &value)
VoxelRGB operator+(const VoxelRGB &aa, const VoxelRGB &bb)
T min(const Volume< T > &vol)
Returns the minimum value of the volume.
T max(const Volume< T > &vol)
Returns the maximum value of the volume.
carto::Volume< bool > operator<(const carto::Volume< T > &vol, const U &value)
DataTypeTraits< T >::LongType sum(const Volume< T > &vol)
Returns the sum of the volume values.
VoxelRGB operator-(const VoxelRGB &aa, const VoxelRGB &bb)
carto::Volume< bool > operator!(const carto::Volume< T > &vol)
bool all(const Volume< T > &vol)
Returns true if all values compare to true.
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)
VoxelRGB operator*(const VoxelRGB &aa, const uint8_t &bb)
carto::Volume< typename carto::volumeutil::bitwise_and< T, U >::result_type > operator&(const carto::Volume< T > &vol, const U &value)
carto::Volume< T > & operator&=(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)
carto::Volume< typename carto::volumeutil::bitwise_or< T, U >::result_type > operator|(const carto::Volume< T > &vol, const U &value)
carto::Volume< T > operator~(const carto::Volume< T > &vol)
carto::Volume< T > & operator%=(carto::Volume< T > &vol, const U &value)
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< bool > operator||(const carto::Volume< T > &vol, const U &value)
carto::Volume< bool > operator==(const carto::Volume< T > &vol, const U &value)
carto::Volume< T > operator++(carto::Volume< T > &vol, int)
carto::Volume< T > operator--(carto::Volume< T > &vol, int)
carto::Volume< T > & operator+=(carto::Volume< T > &vol, const U &value)
static bool all(const Volume< T > &vol)
static bool any(const Volume< T > &vol)
static bool all(const Volume< T > &)
static bool any(const Volume< T > &)
static T min(const Volume< T > &vol)
static DataTypeTraits< T >::LongType sum(const Volume< T > &vol)
static T max(const Volume< T > &vol)
static T max(const Volume< T > &)
static DataTypeTraits< T >::LongType sum(const Volume< T > &)
static T min(const Volume< T > &)