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> 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() );
112 {
return edge_iterator(_vol,
false,v,_conn.begin(),_conn.end()); }
115 {
return edge_iterator(_vol,
true,v,_conn.begin(),_conn.end()); }
132 bool contains(
const Vertex & v )
const;
134 bool contains(
const Edge & e )
const;
140 void insert( Edge e, Weight w = (Weight)0 ) {
throw; }
142 Weight
weight(
const Edge & e );
144 Weight
weight(
const Edge & e )
const;
150 {
return BaseBase::isAdjacent(*
this,x,y); }
152 bool isLinked(
const Vertex & x,
const Vertex & y )
const 153 {
return BaseBase::isLinked(*
this,x,y); }
157 {
return BaseBase::isSubGraph(*
this,g); }
161 {
return BaseBase::isConnectedComponent(*
this,g); }
166 {
return BaseBase::isAdjacentTo(*
this,v,g); }
168 {
return BaseBase::isAdjacentFrom(*
this,v,g); }
172 {
return BaseBase::getConnectedComponent(*
this,v); }
174 Weight
Fm(
const Vertex & v )
const 177 template <
typename Set>
179 {
return BaseBase::getComplement(s,e); }
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. );
197 void setWeightMethod( Weight (*weight)(
const Type &,
const Type & ) );
198 template <
typename M>
202 void mask(
const carto::VolumeRef<M> &
mask );
204 T &
access(
const Point & p );
206 const T &
access(
const Point & p )
const;
208 bool inside(
const Point & p )
const;
213 Weight (*_weight)(
const Type &,
const Type & );
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>
435 _vtx(Vertex::none()),
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;
610 ConnIt b, ConnIt e ):
614 _dim( vol.getSizeX(), vol.getSizeY(), vol.getSizeZ(), vol.getSizeT() ),
623 copy( _vtx.point(), _cur );
630 VertexIt vb, VertexIt ve,
631 ConnIt b, ConnIt e ):
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;
825 ConnIt b, ConnIt e ):
830 VertexIt vb, VertexIt ve,
831 ConnIt b, ConnIt e ):
832 Base(vol,end,vb,ve,b,e)
860 template <
typename T,
typename P>
869 typedef typename Pointed::Type
Type;
870 typedef typename Pointed::Point
Point;
882 Base( new Pointed( sx, sy, sz, st ) ) {}
887 const aims::strel::Connectivity & conn
888 = aims::strel::Connectivity6XYZ() ):
889 Base( new Pointed( volume, conn ) )
904 static Graph
none() {
return This( (Pointed*)0 ); }
912 vertex_const_iterator
beginVertex()
const {
return ((Pointed*)(this->
get()))->beginVertex(); }
913 vertex_const_iterator
endVertex()
const {
return ((Pointed*)(this->
get()))->endVertex(); }
914 vertex_iterator
beginVertex() {
return ((Pointed*)(this->
get()))->beginVertex(); }
915 vertex_iterator
endVertex() {
return ((Pointed*)(this->
get()))->endVertex(); }
916 edge_const_iterator
beginEdge(
const Vertex & v )
const {
return ((Pointed*)(this->
get()))->beginEdge(v); }
917 edge_const_iterator
endEdge(
const Vertex & v )
const {
return ((Pointed*)(this->
get()))->endEdge(v); }
918 edge_iterator
beginEdge(
const Vertex & v ) {
return ((Pointed*)(this->
get()))->beginEdge(v); }
919 edge_iterator
endEdge(
const Vertex & v) {
return ((Pointed*)(this->
get()))->endEdge(v); }
927 bool isAdjacent(
const Vertex & x,
const Vertex & y )
const {
return ((Pointed*)(this->
get()))->isAdjacent(x,y); }
928 bool isLinked(
const Vertex & x,
const Vertex & y )
const {
return ((Pointed*)(this->
get()))->isLinked(x,y); }
929 bool isSubGraph(
const Graph & g )
const {
return ((Pointed*)(this->
get()))->isSubGraph(g); }
930 bool isConnectedComponent(
const Graph & g )
const {
return ((Pointed*)(this->
get()))->isConnectedComponent(g); }
931 bool isAdjacentTo(
const Vertex & v,
const Graph & g )
const {
return ((Pointed*)(this->
get()))->isAdjacentTo(v,g); }
932 bool isAdjacentFrom(
const Vertex & v,
const Graph & g )
const {
return ((Pointed*)(this->
get()))->isAdjacentFrom(v,g); }
934 template <
typename Set>
935 static Set
getComplement(
const Set & s,
const Set & e ) {
return Pointed::getComplement(s,e); }
941 void setDimensions(
int sx = 1,
int sy = 1,
int sz = 1,
int st = 1 ) {
return ((Pointed*)(this->
get()))->setDimensions(sx,sy,sz,st); }
942 void setDimensions(
const Point & dim ) {
return ((Pointed*)(this->
get()))->setDimensions(dim); }
943 void setHeader(
float vx = 1.,
float vy = 1.,
float vz = 1.,
float vt = 1. ) {
return ((Pointed*)(this->
get()))->setHeader(vx,vy,vz,vt); }
944 void setHeader(
const Point4df & vs ) {
return ((Pointed*)(this->
get()))->setHeader(vs); }
946 template <
typename M>
947 void mask(
const carto::VolumeRef<M> &
mask ) {
return ((Pointed*)(this->
get()))->mask(mask); }
948 T &
access(
const Point & p ) {
return ((Pointed*)(this->
get()))->access(p); }
949 const T &
access(
const Point & p )
const {
return ((Pointed*)(this->
get()))->access(p); }
950 bool inside(
const Point & p )
const {
return ((Pointed*)(this->
get()))->inside(p); }
955 #endif // BIOPROCESSING_GRAPH_VOLUMEGRAPH void setDimensions(int sx=1, int sy=1, int sz=1, int st=1)
Sets the dimensions of the underlying volume.
const T & access(const Point &p) const
vertex_iterator NonConstThis
void setDimensions(const Point &dim)
virtual Weight weight(const Edge &e)
edge_const_iterator endEdge(const Vertex &v) const
Iterator on the edges containing a given vertex.
edge_iterator(const Volume &vol, bool end, VertexIt vb, VertexIt ve, ConnIt b, ConnIt e)
vertex_const_iterator(const Volume &vol, bool end)
bool isLinked(const Vertex &x, const Vertex &y) const
BaseGraph< SetEdgeRef< PointVertexRef< P > > > BaseBase
Base class of Base (BaseGraph)
bool isLinked(const Vertex &x, const Vertex &y) const
Are x and y linked in the graph ?
edge_iterator endEdge(const Vertex &v)
edge_iterator NonConstThis
edge_iterator beginEdge(const Vertex &v)
Iterator on the edges containing a given vertex.
VolumeGraphRef(const Base &other)
Copy constructor (it copies the reference, it does not duplicate the pointed object) ...
bool inside(const Point &p) const
True if p is a voxel from the underlying volume.
edge_iterator beginEdge(const Vertex &v)
Iterator on the edges of a volume graph.
void setWeightMethod(Weight(*weight)(const Type &, const Type &))
Graph getConnectedComponent(Vertex &v)
void mask(const carto::VolumeRef< M > &mask)
Mask the underlying volume using mask.
edge_const_iterator(const NonConstThis &o)
void setHeader(const Point4df &vs)
bool isAdjacentFrom(const Vertex &v, const Graph &g) const
vertex_const_iterator(const This &o)
void mask(const carto::VolumeRef< M > &mask)
bool empty() const
True if the graph contains no edges and vertices.
static Type presentValue()
virtual Weight Fm(const Vertex &v) const
Pointed::edge_iterator edge_iterator
bool operator!=(const NonConstThis &o) const
This & operator=(const NonConstThis &o)
VolumeGraphRef< T, P > Ref
Reference type.
Pointed::vertex_iterator vertex_iterator
Weight(* _weight)(const Type &, const 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 ...
aims::StructuringElement::const_iterator ConnIt
bool isConnectedComponent(const Graph &g) const
edge_const_iterator beginEdge(const Vertex &v) const
edge_iterator(const Volume &vol, bool end, const Vertex &v, ConnIt b, ConnIt e)
static Type notPresentValue()
Value whose meaning is "none".
void insert(Vertex v)
Insertion of a new vertex (undefined for now)
bool isAdjacent(const Vertex &x, const Vertex &y) const
virtual bool empty() const
This & operator=(const NonConstThis &o)
VolumeGraph< T, P > Owner
static Type presentValue()
Value whose meaning is "present".
void insert(Edge e, Weight w=(Weight) 0)
Insertion of a weighted edge (undefined for now)
VolumeGraph< T, P > Owner
virtual bool operator=(const This &other)
edge_const_iterator(const Volume &vol, bool end, const Vertex &v, ConnIt b, ConnIt e)
vertex_iterator beginVertex()
Iterator on all vertices.
bool operator==(const This &o) const
Owner::vertex_const_iterator Base
Iterator on the vertices of a volume graph.
static Set getComplement(const Set &s, const Set &e)
void copy(const P1 &p1, P2 &p2)
virtual bool contains(const Vertex &v) const
Weight Fm(const Vertex &v) const
Returns the minimum weight of all edges containing v.
bool operator==(const NonConstThis &o) const
static Type notPresentValue()
bool inside(const Point &p) const
vertex_const_iterator(const NonConstThis &o)
Owner::edge_const_iterator Base
void setHeader(float vx=1., float vy=1., float vz=1., float vt=1.)
This & operator=(const This &o)
const Edge & operator*() const
Pointed::edge_const_iterator edge_const_iterator
VolumeGraphRef< T, P > This
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 ...
VolumeGraph< T, P > Owner
VolumeGraph< T, P > Pointed
void clear()
Clear the graph from all edges and vertices.
vertex_const_iterator endVertex() const
vertex_iterator endVertex()
Iterator on all vertices.
bool isAdjacent(const Vertex &x, const Vertex &y) const
Are x and y adjacent in the graph ?
Volume graphs are a graph implementation specifically designed to represent volumes as graphs (vertic...
vertex_iterator(const Volume &in, bool end=false)
vertex_const_iterator endVertex() const
Iterator on all vertices.
Graph getConnectedComponent(Vertex &v)
Returns the (one and only) connected component of this graph containing v.
edge_const_iterator(const Volume &vol, bool end, VertexIt vb, VertexIt ve, ConnIt b, ConnIt e)
vertex_iterator endVertex()
Base::Edge Edge
Usable edge type (RC)
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 ...
This & operator=(const This &other)
virtual ~VolumeGraphRef()
bool isConnectedComponent(const Graph &g) const
Is g a connected component in this graph (Meaning all its vertices are linked)
Base::Vertex Vertex
Usable vertex type (RC)
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) ...
Owner::edge_iterator This
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 ...
void insert(Edge e)
Insertion of a new edge (undefined for now)
Edge::Vertex Vertex
Usable vertex type.
vertex_const_iterator This
Pointed::vertex_const_iterator vertex_const_iterator
vertex_iterator(const This &other)
VolumeGraph< T, P > Owner
edge_const_iterator(const This &o)
edge_iterator endEdge(const Vertex &v)
Iterator on the edges containing a given vertex.
VolumeGraph< T, P > This
Type of *this.
EWBaseGraphRef< SetEdgeRef< PointVertexRef< P > >, T > Base
Base class for edge weighted graphs.
bool isAdjacentFrom(const Vertex &v, const Graph &g) const
edge_const_iterator beginEdge(const Vertex &v) const
Iterator on the edges containing a given vertex.
vertex_const_iterator beginVertex() const
aims::StructuringElement::const_iterator ConnIt
const Vertex & operator*() const
bool operator==(const NonConstThis &o) const
void setWeightMethod(Weight(*weight)(const Type &, const Type &))
Sets the weight method.
void setHeader(float vx=1., float vy=1., float vz=1., float vt=1.)
Sets the header of the underlying volume.
Reference to a EWBaseGraph.
aims::StructuringElement _conn
Reference to a VolumeGraph.
bool operator!=(const This &o) const
bool isAdjacentTo(const Vertex &v, const Graph &g) const
This & operator=(const This &o)
edge_iterator(const This &other)
carto::VolumeRef< Type > Volume
Volume type.
void setDimensions(int sx=1, int sy=1, int sz=1, int st=1)
bool isSubGraph(const Graph &g) const
static Set getComplement(const Set &s, const Set &e)
Returns the complement of s in e.
Base::Weight Weight
Weight type.
vertex_iterator beginVertex()
bool contains(const Vertex &v) const
True if v is in the graph.
const Vertex * operator->() const
VolumeGraphRef< T, P > Graph
Usable graph type (RC)
const Edge * operator->() const
T & access(const Point &p)
Access the volume at voxel p.
Weight weight(const Edge &e)
Returns the weight of e.
bool operator!=(const This &o) const
edge_const_iterator endEdge(const Vertex &v) const
vertex_const_iterator VertexIt
This & operator=(const This &other)
EWBaseGraph< SetEdgeRef< PointVertexRef< P > >, T > Base
Base class (EWBaseGraph)
T & access(const Point &p)
bool operator!=(const NonConstThis &o) const
static Graph none()
Empty pointer factory.
Reference to a BaseGraph.
VolumeGraphRef(Pointed *e)
Constructor from a pointer (the pointer should either be created by new, or be already referenced by ...
bool operator==(const This &o) const