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 (
auto 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>
103 Point lo = Point::zero;
104 Point hi = Point::diagonal( width );
105 DConvexity dconv( lo, hi );
106 std::vector< Point > X;
111 auto Y = C.extremaOfCells();
114 trace.
warning() <<
"FC*(X) is not fully convex !" << std::endl;
118 trace.
warning() <<
"Extr(Star(CvxH(X))) is not fully convex !" << std::endl;
119 for (
auto p : Y ) std::cout <<
" " << p;
122 bool ok3 = std::includes( Y.cbegin(), Y.cend(), E.cbegin(), E.cend() );
124 <<
" #FC*(X)=" << E.size() << ( ok1 ?
"/FC" :
"/ERROR" )
125 <<
" #Extr(Star(CvxH(X)))=" << Y.size()
126 << ( ok2 ?
"/FC" :
"/ERROR" )
127 << ( ok3 ?
" FC*(X) subset Extr(Star(CvxH(X)))" :
" Inclusion ERROR" )
129 return ok1 && ok2 && ok3;
133template <
typename Space>
144 Point lo = Point::zero;
145 Point hi = Point::diagonal( width );
146 DConvexity dconv( lo, hi );
147 std::vector< Point > X, XpH, Y;
150 std::sort( X.begin(), X.end() );
153 XpH = dconv.
U( k, XpH );
159 trace.
warning() <<
"FC*(X) is not fully convex !" << std::endl;
163 trace.
warning() <<
"CvxH(X+H) cap Z^d is not fully convex !" << std::endl;
164 for (
auto p : Y ) std::cout <<
" " << p;
167 bool ok3 = std::includes( Y.cbegin(), Y.cend(), E.cbegin(), E.cend() );
169 <<
" #CvxH(X+H) cap Z^d=" << Y.size()
170 << ( ok2 ?
"/FC" :
"/ERROR" )
171 <<
" #FC*(X)=" << E.size() << ( ok1 ?
"/FC" :
"/ERROR" )
172 << ( ok3 ?
" FC*(X) subset CvxH(X+H) cap Z^d"
173 :
" FC*(X) not subset CvxH(X+H) cap Z^d" )
179template <
typename Space>
190 typedef typename ProjKSpace::Point ProjPoint;
191 typedef std::vector<ProjPoint> ProjPointRange;
194 Point lo = Point::zero;
195 Point hi = Point::diagonal( width );
196 DConvexity dconv( lo, hi );
197 std::vector< Point > X;
202 unsigned int nb_ok = 0;
208 ProjDConvexity pdconv( plo,
phi );
209 std::vector< ProjPoint > PE;
211 bool ok = pdconv.isFullyConvex( PE );
213 trace.
warning() <<
"Projection is not fully convex !" << std::endl;
216 std::cout <<
"#E=" << E.size() <<
" #Proj(E)=" << PE.size()
217 << (ok ?
"/FC" :
"/ERROR" ) << std::endl;
222template <
typename Po
int>
225 if ( X.empty() )
return;
228 for (
auto&& p : X ) { lo = lo.inf( p ); hi = hi.sup( p ); }
229 auto w = hi[ 0 ] - lo[ 0 ] + 1;
230 auto h = hi[ 1 ] - lo[ 1 ] + 1;
231 for (
int y = 0; y < h; y++ )
233 for (
int x = 0; x < w; x++ )
235 Point q( lo[ 0 ] + x, lo[ 1 ] + y );
236 std::cout << ( std::binary_search( X.cbegin(), X.cend(), q ) ?
"*" :
"." );
238 std::cout << std::endl;
242template <
typename Space>
253 typedef typename ProjKSpace::Point ProjPoint;
254 typedef std::vector<ProjPoint> ProjPointRange;
257 Point lo = Point::zero;
258 Point hi = Point::diagonal( width );
259 DConvexity dconv( lo, hi );
260 std::vector< Point > X, Y;
268 std::cout <<
"#X=" << Y.size()
269 <<
" " << ( cvx ?
"X C" :
"X NC" )
270 <<
"/" << ( fc ?
"X FC" :
"X NFC" );
276 ProjDConvexity pdconv( plo,
phi );
277 std::vector< ProjPoint > PE;
281 std::cout << std::endl;
284 bool ok = pdconv.isFullyConvex( PE );
285 bool ok0 = pdconv.is0Convex( PE );
286 std::cout <<
"/" << a << ( ok0 ? ( ok ?
"FC" :
"NFC" ) :
"NC" );
287 proj_fc = proj_fc && ok;
289 trace.
warning() <<
"Projection is not fully convex !" << std::endl;
292 trace.
warning() <<
"X is " << ( fc ?
"FCvx" :
"not FCvx" )
293 <<
"proj(X) " << ( proj_fc ?
"FCvx" :
"not FCvx" )
295 else std::cout << ( fc ?
" => FC ok" :
" => Not FC ok" ) << std::endl;
296 return fc == proj_fc;
299int main(
int argc,
char* argv[] )
309 unsigned int nb_ok = 0;
310 for (
int i = 0; i < NB_TEST1; i++ )
315 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
322 unsigned int nb_ok = 0;
323 for (
int i = 0; i < NB_TEST1; i++ )
328 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
335 unsigned int nb_ok = 0;
336 for (
int i = 0; i < NB_TEST1; i++ )
341 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
348 unsigned int nb_ok = 0;
349 for (
int i = 0; i < NB_TEST2; i++ )
354 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
361 unsigned int nb_ok = 0;
362 for (
int i = 0; i < NB_TEST2; i++ )
367 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
374 unsigned int nb_ok = 0;
375 for (
int i = 0; i < NB_TEST3; i++ )
380 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
387 unsigned int nb_ok = 0;
388 for (
int i = 0; i < NB_TEST3; i++ )
393 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
400 unsigned int nb_ok = 0;
401 for (
int i = 0; i < NB_TEST3; i++ )
406 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
413 unsigned int nb_ok = 0;
414 for (
int i = 0; i < NB_TEST4; i++ )
419 trace.
info() << nb_ok <<
"/" << nb <<
" OK tests" << std::endl;
426 unsigned int nb_ok = 0;
427 for (
int i = 0; i < NB_TEST4; i++ )
432 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,...
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
static const Dimension dimension
static constants to store the dimension.
void beginBlock(const std::string &keyword="")
PolygonalCalculus< SH3::RealPoint, SH3::RealVector >::Vector phi(const Face f)
std::vector< Point > PointRange
Point::Coordinate Integer
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension