57 static const std::string& s_class() {
58 static const std::string s_v(
"tools::ccontour");
64 virtual void ExportLine(
int iPlane,
int x1,
int y1,
int x2,
int y2) = 0;
71 mem::decrement(s_class().c_str());
101 void set_planes(
const std::vector<double>& vPlanes);
104 void set_field_fcn(
double (*_pFieldFcn)(
double,
double,
void*),
void*);
113 double get_yi(
int i)
const;
137 static const std::string& s_class() {
138 static const std::string s_v(
"tools::ccontour::CFnStr");
143 CFnStr():m_dFnVal(0),m_sLeftLen(0),m_sRightLen(0),m_sTopLen(0),m_sBotLen(0){
145 mem::increment(s_class().c_str());
150 mem::decrement(s_class().c_str());
154 CFnStr(
const CFnStr&){}
155 CFnStr& operator=(
const CFnStr&){
return *
this;}
185 double Field(
int x,
int y);
186 void Cntr1(
int x1,
int x2,
int y1,
int y2);
187 void Pass2(
int x1,
int x2,
int y1,
int y2);
192 static double ContourTestFunction(
double x,
double y,
void*) {
193 return 0.5*(::cos(x+3.14/4)+::sin(y+3.14/4));
197 static void _ASSERT_(
bool a_what,
const char* a_where) {
199 ::printf(
"debug : Contour : assert failure in %s\n",a_where);
204 static void _ASSERTP_(
void* a_what,
const char* a_where) {
206 ::printf(
"debug : Contour : assert failure in %s\n",a_where);
228 mem::increment(s_class().c_str());
242 for (
unsigned int i=0;i<
m_vPlanes.size();i++)
281 int x3, x4, y3, y4, x, y, oldx3, xlow;
298 for (x = oldx3; x <= x4; x++)
306 for (y = 0; y < rows; y++)
315 Cntr1(oldx3, x3, y3, y4);
325 Cntr1(x3, x4, y3, y4);
333 Pass2(oldx3,x3,y3,y4);
341 for (x = x3+1; x <= x4; x++)
354 for (y = 0; y < rows; y++)
371 double f11, f12, f21, f22, f33;
374 if ((x1 == x2) || (y1 == y2))
380 if ((x2 > x1+1) || (y2 > y1+1)) {
385 if (f33 < f11) i++;
else if (f33 > f11) j++;
386 if (f33 < f12) i++;
else if (f33 > f12) j++;
387 if (f33 < f21) i++;
else if (f33 > f21) j++;
388 if (f33 < f22) i++;
else if (f33 > f22) j++;
389 if ((i > 2) || (j > 2))
392 Cntr1(x1, x3, y1, y3);
393 Cntr1(x3, x2, y1, y3);
394 Cntr1(x1, x3, y3, y2);
395 Cntr1(x3, x2, y3, y2);
406 int left = 0,
right = 0,
top = 0, bot = 0,old, iNew, i, j, x3, y3;
407 double yy0 = 0, yy1 = 0, xx0 = 0, xx1 = 0, xx3, yy3;
408 double v, f11, f12, f21, f22, f33, fold, fnew, f;
412 if ((x1 == x2) || (y1 == y2))
418 if ((x2 > x1+1) || (y2 > y1+1))
424 if (f33 < f11) i++;
else if (f33 > f11) j++;
425 if (f33 < f12) i++;
else if (f33 > f12) j++;
426 if (f33 < f21) i++;
else if (f33 > f21) j++;
427 if (f33 < f22) i++;
else if (f33 > f22) j++;
428 if ((i > 2) || (j > 2))
431 Pass2(x1, x3, y1, y3);
432 Pass2(x3, x2, y1, y3);
433 Pass2(x1, x3, y3, y2);
434 Pass2(x3, x2, y3, y2);
439 for (i = 0; i < (int)
m_vPlanes.size(); i++)
446 if (f12 > v) j |= 010;
447 if ((f11 > v) ^ (f12 > v))
449 if ((
FnctData(x1,y1)->m_sLeftLen != 0) &&
456 iNew = old+
FnctData(x1,old)->m_sLeftLen;
458 if ((fnew > v) ^ (fold > v))
463 yy0 = ((old-y1)+(iNew-old)*(v-fold)/(fnew-fold))/(y2-y1);
466 yy0 = (v-f11)/(f12-f11);
468 left = (int)(y1+(y2-y1)*yy0+0.5);
470 if ((f21 > v) ^ (f22 > v))
472 if ((
FnctData(x2,y1)->m_sRightLen != 0) &&
479 iNew = old+
FnctData(x2,old)->m_sRightLen;
481 if ((fnew > v) ^ (fold > v))
486 yy1 = ((old-y1)+(iNew-old)*(v-fold)/(fnew-fold))/(y2-y1);
489 yy1 = (v-f21)/(f22-f21);
491 right = (int)(y1+(y2-y1)*yy1+0.5);
493 if ((f21 > v) ^ (f11 > v))
495 if ((
FnctData(x1,y1)->m_sBotLen != 0) &&
500 iNew = old+
FnctData(old,y1)->m_sBotLen;
502 if ((fnew > v) ^ (fold > v))
507 xx0 = ((old-x1)+(iNew-old)*(v-fold)/(fnew-fold))/(x2-x1);
510 xx0 = (v-f11)/(f21-f11);
512 bot = (int)(x1+(x2-x1)*xx0+0.5);
514 if ((f22 > v) ^ (f12 > v))
516 if ((
FnctData(x1,y2)->m_sTopLen != 0) &&
521 iNew = old+
FnctData(old,y2)->m_sTopLen;
523 if ((fnew > v) ^ (fold > v))
528 xx1 = ((old-x1)+(iNew-old)*(v-fold)/(fnew-fold))/(x2-x1);
531 xx1 = (v-f12)/(f22-f12);
533 top = (int)(x1+(x2-x1)*xx1+0.5);
567 yy3 = (xx0*(yy1-yy0)+yy0)/(1.0-(xx1-xx0)*(yy1-yy0));
568 xx3 = yy3*(xx1-xx0)+xx0;
569 xx3 = x1+xx3*(x2-x1);
570 yy3 = y1+yy3*(y2-y1);
571 xx3 = xoff+xx3*
m_dDx;
572 yy3 = yoff+yy3*
m_dDy;
578 if (((f > v) && (f22 > v)) || ((f < v) && (f22 < v))) {
637 _ASSERT_(pLimits[0]<pLimits[1],
"ccontour::set_limits");
638 _ASSERT_(pLimits[2]<pLimits[3],
"ccontour::set_limits");
639 for (
int i=0;i<4;i++)
647 for (
int i=0;i<4;i++)
661 if(i<0) ::printf(
"ccontour::get_yi : %d\n",i);