34#include "DGtal/base/Common.h"
35#include "DGtal/kernel/SpaceND.h"
36#include "DGtal/kernel/domains/HyperRectDomain.h"
37#include "DGtal/kernel/sets/DigitalSetBySTLSet.h"
38#include "DGtal/topology/KhalimskySpaceND.h"
39#include "DGtal/shapes/Shapes.h"
40#include "DGtal/geometry/volumes/PConvexity.h"
41#include "DGtal/geometry/volumes/DigitalConvexity.h"
70double rand01() {
return double( rand() ) / double( RAND_MAX ); }
72template <Dimension dim>
75 std::size_t nb_tries, std::size_t nb_vertices, std::size_t range,
76 double pconvexity_probability = 0.5 )
84 DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
86 Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
87 std::cout <<
"Computing " << nb_tries <<
" P-convexities in Z" <<
dim << std::endl;
88 for (
auto n = 0; n < nb_tries; ++n )
91 std::vector< Point > V;
92 for (
auto i = 0; i < nb_vertices; i++ ) {
94 for (
auto j = 0; j <
dim; j++ ) p[ j ] = rand() % range;
98 std::vector< Point > X;
99 bool force_pconvexity =
rand01() < pconvexity_probability;
100 if ( force_pconvexity )
104 auto P = dconv.
CvxH( V );
108 std::chrono::high_resolution_clock::time_point
109 t1 = std::chrono::high_resolution_clock::now();
111 std::chrono::high_resolution_clock::time_point
112 t2 = std::chrono::high_resolution_clock::now();
113 double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
114 results.push_back( std::make_tuple( X.size(),
dt/1e6, is_pconvex ) );
115 if ( force_pconvexity && ! is_pconvex )
116 trace.
warning() <<
"Invalid computation of either FC* or P-convexity !" << std::endl;
120template <Dimension dim>
123 std::size_t nb_tries, std::size_t nb_vertices, std::size_t range,
124 double fconvexity_probability = 0.5 )
132 DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
134 Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
135 std::cout <<
"Computing " << nb_tries <<
" full convexities in Z" <<
dim << std::endl;
136 for (
auto n = 0; n < nb_tries; ++n )
139 std::vector< Point > V;
140 for (
auto i = 0; i < nb_vertices; i++ ) {
142 for (
auto j = 0; j <
dim; j++ ) p[ j ] = rand() % range;
146 std::vector< Point > X;
147 bool force_fconvexity =
rand01() < fconvexity_probability;
148 if ( force_fconvexity )
152 auto P = dconv.
CvxH( V );
156 std::chrono::high_resolution_clock::time_point
157 t1 = std::chrono::high_resolution_clock::now();
159 std::chrono::high_resolution_clock::time_point
160 t2 = std::chrono::high_resolution_clock::now();
161 double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
162 results.push_back( std::make_tuple( X.size(),
dt/1e6, is_fconvex ) );
163 if ( force_fconvexity && ! is_fconvex )
164 trace.
warning() <<
"Invalid computation of either FC* or full convexity !" << std::endl;
168template <Dimension dim>
171 std::size_t nb_tries, std::size_t nb_vertices, std::size_t range,
172 double fconvexity_probability = 0.5 )
180 DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
182 Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
183 std::cout <<
"Computing " << nb_tries <<
" full convexities in Z" <<
dim << std::endl;
184 for (
auto n = 0; n < nb_tries; ++n )
187 std::vector< Point > V;
188 for (
auto i = 0; i < nb_vertices; i++ ) {
190 for (
auto j = 0; j <
dim; j++ ) p[ j ] = rand() % range;
194 std::vector< Point > X;
195 bool force_fconvexity =
rand01() < fconvexity_probability;
196 if ( force_fconvexity )
200 auto P = dconv.
CvxH( V );
204 std::chrono::high_resolution_clock::time_point
205 t1 = std::chrono::high_resolution_clock::now();
207 std::chrono::high_resolution_clock::time_point
208 t2 = std::chrono::high_resolution_clock::now();
209 double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
210 results.push_back( std::make_tuple( X.size(),
dt/1e6, is_fconvex ) );
211 if ( force_fconvexity && ! is_fconvex )
212 trace.
warning() <<
"Invalid computation of either FC* or full convexity !" << std::endl;
217template <Dimension dim>
220( std::vector< std::tuple< std::size_t, double, bool > >& results,
221 std::size_t nb_tries, std::size_t range )
229 DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
231 Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
232 std::cout <<
"Computing " << nb_tries <<
" P-convexities in Z" <<
dim << std::endl;
233 for (
auto n = 0; n < nb_tries; ++n )
235 double filling_probability = 0.1 + 0.9 * double( n ) / double( nb_tries );
238 std::size_t nb_vertices
239 = std::size_t( filling_probability * ceil( pow( range,
dim ) ) );
240 for (
auto i = 0; i < nb_vertices; i++ ) {
242 for (
auto j = 0; j <
dim; j++ ) p[ j ] = rand() % range;
246 std::vector< Point > X( S.cbegin(), S.cend() );
248 std::chrono::high_resolution_clock::time_point
249 t1 = std::chrono::high_resolution_clock::now();
251 std::chrono::high_resolution_clock::time_point
252 t2 = std::chrono::high_resolution_clock::now();
253 double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
254 results.push_back( std::make_tuple( X.size(),
dt/1e6, is_pconvex ) );
258template <Dimension dim>
261( std::vector< std::tuple< std::size_t, double, bool > >& results,
262 std::size_t nb_tries, std::size_t range )
270 DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
272 Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
273 std::cout <<
"Computing " << nb_tries <<
" full convexities in Z" <<
dim << std::endl;
274 for (
auto n = 0; n < nb_tries; ++n )
276 double filling_probability = 0.1 + 0.9 * double( n ) / double( nb_tries );
279 std::size_t nb_vertices
280 = std::size_t( filling_probability * ceil( pow( range,
dim ) ) );
281 for (
auto i = 0; i < nb_vertices; i++ ) {
283 for (
auto j = 0; j <
dim; j++ ) p[ j ] = rand() % range;
287 std::vector< Point > X( S.cbegin(), S.cend() );
289 std::chrono::high_resolution_clock::time_point
290 t1 = std::chrono::high_resolution_clock::now();
292 std::chrono::high_resolution_clock::time_point
293 t2 = std::chrono::high_resolution_clock::now();
294 double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
295 results.push_back( std::make_tuple( X.size(),
dt/1e6, is_fconvex ) );
300template <Dimension dim>
303( std::vector< std::tuple< std::size_t, double, bool > >& results,
304 std::size_t nb_tries, std::size_t range )
312 DConvexity dconv( Point::diagonal( -1 ), Point::diagonal( range ) );
314 Domain domain( Point::diagonal( 0 ), Point::diagonal( range ) );
315 std::cout <<
"Computing " << nb_tries <<
" full convexities (fast) in Z" <<
dim << std::endl;
316 for (
auto n = 0; n < nb_tries; ++n )
318 double filling_probability = 0.1 + 0.9 * double( n ) / double( nb_tries );
321 std::size_t nb_vertices
322 = std::size_t( filling_probability * ceil( pow( range,
dim ) ) );
323 for (
auto i = 0; i < nb_vertices; i++ ) {
325 for (
auto j = 0; j <
dim; j++ ) p[ j ] = rand() % range;
329 std::vector< Point > X( S.cbegin(), S.cend() );
331 std::chrono::high_resolution_clock::time_point
332 t1 = std::chrono::high_resolution_clock::now();
334 std::chrono::high_resolution_clock::time_point
335 t2 = std::chrono::high_resolution_clock::now();
336 double dt = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count();
337 results.push_back( std::make_tuple( X.size(),
dt/1e6, is_fconvex ) );
344 const std::vector< std::tuple< std::size_t, double, bool > >& results,
345 const std::string& fname )
347 std::ofstream output( fname );
348 output <<
"# Results of " << results.size() <<
" P-convexity computations in Z"
350 <<
"# Card(X) time(ms) p-convex?" << std::endl;
351 for (
auto&& r : results )
352 output << std::get<0>( r ) <<
" " << std::get<1>( r ) <<
" " << std::get<2>( r )
391int main(
int argc,
char* argv[] )
397 std::vector< std::tuple< std::size_t, double, bool > > R2;
409 std::vector< std::tuple< std::size_t, double, bool > > R3;
420 std::vector< std::tuple< std::size_t, double, bool > > R4;
437 std::vector< std::tuple< std::size_t, double, bool > > R2;
449 std::vector< std::tuple< std::size_t, double, bool > > R3;
460 std::vector< std::tuple< std::size_t, double, bool > > R4;
477 std::vector< std::tuple< std::size_t, double, bool > > R2;
489 std::vector< std::tuple< std::size_t, double, bool > > R3;
500 std::vector< std::tuple< std::size_t, double, bool > > R4;
517 std::vector< std::tuple< std::size_t, double, bool > > R2;
529 std::vector< std::tuple< std::size_t, double, bool > > R3;
539 std::vector< std::tuple< std::size_t, double, bool > > R4;
549 std::vector< std::tuple< std::size_t, double, bool > > R2;
561 std::vector< std::tuple< std::size_t, double, bool > > R3;
571 std::vector< std::tuple< std::size_t, double, bool > > R4;
581 std::vector< std::tuple< std::size_t, double, bool > > R2;
593 std::vector< std::tuple< std::size_t, double, bool > > R3;
603 std::vector< std::tuple< std::size_t, double, bool > > R4;
void getPoints(std::vector< Point > &pts) const
bool isFullyConvexFast(const PointRange &X) const
LatticePolytope CvxH(const PointRange &X) const
bool isFullyConvex(const PointRange &X, bool convex0=false) const
PointRange envelope(const PointRange &Z, EnvelopeAlgorithm algo=EnvelopeAlgorithm::DIRECT) const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Aim: A class to check if digital sets are P-convex. The P-convexity is defined as follows: A digital ...
bool isPConvex(const std::vector< Point > &X) const
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
void timingsFullConvexityNonConvex(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t range)
void timingsFullConvexity(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t nb_vertices, std::size_t range, double fconvexity_probability=0.5)
void outputResults(Dimension dim, const std::vector< std::tuple< std::size_t, double, bool > > &results, const std::string &fname)
void timingsPConvexityNonConvex(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t range)
void timingsFullConvexityFast(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t nb_vertices, std::size_t range, double fconvexity_probability=0.5)
void timingsPConvexity(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t nb_vertices, std::size_t range, double pconvexity_probability=0.5)
void timingsFullConvexityFastNonConvex(std::vector< std::tuple< std::size_t, double, bool > > &results, std::size_t nb_tries, std::size_t range)
HyperRectDomain< Space > Domain