35 #if defined (HAVE_CONFIG_H)
52 #if defined (HAVE_QHULL)
56 # if defined (NEED_QHULL_VERSION)
57 char qh_version[] =
"convhulln.oct 2007-07-24";
69 qh_freeqhull (! qh_ALL);
72 qh_memfreeshort (&curlong, &totlong);
74 if (curlong || totlong)
75 warning (
"convhulln: did not free %d bytes of long memory (%d pieces)",
86 if (dim > maxval ||
n > maxval)
87 error (
"%s: dimension too large for Qhull", who);
130 #if defined (HAVE_QHULL)
132 int nargin = args.length ();
134 if (nargin < 1 || nargin > 2)
139 Matrix points (args(0).matrix_value ());
157 if (args(1).is_string ())
158 options =
' ' + args(1).string_value ();
159 else if (args(1).isempty ())
161 else if (args(1).iscellstr ())
168 options +=
' ' + tmp(i);
171 error (
"convhulln: OPTIONS must be a string, cell array of strings, or empty");
174 boolT ismalloc =
false;
179 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
182 FILE *outfile =
std::fopen (
"/dev/null",
"w");
184 FILE *errfile = stderr;
187 error (
"convhulln: unable to create temporary file for output");
193 std::string cmd =
"qhull" + options;
197 strcpy (cmd_str, cmd.c_str ());
199 int exitcode = qh_new_qhull (dim, num_points, points.
fortran_vec (),
200 ismalloc, cmd_str, outfile, errfile);
205 error (
"convhulln: qhull failed");
207 bool nonsimp_seen =
false;
221 if (! (nonsimp_seen || facet->simplicial || qh hull_dim == 2))
225 if (cmd.find (
"QJ") != std::string::npos)
227 error (
"convhulln: qhull failed: option 'QJ' returned non-simplicial facet");
232 setT *vertices = qh_facet3vertex (facet);
234 vertexT *vertex, **vertexp;
236 FOREACHvertex_ (vertices)
237 idx(i, j++) = 1 + qh_pointid(vertex->point);
239 qh_settempfree (&vertices);
243 if (facet->toporient ^ qh_ORIENTclock)
245 vertexT *vertex, **vertexp;
247 FOREACHvertex_ (facet->vertices)
248 idx(i, j++) = 1 + qh_pointid(vertex->point);
252 vertexT *vertex, **vertexp;
254 FOREACHvertexreverse12_ (facet->vertices)
255 idx(i, j++) = 1 + qh_pointid(vertex->point);
259 warning (
"convhulln: facet %" OCTAVE_IDX_TYPE_FORMAT
260 " only has %" OCTAVE_IDX_TYPE_FORMAT
269 idx.
resize (nf, dim, 0.0);
283 if (facet->upperdelaunay && qh ATinfinity)
286 facet->f.area = area = qh_facetarea (facet);
287 facet->isarea = True;
291 if (facet->upperdelaunay == qh UPPERdelaunay)
297 qh_distplane (qh interior_point, facet, &dist);
298 qh totvol += -dist * area/ qh hull_dim;
311 octave_unused_parameter (args);
312 octave_unused_parameter (nargout);
charNDArray max(char d, const charNDArray &m)
octave_idx_type columns(void) const
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type rows(void) const
const T * fortran_vec(void) const
Size of the specified dimension.
Matrix transpose(void) const
void resize(octave_idx_type nr, octave_idx_type nc, double rfv=0)
void add_fcn(void(*fcn)(Params...), Args &&... args)
static void close_fcn(FILE *f)
static bool octave_qhull_dims_ok(octave_idx_type dim, octave_idx_type n, const char *who)
static void free_qhull_memory()
#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)
F77_RET_T const F77_DBLE const F77_DBLE * f
std::FILE * fopen(const std::string &filename, const std::string &mode)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value::octave_value(const Array< char > &chm, char type) return retval