Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
testPolynomial.cpp
Go to the documentation of this file.
1
16
28
30
31
32#include <iostream>
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"
42#include "DGtal/topology/SCellsFunctors.h"
43#include "DGtal/topology/helpers/BoundaryPredicate.h"
44#include "DGtal/topology/SetOfSurfels.h"
45#include "DGtal/io/viewers/PolyscopeViewer.h"
46#include "DGtal/io/colormaps/GradientColorMap.h"
47#include <boost/math/special_functions/fpclassify.hpp>
48
50
51using namespace std;
52using namespace DGtal;
53using namespace Z3i;
54
56
57
58void usage( int /*argc*/, char** argv )
59{
60 std::cerr << "Usage: " << argv[ 0 ] << " <Polynomial> <Px> <Py> <Pz> <Qx> <Qy> <Qz> <step>" << std::endl;
61 std::cerr << "\t - displays the boundary of a shape defined implicitly by a 3-polynomial <Polynomial>." << std::endl;
62 std::cerr << "\t - P and Q defines the bounding box." << std::endl;
63 std::cerr << "\t - step is the grid step." << std::endl;
64 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;
65 std::cerr << "\t - See http://www.freigeist.cc/gallery.html" << std::endl;
66}
67
75
76
77
78int main( int argc, char** argv )
79{
80 if ( argc < 9 )
81 {
82 usage( argc, argv );
83 return 1;
84 }
85 double p1[ 3 ];
86 double p2[ 3 ];
87 for ( unsigned int i = 0; i < 3; ++i )
88 {
89 p1[ i ] = atof( argv[ 2 + i ] );
90 p2[ i ] = atof( argv[ 5 + i ] );
91 }
92 double step = atof( argv[ 8 ] );
93
94
96 Polynomial3Reader reader;
97 std::string poly_str = argv[ 1 ];
98 std::string::const_iterator iter
99 = reader.read( P, poly_str.begin(), poly_str.end() );
100 if ( iter != poly_str.end() )
101 {
102 std::cerr << "ERROR: I read only <"
103 << poly_str.substr( 0, iter - poly_str.begin() )
104 << ">, and I built P=" << P << std::endl;
105 return 1;
106 }
107
108
109 ImplicitShape ishape( P );
110 DigitalShape dshape;
111 dshape.attach( ishape );
112 dshape.init( RealPointT( p1 ), RealPointT( p2 ), step );
113 Domain domain = dshape.getDomain();
114
115
116 KSpace K;
117
118 bool space_ok = K.init( domain.lowerBound(),
119 domain.upperBound(), true
120 );
121 if ( !space_ok )
122 {
123 trace.error() << "Error in the Khamisky space construction." << std::endl;
124 return 2;
125 }
126
127 typedef SurfelAdjacency< KSpace::dimension > MySurfelAdjacency;
128 MySurfelAdjacency surfAdj( true ); // interior in all directions.
129
130
131 typedef KSpace::Surfel Surfel;
133 typedef SetOfSurfels< KSpace, SurfelSet > MySetOfSurfels;
134
135 MySetOfSurfels theSetOfSurfels( K, surfAdj );
136 Surfel bel = Surfaces< KSpace >::findABel( K, dshape, 100000 );
137 Surfaces< KSpace >::trackBoundary( theSetOfSurfels.surfelSet(),
138 K, surfAdj,
139 dshape, bel );
140
141
142
143
144 PolyscopeViewer<> viewer;
145 viewer.allowReuseList = true;
146 viewer << domain;
147
148 //-----------------------------------------------------------------------
149 // Looking for the min and max values
150
151 double minCurv = 1;
152 double maxCurv = 0;
154 for ( std::set< SCell >::iterator it = theSetOfSurfels.begin(), it_end = theSetOfSurfels.end();
155 it != it_end; ++it)
156 {
157
158 RealPointT A = midpoint( *it ) * step;
159 A = ishape.nearestPoint (A,0.01,200,0.1*step);
160 double a = ishape.meanCurvature( A );
161// double a=ishape.gaussianCurvature(A);
162 if ( !boost::math::isnan( a ))
163 {
164
165 if ( a > maxCurv )
166 {
167 maxCurv = a;
168 }
169 else
170 if ( a < minCurv )
171 {
172 minCurv = a;
173 }
174 }
175 }
176 trace.info() << " Min = " << minCurv << std::endl;
177 trace.info() << " Max = " << maxCurv << std::endl;
178
179 //------------------------------------------------------------------------------------
180 //drawing
181 unsigned int nbSurfels = 0;
182
183 for ( std::set<SCell>::iterator it = theSetOfSurfels.begin(),
184 it_end = theSetOfSurfels.end();
185 it != it_end; ++it, ++nbSurfels )
186 {
187
188
189 RealPointT A = midpoint( *it ) * step;
190 A = ishape.nearestPoint (A,0.01,200,0.1*step);
191// double a=ishape.gaussianCurvature(A);
192 double a = ishape.meanCurvature( A );
193 if ( boost::math::isnan( a ))
194 {
195 a = 0;
196 }
197
198 viewer << WithQuantity(*it, "Mean curvature", a);
199 }
200
201 viewer.show();
202
203 return 0;
204}
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
RegularPointEmbedder< Space > PointEmbedder
void attach(ConstAlias< EuclideanShape > shape)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Domain getDomain() const
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
double meanCurvature(const RealPoint &aPoint) const
RealPoint nearestPoint(const RealPoint &aPoint, const double accuracy=0.0001, const int maxIter=20, const double gamma=0.5) const
Aim: This class converts a string polynomial expression in a multivariate polynomial.
Iterator read(Polynomial &p, Iterator begin, Iterator end)
Aim: Represents a multivariate polynomial, i.e. an element of , where K is some ring or field.
void show() override
Starts the event loop and display of elements.
PointVector< dim, double > RealPoint
Definition SpaceND.h:117
static void trackBoundary(SCellSet &surface, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
MyDigitalSurface::SurfelSet SurfelSet
Z3i this namespace gathers the standard of types for 3D imagery.
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
Attach a property to an element.
Definition Display3D.h:327
int main()
Definition testBits.cpp:56
KSpace K
RealPointT::Coordinate Ring
MPolynomialReader< 3, Ring > Polynomial3Reader
GaussDigitizer< Space, ImplicitShape > DigitalShape
Space::RealPoint RealPointT
ImplicitPolynomial3Shape< Space > ImplicitShape
MPolynomial< 3, Ring > Polynomial3
DigitalShape::PointEmbedder DigitalEmbedder
Domain domain