34 #ifndef CARTODATA_VOLUME_VOLUMEUTIL_D_H 
   35 #define CARTODATA_VOLUME_VOLUMEUTIL_D_H 
   60   T internal_max( 
const T x, 
const T y )
 
   61   { 
return std::max<T>( x, y ); }
 
   65   T internal_min( 
const T x, 
const T y )
 
   66   { 
return std::min<T>( x, y ); }
 
   73   template <
typename T> 
template <
class UnaryFunction>
 
   84     for( ; !it.
ended(); ++it, ++rit )
 
  148   template <
typename T> 
template <
class BinaryFunction>
 
  150                                      const VolumeRef<T> & o1,
 
  151                                      const VolumeRef<T> & o2 )
 
  153     std::cout << 
"VolumeUtil::apply(BinaryFunction)\n";
 
  154     std::vector<int> ns = o1->getSize(), s1 = ns, s2 = o2->getSize();
 
  155     while( ns.size() < s2.size() )
 
  156       ns.push_back( s2[ ns.size() ] );
 
  158     for( 
int i=0; i<s2.size(); ++i )
 
  162       std::cout << 
"size " << i << 
": " << ns[i] << std::endl;
 
  167     int x, nx = o1->getSizeX(), y, ny = o1->getSizeY(),
 
  168       z, nz = o1->getSizeZ(), t, nt = o1->getSizeT(), nx2, ny2, nz2, nt2, nx3;
 
  169     if( o2->getSizeX() < nx )
 
  175       nx2 = o2->getSizeX();
 
  176     if( o2->getSizeY() < ny )
 
  182       ny2 = o2->getSizeY();
 
  183     if( o2->getSizeZ() < nz )
 
  189       nz2 = o2->getSizeZ();
 
  190     if( o2->getSizeT() < nt )
 
  196       nt2 = o2->getSizeT();
 
  198     VolumeRef<T>        res( 
new Volume<T>( ns ) );
 
  199     res->copyHeaderFrom( o1->header() );
 
  201     bool        x1, y1, z1, x2, y2, z2;
 
  203     for( t=0; t<nt2; ++t )
 
  206           if( nt == o1->getSizeT() )
 
  222         for( z=0; z<nz2; ++z )
 
  228               if( nz == o1->getSizeZ() )
 
  234             for( y=0; y<ny2; ++y )
 
  240                   if( ny == o1->getSizeY() )
 
  246                   o1p = &o1->at( 0, y, z, t );
 
  250                   o2p = &o2->at( 0, y, z, t );
 
  253                 rp = &res->at( 0, y, z, t );
 
  266                     res->at( x, y, z, t ) = f( o1->at( x, y, z, t ),
 
  267                                                o2->at( x, y, z, t ) );
 
  269                   if( nx == o1->getSizeX() )
 
  275                   nx3 = o1->getSizeX();
 
  277                   nx3 = o2->getSizeX();
 
  282                     res->at( x, y, z, t ) = f( internal::_neutral<T>(),
 
  283                                                o2->at( x, y, z, t ) );
 
  286                     res->at( x, y, z, t ) = f( o1->at( x, y, z, t ),
 
  287                                                internal::_neutral<T>() );
 
  289                   res->at( x, y, z, t ) = f( internal::_neutral<T>(),
 
  290                                              internal::_neutral<T>() );
 
  298   template <
typename T> 
template <
class UnaryFunction>
 
  304     for( ; !it.
ended(); ++it )
 
  313   template <
typename T> 
template <
class BinaryFunction>
 
  335     for( ; !o1it.
ended(); ++o1it, ++o2it )
 
  341         *o1p = f( *o1p, *o2p );
 
  346   template <
typename T> 
template <
class BinaryFunction>
 
  356     for( ; !it.
ended(); ++it )
 
  367   template <
typename T>
 
  374   template <
typename T>
 
  378               internal_max<T>, o, min_limit<T>() );
 
  383   template <
typename T>
 
  386     std::vector<int> size1 = v1.
getSize();
 
  387     std::vector<int> size2 = v2.
getSize();
 
  388     if( size1[1] != size2[0] )
 
  389       throw std::runtime_error( 
"matrix dimensions do not match" );
 
  393     for( 
long y = 0; y < size2[1]; y++ )
 
  394       for( 
long x = 0; x < size1[0]; x++ )
 
  396         prod->
at( x, y ) = T( 0 );
 
  397         for( 
long k = 0; k < size1[1]; k++ )
 
  398           prod->
at( x, y ) += v1.
at( x, k ) * v2.
at( k, y );
 
  406   template <
typename T>
 
  415   template <
typename T>
 
  418     std::vector<int> size1 = v.
getSize();
 
  429     long inc = &trans->
at(0, 1) - &trans->
at(0);
 
  431     for( ; !it.
ended(); ++it )
 
  434       std::vector<int> pos = it.
position();
 
  438       rp = &trans->
at( pos );
 
  450   template <
typename T>
 
  457       std::vector<int> size1 = v->getSize();
 
  462       std::vector<size_t> strides = v->getStrides();
 
  463       size_t st0 = strides[0];
 
  464       strides[0] = strides[1];
 
  468                                          std::vector<int>( size1.size(), 0 ),
 
  478   extern template VolumeRef<VoxelRGB>
 
  480                               const VolumeRef<VoxelRGB> & );
 
  483                                   VolumeRef<VoxelRGB> & );
 
  484   extern template VolumeRef<VoxelRGB>
 
  486                               const VolumeRef<VoxelRGB> & );
 
  489                                   const VolumeRef<VoxelRGB> & );
 
  490   extern template VolumeRef<VoxelRGB>
 
  492                               std::plus<VoxelRGB> >,
 
  493                               const VolumeRef<VoxelRGB> & );
 
  496                                   std::plus<VoxelRGB> >, VolumeRef<VoxelRGB> & );
 
  497   extern template VolumeRef<VoxelRGB>
 
  499                               std::plus<VoxelRGB> >,
 
  500                               const VolumeRef<VoxelRGB> & );
 
  501   extern template VolumeRef<VoxelRGB>
 
  503                               const VolumeRef<VoxelRGB> & );
 
  506                                   const VolumeRef<VoxelRGB> & );
 
  507   extern template VolumeRef<VoxelRGB>
 
  509                               std::minus<VoxelRGB> >,
 
  510                               const VolumeRef<VoxelRGB> & );
 
  513                                   std::minus<VoxelRGB> >,
 
  514                                   VolumeRef<VoxelRGB> & );
 
  515   extern template VolumeRef<VoxelRGB>
 
  517                               std::minus<VoxelRGB> >,
 
  518                               const VolumeRef<VoxelRGB> & );
 
  520   extern template VolumeRef<VoxelRGBA>
 
  522                                const VolumeRef<VoxelRGBA> & );
 
  525                                    VolumeRef<VoxelRGBA> & );
 
  526   extern template VolumeRef<VoxelRGBA>
 
  528                                const VolumeRef<VoxelRGBA> &,
 
  529                                const VolumeRef<VoxelRGBA> & );
 
  532                                    const VolumeRef<VoxelRGBA> & );
 
  533   extern template VolumeRef<VoxelRGBA>
 
  535                                std::plus<VoxelRGBA> >,
 
  536                                const VolumeRef<VoxelRGBA> & );
 
  539                                    std::plus<VoxelRGBA> >,
 
  540                                    VolumeRef<VoxelRGBA> & );
 
  541   extern template VolumeRef<VoxelRGBA>
 
  543                                std::plus<VoxelRGBA> >,
 
  544                                const VolumeRef<VoxelRGBA> & );
 
  545   extern template VolumeRef<VoxelRGBA>
 
  547                                const VolumeRef<VoxelRGBA> &,
 
  548                                const VolumeRef<VoxelRGBA> & );
 
  551                                    VolumeRef<VoxelRGBA> &,
 
  552                                    const VolumeRef<VoxelRGBA> & );
 
  553   extern template VolumeRef<VoxelRGBA>
 
  555                                std::minus<VoxelRGBA> >,
 
  556                                const VolumeRef<VoxelRGBA> & );
 
  559                                    std::minus<VoxelRGBA> >,
 
  560                                    VolumeRef<VoxelRGBA> & );
 
  561   extern template VolumeRef<VoxelRGBA>
 
  563                                std::minus<VoxelRGBA> >,
 
  564                                const VolumeRef<VoxelRGBA> & );
 
const std::vector< int > & position() const
std::vector< int > getSize() const
get the 4 dimensions in a vector
Convenient handle for a Volume - this is normally the entry point for all volumes handling.
std::vector< int > getSize() const
const T & at(long x, long y=0, long z=0, long t=0) const
const PropertySet & header() const
std::vector< size_t > getStrides() const
static T accumulate(BinaryFunction f, const VolumeRef< T > &o2, T initial)
Apply a binary function to each voxel of the volume, with a "current" value as second argument.
static void selfApply(UnaryFunction f, VolumeRef< T > &o)
applies a binary function to each voxel of a pair of volumes
static VolumeRef< T > apply(UnaryFunction f, const VolumeRef< T > &o)
applies a unary function to each voxel of a volume
std::vector< size_t > getStrides() const
Get strides for the volume.
std::vector< int > getBorders() const
Get borders for the volume.
const T & at(long x, long y=0, long z=0, long t=0) const
void inc_line_ptr(const T *&p) const
void inc_line_ptr(T *&p) const
uint8_t _neutral< uint8_t >()
int8_t _neutral< int8_t >()
double _neutral< double >()
uint16_t _neutral< uint16_t >()
int16_t _neutral< int16_t >()
int32_t _neutral< int32_t >()
float _neutral< float >()
uint32_t _neutral< uint32_t >()
Volume< T > copy(const Volume< T > &src)
Performs a copy of the data (not only a reference copy) Only the data inside the view is copied.
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.
VolumeRef< T > matrix_product(const Volume< T > &v1, const Volume< T > &v2)
matrix product
VolumeRef< T > transpose(const Volume< T > &v)
transpose