11 #ifndef PRIMATOLOGIST_UTILITY_VOLUME_D_H
12 #define PRIMATOLOGIST_UTILITY_VOLUME_D_H
15 #include <aims/vector/vector.h>
16 #include <cartodata/volume/volume.h>
24 carto::VolumeRef<T> vol( (carto::Volume<T>*)0 );
29 carto::VolumeRef<T>
select(
const carto::VolumeRef<T> & in,
int t )
31 return in.view( Point4di( 0, 0, 0, t ),
32 Point4di( in.getSizeX(), in.getSizeY(),
36 template <
typename P,
typename T>
37 bool inside(
const P & p,
const carto::VolumeRef<T> & input )
39 std::vector<int> size = input.getSize();
40 for(
int i = 0; i < p.size(); ++i )
41 if( p[i] < 0 || p[i] >= size[i] )
46 template <
typename P,
typename T>
49 std::vector<int> size = input.getSize();
50 std::vector<int> b = input.getBorders();
51 for(
int i = 0; i < p.size(); ++i )
52 if( p[i] < -b[i/2] || p[i] >= size[i] + b[i/2+1] )
58 bool inside(
const Point4di & p,
const carto::VolumeRef<T> & input )
60 return 0 <= p[0] && p[0] < input.getSizeX() &&
61 0 <= p[1] && p[1] < input.getSizeY() &&
62 0 <= p[2] && p[2] < input.getSizeZ() &&
63 0 <= p[3] && p[3] < input.getSizeT();
69 std::vector<int> b = input.getBorders();
70 return -b[0] <= p[0] && p[0] < input.getSizeX() + b[1] &&
71 -b[2] <= p[1] && p[1] < input.getSizeY() + b[3] &&
72 -b[4] <= p[2] && p[2] < input.getSizeZ() + b[5] &&
73 -b[6] <= p[3] && p[3] < input.getSizeT() + b[7];
76 template <
typename T,
typename M>
78 clip( carto::VolumeRef<T> & in,
81 const carto::VolumeRef<M> & mask )
83 for(
int z = 0; z < in.getSizeZ(); ++z )
84 for(
int y = 0; y < in.getSizeY(); ++y )
85 for(
int x = 0; x < in.getSizeX(); ++x )
86 if( !mask.get() || mask( x, y, z ) != 0 )
87 for(
int t = 0; t < in.getSizeT(); ++t )
89 if( in( x, y,z , t) <
min )
90 in( x, y, z, t ) =
min;
91 else if( in( x, y, z, t ) >
max )
92 in( x, y, z, t ) =
max;
99 clip( carto::VolumeRef<T> & in,
103 return clip( in,
min,
max, vol::empty<int>() );
106 template <
typename T,
typename M>
111 const carto::VolumeRef<M> & mask )
113 carto::VolumeRef<T> copy = in.copy();
118 template <
typename T>
124 carto::VolumeRef<T> copy = in.copy();
129 template <
typename T1,
typename T2,
typename M>
132 const carto::VolumeRef<T2> & two,
133 const carto::VolumeRef<M> & mask )
135 if( one.getSizeX() != two.getSizeX() ||
136 one.getSizeY() != two.getSizeY() ||
137 one.getSizeZ() != two.getSizeZ() ||
138 one.getSizeT() != two.getSizeT() )
139 throw std::invalid_argument(
"aims::vol::sumLogicalDiff: volumes "
140 "should have similar dimensions" );
143 for(
int z = 0; z < one.getSizeZ(); ++z )
144 for(
int y = 0; y < one.getSizeY(); ++y )
145 for(
int x = 0; x < one.getSizeX(); ++x )
146 if( !mask.get() || mask( x, y, z ) != 0 )
147 for(
int t = 0; t < one.getSizeT(); ++t )
148 if( one( x, y, z, t ) != two( x, y, z, t ) )
153 template <
typename T1,
typename T2>
156 const carto::VolumeRef<T2> & two )
161 template <
typename T,
typename M>
162 typename carto::DataTypeTraits<T>::LongType
163 sum(
const carto::VolumeRef<T> & in,
164 const carto::VolumeRef<M> & mask )
166 typename carto::DataTypeTraits<T>::LongType aggregate = 0;
167 for(
int z = 0; z < in.getSizeZ(); ++z )
168 for(
int y = 0; y < in.getSizeY(); ++y )
169 for(
int x = 0; x < in.getSizeX(); ++x )
170 if( !mask.get() || mask( x, y, z ) != 0 )
171 for(
int t = 0; t < in.getSizeT(); ++t )
173 aggregate += in( x, y, z, t );
float min(float x, float y)
float max(float x, float y)
carto::DataTypeTraits< T >::LongType sum(const carto::VolumeRef< T > &in, const carto::VolumeRef< M > &mask)
uintmax_t sumLogicalDiff(const carto::VolumeRef< T1 > &one, const carto::VolumeRef< T2 > &two, const carto::VolumeRef< M > &mask)
bool insideAllocated(const P &p, const carto::VolumeRef< T > &input)
carto::VolumeRef< T > empty()
carto::VolumeRef< T > select(const carto::VolumeRef< T > &in, int t)
carto::VolumeRef< T > newClip(carto::VolumeRef< T > &in, const typename type::identity< T >::type &min, const typename type::identity< T >::type &max, const carto::VolumeRef< M > &mask)
bool inside(const P &p, const carto::VolumeRef< T > &input)
carto::VolumeRef< T > & clip(carto::VolumeRef< T > &in, const typename type::identity< T >::type &min, const typename type::identity< T >::type &max, const carto::VolumeRef< M > &mask)