40#include "DGtal/base/Common.h"
41#include "DGtal/helpers/StdDefs.h"
42#include "DGtal/topology/helpers/Surfaces.h"
43#include "ConfigExamples.h"
44#include "DGtal/io/viewers/PolyscopeViewer.h"
53template <
typename Vector>
56 return Vector( v1[ 1 ] * v2[ 2 ] - v1[ 2 ] * v2[ 1 ],
57 v1[ 2 ] * v2[ 0 ] - v1[ 0 ] * v2[ 2 ],
58 v1[ 0 ] * v2[ 1 ] - v1[ 1 ] * v2[ 0 ] );
61template <
typename Vector>
66 const std::vector< Vector > &
pts;
68 const std::vector< Vector > & aPts )
69 :
N( aN ),
P( aP ),
pts( aPts )
71 inline bool operator()(
unsigned int i1,
unsigned int i2 )
const
79template <
typename Vector>
81( std::vector< std::vector< unsigned int > > & indices,
82 const std::vector<Vector> & points,
bool left_handed )
86 std::vector< unsigned int > aFace;
87 for (
unsigned int i1 = 0; i1 < points.size(); ++i1 )
88 for (
unsigned int i2 = 0; i2 < points.size(); ++i2 )
90 for (
unsigned int i3 = i1 > i2 ? i1+1 : i2+1; i3 < points.size(); ++i3 )
92 Vector P12 = points[ i2 ] - points[ i1 ];
93 Vector P13 = points[ i3 ] - points[ i1 ];
97 unsigned int nbBadPos = 0;
98 for (
unsigned int i4 = 0; i4 < points.size(); ++i4 )
100 Vector P14 = points[ i4 ] - points[ i1 ];
101 Scalar c = N.
dot( P14 );
102 if ( c == 0 ) aFace.push_back( i4 );
103 else if ( ( left_handed && ( c > 0 ) )
104 || ( ! left_handed && ( c < 0 ) ) )
110 std::sort( ++aFace.begin(), aFace.end(), LTOF );
111 indices.push_back( aFace );
116 for (
unsigned int i = 0; i < indices.size(); ++i )
118 auto s = indices[ i ].size();
119 for (
unsigned int j = i+1; j < indices.size(); )
121 if ( indices[ j ].size() == s )
124 for (
unsigned int k = 0; equal && ( k < s ); ++k )
125 if ( indices[ i ][ k ] != indices[ j ][ k ] )
129 std::swap( indices[ j ], indices.back() );
142 return ( x - 1.0 ) * 0.5 + 0.5;
149 const std::vector< std::vector< unsigned int > > & indices,
150 const std::vector<Vector> & points )
153 std::vector<RealPoint> pts3d;
155 for (
unsigned int f = 0; f < indices.size(); ++f )
159 for (
unsigned int v = 0; v < indices[ f ].size(); ++v )
161 unsigned int i = indices[ f ][ v ];
162 P[0] =
rescale( points[ i ][ 0 ] );
163 P[1] =
rescale( points[ i ][ 1 ] );
164 P[2] =
rescale( points[ i ][ 2 ] );
165 pts3d.push_back( P );
172template <
typename Vector>
177 if ( ( z[ i ] % 2 ) == 1 ) ++d;
181template <
typename Vector>
185 if ( ( z[ i ] % 2 ) == 1 )
return i;
188template <
typename Vector>
195template <
typename Vector>
203template <
typename Vector>
207 unsigned int d =
dim( z );
208 if ( d == 0 )
return f[ z ] ? 1 : 0;
216template <
typename Vector>
220 unsigned int d =
dim( z );
221 if ( d == 0 )
return f[ z ];
225 return f[
lower( z, i ) ] || f[
upper( z, i ) ];
232 v1[ i ] = ( ( z[ i ] % 2 ) == 1 ) ? z[ i ] - 1 : z[ i ];
233 v2[ i ] = ( ( z[ i ] % 2 ) == 1 ) ? z[ i ] + 1 : z[ i ];
239 if ( *it == z )
break;
240 Point zp = z*2 - *it;
251template <
typename Vector>
255 unsigned int d =
dim( z );
256 if ( d == 0 )
return f[ z ];
260 return f[
lower( z, i ) ] || f[
upper( z, i ) ];
268template <
typename Vector>
272 unsigned int d =
dim( z );
273 if ( d == 0 )
return f[ z ];
278 for (
unsigned i = 0; i < d; ++i )
280 unsigned int k =
openDim( tmp );
281 tmp =
lower( tmp, k );
287template <
typename Vector>
291 unsigned int d =
dim( z );
292 if ( d == 0 )
return f[ z ];
297 for (
unsigned i = 0; i < d; ++i )
299 unsigned int k =
openDim( tmp );
300 tmp =
lower( tmp, k );
307template <
typename Vector>
310 unsigned int epsilon )
312 unsigned int d =
dim( z );
313 if ( d == 0 )
return f[ z ];
317 bool eps_d = ( ( epsilon >> (d-1)) & 1 ) != 0;
318 bool val = eps_d ? true :
false;
319 for (
unsigned i = 0; i < d; ++i )
321 unsigned int k =
openDim( tmp );
322 tmp =
lower( tmp, k );
335template <
typename Vector>
340 unsigned int d =
dim( z );
348 unsigned n = 1 << ( d - 1 );
349 unsigned int cfgLow = 0;
350 unsigned int cfgUp = 0;
351 for (
unsigned int j = 0; j < n; ++j )
353 cfgLow += ( cfg & 1 ) << j;
355 cfgUp += ( cfg & 1 ) << j;
364template <
typename Vector>
366 std::map< Vector, bool > & f,
374 if ( f[ *it ] ) points.push_back( *it );
378template <
typename Vector>
381 std::map< Vector, bool > &
fct;
384 :
fct( aFct ),
base( aBase ) {}
391int main(
int argc,
char** argv )
406 viewer << surfelColor;
407 std::string surfels = viewer.
newQuadList(
"Surfels");
408 viewer << voxelColor;
411 std::vector<Vector> pts;
413 unsigned int cfg = argc > 1 ? atoi( argv[1] ) : 0;
414 unsigned int cfg2 = argc > 2 ? atoi( argv[2] ) : 255;
415 std::map< Vector, bool > f;
416 for (
unsigned int y = 0; (y < 16) && (cfg <= cfg2); ++y )
417 for (
unsigned int x = 0; (x < 16) && (cfg <= cfg2); ++x, ++cfg )
419 Vector offset( x*6, y*6, 0 );
429 for ( CellSet::const_iterator it = aBoundary.begin(), itE = aBoundary.end();
432 viewer << surfelColor;
443 std::vector< std::vector< unsigned int > > indices;
Structure representing an RGB triple with alpha component.
std::string drawPolygon(const std::vector< Vec > &vertices, const std::string &uname="Polygon_{i}")
Draws a polygon.
bool setCurrentList(const std::string &name)
Set the current group for further updates.
std::string newQuadList(const std::string &name)
typename Space::RealPoint RealPoint
std::string newPolygonList(const std::string &name)
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Cell uTranslation(const Cell &p, const Vector &vec) const
Add the vector [vec] to [p].
std::set< Cell > CellSet
Preferred type for defining a set of Cell(s).
auto dot(const PointVector< dim, OtherComponent, OtherStorage > &v) const -> decltype(DGtal::dotProduct(*this, v))
Dot product with a PointVector.
void clear()
Resets all the values to zero.
Integer Component
Type for Vector elements.
static Self diagonal(Component val=1)
static Self zero
Static const for zero PointVector.
static const Dimension dimension
Copy of the static dimension of the Point/Vector.
void show() override
Starts the event loop and display of elements.
static void uMakeBoundary(CellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
Space::RealPoint RealPoint
DGtal is the top-level namespace which contains all DGtal functions and types.
ConfigPointPredicate(std::map< Vector, bool > &aFct, Vector aBase)
std::map< Vector, bool > & fct
bool operator()(const Vector &p) const
LessThanOnFace(const Vector &aN, const Vector &aP, const std::vector< Vector > &aPts)
const std::vector< Vector > & pts
bool operator()(unsigned int i1, unsigned int i2) const
void naiveConvexHull(std::vector< std::vector< unsigned int > > &indices, const std::vector< Vector > &points, bool left_handed)
void viewPolygons(Viewer &viewer, const std::vector< std::vector< unsigned int > > &indices, const std::vector< Vector > &points)
bool lightMaxMin(std::map< Vector, bool > &f, const Vector &z)
Vector lower(const Vector &z, unsigned int k)
bool lightBetween(std::map< Vector, bool > &f, const Vector &z)
unsigned int openDim(const Vector &z)
void fillCfg(std::map< Vector, bool > &f, const Vector &z, unsigned int cfg)
Vector wedge(const Vector &v1, const Vector &v2)
unsigned int nbLighted(std::map< Vector, bool > &f, const Vector &z)
Vector upper(const Vector &z, unsigned int k)
bool lightMax(std::map< Vector, bool > &f, const Vector &z)
bool lightEpsilon(std::map< Vector, bool > &f, const Vector &z, unsigned int epsilon)
void localDualVolume(std::vector< Vector > &points, std::map< Vector, bool > &f, const Vector &z)
bool lightMinMax(std::map< Vector, bool > &f, const Vector &z)