49 #if defined (HAVE_QHULL)
51 # if defined (NEED_QHULL_VERSION)
52 char qh_version[] =
"__voronoi__.oct 2007-07-24";
69 if (dim > maxval || n > maxval)
71 error (
"%s: dimension too large for Qhull", who);
81 @deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts})\n\
82 @deftypefnx {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts}, @var{options})\n\
83 @deftypefnx {Loadable Function} {@var{C}, @var{F}, @var{Inf_Pts} =} __voronoi__ (@dots{})\n\
84 Undocumented internal function.\n\
89 std::string caller = args(0).string_value ();
91 #if defined (HAVE_QHULL)
95 int nargin = args.
length ();
96 if (nargin < 2 || nargin > 3)
102 Matrix points = args(1).matrix_value ();
133 options +=
" " + tmp(i);
137 error (
"%s: OPTIONS must be a string, cell array of strings, or empty",
143 boolT ismalloc =
false;
148 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
149 FILE *outfile = gnulib::fopen (
"NUL",
"w");
151 FILE *outfile = gnulib::fopen (
"/dev/null",
"w");
153 FILE *errfile = stderr;
159 error (
"__voronoi__: unable to create temporary file for output");
165 std::string cmd =
"qhull v" + options;
169 strcpy (cmd_str, cmd.c_str ());
171 int exitcode = qh_new_qhull (dim, num_points, points.
fortran_vec (),
172 ismalloc, cmd_str, outfile, errfile);
178 qh_findgood_all (qh facet_list);
181 = qh num_vertices - qh_setsize (qh del_vertices);
187 qh_setvoronoi_all ();
210 if (qh hull_dim == 3)
211 qh_order_vertexneighbors (vertex);
213 bool infinity_seen =
false;
215 facetT *neighbor, **neighborp;
217 FOREACHneighbor_ (vertex)
219 if (neighbor->upperdelaunay)
223 infinity_seen =
true;
229 neighbor->seen =
true;
245 ? num_points : num_voronoi_regions);
251 Matrix F (num_voronoi_vertices+1, dim);
275 if (qh hull_dim == 3)
276 qh_order_vertexneighbors (vertex);
278 bool infinity_seen =
false;
288 if (num_vertices == 1)
295 facetT *neighbor, **neighborp;
297 FOREACHneighbor_(vertex)
299 if (neighbor->upperdelaunay)
303 infinity_seen =
true;
310 if (! neighbor->seen)
314 F(i,
d) = neighbor->center[
d];
316 neighbor->seen =
true;
317 neighbor->visitid = i;
320 facet_list(m++) = neighbor->visitid + 1;
332 error (
"%s: qhull failed", caller.c_str ());
335 qh_freeqhull (! qh_ALL);
337 int curlong, totlong;
338 qh_memfreeshort (&curlong, &totlong);
340 if (curlong || totlong)
341 warning (
"%s: qhull did not free %d bytes of long memory (%d pieces)",
342 caller.c_str (), totlong, curlong);
345 error (
"%s: not available in this version of Octave", caller.c_str ());