Implicit polynomial surface defined on the command-line by the user (as "(x^2+y^2+2z^2-1)*(z^2x-0.1)"), then extracted using digital surface tracking and converted into the corresponding combinatorial surface.
#include <iostream>
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/topology/SetOfSurfels.h"
#include "DGtal/math/MPolynomial.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/shapes/implicit/ImplicitPolynomial3Shape.h"
#include "DGtal/shapes/implicit/ImplicitFunctionDiff1LinearCellEmbedder.h"
#include "DGtal/io/readers/MPolynomialReader.h"
using namespace std;
using namespace Z3i;
void usage(
int ,
char** argv )
{
std::cerr << "Usage: " << argv[ 0 ] << " <Polynomial> <Px> <Py> <Pz> <Qx> <Qy> <Qz> <step>" << std::endl;
std::cerr << "\t - displays the boundary of a shape defined implicitly by a 3-polynomial <Polynomial>." << std::endl;
std::cerr << "\t - P and Q defines the bounding box." << std::endl;
std::cerr << "\t - step is the grid step." << std::endl;
std::cerr << "\t - You may try x^3y+xz^3+y^3z+z^3+5z or (y^2+z^2-1)^2 +(x^2+y^2-1)^3 " << std::endl;
std::cerr << "\t - See http://www.freigeist.cc/gallery.html" << std::endl;
}
int main(
int argc,
char** argv )
{
if ( argc < 9 )
{
return 1;
}
double p1[ 3 ];
double p2[ 3 ];
for ( unsigned int i = 0; i < 3; ++i )
{
p1[ i ] = atof( argv[ 2+i ] );
p2[ i ] = atof( argv[ 5+i ] );
}
double step = atof( argv[ 8 ] );
typedef RealPoint::Coordinate Ring;
typedef MPolynomial<3, Ring> Polynomial3;
typedef MPolynomialReader<3, Ring> Polynomial3Reader;
typedef ImplicitPolynomial3Shape<Space> ImplicitShape;
typedef GaussDigitizer<Space,ImplicitShape> DigitalShape;
typedef DigitalShape::PointEmbedder DigitalEmbedder;
Polynomial3 P;
Polynomial3Reader reader;
std::string poly_str = argv[ 1 ];
std::string::const_iterator iter
= reader.read( P, poly_str.begin(), poly_str.end() );
if ( iter != poly_str.end() )
{
std::cerr << "ERROR: I read only <"
<< poly_str.substr( 0, iter - poly_str.begin() )
<< ">, and I built P=" << P << std::endl;
return 1;
}
trace.
info() <<
"P( X_0, X_1, X_2 ) = " << P << std::endl;
ImplicitShape ishape( P );
DigitalShape dshape;
dshape.attach( ishape );
bool space_ok =
K.init(
domain.lowerBound(),
);
if (!space_ok)
{
trace.
error() <<
"Error in the Khamisky space construction."<<std::endl;
return 2;
}
typedef SurfelAdjacency<KSpace::dimension> MySurfelAdjacency;
MySurfelAdjacency surfAdj( true );
typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
MySetOfSurfels theSetOfSurfels(
K, surfAdj );
Surfel bel = Surfaces<KSpace>::findABel(
K, dshape, 100000 );
Surfaces<KSpace>::trackBoundary( theSetOfSurfels.surfelSet(),
dshape, bel );
trace.
info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
<< std::endl;
typedef
ImplicitFunctionDiff1LinearCellEmbedder<
KSpace,
ImplicitShape,
DigitalEmbedder >
CellEmbedder;
CellEmbedder cellEmbedder;
cellEmbedder.init(
K, ishape, dshape.pointEmbedder() );
ofstream out( "marching-cube.off" );
if ( out.good() )
digSurf.exportEmbeddedSurfaceAs3DOFF( out, cellEmbedder );
out.close();
ofstream out2( "marching-cube.noff" );
if ( out2.good() )
digSurf.exportEmbeddedSurfaceAs3DNOFF( out2, cellEmbedder );
out2.close();
return 0;
}
void usage(int, char **argv)
void beginBlock(const std::string &keyword="")
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
MyDigitalSurface::SurfelSet SurfelSet
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
HyperRectDomain< Space > Domain
PointVector< 3, double > RealPoint