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/Viewer3D.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;
67 inline LessThanOnFace(
const Vector & aN,
const Vector & aP,
68 const std::vector< Vector > & aPts )
69 : N( aN ), P( aP ), pts( aPts )
71 inline bool operator()(
unsigned int i1,
unsigned int i2 )
const
73 return N.
dot(
wedge( pts[ i1 ] - P, pts[ i2 ] - P ) ) > 0;
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 ) ) )
109 LessThanOnFace<Vector> LTOF( N, points[ aFace[ 0 ] ], points );
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;
150 const std::vector< std::vector< unsigned int > > & indices,
151 const std::vector<Vector> & points )
154 std::vector<RealPoint> pts3d;
156 for (
unsigned int f = 0; f < indices.size(); ++f )
160 for (
unsigned int v = 0; v < indices[ f ].size(); ++v )
162 unsigned int i = indices[ f ][ v ];
163 P[0] =
rescale( points[ i ][ 0 ] );
164 P[1] =
rescale( points[ i ][ 1 ] );
165 P[2] =
rescale( points[ i ][ 2 ] );
166 pts3d.push_back( P );
173template <
typename Vector>
178 if ( ( z[ i ] % 2 ) == 1 ) ++d;
182template <
typename Vector>
186 if ( ( z[ i ] % 2 ) == 1 )
return i;
189template <
typename Vector>
196template <
typename Vector>
204template <
typename Vector>
208 unsigned int d =
dim( z );
209 if ( d == 0 )
return f[ z ] ? 1 : 0;
217template <
typename Vector>
221 unsigned int d =
dim( z );
222 if ( d == 0 )
return f[ z ];
226 return f[
lower( z, i ) ] || f[
upper( z, i ) ];
233 v1[ i ] = ( ( z[ i ] % 2 ) == 1 ) ? z[ i ] - 1 : z[ i ];
234 v2[ i ] = ( ( z[ i ] % 2 ) == 1 ) ? z[ i ] + 1 : z[ i ];
240 if ( *it == z )
break;
241 Point zp = z*2 - *it;
252template <
typename Vector>
256 unsigned int d =
dim( z );
257 if ( d == 0 )
return f[ z ];
261 return f[
lower( z, i ) ] || f[
upper( z, i ) ];
269template <
typename Vector>
273 unsigned int d =
dim( z );
274 if ( d == 0 )
return f[ z ];
279 for (
unsigned i = 0; i < d; ++i )
281 unsigned int k =
openDim( tmp );
282 tmp =
lower( tmp, k );
288template <
typename Vector>
292 unsigned int d =
dim( z );
293 if ( d == 0 )
return f[ z ];
298 for (
unsigned i = 0; i < d; ++i )
300 unsigned int k =
openDim( tmp );
301 tmp =
lower( tmp, k );
308template <
typename Vector>
311 unsigned int epsilon )
313 unsigned int d =
dim( z );
314 if ( d == 0 )
return f[ z ];
318 bool eps_d = ( ( epsilon >> (d-1)) & 1 ) != 0;
319 bool val = eps_d ? true :
false;
320 for (
unsigned i = 0; i < d; ++i )
322 unsigned int k =
openDim( tmp );
323 tmp =
lower( tmp, k );
336template <
typename Vector>
341 unsigned int d =
dim( z );
349 unsigned n = 1 << ( d - 1 );
350 unsigned int cfgLow = 0;
351 unsigned int cfgUp = 0;
352 for (
unsigned int j = 0; j < n; ++j )
354 cfgLow += ( cfg & 1 ) << j;
356 cfgUp += ( cfg & 1 ) << j;
365template <
typename Vector>
367 std::map< Vector, bool > & f,
375 if ( f[ *it ] ) points.push_back( *it );
379template <
typename Vector>
380struct ConfigPointPredicate
382 std::map< Vector, bool > & fct;
384 ConfigPointPredicate( std::map< Vector, bool > & aFct,
Vector aBase )
385 : fct( aFct ), base( aBase ) {}
386 bool operator()(
const Vector & p )
const
388 return fct[ p * 2 + base];
392int main(
int argc,
char** argv )
395 QApplication application(argc,argv);
405 std::vector<Vector> pts;
407 unsigned int cfg = argc > 1 ? atoi( argv[1] ) : 0;
408 unsigned int cfg2 = argc > 2 ? atoi( argv[2] ) : 255;
409 std::map< Vector, bool > f;
410 for (
unsigned int y = 0; (y < 16) && (cfg <= cfg2); ++y )
411 for (
unsigned int x = 0; (x < 16) && (cfg <= cfg2); ++x, ++cfg )
413 Vector offset( x*6, y*6, 0 );
418 ConfigPointPredicate<Vector> cpp( f, offset );
421 for ( CellSet::const_iterator it = aBoundary.begin(), itE = aBoundary.end();
434 std::vector< std::vector< unsigned int > > indices;
446 viewer << Viewer3D<>::updateDisplay;
448 return application.exec();
Structure representing an RGB triple with alpha component.
virtual DGtal::Color getFillColor()
virtual void setFillColor(DGtal::Color aColor)
void addPolygon(const std::vector< RealPoint > &vertices)
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.
static Self diagonal(Component val=1)
static const Dimension dimension
static void uMakeBoundary(CellSet &aBoundary, const KSpace &aKSpace, const PointPredicate &pp, const Point &aLowerBound, const Point &aUpperBound)
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Space::RealPoint RealPoint
DGtal is the top-level namespace which contains all DGtal functions and types.
void naiveConvexHull(std::vector< std::vector< unsigned int > > &indices, const std::vector< Vector > &points, bool left_handed)
void viewPolygons(Viewer &viewer, const DGtal::Color &color, 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)