40 #if defined (HAVE_CONFIG_H)
57 #define CONTOUR_QUANT 50
99 double lvl,
int r,
int c,
double ct_x,
double ct_y,
100 unsigned int start_edge,
bool first,
charMatrix& mark)
102 double px[4], py[4], pz[4], tmp;
103 unsigned int stop_edge, pt[2];
106 while (
r >= 0 && c >= 0 &&
r < mark.
rows () && c < mark.
cols ()
111 px[0] = px[3] = X(c);
112 px[1] = px[2] = X(c+1);
114 py[0] = py[1] = Y(
r);
115 py[2] = py[3] = Y(
r+1);
117 pz[3] =
Z(
r+1, c) - lvl;
118 pz[2] =
Z(
r+1, c + 1) - lvl;
119 pz[1] =
Z(
r, c+1) - lvl;
120 pz[0] =
Z(
r, c) - lvl;
131 char id =
static_cast<char> (mark(
r, c));
134 if (start_edge == 255)
137 for (
unsigned int k = 0; k < 4; k++)
138 if (
static_cast<char> (1 << k) & id)
142 if (start_edge == 255)
146 mark(
r, c) -=
static_cast<char> (1 << start_edge);
150 pt[1] = (pt[0] + 1) % 4;
155 tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]);
161 ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp);
162 ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp);
171 for (
unsigned int k = 1; k <= 4; k++)
173 if (start_edge == 0 || start_edge == 2)
174 stop_edge = (start_edge + k) % 4;
176 stop_edge = (start_edge - k) % 4;
178 if (
static_cast<char> (1 << stop_edge) & id)
183 pt[1] = (pt[0] + 1) % 4;
184 tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]);
190 ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp);
191 ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp);
198 mark(
r, c) -=
static_cast<char> (1 << stop_edge);
203 else if (stop_edge == 1)
205 else if (stop_edge == 2)
207 else if (stop_edge == 3)
211 start_edge = (stop_edge + 2) % 4;
219 unsigned int nr = mark.
rows ();
220 unsigned int nc = mark.
cols ();
224 for (
unsigned int c = 0; c < nc; c++)
225 for (
unsigned int r = 0;
r < nr;
r++)
227 f[0] =
Z(
r, c) - lvl;
228 f[1] =
Z(
r, c+1) - lvl;
229 f[3] =
Z(
r+1, c) - lvl;
230 f[2] =
Z(
r+1, c+1) - lvl;
232 for (
unsigned int i = 0; i < 4; i++)
233 if (fabs(
f[i]) < std::numeric_limits<double>::epsilon ())
234 f[i] = std::numeric_limits<double>::epsilon ();
243 for (
unsigned int r = 0;
r < nr;
r++)
244 for (
unsigned int c = 0; c < nc; c++)
246 f[0] =
Z(
r, c) - lvl;
247 f[1] =
Z(
r, c+1) - lvl;
248 f[3] =
Z(
r+1, c) - lvl;
249 f[2] =
Z(
r+1, c+1) - lvl;
251 for (
unsigned int i = 0; i < 4; i++)
252 if (fabs(
f[i]) < std::numeric_limits<double>::epsilon ())
253 f[i] = std::numeric_limits<double>::epsilon ();
266 unsigned int nr =
Z.rows ();
267 unsigned int nc =
Z.cols ();
275 for (
unsigned int c = 0; c < nc - 1; c++)
279 drawcn (X, Y,
Z, lvl, 0, c, 0.0, 0.0, 0,
true, mark);
282 if (mark(nr - 2, c) & 4)
283 drawcn (X, Y,
Z, lvl, nr - 2, c, 0.0, 0.0, 2,
true, mark);
286 for (
unsigned int r = 0;
r < nr - 1;
r++)
290 drawcn (X, Y,
Z, lvl,
r, 0, 0.0, 0.0, 3,
true, mark);
293 if (mark(
r, nc - 2) & 2)
294 drawcn (X, Y,
Z, lvl,
r, nc - 2, 0.0, 0.0, 1,
true, mark);
297 for (
unsigned int r = 0;
r < nr - 1;
r++)
298 for (
unsigned int c = 0; c < nc - 1; c++)
300 drawcn (X, Y,
Z, lvl,
r, c, 0.0, 0.0, 255,
true, mark);
304 DEFUN (__contourc__, args, ,
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 ();
317 for (
int i = 0; i < L.
numel (); i++)
318 cntr (X, Y,
Z, L(i));
static void mark_facets(const Matrix &Z, charMatrix &mark, 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 cntr(const RowVector &X, const RowVector &Y, const Matrix &Z, double lvl)
static void add_point(double x, double y)
static Matrix this_contour
static void start_contour(double lvl, double x, double y)
static void end_contour(void)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type cols(void) const
OCTAVE_API Matrix append(const Matrix &a) const
OCTAVE_API Matrix extract_n(octave_idx_type r1, octave_idx_type c1, octave_idx_type nr, octave_idx_type nc) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Z
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))