bioprocessing 6.0.4
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
26namespace 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()); }
107
109 { return edge_const_iterator(_vol,true,v,_conn.begin(),_conn.end()); }
110
112 { return edge_iterator(_vol,false,v,_conn.begin(),_conn.end()); }
113
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); }
151
152 bool isLinked( const Vertex & x, const Vertex & y ) const
153 { return BaseBase::isLinked(*this,x,y); }
154
156 bool isSubGraph( const Graph & g ) const
157 { return BaseBase::isSubGraph(*this,g); }
158
160 bool isConnectedComponent( const Graph & g ) const
161 { return BaseBase::isConnectedComponent(*this,g); }
162
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); }
169
173
174 Weight Fm( const Vertex & v ) const
175 { return Base::Fm(*this,v); }
176
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:
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>
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 }
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 }
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 {}
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 }
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 {
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 ) ) {}
883
886 VolumeGraphRef( carto::VolumeRef<T> volume,
887 const aims::strel::Connectivity & conn
888 = aims::strel::Connectivity6XYZ() ):
889 Base( new Pointed( volume, conn ) )
890 {}
891
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:
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:
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
Base class for graphs.
Definition basegraph.h:40
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)
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)
virtual bool operator=(const This &other)
Definition basegraph.h:74
virtual bool isAdjacentTo(const Vertex &v, const Graph &g) const
Definition basegraph.h:86
virtual Weight weight(const Edge &e)
Base class for edge weighted graphs.
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
Pointed::Type Type
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
Pointed::Vertex Vertex
edge_const_iterator endEdge(const Vertex &v) const
vertex_iterator beginVertex()
Pointed::Graph Graph
Pointed::Weight Weight
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()
Pointed::Point Point
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.
Pointed::Edge Edge
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)
bool operator==(const This &o) const
This & operator=(const NonConstThis &o)
bool operator==(const NonConstThis &o) const
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)
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)
vertex_const_iterator(const Volume &vol, bool end)
bool operator==(const NonConstThis &o) const
bool operator!=(const NonConstThis &o) const
bool operator==(const This &o) const
This & operator=(const NonConstThis &o)
bool operator!=(const This &o) const
This & operator=(const This &other)
Owner::vertex_const_iterator Base
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...
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.
bool contains(const Edge &e) const
True if e is in the graph.
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.
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.
Definition volumegraph.h:72
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.
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 ...
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.
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 ?
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)
Definition volumegraph.h:62
void insert(Edge e)
Insertion of a new edge (undefined for now)
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.
bool isAdjacentFrom(const Vertex &v, const Graph &g) const
vertex_iterator endVertex()
Iterator on all vertices.
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.
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)
Definition volumegraph.h:97
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.
Definition volumegraph.h:69
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.
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.
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