annotate libinterp/dldfcn/__delaunayn__.cc @ 20654:b65888ec820e draft default tip gccjit

dmalcom gcc jit import
author Stefan Mahr <dac922@gmx.de>
date Fri, 27 Feb 2015 16:59:36 +0100
parents 4197fc428c7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
1 /*
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19303
diff changeset
3 Copyright (C) 2000-2015 Kai Habel
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
4
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
5 This file is part of Octave.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
6
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
10 option) any later version.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
11
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
15 for more details.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
16
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6945
diff changeset
19 <http://www.gnu.org/licenses/>.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
20
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
21 */
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
22
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
23 /*
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
24 16. July 2000 - Kai Habel: first release
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 25. September 2002 - Changes by Rafael Laboissiere <rafael@laboissiere.net>
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
27
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
28 * 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
29 * 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
30 containing extra options to the qhull command.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
31 * 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
32 not [n, dim-1].
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
33
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
34 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
35
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
36 * triangulate non-simplicial facets
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
37 * allow options to be specified as cell array of strings
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
38 * change the default options (for compatibility with matlab)
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
39 */
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
40
9786
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
41 #ifdef HAVE_CONFIG_H
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
42 #include <config.h>
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
43 #endif
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
44
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
45 #include <iostream>
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
46 #include <string>
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
47
19303
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18099
diff changeset
48 #include "oct-locbuf.h"
65554f5847ac don't include oct-locbuf.h in header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 18099
diff changeset
49
9786
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
50 #include "Cell.h"
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
51 #include "defun-dld.h"
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
52 #include "error.h"
2c279308f6ab fix includes in some src/DLD-FUNCTIONS files
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
53 #include "oct-obj.h"
14339
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
54 #include "unwind-prot.h"
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
55
14043
f913363318e0 handle new names and locations of qhull include files (bug #33712)
John W. Eaton <jwe@octave.org>
parents: 13746
diff changeset
56 #if defined (HAVE_QHULL)
f913363318e0 handle new names and locations of qhull include files (bug #33712)
John W. Eaton <jwe@octave.org>
parents: 13746
diff changeset
57 # include "oct-qhull.h"
f913363318e0 handle new names and locations of qhull include files (bug #33712)
John W. Eaton <jwe@octave.org>
parents: 13746
diff changeset
58 # if defined (NEED_QHULL_VERSION)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
59 char qh_version[] = "__delaunayn__.oct 2007-08-21";
14043
f913363318e0 handle new names and locations of qhull include files (bug #33712)
John W. Eaton <jwe@octave.org>
parents: 13746
diff changeset
60 # endif
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
61 #endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
62
14339
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
63 static void
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
64 close_fcn (FILE *f)
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
65 {
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
66 gnulib::fclose (f);
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
67 }
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
68
18077
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
69 static bool
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
70 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
71 {
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
72 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
73 {
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
74 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
75
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
76 if (dim > maxval || n > maxval)
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
77 {
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
78 error ("%s: dimension too large for Qhull", who);
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
79 return false;
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
80 }
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
81 }
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
82
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
83 return true;
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
84 }
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
85
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
86 DEFUN_DLD (__delaunayn__, args, ,
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
87 "-*- texinfo -*-\n\
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
88 @deftypefn {Loadable Function} {@var{T} =} __delaunayn__ (@var{pts})\n\
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
89 @deftypefnx {Loadable Function} {@var{T} =} __delaunayn__ (@var{pts}, @var{options})\n\
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
90 Undocumented internal function.\n\
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
91 @end deftypefn")
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
92
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
93 {
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
94 octave_value_list retval;
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
95
14043
f913363318e0 handle new names and locations of qhull include files (bug #33712)
John W. Eaton <jwe@octave.org>
parents: 13746
diff changeset
96 #if defined (HAVE_QHULL)
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
97
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
98 retval(0) = 0.0;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
99
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
100 int nargin = args.length ();
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
101 if (nargin < 1 || nargin > 2)
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
102 {
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
103 print_usage ();
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
104 return retval;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
105 }
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
106
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
107 Matrix p (args(0).matrix_value ());
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
108 const octave_idx_type dim = p.columns ();
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
109 const octave_idx_type n = p.rows ();
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
110
18077
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
111 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
112 return retval;
ac74b0c4c564 avoid overflow when passing problem dimensions to qhull with --enable-64
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
113
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
114 // Default options
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
115 std::string options;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
116 if (dim <= 3)
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
117 options = "Qt Qbb Qc Qz";
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
118 else
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
119 options = "Qt Qbb Qc Qx";
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
120
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
121 if (nargin == 2)
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
122 {
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
123 if (args(1).is_string ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
124 options = args(1).string_value ();
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
125 else if (args(1).is_empty ())
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
126 ; // Use default options
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
127 else if (args(1).is_cellstr ())
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
128 {
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
129 options = "";
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
130 Array<std::string> tmp = args(1).cellstr_value ();
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
131
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
132 for (octave_idx_type i = 0; i < tmp.numel (); i++)
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
133 options += tmp(i) + " ";
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
134 }
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
135 else
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
136 {
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
137 error ("__delaunayn__: OPTIONS argument must be a string, cell array of strings, or empty");
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
138 return retval;
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
139 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
140 }
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
141
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
142 if (n > dim + 1)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
143 {
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
144 p = p.transpose ();
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
145 double *pt_array = p.fortran_vec ();
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
146 boolT ismalloc = false;
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 // Qhull flags argument is not const char*
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
149 OCTAVE_LOCAL_BUFFER (char, flags, 9 + options.length ());
6880
e00a8f661f06 [project @ 2007-09-07 21:39:55 by dbateman]
dbateman
parents: 6823
diff changeset
150
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
151 sprintf (flags, "qhull d %s", options.c_str ());
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
152
14339
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
153 unwind_protect frame;
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
154
14309
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
155 // Replace the outfile pointer with stdout for debugging information.
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
156 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
157 FILE *outfile = gnulib::fopen ("NUL", "w");
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
158 #else
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
159 FILE *outfile = gnulib::fopen ("/dev/null", "w");
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
160 #endif
6880
e00a8f661f06 [project @ 2007-09-07 21:39:55 by dbateman]
dbateman
parents: 6823
diff changeset
161 FILE *errfile = stderr;
14339
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
162
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
163 if (outfile)
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
164 frame.add_fcn (close_fcn, outfile);
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
165 else
14309
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
166 {
14339
3e4350f09a55 close temporary files opened for Qhull
John W. Eaton <jwe@octave.org>
parents: 14309
diff changeset
167 error ("__delaunayn__: unable to create temporary file for output");
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 return retval;
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
169 }
824e5d362aba Fix Qhull calling convention by passing true file pointer to qh_new_qhull
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
170
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
171 int exitcode = qh_new_qhull (dim, n, pt_array,
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
172 ismalloc, flags, outfile, errfile);
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
173 if (! exitcode)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
174 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
175 // triangulate non-simplicial facets
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
176 qh_triangulate ();
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
177
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
178 facetT *facet;
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
179 vertexT *vertex, **vertexp;
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18077
diff changeset
180 octave_idx_type nf = 0;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18077
diff changeset
181 octave_idx_type i = 0;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
182
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
183 FORALLfacets
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 (! facet->upperdelaunay)
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
186 nf++;
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
187
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
188 // Double check. Non-simplicial facets will cause segfault below
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
189 if (! facet->simplicial)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
190 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
191 error ("__delaunayn__: Qhull returned non-simplicial facets -- try delaunayn with different options");
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
192 exitcode = 1;
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
193 break;
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 }
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
196
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
197 if (! exitcode)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
198 {
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
199 Matrix simpl (nf, dim+1);
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
200
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
201 FORALLfacets
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
202 {
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
203 if (! facet->upperdelaunay)
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
204 {
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
205 octave_idx_type j = 0;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
206
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
207 FOREACHvertex_ (facet->vertices)
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
208 {
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
209 simpl(i, j++) = 1 + qh_pointid(vertex->point);
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
210 }
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
211 i++;
10154
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 }
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
214
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
215 retval(0) = simpl;
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
216 }
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9786
diff changeset
217 }
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
218 else
11590
4ced6b90fffb style fixes for warning and error messages in source files
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
219 error ("__delaunayn__: qhull failed");
13746
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
220
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
221 // Free memory from Qhull
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
222 qh_freeqhull (! qh_ALL);
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
223
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
224 int curlong, totlong;
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
225 qh_memfreeshort (&curlong, &totlong);
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
226
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
227 if (curlong || totlong)
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
228 warning ("__delaunay__: did not free %d bytes of long memory (%d pieces)",
7ff0bdc3dc4c Revamp geometry functions dependent on Qhull (Bug #34604, Bug #33346)
Rik <octave@nomad.inbox5.com>
parents: 12805
diff changeset
229 totlong, curlong);
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
230 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
231 else if (n == dim + 1)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
232 {
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
233 // one should check if nx points span a simplex
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
234 // I will look at this later.
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
235 RowVector vec (n);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11553
diff changeset
236 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
237 vec(i) = i + 1.0;
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
238
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
239 retval(0) = vec;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
240 }
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
241
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
242 #else
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
243 error ("__delaunayn__: not available in this version of Octave");
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
244 #endif
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6880
diff changeset
245
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
246 return retval;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
247 }
12805
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 /*
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
250 ## 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
251 %!assert (1)
3641167e5b75 codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents: 11590
diff changeset
252 */