8
8
#define PY_SSIZE_T_CLEAN
9
9
#include "Python.h"
10
10
#include "numpy/ndarrayobject.h"
11
- #include "libqhull/qhull_a .h"
11
+ #include "libqhull_r/qhull_ra .h"
12
12
#include <stdio.h>
13
13
14
14
@@ -32,11 +32,11 @@ static const char* qhull_error_msg[6] = {
32
32
/* Return the indices of the 3 vertices that comprise the specified facet (i.e.
33
33
* triangle). */
34
34
static void
35
- get_facet_vertices (const facetT * facet , int indices [3 ])
35
+ get_facet_vertices (qhT * qh , const facetT * facet , int indices [3 ])
36
36
{
37
37
vertexT * vertex , * * vertexp ;
38
38
FOREACHvertex_ (facet -> vertices )
39
- * indices ++ = qh_pointid (vertex -> point );
39
+ * indices ++ = qh_pointid (qh , vertex -> point );
40
40
}
41
41
42
42
/* Return the indices of the 3 triangles that are neighbors of the specified
@@ -88,6 +88,8 @@ static PyObject*
88
88
delaunay_impl (int npoints , const double * x , const double * y ,
89
89
int hide_qhull_errors )
90
90
{
91
+ qhT qh_qh ; /* qh variable type and name must be like */
92
+ qhT * qh = & qh_qh ; /* this for Qhull macros to work correctly. */
91
93
coordT * points = NULL ;
92
94
facetT * facet ;
93
95
int i , ntri , max_facet_id ;
@@ -148,7 +150,8 @@ delaunay_impl(int npoints, const double* x, const double* y,
148
150
}
149
151
150
152
/* Perform Delaunay triangulation. */
151
- exitcode = qh_new_qhull (ndim , npoints , points , False ,
153
+ qh_zero (qh , error_file );
154
+ exitcode = qh_new_qhull (qh , ndim , npoints , points , False ,
152
155
"qhull d Qt Qbb Qc Qz" , NULL , error_file );
153
156
if (exitcode != qh_ERRnone ) {
154
157
PyErr_Format (PyExc_RuntimeError ,
@@ -159,7 +162,7 @@ delaunay_impl(int npoints, const double* x, const double* y,
159
162
}
160
163
161
164
/* Split facets so that they only have 3 points each. */
162
- qh_triangulate ();
165
+ qh_triangulate (qh );
163
166
164
167
/* Determine ntri and max_facet_id.
165
168
Note that libqhull uses macros to iterate through collections. */
@@ -169,7 +172,7 @@ delaunay_impl(int npoints, const double* x, const double* y,
169
172
++ ntri ;
170
173
}
171
174
172
- max_facet_id = qh facet_id - 1 ;
175
+ max_facet_id = qh -> facet_id - 1 ;
173
176
174
177
/* Create array to map facet id to triangle index. */
175
178
tri_indices = (int * )malloc ((max_facet_id + 1 )* sizeof (int ));
@@ -204,7 +207,7 @@ delaunay_impl(int npoints, const double* x, const double* y,
204
207
FORALLfacets {
205
208
if (!facet -> upperdelaunay ) {
206
209
tri_indices [facet -> id ] = i ++ ;
207
- get_facet_vertices (facet , indices );
210
+ get_facet_vertices (qh , facet , indices );
208
211
* triangles_ptr ++ = (facet -> toporient ? indices [0 ] : indices [2 ]);
209
212
* triangles_ptr ++ = indices [1 ];
210
213
* triangles_ptr ++ = (facet -> toporient ? indices [2 ] : indices [0 ]);
@@ -224,8 +227,8 @@ delaunay_impl(int npoints, const double* x, const double* y,
224
227
}
225
228
226
229
/* Clean up. */
227
- qh_freeqhull (!qh_ALL );
228
- qh_memfreeshort (& curlong , & totlong );
230
+ qh_freeqhull (qh , !qh_ALL );
231
+ qh_memfreeshort (qh , & curlong , & totlong );
229
232
if (curlong || totlong )
230
233
PyErr_WarnEx (PyExc_RuntimeWarning ,
231
234
"Qhull could not free all allocated memory" , 1 );
@@ -243,8 +246,8 @@ delaunay_impl(int npoints, const double* x, const double* y,
243
246
/* Clean up. */
244
247
Py_XDECREF (triangles );
245
248
Py_XDECREF (neighbors );
246
- qh_freeqhull (!qh_ALL );
247
- qh_memfreeshort (& curlong , & totlong );
249
+ qh_freeqhull (qh , !qh_ALL );
250
+ qh_memfreeshort (qh , & curlong , & totlong );
248
251
/* Don't bother checking curlong and totlong as raising error anyway. */
249
252
if (hide_qhull_errors )
250
253
fclose (error_file );
0 commit comments