126#if defined (HAVE_QHULL)
128 int nargin = args.length ();
130 if (nargin < 1 || nargin > 2)
135 Matrix points (args(0).matrix_value ());
139 if (! octave_qhull_dims_ok (dim, num_points,
"convhulln"))
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.
rwdata (),
182 ismalloc, &cmd[0], outfile, errfile);
184 unwind_action free_memory ([qh] () { free_qhull_memory (qh); });
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);
#define DEFUN_DLD(name, args_name, nargout_name, doc)
Macro to define an at run time dynamically loadable builtin function.