11 #ifndef BIOPROCESSING_WATERSHED_COUSTYFLOWMAP
12 #define BIOPROCESSING_WATERSHED_COUSTYFLOWMAP
17 #include <aims/vector/vector.h>
19 #include <cartodata/volume/volume.h>
21 #include <cartobase/smart/rcptr.h>
22 #include <cartobase/smart/refwrapper.h>
30 template <
typename V,
typename L>
class CoustyFlowMap;
31 template <
typename V,
typename L>
class CoustyFlowMapRef;
47 template <
typename V,
typename L>
74 const_iterator
begin()
const {
return const_iterator(_volume,
false); }
75 const_iterator
end()
const {
return const_iterator(_volume,
true); }
76 iterator
begin() {
return iterator(_volume,
false); }
77 iterator
end() {
return iterator(_volume,
true); }
84 template <
typename Iterator>
85 void init( Iterator b, Iterator e )
89 for( i = b; i != e; ++i )
91 const typename Iterator::Point & p = i->point();
92 _volume( p[0], p[1], p[2], p[3] ) = labelNone();
98 return std::numeric_limits<L>::max();
103 if( std::numeric_limits<L>::min() < 0 )
106 return std::numeric_limits<L>::max() - 1;
112 return _volume( p[0], p[1], p[2], p[3] );
118 _volume( p[0], p[1], p[2], p[3] ) = lab;
123 _minima( p[0], p[1], p[2], p[3] ) = 1;
131 size_t size()
const {
return (
size_t) _volume.getSizeX() *
132 (size_t) _volume.getSizeY() *
133 (size_t) _volume.getSizeZ() *
134 (size_t) _volume.getSizeT(); }
146 _minima->reallocate( in.getSizeX(), in.getSizeY(), in.getSizeZ(), in.getSizeT() );
151 _volume->reallocate( sx, sy, sz, st );
152 _minima->reallocate( sx, sy, sz, st );
157 _volume->copyHeaderFrom( h );
158 _minima->copyHeaderFrom( h );
172 template <
typename L>
178 typedef std::pair<Vertex,carto::reference_wrapper<L> >
IterType;
185 _dimensions(in.getSizeX(),in.getSizeY(),in.getSizeZ(),in.getSizeT())
198 const_iterator &
operator=(
const const_iterator & other )
200 _current = other._current;
201 _dimensions = other._dimensions;
202 _volume = other._volume;
207 _current = other._current;
208 _dimensions = other._dimensions;
209 _volume = other._volume;
214 if( _current.first.point()[0] < _dimensions[0]-1 )
215 ++( _current.first.point()[0] );
218 _current.first.point()[0] = 0;
219 if( _current.first.point()[1] < _dimensions[1]-1 )
220 ++( _current.first.point()[1] );
223 _current.first.point()[1] = 0;
224 if( _current.first.point()[2] < _dimensions[2]-1 )
225 ++( _current.first.point()[2] );
228 _current.first.point()[2] = 0;
229 if( _current.first.point()[3] < _dimensions[3]-1 )
230 ++( _current.first.point()[3] );
241 const_iterator prev = *
this;
249 return other._current.first == _current.first;
251 bool operator==(
const iterator & other )
const {
return other == *
this; }
252 bool operator!=(
const const_iterator & other )
const {
return !( other == *this ); }
253 bool operator!=(
const iterator & other )
const {
return !( other == *this ); }
256 void toBegin() { _current.first =
Vertex(Point4dl(0,0,0,0)); computeLabel(); }
257 void toEnd() { _current.first =
Vertex(_dimensions); computeLabel(); }
260 if( _current.first.point() != _dimensions )
261 _current.second = carto::wrap::ref(
262 _volume( _current.first.point()[0], _current.first.point()[1],
263 _current.first.point()[2], _current.first.point()[3] ) );
265 _current.second = carto::wrap::ref(noneref());
274 template <
typename L>
276 public CoustyFlowMap<PointVertexRef<Point4dl>,L>::const_iterator
279 iterator( carto::VolumeRef<L> in,
bool end =
false ): const_iterator(in,end) {}
282 iterator(
const iterator & other ): const_iterator(other) {}
286 typedef std::pair<Vertex,carto::reference_wrapper<L> >
IterType;
288 iterator &
operator=(
const iterator & other ) { const_iterator::operator=(other); }
289 iterator &
operator++() { const_iterator::operator++();
return *
this; }
292 iterator prev = *
this;
297 IterType * operator->() {
return &(this->_current); }
309 template <
typename V,
typename L>
321 template <
typename L>
323 public carto::rc_ptr<CoustyFlowMap<PointVertexRef<Point4dl>,L> >
327 typedef carto::rc_ptr<CoustyFlowMap<PointVertexRef<Point4dl>,L> >
Base;
348 template <
typename Iterator>
349 void init( Iterator b, Iterator e ) {
return (*this)->init(b,e); }
355 carto::VolumeRef<L>
volume() {
return (*this)->volume(); }
356 size_t size()
const {
return (*this)->size(); }
357 carto::VolumeRef<L>
getMinima() {
return (*this)->getMinima(); }
364 {
return (*this)->setVolume(in); }
366 {
return (*this)->setDimensions(sx,sy,sz,st); }
368 {
return (*this)->setHeader(h); }
carto::rc_ptr< CoustyFlowMap< PointVertexRef< Point4dl >, L > > Base
void setVolume(carto::VolumeRef< L > in)
Pointed::iterator iterator
void setDimensions(int sx=1, int sy=1, int sz=1, int st=1)
Pointed::const_iterator const_iterator
void init(Iterator b, Iterator e)
void setLabel(Vertex v, L lab)
CoustyFlowMap< PointVertexRef< Point4dl >, L > Pointed
void setHeader(const carto::PropertySet &h)
const_iterator end() const
carto::VolumeRef< L > getMinima()
carto::VolumeRef< L > volume()
void setMinimum(Vertex v)
const_iterator begin() const
Reference counting pointer to a CoustyFlowMap.
bool operator==(const const_iterator &other) const
const_iterator & operator++()
const_iterator(const iterator &other)
const IterType * operator->() const
std::pair< Vertex, carto::reference_wrapper< L > > IterType
const_iterator & operator=(const const_iterator &other)
bool operator!=(const iterator &other) const
const_iterator(const const_iterator &other)
const_iterator operator++(int)
const_iterator & operator=(const iterator &other)
carto::VolumeRef< L > _volume
const IterType & operator*() const
bool operator!=(const const_iterator &other) const
CoustyFlowMap< PointVertexRef< Point4dl >, L > Owner
bool operator==(const iterator &other) const
const_iterator(carto::VolumeRef< L > in, bool end=false)
iterator & operator=(const iterator &other)
iterator(carto::VolumeRef< L > in, bool end=false)
iterator(const iterator &other)
std::pair< Vertex, carto::reference_wrapper< L > > IterType
CoustyFlowMap< PointVertexRef< Point4dl >, L > Owner
Flow map specialization for PointVertexRef<Point4dl> (as used by CoustyWatershed)
PointVertexRef< Point4dl > Vertex
Usable vertex type.
carto::VolumeRef< L > _minima
void setMinimum(Vertex v)
void setHeader(const carto::PropertySet &h)
Set the underlying volume's header.
size_t size() const
Get the number of voxels/vertices.
void setLabel(Vertex v, L lab)
Set a value ti vertex v.
void setDimensions(int sx=1, int sy=1, int sz=1, int st=1)
Set the underlying volume's dimensions.
L labelMinus() const
Minimumvalue (see CoustyWatershed and Cousty et al 2007)
const_iterator begin() const
iterator pointing to a pair<PointVertexRef,L>
const_iterator end() const
L label(Vertex v) const
Get the label of vertex v.
carto::VolumeRef< L > getMinima()
CoustyFlowMap()
Default constructor: builds an empty volume.
void setVolume(carto::VolumeRef< L > in)
Set the underlying volume.
L labelNone() const
None value (see CoustyWatershed and Cousty et al 2007)
carto::VolumeRef< L > volume()
Get the underlying volume.
carto::VolumeRef< L > _volume
void init(Iterator b, Iterator e)
FlowMap initialization For all given vertices, the none value (see labelNone()) is given to the map.
A flow map is a mapping of the vertices of a graph to a value.
Reference counting pointer to a PointVertex.
Pointed::Point Point
Point.
const Point & point() const
constant accessor to the coordinates