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.
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{
232
233
235 typedef Z2::Point
Point;
243
244
245 Point p1 ( -20, -10 );
248
252
254
255
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
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
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
285
290 << bubble_set;
291 board.
saveSVG (
"bubble-set-dgtalboard.svg" );
292
293 board <<
SetMode( bubbleBorder.className(),
"DrawAdjacencies" )
295 << bubbleBorder;
296 board.
saveSVG (
"bubble-object-border-dgtalboard.svg" );
298
300 return true;
301}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Represents a digital topology as a couple of adjacency relations.
Iterator for HyperRectDomain.
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
const ConstIterator & begin() const
std::string className() const
const ConstIterator & end() const
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...
void beginBlock(const std::string &keyword="")
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
DigitalTopology< Adj8, Adj4 > DT8_4
MetricAdjacency< Space, 1 > Adj4
MetricAdjacency< Space, 2 > Adj8
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....
Struct representing a 2D point.
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet
References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::className(), LibBoard::Board::clear(), DGtal::CONNECTED, domain, DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insertNew(), DGtal::JORDAN_DT, LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.
Referenced by main().
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{
115
117 typedef Z2::Point
Point;
125
126
127 Point p1 ( -20, -10 );
130
134
136
137
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
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
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
167
169 board.
saveSVG (
"bubble-set.svg" );
170
171 board <<
SetMode( bubbleBorder.className(),
"DrawAdjacencies" )
173 << bubbleBorder;
174 board.
saveSVG (
"bubble-object-border.svg" );
175
177
179
181 DT8_4::ReverseTopology dt4_8 = dt8_4.reverseTopology();
182
183 ObjectType48 bubble2 ( dt4_8, bubble_set );
184
185
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
193 board << bubble_set
194 <<
SetMode( bubbleBorder2.className(),
"DrawAdjacencies" )
196 << bubbleBorder2;
197
198 board.
saveSVG (
"bubble-object-border-48.svg" );
199
200
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 )
212 else
214 flag = !flag;
215 }
216
217 board.
saveSVG (
"bubble-object-color-borders-48.svg" );
219
220 return true;
221}
References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Trace::beginBlock(), DGtal::HyperRectDomain< TSpace >::className(), LibBoard::Board::clear(), DGtal::CONNECTED, domain, DGtal::HyperRectDomain< TSpace >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insertNew(), DGtal::JORDAN_DT, LibBoard::Board::saveSVG(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.
Referenced by main().