File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
testObjectBorder.cpp File Reference
#include <iostream>
#include <iterator>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/DomainPredicate.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/kernel/sets/DigitalSetSelector.h"
#include "DGtal/kernel/sets/DigitalSetConverter.h"
#include "DGtal/topology/MetricAdjacency.h"
#include "DGtal/topology/DomainAdjacency.h"
#include "DGtal/topology/DigitalTopology.h"
#include "DGtal/topology/Object.h"
#include "DGtal/graph/Expander.h"
#include "DGtal/io/boards/Board2D.h"
Include dependency graph for testObjectBorder.cpp:

Go to the source code of this file.

Data Structures

struct  MyObjectStyleCustom
struct  MyObjectStyleCustomRed
struct  MyDrawStyleCustomRed
struct  MyDrawStyleCustomBlue
struct  MyDrawStyleCustomGreen

Functions

bool testObjectBorder ()
bool testBoard2D ()
int main ()

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2010/09/17

Functions for testing class ObjectBorder.

This file is part of the DGtal library.

Definition in file testObjectBorder.cpp.

Function Documentation

◆ main()

int main ( void )

Definition at line 306 of file testObjectBorder.cpp.

307{
308 bool res = testObjectBorder()
309 && testBoard2D();
310 return res ? 0 : 1;
311}
bool testObjectBorder()
bool testBoard2D()

References testBoard2D(), and testObjectBorder().

◆ testBoard2D()

bool testBoard2D ( )

Simple test of Board2D. Illustrates the border extraction of a simple 2D object considering different topologies.

Definition at line 229 of file testObjectBorder.cpp.

230{
231 trace.beginBlock ( "Testing Board2D with Object Borders in 2D ..." );
232
233 //typedef int Integer; // choose your digital line here.
234 typedef SpaceND<2> Z2; // Z^2
235 typedef Z2::Point Point;
236 typedef MetricAdjacency<Z2, 1> Adj4; // 4-adjacency type
237 typedef MetricAdjacency<Z2, 2> Adj8; // 8-adjacency type
238 typedef DigitalTopology< Adj8, Adj4 > DT8_4; //8,4 topology type
240 typedef Domain::ConstIterator DomainConstIterator;
242 typedef Object<DT8_4, DigitalSet> ObjectType;
243
244
245 Point p1 ( -20, -10 );
246 Point p2 ( 20, 10 );
247 Domain domain ( p1, p2 );
248
249 Adj4 adj4; // instance of 4-adjacency
250 Adj8 adj8; // instance of 8-adjacency
251 DT8_4 dt8_4 ( adj8, adj4, JORDAN_DT );
252
253 Point c ( 0, 0 );
254
255 //We construct a simple 3-bubbles set
256 DigitalSet bubble_set ( domain );
257 for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
258 {
259 int x = ( *it ) [0];
260 int y = ( *it ) [1];
261 if ( ( x*x + y*y < 82 ) ||
262 ( ( x - 14 ) * ( x - 14 ) + ( y + 1 ) * ( y + 1 ) < 17 ) ||
263 ( ( x + 14 ) * ( x + 14 ) + ( y - 1 ) * ( y - 1 ) < 17 ) )
264 bubble_set.insertNew ( *it );
265 }
266
267 ObjectType bubble ( dt8_4, bubble_set );
268
269 //Connectedness Check
270 if (bubble.computeConnectedness() == CONNECTED)
271 trace.info() << "The object is (8,4)connected." << endl;
272 else
273 trace.info() << "The object is not (8,4)connected." << endl;
274
275 //Border Computation
276 ObjectType bubbleBorder = bubble.border();
277 if (bubbleBorder.computeConnectedness() == CONNECTED)
278 trace.info() << "The object (8,4) border is connected." << endl;
279 else
280 trace.info() << "The object (8,4) border is not connected." << endl;
281
282 //Board Export
283 Board2D board;
284 board.setUnit ( Board::UCentimeter );
285
286 board << SetMode( domain.className(), "Grid" )
287 << CustomStyle ( domain.className(), new MyDrawStyleCustomGreen )
288 << domain
289 << CustomStyle ( bubble_set.className(), new MyDrawStyleCustomRed )
290 << bubble_set;
291 board.saveSVG ( "bubble-set-dgtalboard.svg" );
292
293 board << SetMode( bubbleBorder.className(), "DrawAdjacencies" )
294 << CustomStyle ( bubbleBorder.className(), new MyDrawStyleCustomBlue )
295 << bubbleBorder;
296 board.saveSVG ( "bubble-object-border-dgtalboard.svg" );
297 board.clear();
298
299 trace.endBlock();
300 return true;
301}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: Describes digital adjacencies in digital spaces that are defined with the 1-norm and the infinit...
Aim: An object (or digital object) represents a set in some digital space associated with a digital t...
Definition Object.h:120
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition Board.cpp:151
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition Board.cpp:1011
void setUnit(Unit unit)
Definition Board.cpp:239
DigitalTopology< Adj8, Adj4 > DT8_4
Definition StdDefs.h:94
MetricAdjacency< Space, 1 > Adj4
Definition StdDefs.h:90
MetricAdjacency< Space, 2 > Adj8
Definition StdDefs.h:92
Space Z2
Definition StdDefs.h:76
@ CONNECTED
Definition Topology.h:52
Trace trace
DigitalSetByAssociativeContainer< Domain, std::unordered_set< typename Domain::Point > > Type
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Definition Board2D.h:247
Struct representing a 2D point.
Definition Point.h:27
Domain domain
Z2i::DigitalSet DigitalSet

References DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::className(), LibBoard::Board::clear(), DGtal::CONNECTED, domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insertNew(), DGtal::JORDAN_DT, LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.

Referenced by main().

◆ testObjectBorder()

bool testObjectBorder ( )

Simple test to illustrate the border extraction of a simple 2D object considering different topologies.

Definition at line 112 of file testObjectBorder.cpp.

113{
114 trace.beginBlock ( "Testing Object Borders in 2D ..." );
115
116 typedef SpaceND<2> Z2; // Z^2
117 typedef Z2::Point Point;
118 typedef MetricAdjacency<Z2, 1> Adj4; // 4-adjacency type
119 typedef MetricAdjacency<Z2, 2> Adj8; // 8-adjacency type
120 typedef DigitalTopology< Adj8, Adj4 > DT8_4; //8,4 topology type
122 typedef Domain::ConstIterator DomainConstIterator;
124 typedef Object<DT8_4, DigitalSet> ObjectType;
125
126
127 Point p1 ( -20, -10 );
128 Point p2 ( 20, 10 );
129 Domain domain ( p1, p2 );
130
131 Adj4 adj4; // instance of 4-adjacency
132 Adj8 adj8; // instance of 8-adjacency
133 DT8_4 dt8_4 ( adj8, adj4, JORDAN_DT );
134
135 Point c ( 0, 0 );
136
137 //We construct a simple 3-bubbles set
138 DigitalSet bubble_set ( domain );
139 for ( DomainConstIterator it = domain.begin(); it != domain.end(); ++it )
140 {
141 int x = ( *it ) [0];
142 int y = ( *it ) [1];
143 if ( ( x*x + y*y < 82 ) ||
144 ( ( x - 14 ) * ( x - 14 ) + ( y + 1 ) * ( y + 1 ) < 17 ) ||
145 ( ( x + 14 ) * ( x + 14 ) + ( y - 1 ) * ( y - 1 ) < 17 ) )
146 bubble_set.insertNew ( *it );
147 }
148
149 ObjectType bubble ( dt8_4, bubble_set );
150
151 //Connectedness Check
152 if (bubble.computeConnectedness() == CONNECTED)
153 trace.info() << "The object is (8,4)connected." << endl;
154 else
155 trace.info() << "The object is not (8,4)connected." << endl;
156
157 //Border Computation
158 ObjectType bubbleBorder = bubble.border();
159 if (bubbleBorder.computeConnectedness() == CONNECTED)
160 trace.info() << "The object (8,4) border is connected." << endl;
161 else
162 trace.info() << "The object (8,4) border is not connected." << endl;
163
164 //Board Export
165 Board2D board;
166 board.setUnit ( Board::UCentimeter );
167
168 board << SetMode( domain.className(), "Grid" ) << domain << bubble_set;
169 board.saveSVG ( "bubble-set.svg" );
170
171 board << SetMode( bubbleBorder.className(), "DrawAdjacencies" )
172 << CustomStyle ( bubbleBorder.className(), new MyObjectStyleCustom )
173 << bubbleBorder;
174 board.saveSVG ( "bubble-object-border.svg" );
175
176 board.clear();
177
179 //the same with the reverse topology
181 DT8_4::ReverseTopology dt4_8 = dt8_4.reverseTopology();
182
183 ObjectType48 bubble2 ( dt4_8, bubble_set );
184
185 //Border Computation
186 ObjectType48 bubbleBorder2 = bubble2.border();
187 if (bubbleBorder2.computeConnectedness() == CONNECTED)
188 trace.info() << "The object (4,8) border is connected." << endl;
189 else
190 trace.info() << "The object (4,8) border is not connected." << endl;
191
192 board << SetMode( domain.className(), "Grid" ) << domain;
193 board << bubble_set
194 << SetMode( bubbleBorder2.className(), "DrawAdjacencies" )
195 << CustomStyle ( bubbleBorder2.className(), new MyObjectStyleCustom )
196 << bubbleBorder2;
197
198 board.saveSVG ( "bubble-object-border-48.svg" );
199
200 //We split the border according to its components
201 vector<ObjectType48> borders ( 30 );
202 vector<ObjectType48>::iterator it = borders.begin();
203 auto nbComponents = bubbleBorder2.writeComponents ( it );
204
205 trace.info() << "The Bubble object has " << nbComponents << " (4,8)-connected components" << endl;
206
207 bool flag = true;
208 for ( unsigned int k = 0;k < nbComponents ; k++ )
209 {
210 if ( flag )
211 board << SetMode( borders[k].className(), "DrawAdjacencies" ) << CustomStyle ( borders[k].className(), new MyObjectStyleCustom ) << borders[k];
212 else
213 board << SetMode( borders[k].className(), "DrawAdjacencies" ) << CustomStyle ( borders[k].className(), new MyObjectStyleCustom ) << borders[k];
214 flag = !flag;
215 }
216
217 board.saveSVG ( "bubble-object-color-borders-48.svg" );
218 trace.endBlock();
219
220 return true;
221}

References LibBoard::Board::clear(), DGtal::CONNECTED, domain, DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insertNew(), DGtal::JORDAN_DT, LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.

Referenced by main().