31 #if defined(QuickHullKernels_RECURSES)
32 #error Recursive header files inclusion detected in QuickHullKernels.h
35 #define QuickHullKernels_RECURSES
37 #if !defined QuickHullKernels_h
39 #define QuickHullKernels_h
47 #include "DGtal/base/Common.h"
48 #include "DGtal/kernel/CInteger.h"
49 #include "DGtal/kernel/NumberTraits.h"
50 #include "DGtal/kernel/PointVector.h"
51 #include "DGtal/kernel/IntegerConverter.h"
52 #include "DGtal/math/linalg/SimpleMatrix.h"
65 template <
typename Po
int >
68 if ( points.empty() )
return Point::zero;
69 Point l = points[ 0 ];
71 for (
const auto& p : points ) {
75 return Point( ( l + u ) / 2 );
106 template <
typename OutputValue,
107 typename ForwardIterator,
108 typename ConversionFct >
109 void transform( std::vector< OutputValue >& output_values,
110 std::vector< std::size_t >& input2output,
111 std::vector< std::size_t >& output2input,
112 ForwardIterator itb, ForwardIterator ite,
113 const ConversionFct& F,
114 bool remove_duplicates )
116 typedef std::size_t
Size;
117 std::vector< OutputValue > input;
118 while ( itb != ite ) {
119 const auto ip = *itb++;
120 input.push_back( F( ip ) );
122 if ( ! remove_duplicates ) {
123 output_values.swap( input );
124 input2output.resize( input.size() );
125 output2input.resize( input.size() );
126 for (
Size i = 0; i < input.size(); ++i )
127 input2output[ i ] = output2input[ i ] = i;
130 output_values.clear();
131 std::vector< std::size_t > i2c_sort( input.size() );
132 input2output.resize( input.size() );
133 for (
Size i = 0; i < input.size(); i++ ) i2c_sort[ i ] = i;
135 std::sort( i2c_sort.begin(), i2c_sort.end(),
136 [&input] (
Size i,
Size j ) { return input[ i ] < input[ j ]; } );
137 output_values.resize( input.size() );
138 output_values[ 0 ] = input[ i2c_sort[ 0 ] ];
139 input2output[ i2c_sort[ 0 ] ] = 0;
141 for (
Size i = 1; i < input.size(); i++ ) {
142 if ( input[ i2c_sort[ i-1 ] ] != input[ i2c_sort[ i ] ] )
143 output_values[ ++j ] = input[ i2c_sort[ i ] ];
144 input2output[ i2c_sort[ i ] ] = j;
146 output_values.resize( j+1 );
147 output2input.resize( output_values.size() );
148 for (
Size i = 0; i < input2output.size(); i++ )
149 output2input[ input2output[ i ] ] = i;
208 :
N( aN ), c( aC ) {}
230 compute(
const std::vector< CoordinatePoint >& vpoints,
240 if ( nu > hs.
c ) { hs.
N = -hs.
N; hs.
c = -hs.
c; }
257 compute(
const std::vector< CoordinatePoint >& vpoints,
265 A.setComponent( i-1, j,
267 - vpoints[ simplex[ 0 ] ][ j ] ) );
299 return H1.
N.
dot( H2.
N );
312 return H1.
c == H2.
c && H1.
N == H2.
N;
340 {
return height(
H, p ) >= 0; }
346 {
return height(
H, p ) == 0; }
452 template <
typename InputPo
int>
453 void makeInput( std::vector< CoordinatePoint >& processed_points,
455 const std::vector< InputPoint >& input_points,
456 bool remove_duplicates )
466 input_points.cbegin(), input_points.cend(),
467 F, remove_duplicates );
472 template <
typename OutputPo
int>
476 out_p[ k ] =
static_cast<typename OutputPoint::Component
>(p[ k ]);
587 template <
typename InputPo
int>
588 void makeInput( std::vector< CoordinatePoint >& processed_points,
590 const std::vector< InputPoint >& input_points,
591 bool remove_duplicates )
606 input_points.cbegin(), input_points.cend(),
607 F, remove_duplicates );
612 template <
typename OutputPo
int>
698 : precision( aPrecision ) {}
746 template <
typename InputPo
int>
747 void makeInput( std::vector< CoordinatePoint >& processed_points,
749 const std::vector< InputPoint >& input_points,
750 bool remove_duplicates )
760 input_points.cbegin(), input_points.cend(),
761 F, remove_duplicates );
780 template <
typename OutputPo
int>
784 out_p[ k ] = ( (
double) p[ k ] ) /
precision;
870 : precision( aPrecision ) {}
922 template <
typename InputPo
int>
923 void makeInput( std::vector< CoordinatePoint >& processed_points,
925 const std::vector< InputPoint >& input_points,
926 bool remove_duplicates )
942 input_points.cbegin(), input_points.cend(),
943 F, remove_duplicates );
965 template <
typename OutputPo
int>
969 out_p[ k ] = ( (
double) p[ k ] ) /
precision;
980 #undef QuickHullKernels_RECURSES
InternalScalar c
the intercept
const InternalVector & internalNormal() const
HalfSpace(const InternalVector &aN, const InternalScalar aC)
InternalVector N
the normal vector
InternalScalar internalIntercept() const
Aim: Implements basic operations that will be used in Point and Vector classes.
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
static Self zero
Static const for zero PointVector.
Aim: implements basic MxN Matrix services (M,N>=1).
void transform(std::vector< OutputValue > &output_values, std::vector< std::size_t > &input2output, std::vector< std::size_t > &output2input, ForwardIterator itb, ForwardIterator ite, const ConversionFct &F, bool remove_duplicates)
Point center(const std::vector< Point > &points)
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
DGtal::uint32_t Dimension
Aim: the common part of all geometric kernels for computing the convex hull or Delaunay triangulation...
DGtal::PointVector< dim, InternalInteger > InternalVector
BOOST_CONCEPT_ASSERT((concepts::CInteger< TCoordinateInteger >))
InternalInteger InternalScalar
std::array< Index, dim > CombinatorialPlaneSimplex
bool above(const HalfSpace &H, const CoordinatePoint &p) const
InternalScalar height(const HalfSpace &H, const CoordinatePoint &p) const
CoordinateInteger CoordinateScalar
HalfSpace compute(const std::vector< CoordinatePoint > &vpoints, const CombinatorialPlaneSimplex &simplex)
TCoordinateInteger CoordinateInteger
CoordinateVector normal(const HalfSpace &H) const
InternalScalar volume(const HalfSpace &H, const CoordinatePoint &p) const
InternalScalar dot(const HalfSpace &H1, const HalfSpace &H2) const
HalfSpace compute(const std::vector< CoordinatePoint > &vpoints, const CombinatorialPlaneSimplex &simplex, Index idx_below)
DGtal::PointVector< dim, CoordinateInteger > CoordinatePoint
std::vector< Index > IndexRange
bool equal(const HalfSpace &H1, const HalfSpace &H2) const
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInternalInteger >))
DGtal::PointVector< dim, InternalInteger > InternalPoint
IntegerConverter< dim, InternalInteger > Inner
Converter to inner internal integers or lattice points / vector.
bool on(const HalfSpace &H, const CoordinatePoint &p) const
TInternalInteger InternalInteger
static const Dimension dimension
bool aboveOrOn(const HalfSpace &H, const CoordinatePoint &p) const
IntegerConverter< dim, CoordinateInteger > Outer
Converter to outer coordinate integers or lattice points / vector.
ConvexHullCommonKernel()=default
Default constructor.
CoordinateScalar intercept(const HalfSpace &H) const
DGtal::PointVector< dim, CoordinateInteger > CoordinateVector
Aim: a geometric kernel to compute the convex hull of digital points with integer-only arithmetic.
CoordinateInteger CoordinateScalar
ConvexHullCommonKernel< dim, TCoordinateInteger, TInternalInteger > Base
void convertPointTo(const CoordinatePoint &p, OutputPoint &out_p) const
std::vector< Index > IndexRange
bool hasInfiniteFacets() const
void makeInput(std::vector< CoordinatePoint > &processed_points, IndexRange &input2comp, IndexRange &comp2input, const std::vector< InputPoint > &input_points, bool remove_duplicates)
bool isHalfSpaceFacetInfinite(const HalfSpace &hs) const
static const Dimension dimension
ConvexHullIntegralKernel()=default
Default constructor.
Aim: a geometric kernel to compute the convex hull of floating points with integer-only arithmetic....
void convertPointTo(const CoordinatePoint &p, OutputPoint &out_p) const
CoordinateInteger CoordinateScalar
void makeInput(std::vector< CoordinatePoint > &processed_points, IndexRange &input2comp, IndexRange &comp2input, const std::vector< InputPoint > &input_points, bool remove_duplicates)
std::vector< Index > IndexRange
double precision
The precision as the common denominator for all rational points.
bool hasInfiniteFacets() const
bool isHalfSpaceFacetInfinite(const HalfSpace &hs) const
ConvexHullRationalKernel(double aPrecision=1024.)
static const Dimension dimension
ConvexHullCommonKernel< dim, TCoordinateInteger, TInternalInteger > Base
Aim: a geometric kernel to compute the Delaunay triangulation of digital points with integer-only ari...
InternalInteger InternalScalar
CoordinateInteger CoordinateScalar
std::vector< Index > IndexRange
ConvexHullCommonKernel< dim+1, TCoordinateInteger, TInternalInteger > Base
void convertPointTo(const CoordinatePoint &p, OutputPoint &out_p) const
DelaunayIntegralKernel()=default
Default constructor.
void makeInput(std::vector< CoordinatePoint > &processed_points, IndexRange &input2comp, IndexRange &comp2input, const std::vector< InputPoint > &input_points, bool remove_duplicates)
static const Dimension dimension
bool isHalfSpaceFacetInfinite(const HalfSpace &hs) const
bool hasInfiniteFacets() const
Aim: a geometric kernel to compute the Delaunay triangulation of a range of floating points with inte...
InternalInteger InternalScalar
CoordinateInteger CoordinateScalar
std::vector< Index > IndexRange
bool hasInfiniteFacets() const
double precision
The precision as the common denominator for all rational points.
ConvexHullCommonKernel< dim+1, TCoordinateInteger, TInternalInteger > Base
DelaunayRationalKernel(double aPrecision=1024.)
static const Dimension dimension
void makeInput(std::vector< CoordinatePoint > &processed_points, IndexRange &input2comp, IndexRange &comp2input, const std::vector< InputPoint > &input_points, bool remove_duplicates)
void convertPointTo(const CoordinatePoint &p, OutputPoint &out_p) const
bool isHalfSpaceFacetInfinite(const HalfSpace &hs) const
----------— INTEGER/POINT CONVERSION SERVICES -----------------—
static Integer cast(Integer i)
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
HalfEdgeDataStructure::Size Size
unsigned int dim(const Vector &z)