DGtal  1.3.beta
topology/frontierAndBoundary.cpp

Frontiers and boundary of two intersecting balls. The first ball is labelled 1 (red), the second 2 (yellow), their intersection 3 (orange). The frontier between 1 and 0 is displayed in red, the frontier between 2 and 0 is displayed in yellow, the boundary of region 3 is displayed in orange.

See also
Boundary and frontiers examples of digital surface
#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"
using namespace std;
using namespace DGtal;
using namespace Z3i;
int main( int argc, char** argv )
{
typedef ImplicitBall<Space> EuclideanShape;
Point c1( 2, 0, 0 );
int radius1 = 6;
EuclideanShape ball1( c1, radius1 ); // ball r=6
DigitalShape shape1;
shape1.attach( ball1 );
shape1.init( RealPoint( -10.0, -10.0, -10.0 ),
RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
Point c2( -2, 0, 0 );
int radius2 = 5;
EuclideanShape ball2( c2, radius2 ); // ball r=6
DigitalShape shape2;
shape2.attach( ball2 );
shape2.init( RealPoint( -10.0, -10.0, -10.0 ),
RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
Domain domain = shape1.getDomain();
Image image( domain ); // p1, p2 );
std::cerr << std::endl;
for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end();
it != it_end; ++it )
{
DGtal::uint8_t label = shape1( *it ) ? 1 : 0;
label += shape2( *it ) ? 2 : 0;
image.setValue( *it, label );
std::cerr << (int) image( *it );
}
std::cerr << std::endl;
trace.beginBlock( "Construct the Khalimsky space from the image domain." );
bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true );
if (!space_ok)
{
trace.error() << "Error in the Khamisky space construction."<<std::endl;
return 2;
}
trace.beginBlock( "Set up digital surface." );
typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
MySurfelAdjacency surfAdj( true ); // interior in all directions.
// frontier between label 1 and 0 (connected part containing bel10)
SCell vox1 = K.sSpel( c1 + Point( radius1, 0, 0 ), K.POS );
SCell bel10 = K.sIncident( vox1, 0, true );
FSurfelPredicate surfPredicate10( K, image, 1, 0 );
Frontier frontier10 =
new FrontierContainer( K, surfPredicate10, surfAdj, bel10 );
// frontier between label 2 and 0 (connected part containing bel20)
SCell vox2 = K.sSpel( c2 - Point( radius2, 0, 0 ), K.POS );
SCell bel20 = K.sIncident( vox2, 0, false );
FSurfelPredicate surfPredicate20( K, image, 2, 0 );
Frontier frontier20 =
new FrontierContainer( K, surfPredicate20, surfAdj, bel20 );
// boundary of label 3 (connected part containing bel32)
SCell vox3 = K.sSpel( c1 - Point( radius1, 0, 0 ), K.POS );
SCell bel32 = K.sIncident( vox3, 0, false );
BSurfelPredicate surfPredicate3( K, image, 3 );
Boundary boundary3 =
new BoundaryContainer( K, surfPredicate3, surfAdj, bel32 );
trace.beginBlock( "Displaying surface in Viewer3D." );
QApplication application(argc,argv);
Viewer3D<> viewer;
viewer.show();
viewer << SetMode3D( domain.className(), "BoundingBox" )
<< domain;
Cell dummy;
// Display frontier between 1 and 0.
unsigned int nbSurfels10 = 0;
viewer << CustomColors3D( Color::Red, Color::Red );
it = frontier10.begin(), it_end = frontier10.end();
it != it_end; ++it, ++nbSurfels10 )
viewer << *it;
// Display frontier between 2 and 0.
unsigned int nbSurfels20 = 0;
viewer << CustomColors3D( Color::Yellow, Color::Yellow );
it = frontier20.begin(), it_end = frontier20.end();
it != it_end; ++it, ++nbSurfels20 )
viewer << *it;
// Display boundary of 3.
unsigned int nbSurfels3 = 0;
viewer << CustomColors3D( Color( 255, 130, 15 ), Color( 255, 130, 15 ) );
it = boundary3.begin(), it_end = boundary3.end();
it != it_end; ++it, ++nbSurfels3 )
viewer << *it;
trace.info() << "nbSurfels10 = " << nbSurfels10
<< ", nbSurfels20 = " << nbSurfels20
<< ", nbSurfels3 = " << nbSurfels3 << std::endl;
viewer << Viewer3D<>::updateDisplay;
return application.exec();
}
DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition: GaussDigitizer.h:79
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::GaussDigitizer::getDomain
Domain getDomain() const
image
Image image(domain)
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition: DigitalSurface.h:139
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::Trace::error
std::ostream & error()
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::HyperRectDomain::className
std::string className() const
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::KhalimskySpaceND::sSpel
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...
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::GaussDigitizer::init
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
DGtal::Trace::info
std::ostream & info()
DGtal::Viewer3D
Definition: Viewer3D.h:135
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition: testSimpleRandomAccessRangeFromPoint.cpp:45
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::ExplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: ExplicitDigitalSurface.h:81
DGtal::functors::FrontierPredicate
Aim: The predicate on surfels that represents the frontier between two regions in an image....
Definition: FrontierPredicate.h:67
DGtal::KhalimskySpaceND::POS
static const constexpr Sign POS
Definition: KhalimskySpaceND.h:432
DGtal::ImplicitBall
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition: ImplicitBall.h:64
DGtal::CustomColors3D
Definition: DrawWithDisplay3DModifier.h:129
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition: HyperRectDomain.h:201
DGtal::SetMode3D
Modifier class in a Display3D stream. Useful to choose your own mode for a given class....
Definition: DrawWithDisplay3DModifier.h:73
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
DGtal::HyperRectDomain_Iterator
Iterator for HyperRectDomain.
Definition: HyperRectDomain_Iterator.h:142
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
DGtal::Viewer3D::show
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
DGtal::KhalimskySpaceND::sIncident
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].
DGtal::functors::BoundaryPredicate
Aim: The predicate on surfels that represents the frontier between a region and its complementary in ...
Definition: BoundaryPredicate.h:69
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition: HyperRectDomain.h:176
Point
MyPointD Point
Definition: testClone2.cpp:383
RealPoint
Z2i::RealPoint RealPoint
Definition: testAstroid2D.cpp:46
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::KhalimskyCell< dim, Integer >
DGtal::uint8_t
boost::uint8_t uint8_t
unsigned 8-bit integer.
Definition: BasicTypes.h:59
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64