Mercurial > hg > octave-lyh
view libinterp/corefcn/__contourc__.cc @ 17289:bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Macro handles options ("on") or properties ("position") more elegantly
than @code{"text"}.
* doc/interpreter/macros.texi: Add new @qcode macro.
* doc/interpreter/tips.txi: Add documentation about @qcode macro.
* doc/interpreter/basics.txi, doc/interpreter/container.txi,
doc/interpreter/emacs.txi, doc/interpreter/errors.txi,
doc/interpreter/eval.txi, doc/interpreter/expr.txi,
doc/interpreter/external.txi, doc/interpreter/func.txi,
doc/interpreter/grammar.txi, doc/interpreter/image.txi,
doc/interpreter/install.txi, doc/interpreter/interp.txi,
doc/interpreter/io.txi, doc/interpreter/matrix.txi,
doc/interpreter/numbers.txi, doc/interpreter/oop.txi,
doc/interpreter/package.txi, doc/interpreter/plot.txi,
doc/interpreter/quad.txi, doc/interpreter/sparse.txi,
doc/interpreter/strings.txi, doc/interpreter/system.txi,
doc/interpreter/vectorize.txi, libinterp/corefcn/balance.cc,
libinterp/corefcn/bitfcns.cc, libinterp/corefcn/cellfun.cc,
libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc,
libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc,
libinterp/corefcn/dirfns.cc, libinterp/corefcn/dlmread.cc,
libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc,
libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lu.cc,
libinterp/corefcn/luinc.cc, libinterp/corefcn/matrix_type.cc,
libinterp/corefcn/oct-hist.cc, libinterp/corefcn/pager.cc,
libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc,
libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc,
libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc,
libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc,
libinterp/corefcn/svd.cc, libinterp/corefcn/symtab.cc,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/toplev.cc,
libinterp/corefcn/tril.cc, libinterp/corefcn/typecast.cc,
libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/chol.cc,
libinterp/dldfcn/colamd.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc,
libinterp/dldfcn/symbfact.cc, libinterp/octave-value/ov-base.cc,
libinterp/octave-value/ov-fcn-handle.cc,
libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc,
libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-usr-fcn.cc, libinterp/parse-tree/oct-parse.in.yy,
libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-eval.cc,
libinterp/parse-tree/pt-mat.cc, scripts/@ftp/ftp.m,
scripts/deprecated/java_convert_matrix.m, scripts/deprecated/java_debug.m,
scripts/deprecated/java_unsigned_conversion.m, scripts/deprecated/shell_cmd.m,
scripts/general/dblquad.m, scripts/general/display.m,
scripts/general/genvarname.m, scripts/general/idivide.m,
scripts/general/interp1.m, scripts/general/interp2.m,
scripts/general/interp3.m, scripts/general/interpn.m, scripts/general/isa.m,
scripts/general/profexplore.m, scripts/general/profile.m,
scripts/general/quadgk.m, scripts/general/randi.m, scripts/general/structfun.m,
scripts/general/subsindex.m, scripts/general/triplequad.m,
scripts/geometry/griddata.m, scripts/geometry/griddata3.m,
scripts/geometry/griddatan.m, scripts/geometry/voronoi.m, scripts/help/help.m,
scripts/help/lookfor.m, scripts/image/cmpermute.m, scripts/image/colormap.m,
scripts/image/image.m, scripts/image/imagesc.m, scripts/image/imfinfo.m,
scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imshow.m,
scripts/image/imwrite.m, scripts/image/ind2gray.m, scripts/image/lines.m,
scripts/image/rgb2ind.m, scripts/image/spinmap.m, scripts/io/dlmwrite.m,
scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m,
scripts/java/javaclasspath.m, scripts/java/usejava.m,
scripts/miscellaneous/bzip2.m, scripts/miscellaneous/computer.m,
scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m,
scripts/miscellaneous/dos.m, scripts/miscellaneous/edit.m,
scripts/miscellaneous/gzip.m, scripts/miscellaneous/license.m,
scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m,
scripts/miscellaneous/parseparams.m, scripts/miscellaneous/unix.m,
scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m,
scripts/optimization/fminunc.m, scripts/optimization/fsolve.m,
scripts/optimization/fzero.m, scripts/optimization/glpk.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/optimset.m,
scripts/optimization/pqpnonneg.m, scripts/pkg/pkg.m, scripts/plot/allchild.m,
scripts/plot/ancestor.m, scripts/plot/area.m, scripts/plot/axis.m,
scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/box.m,
scripts/plot/caxis.m, scripts/plot/cla.m, scripts/plot/clabel.m,
scripts/plot/clf.m, scripts/plot/close.m, scripts/plot/colorbar.m,
scripts/plot/daspect.m, scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m,
scripts/plot/ezsurf.m, scripts/plot/ezsurfc.m, scripts/plot/findall.m,
scripts/plot/findobj.m, scripts/plot/gcbo.m, scripts/plot/gcf.m,
scripts/plot/gco.m, scripts/plot/grid.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/hidden.m, scripts/plot/hold.m,
scripts/plot/isonormals.m, scripts/plot/isosurface.m, scripts/plot/legend.m,
scripts/plot/mesh.m, scripts/plot/meshc.m, scripts/plot/meshz.m,
scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m,
scripts/plot/patch.m, scripts/plot/pbaspect.m, scripts/plot/pcolor.m,
scripts/plot/plot.m, scripts/plot/print.m,
scripts/plot/private/__add_default_menu__.m, scripts/plot/quiver.m,
scripts/plot/quiver3.m, scripts/plot/refreshdata.m, scripts/plot/saveas.m,
scripts/plot/scatter.m, scripts/plot/scatter3.m, scripts/plot/shading.m,
scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/stem.m,
scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/surf.m, scripts/plot/surfc.m, scripts/plot/surfl.m,
scripts/plot/tetramesh.m, scripts/plot/uigetfile.m, scripts/plot/uimenu.m,
scripts/plot/uiputfile.m, scripts/plot/waterfall.m, scripts/plot/whitebg.m,
scripts/plot/xlim.m, scripts/plot/ylim.m, scripts/plot/zlim.m,
scripts/polynomial/conv.m, scripts/polynomial/polyout.m,
scripts/polynomial/splinefit.m, scripts/set/ismember.m, scripts/set/powerset.m,
scripts/set/setdiff.m, scripts/set/union.m, scripts/set/unique.m,
scripts/signal/detrend.m, scripts/signal/filter2.m, scripts/signal/freqz.m,
scripts/signal/periodogram.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/sparse/eigs.m, scripts/sparse/svds.m,
scripts/specfun/legendre.m, scripts/special-matrix/gallery.m,
scripts/statistics/base/mean.m, scripts/statistics/base/moment.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/sign_test.m,
scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m, scripts/strings/base2dec.m,
scripts/strings/index.m, scripts/strings/isstrprop.m,
scripts/strings/mat2str.m, scripts/strings/regexptranslate.m,
scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m,
scripts/strings/strjust.m, scripts/strings/strmatch.m,
scripts/strings/validatestring.m, scripts/testfun/demo.m,
scripts/testfun/example.m, scripts/testfun/test.m, scripts/time/addtodate.m,
scripts/time/asctime.m, scripts/time/datestr.m, scripts/time/datetick.m,
scripts/time/weekday.m, scripts/ui/errordlg.m, scripts/ui/helpdlg.m,
scripts/ui/inputdlg.m, scripts/ui/listdlg.m, scripts/ui/msgbox.m,
scripts/ui/questdlg.m, scripts/ui/warndlg.m: Use new @qcode macro.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 19 Aug 2013 20:46:38 -0700 |
parents | 704e15f8fecd |
children |
line wrap: on
line source
/* Contour lines for function evaluated on a grid. Copyright (C) 2007-2012 Kai Habel Copyright (C) 2004, 2007 Shai Ayal Adapted to an oct file from the stand alone contourl by Victro Munoz Copyright (C) 2004 Victor Munoz Based on contour plot routine (plcont.c) in PLPlot package http://plplot.org/ Copyright (C) 1995, 2000, 2001 Maurice LeBrun Copyright (C) 2000, 2002 Joao Cardoso Copyright (C) 2000, 2001, 2002, 2004 Alan W. Irwin Copyright (C) 2004 Andrew Ross This file is part of Octave. Octave is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. Octave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Octave; see the file COPYING. If not, see <http://www.gnu.org/licenses/>. */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <cfloat> #include "quit.h" #include "defun.h" #include "error.h" #include "oct-obj.h" static Matrix this_contour; static Matrix contourc; static int elem; // This is the quanta in which we increase this_contour. #define CONTOUR_QUANT 50 // Add a coordinate point (x,y) to this_contour. static void add_point (double x, double y) { if (elem % CONTOUR_QUANT == 0) this_contour = this_contour.append (Matrix (2, CONTOUR_QUANT, 0)); this_contour (0, elem) = x; this_contour (1, elem) = y; elem++; } // Add contents of current contour to contourc. // this_contour.cols () - 1; static void end_contour (void) { if (elem > 2) { this_contour (1, 0) = elem - 1; contourc = contourc.append (this_contour.extract_n (0, 0, 2, elem)); } this_contour = Matrix (); elem = 0; } // Start a new contour, and add contents of current one to contourc. static void start_contour (double lvl, double x, double y) { end_contour (); this_contour.resize (2, 0); add_point (lvl, 0); add_point (x, y); } 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) { double px[4], py[4], pz[4], tmp; unsigned int stop_edge, pt[2]; // Continue while next facet is not done yet. while (r >= 0 && c >= 0 && r < mark.rows () && c < mark.cols () && mark(r, c) > 0) { //get x, y, and z - lvl for current facet px[0] = px[3] = X(c); px[1] = px[2] = X(c+1); py[0] = py[1] = Y(r); py[2] = py[3] = Y(r+1); pz[3] = Z(r+1, c) - lvl; pz[2] = Z(r+1, c + 1) - lvl; pz[1] = Z(r, c+1) - lvl; pz[0] = Z(r, c) - lvl; // Facet edge and point naming assignment. // // 0-----1 .-0-. // | | | | // | | 3 1 // | | | | // 3-----2 .-2-. // Get mark value of current facet. char id = static_cast<char> (mark(r, c)); // Check startedge s. if (start_edge == 255) { // Find start edge. for (unsigned int k = 0; k < 4; k++) if (static_cast<char> (1 << k) & id) start_edge = k; } if (start_edge == 255) break; // Decrease mark value of current facet for start edge. mark(r, c) -= static_cast<char> (1 << start_edge); // Next point (clockwise). pt[0] = start_edge; pt[1] = (pt[0] + 1) % 4; // Calculate contour segment start if first of contour. if (first) { tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]); if (xisnan (tmp)) ct_x = ct_y = 0.5; else { ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp); ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp); } start_contour (lvl, ct_x, ct_y); first = false; } // Find stop edge. // FIXME -- perhaps this should use a while loop? for (unsigned int k = 1; k <= 4; k++) { if (start_edge == 0 || start_edge == 2) stop_edge = (start_edge + k) % 4; else stop_edge = (start_edge - k) % 4; if (static_cast<char> (1 << stop_edge) & id) break; } pt[0] = stop_edge; pt[1] = (pt[0] + 1) % 4; tmp = fabs (pz[pt[1]]) / fabs (pz[pt[0]]); if (xisnan (tmp)) ct_x = ct_y = 0.5; else { ct_x = px[pt[0]] + (px[pt[1]] - px[pt[0]])/(1 + tmp); ct_y = py[pt[0]] + (py[pt[1]] - py[pt[0]])/(1 + tmp); } // Add point to contour. add_point (ct_x, ct_y); // Decrease id value of current facet for start edge. mark(r, c) -= static_cast<char> (1 << stop_edge); // Find next facet. if (stop_edge == 0) r--; else if (stop_edge == 1) c++; else if (stop_edge == 2) r++; else if (stop_edge == 3) c--; // Go to next facet. start_edge = (stop_edge + 2) % 4; } } static void mark_facets (const Matrix& Z, charMatrix& mark, double lvl) { unsigned int nr = mark.rows (); unsigned int nc = mark.cols (); double f[4]; for (unsigned int c = 0; c < nc; c++) for (unsigned int r = 0; r < nr; r++) { f[0] = Z(r, c) - lvl; f[1] = Z(r, c+1) - lvl; f[3] = Z(r+1, c) - lvl; f[2] = Z(r+1, c+1) - lvl; for (unsigned int i = 0; i < 4; i++) if (fabs(f[i]) < std::numeric_limits<double>::epsilon ()) f[i] = std::numeric_limits<double>::epsilon (); if (f[1] * f[2] < 0) mark(r, c) += 2; if (f[0] * f[3] < 0) mark(r, c) += 8; } for (unsigned int r = 0; r < nr; r++) for (unsigned int c = 0; c < nc; c++) { f[0] = Z(r, c) - lvl; f[1] = Z(r, c+1) - lvl; f[3] = Z(r+1, c) - lvl; f[2] = Z(r+1, c+1) - lvl; for (unsigned int i = 0; i < 4; i++) if (fabs(f[i]) < std::numeric_limits<double>::epsilon ()) f[i] = std::numeric_limits<double>::epsilon (); if (f[0] * f[1] < 0) mark(r, c) += 1; if (f[2] * f[3] < 0) mark(r, c) += 4; } } static void cntr (const RowVector& X, const RowVector& Y, const Matrix& Z, double lvl) { unsigned int nr = Z.rows (); unsigned int nc = Z.cols (); charMatrix mark (nr - 1, nc - 1, 0); mark_facets (Z, mark, lvl); // Find contours that start at a domain edge. for (unsigned int c = 0; c < nc - 1; c++) { // Top. if (mark(0, c) & 1) drawcn (X, Y, Z, lvl, 0, c, 0.0, 0.0, 0, true, mark); // Bottom. if (mark(nr - 2, c) & 4) drawcn (X, Y, Z, lvl, nr - 2, c, 0.0, 0.0, 2, true, mark); } for (unsigned int r = 0; r < nr - 1; r++) { // Left. if (mark(r, 0) & 8) drawcn (X, Y, Z, lvl, r, 0, 0.0, 0.0, 3, true, mark); // Right. if (mark(r, nc - 2) & 2) drawcn (X, Y, Z, lvl, r, nc - 2, 0.0, 0.0, 1, true, mark); } for (unsigned int r = 0; r < nr - 1; r++) for (unsigned int c = 0; c < nc - 1; c++) if (mark (r, c) > 0) drawcn (X, Y, Z, lvl, r, c, 0.0, 0.0, 255, true, mark); } DEFUN (__contourc__, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} __contourc__ (@var{x}, @var{y}, @var{z}, @var{levels})\n\ Undocumented internal function.\n\ @end deftypefn") { octave_value retval; if (args.length () == 4) { RowVector X = args (0).row_vector_value (); RowVector Y = args (1).row_vector_value (); Matrix Z = args (2).matrix_value (); RowVector L = args (3).row_vector_value (); if (! error_state) { contourc.resize (2, 0); for (int i = 0; i < L.length (); i++) cntr (X, Y, Z, L (i)); end_contour (); retval = contourc; } else error ("__contourc__: invalid argument values"); } else print_usage (); return retval; } /* ## No test needed for internal helper function. %!assert (1) */