35 #include "DGtal/base/Common.h"
36 #include "DGtal/arithmetic/LatticePolytope2D.h"
37 #include "DGtal/shapes/Shapes.h"
38 #include "DGtal/io/boards/Board2D.h"
43 using namespace DGtal;
49 template <
typename LatticePolytope2D>
60 #ifdef DEBUG_LatticePolytope2D
65 Color col1( 100, 100, 255 );
66 Color col2( 180, 180, 255 );
79 #ifdef DEBUG_LatticePolytope2D
89 unsigned int nbok = 0;
94 nbok += ( cipSet.
find( *it ) != cipSet.
end() ) ? 1 : 0;
102 if ( cipSet2.
find( *it ) == cipSet2.
end() )
108 trace.
info() <<
"(" << nbok <<
"/" << nb <<
")"
109 <<
" cip.size()=" << cip.
size()
110 <<
" #before=" << cipSet.
size()
111 <<
" #after=" << cipSet2.
size()
121 template <
typename Space>
124 unsigned int nbok = 0;
127 trace.
beginBlock (
"Testing block LatticePolytope2D area and centroid" );
132 typedef typename CIP::Point3I Point3I;
134 typedef typename CIP::HalfSpace HalfSpace;
135 typedef typename CIP::Iterator Iterator;
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;
157 cip.pushBack(
Point( -4, 4 ) );
158 cip.pushBack(
Point( -7, 2 ) );
159 cip.pushBack(
Point( -5, 1 ) );
161 d = cip.boundingBoxDomain();
164 HalfSpace h(
Vector( 1, 3 ), 8 );
167 Color col1( 100, 100, 255 );
168 Color col2( 180, 180, 255 );
171 cip.getIncludedDigitalPoints( aSet );
174 board <<
SetMode( cip.className(),
"Transparent" ) << cip;
177 cip.findCut( itA1, itB2, h );
178 Iterator itB1 = itA1; ++itB1;
179 if ( itB1 == cip.end() ) itB1 = cip.begin();
180 Iterator itA2 = itB2; ++itA2;
181 if ( itA2 == cip.end() ) itA2 = cip.begin();
182 Color col3( 0, 255, 0 );
183 Color col4( 255, 0, 0 );
195 board <<
SetMode( cip.className(),
"Transparent" ) << cip;
196 bool wasCut = cip.cut( h );
198 board <<
SetMode( cip.className(),
"Filled" ) << cip;
217 template <
typename Space>
220 unsigned int nbok = 0;
223 trace.
beginBlock (
"Testing block LatticePolytope2D area and centroid" );
228 typedef typename CIP::Point3I Point3I;
230 typedef typename CIP::HalfSpace HalfSpace;
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;
249 for (
unsigned int j = 0; j < 100; ++j )
254 while ( ( x == 0 ) && ( y == 0 ) )
262 for (
unsigned int i = 0; i < 10; ++i, cc -=
myRand( 40 ) )
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;
270 if ( nb != nbok )
break;
272 std::cerr << std::endl;
273 if ( nb != nbok )
break;
283 template <
typename Space>
286 unsigned int nbok = 0;
293 typedef typename CIP::HalfSpace HalfSpace;
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;
309 Domain d = cip.boundingBoxDomain();
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 );
321 board <<
SetMode( cip.className(),
"Transparent" ) << cip;
328 ++nb; nbok +=
checkCut( cip, hs2 ) ? 1 : 0;
332 template <
typename Space>
341 typedef typename CIP::HalfSpace HalfSpace;
352 HalfSpace hs1( c1, c1 +
Vector( 0, 1 ), In, ic );
353 HalfSpace hs2( A, B, In, ic );
354 HalfSpace hs3( c3, c3 +
Vector( 0, 1 ), In, ic );
357 cip.computeConvexHullBorder( std::back_inserter( cip ), c1, c3, hs1, hs2, hs3 );
360 Domain d = cip.boundingBoxDomain();
365 Color col1( 100, 180, 100 );
366 Color col2( 220, 250, 220 );
369 board <<
SetMode( cip.className(),
"Transparent" ) << cip;
387 bool res = testLatticePolytope2D<Z2>()
388 && testLatticePolytope2D<Z2I>()
389 && exhaustiveTestLatticePolytope2D<Z2>()
390 && checkOutputConvexHullBorder<Z2>();
393 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Structure representing an RGB triple with alpha component.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
std::string className() const
ConstIterator end() const
ConstIterator find(const Point &p) const
ConstIterator begin() const
Container::const_iterator ConstIterator
ConstIterator type of the container;.
std::string className() const
Aim: This class gathers several types and methods to make computation with integers.
Aim: Represents a 2D polytope, i.e. a convex polygon, in the two-dimensional digital plane....
Domain boundingBoxDomain() const
std::string className() const
bool cut(const HalfSpace &hs)
void getIncludedDigitalPoints(DigitalSet &aSet) const
Aim: A utility class for constructing different shapes (balls, diamonds, and others).
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
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
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
DigitalPlane::Point Vector
Point::Coordinate Integer
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A half-space specified by a vector N and a constant c. The half-space is the set .
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Modifier class in a Board2D stream. Useful to choose your own mode for a given class....
Go to http://www.sgi.com/tech/stl/Container.html.
bool checkOutputConvexHullBorder()
bool testLatticePolytope2D()
bool checkCut(LatticePolytope2D &cip, typename LatticePolytope2D::HalfSpace hs)
bool exhaustiveTestLatticePolytope2D()
bool specificTestLatticePolytope2D()
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet