35 #if defined (HAVE_CONFIG_H)
52 #if defined (HAVE_QHULL)
56 # if defined (NEED_QHULL_R_VERSION)
57 char qh_version[] =
"convhulln.oct 2007-07-24";
63 qh_freeqhull (qh, ! qh_ALL);
66 qh_memfreeshort (qh, &curlong, &totlong);
68 if (curlong || totlong)
69 warning (
"convhulln: did not free %d bytes of long memory (%d pieces)",
80 if (dim > maxval ||
n > maxval)
81 error (
"%s: dimension too large for Qhull", who);
126 #if defined (HAVE_QHULL)
128 int nargin = args.length ();
130 if (nargin < 1 || nargin > 2)
135 Matrix points (args(0).matrix_value ());
153 if (args(1).is_string ())
154 options =
' ' + args(1).string_value ();
155 else if (args(1).isempty ())
157 else if (args(1).iscellstr ())
164 options +=
' ' + tmp(i);
167 error (
"convhulln: OPTIONS must be a string, cell array of strings, or empty");
170 boolT ismalloc =
false;
173 FILE *outfile =
nullptr;
174 FILE *errfile = stderr;
179 std::string cmd =
"qhull" + options;
181 int exitcode = qh_new_qhull (qh, dim, num_points, points.
fortran_vec (),
182 ismalloc, &cmd[0], outfile, errfile);
187 error (
"convhulln: qhull failed");
189 bool nonsimp_seen =
false;
203 if (! (nonsimp_seen || facet->simplicial || qh->hull_dim == 2))
207 if (cmd.find (
"QJ") != std::string::npos)
209 error (
"convhulln: qhull failed: option 'QJ' returned non-simplicial facet");
214 setT *vertices = qh_facet3vertex (qh, facet);
216 vertexT *vertex, **vertexp;
218 FOREACHvertex_ (vertices)
219 idx(i, j++) = 1 + qh_pointid(qh, vertex->point);
221 qh_settempfree (qh, &vertices);
225 if (facet->toporient ^ qh_ORIENTclock)
227 vertexT *vertex, **vertexp;
229 FOREACHvertex_ (facet->vertices)
230 idx(i, j++) = 1 + qh_pointid(qh, vertex->point);
234 vertexT *vertex, **vertexp;
236 FOREACHvertexreverse12_ (facet->vertices)
237 idx(i, j++) = 1 + qh_pointid(qh, vertex->point);
241 warning (
"convhulln: facet %" OCTAVE_IDX_TYPE_FORMAT
242 " only has %" OCTAVE_IDX_TYPE_FORMAT
251 idx.
resize (nf, dim, 0.0);
265 if (facet->upperdelaunay && qh->ATinfinity)
268 facet->f.area = area = qh_facetarea (qh, facet);
269 facet->isarea = True;
273 if (facet->upperdelaunay == qh->UPPERdelaunay)
279 qh_distplane (qh, qh->interior_point, facet, &dist);
280 qh->totvol += -dist * area / qh->hull_dim;
293 octave_unused_parameter (args);
294 octave_unused_parameter (nargout);
charNDArray max(char d, const charNDArray &m)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type columns(void) const
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_API T * fortran_vec(void)
Size of the specified dimension.
Matrix transpose(void) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
static bool octave_qhull_dims_ok(octave_idx_type dim, octave_idx_type n, const char *who)
static void free_qhull_memory(qhT *qh)
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.
OCTINTERP_API void print_usage(void)
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)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))