34 #ifndef CARTODATA_VOLUME_VOLUMEUTIL_H
35 #define CARTODATA_VOLUME_VOLUMEUTIL_H
58 namespace volumeutil {
69 inline bool sameSize(
const std::vector<int> & s1,
70 const std::vector<int> & s2 );
72 inline std::vector<int>
maxSize(
const std::vector<int> & s1,
73 const std::vector<int> & s2 );
75 inline std::vector<int>
minSize(
const std::vector<int> & s1,
76 const std::vector<int> & s2 );
81 template <
typename T,
typename UnaryFunction>
82 Volume<typename UnaryFunction::result_type>
83 apply(
const Volume<T> & vol, UnaryFunction func );
84 template <
typename T,
typename U,
typename BinaryFunction>
85 Volume<typename BinaryFunction::result_type>
86 apply(
const Volume<T> & vol1,
const Volume<U> & vol2, BinaryFunction func );
87 template <
typename T,
typename UnaryFunction>
88 rc_ptr<Volume<typename UnaryFunction::result_type> >
89 apply(
const rc_ptr<Volume<T> > & vol, UnaryFunction func );
90 template <
typename T,
typename U,
typename BinaryFunction>
91 rc_ptr<Volume<typename BinaryFunction::result_type> >
92 apply(
const rc_ptr<Volume<T> > & vol1,
const Volume<U> & vol2, BinaryFunction func );
97 template <
typename T,
typename UnaryFunction>
98 Volume<T> &
selfApply( Volume<T> & vol, UnaryFunction func );
99 template <
typename T,
typename U,
typename BinaryFunction>
100 Volume<T> &
selfApply( Volume<T> & vol1,
const Volume<U> & vol2, BinaryFunction func );
101 template <
typename T,
typename UnaryFunction>
102 rc_ptr<Volume<T> > &
selfApply( rc_ptr<Volume<T> > & vol, UnaryFunction func );
103 template <
typename T,
typename U,
typename BinaryFunction>
104 rc_ptr<Volume<T> > &
selfApply( rc_ptr<Volume<T> > & vol1,
const Volume<U> & vol2, BinaryFunction func );
113 template <
typename T,
typename OUTP,
typename UnaryFunction>
115 applyTowards(
const Volume<T> & vol, Volume<OUTP> & dst, UnaryFunction func );
116 template <
typename T,
typename OUTP,
typename UnaryFunction>
118 applyTowards(
const T & cst, Volume<OUTP> & dst, UnaryFunction func );
119 template <
typename T,
typename U,
typename OUTP,
typename BinaryFunction>
121 applyTowards(
const Volume<T> & vol1,
const Volume<U> & vol2, Volume<OUTP> & dst, BinaryFunction func );
122 template <
typename T,
typename U,
typename OUTP,
typename BinaryFunction>
124 applyTowards(
const Volume<T> & vol1,
const U & cst2, Volume<OUTP> & dst, BinaryFunction func );
140 template <
typename OUTP,
typename T,
typename BinaryFunction>
141 OUTP
accumulate(
const Volume<T> & vol, BinaryFunction func, OUTP initial );
142 template <
typename OUTP,
typename T,
typename BinaryFunction>
143 OUTP
accumulate(
const rc_ptr<Volume<T> > & vol, BinaryFunction func, OUTP initial );
155 template <
typename T>
156 void transfer(
const Volume<T> & src, Volume<T> & dst );
157 template <
typename T>
158 void transfer(
const rc_ptr<Volume<T> > & src, rc_ptr<Volume<T> > & dst );
159 template <
typename OUTP,
typename INP>
160 void transfer(
const Volume<INP> & src, Volume<OUTP> & dst );
161 template <
typename OUTP,
typename INP>
162 void transfer(
const rc_ptr<Volume<INP> > & src, rc_ptr<Volume<OUTP> > & dst );
168 template <
typename T>
169 Volume<T>
deepcopy(
const Volume<T> & src,
170 const std::vector<int> & size = std::vector<int>() );
171 template <
typename T>
173 const rc_ptr<Volume<T> > & src,
174 const std::vector<int> & size = std::vector<int>() );
175 template <
typename OUTP,
typename INP>
176 Volume<OUTP>
deepcopy(
const Volume<INP> & src,
177 const std::vector<int> & size = std::vector<int>() );
178 template <
typename OUTP,
typename INP>
180 const rc_ptr<Volume<INP> > & src,
181 const std::vector<int> & size = std::vector<int>() );
188 template <
typename T>
189 Volume<T>
copy(
const Volume<T> & src );
190 template <
typename T>
191 rc_ptr<Volume<T> >
copy(
const rc_ptr<Volume<T> > & src );
192 template <
typename OUTP,
typename INP>
193 Volume<OUTP>
copy(
const Volume<INP> & src );
194 template <
typename OUTP,
typename INP>
195 rc_ptr<Volume<OUTP> >
copy(
const rc_ptr<Volume<INP> > & src );
200 template <
typename T>
202 template <
typename T>
203 rc_ptr<Volume<T> >
copyStructure(
const rc_ptr<Volume<T> > & src );
204 template <
typename OUTP,
typename INP>
206 template <
typename OUTP,
typename INP>
207 rc_ptr<Volume<OUTP> >
copyStructure(
const rc_ptr<Volume<INP> > & src );
218 template <
typename T>
219 T
min(
const Volume<T> & vol );
220 template <
typename T>
221 T
min(
const rc_ptr<Volume<T> > & vol );
228 template <
typename T>
229 T
max(
const Volume<T> & vol );
230 template <
typename T>
231 T
max(
const rc_ptr<Volume<T> > & vol );
236 template <
typename T>
238 template <
typename OUTP,
typename T>
239 OUTP
sum(
const Volume<T> & vol );
240 template <
typename T>
242 template <
typename OUTP,
typename T>
243 OUTP
sum(
const rc_ptr<Volume<T> > & vol );
248 template <
typename T>
249 bool all(
const Volume<T> & vol );
250 template <
typename T>
251 bool all(
const rc_ptr<Volume<T> > & vol );
256 template <
typename T>
257 bool any(
const Volume<T> & vol );
258 template <
typename T>
259 bool any(
const rc_ptr<Volume<T> > & vol );
273 template <
typename T,
typename U>
274 Volume<bool>
valuesIn(
const Volume<T> & volume,
const U & set );
275 template <
typename T,
typename U>
276 rc_ptr<Volume<bool> >
valuesIn(
const rc_ptr<Volume<T> > & volume,
const U & set );
286 template <
typename T,
typename U>
287 Volume<bool>
valuesNotIn(
const Volume<T> & volume,
const U & set );
288 template <
typename T,
typename U>
289 rc_ptr<Volume<bool> >
valuesNotIn(
const rc_ptr<Volume<T> > & volume,
const U & set );
297 template <
typename T,
typename U>
298 void conditionalSet( Volume<T> & volume,
const Volume<U> & condition,
const T & value );
299 template <
typename T,
typename U>
300 void conditionalSet( rc_ptr<Volume<T> > & volume,
const rc_ptr<Volume<U> > & condition,
const T & value );
307 template <
typename T>
309 template <
typename T>
310 rc_ptr<Volume<T> >
invertMinMax(
const rc_ptr<Volume<T> > & volume );
314 template <
typename T>
315 VolumeRef<T>
matrix_product(
const Volume<T> & v1,
const Volume<T> & v2 );
317 template <
typename T>
319 const rc_ptr<Volume<T> > & v2 );
321 template <
typename T>
322 VolumeRef<T>
transpose(
const Volume<T> & v );
327 template <
typename T>
328 VolumeRef<T>
transpose(
const rc_ptr<Volume<T> > & v,
bool copy=
false );
332 template <
typename T>
336 if( thing->getSizeT() != 1 || thing->getSizeZ() != 1
337 || thing->getSizeY() != 1 )
338 throw std::runtime_error(
"diag expects a 1D (Nx1x1x1) vector as input");
340 int n = thing->getSizeX();
344 for(
int x = 0; x < n; x++ )
345 m->at( x, x ) = thing->at( x );
351 template <
typename T>
355 if( thing->getSizeT() != 1 || thing->getSizeZ() != 1 )
356 throw std::runtime_error(
357 "undiag expects a 2D (NxMx1x1) matrix as input");
359 int n =
std::min( thing->getSizeX(), thing->getSizeY() );
362 AllocatorContext::fast() ) );
364 for(
int x = 0; x < n; x++ )
365 m->at( x, 0 ) = thing->at( x, x );
382 template <
typename T>
384 const typename Volume<T>::Position4Di & top,
385 const typename Volume<T>::Position4Di & bottom
386 =
typename Volume<T>::Position4Di(-1, -1, -1, -1) );
389 template <
typename T>
391 const typename Volume<T>::Position4Di & top,
392 const typename Volume<T>::Position4Di & bottom
393 =
typename Volume<T>::Position4Di(-1, -1, -1, -1) );
403 template <
typename T>
405 const typename Volume<T>::Position4Di & top,
406 const typename Volume<T>::Position4Di & bottom
407 =
typename Volume<T>::Position4Di(-1, -1, -1, -1) );
410 template <
typename T>
412 const typename Volume<T>::Position4Di & top,
413 const typename Volume<T>::Position4Di & bottom
414 =
typename Volume<T>::Position4Di(-1, -1, -1, -1) );
422 std::vector<int> dim1 = v1.
getSize();
423 std::vector<int> dim2 = v2.
getSize();
424 int i, n1 = dim1.size(), n2 = dim2.size(), n =
std::min( n1, n2 );
426 if( dim1[i] != dim2[i] )
454 namespace volumeutil {
460 bool sameSize(
const std::vector<int> & s1,
const std::vector<int> & s2 )
466 for( i=0; i<s0; ++i )
469 for( ; i<s1.size(); ++i )
472 for( ; i<s2.size(); ++i )
479 std::vector<int>
maxSize(
const std::vector<int> & s1,
480 const std::vector<int> & s2 )
482 std::vector<int> dim(
std::max( s1.size(), s2.size() ), 1 );
487 for( i=0; i<s0; ++i )
489 for( ; i<s1.size(); ++i )
491 for( ; i<s2.size(); ++i )
497 std::vector<int>
minSize(
const std::vector<int> & s1,
498 const std::vector<int> & s2 )
500 std::vector<int> dim(
std::min( s1.size(), s2.size() ), 1 );
505 for( i=0; i<s0; ++i )
507 for( ; i<dim.size(); ++i )
515 template <
typename T,
typename UnaryFunction>
520 typedef typename UnaryFunction::result_type OUTP;
526 template <
typename T,
typename U,
typename BinaryFunction>
531 typedef typename BinaryFunction::result_type OUTP;
540 template <
typename T,
typename UnaryFunction>
545 typedef typename UnaryFunction::result_type OUTP;
551 template <
typename T,
typename U,
typename BinaryFunction>
556 typedef typename BinaryFunction::result_type OUTP;
565 template <
typename T,
typename UnaryFunction>
573 template <
typename T,
typename U,
typename BinaryFunction>
583 template <
typename T,
typename UnaryFunction>
591 template <
typename T,
typename U,
typename BinaryFunction>
600 template <
typename T,
typename OUTP,
typename UnaryFunction>
613 std::vector<int> pos( size.size(), 0 );
633 for( ; !it.
ended(); ++it, ++dit )
644 template <
typename T,
typename OUTP,
typename UnaryFunction>
653 OUTP value = func( cst );
654 for( ; !dit.
ended(); ++dit )
663 template <
typename T,
typename U,
typename OUTP,
typename BinaryFunction>
678 std::vector<int> pos( size.size(), 0 );
707 for( ; !it1.
ended(); ++it1, ++it2, ++dit )
715 *d = func( *p, *p2 );
720 template <
typename T,
typename U,
typename OUTP,
typename BinaryFunction>
731 std::vector<int> pos( size.size(), 0 );
754 for( ; !it2.
ended(); ++it2, ++dit )
760 *d = func( cst1, *p2 );
765 template <
typename T,
typename U,
typename OUTP,
typename BinaryFunction>
778 std::vector<int> pos( size.size(), 0 );
799 for( ; !it1.
ended(); ++it1, ++dit )
805 *d = func( *p, cst2 );
812 template <
typename OUTP,
typename T,
typename BinaryFunction>
819 for( ; !it.
ended(); ++it )
823 initial = func( initial, *p );
830 template <
typename OUTP,
typename T,
typename BinaryFunction>
834 return accumulate<OUTP, T, BinaryFunction>( *vol, func, initial );
845 template <
typename T>
849 transfer<T,T>( src, dst );
852 template <
typename T>
856 transfer<T,T>( src, dst );
859 template <
typename OUTP,
typename INP>
866 template <
typename OUTP,
typename INP>
875 template <
typename T>
879 return deepcopy<T,T>( src, size );
882 template <
typename T>
885 const std::vector<int> & size )
887 return deepcopy<T,T>( src, size );
890 template <
typename OUTP,
typename INP>
893 const std::vector<int> & size )
895 std::vector<int> nsize = size;
904 != AllocatorStrategy::Unallocated )
911 srcparent->getSize(),
912 srcparent->allocatorContext(),
913 srcparent->allocatorContext().isAllocated() ) );
914 if( srcparent->allocatorContext().isAllocated()
915 && srcparent->allocatorContext().allocatorType()
916 != AllocatorStrategy::Unallocated )
925 while( srcchild->refVolume().
get() )
929 srcparent->getSize(),
930 srcparent->allocatorContext(),
931 srcparent->allocatorContext().isAllocated() ) );
932 dstparent->copyHeaderFrom( srcparent->header() );
933 if( srcparent->allocatorContext().isAllocated()
934 && srcparent->allocatorContext().allocatorType()
935 != AllocatorStrategy::Unallocated )
937 dstchild->setRefVolume( dstparent );
938 dstchild->setPosInRefVolume( srcchild->posInRefVolume() );
939 srcchild = srcparent;
940 dstchild = dstparent;
946 template <
typename OUTP,
typename INP>
949 const std::vector<int> & size )
951 std::vector<int> nsize = size;
953 nsize = src->getSize();
956 src->allocatorContext(),
957 src->allocatorContext().isAllocated() ) );
958 dst->copyHeaderFrom( src->header() );
959 if( src->allocatorContext().isAllocated()
960 && src->allocatorContext().allocatorType()
961 != AllocatorStrategy::Unallocated )
967 while( srcchild->refVolume().
get() )
971 srcparent->getSize(),
972 srcparent->allocatorContext(),
973 srcparent->allocatorContext().isAllocated() ) );
974 dstparent->copyHeaderFrom( srcparent->header() );
975 if( srcparent->allocatorContext().isAllocated()
976 && srcparent->allocatorContext().allocatorType()
977 != AllocatorStrategy::Unallocated )
979 dstchild->setRefVolume( dstparent );
980 dstchild->setPosInRefVolume( srcchild->posInRefVolume() );
981 srcchild = srcparent;
982 dstchild = dstparent;
991 template <
typename T>
995 return copy<T,T>( src );
998 template <
typename T>
1002 return copy<T,T>( src );
1005 template <
typename OUTP,
typename INP>
1015 template <
typename OUTP,
typename INP>
1020 dst->copyHeaderFrom( src->header() );
1028 template <
typename T>
1032 return copyStructure<T,T>( src );
1035 template <
typename T>
1039 return copyStructure<T,T>( src );
1042 template <
typename OUTP,
typename INP>
1057 srcparent->getSize(),
1058 srcparent->allocatorContext(),
1059 srcparent->allocatorContext().isAllocated() ) );
1068 while( srcchild->refVolume().
get() )
1072 srcparent->getSize(),
1073 srcparent->allocatorContext(),
1074 srcparent->allocatorContext().isAllocated() ) );
1075 dstparent->copyHeaderFrom( srcparent->header() );
1078 dstchild->setRefVolume( dstparent );
1079 dstchild->setPosInRefVolume( srcchild->posInRefVolume() );
1080 srcchild = srcparent;
1081 dstchild = dstparent;
1089 template <
typename OUTP,
typename INP>
1098 src->allocatorContext(),
1099 src->allocatorContext().isAllocated() ) );
1100 dst->copyHeaderFrom( src->header() );
1107 while( srcchild->refVolume().
get() )
1111 srcparent->getSize(),
1112 srcparent->allocatorContext(),
1113 srcparent->allocatorContext().isAllocated() ) );
1114 dstparent->copyHeaderFrom( srcparent->header() );
1117 dstchild->setRefVolume( dstparent );
1118 dstchild->setPosInRefVolume( srcchild->posInRefVolume() );
1119 srcchild = srcparent;
1120 dstchild = dstparent;
1131 template <
typename T>
1137 throw std::runtime_error(
"Cannot compute min of an empty volume");
1141 template <
typename T>
1145 if( !vol.get() || ( vol->getSizeX() == 0 && vol->getSizeY() == 0 &&
1146 vol->getSizeZ() == 0 && vol->getSizeT() == 0 ) )
1147 throw std::runtime_error(
"Cannot compute min of an empty volume");
1151 template <
typename T>
1157 throw std::runtime_error(
"Cannot compute max of an empty volume");
1161 template <
typename T>
1165 if( !vol.get() || ( vol->getSizeX() == 0 && vol->getSizeY() == 0 &&
1166 vol->getSizeZ() == 0 && vol->getSizeT() == 0 ) )
1167 throw std::runtime_error(
"Cannot compute max of an empty volume");
1171 template <
typename T>
1175 return sum<typename DataTypeTraits<T>::LongType,T>( vol );
1179 template <
typename OUTP,
typename T>
1186 template <
typename T>
1190 return sum<typename DataTypeTraits<T>::LongType,T>( vol );
1193 template <
typename OUTP,
typename T>
1198 return static_cast<OUTP
>(0);
1202 template <
typename T>
1209 template <
typename T>
1216 template <
typename T>
1223 template <
typename T>
1235 template <
typename T,
typename U>
1236 struct inSet:
public std::binary_function<T, U, bool>
1240 for(
typename U::const_iterator k = y.begin(); k != y.end(); ++k )
1248 template <
typename T,
typename U>
1252 Volume<bool> output = copyStructure<bool, T>( volume );
1257 template <
typename T,
typename U>
1267 template <
typename T,
typename U>
1268 struct notInSet:
public std::binary_function<T, U, bool>
1272 for(
typename U::const_iterator k = y.begin(); k != y.end(); ++k )
1280 template <
typename T,
typename U>
1284 Volume<bool> output = copyStructure<bool, T>( volume );
1289 template <
typename T,
typename U>
1299 template <
typename T,
typename U>
1305 return y ? _value : x;
1312 template <
typename T,
typename U>
1319 template <
typename T,
typename U>
1327 template <
typename T>
1345 template <
typename T>
1354 template <
typename T>
1367 template <
typename T>
1377 if( b[0] != top[0] || b[1] != bot[0] ||
1378 b[2] != top[1] || b[3] != bot[1] ||
1379 b[4] != top[2] || b[5] != bot[2] ||
1380 b[6] != top[3] || b[7] != bot[3] )
1383 volume.
getSizeX() + top[0] + bot[0],
1384 volume.
getSizeY() + top[1] + bot[1],
1385 volume.
getSizeZ() + top[2] + bot[2],
1386 volume.
getSizeT() + top[3] + bot[3] ) );
1387 parent->copyHeaderFrom( volume.
header() );
1402 template <
typename T>
1411 std::vector<int> b = volume->getBorders();
1412 if( b[0] != top[0] || b[1] != bot[0] ||
1413 b[2] != top[1] || b[3] != bot[1] ||
1414 b[4] != top[2] || b[5] != bot[2] ||
1415 b[6] != top[3] || b[7] != bot[3] )
1418 volume->getSizeX() + top[0] + bot[0],
1419 volume->getSizeY() + top[1] + bot[1],
1420 volume->getSizeZ() + top[2] + bot[2],
1421 volume->getSizeT() + top[3] + bot[3] ) );
1422 parent->copyHeaderFrom( volume->header() );
1426 volume->getSizeT() );
1429 volume->reallocate( volume->getSizeX(), volume->getSizeY(),
1430 volume->getSizeZ(), volume->getSizeT(),
1431 true, volume->allocatorContext(),
false );
1432 volume->setRefVolume( parent );
1433 volume->setPosInRefVolume( top );
1437 template <
typename T>
1447 if( b[0] < top[0] || b[1] < bot[0] ||
1448 b[2] < top[1] || b[3] < bot[1] ||
1449 b[4] < top[2] || b[5] < bot[2] ||
1450 b[6] < top[3] || b[7] < bot[3] )
1453 volume.
getSizeX() + top[0] + bot[0],
1454 volume.
getSizeY() + top[1] + bot[1],
1455 volume.
getSizeZ() + top[2] + bot[2],
1456 volume.
getSizeT() + top[3] + bot[3] ) );
1457 parent->copyHeaderFrom( volume.
header() );
1472 template <
typename T>
1481 std::vector<int> b = volume->getBorders();
1482 if( b[0] < top[0] || b[1] < bot[0] ||
1483 b[2] < top[1] || b[3] < bot[1] ||
1484 b[4] < top[2] || b[5] < bot[2] ||
1485 b[6] < top[3] || b[7] < bot[3] )
1488 volume->getSizeX() + top[0] + bot[0],
1489 volume->getSizeY() + top[1] + bot[1],
1490 volume->getSizeZ() + top[2] + bot[2],
1491 volume->getSizeT() + top[3] + bot[3] ) );
1492 parent->copyHeaderFrom( volume->header() );
1496 volume->getSizeT() );
1499 volume->reallocate( volume->getSizeX(), volume->getSizeY(),
1500 volume->getSizeZ(), volume->getSizeT(),
1501 true, volume->allocatorContext(),
false );
1502 volume->setRefVolume( parent );
1503 volume->setPosInRefVolume( top );
1512 template <
typename T>
class VolumeRef;
1520 template <
typename T,
class BinaryFunction>
1525 :
value( x ),
f( func ) {}
1527 {
return f( y,
value ); }
1537 template <
typename T,
class BinaryFunction>
1542 :
value( x ),
f( func ) {}
1544 {
return f(
value, y ); }
1552 template <
typename T,
typename U>
1558 {
return (T) ( x *
scale ); }
1565 return x * (float) scale;
1571 return x * (float) scale;
1577 return x * (double) scale;
1583 return x * (double) scale;
1590 template <
typename T,
typename U>
1596 {
return (T) ( x /
divisor ); }
1603 return x * (float) ( 1. / divisor );
1609 return x * (float) ( 1. / (
double) divisor );
1615 return x * ( 1. / divisor );
1621 return x * (double) ( 1. / divisor );
1627 return x * (double) ( 1. / divisor );
1630 template <
typename T,
bool Scalar>
1635 template <
typename T>
1648 template <
typename T>
1653 template <
typename T>
1658 template <
class UnaryFunction>
static
1666 template <
class UnaryFunction>
static
1670 template <
class BinaryFunction>
static
1683 template <
class BinaryFunction>
static
1686 template <
class BinaryFunction>
static
1691 template <
typename T>
1700 for( j=1; j<n; ++j )
1702 tmp = thing.
at( j );
1704 while( i >= 0L && thing.
at( i ) > tmp )
1706 thing.
at( i + 1 ) = thing.
at( i );
1709 thing.
at( i + 1 ) = tmp;
1714 for( j=1; j<n; ++j )
1716 tmp = thing.
at( j );
1718 while( i >= 0L && thing.
at( i ) < tmp )
1720 thing.
at( i + 1 ) = thing.
at( i );
1723 thing.
at( i + 1 ) = tmp;
1729 template <
typename T>
1733 sort( *thing, ascending );
T operator()(const T &x) const
T operator()(const T &x) const
T operator()(const T &y) const
UnaryFromConstantBinaryFunctor2(const T &x, BinaryFunction func)
T operator()(const T &y) const
UnaryFromConstantBinaryFunctor(const T &x, BinaryFunction func)
std::vector< int > getSize() const
get the 4 dimensions in a vector
virtual void copyHeaderFrom(const PropertySet &other)
copy properties from other to this, avoiding forbidden properties like size.
Convenient handle for a Volume - this is normally the entry point for all volumes handling.
Volume utilities classes.
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
const AllocatorContext & allocatorContext() const
returns volume's AllocatorContext
void setPosInRefVolume(const Position4Di &pos)
Set position in parent volume.
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 std::vector< size_t > *strides=0)
allows resizing and changing allocator
const Position & posInRefVolume() const
Get position in parent volume.
std::vector< size_t > getStrides() const
Get strides for the volume.
void setRefVolume(const rc_ptr< Volume< T > > &refvol)
Set parent volume.
rc_ptr< Volume< T > > refVolume() const
Get parent 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
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)
OUTP accumulate(const Volume< T > &vol, BinaryFunction func, OUTP initial)
Accumulation over a volume.
OUTP accumulate(const rc_ptr< Volume< T > > &vol, BinaryFunction func, OUTP initial)
std::vector< int > minSize(const std::vector< int > &s1, const std::vector< int > &s2)
return the smallest dimensions between s1 and s2
Volume< T > & selfApply(Volume< T > &vol, UnaryFunction func)
Apply a function to all the elements of a volume (in place version)
std::vector< int > maxSize(const std::vector< int > &s1, const std::vector< int > &s2)
return the largest dimensions between s1 and s2
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)
bool sameSize(const std::vector< int > &s1, const std::vector< int > &s2)
Used by the actual Volume and VolumeRef operators It allows to keep the loops in one place and to spe...
bool any(const Volume< T > &vol)
Returns true if at least one value compares to true.
Volume< bool > valuesIn(const Volume< T > &volume, const U &set)
Find values contained in a set.
Volume< T > invertMinMax(const Volume< T > &volume)
Invert a volume between its min and max values.
bool isSameVolumeSize(const Volume< T > &v1, const Volume< T > &v2)
Volume< T > deepcopy(const Volume< T > &src, const std::vector< int > &size=std::vector< int >())
Performs a copy of the data (not only a reference copy) The whole view hierarchy is fully duplicated.
void conditionalSet(Volume< T > &volume, const Volume< U > &condition, const T &value)
Conditionally fill a volume.
void transfer(const Volume< T > &src, Volume< T > &dst)
Transfer data from an allocated volume to another Allocated sizes must be equal (same number of voxel...
Volume< T > copyStructure(const Volume< T > &src)
Performs a copy of the view structure without transfering the data.
T min(const rc_ptr< Volume< T > > &vol)
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.
DataTypeTraits< T >::LongType sum(const Volume< T > &vol)
Returns the sum of the volume values.
void sort(Volume< T > &thing, bool ascending=true)
VolumeRef< T > matrix_product(const Volume< T > &v1, const Volume< T > &v2)
matrix product
VolumeRef< T > transpose(const Volume< T > &v)
transpose
bool all(const Volume< T > &vol)
Returns true if all values compare to true.
rc_ptr< Volume< T > > undiag(const rc_ptr< Volume< T > > &thing)
void setBorders(Volume< T > &volume, const typename Volume< T >::Position4Di &top, const typename Volume< T >::Position4Di &bottom=typename Volume< T >::Position4Di(-1, -1, -1, -1))
Set border width.
void setMinBorders(Volume< T > &volume, const typename Volume< T >::Position4Di &top, const typename Volume< T >::Position4Di &bottom=typename Volume< T >::Position4Di(-1, -1, -1, -1))
Set border width.
rc_ptr< Volume< T > > diag(const rc_ptr< Volume< T > > &thing)
Build a diagonal matrix from a line (1D) vector.
Volume< bool > valuesNotIn(const Volume< T > &volume, const U &set)
Find values not contained in a set.
T max(const rc_ptr< Volume< T > > &vol)
bool operator()(const T &x, const U &y)
bool operator()(const T &x, const U &y)
invMinMax(const T &min, const T &max)
bool operator()(const T &x, const U &y)
std::complex< double > cdouble
std::complex< float > cfloat