52 #define CONTOUR_QUANT 50
89 this_contour.
resize (2, 0);
96 double lvl,
int r,
int c,
double ct_x,
double ct_y,
99 double px[4], py[4], pz[4], tmp;
100 unsigned int stop_edge, pt[2];
103 while (r >= 0 && c >= 0 && r < mark.
rows () && c < mark.
cols ()
108 px[0] = px[3] = X(c);
109 px[1] = px[2] = X(c+1);
111 py[0] = py[1] = Y(r);
112 py[2] = py[3] = Y(r+1);
114 pz[3] =
Z(r+1, c) - lvl;
115 pz[2] =
Z(r+1, c + 1) - lvl;
116 pz[1] =
Z(r, c+1) - lvl;
117 pz[0] =
Z(r, c) - lvl;
128 char id =
static_cast<char> (
mark(r, c));
131 if (start_edge == 255)
134 for (
unsigned int k = 0; k < 4; k++)
135 if (static_cast<char> (1 << k) & id)
139 if (start_edge == 255)
143 mark(r, c) -=
static_cast<char> (1 << start_edge);
147 pt[1] = (pt[0] + 1) % 4;
152 tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]);
158 ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp);
159 ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp);
168 for (
unsigned int k = 1; k <= 4; k++)
170 if (start_edge == 0 || start_edge == 2)
171 stop_edge = (start_edge + k) % 4;
173 stop_edge = (start_edge - k) % 4;
175 if (static_cast<char> (1 << stop_edge) & id)
180 pt[1] = (pt[0] + 1) % 4;
181 tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]);
187 ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp);
188 ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp);
195 mark(r, c) -=
static_cast<char> (1 << stop_edge);
200 else if (stop_edge == 1)
202 else if (stop_edge == 2)
204 else if (stop_edge == 3)
208 start_edge = (stop_edge + 2) % 4;
216 unsigned int nr = mark.
rows ();
217 unsigned int nc = mark.
cols ();
221 for (
unsigned int c = 0; c < nc; c++)
222 for (
unsigned int r = 0; r < nr; r++)
224 f[0] =
Z(r, c) - lvl;
225 f[1] =
Z(r, c+1) - lvl;
226 f[3] =
Z(r+1, c) - lvl;
227 f[2] =
Z(r+1, c+1) - lvl;
229 for (
unsigned int i = 0; i < 4; i++)
230 if (fabs(f[i]) < std::numeric_limits<double>::epsilon ())
231 f[i] = std::numeric_limits<double>::epsilon ();
240 for (
unsigned int r = 0; r < nr; r++)
241 for (
unsigned int c = 0; c < nc; c++)
243 f[0] =
Z(r, c) - lvl;
244 f[1] =
Z(r, c+1) - lvl;
245 f[3] =
Z(r+1, c) - lvl;
246 f[2] =
Z(r+1, c+1) - lvl;
248 for (
unsigned int i = 0; i < 4; i++)
249 if (fabs(f[i]) < std::numeric_limits<double>::epsilon ())
250 f[i] = std::numeric_limits<double>::epsilon ();
263 unsigned int nr = Z.
rows ();
264 unsigned int nc = Z.
cols ();
272 for (
unsigned int c = 0; c < nc - 1; c++)
276 drawcn (X, Y, Z, lvl, 0, c, 0.0, 0.0, 0,
true, mark);
279 if (
mark(nr - 2, c) & 4)
280 drawcn (X, Y, Z, lvl, nr - 2, c, 0.0, 0.0, 2,
true, mark);
283 for (
unsigned int r = 0; r < nr - 1; r++)
287 drawcn (X, Y, Z, lvl, r, 0, 0.0, 0.0, 3,
true, mark);
290 if (
mark(r, nc - 2) & 2)
291 drawcn (X, Y, Z, lvl, r, nc - 2, 0.0, 0.0, 1,
true, mark);
294 for (
unsigned int r = 0; r < nr - 1; r++)
295 for (
unsigned int c = 0; c < nc - 1; c++)
297 drawcn (X, Y, Z, lvl, r, c, 0.0, 0.0, 255,
true, mark);
300 DEFUN (__contourc__, args, ,
302 @deftypefn {Built-in Function} {} __contourc__ (@var{x}, @var{y}, @var{z}, @var{levels})\n\
303 Undocumented internal function.\n\
308 if (args.length () == 4)
310 RowVector X = args(0).row_vector_value ();
311 RowVector Y = args(1).row_vector_value ();
312 Matrix Z = args(2).matrix_value ();
313 RowVector L = args(3).row_vector_value ();
319 for (
int i = 0; i < L.
length (); i++)
320 cntr (X, Y, Z, L (i));
327 error (
"__contourc__: invalid argument values");
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
static Matrix this_contour
OCTINTERP_API void print_usage(void)
Matrix extract_n(octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
F77_RET_T const octave_idx_type const octave_idx_type const octave_idx_type double const octave_idx_type double const octave_idx_type double const octave_idx_type double * Z
octave_idx_type rows(void) const
static void start_contour(double lvl, double x, double y)
F77_RET_T const double const double * f
static void cntr(const RowVector &X, const RowVector &Y, const Matrix &Z, double lvl)
static void drawcn(const RowVector &X, const RowVector &Y, const Matrix &Z, double lvl, int r, int c, double ct_x, double ct_y, unsigned int start_edge, bool first, charMatrix &mark)
static void end_contour(void)
static void mark_facets(const Matrix &Z, charMatrix &mark, double lvl)
octave_idx_type length(void) const
Number of elements in the array.
static void add_point(double x, double y)
octave_idx_type cols(void) const
F77_RET_T const double * x
Matrix append(const Matrix &a) const