Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
frontierAndBoundary.cpp
Go to the documentation of this file.
1
13
28
29
32#include <iostream>
33
34#include "DGtal/helpers/StdDefs.h"
35#include "DGtal/io/readers/VolReader.h"
36#include "DGtal/io/viewers/PolyscopeViewer.h"
37#include "DGtal/io/Color.h"
38#include "DGtal/io/colormaps/HueShadeColorMap.h"
39#include "DGtal/images/ImageSelector.h"
40#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
41#include "DGtal/shapes/implicit/ImplicitBall.h"
42#include "DGtal/shapes/GaussDigitizer.h"
43#include "DGtal/shapes/Shapes.h"
44#include "DGtal/topology/DigitalSurface.h"
45#include "DGtal/topology/ExplicitDigitalSurface.h"
46#include "DGtal/topology/helpers/FrontierPredicate.h"
47#include "DGtal/topology/helpers/BoundaryPredicate.h"
49
51
52using namespace std;
53using namespace DGtal;
54using namespace Z3i;
55
57
58int main( int argc, char** argv )
59{
62 typedef ImplicitBall<Space> EuclideanShape;
65 Point c1( 2, 0, 0 );
66 int radius1 = 6;
67 EuclideanShape ball1( c1, radius1 ); // ball r=6
68 DigitalShape shape1;
69 shape1.attach( ball1 );
70 shape1.init( RealPoint( -10.0, -10.0, -10.0 ),
71 RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
72 Point c2( -2, 0, 0 );
73 int radius2 = 5;
74 EuclideanShape ball2( c2, radius2 ); // ball r=6
75 DigitalShape shape2;
76 shape2.attach( ball2 );
77 shape2.init( RealPoint( -10.0, -10.0, -10.0 ),
78 RealPoint( 10.0, 10.0, 10.0 ), 1.0 );
79 Domain domain = shape1.getDomain();
80 Image image( domain ); // p1, p2 );
81 std::cerr << std::endl;
82 for ( Domain::ConstIterator it = domain.begin(), it_end = domain.end();
83 it != it_end; ++it )
84 {
85 DGtal::uint8_t label = shape1( *it ) ? 1 : 0;
86 label += shape2( *it ) ? 2 : 0;
87 image.setValue( *it, label );
88 std::cerr << (int) image( *it );
89 }
90 std::cerr << std::endl;
92
94 trace.beginBlock( "Construct the Khalimsky space from the image domain." );
95 KSpace K;
96 bool space_ok = K.init( domain.lowerBound(), domain.upperBound(), true );
97 if (!space_ok)
98 {
99 trace.error() << "Error in the Khamisky space construction."<<std::endl;
100 return 2;
101 }
102 trace.endBlock();
104
106 trace.beginBlock( "Set up digital surface." );
107 typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
108 MySurfelAdjacency surfAdj( true ); // interior in all directions.
109 typedef functors::FrontierPredicate<KSpace, Image> FSurfelPredicate;
110 typedef ExplicitDigitalSurface<KSpace,FSurfelPredicate> FrontierContainer;
111 typedef DigitalSurface<FrontierContainer> Frontier;
112 typedef functors::BoundaryPredicate<KSpace, Image> BSurfelPredicate;
113 typedef ExplicitDigitalSurface<KSpace,BSurfelPredicate> BoundaryContainer;
114 typedef DigitalSurface<BoundaryContainer> Boundary;
115 // frontier between label 1 and 0 (connected part containing bel10)
116 SCell vox1 = K.sSpel( c1 + Point( radius1, 0, 0 ), K.POS );
117 SCell bel10 = K.sIncident( vox1, 0, true );
118 FSurfelPredicate surfPredicate10( K, image, 1, 0 );
119 Frontier frontier10 =
120 new FrontierContainer( K, surfPredicate10, surfAdj, bel10 );
121 // frontier between label 2 and 0 (connected part containing bel20)
122 SCell vox2 = K.sSpel( c2 - Point( radius2, 0, 0 ), K.POS );
123 SCell bel20 = K.sIncident( vox2, 0, false );
124 FSurfelPredicate surfPredicate20( K, image, 2, 0 );
125 Frontier frontier20 =
126 new FrontierContainer( K, surfPredicate20, surfAdj, bel20 );
127 // boundary of label 3 (connected part containing bel32)
128 SCell vox3 = K.sSpel( c1 - Point( radius1, 0, 0 ), K.POS );
129 SCell bel32 = K.sIncident( vox3, 0, false );
130 BSurfelPredicate surfPredicate3( K, image, 3 );
131 Boundary boundary3 =
132 new BoundaryContainer( K, surfPredicate3, surfAdj, bel32 );
133 trace.endBlock();
135
137 trace.beginBlock( "Displaying surface in PolyscopeViewer." );
138 PolyscopeViewer<> viewer;
139 viewer << domain;
140
141 Cell dummy;
142 // Display frontier between 1 and 0.
143 unsigned int nbSurfels10 = 0;
144 viewer << Color::Red;
145 for ( Frontier::ConstIterator
146 it = frontier10.begin(), it_end = frontier10.end();
147 it != it_end; ++it, ++nbSurfels10 )
148 viewer << *it;
149 // Display frontier between 2 and 0.
150 unsigned int nbSurfels20 = 0;
151 viewer << Color::Yellow;
152 for ( Frontier::ConstIterator
153 it = frontier20.begin(), it_end = frontier20.end();
154 it != it_end; ++it, ++nbSurfels20 )
155 viewer << *it;
156 // Display boundary of 3.
157 unsigned int nbSurfels3 = 0;
158 viewer << Color( 255, 130, 15 );
159 for ( Boundary::ConstIterator
160 it = boundary3.begin(), it_end = boundary3.end();
161 it != it_end; ++it, ++nbSurfels3 )
162 viewer << *it;
163 trace.info() << "nbSurfels10 = " << nbSurfels10
164 << ", nbSurfels20 = " << nbSurfels20
165 << ", nbSurfels3 = " << nbSurfels3 << std::endl;
166 trace.endBlock();
167 viewer.show();
168 return 0;
170}
Structure representing an RGB triple with alpha component.
Definition Color.h:77
static const Color Red
Definition Color.h:425
static const Color Yellow
Definition Color.h:431
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
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....
void show() override
Starts the event loop and display of elements.
PointVector< dim, double > RealPoint
Definition SpaceND.h:117
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
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....
Z3i this namespace gathers the standard of types for 3D imagery.
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Space::RealPoint RealPoint
Definition StdDefs.h:170
Space::Point Point
Definition StdDefs.h:168
KSpace::SCell SCell
Definition StdDefs.h:149
KSpace::Cell Cell
Definition StdDefs.h:148
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
std::uint8_t uint8_t
unsigned 8-bit integer.
Definition BasicTypes.h:57
STL namespace.
int main()
Definition testBits.cpp:56
KSpace K
GaussDigitizer< Space, ImplicitShape > DigitalShape
Domain domain
Image image(domain)