Go to the source code of this file.
◆ ExpSimplifyUsage()
void ExpSimplifyUsage |
( |
void |
| ) |
|
Definition at line 6 of file ExpSimplify.cpp.
7 _printf_(
"ExpSimplify - Simplify Exp contour\n");
9 _printf_(
" Recursive Douglas-Peucker Polygon Simplification\n");
12 _printf_(
" ExpSimplify(expfile,tol);\n");
13 _printf_(
" - expfile: name of the exp file\n");
14 _printf_(
" - tol: tolerance (maximal euclidean distance allowed between the new line and a vertex)\n");
16 _printf_(
" - 'min': minimum number of vertices to save contours in exp file (default is 3)\n");
19 _printf_(
" ExpSimplify('file.exp',100);\n");
20 _printf_(
" ExpSimplify('file.exp',100,'min',4);\n");
◆ simplify()
void simplify |
( |
Contour< double > * |
contour, |
|
|
bool * |
flags, |
|
|
int |
ind0, |
|
|
int |
ind1, |
|
|
double |
tolerance |
|
) |
| |
Definition at line 22 of file ExpSimplify.cpp.
25 double distance,beta,dx,dy;
28 double *x = contour->
x;
29 double *y = contour->
y;
32 _assert_(ind0>=0 && ind0<contour->nods);
33 _assert_(ind1>=0 && ind1<contour->nods);
37 if(x[ind0]==x[ind1] && y[ind0]==y[ind1]) closed=
true;
42 for(
int i=ind0;i<ind1-1;i++){
43 distance = sqrt((x[ind0]-x[i+1])*(x[ind0]-x[i+1]) + (y[ind0]-y[i+1])*(y[ind0]-y[i+1]));
44 if(i==ind0 || distance>maxdistance){
60 for(
int i=ind0+1;i<=ind1;i++){
61 beta = ((x[i]-x[ind0])*(x[ind1]-x[ind0]) + (y[i]-y[ind0])*(y[ind1]-y[ind0]))/((x[ind1]-x[ind0])*(x[ind1]-x[ind0])+(y[ind1]-y[ind0])*(y[ind1]-y[ind0]));
62 dx = x[i]-beta*x[ind1]+(beta-1.)*x[ind0];
63 dy = y[i]-beta*y[ind1]+(beta-1.)*y[ind0];
64 distance = sqrt(dx*dx + dy*dy);
65 if(i==ind0+1 || distance>maxdistance){
66 maxdistance = distance;
74 if(maxdistance<tolerance){
76 for(
int i=ind0+1;i<ind1;i++) flags[i]=
false;
85 simplify(contour,flags,ind0 ,index,tolerance);
86 simplify(contour,flags,index,ind1, tolerance);
◆ WRAPPER()
WRAPPER |
( |
ExpSimplify_python |
| ) |
|
Definition at line 90 of file ExpSimplify.cpp.
98 double minimumvertices_double;
110 if (nrhs<NRHS || nlhs>
NLHS){
120 if(tolerance<0)
_error_(
"tolerance must be a positivve scalar");
132 options->
Get(&minimumvertices_double,
"min",3.);
133 if(minimumvertices_double<1.)
_error_(
"'min' (minimum number of verties) should be a positive integer");
134 minimumvertices = int(minimumvertices_double);
137 oldcontours=ExpRead<double>(expfile);
139 for(
int counter=0;counter<oldcontours->
Size();counter++){
143 nods = contour->
nods;
146 _printf_(
" Initial number of vertices in contour #"<<counter+1<<
": "<<nods <<
"\n");
149 if(nods>0) flags = xNew<bool>(nods);
160 distance = sqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]));
161 if(distance<=tolerance){
174 for(
int i=0;i<nods;i++) flags[i]=
true;
175 simplify(contour,flags,0,nods-1,tolerance);
180 for(
int i=0;i<nods;i++)
if(flags[i]) newnods++;
183 if(newnods>=minimumvertices){
184 _printf_(
" Final number of vertices in contour #"<<counter+1<<
": "<<newnods <<
"\n");
186 newcontour->
nods = newnods;
187 newcontour->
x = xNew<double>(newnods);
188 newcontour->
y = xNew<double>(newnods);
190 for(
int i=0;i<nods;i++){
192 newcontour->
x[newnods] = contour->
x[i];
193 newcontour->
y[newnods] = contour->
y[i];
203 _printf_(
" Final number of vertices in contour #"<<counter+1<<
": "<<newnods<<
" (not saved)\n");
207 xDelete<bool>(flags);
209 _printf_(
" Initial number of contours: "<<oldcontours->
Size() <<
"\n");
210 _printf_(
" Final number of contours: "<<newcontours->
Size() <<
"\n");
216 xDelete<char>(expfile);