DGtal  1.2.0
Functions
checkLatticeBallQuickHull.cpp File Reference
#include <cstdlib>
#include <iostream>
#include <chrono>
#include "DGtal/base/Common.h"
#include "DGtal/geometry/tools/QuickHull.h"
Include dependency graph for checkLatticeBallQuickHull.cpp:

Go to the source code of this file.

Functions

template<typename Point >
std::vector< PointrandomPointsInBall (int nb, double R)
 
template<typename Point >
std::vector< PointrandomPointsInBallBigInteger (int nb, double R)
 
template<DGtal::Dimension dim, typename Integer >
bool checkQuickHull (int nb, double R)
 
template<DGtal::Dimension dim>
bool checkQuickHullBigInteger (int nb, double R)
 
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
2021/01/01

An example file named checkLatticeBallQuickHull.

This file is part of the DGtal library.

Definition in file checkLatticeBallQuickHull.cpp.

Function Documentation

◆ checkQuickHull()

template<DGtal::Dimension dim, typename Integer >
bool checkQuickHull ( int  nb,
double  R 
)
Examples
geometry/tools/checkLatticeBallQuickHull.cpp.

Definition at line 104 of file checkLatticeBallQuickHull.cpp.

105 {
107  typedef DGtal::QuickHull< Kernel > ConvexHull;
108  typedef typename ConvexHull::Point Point;
109 
110  const auto V = randomPointsInBall< Point >( nb, R );
111  ConvexHull hull;
112  hull.setInput( V );
113  hull.computeConvexHull();
114  std::cout << "#points=" << hull.nbPoints()
115  << " #vertices=" << hull.nbVertices()
116  << " #facets=" << hull.nbFacets() << std::endl;
117  double total_time = 0;
118  std::for_each( hull.timings.cbegin(), hull.timings.cend(),
119  [&total_time] ( double t ) { total_time += t; } );
120  std::cout << "purge duplicates= " << round(hull.timings[ 0 ]) << " ms." << std::endl;
121  std::cout << "init simplex = " << round(hull.timings[ 1 ]) << " ms." << std::endl;
122  std::cout << "quickhull core = " << round(hull.timings[ 2 ]) << " ms." << std::endl;
123  std::cout << "compute vertices= " << round(hull.timings[ 3 ]) << " ms." << std::endl;
124  std::cout << "total time = " << round(total_time) << " ms." << std::endl;
125  std::cout << "Checking hull ... " << std::endl;
126  auto start = std::chrono::steady_clock::now();
127  bool ok = hull.check();
128  auto end = std::chrono::steady_clock::now();
129  std::chrono::duration<double> elapsed_seconds = end-start;
130  std::cout << " ... in " << elapsed_seconds.count() << "s"
131  << " => " << ( ok ? "OK" : "ERROR" ) << std::endl;
132  return ok;
133 }
Aim: a geometric kernel to compute the convex hull of digital points with integer-only arithmetic.
Aim: Implements the quickhull algorithm by Barber et al. , a famous arbitrary dimensional convex hull...
Definition: QuickHull.h:140
MyPointD Point
Definition: testClone2.cpp:383

◆ checkQuickHullBigInteger()

template<DGtal::Dimension dim>
bool checkQuickHullBigInteger ( int  nb,
double  R 
)
Examples
geometry/tools/checkLatticeBallQuickHull.cpp.

Definition at line 137 of file checkLatticeBallQuickHull.cpp.

138 {
140  typedef DGtal::QuickHull< Kernel > ConvexHull;
141  typedef typename ConvexHull::Point Point;
142 
143  const auto V = randomPointsInBallBigInteger< Point >( nb, R );
144  ConvexHull hull;
145  hull.setInput( V );
146  hull.computeConvexHull();
147  std::cout << "#points=" << hull.nbPoints()
148  << " #vertices=" << hull.nbVertices()
149  << " #facets=" << hull.nbFacets() << std::endl;
150  double total_time = 0;
151  std::for_each( hull.timings.cbegin(), hull.timings.cend(),
152  [&total_time] ( double t ) { total_time += t; } );
153  std::cout << "purge duplicates= " << round(hull.timings[ 0 ]) << " ms." << std::endl;
154  std::cout << "init simplex = " << round(hull.timings[ 1 ]) << " ms." << std::endl;
155  std::cout << "quickhull core = " << round(hull.timings[ 2 ]) << " ms." << std::endl;
156  std::cout << "compute vertices= " << round(hull.timings[ 3 ]) << " ms." << std::endl;
157  std::cout << "total time = " << round(total_time) << " ms." << std::endl;
158  std::cout << "Checking hull ... " << std::endl;
159  auto start = std::chrono::steady_clock::now();
160  bool ok = hull.check();
161  auto end = std::chrono::steady_clock::now();
162  std::chrono::duration<double> elapsed_seconds = end-start;
163  std::cout << " ... in " << elapsed_seconds.count() << "s"
164  << " => " << ( ok ? "OK" : "ERROR" ) << std::endl;
165  return ok;
166 }

◆ main()

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

Definition at line 168 of file checkLatticeBallQuickHull.cpp.

169 {
170  int dim = argc > 1 ? atoi( argv[ 1 ] ) : 3; // dimension
171  int nb = argc > 2 ? atoi( argv[ 2 ] ) : 1000; // nb points
172  double R = argc > 3 ? atof( argv[ 3 ] ) : 100.0; // radius of ball
173  std::string i = argc > 4 ? argv[ 4 ] : "int64"; // type for internal integers
174  bool ok = true;
175  if ( ( i != "int64" ) && ( i != "bigint" ) && ( i != "allbigint" ) )
176  {
177  DGtal::trace.error() << "Integer type in {int64,bigint,allbigint}" << std::endl;
178  ok = false;
179  }
180  if ( ( dim < 2 ) || ( dim > 6 ) )
181  {
182  DGtal::trace.error() << "Dimension must be in {2,3,4,5,6}" << std::endl;
183  ok = false;
184  }
185  if ( ! ok ) return 1;
186  if ( i == "bigint" )
187  {
188  switch( dim ) {
189  case 2 : ok = checkQuickHull< 2, DGtal::BigInteger >( nb, R ); break;
190  case 3 : ok = checkQuickHull< 3, DGtal::BigInteger >( nb, R ); break;
191  case 4 : ok = checkQuickHull< 4, DGtal::BigInteger >( nb, R ); break;
192  case 5 : ok = checkQuickHull< 5, DGtal::BigInteger >( nb, R ); break;
193  case 6 : ok = checkQuickHull< 6, DGtal::BigInteger >( nb, R ); break;
194  }
195  }
196  else if ( i == "int64" )
197  {
198  switch( dim ) {
199  case 2 : ok = checkQuickHull< 2, DGtal::int64_t >( nb, R ); break;
200  case 3 : ok = checkQuickHull< 3, DGtal::int64_t >( nb, R ); break;
201  case 4 : ok = checkQuickHull< 4, DGtal::int64_t >( nb, R ); break;
202  case 5 : ok = checkQuickHull< 5, DGtal::int64_t >( nb, R ); break;
203  case 6 : ok = checkQuickHull< 6, DGtal::int64_t >( nb, R ); break;
204  }
205  }
206  else if ( i == "allbigint" )
207  {
208  switch( dim ) {
209  case 2 : ok = checkQuickHullBigInteger< 2 >( nb, R ); break;
210  case 3 : ok = checkQuickHullBigInteger< 3 >( nb, R ); break;
211  case 4 : ok = checkQuickHullBigInteger< 4 >( nb, R ); break;
212  case 5 : ok = checkQuickHullBigInteger< 5 >( nb, R ); break;
213  case 6 : ok = checkQuickHullBigInteger< 6 >( nb, R ); break;
214  }
215  }
216  return ok ? 0 : 1;
217 }
std::ostream & error()
Trace trace
Definition: Common.h:154
unsigned int dim(const Vector &z)

References dim(), DGtal::Trace::error(), and DGtal::trace.

◆ randomPointsInBall()

template<typename Point >
std::vector< Point > randomPointsInBall ( int  nb,
double  R 
)

Definition at line 69 of file checkLatticeBallQuickHull.cpp.

70 {
71  std::vector< Point > V;
72  DGtal::int64_t iR = DGtal::int64_t( round( R ) );
73  Point c = Point::diagonal( iR );
74  double R2 = (double) R * (double) R;
75  for ( int i = 0; i < nb; ) {
76  Point p;
77  for ( DGtal::Dimension k = 0; k < Point::dimension; ++k )
78  p[ k ] = DGtal::int64_t( round( (double) rand() * 2.0 * R / (double) RAND_MAX ));
79  if ( ( p - c ).squaredNorm() < R2 ) { V.push_back( p - c ); i++; }
80  }
81  return V;
82 }
boost::int64_t int64_t
signed 94-bit integer.
Definition: BasicTypes.h:74
DGtal::uint32_t Dimension
Definition: Common.h:137

◆ randomPointsInBallBigInteger()

template<typename Point >
std::vector< Point > randomPointsInBallBigInteger ( int  nb,
double  R 
)
Examples
geometry/tools/checkLatticeBallQuickHull.cpp.

Definition at line 86 of file checkLatticeBallQuickHull.cpp.

87 {
88  std::vector< Point > V;
89  DGtal::int64_t iR = DGtal::int64_t( round( R ) );
91  Point c = Point::diagonal( Converter::cast( iR ) );
92  double R2 = (double) R * (double) R;
93  for ( int i = 0; i < nb; ) {
94  Point p;
95  for ( DGtal::Dimension k = 0; k < Point::dimension; ++k )
96  p[ k ] = Converter::cast( DGtal::int64_t( round( (double) rand() * 2.0 * R / (double) RAND_MAX )) );
97  if ( ( p - c ).squaredNorm() < R2 ) { V.push_back( p - c ); i++; }
98  }
99  return V;
100 }
----------— INTEGER/POINT CONVERSION SERVICES -----------------—