annotate libinterp/dldfcn/__delaunayn__.cc @ 29969:7a4f16bff8fd

use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible * __magick_read__.cc, __delaunayn__.cc, __ode15__.cc, __voronoi__.cc: Place optional header files in separate #ifdef blocks from optional code so that a single OCTAVE_NAMESPACE_BEGIN/END pair can surround the entire code section of the file.
author John W. Eaton <jwe@octave.org>
date Sun, 15 Aug 2021 16:57:52 -0400
parents bdf99bc91d94
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 28027
diff changeset
3 // Copyright (C) 2000-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
25
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
26 /*
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
27 16. July 2000 - Kai Habel: first release
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
28
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
29 25. September 2002 - Changes by Rafael Laboissiere <rafael@laboissiere.net>
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
30
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
31 * Added Qbb option to normalize the input and avoid crashes in Octave.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
32 * delaunayn accepts now a second (optional) argument that must be a string
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
33 containing extra options to the qhull command.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
34 * Fixed doc string. The dimension of the result matrix is [m, dim+1], and
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
35 not [n, dim-1].
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
36
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
37 6. June 2006: Changes by Alexander Barth <abarth@marine.usf.edu>
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
38
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
39 * triangulate non-simplicial facets
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
40 * allow options to be specified as cell array of strings
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
41 * change the default options (for compatibility with matlab)
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
42 */
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
43
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
44 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
45 # include "config.h"
9786
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
46 #endif
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
47
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
48 #include <cstdio>
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
49
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
50 #include <limits>
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
51 #include <string>
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
52
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
53 #include "Array.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
54 #include "dMatrix.h"
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
55 #include "dRowVector.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18100
diff changeset
56 #include "oct-locbuf.h"
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
57 #include "unwind-prot.h"
19269
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18100
diff changeset
58
9786
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
59 #include "defun-dld.h"
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
60 #include "error.h"
21126
ba0a4b4f021d include errwarn.h in files that use err_disabled_feature conditionally
John W. Eaton <jwe@octave.org>
parents: 21109
diff changeset
61 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
62 #include "ovl.h"
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
63
14043
f913363318e0 handle new names and locations of qhull include files (bug #33712)
John W. Eaton <jwe@octave.org>
parents: 13746
diff changeset
64 #if defined (HAVE_QHULL)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21126
diff changeset
65 # include "oct-qhull.h"
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
66 # if defined (NEED_QHULL_R_VERSION)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
67 char qh_version[] = "__delaunayn__.oct 2007-08-21";
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21126
diff changeset
68 # endif
29969
7a4f16bff8fd use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible
John W. Eaton <jwe@octave.org>
parents: 29964
diff changeset
69 #endif
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
70
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29629
diff changeset
71 OCTAVE_NAMESPACE_BEGIN
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29629
diff changeset
72
29969
7a4f16bff8fd use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible
John W. Eaton <jwe@octave.org>
parents: 29964
diff changeset
73 #if defined (HAVE_QHULL)
7a4f16bff8fd use fewer OCTAVE_NAMESPACE_BEGIN/END blocks where possible
John W. Eaton <jwe@octave.org>
parents: 29964
diff changeset
74
14339
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
75 static void
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
76 free_qhull_memory (qhT *qh)
24258
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
77 {
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
78 qh_freeqhull (qh, ! qh_ALL);
24258
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
79
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
80 int curlong, totlong;
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
81 qh_memfreeshort (qh, &curlong, &totlong);
24258
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
82
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
83 if (curlong || totlong)
24260
0f2dc8d6c34d Eliminate possible segfaults related to not cleaning up Qhull workspace.
Rik <rik@octave.org>
parents: 24258
diff changeset
84 warning ("__delaunayn__: did not free %d bytes of long memory (%d pieces)",
24258
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
85 totlong, curlong);
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
86 }
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
87
18077
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
88 static bool
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
89 octave_qhull_dims_ok (octave_idx_type dim, octave_idx_type n, const char *who)
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
90 {
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
91 if (sizeof (octave_idx_type) > sizeof (int))
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
92 {
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
93 int maxval = std::numeric_limits<int>::max ();
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
94
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
95 if (dim > maxval || n > maxval)
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20853
diff changeset
96 error ("%s: dimension too large for Qhull", who);
18077
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
97 }
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
98
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
99 return true;
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
100 }
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
101
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
102 #endif
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
103
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
104 DEFUN_DLD (__delaunayn__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
105 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
106 @deftypefn {} {@var{T} =} __delaunayn__ (@var{pts})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
107 @deftypefnx {} {@var{T} =} __delaunayn__ (@var{pts}, @var{options})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
108 Undocumented internal function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
109 @end deftypefn */)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
110
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
111 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
112 #if defined (HAVE_QHULL)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
113
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
114 int nargin = args.length ();
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
115
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
116 if (nargin < 1 || nargin > 2)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
117 print_usage ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
118
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
119 octave_value_list retval;
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
120
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
121 retval(0) = 0.0;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
122
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
123 Matrix p (args(0).matrix_value ());
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
124 const octave_idx_type dim = p.columns ();
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
125 const octave_idx_type n = p.rows ();
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
126
18077
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
127 if (! octave_qhull_dims_ok (dim, n, "__delaynayn__"))
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
128 return retval;
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
129
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
130 // Default options
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
131 std::string options;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
132 if (dim <= 3)
28027
2e6dc7e2b191 Use appropriate Qhull options as necessary to obtain triangulation (bug #50494).
Rik <rik@octave.org>
parents: 27923
diff changeset
133 options = "Qt Qbb Qc";
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
134 else
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
135 options = "Qt Qbb Qc Qx";
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
136
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
137 if (nargin == 2)
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
138 {
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
139 if (args(1).is_string ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
140 options = args(1).string_value ();
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23575
diff changeset
141 else if (args(1).isempty ())
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
142 ; // Use default options
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23220
diff changeset
143 else if (args(1).iscellstr ())
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
144 {
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
145 options = "";
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
146 Array<std::string> tmp = args(1).cellstr_value ();
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
147
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
148 for (octave_idx_type i = 0; i < tmp.numel (); i++)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23577
diff changeset
149 options += tmp(i) + ' ';
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
150 }
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
151 else
20825
66cd994d1b79 eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20790
diff changeset
152 error ("__delaunayn__: OPTIONS argument must be a string, cell array of strings, or empty");
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
153 }
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
154
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
155 if (n > dim + 1)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
156 {
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
157 p = p.transpose ();
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
158 double *pt_array = p.fortran_vec ();
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
159 boolT ismalloc = false;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
160
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
161 std::string cmd = "qhull d " + options;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
162
29517
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
163 // Set the outfile pointer to stdout for status information.
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
164 FILE *outfile = nullptr;
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
165
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
166 // Set the errfile pointer to stderr for errors and summary information.
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
167 // Note: pointer cannot be NULL to disable reporting, unlike outfile.
14309
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
168 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
29517
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
169 FILE *errfile = std::fopen ("NUL", "w");
14309
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
170 #else
29517
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
171 FILE *errfile = std::fopen ("/dev/null", "w");
14309
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
172 #endif
14339
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
173
29517
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
174 if (! errfile)
78ccd8bf439c Suppress extraneous error messages from Qhull (bug #57727).
Rik <rik@octave.org>
parents: 29359
diff changeset
175 error ("__delaunayn__: unable to redirect Qhull errors to /dev/null");
14309
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
176
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
177 unwind_action close_errfile ([=] () { std::fclose (errfile); });
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
178
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
179 qhT context = { };
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
180 qhT *qh = &context;
24258
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
181
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
182 int exitcode = qh_new_qhull (qh, dim, n, pt_array, ismalloc, &cmd[0],
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
183 outfile, errfile);
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
184
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
185 unwind_action free_memory ([qh] () { free_qhull_memory (qh); });
24258
bffbc95fa72b Fix segfault in delaunayn when Qhull memory is not properly cleared (bug #52410).
Rik <rik@octave.org>
parents: 23219
diff changeset
186
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
187 if (exitcode)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
188 error ("__delaunayn__: qhull failed");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
189
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
190 // triangulate non-simplicial facets
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
191 qh_triangulate (qh);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
192
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
193 facetT *facet;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
194 vertexT *vertex, **vertexp;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
195 octave_idx_type nf = 0;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
196 octave_idx_type i = 0;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
197
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
198 FORALLfacets
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
199 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
200 if (! facet->upperdelaunay)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
201 nf++;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
202
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
203 // Double check. Non-simplicial facets will cause segfault below
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
204 if (! facet->simplicial)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
205 error ("__delaunayn__: Qhull returned non-simplicial facets -- try delaunayn with different options");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
206 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
207
26352
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
208 Matrix simpl (nf, dim+1);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
209
26352
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
210 FORALLfacets
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
211 {
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
212 if (! facet->upperdelaunay)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
213 {
26352
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
214 octave_idx_type j = 0;
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
215
26352
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
216 FOREACHvertex_ (facet->vertices)
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
217 {
29629
93c8df989ea0 qhull: Use reentrant libqhull_r (bug #60016).
Stefan Brüns <stefan.bruens@rwth-aachen.de>
parents: 29517
diff changeset
218 simpl(i, j++) = 1 + qh_pointid(qh, vertex->point);
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
219 }
26352
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
220 i++;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
221 }
26352
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
222 }
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
223
26352
8020c9ba82fc __delaunayn__.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 25054
diff changeset
224 retval(0) = simpl;
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
225 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
226 else if (n == dim + 1)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
227 {
23024
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
228 // FIXME: One should check if nx points span a simplex.
a6a7b054e4ba Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents: 22755
diff changeset
229 // I will look at this later.
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
230 RowVector vec (n);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
231 for (octave_idx_type i = 0; i < n; i++)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
232 vec(i) = i + 1.0;
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
233
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
234 retval(0) = vec;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
235 }
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
236
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
237 return retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20893
diff changeset
238
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
239 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
240
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
241 octave_unused_parameter (args);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
242
21109
bd1752782e56 Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents: 20940
diff changeset
243 err_disabled_feature ("__delaunayn__", "Qhull");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
244
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
245 #endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
246 }
12805
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
247
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
248 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
249 ## No test needed for internal helper function.
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
250 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
251 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29629
diff changeset
252
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29629
diff changeset
253 OCTAVE_NAMESPACE_END