DGtal 2.1.0
Loading...
Searching...
No Matches
exampleGenericLatticeConvexHull4D.cpp File Reference
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
#include <polyscope/polyscope.h>
#include <polyscope/surface_mesh.h>
#include <polyscope/point_cloud.h>
#include <polyscope/curve_network.h>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/tools/GenericLatticeConvexHull.h"
Include dependency graph for exampleGenericLatticeConvexHull4D.cpp:

Go to the source code of this file.

Functions

std::mt19937 g (rd())
 
template<Dimension dim, typename TComponent , typename TContainer >
static DGtal::PointVector< dim-1, TComponent, TContainer > project (Dimension k, const DGtal::PointVector< dim, TComponent, TContainer > &p)
 
template<Dimension dim, typename TComponent , typename TContainer >
static std::vector< DGtal::PointVector< dim-1, TComponent, TContainer > > project (Dimension k, const std::vector< DGtal::PointVector< dim, TComponent, TContainer > > &V)
 
template<typename Point >
static std::vector< PointmakeRandomLatticePointsFromDirVectors (Point A, const std::vector< Point > &V, int nb, double radius, int amplitude, int aff_dim)
 
int main (int argc, char *argv[])
 

Variables

polyscope::PointCloud * psPoints [4]
 
polyscope::PointCloud * psVertices [4]
 
polyscope::PointCloud * psBoundary0 [4]
 
polyscope::CurveNetwork * psBoundary1 [4]
 
polyscope::SurfaceMesh * psBoundary2 [4]
 
polyscope::Group * group [4]
 
std::random_device rd
 

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
2025/09/07

This file is part of the DGtal library.

Definition in file exampleGenericLatticeConvexHull4D.cpp.

Function Documentation

◆ g()

std::mt19937 g ( rd()  )

◆ main()

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

Definition at line 122 of file exampleGenericLatticeConvexHull4D.cpp.

123{
125 typedef SpaceND< 4, int > Space;
126 typedef Space::Point Point4;
127
128 std::cout << "Usage: " << argv[ 0 ] << " [R=30] [N=30] [D=2]\n";
129 std::cout << "Computes the convex hull of N 4D points within a ball of radius R, these points belonging to a lattice of chosen dimension 0<=D<=3. The output is projected along the 4 canonic projections onto 3D space. You cannot choose D=4 since we cannot diplay the result in 3D.\n";
130 double radius = argc > 1 ? atof( argv[ 1 ] ) : 30.0;
131 int nb = argc > 2 ? atoi( argv[ 2 ] ) : 30;
132 int adim = argc > 3 ? atoi( argv[ 3 ] ) : 2;
133 if ( nb < 0 ) return 1;
134 if ( adim < 0 || adim > 3 ) return 1;
135
136 // Create points
137 std::vector< Point4 > L = { Point4{ 4, 1, -3, 1 },
138 Point4{ 0, 2, 5, -1 },
139 Point4{ -1, -3, 5, 0 },
140 Point4{ 2, 0, 3, -3 } };
141 std::vector< Point4 > X
142 = makeRandomLatticePointsFromDirVectors( Point4(1,2,-1,0),
143 L, nb,
144 radius,
145 int( round( radius+0.5 ) ),
146 adim );
147
148 // Compute convex hull
149 QHull hull;
150 bool ok = hull.compute( X );
151 std:: cout << ( ok ? "[PASSED]" : "[FAILED]" ) << " hull=" << hull << "\n";
152 // Initialize polyscope
153 polyscope::init();
154 std::string proj[ 4 ] = { "(yzw)", "(xzw)", "(xyw)", "(xyz)" };
155 for ( Dimension k = 0; k < 4; k++ )
156 {
157 group [k] = polyscope::createGroup( proj[k] );
158 psPoints [k] = polyscope::registerPointCloud( proj[k]+" Points",
159 project( k, X ) );
160 psVertices[k] = polyscope::registerPointCloud( proj[k]+" Vertices",
161 project( k, hull.positions ) );
162 psPoints [k]->addToGroup( proj[k] ); // add by name
163 psVertices[k]->addToGroup( proj[k] ); // add by name
164
165 if ( hull.affine_dimension <= 1 ) // 1 or 2 points
166 {
167 // no facets
168 psBoundary0[k] = polyscope::registerPointCloud( proj[k]+" Convex hull bdy dim=0",
169 project( k, hull.positions ) );
170 psBoundary0[k]->addToGroup( proj[k] ); // add by name
171 }
172 else if ( hull.affine_dimension == 2 ) // 2D
173 {
174 // facets are edges (and implicitly converted by polyscope)
175 psBoundary1[k] = polyscope::registerCurveNetwork( proj[k]+" Convex hull bdy dim=1",
176 project( k, hull.positions ),
177 hull.facets );
178 psBoundary1[k]->addToGroup( proj[k] ); // add by name
179 }
180 else if ( hull.affine_dimension == 3 ) // 3D
181 {
182 // facets are polygons
183 psBoundary2[k] = polyscope::registerSurfaceMesh( proj[k]+" Convex hull bdy dim=2",
184 project( k, hull.positions ),
185 hull.facets );
186 psBoundary2[k]->addToGroup( proj[k] ); // add by name
187 }
188 }
189
190 polyscope::show();
191 return EXIT_SUCCESS;
192
193}
polyscope::PointCloud * psBoundary0[4]
static DGtal::PointVector< dim-1, TComponent, TContainer > project(Dimension k, const DGtal::PointVector< dim, TComponent, TContainer > &p)
polyscope::SurfaceMesh * psBoundary2[4]
polyscope::Group * group[4]
polyscope::PointCloud * psVertices[4]
polyscope::PointCloud * psPoints[4]
polyscope::CurveNetwork * psBoundary1[4]
static std::vector< Point > makeRandomLatticePointsFromDirVectors(Point A, const std::vector< Point > &V, int nb, double radius, int amplitude, int aff_dim)
DGtal::uint32_t Dimension
Definition Common.h:119
Aim: Implements the quickhull algorithm by Barber et al. , a famous arbitrary dimensional convex hull...

References group, DGtal::L, makeRandomLatticePointsFromDirVectors(), project(), psBoundary0, psBoundary1, psBoundary2, psPoints, and psVertices.

◆ makeRandomLatticePointsFromDirVectors()

template<typename Point >
static std::vector< Point > makeRandomLatticePointsFromDirVectors ( Point  A,
const std::vector< Point > &  V,
int  nb,
double  radius,
int  amplitude,
int  aff_dim 
)
static

Definition at line 101 of file exampleGenericLatticeConvexHull4D.cpp.

103{
104 std::uniform_int_distribution<int> U(-amplitude, amplitude);
105 std::vector< Point > P;
106 int m = std::min( aff_dim, (int) V.size() );
107 for ( auto k = 0; P.size() < nb && k < 100000; k++ )
108 {
109 Point B = A;
110 for ( auto i = 0; i < m; i++ )
111 {
112 int l = U( g );
113 B += l * V[ i ];
114 }
115 if ( (B-A).norm() <= radius )
116 P.push_back( B );
117 }
118 std::shuffle( P.begin(), P.end(), g );
119 return P;
120}
std::mt19937 g(rd())

References g().

Referenced by main().

◆ project() [1/2]

template<Dimension dim, typename TComponent , typename TContainer >
static DGtal::PointVector< dim-1, TComponent, TContainer > project ( Dimension  k,
const DGtal::PointVector< dim, TComponent, TContainer > &  p 
)
static

Definition at line 75 of file exampleGenericLatticeConvexHull4D.cpp.

77{
78 DGtal::PointVector< dim-1, TComponent, TContainer > pp;
79 Dimension l = 0;
80 for ( Dimension i = 0; i < dim; i++ )
81 if ( i != k ) pp[ l++ ] = p[ i ];
82 return pp;
83}
Aim: Implements basic operations that will be used in Point and Vector classes.

References dim.

Referenced by main(), and project().

◆ project() [2/2]

template<Dimension dim, typename TComponent , typename TContainer >
static std::vector< DGtal::PointVector< dim-1, TComponent, TContainer > > project ( Dimension  k,
const std::vector< DGtal::PointVector< dim, TComponent, TContainer > > &  V 
)
static

Definition at line 88 of file exampleGenericLatticeConvexHull4D.cpp.

90{
91 std::vector< DGtal::PointVector< dim-1, TComponent, TContainer > > pV( V.size() );
92 for ( auto i = 0; i < pV.size(); i++ )
93 pV[ i ] = project( k, V[ i ] );
94 return pV;
95}

References dim, and project().

Variable Documentation

◆ group

polyscope::Group* group[4]

◆ psBoundary0

polyscope::PointCloud* psBoundary0[4]

Definition at line 64 of file exampleGenericLatticeConvexHull4D.cpp.

Referenced by main().

◆ psBoundary1

polyscope::CurveNetwork* psBoundary1[4]

Definition at line 65 of file exampleGenericLatticeConvexHull4D.cpp.

Referenced by main().

◆ psBoundary2

polyscope::SurfaceMesh* psBoundary2[4]

Definition at line 66 of file exampleGenericLatticeConvexHull4D.cpp.

Referenced by main().

◆ psPoints

polyscope::PointCloud* psPoints[4]

Definition at line 62 of file exampleGenericLatticeConvexHull4D.cpp.

Referenced by main().

◆ psVertices

polyscope::PointCloud* psVertices[4]

Definition at line 63 of file exampleGenericLatticeConvexHull4D.cpp.

Referenced by main().

◆ rd

std::random_device rd

Definition at line 69 of file exampleGenericLatticeConvexHull4D.cpp.