Mercurial > octave-nkf
comparison src/DLD-FUNCTIONS/__voronoi__.cc @ 13879:440d7914cf01
fix regression in __voronoi__ and convhulln option processing
* __voronoi__.cc (F__voronoi__): Allow user-supplied options to
completely replace defaults.
* convhulln.cc (F__convhulln__): Likewise.
* __voronoi__.cc (F__voronoi__): New argument, caller.
* voronoi.m, voronoin.m: Pass name of function to __voronoi__.
* voronoin.m: Don't check options here.
* voronoi.m: Don't check nargout.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 17 Nov 2011 13:47:12 -0500 |
parents | adf60d6dc1dd |
children | 1dc120c06ce0 |
comparison
equal
deleted
inserted
replaced
13877:0d32a681d943 | 13879:440d7914cf01 |
---|---|
55 #endif | 55 #endif |
56 #endif | 56 #endif |
57 | 57 |
58 DEFUN_DLD (__voronoi__, args, , | 58 DEFUN_DLD (__voronoi__, args, , |
59 "-*- texinfo -*-\n\ | 59 "-*- texinfo -*-\n\ |
60 @deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{pts})\n\ | 60 @deftypefn {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts})\n\ |
61 @deftypefnx {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{pts}, @var{options})\n\ | 61 @deftypefnx {Loadable Function} {@var{C}, @var{F} =} __voronoi__ (@var{caller}, @var{pts}, @var{options})\n\ |
62 @deftypefnx {Loadable Function} {@var{C}, @var{F}, @var{Inf_Pts} =} __voronoi__ (@dots{})\n\ | 62 @deftypefnx {Loadable Function} {@var{C}, @var{F}, @var{Inf_Pts} =} __voronoi__ (@dots{})\n\ |
63 Undocumented internal function.\n\ | 63 Undocumented internal function.\n\ |
64 @end deftypefn") | 64 @end deftypefn") |
65 { | 65 { |
66 octave_value_list retval; | 66 octave_value_list retval; |
68 #ifdef HAVE_QHULL | 68 #ifdef HAVE_QHULL |
69 | 69 |
70 retval(0) = 0.0; | 70 retval(0) = 0.0; |
71 | 71 |
72 int nargin = args.length (); | 72 int nargin = args.length (); |
73 if (nargin < 1 || nargin > 2) | 73 if (nargin < 2 || nargin > 3) |
74 { | 74 { |
75 print_usage (); | 75 print_usage (); |
76 return retval; | 76 return retval; |
77 } | 77 } |
78 | 78 |
79 std::string cmd = "qhull v"; | 79 std::string caller = args(0).string_value (); |
80 | 80 |
81 if (nargin == 2 && ! args(1).is_empty ()) | 81 Matrix points = args(1).matrix_value (); |
82 { | |
83 if (args(1).is_string ()) | |
84 cmd += " " + args(1).string_value (); | |
85 else if (args(1).is_cellstr ()) | |
86 { | |
87 Array<std::string> tmp = args(1).cellstr_value (); | |
88 | |
89 for (octave_idx_type i = 0; i < tmp.numel (); i++) | |
90 cmd += " " + tmp(i); | |
91 } | |
92 else | |
93 { | |
94 error ("__voronoi__: OPTIONS argument must be a string, cell array of strings, or empty"); | |
95 return retval; | |
96 } | |
97 } | |
98 | |
99 Matrix points (args(0).matrix_value ()); | |
100 const octave_idx_type dim = points.columns (); | 82 const octave_idx_type dim = points.columns (); |
101 const octave_idx_type num_points = points.rows (); | 83 const octave_idx_type num_points = points.rows (); |
102 | 84 |
103 points = points.transpose (); | 85 points = points.transpose (); |
86 | |
87 std::string options; | |
88 | |
89 if (dim <= 4) | |
90 options = " Qbb"; | |
91 else | |
92 options = " Qbb Qx"; | |
93 | |
94 if (nargin == 3) | |
95 { | |
96 octave_value opt_arg = args(2); | |
97 | |
98 if (opt_arg.is_string ()) | |
99 options = " " + args(1).string_value (); | |
100 else if (opt_arg.is_empty ()) | |
101 ; // Use default options. | |
102 else if (args(1).is_cellstr ()) | |
103 { | |
104 options = ""; | |
105 | |
106 Array<std::string> tmp = opt_arg.cellstr_value (); | |
107 | |
108 for (octave_idx_type i = 0; i < tmp.numel (); i++) | |
109 options += " " + tmp(i); | |
110 } | |
111 else | |
112 { | |
113 error ("%s: OPTIONS must be a string, cell array of strings, or empty", | |
114 caller.c_str ()); | |
115 return retval; | |
116 } | |
117 } | |
104 | 118 |
105 boolT ismalloc = false; | 119 boolT ismalloc = false; |
106 | 120 |
107 // Replace the 0 pointer with stdout for debugging information | 121 // Replace the 0 pointer with stdout for debugging information |
108 FILE *outfile = 0; | 122 FILE *outfile = 0; |
109 FILE *errfile = stderr; | 123 FILE *errfile = stderr; |
110 | 124 |
111 // Qhull flags and points arguments are not const... | 125 // qh_new_qhull command and points arguments are not const... |
126 | |
127 std::string cmd = "qhull v" + options; | |
112 | 128 |
113 OCTAVE_LOCAL_BUFFER (char, cmd_str, cmd.length () + 1); | 129 OCTAVE_LOCAL_BUFFER (char, cmd_str, cmd.length () + 1); |
114 | 130 |
115 strcpy (cmd_str, cmd.c_str ()); | 131 strcpy (cmd_str, cmd.c_str ()); |
116 | 132 |
273 retval(2) = at_inf; | 289 retval(2) = at_inf; |
274 retval(1) = C; | 290 retval(1) = C; |
275 retval(0) = F; | 291 retval(0) = F; |
276 } | 292 } |
277 else | 293 else |
278 error ("__voronoi__: qhull failed"); | 294 error ("%s: qhull failed", caller.c_str ()); |
279 | 295 |
280 // Free memory from Qhull | 296 // Free memory from Qhull |
281 qh_freeqhull (! qh_ALL); | 297 qh_freeqhull (! qh_ALL); |
282 | 298 |
283 int curlong, totlong; | 299 int curlong, totlong; |
284 qh_memfreeshort (&curlong, &totlong); | 300 qh_memfreeshort (&curlong, &totlong); |
285 | 301 |
286 if (curlong || totlong) | 302 if (curlong || totlong) |
287 warning ("__voronoi__: did not free %d bytes of long memory (%d pieces)", | 303 warning ("%s: qhull did not free %d bytes of long memory (%d pieces)", |
288 totlong, curlong); | 304 caller.c_str (), totlong, curlong); |
289 | 305 |
290 #else | 306 #else |
291 error ("__voronoi__: not available in this version of Octave"); | 307 error ("%s: not available in this version of Octave", caller.c_str ()); |
292 #endif | 308 #endif |
293 | 309 |
294 return retval; | 310 return retval; |
295 } | 311 } |
296 | 312 |