33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/topology/helpers/Surfaces.h"
35 #include "DGtal/topology/DigitalSurface.h"
36 #include "DGtal/topology/SetOfSurfels.h"
37 #include "DGtal/math/MPolynomial.h"
38 #include "DGtal/shapes/GaussDigitizer.h"
39 #include "DGtal/shapes/implicit/ImplicitPolynomial3Shape.h"
40 #include "DGtal/shapes/implicit/ImplicitFunctionDiff1LinearCellEmbedder.h"
41 #include "DGtal/io/readers/MPolynomialReader.h"
47 using namespace DGtal;
53 void usage(
int ,
char** argv )
55 std::cerr <<
"Usage: " << argv[ 0 ] <<
" <Polynomial> <Px> <Py> <Pz> <Qx> <Qy> <Qz> <step>" << std::endl;
56 std::cerr <<
"\t - displays the boundary of a shape defined implicitly by a 3-polynomial <Polynomial>." << std::endl;
57 std::cerr <<
"\t - P and Q defines the bounding box." << std::endl;
58 std::cerr <<
"\t - step is the grid step." << std::endl;
59 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;
60 std::cerr <<
"\t - See http://www.freigeist.cc/gallery.html" << std::endl;
63 int main(
int argc,
char** argv )
72 for (
unsigned int i = 0; i < 3; ++i )
74 p1[ i ] = atof( argv[ 2+i ] );
75 p2[ i ] = atof( argv[ 5+i ] );
77 double step = atof( argv[ 8 ] );
84 typedef MPolynomialReader<3, Ring> Polynomial3Reader;
91 Polynomial3Reader reader;
92 std::string poly_str = argv[ 1 ];
93 std::string::const_iterator iter
94 = reader.read( P, poly_str.begin(), poly_str.end() );
95 if ( iter != poly_str.end() )
97 std::cerr <<
"ERROR: I read only <"
98 << poly_str.substr( 0, iter - poly_str.begin() )
99 <<
">, and I built P=" << P << std::endl;
125 trace.
info() <<
"P( X_0, X_1, X_2 ) = " << P << std::endl;
126 ImplicitShape ishape( P );
129 dshape.
init( RealPoint( p1 ), RealPoint( p2 ), step );
145 trace.
error() <<
"Error in the Khamisky space construction."<<std::endl;
152 MySurfelAdjacency surfAdj(
true );
164 MySetOfSurfels theSetOfSurfels( K, surfAdj );
174 MyDigitalSurface digSurf( theSetOfSurfels );
175 trace.
info() <<
"Digital surface has " << digSurf.size() <<
" surfels."
184 CellEmbedder cellEmbedder;
185 cellEmbedder.
init( K, ishape, dshape.pointEmbedder() );
186 ofstream out(
"marching-cube.off" );
188 digSurf.exportEmbeddedSurfaceAs3DOFF( out, cellEmbedder );
193 ofstream out2(
"marching-cube.noff" );
195 digSurf.exportEmbeddedSurfaceAs3DNOFF( out2, cellEmbedder );