46#include "DGtal/base/Common.h"
47#include "DGtal/helpers/StdDefs.h"
48#include "DGtal/geometry/volumes/DigitalConvexity.h"
55template <
typename Po
int>
58 for (
Dimension i = 0; i < Point::dimension; i++ )
59 p[ i ] = rand() % width;
62template <
typename Po
int>
66 for (
int i = 0; i < nb; i++ )
70template <
typename ProjectedPo
int,
typename Po
int >
74 for (
Dimension i = 0; i < Point::dimension; i++ )
75 if ( i != a ) pp[ j++ ] = p[ i ];
78template <
typename ProjectedPo
int,
typename Po
int >
80 const std::vector< Point > & p,
Dimension a )
82 pp.resize( p.size() );
83 for (
size_t i = 0; i < p.size(); i++ )
85 std::sort( pp.begin(), pp.end() );
86 auto last = std::unique( pp.begin(), pp.end() );
87 pp.erase( last, pp.end() );
92template <
typename Space>
96 typedef typename Space::Integer
Integer;
102 Point lo = Point::zero;
103 Point hi = Point::diagonal( width );
104 DConvexity dconv( lo, hi );
105 std::vector< Point > X;
106 int nb = Space::dimension + rand() % 7;
110 auto Y = C.extremaOfCells();
113 trace.
warning() <<
"FC*(X) is not fully convex !" << std::endl;
117 trace.
warning() <<
"Extr(Star(CvxH(X))) is not fully convex !" << std::endl;
118 for (
auto p : Y ) std::cout <<
" " << p;
121 bool ok3 = std::includes( Y.cbegin(), Y.cend(), E.cbegin(), E.cend() );
123 <<
" #FC*(X)=" << E.size() << ( ok1 ?
"/FC" :
"/ERROR" )
124 <<
" #Extr(Star(CvxH(X)))=" << Y.size()
125 << ( ok2 ?
"/FC" :
"/ERROR" )
126 << ( ok3 ?
" FC*(X) subset Extr(Star(CvxH(X)))" :
" Inclusion ERROR" )
128 return ok1 && ok2 && ok3;
132template <
typename Space>
136 typedef typename Space::Integer
Integer;
143 Point lo = Point::zero;
144 Point hi = Point::diagonal( width );
145 DConvexity dconv( lo, hi );
146 std::vector< Point > X, XpH, Y;
147 int nb = Space::dimension + rand() % 7;
149 std::sort( X.begin(), X.end() );
151 for (
Dimension k = 0; k < Space::dimension; k++ )
152 XpH = dconv.
U( k, XpH );
158 trace.
warning() <<
"FC*(X) is not fully convex !" << std::endl;
162 trace.
warning() <<
"CvxH(X+H) cap Z^d is not fully convex !" << std::endl;
163 for (
auto p : Y ) std::cout <<
" " << p;
166 bool ok3 = std::includes( Y.cbegin(), Y.cend(), E.cbegin(), E.cend() );
168 <<
" #CvxH(X+H) cap Z^d=" << Y.size()
169 << ( ok2 ?
"/FC" :
"/ERROR" )
170 <<
" #FC*(X)=" << E.size() << ( ok1 ?
"/FC" :
"/ERROR" )
171 << ( ok3 ?
" FC*(X) subset CvxH(X+H) cap Z^d"
172 :
" FC*(X) not subset CvxH(X+H) cap Z^d" )
178template <
typename Space>
182 typedef typename Space::Integer
Integer;
189 typedef typename ProjKSpace::Point ProjPoint;
193 Point lo = Point::zero;
194 Point hi = Point::diagonal( width );
195 DConvexity dconv( lo, hi );
196 std::vector< Point > X;
197 int n = Space::dimension + rand() % 7;
201 unsigned int nb_ok = 0;
202 for (
Dimension a = 0; a < Space::dimension; a++ )
207 ProjDConvexity pdconv( plo,
phi );
208 std::vector< ProjPoint > PE;
210 bool ok = pdconv.isFullyConvex( PE );
212 trace.
warning() <<
"Projection is not fully convex !" << std::endl;
215 std::cout <<
"#E=" << E.size() <<
" #Proj(E)=" << PE.size()
216 << (ok ?
"/FC" :
"/ERROR" ) << std::endl;
221template <
typename Po
int>
224 if ( X.empty() )
return;
227 for (
auto&& p : X ) { lo = lo.inf( p ); hi = hi.sup( p ); }
228 auto w = hi[ 0 ] - lo[ 0 ] + 1;
229 auto h = hi[ 1 ] - lo[ 1 ] + 1;
230 for (
int y = 0; y < h; y++ )
232 for (
int x = 0; x < w; x++ )
234 Point q( lo[ 0 ] + x, lo[ 1 ] + y );
235 std::cout << ( std::binary_search( X.cbegin(), X.cend(), q ) ?
"*" :
"." );
237 std::cout << std::endl;
241template <
typename Space>
245 typedef typename Space::Integer
Integer;
252 typedef typename ProjKSpace::Point ProjPoint;
256 Point lo = Point::zero;
257 Point hi = Point::diagonal( width );
258 DConvexity dconv( lo, hi );
259 std::vector< Point > X, Y;
260 int n = Space::dimension + rand() % 17;
267 std::cout <<
"#X=" << Y.size()
268 <<
" " << ( cvx ?
"X C" :
"X NC" )
269 <<
"/" << ( fc ?
"X FC" :
"X NFC" );
270 for (
Dimension a = 0; a < Space::dimension; a++ )
275 ProjDConvexity pdconv( plo,
phi );
276 std::vector< ProjPoint > PE;
278 if ( Space::dimension == 3 )
280 std::cout << std::endl;
283 bool ok = pdconv.isFullyConvex( PE );
284 bool ok0 = pdconv.is0Convex( PE );
285 std::cout <<
"/" << a << ( ok0 ? ( ok ?
"FC" :
"NFC" ) :
"NC" );
286 proj_fc = proj_fc && ok;
288 trace.
warning() <<
"Projection is not fully convex !" << std::endl;
291 trace.
warning() <<
"X is " << ( fc ?
"FCvx" :
"not FCvx" )
292 <<
"proj(X) " << ( proj_fc ?
"FCvx" :
"not FCvx" )
294 else std::cout << ( fc ?
" => FC ok" :
" => Not FC ok" ) << std::endl;
295 return fc == proj_fc;
308 unsigned int nb_ok = 0;
309 for (
int i = 0; i < NB_TEST1; i++ )
311 nb_ok += checkSkelStarCvxHFullConvexity< Space >( 100 ) ? 1 : 0;
314 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
321 unsigned int nb_ok = 0;
322 for (
int i = 0; i < NB_TEST1; i++ )
324 nb_ok += checkSkelStarCvxHFullConvexity< Space >( 30 ) ? 1 : 0;
327 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
334 unsigned int nb_ok = 0;
335 for (
int i = 0; i < NB_TEST1; i++ )
337 nb_ok += checkSkelStarCvxHFullConvexity< Space >( 10 ) ? 1 : 0;
340 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
347 unsigned int nb_ok = 0;
348 for (
int i = 0; i < NB_TEST2; i++ )
350 nb_ok += checkProjectionFullConvexity< Space >( 30 ) ? 1 : 0;
353 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
360 unsigned int nb_ok = 0;
361 for (
int i = 0; i < NB_TEST2; i++ )
363 nb_ok += checkProjectionFullConvexity< Space >( 10 ) ? 1 : 0;
366 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
373 unsigned int nb_ok = 0;
374 for (
int i = 0; i < NB_TEST3; i++ )
376 nb_ok += checkCvxHPlusHypercubeFullConvexity< Space >( 100 ) ? 1 : 0;
379 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
386 unsigned int nb_ok = 0;
387 for (
int i = 0; i < NB_TEST3; i++ )
389 nb_ok += checkCvxHPlusHypercubeFullConvexity< Space >( 30 ) ? 1 : 0;
392 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
399 unsigned int nb_ok = 0;
400 for (
int i = 0; i < NB_TEST3; i++ )
402 nb_ok += checkCvxHPlusHypercubeFullConvexity< Space >( 10 ) ? 1 : 0;
405 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
412 unsigned int nb_ok = 0;
413 for (
int i = 0; i < NB_TEST4; i++ )
415 nb_ok += checkFullConvexityCharacterization< Space >( 10 ) ? 1 : 0;
418 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
425 unsigned int nb_ok = 0;
426 for (
int i = 0; i < NB_TEST4; i++ )
428 nb_ok += checkFullConvexityCharacterization< Space >( 10 ) ? 1 : 0;
431 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
void makeRandomRange(std::vector< Point > &X, int nb, int width)
void projectRange(std::vector< ProjectedPoint > &pp, const std::vector< Point > &p, Dimension a)
bool checkSkelStarCvxHFullConvexity(int width)
void makeRandom(Point &p, int width)
bool checkProjectionFullConvexity(int width)
bool checkFullConvexityCharacterization(int width)
void project(ProjectedPoint &pp, const Point &p, Dimension a)
bool checkCvxHPlusHypercubeFullConvexity(int width)
void displayPointRange2D(const std::vector< Point > &X)
void getPoints(std::vector< Point > &pts) const
PointRange U(Dimension i, const PointRange &X) const
bool isFullyConvex(const PointRange &X, bool convex0=false) const
bool is0Convex(const PointRange &X) const
PointRange envelope(const PointRange &Z, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
LatticeSet StarCvxH(const PointRange &X, Dimension axis=dimension) const
LatticePolytope makePolytope(const PointRange &X, bool make_minkowski_summable=false) const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
void beginBlock(const std::string &keyword="")
PolygonalCalculus< SH3::RealPoint, SH3::RealVector >::Vector phi(const Face f)
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension