Mercurial > octave
annotate src/DLD-FUNCTIONS/convhulln.cc @ 10257:cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2010 06:34:29 -0500 |
parents | 40dfc0c99116 |
children | b2143d97c002 |
rev | line source |
---|---|
6823 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2000, 2007, 2008, 2009 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 29. July 2000 - Kai Habel: first release | |
25 2002-04-22 Paul Kienzle | |
26 * Use warning(...) function rather than writing to cerr | |
27 2006-05-01 Tom Holroyd | |
28 * add support for consistent winding in all dimensions; output is | |
29 * guaranteed to be simplicial. | |
30 */ | |
31 | |
32 #ifdef HAVE_CONFIG_H | |
33 #include <config.h> | |
34 #endif | |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
35 |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
36 #include <sstream> |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
37 |
6823 | 38 #include "Cell.h" |
9786
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
39 #include "defun-dld.h" |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
40 #include "error.h" |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
41 #include "oct-obj.h" |
2c279308f6ab
fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
42 #include "parse.h" |
6823 | 43 |
44 extern "C" { | |
45 #include <qhull/qhull_a.h> | |
46 } | |
47 | |
10257
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
48 #if defined (HAVE_QHULL) && defined (NEED_QHULL_VERSION) |
6823 | 49 char qh_version[] = "convhulln.oct 2007-07-24"; |
50 #endif | |
51 | |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
52 DEFUN_DLD (convhulln, args, nargout, |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
53 "-*- texinfo -*-\n\ |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
54 @deftypefn {Loadable Function} {@var{h} =} convhulln (@var{p})\n\ |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
55 @deftypefnx {Loadable Function} {@var{h} =} convhulln (@var{p}, @var{opt})\n\ |
8788 | 56 @deftypefnx {Loadable Function} {[@var{h}, @var{v}] =} convhulln (@dots{})\n\ |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
57 Return an index vector to the points of the enclosing convex hull.\n\ |
6823 | 58 The input matrix of size [n, dim] contains n points of dimension dim.\n\n\ |
59 If a second optional argument is given, it must be a string or cell array\n\ | |
60 of strings containing options for the underlying qhull command. (See\n\ | |
61 the Qhull documentation for the available options.) The default options\n\ | |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
62 are \"s Qci Tcv\".\n\ |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
63 If the second output @var{V} is requested the volume of the convex hull is\n\ |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
64 calculated.\n\n\ |
6823 | 65 @seealso{convhull, delaunayn}\n\ |
66 @end deftypefn") | |
67 { | |
68 octave_value_list retval; | |
6959 | 69 |
6823 | 70 #ifdef HAVE_QHULL |
71 std::string options; | |
72 | |
6959 | 73 int nargin = args.length (); |
6823 | 74 if (nargin < 1 || nargin > 2) |
75 { | |
76 print_usage (); | |
77 return retval; | |
78 } | |
79 | |
80 if (nargin == 2) | |
81 { | |
6959 | 82 if (args (1).is_string ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
83 options = args(1).string_value (); |
6959 | 84 else if (args(1).is_cell ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
85 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
86 Cell c = args(1).cell_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
87 options = ""; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
88 for (octave_idx_type i = 0; i < c.numel (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
89 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
90 if (! c.elem(i).is_string ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
91 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
92 error ("convhulln: second argument must be a string or cell array of strings"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
93 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
94 } |
6823 | 95 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
96 options = options + c.elem(i).string_value() + " "; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
97 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
98 } |
6823 | 99 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
100 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
101 error ("convhulln: second argument must be a string or cell array of strings"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
102 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
103 } |
6823 | 104 } |
105 else | |
106 // turn on some consistency checks | |
107 options = "s Qci Tcv"; | |
108 | |
6959 | 109 Matrix p (args(0).matrix_value ()); |
6823 | 110 |
6959 | 111 const octave_idx_type dim = p.columns (); |
112 const octave_idx_type n = p.rows (); | |
113 p = p.transpose (); | |
6823 | 114 |
6959 | 115 double *pt_array = p.fortran_vec (); |
6823 | 116 |
117 boolT ismalloc = False; | |
118 | |
10257
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
119 std::ostringstream buf; |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
120 |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
121 buf << "qhull QJ " << options; |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
122 |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
123 std::string buf_string = buf.str (); |
6880 | 124 |
10257
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
125 // FIXME -- we can't just pass buf_string.c_str () to qh_new_qhull |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
126 // because the argument is not declared const. Ugh. Unless |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
127 // qh_new_qhull really needs to modify this argument, someone should |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
128 // fix QHULL. |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
129 |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
130 OCTAVE_LOCAL_BUFFER (char, flags, buf_string.length () + 1); |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
131 |
cd550069240e
assume vsnprintf from gnulib; use sstream instead of snprintf
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
132 strcpy (flags, buf_string.c_str ()); |
6823 | 133 |
7520 | 134 if (! qh_new_qhull (dim, n, pt_array, ismalloc, flags, 0, stderr)) |
6823 | 135 { |
136 // If you want some debugging information replace the NULL | |
137 // pointer with stdout | |
138 | |
6959 | 139 vertexT *vertex, **vertexp; |
6823 | 140 facetT *facet; |
141 setT *vertices; | |
142 unsigned int nf = qh num_facets; | |
143 | |
6959 | 144 Matrix idx (nf, dim); |
6823 | 145 |
146 octave_idx_type j, i = 0; | |
147 FORALLfacets | |
10154
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 j = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
150 if (! facet->simplicial) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
151 // should never happen with QJ |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
152 error ("convhulln: non-simplicial facet"); |
6823 | 153 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
154 if (dim == 3) |
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 vertices = qh_facet3vertex (facet); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
157 FOREACHvertex_ (vertices) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
158 idx(i, j++) = 1 + qh_pointid(vertex->point); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
159 qh_settempfree (&vertices); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
160 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
161 else |
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 if (facet->toporient ^ qh_ORIENTclock) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
164 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
165 FOREACHvertex_ (facet->vertices) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
166 idx(i, j++) = 1 + qh_pointid(vertex->point); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
167 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
168 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
169 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
170 FOREACHvertexreverse12_ (facet->vertices) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
171 idx(i, j++) = 1 + qh_pointid(vertex->point); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
172 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
173 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
174 if (j < dim) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
175 // likewise but less fatal |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
176 warning ("facet %d only has %d vertices", i, j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
177 i++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
178 } |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
179 |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
180 if (nargout == 2) |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
181 // calculate volume of convex hull |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
182 // taken from qhull src/geom2.c |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
183 { |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
184 realT area; |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
185 realT dist; |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
186 |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
187 FORALLfacets |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
188 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
189 if (! facet->normal) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
190 continue; |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
191 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
192 if (facet->upperdelaunay && qh ATinfinity) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
193 continue; |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
194 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
195 facet->f.area = area = qh_facetarea (facet); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
196 facet->isarea = True; |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
197 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
198 if (qh DELAUNAY) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
199 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
200 if (facet->upperdelaunay == qh UPPERdelaunay) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
201 qh totarea += area; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
202 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
203 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
204 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
205 qh totarea += area; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
206 qh_distplane (qh interior_point, facet, &dist); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
207 qh totvol += -dist * area/ qh hull_dim; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
208 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
209 } |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
210 |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
211 retval(1) = octave_value (qh totvol); |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
212 } |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
213 |
6959 | 214 retval(0) = octave_value (idx); |
6823 | 215 } |
6959 | 216 |
217 // free long memory | |
218 qh_freeqhull (! qh_ALL); | |
219 | |
220 // free short memory and memory allocator | |
6823 | 221 int curlong, totlong; |
222 qh_memfreeshort (&curlong, &totlong); | |
223 | |
224 if (curlong || totlong) | |
6959 | 225 warning ("convhulln: did not free %d bytes of long memory (%d pieces)", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9786
diff
changeset
|
226 totlong, curlong); |
6823 | 227 #else |
228 error ("convhulln: not available in this version of Octave"); | |
229 #endif | |
6959 | 230 |
6823 | 231 return retval; |
232 } | |
8786
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
233 |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
234 /* |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
235 %!test |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
236 %! cube = [0 0 0;1 0 0;1 1 0;0 1 0;0 0 1;1 0 1;1 1 1;0 1 1]; |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
237 %! [h, v] = convhulln(cube,'Pp'); |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
238 %! assert (v, 1.0, 1e6*eps); |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
239 %!test |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
240 %! tetrahedron = [1 1 1;-1 -1 1;-1 1 -1;1 -1 -1]; |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
241 %! [h, v] = convhulln(tetrahedron,'Pp'); |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
242 %! assert (v, 8/3, 1e6*eps); |
dbd428efbf56
Add calculation convex hull volume
Kai Habel <kai.habel@gmx.de>
parents:
7520
diff
changeset
|
243 */ |