DGtal  0.9.3beta
frontierAndBoundary.cpp
1 
14 #include <iostream>
17 
18 #include "DGtal/helpers/StdDefs.h"
19 #include "DGtal/io/readers/VolReader.h"
20 #include "DGtal/io/DrawWithDisplay3DModifier.h"
21 #include "DGtal/io/viewers/Viewer3D.h"
22 #include "DGtal/io/Color.h"
23 #include "DGtal/io/colormaps/HueShadeColorMap.h"
24 #include "DGtal/images/ImageSelector.h"
25 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
26 #include "DGtal/shapes/implicit/ImplicitBall.h"
27 #include "DGtal/shapes/GaussDigitizer.h"
28 #include "DGtal/shapes/Shapes.h"
29 #include "DGtal/topology/DigitalSurface.h"
30 #include "DGtal/topology/ExplicitDigitalSurface.h"
31 #include "DGtal/topology/helpers/FrontierPredicate.h"
32 #include "DGtal/topology/helpers/BoundaryPredicate.h"
34 
36 
37 using namespace std;
38 using namespace DGtal;
39 using namespace Z3i;
40 
42 
43 int main( int argc, char** argv )
44 {
47  typedef ImplicitBall<Space> EuclideanShape;
50  Point c1( 2, 0, 0 );
51  int radius1 = 6;
52  EuclideanShape ball1( c1, radius1 ); // ball r=6
53  DigitalShape shape1;
54  shape1.attach( ball1 );
55  shape1.init( RealPoint( -10.0, -10.0, -10.0 ),
56  RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
57  Point c2( -2, 0, 0 );
58  int radius2 = 5;
59  EuclideanShape ball2( c2, radius2 ); // ball r=6
60  DigitalShape shape2;
61  shape2.attach( ball2 );
62  shape2.init( RealPoint( -10.0, -10.0, -10.0 ),
63  RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
64  Domain domain = shape1.getDomain();
65  Image image( domain ); // p1, p2 );
66  std::cerr << std::endl;
67  for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end();
68  it != it_end; ++it )
69  {
70  DGtal::uint8_t label = shape1( *it ) ? 1 : 0;
71  label += shape2( *it ) ? 2 : 0;
72  image.setValue( *it, label );
73  std::cerr << (int) image( *it );
74  }
75  std::cerr << std::endl;
77 
79  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
80  KSpace K;
81  bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true );
82  if (!space_ok)
83  {
84  trace.error() << "Error in the Khamisky space construction."<<std::endl;
85  return 2;
86  }
87  trace.endBlock();
89 
91  trace.beginBlock( "Set up digital surface." );
92  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
93  MySurfelAdjacency surfAdj( true ); // interior in all directions.
94  typedef functors::FrontierPredicate<KSpace, Image> FSurfelPredicate;
95  typedef ExplicitDigitalSurface<KSpace,FSurfelPredicate> FrontierContainer;
96  typedef DigitalSurface<FrontierContainer> Frontier;
97  typedef functors::BoundaryPredicate<KSpace, Image> BSurfelPredicate;
98  typedef ExplicitDigitalSurface<KSpace,BSurfelPredicate> BoundaryContainer;
99  typedef DigitalSurface<BoundaryContainer> Boundary;
100  // frontier between label 1 and 0 (connected part containing bel10)
101  SCell vox1 = K.sSpel( c1 + Point( radius1, 0, 0 ), K.POS );
102  SCell bel10 = K.sIncident( vox1, 0, true );
103  FSurfelPredicate surfPredicate10( K, image, 1, 0 );
104  Frontier frontier10 =
105  new FrontierContainer( K, surfPredicate10, surfAdj, bel10 );
106  // frontier between label 2 and 0 (connected part containing bel20)
107  SCell vox2 = K.sSpel( c2 - Point( radius2, 0, 0 ), K.POS );
108  SCell bel20 = K.sIncident( vox2, 0, false );
109  FSurfelPredicate surfPredicate20( K, image, 2, 0 );
110  Frontier frontier20 =
111  new FrontierContainer( K, surfPredicate20, surfAdj, bel20 );
112  // boundary of label 3 (connected part containing bel32)
113  SCell vox3 = K.sSpel( c1 - Point( radius1, 0, 0 ), K.POS );
114  SCell bel32 = K.sIncident( vox3, 0, false );
115  BSurfelPredicate surfPredicate3( K, image, 3 );
116  Boundary boundary3 =
117  new BoundaryContainer( K, surfPredicate3, surfAdj, bel32 );
118  trace.endBlock();
120 
122  trace.beginBlock( "Displaying surface in Viewer3D." );
123  QApplication application(argc,argv);
124  Viewer3D<> viewer;
125  viewer.show();
126  viewer << SetMode3D( domain.className(), "BoundingBox" )
127  << domain;
128  Cell dummy;
129  // Display frontier between 1 and 0.
130  unsigned int nbSurfels10 = 0;
131  viewer << CustomColors3D( Color::Red, Color::Red );
132  for ( Frontier::ConstIterator
133  it = frontier10.begin(), it_end = frontier10.end();
134  it != it_end; ++it, ++nbSurfels10 )
135  viewer << *it;
136  // Display frontier between 2 and 0.
137  unsigned int nbSurfels20 = 0;
138  viewer << CustomColors3D( Color::Yellow, Color::Yellow );
139  for ( Frontier::ConstIterator
140  it = frontier20.begin(), it_end = frontier20.end();
141  it != it_end; ++it, ++nbSurfels20 )
142  viewer << *it;
143  // Display boundary of 3.
144  unsigned int nbSurfels3 = 0;
145  viewer << CustomColors3D( Color( 255, 130, 15 ), Color( 255, 130, 15 ) );
146  for ( Boundary::ConstIterator
147  it = boundary3.begin(), it_end = boundary3.end();
148  it != it_end; ++it, ++nbSurfels3 )
149  viewer << *it;
150  trace.info() << "nbSurfels10 = " << nbSurfels10
151  << ", nbSurfels20 = " << nbSurfels20
152  << ", nbSurfels3 = " << nbSurfels3 << std::endl;
153  viewer << Viewer3D<>::updateDisplay;
154  trace.endBlock();
155  return application.exec();
157 }
void beginBlock(const std::string &keyword="")
Aim: The predicate on surfels that represents the frontier between two regions in an image...
const ConstIterator & begin() const
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
const ConstIterator & end() const
Trace trace
Definition: Common.h:137
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
double endBlock()
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
Aim: The predicate on surfels that represents the frontier between a region and its complementary in ...
void attach(const EuclideanShape &shape)
std::string className() const
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Domain getDomain() const
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD...
Definition: ImplicitBall.h:64
const Point & upperBound() const
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::uint8_t uint8_t
unsigned 8-bit integer.
Definition: BasicTypes.h:59
std::ostream & info()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Space::RealPoint RealPoint
Definition: StdDefs.h:97
const Point & lowerBound() const
std::ostream & error()
Modifier class in a Display3D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithDisplay3D.