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
- 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/04/19
Functions for testing class LatticePolytope2D.
This file is part of the DGtal library.
Definition in file testLatticePolytope2D.cpp.
Definition at line 51 of file testLatticePolytope2D.cpp.
53{
58
60#ifdef DEBUG_LatticePolytope2D
62 board <<
SetMode( d.className(),
"Grid" ) << d;
65 Color col1( 100, 100, 255 );
66 Color col2( 180, 180, 255 );
68 << aSet;
72#endif
73
76 cip.getIncludedDigitalPoints( cipSet );
77 cip.cut( hs );
78 cip.getIncludedDigitalPoints( cipSet2 );
79#ifdef DEBUG_LatticePolytope2D
80 board <<
SetMode( d.className(),
"Grid" ) << d;
82 << cipSet;
84 << cipSet2;
85 board <<
SetMode( cip.className(),
"Transparent" ) << cip;
87#endif
88
89 unsigned int nbok = 0;
90 unsigned int nb = 0;
91 for (
ConstIterator it = cipSet2.begin(), it_end = cipSet2.end();
92 it != it_end; ++it )
93 {
94 nbok += ( cipSet.find( *it ) != cipSet.end() ) ? 1 : 0;
95 ++nb;
96 nbok += hs( *it );
97 ++nb;
98 }
99 for (
ConstIterator it = cipSet.begin(), it_end = cipSet.end();
100 it != it_end; ++it )
101 {
102 if ( cipSet2.find( *it ) == cipSet2.end() )
103 nbok += ! hs( *it );
104 else
105 nbok += hs( *it );
106 ++nb;
107 }
108 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
109 << " cip.size()=" << cip.size()
110 << " #before=" << cipSet.size()
111 << " #after=" << cipSet2.size()
112 << std::endl;
114 return nbok == nb;
115}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Structure representing an RGB triple with alpha component.
Container::const_iterator ConstIterator
Domain boundingBoxDomain() const
std::string className() const
HyperRectDomain< Space > Domain
static void makeSetFromPointPredicate(DigitalSet &aSet, const PointPredicate &aPP)
void beginBlock(const std::string &keyword="")
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
CustomStyle(std::string classname, DrawableWithBoard2D *style)
DigitalSetByAssociativeContainer< Domain, std::unordered_set< typename Domain::Point > > Type
SetMode(std::string classname, std::string mode)
Z2i::DigitalSet DigitalSet
References DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::LatticePolytope2D< TSpace, TSequence >::boundingBoxDomain(), checkCut(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::className(), DGtal::LatticePolytope2D< TSpace, TSequence >::className(), LibBoard::Board::clear(), DGtal::Color::Color(), DGtal::CustomStyle::CustomStyle(), DGtal::LatticePolytope2D< TSpace, TSequence >::cut(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::end(), DGtal::Trace::endBlock(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::find(), DGtal::LatticePolytope2D< TSpace, TSequence >::getIncludedDigitalPoints(), DGtal::Trace::info(), DGtal::Shapes< TDomain >::makeSetFromPointPredicate(), LibBoard::Board::saveEPS(), DGtal::SetMode::SetMode(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::size(), DGtal::LatticePolytope2D< TSpace, TSequence >::size(), and DGtal::trace.
Referenced by checkCut(), exhaustiveTestLatticePolytope2D(), specificTestLatticePolytope2D(), and testLatticePolytope2D().
| bool exhaustiveTestLatticePolytope2D |
( |
| ) |
|
Example of a test. To be completed.
Definition at line 218 of file testLatticePolytope2D.cpp.
219{
220 unsigned int nbok = 0;
221 unsigned int nb = 0;
222
223 trace.
beginBlock (
"Testing block LatticePolytope2D area and centroid" );
228 typedef typename CIP::Point3I Point3I;
229 typedef typename CIP::Domain
Domain;
230 typedef typename CIP::HalfSpace HalfSpace;
231
232 CIP cip;
233 cip.pushBack(
Point( 0, 0 ) );
234 cip.pushBack(
Point( 8, -3 ) );
235 cip.pushBack(
Point( 17, 2 ) );
236 cip.pushBack(
Point( 21, 13 ) );
237 cip.pushBack(
Point( 13, 19 ) );
238 cip.pushBack(
Point( 6, 17 ) );
239 cip.pushBack(
Point( -3, 6 ) );
240 Integer area2 = cip.twiceArea();
241 trace.
info() <<
"- 2*area = " << area2 << std::endl;
242 Point3I c = cip.centroid( area2 );
243 trace.
info() <<
"- centroid = " << c << std::endl;
244 Domain d = cip.boundingBoxDomain();
245 trace.
info() <<
"- domain = " << d << std::endl;
247
249 for ( unsigned int j = 0; j < 100; ++j )
250 {
251 CIP cip2 = cip;
252 int x = 0;
253 int y = 0;
254 while ( ( x == 0 ) && ( y == 0 ) )
255 {
258 }
262 for (
unsigned int i = 0; i < 10; ++i, cc -=
myRand( 40 ) )
263 {
264 HalfSpace h(
Vector( x, y ), cc );
265 trace.
info() <<
"[" << j <<
" size=" << cip2.size() <<
"]"
266 << " cut by (" << x << "," << y << ")," << c << std::endl;
267 ++nb; nbok +=
checkCut( cip2, h ) ? 1 : 0;
268 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") cuts" << std::endl;
269
270 if ( nb != nbok ) break;
271 }
272 std::cerr << std::endl;
273 if ( nb != nbok ) break;
274 }
276 return nbok == nb;
277}
static Integer staticGcd(IntegerParamType a, IntegerParamType b)
bool checkCut(LatticePolytope2D &cip, typename LatticePolytope2D::HalfSpace hs)
References DGtal::Trace::beginBlock(), checkCut(), DGtal::Trace::endBlock(), exhaustiveTestLatticePolytope2D(), g(), DGtal::Trace::info(), myRand(), DGtal::IntegerComputer< TInteger >::staticGcd(), and DGtal::trace.
Referenced by exhaustiveTestLatticePolytope2D(), and main().
| bool specificTestLatticePolytope2D |
( |
| ) |
|
Example of a test. To be completed.
Definition at line 284 of file testLatticePolytope2D.cpp.
285{
286 unsigned int nbok = 0;
287 unsigned int nb = 0;
288
292 typedef typename CIP::Domain
Domain;
293 typedef typename CIP::HalfSpace HalfSpace;
296
297 CIP cip;
298 cip.pushBack(
Point( 0, 0 ) );
299 cip.pushBack(
Point( 8, -3 ) );
300 cip.pushBack(
Point( 17, 2 ) );
301 cip.pushBack(
Point( 21, 13 ) );
302 cip.pushBack(
Point( 13, 19 ) );
303 cip.pushBack(
Point( 6, 17 ) );
304 cip.pushBack(
Point( -3, 6 ) );
305 HalfSpace hs1(
Vector( -5, 11 ), 8 );
306 HalfSpace hs2(
Vector( -3, -11 ), 8 );
307 ++nb; nbok +=
checkCut( cip, hs1 ) ? 1 : 0;
308
309 Domain d = cip.boundingBoxDomain();
311 board <<
SetMode( d.className(),
"Grid" ) << d;
314 ++itv; ++itv; ++itv; ++itv; ++itv; ++itv; ++itv;
315 HalfSpace hs( cip.halfSpace( itv ) );
317 Color col1( 100, 180, 100 );
318 Color col2( 130, 200, 130 );
320 << aSet;
321 board <<
SetMode( cip.className(),
"Transparent" ) << cip;
324 << p;
327
328 ++nb; nbok +=
checkCut( cip, hs2 ) ? 1 : 0;
329 return nbok == nb;
330}
References checkCut(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::className(), LibBoard::Board::clear(), DGtal::CustomStyle::CustomStyle(), DGtal::Shapes< TDomain >::makeSetFromPointPredicate(), DGtal::Color::Red, LibBoard::Board::saveEPS(), DGtal::SetMode::SetMode(), and specificTestLatticePolytope2D().
Referenced by specificTestLatticePolytope2D().
| bool testLatticePolytope2D |
( |
| ) |
|
Example of a test. To be completed.
Definition at line 122 of file testLatticePolytope2D.cpp.
123{
124 unsigned int nbok = 0;
125 unsigned int nb = 0;
126
127 trace.
beginBlock (
"Testing block LatticePolytope2D area and centroid" );
132 typedef typename CIP::Point3I Point3I;
133 typedef typename CIP::Domain
Domain;
134 typedef typename CIP::HalfSpace HalfSpace;
135 typedef typename CIP::Iterator
Iterator;
137
138 CIP cip;
139 cip.pushBack(
Point( 0, 0 ) );
140 cip.pushBack(
Point( 5, 0 ) );
141 cip.pushBack(
Point( 0, 3 ) );
142 Integer area2 = cip.twiceArea();
143 trace.
info() <<
"- 2*area = " << area2 << std::endl;
144 ++nb; nbok += ( area2 == 15 ) ? 1 : 0;
145 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
146 << "2*area == 15" << std::endl;
147 Point3I c = cip.centroid( area2 );
148 trace.
info() <<
"- centroid = " << c << std::endl;
149 ++nb; nbok += ( c == Point3I( 75, 45, 45 ) ) ? 1 : 0;
150 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
151 << "centroid == [75,45,45]" << std::endl;
152 Domain d = cip.boundingBoxDomain();
153 trace.
info() <<
"- domain = " << d << std::endl;
155
157 cip.pushBack(
Point( -4, 4 ) );
158 cip.pushBack(
Point( -7, 2 ) );
159 cip.pushBack(
Point( -5, 1 ) );
161 d = cip.boundingBoxDomain();
162 board <<
SetMode( d.className(),
"Grid" ) << d;
164 HalfSpace h(
Vector( 1, 3 ), 8 );
165
167 Color col1( 100, 100, 255 );
168 Color col2( 180, 180, 255 );
170 << aSet;
171 cip.getIncludedDigitalPoints( aSet );
173 << aSet;
174 board <<
SetMode( cip.className(),
"Transparent" ) << cip;
176
177 cip.findCut( itA1, itB2, h );
179 if ( itB1 == cip.end() ) itB1 = cip.begin();
181 if ( itA2 == cip.end() ) itA2 = cip.begin();
182 Color col3( 0, 255, 0 );
183 Color col4( 255, 0, 0 );
185 << *itA1 << *itA2;
187 << *itB1 << *itB2;
191
194 board <<
SetMode( d.className(),
"Grid" ) << d;
195 board <<
SetMode( cip.className(),
"Transparent" ) << cip;
196 bool wasCut = cip.cut( h );
197 FATAL_ERROR(wasCut);
198 board <<
SetMode( cip.className(),
"Filled" ) << cip;
202
204
205 return nbok == nb;
206}
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
CustomColors(const Color &penColor, const Color &fillColor)
References DGtal::Trace::beginBlock(), checkCut(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::className(), LibBoard::Board::clear(), DGtal::Color::Color(), DGtal::CustomColors::CustomColors(), DGtal::CustomStyle::CustomStyle(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::Shapes< TDomain >::makeSetFromPointPredicate(), LibBoard::Board::saveEPS(), LibBoard::Board::saveSVG(), DGtal::SetMode::SetMode(), testLatticePolytope2D(), and DGtal::trace.
Referenced by main(), and testLatticePolytope2D().