11 #ifndef BIOPROCESSING_GRAPH_VOLUMEGRAPH
12 #define BIOPROCESSING_GRAPH_VOLUMEGRAPH
19 #include <aims/connectivity/structuring_element.h>
20 #include <aims/math/mathelem.h>
21 #include <aims/vector/vector.h>
23 #include <cartodata/volume/volume.h>
27 template <
typename T,
typename P>
class VolumeGraph;
28 template <
typename T,
typename P>
class VolumeGraphRef;
33 T weightMin(
const T & a,
const T & b )
35 return ( a < b ? a : b );
56 template <
typename T,
typename P>
72 typedef carto::VolumeRef<Type>
Volume;
79 VolumeGraph(
int sx = 1,
int sy = 1,
int sz = 1,
int st = 1,
80 const aims::strel::Connectivity & conn
81 = aims::strel::Connectivity6XYZ() );
86 const aims::strel::Connectivity & conn
87 = aims::strel::Connectivity6XYZ() );
92 class vertex_const_iterator;
93 class vertex_iterator;
95 class edge_const_iterator;
177 template <
typename Set>
188 void setDimensions(
int sx = 1,
int sy = 1,
int sz = 1,
int st = 1 );
192 void setHeader(
float vx = 1.,
float vy = 1.,
float vz = 1.,
float vt = 1. );
198 template <
typename M>
202 void mask(
const carto::VolumeRef<M> &
mask );
221 template <
typename T,
typename P>
223 const aims::strel::Connectivity & conn ):
229 template <
typename T,
typename P>
231 const aims::strel::Connectivity & conn ):
237 template <
typename T,
typename P>
240 if( !inside( v.point() ) )
242 return access( v.point() ) != notPresentValue();
246 template <
typename T,
typename P>
249 if( !inside( e.x().point() ) || !inside( e.y().point() ) )
251 return ( access( e.x().point() ) != notPresentValue() ) &&
252 ( access( e.y().point() ) != notPresentValue() );
255 template <
typename T,
typename P>
259 for( t=0; t<_vol.getSizeT(); ++t )
260 for( z=0; z<_vol.getSizeZ(); ++z )
261 for( y=0; y<_vol.getSizeY(); ++y )
262 for( x=0; x<_vol.getSizeX(); ++x )
263 if( _vol( x, y, z, t ) != notPresentValue() )
268 template <
typename T,
typename P>
272 for( t=0; t<_vol.getSizeT(); ++t )
273 for( z=0; z<_vol.getSizeZ(); ++z )
274 for( y=0; y<_vol.getSizeY(); ++y )
275 for( x=0; x<_vol.getSizeX(); ++x )
276 _vol( x, y, z, t ) = notPresentValue();
279 template <
typename T,
typename P>
283 x = access( e.x().point() );
284 y = access( e.y().point() );
285 return _weight( x, y );
288 template <
typename T,
typename P>
292 x = access( e.x().point() );
293 y = access( e.y().point() );
294 return _weight( x, y );
297 template <
typename T,
typename P>
300 return std::numeric_limits<T>::min();
303 template <
typename T,
typename P>
306 return std::numeric_limits<T>::max();
309 template <
typename T,
typename P>
312 _vol->reallocate(sx,sy,sz,st);
315 template <
typename T,
typename P>
318 Point4d dim4(1,1,1,1);
319 for(
int i = 0; i < dim.size(); ++i )
321 setDimensions( dim4[0], dim4[1], dim4[2], dim4[3] );
324 template <
typename T,
typename P>
327 std::vector<float> vs(4,1.0);
334 template <
typename T,
typename P>
337 setHeader( vs[0], vs[1], vs[2], vs[3] );
340 template <
typename T,
typename P>
346 template <
typename T,
typename P>
347 template <
typename M>
350 ASSERT( ( mask.getSizeX() == _vol.getSizeX() ) &&
351 ( mask.getSizeY() == _vol.getSizeY() ) &&
352 ( mask.getSizeZ() == _vol.getSizeZ() ) &&
353 ( mask.getSizeT() == _vol.getSizeT() ) );
355 for( t=0; t<_vol.getSizeT(); ++t )
356 for( z=0; z<_vol.getSizeZ(); ++z )
357 for( y=0; y<_vol.getSizeY(); ++y )
358 for( x=0; x<_vol.getSizeX(); ++x )
360 _vol( x, y, z, t ) = notPresentValue();
363 template <
typename T,
typename P>
367 for(
int i = 0; i < p.size(); ++i )
369 return _vol( p4[0], p4[1], p4[2], p4[3] );
372 template <
typename T,
typename P>
376 for(
int i = 0; i < p.size(); ++i )
378 return _vol( p4[0], p4[1], p4[2], p4[3] );
381 template <
typename T,
typename P>
384 Point4d dim4(1,1,1,1);
385 dim4[0] = _vol.getSizeX();
386 dim4[1] = _vol.getSizeY();
387 dim4[2] = _vol.getSizeZ();
388 dim4[3] = _vol.getSizeT();
389 for(
int i = 0; i < p.size(); ++i )
390 if( p[1] < 0 || p[1] >= dim4[i] )
419 template <
typename T,
typename P>
436 _dim(vol.getSizeX(),vol.getSizeY(), vol.getSizeZ(), vol.getSizeT())
483 if( _cur[0] < _dim[0]-1 )
488 if( _cur[1] < _dim[1]-1 )
493 if( _cur[2] < _dim[2]-1 )
498 if( _cur[3] < _dim[3]-1 )
532 for(
int i = 0; i < p.size(); ++i )
544 template <
typename T,
typename P>
592 template <
typename T,
typename P>
605 typedef typename aims::StructuringElement::const_iterator
ConnIt;
614 _dim( vol.getSizeX(), vol.getSizeY(), vol.getSizeZ(), vol.getSizeT() ),
623 copy( _vtx.point(), _cur );
635 _dim( vol.getSizeX(), vol.getSizeY(), vol.getSizeZ(), vol.getSizeT() ),
644 copy( vb->point(), _cur );
742 _cur = Point4d(0,0,0,0);
747 if( _concur == _conend ) {
748 if( _vtx != Vertex::none() )
751 if( _vtxbeg == _vtxend )
756 copy( _vtxbeg->point(), _cur );
760 Point4d move(0,0,0,0);
761 copy( *_concur, move );
776 template <
typename P1,
typename P2>
777 void copy(
const P1 & p1, P2 & p2 )
779 int size = ( p1.size() > p2.size() ? p2.size() : p1.size() );
780 for(
int i = 0; i < size; ++i )
785 for(
int i = 0; i<4; ++i )
786 if( _nbr[i] < 0 || _nbr[i] >= _dim[i] )
807 template <
typename T,
typename P>
820 typedef typename aims::StructuringElement::const_iterator
ConnIt;
832 Base(vol,end,vb,ve,b,e)
860 template <
typename T,
typename P>
887 const aims::strel::Connectivity & conn
888 = aims::strel::Connectivity6XYZ() ):
934 template <
typename Set>
941 void setDimensions(
int sx = 1,
int sy = 1,
int sz = 1,
int st = 1 ) {
return ((
Pointed*)(this->get()))->setDimensions(sx,sy,sz,st); }
943 void setHeader(
float vx = 1.,
float vy = 1.,
float vz = 1.,
float vt = 1. ) {
return ((
Pointed*)(this->get()))->setHeader(vx,vy,vz,vt); }
946 template <
typename M>
Reference to a BaseGraph.
carto::rc_ptr< BaseGraph< E > > Base
virtual bool isAdjacent(const Vertex &x, const Vertex &y) const
virtual bool isAdjacentFrom(const Vertex &v, const Graph &g) const
virtual bool isSubGraph(const Graph &g) const
static Set getComplement(const Set &s, const Set &e)
virtual bool isLinked(const Vertex &x, const Vertex &y) const
virtual bool isConnectedComponent(const Graph &g) const
static G::Ref getConnectedComponent(G &thisg, Vertex &v)
virtual bool operator=(const This &other)
Edge::Vertex Vertex
Usable vertex type.
virtual bool isAdjacentTo(const Vertex &v, const Graph &g) const
Reference to a EWBaseGraph.
virtual Weight weight(const Edge &e)
Base class for edge weighted graphs.
virtual Weight Fm(const Vertex &v) const
Base::Vertex Vertex
Usable vertex type.
Base::Edge Edge
Usable edge type.
Reference to a VolumeGraph.
bool inside(const Point &p) const
vertex_iterator endVertex()
void mask(const carto::VolumeRef< M > &mask)
Pointed::edge_const_iterator edge_const_iterator
bool isAdjacentFrom(const Vertex &v, const Graph &g) const
void setDimensions(const Point &dim)
VolumeGraphRef(carto::VolumeRef< T > volume, const aims::strel::Connectivity &conn=aims::strel::Connectivity6XYZ())
Constructor from an exisiting volume and connectivity The volume is not copied, a reference to it is ...
Graph getConnectedComponent(Vertex &v)
edge_const_iterator beginEdge(const Vertex &v) const
static Type notPresentValue()
edge_iterator endEdge(const Vertex &v)
bool isLinked(const Vertex &x, const Vertex &y) const
edge_const_iterator endEdge(const Vertex &v) const
vertex_iterator beginVertex()
Pointed::vertex_const_iterator vertex_const_iterator
VolumeGraphRef(int sx=1, int sy=1, int sz=1, int st=1)
Constructor from volume dimensions and connectivity This initializes the graph so that it represents ...
Pointed::edge_iterator edge_iterator
VolumeGraphRef< T, P > This
bool isSubGraph(const Graph &g) const
static Type presentValue()
virtual ~VolumeGraphRef()
bool isAdjacentTo(const Vertex &v, const Graph &g) const
static Set getComplement(const Set &s, const Set &e)
vertex_const_iterator beginVertex() const
void setDimensions(int sx=1, int sy=1, int sz=1, int st=1)
static Graph none()
Empty pointer factory.
void setHeader(float vx=1., float vy=1., float vz=1., float vt=1.)
VolumeGraph< T, P > Pointed
bool isAdjacent(const Vertex &x, const Vertex &y) const
vertex_const_iterator endVertex() const
void setWeightMethod(Weight(*weight)(const Type &, const Type &))
EWBaseGraphRef< SetEdgeRef< PointVertexRef< P > >, T > Base
Pointed::vertex_iterator vertex_iterator
edge_iterator beginEdge(const Vertex &v)
T & access(const Point &p)
VolumeGraphRef(const Base &other)
Copy constructor (it copies the reference, it does not duplicate the pointed object)
VolumeGraphRef(Pointed *e)
Constructor from a pointer (the pointer should either be created by new, or be already referenced by ...
void setHeader(const Point4df &vs)
bool isConnectedComponent(const Graph &g) const
const T & access(const Point &p) const
Iterator on the edges of a volume graph.
bool operator!=(const This &o) const
This & operator=(const This &o)
const Edge * operator->() const
const Edge & operator*() const
edge_const_iterator(const NonConstThis &o)
VolumeGraph< T, P > Owner
bool operator==(const This &o) const
This & operator=(const NonConstThis &o)
edge_iterator NonConstThis
edge_const_iterator(const This &o)
bool operator==(const NonConstThis &o) const
vertex_const_iterator VertexIt
void copy(const P1 &p1, P2 &p2)
edge_const_iterator(const Volume &vol, bool end, VertexIt vb, VertexIt ve, ConnIt b, ConnIt e)
edge_const_iterator(const Volume &vol, bool end, const Vertex &v, ConnIt b, ConnIt e)
aims::StructuringElement::const_iterator ConnIt
bool operator!=(const NonConstThis &o) const
edge_iterator(const This &other)
VolumeGraph< T, P > Owner
edge_iterator(const Volume &vol, bool end, const Vertex &v, ConnIt b, ConnIt e)
Owner::edge_const_iterator Base
edge_iterator(const Volume &vol, bool end, VertexIt vb, VertexIt ve, ConnIt b, ConnIt e)
aims::StructuringElement::const_iterator ConnIt
This & operator=(const This &other)
Owner::edge_iterator This
Iterator on the vertices of a volume graph.
const Vertex & operator*() const
vertex_const_iterator(const NonConstThis &o)
VolumeGraph< T, P > Owner
vertex_const_iterator(const Volume &vol, bool end)
This & operator=(const This &o)
const Vertex * operator->() const
bool operator==(const NonConstThis &o) const
vertex_const_iterator This
bool operator!=(const NonConstThis &o) const
This & operator=(const NonConstThis &o)
vertex_iterator NonConstThis
bool operator==(const This &o) const
vertex_const_iterator(const This &o)
bool operator!=(const This &o) const
Owner::vertex_const_iterator Base
VolumeGraph< T, P > Owner
vertex_iterator(const This &other)
This & operator=(const This &other)
vertex_iterator(const Volume &in, bool end=false)
Volume graphs are a graph implementation specifically designed to represent volumes as graphs (vertic...
void setDimensions(int sx=1, int sy=1, int sz=1, int st=1)
Sets the dimensions of the underlying volume.
VolumeGraph< T, P > This
Type of *this.
void setWeightMethod(Weight(*weight)(const Type &, const Type &))
Sets the weight method.
bool isSubGraph(const Graph &g) const
Is g a sub-graph os this graph ? (Meaning all its edges and vertices are included in this graph)
bool empty() const
True if the graph contains no edges and vertices.
carto::VolumeRef< Type > Volume
Volume type.
Weight weight(const Edge &e)
Returns the weight of e.
Graph getConnectedComponent(Vertex &v)
Returns the (one and only) connected component of this graph containing v.
void insert(Edge e, Weight w=(Weight) 0)
Insertion of a weighted edge (undefined for now)
VolumeGraphRef< T, P > Ref
Reference type.
VolumeGraph(int sx=1, int sy=1, int sz=1, int st=1, const aims::strel::Connectivity &conn=aims::strel::Connectivity6XYZ())
Constructor from volume dimensions and connectivity This initializes the graph so that it represents ...
bool inside(const Point &p) const
True if p is a voxel from the underlying volume.
vertex_iterator beginVertex()
Iterator on all vertices.
Weight Fm(const Vertex &v) const
Returns the minimum weight of all edges containing v.
static Set getComplement(const Set &s, const Set &e)
Returns the complement of s in e.
BaseGraph< SetEdgeRef< PointVertexRef< P > > > BaseBase
Base class of Base (BaseGraph)
edge_const_iterator beginEdge() const
vertex_const_iterator endVertex() const
Iterator on all vertices.
Base::Edge Edge
Usable edge type (RC)
bool isLinked(const Vertex &x, const Vertex &y) const
Are x and y linked in the graph ?
edge_iterator beginEdge(const Vertex &v)
Iterator on the edges containing a given vertex.
bool contains(const Vertex &v) const
True if v is in the graph.
EWBaseGraph< SetEdgeRef< PointVertexRef< P > >, T > Base
Base class (EWBaseGraph)
void insert(Edge e)
Insertion of a new edge (undefined for now)
edge_const_iterator endEdge() const
Base::Vertex Vertex
Usable vertex type (RC)
T & access(const Point &p)
Access the volume at voxel p.
bool isAdjacentFrom(const Vertex &v, const Graph &g) const
vertex_iterator endVertex()
Iterator on all vertices.
VolumeGraphRef< T, P > Graph
Usable graph type (RC)
void mask(const carto::VolumeRef< M > &mask)
Mask the underlying volume using mask.
Weight(* _weight)(const Type &, const Type &)
bool isAdjacentTo(const Vertex &v, const Graph &g) const
Is v adjacent to g ? (Meaning v isn't in g and there exist an edge in this graph that contains v and ...
vertex_const_iterator beginVertex() const
Iterator on all edges (This::Edge)
bool isAdjacent(const Vertex &x, const Vertex &y) const
Are x and y adjacent in the graph ?
Base::Weight Weight
Weight type.
void clear()
Clear the graph from all edges and vertices.
edge_iterator endEdge(const Vertex &v)
Iterator on the edges containing a given vertex.
bool isConnectedComponent(const Graph &g) const
Is g a connected component in this graph (Meaning all its vertices are linked)
edge_const_iterator endEdge(const Vertex &v) const
Iterator on the edges containing a given vertex.
void setHeader(float vx=1., float vy=1., float vz=1., float vt=1.)
Sets the header of the underlying volume.
static Type presentValue()
Value whose meaning is "present".
edge_const_iterator beginEdge(const Vertex &v) const
Iterator on the edges containing a given vertex.
static Type notPresentValue()
Value whose meaning is "none".
edge_iterator beginEdge()
void insert(Vertex v)
Insertion of a new vertex (undefined for now)
aims::StructuringElement _conn