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 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 )
{
usage( argc, argv );
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 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;
}
MySurfelAdjacency surfAdj( true );
typedef KSpace::Surfel
Surfel;
MySetOfSurfels theSetOfSurfels(
K, surfAdj );
dshape, bel );
trace.
info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
<< std::endl;
typedef
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;
}
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Aim: a cellular embedder for implicit functions, (default constructible, copy constructible,...
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Aim: This class converts a string polynomial expression in a multivariate polynomial.
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
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.
HyperRectDomain< Space > Domain