Example of viewing dual surfaces in Viewer3D.
#include <iostream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "ConfigExamples.h"
#include "DGtal/io/viewers/Viewer3D.h"
using namespace Z3i;
template <typename Vector>
{
return Vector( v1[ 1 ] * v2[ 2 ] - v1[ 2 ] * v2[ 1 ],
v1[ 2 ] * v2[ 0 ] - v1[ 0 ] * v2[ 2 ],
v1[ 0 ] * v2[ 1 ] - v1[ 1 ] * v2[ 0 ] );
}
template <typename Vector>
struct LessThanOnFace
{
const std::vector< Vector > & pts;
inline LessThanOnFace(
const Vector & aN,
const Vector & aP,
const std::vector< Vector > & aPts )
: N( aN ), P( aP ), pts( aPts )
{}
inline bool operator()( unsigned int i1, unsigned int i2 ) const
{
return N.dot(
wedge( pts[ i1 ] - P, pts[ i2 ] - P ) ) > 0;
}
};
template <typename Vector>
( std::vector< std::vector< unsigned int > > & indices,
const std::vector<Vector> & points, bool left_handed )
{
typedef typename Vector::Component Scalar;
std::vector< unsigned int > aFace;
for ( unsigned int i1 = 0; i1 < points.size(); ++i1 )
for ( unsigned int i2 = 0; i2 < points.size(); ++i2 )
if ( i1 != i2 )
for ( unsigned int i3 = i1 > i2 ? i1+1 : i2+1; i3 < points.size(); ++i3 )
{
Vector P12 = points[ i2 ] - points[ i1 ];
Vector P13 = points[ i3 ] - points[ i1 ];
if ( N == Vector::zero ) continue;
unsigned int nbBadPos = 0;
for ( unsigned int i4 = 0; i4 < points.size(); ++i4 )
{
Vector P14 = points[ i4 ] - points[ i1 ];
Scalar c = N.dot( P14 );
if ( c == 0 ) aFace.push_back( i4 );
else if ( ( left_handed && ( c > 0 ) )
|| ( ! left_handed && ( c < 0 ) ) )
++nbBadPos;
}
if ( nbBadPos == 0 )
{
LessThanOnFace<Vector> LTOF( N, points[ aFace[ 0 ] ], points );
std::sort( ++aFace.begin(), aFace.end(), LTOF );
indices.push_back( aFace );
}
aFace.clear();
}
for ( unsigned int i = 0; i < indices.size(); ++i )
{
auto s = indices[ i ].size();
for ( unsigned int j = i+1; j < indices.size(); )
{
if ( indices[ j ].size() == s )
{
bool equal = true;
for ( unsigned int k = 0; equal && ( k < s ); ++k )
if ( indices[ i ][ k ] != indices[ j ][ k ] )
equal = false;
if ( equal )
{
std::swap( indices[ j ], indices.back() );
indices.pop_back();
}
else
++j;
}
else ++j;
}
}
}
{
return ( x - 1.0 ) * 0.5 + 0.5;
}
const std::vector< std::vector< unsigned int > > & indices,
const std::vector<Vector> & points )
{
std::vector<RealPoint> pts3d;
for ( unsigned int f = 0; f < indices.size(); ++f )
{
pts3d.clear();
for ( unsigned int v = 0; v < indices[ f ].size(); ++v )
{
unsigned int i = indices[ f ][ v ];
P[0] =
rescale( points[ i ][ 0 ] );
P[1] =
rescale( points[ i ][ 1 ] );
P[2] =
rescale( points[ i ][ 2 ] );
pts3d.push_back( P );
}
}
}
template <typename Vector>
{
unsigned int d = 0;
for ( unsigned int i = 0; i < Vector::dimension; ++i )
if ( ( z[ i ] % 2 ) == 1 ) ++d;
return d;
}
template <typename Vector>
{
for ( unsigned int i = 0; i < Vector::dimension; ++i )
if ( ( z[ i ] % 2 ) == 1 ) return i;
return Vector::dimension;
}
template <typename Vector>
{
--z2[ k ];
return z2;
}
template <typename Vector>
{
++z2[ k ];
return z2;
}
template <typename Vector>
unsigned int nbLighted( std::map< Vector, bool > & f,
{
unsigned int d =
dim( z );
if ( d == 0 ) return f[ z ] ? 1 : 0;
}
template <typename Vector>
{
unsigned int d =
dim( z );
if ( d == 0 ) return f[ z ];
else if ( d == 1 )
{
}
else
{
for ( unsigned int i = 0; i < Vector::dimension; ++i )
{
v1[ i ] = ( ( z[ i ] % 2 ) == 1 ) ? z[ i ] - 1 : z[ i ];
v2[ i ] = ( ( z[ i ] % 2 ) == 1 ) ? z[ i ] + 1 : z[ i ];
}
for ( Domain::ConstIterator it =
domain.begin(), itE =
domain.end();
it != itE; ++it )
{
if ( *it == z ) break;
return true;
}
return false;
}
}
template <typename Vector>
bool lightMax( std::map< Vector, bool > & f,
{
unsigned int d =
dim( z );
if ( d == 0 ) return f[ z ];
else if ( d == 1 )
{
}
else
{
return n >= 2;
}
}
template <typename Vector>
{
unsigned int d =
dim( z );
if ( d == 0 ) return f[ z ];
else
{
bool val = true;
for ( unsigned i = 0; i < d; ++i )
{
}
return val;
}
}
template <typename Vector>
{
unsigned int d =
dim( z );
if ( d == 0 ) return f[ z ];
else
{
bool val = false;
for ( unsigned i = 0; i < d; ++i )
{
}
return val;
}
}
template <typename Vector>
unsigned int epsilon )
{
unsigned int d =
dim( z );
if ( d == 0 ) return f[ z ];
else
{
bool eps_d = ( ( epsilon >> (d-1)) & 1 ) != 0;
bool val = eps_d ? true : false;
for ( unsigned i = 0; i < d; ++i )
{
if ( eps_d )
else
}
return val;
}
}
template <typename Vector>
void fillCfg( std::map< Vector, bool > & f,
unsigned int cfg )
{
unsigned int d =
dim( z );
if ( d == 0 )
{
f[ z ] = (cfg == 1);
}
else
{
unsigned n = 1 << ( d - 1 );
unsigned int cfgLow = 0;
unsigned int cfgUp = 0;
for ( unsigned int j = 0; j < n; ++j )
{
cfgLow += ( cfg & 1 ) << j;
cfg >>= 1;
cfgUp += ( cfg & 1 ) << j;
cfg >>= 1;
}
}
}
template <typename Vector>
std::map< Vector, bool > & f,
{
points.clear();
it != itE; ++it )
{
if ( f[ *it ] ) points.push_back( *it );
}
}
template <typename Vector>
struct ConfigPointPredicate
{
std::map< Vector, bool > & fct;
ConfigPointPredicate( std::map< Vector, bool > & aFct,
Vector aBase )
: fct( aFct ), base( aBase ) {}
bool operator()(
const Vector & p )
const
{
return fct[ p * 2 + base];
}
};
int main(
int argc,
char** argv )
{
typedef KSpace::CellSet CellSet;
QApplication application(argc,argv);
std::vector<Vector> pts;
unsigned int cfg = argc > 1 ? atoi( argv[1] ) : 0;
unsigned int cfg2 = argc > 2 ? atoi( argv[2] ) : 255;
std::map< Vector, bool > f;
for ( unsigned int y = 0; (y < 16) && (cfg <= cfg2); ++y )
for ( unsigned int x = 0; (x < 16) && (cfg <= cfg2); ++x, ++cfg )
{
ConfigPointPredicate<Vector> cpp( f, offset );
CellSet aBoundary;
for ( CellSet::const_iterator it = aBoundary.begin(), itE = aBoundary.end();
it != itE; ++it )
{
viewer << KS.uTranslation( *it, offset/2 );
}
for ( Domain::ConstIterator it =
domain.begin(), itE =
domain.end();
it != itE; ++it )
{
}
std::vector< std::vector< unsigned int > > indices;
for ( Domain::ConstIterator it =
domain.begin(), itE =
domain.end();
it != itE; ++it )
{
indices.clear();
}
}
viewer << Viewer3D<>::updateDisplay;
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.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Display::RealPoint RealPoint
DGtal is the top-level namespace which contains all DGtal functions and types.
FreemanChain< int >::Vector Vector
HyperRectDomain< Space > Domain
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)