DGtal 2.1.0
Loading...
Searching...
No Matches
DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K > Struct Template Reference

#include <DGtal/geometry/tools/GenericLatticeConvexHull.h>

Inheritance diagram for DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >:
[legend]

Public Types

typedef ConvexHullIntegralKernel< K, TCoordinateInteger, TInternalInteger > Kernel
typedef detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K-1 > LowerKernels
typedef std::size_t Size
typedef Kernel::CoordinatePoint Point
typedef Point::Coordinate Integer
typedef QuickHull< KernelQHull
typedef SpaceND< K, IntegerSpace
typedef BoundedLatticePolytope< SpaceLatticePolytope
typedef GenericLatticeConvexHull< dim, TCoordinateInteger, TInternalInteger > Computer
typedef Computer::OutputPoint OutputPoint

Public Member Functions

 GenericLatticeConvexHullComputers (Computer *ptrGenQHull)
void clear ()
 Clears the object as if no computations have been made.
template<typename TInputPoint>
bool compute (const std::vector< Size > &I, const std::vector< TInputPoint > &X)
bool makePolytope ()
Integer count ()
Integer countInterior ()
Integer countBoundary ()
Integer countUpTo (Integer max)

Data Fields

Computerptr_gen_qhull
 the pointer on the parent computer
LowerKernels lower_kernels
 the computers of lower dimension
QHull hull
 the quick hull object that computes the convex hull
std::vector< Pointproj_points
 the projected points, as points in lower dimension
LatticePolytope polytope
 the polytope corresponding to the convex hull

Static Public Attributes

static const Dimension dimension = K

Detailed Description

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
struct DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >

Definition at line 69 of file GenericLatticeConvexHull.h.

Member Typedef Documentation

◆ Computer

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef GenericLatticeConvexHull< dim, TCoordinateInteger, TInternalInteger > DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::Computer

Definition at line 83 of file GenericLatticeConvexHull.h.

◆ Integer

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef Point::Coordinate DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::Integer

Definition at line 77 of file GenericLatticeConvexHull.h.

◆ Kernel

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef ConvexHullIntegralKernel< K,TCoordinateInteger,TInternalInteger > DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::Kernel

Definition at line 72 of file GenericLatticeConvexHull.h.

◆ LatticePolytope

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef BoundedLatticePolytope< Space > DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::LatticePolytope

Definition at line 80 of file GenericLatticeConvexHull.h.

◆ LowerKernels

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K-1> DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::LowerKernels

Definition at line 74 of file GenericLatticeConvexHull.h.

◆ OutputPoint

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef Computer::OutputPoint DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::OutputPoint

Definition at line 84 of file GenericLatticeConvexHull.h.

◆ Point

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef Kernel::CoordinatePoint DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::Point

Definition at line 76 of file GenericLatticeConvexHull.h.

◆ QHull

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef QuickHull< Kernel > DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::QHull

Definition at line 78 of file GenericLatticeConvexHull.h.

◆ Size

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef std::size_t DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::Size

Definition at line 75 of file GenericLatticeConvexHull.h.

◆ Space

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
typedef SpaceND< K, Integer > DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::Space

Definition at line 79 of file GenericLatticeConvexHull.h.

Constructor & Destructor Documentation

◆ GenericLatticeConvexHullComputers()

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::GenericLatticeConvexHullComputers ( Computer * ptrGenQHull)
inline

Constructor.

Parameters
ptrGenQHullthe pointer on the parent computer.

Definition at line 89 of file GenericLatticeConvexHull.h.

91 hull( Kernel(), ptrGenQHull->debug_level )
92 {
93 clear();
94 }
LowerKernels lower_kernels
the computers of lower dimension
void clear()
Clears the object as if no computations have been made.
QHull hull
the quick hull object that computes the convex hull
ConvexHullIntegralKernel< K, TCoordinateInteger, TInternalInteger > Kernel
Computer * ptr_gen_qhull
the pointer on the parent computer

Member Function Documentation

◆ clear()

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
void DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::clear ( )
inline

Clears the object as if no computations have been made.

Definition at line 97 of file GenericLatticeConvexHull.h.

98 {
99 hull.clear();
100 proj_points.clear();
101 polytope.clear();
102 lower_kernels.clear();
103 }
LatticePolytope polytope
the polytope corresponding to the convex hull
std::vector< Point > proj_points
the projected points, as points in lower dimension

Referenced by DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, 1 >::GenericLatticeConvexHullComputers(), and DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K-1 >::GenericLatticeConvexHullComputers().

◆ compute()

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
template<typename TInputPoint>
bool DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::compute ( const std::vector< Size > & I,
const std::vector< TInputPoint > & X )
inline
Template Parameters
TInputPointany type of input points.
Parameters
Ia range of indices specifying an affine subset of X.
Xthe range of input points.

Copy back convex hull in initial space.

Definition at line 109 of file GenericLatticeConvexHull.h.

111 {
112 typedef TInputPoint InputPoint;
115 hull.clear();
116 polytope.clear();
117 if ( (I.size()-1) != dimension )
118 { // This kernel is not adapted => go to lower dimension
119 return lower_kernels.compute( I, X );
120 }
121 ptr_gen_qhull->affine_dimension = dimension;
122 auto& points = ptr_gen_qhull->points;
123 auto& ppoints = ptr_gen_qhull->projected_points;
124 auto& positions = ptr_gen_qhull->positions;
125 auto& v2p = ptr_gen_qhull->vertex2point;
126 auto& facets = ptr_gen_qhull->facets;
127 auto& dilation = ptr_gen_qhull->projected_dilation;
128 auto& aff_basis = ptr_gen_qhull->affine_basis;
129
130 Basis basis;
131 if ( dimension != ptr_gen_qhull->dimension )
132 { // Build the affine basis spanning the convex hull affine space.
133 if ( dimension == ptr_gen_qhull->dimension-1 )
134 { // codimension 1
135 // builds orthogonal vector
139 }
140 else
141 { // Generic case
143 }
144 }
145 // Build projected points on affine basis
146 dilation = basis.projectPoints( proj_points, X );
147
148 // Compute convex hull using quickhull.
149 bool ok_input = hull.setInput( proj_points, false );
150 bool ok_hull = hull.computeConvexHull( QHull::Status::VerticesCompleted );
151 if ( ! ok_hull || ! ok_input )
152 {
153 trace.error() << "[GenericLatticeConvexHullComputers::compute]"
154 << " Error in quick hull computation.\n"
155 << "qhull=" << hull << "\n";
156 return false;
157 }
159 points.resize( X.size() );
160 for ( Size i = 0; i < points.size(); i++ )
161 points[ i ] = Affine::transform( X[ i ] );
162 hull.getVertex2Point( v2p );
163 hull.getFacetVertices( facets );
164 positions.resize( v2p.size() );
165 for ( Size i = 0; i < positions.size(); i++ )
166 positions[ i ] = X[ v2p[ i ] ];
167 ppoints.resize( proj_points.size() );
168 for ( Size i = 0; i < ppoints.size(); i++ )
169 {
171 for ( Dimension j = 0; j < Point::dimension; j++ )
172 ppoints[ i ][ j ] = proj_points[ i ][ j ];
173 }
175 basis.basis(),
177 true );
178 return true;
179 }
static void getOrthogonalVector(TPoint &w, const std::vector< TInputPoint > &X, const TIndexRange &I, const double tolerance=1e-12)

◆ count()

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
Integer DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::count ( )
inline

Computes the number of integer points lying within the polytope.

Returns
the number of integer points lying within the polytope, or -1 if their was a problem when computing the polytope.
Note
Quite fast: obtained by line intersection, see BoundedLatticePolytopeCounter

Definition at line 233 of file GenericLatticeConvexHull.h.

234 {
235 if ( ptr_gen_qhull->affine_dimension != dimension )
236 { // This kernel is not adapted => go to lower dimension
237 return lower_kernels.count();
238 }
239 // If polytope is not initialized returns error.
240 if ( polytope.nbHalfSpaces() == 0 ) return -1;
241 return polytope.count();
242 }

◆ countBoundary()

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
Integer DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::countBoundary ( )
inline

Computes the number of integer points lying on the boundary of the polytope.

Returns
the number of integer points lying on the boundary of the polytope.
Note
Quite fast: obtained by line intersection, see BoundedLatticePolytopeCounter
count() <= countInterior() + countBoundary() with equality when the polytope is closed.

Definition at line 273 of file GenericLatticeConvexHull.h.

274 {
275 if ( ptr_gen_qhull->affine_dimension != dimension )
276 { // This kernel is not adapted => go to lower dimension
277 return lower_kernels.countBoundary();
278 }
279 // If polytope is not initialized returns error.
280 if ( polytope.nbHalfSpaces() == 0 ) return -1;
281 return polytope.countBoundary();
282 }

◆ countInterior()

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
Integer DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::countInterior ( )
inline

Computes the number of integer points lying within the interior of the polytope.

Returns
the number of integer points lying within the interior of the polytope.
Note
Quite fast: obtained by line intersection, see BoundedLatticePolytopeCounter
count() <= countInterior() + countBoundary() with equality when the polytope is closed.

Definition at line 253 of file GenericLatticeConvexHull.h.

254 {
255 if ( ptr_gen_qhull->affine_dimension != dimension )
256 { // This kernel is not adapted => go to lower dimension
257 return lower_kernels.countInterior();
258 }
259 // If polytope is not initialized returns error.
260 if ( polytope.nbHalfSpaces() == 0 ) return -1;
261 return polytope.countInterior();
262 }

◆ countUpTo()

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
Integer DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::countUpTo ( Integer max)
inline

Computes the number of integer points within the polytope up to some maximum number max.

Note
For instance, a d-dimensional simplex that contains no integer points in its interior contains only d+1 points. If there is more, you know that the simplex has a non empty interior.
Parameters
[in]maxthe maximum number of points that are counted, the method exists when this number of reached.
Returns
the number of integer points within the polytope up to .
Note
Quite fast: obtained by line intersection, see BoundedLatticePolytopeCounter

Definition at line 299 of file GenericLatticeConvexHull.h.

300 {
301 if ( ptr_gen_qhull->affine_dimension != dimension )
302 { // This kernel is not adapted => go to lower dimension
303 return lower_kernels.countUpTo( max );
304 }
305 // If polytope is not initialized returns error.
306 if ( polytope.nbHalfSpaces() == 0 ) return -1;
307 return polytope.countUpTo( max );
308 }

◆ makePolytope()

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
bool DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::makePolytope ( )
inline

Constructs the polytope that is the F-representation of the convex hull.

Returns
'true' iff the constructed polytope is valid.

Definition at line 183 of file GenericLatticeConvexHull.h.

184 {
185 typedef typename LatticePolytope::Domain Domain;
187 typedef typename QHull::HalfSpace ConvexHullHalfSpace;
189 if ( ptr_gen_qhull->affine_dimension != dimension )
190 { // This kernel is not adapted => go to lower dimension
191 return lower_kernels.makePolytope();
192 }
193 // If polytope is already initialized returns.
194 if ( polytope.nbHalfSpaces() > 0 ) return true;
195 // Compute domain
196 Point l = proj_points[ 0 ];
197 Point u = proj_points[ 0 ];
198 for ( std::size_t i = 1; i < proj_points.size(); i++ )
199 {
200 const auto& p = proj_points[ i ];
201 l = l.inf( p );
202 u = u.sup( p );
203 }
204 Domain domain( l, u );
205
206 // Initialize polytope
209 hull.getFacetHalfSpaces( HS );
210 PHS.reserve( HS.size() );
211 for ( auto& H : HS ) {
212 Point N;
213 Integer nu;
214 for ( Dimension i = 0; i < dimension; ++i )
216 ::cast( H.internalNormal()[ i ] );
218 Integer g = N.norm1() / Ns.norm1();
219 nu = IntegerConverter< dimension, Integer >::cast( H.internalIntercept() );
220 PHS.emplace_back( Ns, nu / g );
221 }
222 polytope = LatticePolytope( domain, PHS.cbegin(), PHS.cend(), false, true );
223 return polytope.isValid();
224 }
ClosedIntegerHalfPlane< Space > HalfSpace
static Integer cast(Integer i)
Kernel::HalfSpace HalfSpace
Definition QuickHull.h:151
Domain domain

Field Documentation

◆ dimension

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
const Dimension DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::dimension = K
static

Definition at line 85 of file GenericLatticeConvexHull.h.

◆ hull

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
QHull DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::hull

the quick hull object that computes the convex hull

Definition at line 313 of file GenericLatticeConvexHull.h.

◆ lower_kernels

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
LowerKernels DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::lower_kernels

the computers of lower dimension

Definition at line 312 of file GenericLatticeConvexHull.h.

◆ polytope

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
LatticePolytope DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::polytope

the polytope corresponding to the convex hull

Definition at line 315 of file GenericLatticeConvexHull.h.

◆ proj_points

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
std::vector< Point > DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::proj_points

the projected points, as points in lower dimension

Definition at line 314 of file GenericLatticeConvexHull.h.

◆ ptr_gen_qhull

template<Dimension dim, typename TCoordinateInteger, typename TInternalInteger, Dimension K>
Computer* DGtal::detail::GenericLatticeConvexHullComputers< dim, TCoordinateInteger, TInternalInteger, K >::ptr_gen_qhull

the pointer on the parent computer

Definition at line 311 of file GenericLatticeConvexHull.h.


The documentation for this struct was generated from the following file: