Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/__voronoi__.cc @ 11553:01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Use same variable names in error() strings and in documentation.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 16 Jan 2011 22:13:23 -0800 |
parents | fd0a3ac60b0e |
children | 12df7854fa7c |
rev | line source |
---|---|
6823 | 1 /* |
2 | |
11523 | 3 Copyright (C) 2000-2011 Kai Habel |
6823 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
6823 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
6823 | 20 |
21 */ | |
22 | |
23 /* | |
24 20. Augiust 2000 - Kai Habel: first release | |
25 */ | |
26 | |
27 /* | |
28 2003-12-14 Rafael Laboissiere <rafael@laboissiere.net> | |
29 Added optional second argument to pass options to the underlying | |
30 qhull command | |
31 */ | |
32 | |
33 #ifdef HAVE_CONFIG_H | |
34 #include <config.h> | |
35 #endif | |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
36 |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
37 #include <cstdio> |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
38 |
9003
0631d397fbe0
replace lo_ieee_isnan by xisnan, add missing includes
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
39 #include "lo-ieee.h" |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
40 |
6823 | 41 #include "Cell.h" |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
42 #include "defun-dld.h" |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
43 #include "error.h" |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
44 #include "oct-obj.h" |
6823 | 45 |
46 #ifdef HAVE_QHULL | |
47 extern "C" { | |
48 #include <qhull/qhull_a.h> | |
49 } | |
50 | |
51 #ifdef NEED_QHULL_VERSION | |
52 char qh_version[] = "__voronoi__.oct 2007-07-24"; | |
53 #endif | |
54 #endif | |
55 | |
56 DEFUN_DLD (__voronoi__, args, , | |
57 "-*- texinfo -*-\n\ | |
10840 | 58 @deftypefn {Loadable Function} {@var{tri} =} __voronoi__ (@var{point})\n\ |
6823 | 59 @deftypefnx {Loadable Function} {@var{tri} =} __voronoi__ (@var{point}, @var{options})\n\ |
6945 | 60 Undocumented internal function.\n\ |
6823 | 61 @end deftypefn") |
62 { | |
63 octave_value_list retval; | |
6945 | 64 |
6823 | 65 #ifdef HAVE_QHULL |
6945 | 66 |
6823 | 67 retval(0) = 0.0; |
68 | |
6945 | 69 int nargin = args.length (); |
6823 | 70 if (nargin < 1 || nargin > 2) |
71 { | |
72 print_usage (); | |
73 return retval; | |
74 } | |
75 | |
6880 | 76 const char *options; |
77 | |
6823 | 78 if (nargin == 2) |
79 { | |
6945 | 80 if (! args (1).is_string ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
81 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
82 error ("__voronoi__: OPTIONS argument must be a string"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
83 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
84 } |
6945 | 85 |
86 options = args (1).string_value().c_str (); | |
6823 | 87 } |
88 else | |
89 options = ""; | |
90 | |
6945 | 91 Matrix p (args(0).matrix_value ()); |
6823 | 92 |
6945 | 93 const octave_idx_type dim = p.columns (); |
94 const octave_idx_type np = p.rows (); | |
95 p = p.transpose (); | |
6823 | 96 |
6945 | 97 double *pt_array = p.fortran_vec (); |
98 | |
6823 | 99 //double pt_array[dim * np]; |
100 //for (int i = 0; i < np; i++) | |
101 // { | |
102 // for (int j = 0; j < dim; j++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
103 // { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
104 // pt_array[j+i*dim] = p(i,j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
105 // } |
6823 | 106 // } |
107 | |
108 boolT ismalloc = false; | |
109 | |
6945 | 110 OCTAVE_LOCAL_BUFFER (char, flags, 250); |
6880 | 111 |
6823 | 112 // hmm lot's of options for qhull here |
6945 | 113 sprintf (flags, "qhull v Fv T0 %s", options); |
6880 | 114 |
6945 | 115 // If you want some debugging information replace the 0 pointer |
116 // with stdout or some other file open for writing. | |
117 | |
118 FILE *outfile = 0; | |
6880 | 119 FILE *errfile = stderr; |
120 | |
6945 | 121 if (! qh_new_qhull (dim, np, pt_array, ismalloc, flags, outfile, errfile)) |
6823 | 122 { |
123 facetT *facet; | |
124 vertexT *vertex; | |
125 | |
126 octave_idx_type i = 0, n = 1, k = 0, m = 0, fidx = 0, j = 0, r = 0; | |
6945 | 127 OCTAVE_LOCAL_BUFFER (octave_idx_type, ni, np); |
6823 | 128 |
129 for (i = 0; i < np; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
130 ni[i] = 0; |
6945 | 131 qh_setvoronoi_all (); |
6823 | 132 bool infinity_seen = false; |
6945 | 133 facetT *neighbor, **neighborp; |
6823 | 134 coordT *voronoi_vertex; |
6945 | 135 |
6823 | 136 FORALLfacets |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
137 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
138 facet->seen = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
139 } |
6945 | 140 |
6823 | 141 FORALLvertices |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
142 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
143 if (qh hull_dim == 3) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
144 qh_order_vertexneighbors (vertex); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
145 infinity_seen = false; |
6945 | 146 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
147 FOREACHneighbor_ (vertex) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
148 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
149 if (! neighbor->upperdelaunay) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
150 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
151 if (! neighbor->seen) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
152 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
153 n++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
154 neighbor->seen = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
155 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
156 ni[k]++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
157 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
158 else if (! infinity_seen) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
159 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
160 infinity_seen = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
161 ni[k]++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
162 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
163 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
164 k++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
165 } |
6823 | 166 |
6945 | 167 Matrix v (n, dim); |
6823 | 168 for (octave_idx_type d = 0; d < dim; d++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
169 v(0,d) = octave_Inf; |
6823 | 170 |
6945 | 171 boolMatrix AtInf (np, 1); |
6823 | 172 for (i = 0; i < np; i++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
173 AtInf(i) = false; |
8415
fa12c67683d3
Reszie third arg of __voronoi__ before retuning it
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
174 octave_value_list F (np, octave_value ()); |
6823 | 175 k = 0; |
176 i = 0; | |
6945 | 177 |
6823 | 178 FORALLfacets |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
179 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
180 facet->seen = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
181 } |
6945 | 182 |
6823 | 183 FORALLvertices |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
184 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
185 if (qh hull_dim == 3) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
186 qh_order_vertexneighbors(vertex); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
187 infinity_seen = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
188 RowVector facet_list (ni[k++]); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
189 m = 0; |
6945 | 190 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
191 FOREACHneighbor_(vertex) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
192 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
193 if (neighbor->upperdelaunay) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
194 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
195 if (! infinity_seen) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
196 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
197 infinity_seen = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
198 facet_list(m++) = 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
199 AtInf(j) = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
200 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
201 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
202 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
203 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
204 if (! neighbor->seen) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
205 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
206 voronoi_vertex = neighbor->center; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
207 fidx = neighbor->id; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
208 i++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
209 for (octave_idx_type d = 0; d < dim; d++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
210 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
211 v(i,d) = *(voronoi_vertex++); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
212 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
213 neighbor->seen = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
214 neighbor->visitid = i; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
215 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
216 facet_list(m++) = neighbor->visitid + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
217 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
218 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
219 F(r++) = facet_list; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
220 j++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
221 } |
6823 | 222 |
223 Cell C(r, 1); | |
224 for (i = 0; i < r; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
225 C.elem (i) = F(i); |
6823 | 226 |
227 retval(0) = v; | |
228 retval(1) = C; | |
8415
fa12c67683d3
Reszie third arg of __voronoi__ before retuning it
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
229 AtInf.resize (r, 1); |
6823 | 230 retval(2) = AtInf; |
231 | |
6945 | 232 // free long memory |
233 qh_freeqhull (! qh_ALL); | |
6823 | 234 |
6945 | 235 // free short memory and memory allocator |
6823 | 236 int curlong, totlong; |
237 qh_memfreeshort (&curlong, &totlong); | |
238 | |
6945 | 239 if (curlong || totlong) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
240 warning ("__voronoi__: did not free %d bytes of long memory (%d pieces)", totlong, curlong); |
6823 | 241 } |
6945 | 242 else |
243 error ("__voronoi__: qhull failed"); | |
244 | |
6823 | 245 #else |
246 error ("__voronoi__: not available in this version of Octave"); | |
247 #endif | |
6945 | 248 |
6823 | 249 return retval; |
250 } |