bioprocessing  5.1.2
volumegraph.h
Go to the documentation of this file.
1 /* Copyright (C) 2000-2013 CEA
2  *
3  * This software and supporting documentation were developed by
4  * bioPICSEL
5  * CEA/DSV/I²BM/MIRCen/LMN, Batiment 61,
6  * 18, route du Panorama
7  * 92265 Fontenay-aux-Roses
8  * France
9  */
10 
11 #ifndef BIOPROCESSING_GRAPH_VOLUMEGRAPH
12 #define BIOPROCESSING_GRAPH_VOLUMEGRAPH
13 
14 //--- bioprocessing ----------------------------------------------------------
15 #include <bioprocessing/graph/edgeweightedgraph.h> // bio::EWBaseGraph
16 #include <bioprocessing/graph/setedge.h> // bio::SetEdgeRef
17 #include <bioprocessing/graph/pointvertex.h> // bio::PointVertexRef
18 //--- aims -------------------------------------------------------------------
19 #include <aims/connectivity/structuring_element.h> // aims::StructuringElement
20 #include <aims/math/mathelem.h> // aims::MathUtil
21 #include <aims/vector/vector.h> // Point*
22 //--- cartodata --------------------------------------------------------------
23 #include <cartodata/volume/volume.h> // carto::VolumeRef
24 //----------------------------------------------------------------------------
25 
26 namespace bio {
27  template <typename T, typename P> class VolumeGraph;
28  template <typename T, typename P> class VolumeGraphRef;
29 
30  namespace {
31  // default weight function for volume graphs
32  template <typename T>
33  T weightMin( const T & a, const T & b )
34  {
35  return ( a < b ? a : b );
36  }
37  }
38 
39 //============================================================================
40 // VOLUME GRAPH: DECLARATION
41 //============================================================================
56  template <typename T, typename P>
57  class VolumeGraph: public EWBaseGraph< SetEdgeRef< PointVertexRef< P > >, T >
58  {
59  //--- typedef ------------------------------------------------------------
60  protected:
64  public:
65  typedef T Type;
66  typedef P Point;
67  typedef typename Base::Edge Edge;
68  typedef typename Base::Vertex Vertex;
69  typedef typename Base::Weight Weight;
72  typedef carto::VolumeRef<Type> Volume;
73 
74  //--- constructor --------------------------------------------------------
75  public:
79  VolumeGraph( int sx = 1, int sy = 1, int sz = 1, int st = 1,
80  const aims::strel::Connectivity & conn
81  = aims::strel::Connectivity6XYZ() );
85  VolumeGraph( const Volume & in,
86  const aims::strel::Connectivity & conn
87  = aims::strel::Connectivity6XYZ() );
88  virtual ~VolumeGraph() {}
89 
90  //--- iterators ----------------------------------------------------------
91  public:
92  class vertex_const_iterator;
93  class vertex_iterator;
94  class edge_iterator;
95  class edge_const_iterator;
106  { return edge_const_iterator(_vol,false,v,_conn.begin(),_conn.end()); }
108  edge_const_iterator endEdge( const Vertex & v ) const
109  { return edge_const_iterator(_vol,true,v,_conn.begin(),_conn.end()); }
112  { return edge_iterator(_vol,false,v,_conn.begin(),_conn.end()); }
115  { return edge_iterator(_vol,true,v,_conn.begin(),_conn.end()); }
116  // Iterator on all edges (not yet defined)
118  // Iterator on all edges (not yet defined)
120  // Iterator on all edges (not yet defined)
122  // Iterator on all edges (not yet defined)
124 
125  //--- implementation -----------------------------------------------------
126  public:
128  void insert( Vertex v ) { throw; } //< not defined
130  void insert( Edge e ) { throw; } //< not defined
132  bool contains( const Vertex & v ) const;
134  bool contains( const Edge & e ) const;
136  bool empty() const;
138  void clear();
140  void insert( Edge e, Weight w = (Weight)0 ) { throw; } // not defined
142  Weight weight( const Edge & e );
144  Weight weight( const Edge & e ) const;
145 
146  //--- template implementation --------------------------------------------
147  public:
149  bool isAdjacent( const Vertex & x, const Vertex & y ) 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); }
156  bool isSubGraph( const Graph & g ) const
157  { return BaseBase::isSubGraph(*this,g); }
160  bool isConnectedComponent( const Graph & g ) const
161  { return BaseBase::isConnectedComponent(*this,g); }
165  bool isAdjacentTo( const Vertex & v, const Graph & g ) const
166  { return BaseBase::isAdjacentTo(*this,v,g); }
167  bool isAdjacentFrom( const Vertex & v, const Graph & g ) const
168  { return BaseBase::isAdjacentFrom(*this,v,g); }
172  { return BaseBase::getConnectedComponent(*this,v); }
174  Weight Fm( const Vertex & v ) const
175  { return Base::Fm(*this,v); }
177  template <typename Set>
178  static Set getComplement( const Set & s, const Set & e )
179  { return BaseBase::getComplement(s,e); }
180 
181  //--- volume methods -----------------------------------------------------
182  public:
184  static Type notPresentValue();
186  static Type presentValue();
188  void setDimensions( int sx = 1, int sy = 1, int sz = 1, int st = 1 );
190  void setDimensions( const Point & dim );
192  void setHeader( float vx = 1., float vy = 1., float vz = 1., float vt = 1. );
194  void setHeader( const Point4df & vs );
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;
209 
210  //--- members ------------------------------------------------------------
211  protected:
213  Weight (*_weight)( const Type &, const Type & );
214  aims::StructuringElement _conn;
215  };
216 
217 //============================================================================
218 // VOLUME GRAPH: DEFINITION
219 //============================================================================
220 
221  template <typename T, typename P>
222  VolumeGraph<T,P>::VolumeGraph( int sx, int sy, int sz, int st,
223  const aims::strel::Connectivity & conn ):
224  _vol(sx,sy,sz,st),
225  _conn(conn),
226  _weight(&weightMin)
227  {}
228 
229  template <typename T, typename P>
231  const aims::strel::Connectivity & conn ):
232  _vol(in),
233  _conn(conn),
234  _weight(&weightMin)
235  {}
236 
237  template <typename T, typename P>
238  bool VolumeGraph<T,P>::contains( const Vertex & v ) const
239  {
240  if( !inside( v.point() ) )
241  return false;
242  return access( v.point() ) != notPresentValue();
243  }
244 
245 
246  template <typename T, typename P>
247  bool VolumeGraph<T,P>::contains( const Edge & e ) const
248  {
249  if( !inside( e.x().point() ) || !inside( e.y().point() ) )
250  return false;
251  return ( access( e.x().point() ) != notPresentValue() ) &&
252  ( access( e.y().point() ) != notPresentValue() );
253  }
254 
255  template <typename T, typename P>
257  {
258  int x, y, z, t;
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() )
264  return false;
265  return true;
266  }
267 
268  template <typename T, typename P>
270  {
271  int x, y, z, t;
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();
277  }
278 
279  template <typename T, typename P>
281  {
282  T x, y;
283  x = access( e.x().point() );
284  y = access( e.y().point() );
285  return _weight( x, y );
286  }
287 
288  template <typename T, typename P>
290  {
291  T x, y;
292  x = access( e.x().point() );
293  y = access( e.y().point() );
294  return _weight( x, y );
295  }
296 
297  template <typename T, typename P>
299  {
300  return std::numeric_limits<T>::min();
301  }
302 
303  template <typename T, typename P>
305  {
306  return std::numeric_limits<T>::max();
307  }
308 
309  template <typename T, typename P>
310  void VolumeGraph<T,P>::setDimensions( int sx, int sy, int sz, int st )
311  {
312  _vol->reallocate(sx,sy,sz,st);
313  }
314 
315  template <typename T, typename P>
317  {
318  Point4d dim4(1,1,1,1);
319  for( int i = 0; i < dim.size(); ++i )
320  dim4[i] = dim[i];
321  setDimensions( dim4[0], dim4[1], dim4[2], dim4[3] );
322  }
323 
324  template <typename T, typename P>
325  void VolumeGraph<T,P>::setHeader( float vx, float vy, float vz, float vt )
326  {
327  std::vector<float> vs(4,1.0);
328  vs[0] = vx;
329  vs[1] = vy;
330  vs[2] = vz;
331  vs[3] = vt;
332  }
333 
334  template <typename T, typename P>
335  void VolumeGraph<T,P>::setHeader( const Point4df & vs )
336  {
337  setHeader( vs[0], vs[1], vs[2], vs[3] );
338  }
339 
340  template <typename T, typename P>
341  void VolumeGraph<T,P>::setWeightMethod( Weight (*weight)( const Type &, const Type & ) )
342  {
343  _weight = weight;
344  }
345 
346  template <typename T, typename P>
347  template <typename M>
348  void VolumeGraph<T,P>::mask( const carto::VolumeRef<M> & mask )
349  {
350  ASSERT( ( mask.getSizeX() == _vol.getSizeX() ) &&
351  ( mask.getSizeY() == _vol.getSizeY() ) &&
352  ( mask.getSizeZ() == _vol.getSizeZ() ) &&
353  ( mask.getSizeT() == _vol.getSizeT() ) );
354  int x, y, z, t;
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 )
359  if( !mask(x,y,z,t) )
360  _vol( x, y, z, t ) = notPresentValue();
361  }
362 
363  template <typename T, typename P>
365  {
366  Point4d p4(0,0,0,0);
367  for( int i = 0; i < p.size(); ++i )
368  p4[i] = p[i];
369  return _vol( p4[0], p4[1], p4[2], p4[3] );
370  }
371 
372  template <typename T, typename P>
373  const T & VolumeGraph<T,P>::access( const Point & p ) const
374  {
375  Point4d p4(0,0,0,0);
376  for( int i = 0; i < p.size(); ++i )
377  p4[i] = p[i];
378  return _vol( p4[0], p4[1], p4[2], p4[3] );
379  }
380 
381  template <typename T, typename P>
382  bool VolumeGraph<T,P>::inside( const Point & p ) const
383  {
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] )
391  return false;
392  }
393 
394 //============================================================================
395 // VOLUME GRAPH: VERTEX ITERATORS
396 //============================================================================
397 
419  template <typename T, typename P>
421  {
422  protected:
426  public:
427  typedef typename Owner::Edge Edge;
428  typedef typename Owner::Vertex Vertex;
429  typedef typename Owner::Volume Volume;
430  typedef typename Owner::Point Point;
431  protected:
432  vertex_const_iterator( const Volume & vol, bool end ):
433  _vol(vol),
434  _cur(0,0,0,0),
435  _vtx(Vertex::none()),
436  _dim(vol.getSizeX(),vol.getSizeY(), vol.getSizeZ(), vol.getSizeT())
437  {
438  if( end )
439  toEnd();
440  else
441  if( ( _cur != _dim ) && ( _vol(_cur[0],_cur[1],_cur[2],_cur[3]) == notPresentValue() ) )
442  ++(*this);
443  setVertex();
444  }
445  public:
447  _vol((carto::Volume<T>*)0),
448  _cur(0,0,0,0),
449  _dim(0,0,0,0),
450  _vtx(Vertex::none())
451  {}
453  _vol(o._vol),
454  _cur(o._cur),
455  _dim(o._dim),
456  _vtx(o._vtx)
457  {}
459  _vol(o._vol),
460  _cur(o._cur),
461  _dim(o._dim),
462  _vtx(o._vtx)
463  {}
465  This & operator=( const This & o )
466  {
467  _vol = o._vol;
468  _cur = o._cur;
469  _dim = o._dim;
470  _vtx = o._vtx;
471  return *this;
472  }
473  This & operator=( const NonConstThis & o )
474  {
475  _vol = o._vol;
476  _cur = o._cur;
477  _dim = o._dim;
478  _vtx = o._vtx;
479  return *this;
480  }
482  {
483  if( _cur[0] < _dim[0]-1 )
484  ++( _cur[0] );
485  else
486  {
487  _cur[0] = 0;
488  if( _cur[1] < _dim[1]-1 )
489  ++( _cur[1] );
490  else
491  {
492  _cur[1] = 0;
493  if( _cur[2] < _dim[2]-1 )
494  ++( _cur[2] );
495  else
496  {
497  _cur[2] = 0;
498  if( _cur[3] < _dim[3]-1 )
499  ++( _cur[3] );
500  else
501  toEnd();
502  }
503  }
504  }
505 
506  if( ( _cur != _dim ) && ( _vol(_cur[0],_cur[1],_cur[2],_cur[3]) == notPresentValue() ) )
507  return ++(*this);
508  setVertex();
509  return *this;
510  }
512  {
513  This prev = *this;
514  ++(*this);
515  return prev;
516  }
517  bool operator==( const This & o ) const { return _cur == o._cur; }
518  bool operator!=( const This & o ) const { return _cur != o._cur; }
519  bool operator==( const NonConstThis & o ) const { return _cur == o._cur; }
520  bool operator!=( const NonConstThis & o ) const { return _cur != o._cur; }
521  const Vertex & operator*() const { return _vtx; }
522  const Vertex * operator->() const { return &_vtx; }
523 
524  protected:
525  void toEnd()
526  {
527  _cur = _dim;
528  }
529  void setVertex()
530  {
531  Point p;
532  for( int i = 0; i < p.size(); ++i )
533  p[i] = _cur[i];
534  _vtx = Vertex(p);
535  }
537  Point4d _cur;
538  Point4d _dim;
540  friend class VolumeGraph<T,P>;
541  };
542 
544  template <typename T, typename P>
546  {
547  protected:
551  public:
552  typedef typename Owner::Edge Edge;
553  typedef typename Owner::Vertex Vertex;
554  typedef typename Owner::Volume Volume;
555  typedef typename Owner::Point Point;
556  protected:
557  vertex_iterator( const Volume & in, bool end = false ): Base(in,end) {}
558  public:
560  vertex_iterator( const This & other ): Base(other) {}
561 
562  This & operator=( const This & other ) { Base::operator=(other); }
563  This & operator++() { Base::operator++(); return *this; }
565  {
566  This prev = *this;
567  ++(*this);
568  return prev;
569  }
570  Vertex & operator*() { return this->_vtx; }
571  Vertex * operator->() { return &(this->_vtx); }
572 
573  friend class VolumeGraph<T,P>;
574  };
575 
576 
577 //============================================================================
578 // VOLUME GRAPH: EDGE ITERATORS
579 //============================================================================
592  template <typename T, typename P>
594  {
595  protected:
599  public:
600  typedef typename Owner::Edge Edge;
601  typedef typename Owner::Vertex Vertex;
602  typedef typename Owner::Volume Volume;
603  typedef typename Owner::Point Point;
604  protected:
605  typedef typename aims::StructuringElement::const_iterator ConnIt;
608  bool end,
609  const Vertex & v,
610  ConnIt b, ConnIt e ):
611  _vol(vol),
612  _cur(0,0,0,0),
613  _nbr(0,0,0,0),
614  _dim( vol.getSizeX(), vol.getSizeY(), vol.getSizeZ(), vol.getSizeT() ),
615  _vtxbeg(),
616  _vtxend(),
617  _conbeg(b),
618  _concur(b),
619  _conend(e),
620  _edg(Edge::none()),
621  _vtx(v)
622  {
623  copy( _vtx.point(), _cur );
624  if( end ) toEnd();
625  else toNext();
626  setEdge();
627  }
629  bool end,
630  VertexIt vb, VertexIt ve,
631  ConnIt b, ConnIt e ):
632  _vol(vol),
633  _cur(0,0,0,0),
634  _nbr(0,0,0,0),
635  _dim( vol.getSizeX(), vol.getSizeY(), vol.getSizeZ(), vol.getSizeT() ),
636  _vtxbeg(vb),
637  _vtxend(ve),
638  _conbeg(b),
639  _concur(b),
640  _conend(e),
641  _edg(Edge::none()),
642  _vtx(Vertex::none())
643  {
644  copy( vb->point(), _cur );
645  if( end ) toEnd();
646  else toNext();
647  setEdge();
648  }
649  public:
651  _vol((carto::Volume<T>*)0),
652  _cur(0,0,0,0),
653  _nbr(0,0,0,0),
654  _dim(0,0,0,0),
655  _vtxbeg(),
656  _vtxend(),
657  _conbeg(),
658  _concur(),
659  _conend(),
660  _edg(Edge::none()),
661  _vtx(Vertex::none())
662  {}
663  edge_const_iterator( const This & o ):
664  _vol(o._vol),
665  _cur(o._cur),
666  _nbr(o._nbr),
667  _dim(o._dim),
668  _vtxbeg(o._vtxbeg),
669  _vtxend(o._vtxend),
670  _conbeg(o._conbeg),
671  _concur(o._concur),
672  _conend(o._conend),
673  _edg(o._edg),
674  _vtx(o._vtx)
675  {}
677  _vol(o._vol),
678  _cur(o._cur),
679  _nbr(o._nbr),
680  _dim(o._dim),
681  _vtxbeg(o._vtxbeg),
682  _vtxend(o._vtxend),
683  _conbeg(o._conbeg),
684  _concur(o._concur),
685  _conend(o._conend),
686  _edg(o._edg),
687  _vtx(o._vtx)
688  {}
690  This & operator=( const This & o )
691  {
692  _vol = o._vol;
693  _cur = o._cur;
694  _nbr = o._nbr;
695  _dim = o._dim;
696  _vtxbeg = o._vtxbeg;
697  _vtxend = o._vtxend;
698  _conbeg = o._conbeg;
699  _concur = o._concur;
700  _conend = o._conend;
701  _edg = o._edg;
702  _vtx = o._vtx;
703  return *this;
704  }
705  This & operator=( const NonConstThis & o )
706  {
707  _vol = o._vol;
708  _cur = o._cur;
709  _nbr = o._nbr;
710  _dim = o._dim;
711  _vtxbeg = o._vtxbeg;
712  _vtxend = o._vtxend;
713  _conbeg = o._conbeg;
714  _concur = o._concur;
715  _conend = o._conend;
716  _edg = o._edg;
717  _vtx = o._vtx;
718  return *this;
719  }
721  {
722  toNext();
723  setEdge();
724  return *this;
725  }
727  {
728  This prev = *this;
729  ++(*this);
730  return prev;
731  }
732  bool operator==( const This & o ) const { return _edg == o._edg; }
733  bool operator!=( const This & o ) const { return _edg != o._edg; }
734  bool operator==( const NonConstThis & o ) const { return _edg == o._edg; }
735  bool operator!=( const NonConstThis & o ) const { return _edg != o._edg; }
736  const Edge & operator*() const { return _edg; }
737  const Edge * operator->() const { return &_edg; }
738 
739  protected:
740  void toEnd()
741  {
742  _cur = Point4d(0,0,0,0);
743  _nbr = _dim;
744  }
745  void toNext()
746  {
747  if( _concur == _conend ) {
748  if( _vtx != Vertex::none() )
749  return toEnd();
750  else {
751  if( _vtxbeg == _vtxend )
752  return toEnd();
753  else {
754  _concur = _conbeg;
755  ++_vtxbeg;
756  copy( _vtxbeg->point(), _cur );
757  }
758  }
759  }
760  Point4d move(0,0,0,0);
761  copy( *_concur, move );
762  _nbr = _cur + move;
763  ++_concur;
764  if( !inside() )
765  toNext();
766  if( _nbr == _cur )
767  toNext();
768  }
769  void setEdge()
770  {
771  Point p1, p2;
772  copy(_cur,p1);
773  copy(_nbr,p2);
774  _edg = Edge( Vertex(p1), Vertex(p2) );
775  }
776  template <typename P1, typename P2>
777  void copy( const P1 & p1, P2 & p2 )
778  {
779  int size = ( p1.size() > p2.size() ? p2.size() : p1.size() );
780  for( int i = 0; i < size; ++i )
781  p2[i] = p1[i];
782  }
783  bool inside()
784  {
785  for( int i = 0; i<4; ++i )
786  if( _nbr[i] < 0 || _nbr[i] >= _dim[i] )
787  return false;
788  return true;
789  }
790 
792  Point4d _cur;
793  Point4d _nbr;
794  Point4d _dim;
802 
803  friend class VolumeGraph<T,P>;
804  };
805 
807  template <typename T, typename P>
809  {
810  protected:
813  typedef typename Owner::edge_iterator This;
814  public:
815  typedef typename Owner::Edge Edge;
816  typedef typename Owner::Vertex Vertex;
817  typedef typename Owner::Volume Volume;
818  typedef typename Owner::Point Point;
819  protected:
820  typedef typename aims::StructuringElement::const_iterator ConnIt;
822  edge_iterator( const Volume & vol,
823  bool end,
824  const Vertex & v,
825  ConnIt b, ConnIt e ):
826  Base(vol,end,v,b,e)
827  {}
828  edge_iterator( const Volume & vol,
829  bool end,
830  VertexIt vb, VertexIt ve,
831  ConnIt b, ConnIt e ):
832  Base(vol,end,vb,ve,b,e)
833  {}
834  public:
836  edge_iterator( const This & other ): Base(other) {}
837 
838  This & operator=( const This & other ) { Base::operator=(other); }
839  This & operator++() { Base::operator++(); return *this; }
841  {
842  This prev = *this;
843  ++(*this);
844  return prev;
845  }
846  Edge & operator*() { return this->_edg; }
847  Edge * operator->() { return &(this->_edg); }
848 
849  friend class VolumeGraph<T,P>;
850  };
851 
852 //============================================================================
853 // VOLUME GRAPH REF
854 //============================================================================
860  template <typename T, typename P>
861  class VolumeGraphRef: public EWBaseGraphRef< SetEdgeRef< PointVertexRef< P > >, T>
862  {
863  //--- typedef ------------------------------------------------------------
864  protected:
868  public:
869  typedef typename Pointed::Type Type;
870  typedef typename Pointed::Point Point;
871  typedef typename Pointed::Vertex Vertex;
872  typedef typename Pointed::Edge Edge;
873  typedef typename Pointed::Weight Weight;
874  typedef typename Pointed::Graph Graph;
875 
876  //--- constructor --------------------------------------------------------
877  public:
881  VolumeGraphRef( int sx = 1, int sy = 1, int sz = 1, int st = 1 ):
882  Base( new Pointed( sx, sy, sz, st ) ) {}
886  VolumeGraphRef( carto::VolumeRef<T> volume,
887  const aims::strel::Connectivity & conn
888  = aims::strel::Connectivity6XYZ() ):
889  Base( new Pointed( volume, conn ) )
890  {}
897  VolumeGraphRef( const Base & other ): Base(other) {}
898  virtual ~VolumeGraphRef() {}
899 
900  //--- none factory -------------------------------------------------------
901  public:
904  static Graph none() { return This( (Pointed*)0 ); }
905 
906  //--- iterator -----------------------------------------------------------
907  public:
908  typedef typename Pointed::vertex_const_iterator vertex_const_iterator;
909  typedef typename Pointed::vertex_iterator vertex_iterator;
910  typedef typename Pointed::edge_const_iterator edge_const_iterator;
911  typedef typename Pointed::edge_iterator edge_iterator;
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); }
920  // edge_const_iterator beginEdge() const { return ((Pointed*)(this->get()))->beginEdge(); }
921  // edge_const_iterator endEdge() const { return ((Pointed*)(this->get()))->endEdge(); }
922  // edge_iterator beginEdge() { return ((Pointed*)(this->get()))->beginEdge(); }
923  // edge_iterator endEdge() { return ((Pointed*)(this->get()))->endEdge(); }
924 
925  //--- template implementation --------------------------------------------
926  public:
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); }
933  Graph getConnectedComponent( Vertex & v ) { return ((Pointed*)(this->get()))->getConnectedComponent(v); }
934  template <typename Set>
935  static Set getComplement( const Set & s, const Set & e ) { return Pointed::getComplement(s,e); }
936 
937  //--- volume methods -----------------------------------------------------
938  public:
940  static Type presentValue() { return Pointed::presentValue(); }
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); }
945  void setWeightMethod( Weight (*weight)( const Type &, const Type & ) ) { return ((Pointed*)(this->get()))->setWeightMethod(weight); }
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); }
951  };
952 
953 } // namespace bio
954 
955 #endif // BIOPROCESSING_GRAPH_VOLUMEGRAPH
Reference to a BaseGraph.
Definition: basegraph.h:312
Pointed::Vertex Vertex
Definition: basegraph.h:319
carto::rc_ptr< BaseGraph< E > > Base
Definition: basegraph.h:315
Base class for graphs.
Definition: basegraph.h:40
E Edge
Usable edge type.
Definition: basegraph.h:45
virtual bool isAdjacent(const Vertex &x, const Vertex &y) const
Definition: basegraph.h:82
virtual bool isAdjacentFrom(const Vertex &v, const Graph &g) const
Definition: basegraph.h:87
virtual bool isSubGraph(const Graph &g) const
Definition: basegraph.h:84
static Set getComplement(const Set &s, const Set &e)
Definition: basegraph.h:291
virtual bool isLinked(const Vertex &x, const Vertex &y) const
Definition: basegraph.h:83
virtual bool isConnectedComponent(const Graph &g) const
Definition: basegraph.h:85
static G::Ref getConnectedComponent(G &thisg, Vertex &v)
Definition: basegraph.h:264
virtual bool operator=(const This &other)
Definition: basegraph.h:74
Edge::Vertex Vertex
Usable vertex type.
Definition: basegraph.h:46
virtual bool isAdjacentTo(const Vertex &v, const Graph &g) const
Definition: basegraph.h:86
Reference to a EWBaseGraph.
Base class for edge weighted graphs.
Reference to a VolumeGraph.
Definition: volumegraph.h:862
bool inside(const Point &p) const
Definition: volumegraph.h:950
vertex_iterator endVertex()
Definition: volumegraph.h:915
void mask(const carto::VolumeRef< M > &mask)
Definition: volumegraph.h:947
Pointed::edge_const_iterator edge_const_iterator
Definition: volumegraph.h:910
bool isAdjacentFrom(const Vertex &v, const Graph &g) const
Definition: volumegraph.h:932
Pointed::Type Type
Definition: volumegraph.h:869
void setDimensions(const Point &dim)
Definition: volumegraph.h:942
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 ...
Definition: volumegraph.h:886
Graph getConnectedComponent(Vertex &v)
Definition: volumegraph.h:933
edge_const_iterator beginEdge(const Vertex &v) const
Definition: volumegraph.h:916
static Type notPresentValue()
Definition: volumegraph.h:939
edge_iterator endEdge(const Vertex &v)
Definition: volumegraph.h:919
bool isLinked(const Vertex &x, const Vertex &y) const
Definition: volumegraph.h:928
Pointed::Vertex Vertex
Definition: volumegraph.h:871
edge_const_iterator endEdge(const Vertex &v) const
Definition: volumegraph.h:917
vertex_iterator beginVertex()
Definition: volumegraph.h:914
Pointed::Graph Graph
Definition: volumegraph.h:874
Pointed::Weight Weight
Definition: volumegraph.h:873
Pointed::vertex_const_iterator vertex_const_iterator
Definition: volumegraph.h:908
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 ...
Definition: volumegraph.h:881
Pointed::edge_iterator edge_iterator
Definition: volumegraph.h:911
VolumeGraphRef< T, P > This
Definition: volumegraph.h:865
bool isSubGraph(const Graph &g) const
Definition: volumegraph.h:929
static Type presentValue()
Definition: volumegraph.h:940
Pointed::Point Point
Definition: volumegraph.h:870
virtual ~VolumeGraphRef()
Definition: volumegraph.h:898
bool isAdjacentTo(const Vertex &v, const Graph &g) const
Definition: volumegraph.h:931
static Set getComplement(const Set &s, const Set &e)
Definition: volumegraph.h:935
vertex_const_iterator beginVertex() const
Definition: volumegraph.h:912
void setDimensions(int sx=1, int sy=1, int sz=1, int st=1)
Definition: volumegraph.h:941
static Graph none()
Empty pointer factory.
Definition: volumegraph.h:904
Pointed::Edge Edge
Definition: volumegraph.h:872
void setHeader(float vx=1., float vy=1., float vz=1., float vt=1.)
Definition: volumegraph.h:943
VolumeGraph< T, P > Pointed
Definition: volumegraph.h:867
bool isAdjacent(const Vertex &x, const Vertex &y) const
Definition: volumegraph.h:927
vertex_const_iterator endVertex() const
Definition: volumegraph.h:913
void setWeightMethod(Weight(*weight)(const Type &, const Type &))
Definition: volumegraph.h:945
EWBaseGraphRef< SetEdgeRef< PointVertexRef< P > >, T > Base
Definition: volumegraph.h:866
Pointed::vertex_iterator vertex_iterator
Definition: volumegraph.h:909
edge_iterator beginEdge(const Vertex &v)
Definition: volumegraph.h:918
T & access(const Point &p)
Definition: volumegraph.h:948
VolumeGraphRef(const Base &other)
Copy constructor (it copies the reference, it does not duplicate the pointed object)
Definition: volumegraph.h:897
VolumeGraphRef(Pointed *e)
Constructor from a pointer (the pointer should either be created by new, or be already referenced by ...
Definition: volumegraph.h:894
void setHeader(const Point4df &vs)
Definition: volumegraph.h:944
bool isConnectedComponent(const Graph &g) const
Definition: volumegraph.h:930
const T & access(const Point &p) const
Definition: volumegraph.h:949
Iterator on the edges of a volume graph.
Definition: volumegraph.h:594
bool operator!=(const This &o) const
Definition: volumegraph.h:733
edge_const_iterator(const NonConstThis &o)
Definition: volumegraph.h:676
bool operator==(const This &o) const
Definition: volumegraph.h:732
This & operator=(const NonConstThis &o)
Definition: volumegraph.h:705
bool operator==(const NonConstThis &o) const
Definition: volumegraph.h:734
void copy(const P1 &p1, P2 &p2)
Definition: volumegraph.h:777
edge_const_iterator(const Volume &vol, bool end, VertexIt vb, VertexIt ve, ConnIt b, ConnIt e)
Definition: volumegraph.h:628
edge_const_iterator(const Volume &vol, bool end, const Vertex &v, ConnIt b, ConnIt e)
Definition: volumegraph.h:607
aims::StructuringElement::const_iterator ConnIt
Definition: volumegraph.h:605
bool operator!=(const NonConstThis &o) const
Definition: volumegraph.h:735
edge_iterator(const This &other)
Definition: volumegraph.h:836
VolumeGraph< T, P > Owner
Definition: volumegraph.h:811
edge_iterator(const Volume &vol, bool end, const Vertex &v, ConnIt b, ConnIt e)
Definition: volumegraph.h:822
Owner::edge_const_iterator Base
Definition: volumegraph.h:812
edge_iterator(const Volume &vol, bool end, VertexIt vb, VertexIt ve, ConnIt b, ConnIt e)
Definition: volumegraph.h:828
aims::StructuringElement::const_iterator ConnIt
Definition: volumegraph.h:820
This & operator=(const This &other)
Definition: volumegraph.h:838
Owner::edge_iterator This
Definition: volumegraph.h:813
Iterator on the vertices of a volume graph.
Definition: volumegraph.h:421
vertex_const_iterator(const NonConstThis &o)
Definition: volumegraph.h:458
vertex_const_iterator(const Volume &vol, bool end)
Definition: volumegraph.h:432
bool operator==(const NonConstThis &o) const
Definition: volumegraph.h:519
bool operator!=(const NonConstThis &o) const
Definition: volumegraph.h:520
This & operator=(const NonConstThis &o)
Definition: volumegraph.h:473
bool operator==(const This &o) const
Definition: volumegraph.h:517
bool operator!=(const This &o) const
Definition: volumegraph.h:518
Owner::vertex_const_iterator Base
Definition: volumegraph.h:550
vertex_iterator(const This &other)
Definition: volumegraph.h:560
This & operator=(const This &other)
Definition: volumegraph.h:562
vertex_iterator(const Volume &in, bool end=false)
Definition: volumegraph.h:557
Volume graphs are a graph implementation specifically designed to represent volumes as graphs (vertic...
Definition: volumegraph.h:58
void setDimensions(int sx=1, int sy=1, int sz=1, int st=1)
Sets the dimensions of the underlying volume.
Definition: volumegraph.h:310
VolumeGraph< T, P > This
Type of *this.
Definition: volumegraph.h:61
P Point
Point type.
Definition: volumegraph.h:66
void setWeightMethod(Weight(*weight)(const Type &, const Type &))
Sets the weight method.
Definition: volumegraph.h:341
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)
Definition: volumegraph.h:156
bool empty() const
True if the graph contains no edges and vertices.
Definition: volumegraph.h:256
carto::VolumeRef< Type > Volume
Volume type.
Definition: volumegraph.h:72
Weight weight(const Edge &e)
Returns the weight of e.
Definition: volumegraph.h:280
Graph getConnectedComponent(Vertex &v)
Returns the (one and only) connected component of this graph containing v.
Definition: volumegraph.h:171
void insert(Edge e, Weight w=(Weight) 0)
Insertion of a weighted edge (undefined for now)
Definition: volumegraph.h:140
VolumeGraphRef< T, P > Ref
Reference type.
Definition: volumegraph.h:71
edge_iterator endEdge()
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 ...
Definition: volumegraph.h:222
bool inside(const Point &p) const
True if p is a voxel from the underlying volume.
Definition: volumegraph.h:382
vertex_iterator beginVertex()
Iterator on all vertices.
Definition: volumegraph.h:101
Weight Fm(const Vertex &v) const
Returns the minimum weight of all edges containing v.
Definition: volumegraph.h:174
static Set getComplement(const Set &s, const Set &e)
Returns the complement of s in e.
Definition: volumegraph.h:178
T Type
Value type.
Definition: volumegraph.h:65
BaseGraph< SetEdgeRef< PointVertexRef< P > > > BaseBase
Base class of Base (BaseGraph)
Definition: volumegraph.h:63
edge_const_iterator beginEdge() const
vertex_const_iterator endVertex() const
Iterator on all vertices.
Definition: volumegraph.h:99
Base::Edge Edge
Usable edge type (RC)
Definition: volumegraph.h:67
bool isLinked(const Vertex &x, const Vertex &y) const
Are x and y linked in the graph ?
Definition: volumegraph.h:152
edge_iterator beginEdge(const Vertex &v)
Iterator on the edges containing a given vertex.
Definition: volumegraph.h:111
bool contains(const Vertex &v) const
True if v is in the graph.
Definition: volumegraph.h:238
EWBaseGraph< SetEdgeRef< PointVertexRef< P > >, T > Base
Base class (EWBaseGraph)
Definition: volumegraph.h:62
void insert(Edge e)
Insertion of a new edge (undefined for now)
Definition: volumegraph.h:130
edge_const_iterator endEdge() const
Base::Vertex Vertex
Usable vertex type (RC)
Definition: volumegraph.h:68
T & access(const Point &p)
Access the volume at voxel p.
Definition: volumegraph.h:364
bool isAdjacentFrom(const Vertex &v, const Graph &g) const
Definition: volumegraph.h:167
vertex_iterator endVertex()
Iterator on all vertices.
Definition: volumegraph.h:103
VolumeGraphRef< T, P > Graph
Usable graph type (RC)
Definition: volumegraph.h:70
void mask(const carto::VolumeRef< M > &mask)
Mask the underlying volume using mask.
Definition: volumegraph.h:348
Weight(* _weight)(const Type &, const Type &)
Definition: volumegraph.h:213
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 ...
Definition: volumegraph.h:165
vertex_const_iterator beginVertex() const
Iterator on all edges (This::Edge)
Definition: volumegraph.h:97
bool isAdjacent(const Vertex &x, const Vertex &y) const
Are x and y adjacent in the graph ?
Definition: volumegraph.h:149
Base::Weight Weight
Weight type.
Definition: volumegraph.h:69
void clear()
Clear the graph from all edges and vertices.
Definition: volumegraph.h:269
edge_iterator endEdge(const Vertex &v)
Iterator on the edges containing a given vertex.
Definition: volumegraph.h:114
bool isConnectedComponent(const Graph &g) const
Is g a connected component in this graph (Meaning all its vertices are linked)
Definition: volumegraph.h:160
edge_const_iterator endEdge(const Vertex &v) const
Iterator on the edges containing a given vertex.
Definition: volumegraph.h:108
virtual ~VolumeGraph()
Definition: volumegraph.h:88
void setHeader(float vx=1., float vy=1., float vz=1., float vt=1.)
Sets the header of the underlying volume.
Definition: volumegraph.h:325
static Type presentValue()
Value whose meaning is "present".
Definition: volumegraph.h:304
edge_const_iterator beginEdge(const Vertex &v) const
Iterator on the edges containing a given vertex.
Definition: volumegraph.h:105
static Type notPresentValue()
Value whose meaning is "none".
Definition: volumegraph.h:298
edge_iterator beginEdge()
void insert(Vertex v)
Insertion of a new vertex (undefined for now)
Definition: volumegraph.h:128
aims::StructuringElement _conn
Definition: volumegraph.h:214