Cython wrapper trial 2
parent
5e29631244
commit
b526fe1a9f
|
@ -671,6 +671,8 @@ inline static void subalgorithm(struct simplex *s, double *v) {
|
|||
}
|
||||
}
|
||||
|
||||
#define DEBUG
|
||||
|
||||
double gjk(struct bd bd1, struct bd bd2, struct simplex *s) {
|
||||
|
||||
int k = 0; /**< Iteration counter */
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,5 +1,6 @@
|
|||
#cython: language_level=3, boundscheck=False
|
||||
import numpy as np
|
||||
from libc.stdlib cimport free
|
||||
|
||||
cdef extern from "openGJK.h":
|
||||
struct bd:
|
||||
|
@ -18,35 +19,42 @@ cdef extern from "openGJK.h":
|
|||
def pygjk(bod1, bod2):
|
||||
"""Returns distance between two bodies, input: array of nodal coordinates for each body"""
|
||||
|
||||
print("Hello!!")
|
||||
cdef:
|
||||
simplex s
|
||||
simplex ss
|
||||
bd bd1
|
||||
bd bd2
|
||||
double v1[3], v2[3]
|
||||
int i, j
|
||||
double answer
|
||||
|
||||
dummyRow = np.array([0.,0.,0.])
|
||||
if bod1.ndim < 2:
|
||||
bod1 = np.append([bod1], [[1.,1.,1.]], axis = 0)
|
||||
if bod2.ndim < 2:
|
||||
bod2 = np.append([bod2], [[1.,1.,1.]], axis = 0)
|
||||
|
||||
bd1.numpoints = np.size(bod1,0)
|
||||
bd2.numpoints = np.size(bod2,0)
|
||||
|
||||
cdef:
|
||||
double [:,:] narr1 = bod1 # create numpy-array MemoryView
|
||||
double [:,:] narr2 = bod2
|
||||
|
||||
|
||||
for i in range(0, bd1.numpoints):
|
||||
bd1.coord[i] = hex(id(bod1[i]))
|
||||
|
||||
bd1.numpoints = np.size(bod1, 0)
|
||||
if bd1.numpoints < 2:
|
||||
bod1 = np.vstack([bod1, dummyRow])
|
||||
for i in range(0, bd1.numpoints):
|
||||
v1[0] = bod1[i,0]
|
||||
v1[1] = bod1[i,1]
|
||||
v1[2] = bod1[i,2]
|
||||
bd1.coord[i] = v1
|
||||
|
||||
bd2.numpoints = np.size(bod2, 0)
|
||||
if bd2.numpoints < 2:
|
||||
bod2 = np.vstack([bod2, dummyRow])
|
||||
for j in range(0, bd2.numpoints):
|
||||
v2[0] = bod2[j,0]
|
||||
v2[1] = bod2[j,1]
|
||||
v2[2] = bod2[j,2]
|
||||
bd2.coord[i] = v2
|
||||
|
||||
answer = gjk(bd1, bd2, &s)
|
||||
bd2.coord[i][0] = narr2[j,0]
|
||||
bd2.coord[i][1] = narr2[j,1]
|
||||
bd2.coord[i][2] = narr2[j,2]
|
||||
|
||||
|
||||
answer = gjk(bd1, bd2, &ss)
|
||||
|
||||
free(bd1.coord)
|
||||
free(bd2.coord)
|
||||
|
||||
|
||||
return answer
|
||||
|
||||
return answer
|
Loading…
Reference in New Issue