DGtal  1.5.beta
frontierAndBoundary.cpp File Reference
#include <iostream>
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/io/DrawWithDisplay3DModifier.h"
#include "DGtal/io/viewers/Viewer3D.h"
#include "DGtal/io/Color.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "DGtal/shapes/implicit/ImplicitBall.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/ExplicitDigitalSurface.h"
#include "DGtal/topology/helpers/FrontierPredicate.h"
#include "DGtal/topology/helpers/BoundaryPredicate.h"
Include dependency graph for frontierAndBoundary.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2012/02/06

An example file named qglViewer.

This file is part of the DGtal library.

Definition in file frontierAndBoundary.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[frontierAndBoundary-LabelledImage]

[frontierAndBoundary-LabelledImage]

[frontierAndBoundary-KSpace]

[frontierAndBoundary-KSpace]

[frontierAndBoundary-SetUpDigitalSurface]

[frontierAndBoundary-SetUpDigitalSurface]

[volBreadthFirstTraversal-DisplayingSurface]

[volBreadthFirstTraversal-DisplayingSurface]

Definition at line 59 of file frontierAndBoundary.cpp.

60 {
63  typedef ImplicitBall<Space> EuclideanShape;
66  Point c1( 2, 0, 0 );
67  int radius1 = 6;
68  EuclideanShape ball1( c1, radius1 ); // ball r=6
69  DigitalShape shape1;
70  shape1.attach( ball1 );
71  shape1.init( RealPoint( -10.0, -10.0, -10.0 ),
72  RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
73  Point c2( -2, 0, 0 );
74  int radius2 = 5;
75  EuclideanShape ball2( c2, radius2 ); // ball r=6
76  DigitalShape shape2;
77  shape2.attach( ball2 );
78  shape2.init( RealPoint( -10.0, -10.0, -10.0 ),
79  RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
80  Domain domain = shape1.getDomain();
81  Image image( domain ); // p1, p2 );
82  std::cerr << std::endl;
83  for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end();
84  it != it_end; ++it )
85  {
86  DGtal::uint8_t label = shape1( *it ) ? 1 : 0;
87  label += shape2( *it ) ? 2 : 0;
88  image.setValue( *it, label );
89  std::cerr << (int) image( *it );
90  }
91  std::cerr << std::endl;
93 
95  trace.beginBlock( "Construct the Khalimsky space from the image domain." );
96  KSpace K;
97  bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true );
98  if (!space_ok)
99  {
100  trace.error() << "Error in the Khamisky space construction."<<std::endl;
101  return 2;
102  }
103  trace.endBlock();
105 
107  trace.beginBlock( "Set up digital surface." );
108  typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
109  MySurfelAdjacency surfAdj( true ); // interior in all directions.
110  typedef functors::FrontierPredicate<KSpace, Image> FSurfelPredicate;
111  typedef ExplicitDigitalSurface<KSpace,FSurfelPredicate> FrontierContainer;
112  typedef DigitalSurface<FrontierContainer> Frontier;
113  typedef functors::BoundaryPredicate<KSpace, Image> BSurfelPredicate;
114  typedef ExplicitDigitalSurface<KSpace,BSurfelPredicate> BoundaryContainer;
115  typedef DigitalSurface<BoundaryContainer> Boundary;
116  // frontier between label 1 and 0 (connected part containing bel10)
117  SCell vox1 = K.sSpel( c1 + Point( radius1, 0, 0 ), K.POS );
118  SCell bel10 = K.sIncident( vox1, 0, true );
119  FSurfelPredicate surfPredicate10( K, image, 1, 0 );
120  Frontier frontier10 =
121  new FrontierContainer( K, surfPredicate10, surfAdj, bel10 );
122  // frontier between label 2 and 0 (connected part containing bel20)
123  SCell vox2 = K.sSpel( c2 - Point( radius2, 0, 0 ), K.POS );
124  SCell bel20 = K.sIncident( vox2, 0, false );
125  FSurfelPredicate surfPredicate20( K, image, 2, 0 );
126  Frontier frontier20 =
127  new FrontierContainer( K, surfPredicate20, surfAdj, bel20 );
128  // boundary of label 3 (connected part containing bel32)
129  SCell vox3 = K.sSpel( c1 - Point( radius1, 0, 0 ), K.POS );
130  SCell bel32 = K.sIncident( vox3, 0, false );
131  BSurfelPredicate surfPredicate3( K, image, 3 );
132  Boundary boundary3 =
133  new BoundaryContainer( K, surfPredicate3, surfAdj, bel32 );
134  trace.endBlock();
136 
138  trace.beginBlock( "Displaying surface in Viewer3D." );
139  QApplication application(argc,argv);
140  Viewer3D<> viewer;
141  viewer.show();
142  viewer << SetMode3D( domain.className(), "BoundingBox" )
143  << domain;
144  Cell dummy;
145  // Display frontier between 1 and 0.
146  unsigned int nbSurfels10 = 0;
147  viewer << CustomColors3D( Color::Red, Color::Red );
149  it = frontier10.begin(), it_end = frontier10.end();
150  it != it_end; ++it, ++nbSurfels10 )
151  viewer << *it;
152  // Display frontier between 2 and 0.
153  unsigned int nbSurfels20 = 0;
154  viewer << CustomColors3D( Color::Yellow, Color::Yellow );
156  it = frontier20.begin(), it_end = frontier20.end();
157  it != it_end; ++it, ++nbSurfels20 )
158  viewer << *it;
159  // Display boundary of 3.
160  unsigned int nbSurfels3 = 0;
161  viewer << CustomColors3D( Color( 255, 130, 15 ), Color( 255, 130, 15 ) );
163  it = boundary3.begin(), it_end = boundary3.end();
164  it != it_end; ++it, ++nbSurfels3 )
165  viewer << *it;
166  trace.info() << "nbSurfels10 = " << nbSurfels10
167  << ", nbSurfels20 = " << nbSurfels20
168  << ", nbSurfels3 = " << nbSurfels3 << std::endl;
169  viewer << Viewer3D<>::updateDisplay;
170  trace.endBlock();
171  return application.exec();
173 }
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
void attach(ConstAlias< EuclideanShape > shape)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Domain getDomain() const
Iterator for HyperRectDomain.
const ConstIterator & end() const
const ConstIterator & begin() const
const Point & lowerBound() const
const Point & upperBound() const
std::string className() const
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:65
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
static constexpr const Sign POS
SCell sSpel(Point p, Sign sign=POS) const
From the digital coordinates of a point in Zn, builds the corresponding spel (cell of maximal dimensi...
SCell sIncident(const SCell &c, Dimension k, bool up) const
Return the forward or backward signed cell incident to [c] along axis [k], depending on [up].
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
std::ostream & error()
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Aim: The predicate on surfels that represents the frontier between a region and its complementary in ...
Aim: The predicate on surfels that represents the frontier between two regions in an image....
MyDigitalSurface::ConstIterator ConstIterator
boost::uint8_t uint8_t
unsigned 8-bit integer.
Definition: BasicTypes.h:59
Trace trace
Definition: Common.h:153
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
MyPointD Point
Definition: testClone2.cpp:383
KSpace K
Domain domain
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image
PointVector< 3, double > RealPoint

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), domain, DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getDomain(), image(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), K, DGtal::HyperRectDomain< TSpace >::lowerBound(), DGtal::KhalimskySpaceND< dim, TInteger >::POS, DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::KhalimskySpaceND< dim, TInteger >::sIncident(), DGtal::KhalimskySpaceND< dim, TInteger >::sSpel(), DGtal::trace, and DGtal::HyperRectDomain< TSpace >::upperBound().