44#if defined (HAVE_CONFIG_H)
64#if defined (HAVE_QHULL)
66# if defined (NEED_QHULL_R_VERSION)
67char qh_version[] =
"__delaunayn__.oct 2007-08-21";
73#if defined (HAVE_QHULL)
76free_qhull_memory (qhT *qh)
78 qh_freeqhull (qh, ! qh_ALL);
81 qh_memfreeshort (qh, &curlong, &totlong);
83 if (curlong || totlong)
84 warning (
"__delaunayn__: did not free %d bytes of long memory (%d pieces)",
93 int maxval = std::numeric_limits<int>::max ();
95 if (dim > maxval || n > maxval)
96 error (
"%s: dimension too large for Qhull", who);
112#if defined (HAVE_QHULL)
114 int nargin = args.length ();
116 if (nargin < 1 || nargin > 2)
123 Matrix p (args(0).matrix_value ());
127 if (! octave_qhull_dims_ok (dim, n,
"__delaynayn__"))
133 options =
"Qt Qbb Qc";
135 options =
"Qt Qbb Qc Qx";
139 if (args(1).is_string ())
140 options = args(1).string_value ();
141 else if (args(1).isempty ())
143 else if (args(1).iscellstr ())
149 options += tmp(i) +
' ';
152 error (
"__delaunayn__: OPTIONS argument must be a string, cell array of strings, or empty");
158 double *pt_array = p.
rwdata ();
159 boolT ismalloc =
false;
161 std::string cmd =
"qhull d " + options;
164 FILE *outfile =
nullptr;
168#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
169 FILE *errfile = std::fopen (
"NUL",
"w");
171 FILE *errfile = std::fopen (
"/dev/null",
"w");
175 error (
"__delaunayn__: unable to redirect Qhull errors to /dev/null");
177 unwind_action close_errfile ([errfile] () { std::fclose (errfile); });
182 int exitcode = qh_new_qhull (qh, dim, n, pt_array, ismalloc, &cmd[0],
185 unwind_action free_memory ([qh] () { free_qhull_memory (qh); });
188 error (
"__delaunayn__: qhull failed");
194 vertexT *vertex, **vertexp;
200 if (! facet->upperdelaunay)
204 if (! facet->simplicial)
205 error (
"__delaunayn__: Qhull returned non-simplicial facets -- try delaunayn with different options");
212 if (! facet->upperdelaunay)
216 FOREACHvertex_ (facet->vertices)
218 simpl(i, j++) = 1 + qh_pointid(qh, vertex->point);
226 else if (n == dim + 1)
241 octave_unused_parameter (args);
253OCTAVE_END_NAMESPACE(octave)
N Dimensional Array with copy-on-write semantics.
octave_idx_type rows() const
octave_idx_type columns() const
T * rwdata()
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN_DLD(name, args_name, nargout_name, doc)
Macro to define an at run time dynamically loadable builtin function.
void warning(const char *fmt,...)
void error(const char *fmt,...)
void err_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)