DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
exampleBoundedLatticePolytopeCount4D.cpp File Reference
#include "DGtal/base/Common.h"
#include "DGtal/geometry/volumes/ConvexityHelper.h"
#include "DGtal/geometry/volumes/BoundedLatticePolytope.h"

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Detailed Description

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
2022/06/19

An example file named exampleBoundedLatticePolytopeCount4D.

This file is part of the DGtal library.

Definition in file exampleBoundedLatticePolytopeCount4D.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 62 of file exampleBoundedLatticePolytopeCount4D.cpp.

63{
64 int N = argc > 1 ? atoi( argv[ 1 ] ) : 10; // nb of polytopes
65 int nb = argc > 2 ? atoi( argv[ 2 ] ) : 10; // nb points per polytope
66 int R = argc > 3 ? atoi( argv[ 3 ] ) : 50; // max diameter of shape
67
68 typedef int64_t Integer;
71 typedef Helper::LatticePolytope Polytope;
72 typedef Polytope::Point Point;
73 // Compute all polytopes
74 DGtal::trace.beginBlock( "Compute 4D polytopes" );
75 std::vector< Polytope > polytopes;
76 int sum_nb_facets = 0;
77 for ( int i = 0; i < N; i++ )
78 {
79 std::vector< Point > V;
80 for ( int i = 0; i < nb; i++ ) {
81 Point p( rand() % (2*R+1) - R, rand() % (2*R+1) - R,
82 rand() % (2*R+1) - R, rand() % (2*R+1) - R );
83 V.push_back( p );
84 }
85 Polytope P = Helper::computeLatticePolytope( V );
86 sum_nb_facets += P.nbHalfSpaces();
87 polytopes.push_back( P );
88 }
89 double t1 = DGtal::trace.endBlock();
90 DGtal::trace.info() << "Computed " << N
91 << " 4D polytopes with " << ( sum_nb_facets / (double) N )
92 << " facets on average, in " << t1 << " ms." << std::endl;
93 // Count interior points (slow method)
94 DGtal::trace.beginBlock( "Compute number of lattice points within polytope (slow)" );
95 std::size_t slow_nb = 0;
96 std::vector< Integer > slow_counts;
97 for ( const auto& P : polytopes )
98 {
99 const auto nb = P.countByScanning();
100 slow_nb += nb;
101 slow_counts.push_back( nb );
102 }
103 double t2 = DGtal::trace.endBlock();
104 // Count interior points (fast method)
105 DGtal::trace.beginBlock( "Compute number of lattice points within polytope (fast)" );
106 std::size_t fast_nb = 0;
107 std::vector< Integer > fast_counts;
108 for ( const auto& P : polytopes )
109 {
110 const auto nb = P.count();
111 fast_nb += nb;
112 fast_counts.push_back( nb );
113 }
114 double t3 = DGtal::trace.endBlock();
115 bool ok = std::equal( slow_counts.cbegin(), slow_counts.cend(), fast_counts.cbegin() );
116 DGtal::trace.info() << "Computed inside points is " << ( ok ? "OK" : "ERROR" ) << std::endl;
117 DGtal::trace.info() << "Reference method computed " << slow_nb
118 << " points in " << t2 << " ms." << std::endl;
119 DGtal::trace.info() << "Fast method computed " << fast_nb
120 << " points in " << t3 << " ms." << std::endl;
121 return 0;
122}
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
Trace trace
Definition: Common.h:154
Aim: Provides a set of functions to facilitate the computation of convex hulls and polytopes,...
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.