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;
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;
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>
192 void setHeader(
float vx = 1.,
float vy = 1.,
float vz = 1.,
float vt = 1. );
198 template <
typename M>
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() ) )
246 template <
typename T,
typename P>
249 if( !
inside( e.x().point() ) || !
inside( e.y().point() ) )
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 )
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 )
279 template <
typename T,
typename P>
283 x =
access( e.x().point() );
284 y =
access( e.y().point() );
288 template <
typename T,
typename P>
292 x =
access( e.x().point() );
293 y =
access( e.y().point() );
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 )
324 template <
typename T,
typename P>
327 std::vector<float> vs(4,1.0);
334 template <
typename T,
typename P>
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 )
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())
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() ),
635 _dim( vol.getSizeX(), vol.getSizeY(), vol.getSizeZ(), vol.getSizeT() ),
742 _cur = Point4d(0,0,0,0);
748 if(
_vtx != Vertex::none() )
760 Point4d move(0,0,0,0);
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 )
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>
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)
virtual bool isAdjacentTo(const Vertex &v, const Graph &g) const
virtual Weight weight(const Edge &e)
Base class for edge weighted graphs.
virtual Weight Fm(const Vertex &v) const
Reference to a VolumeGraph.
bool inside(const Point &p) const
vertex_iterator endVertex()
const T & access(const Point &p) const
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)
T & access(const Point &p)
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)
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
Iterator on the edges of a volume graph.
bool operator!=(const This &o) const
edge_const_iterator(const NonConstThis &o)
VolumeGraph< T, P > Owner
bool operator==(const This &o) const
This & operator=(const NonConstThis &o)
const Edge & operator*() const
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
This & operator=(const This &o)
const Edge * operator->() const
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
Owner::edge_iterator This
This & operator=(const This &other)
Iterator on the vertices of a volume graph.
vertex_const_iterator(const NonConstThis &o)
This & operator=(const This &o)
VolumeGraph< T, P > Owner
const Vertex & operator*() const
vertex_const_iterator(const Volume &vol, bool end)
const Vertex * operator->() const
bool operator==(const NonConstThis &o) const
vertex_const_iterator This
bool operator!=(const NonConstThis &o) const
vertex_iterator NonConstThis
bool operator==(const This &o) const
This & operator=(const NonConstThis &o)
vertex_const_iterator(const This &o)
bool operator!=(const This &o) const
This & operator=(const This &other)
Owner::vertex_const_iterator Base
VolumeGraph< T, P > Owner
vertex_iterator(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.
bool contains(const Edge &e) const
True if e is in the graph.
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 ?
VolumeGraph(const Volume &in, 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 ...
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 ...
Weight weight(const Edge &e) const
Returns the weight of e.
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 ?
void setHeader(const Point4df &vs)
Sets the header of the underlying volume.
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 ?
vertex_const_iterator beginVertex() const
Iterator on all edges (This::Edge)
const T & access(const Point &p) const
Access the volume at voxel p.
bool isAdjacent(const Vertex &x, const Vertex &y) const
Are x and y adjacent in the graph ?
Base::Weight Weight
Weight type.
void setDimensions(const Point &dim)
Sets the dimensions of the underlying volume.
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