Skip to content

Commit

Permalink
some optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
smparker committed Jan 14, 2024
1 parent 6646b56 commit 3593096
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/blender-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: |
mkdir -p ${HOME}/.config/blender/${BLENDER_MAJOR_VERSION}/scripts/addons
python setup.py build
python setup.py install --mode copy
python setup.py install
- name: Test Blender
run: |
bash run_test.sh -b blender-${BLENDER_VERSION}-linux-x64/blender
11 changes: 4 additions & 7 deletions molecular_blender/isosurfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def transform_triangles(triangles, origin, axes):
if not triangles:
return triangles
coords = np.array(triangles, dtype=DTYPE)
out = np.dot(coords, axes)
return [out[i, :] + origin for i in range(coords.shape[0])]
out = np.dot(coords, axes) + origin
return [ out[i,:] for i in range(out.shape[0]) ]


def cube_isosurface(data, origin, axes, isovalues, name="cube", wm=None):
Expand Down Expand Up @@ -113,16 +113,13 @@ def isosurface_simple(p0, p1, nvoxels, isovalues, box_func, axes, name, wm=None)
yvals, ystep = np.linspace(p0[1], p1[1], num=nvoxels[1]+1, retstep=True, endpoint=True, dtype=DTYPE)
zvals, zstep = np.linspace(p0[2], p1[2], num=nvoxels[2]+1, retstep=True, endpoint=True, dtype=DTYPE)

scaled_axes = np.array(axes, dtype=DTYPE)
scaled_axes[:,0] *= xstep
scaled_axes[:,1] *= ystep
scaled_axes[:,2] *= zstep
scaled_axes = np.array(axes, dtype=DTYPE) * np.array([xstep, ystep, zstep], dtype=DTYPE)

box_values = box_func(xvals, yvals, zvals)
tri_list = marching_cube_box(box_values, isovalues)

origin = np.array(p0, dtype=DTYPE) * bohr2ang
for iiso in range(len(isovalues)):
origin = np.array(p0, dtype=DTYPE) * bohr2ang
triangle_sets[iiso]["triangles"] = transform_triangles(
tri_list[iiso], origin, scaled_axes)

Expand Down
4 changes: 2 additions & 2 deletions molecular_blender/marching_cube_cy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ ctypedef vector[triangle_vec] iso_triangles
@cython.nonecheck(CYDEBUG)
cdef void polygonise(triangle_vec* tri_list, const DTYPE_t* cornervalues,
const DTYPE_t* cornerpos,
float isolevel) nogil:
float isolevel) noexcept nogil:
global edgetable, tritable

cdef point[12] vertlist
Expand Down Expand Up @@ -379,7 +379,7 @@ cdef void polygonise(triangle_vec* tri_list, const DTYPE_t* cornervalues,
@cython.wraparound(CYDEBUG)
@cython.initializedcheck(CYDEBUG)
@cython.nonecheck(CYDEBUG)
cdef void vertex_interp(point* vert_out, float isolevel, const DTYPE_t* p1, const DTYPE_t* p2, const float v1, const float v2) nogil:
cdef void vertex_interp(point* vert_out, float isolevel, const DTYPE_t* p1, const DTYPE_t* p2, const float v1, const float v2) noexcept nogil:
cdef float zero = 1e-8
if (fabs(isolevel-v1) < zero):
vert_out.x = p1[0]
Expand Down
2 changes: 1 addition & 1 deletion molecular_blender/orbitals_cy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ cdef void add_box_values(CShell* shell,
int nz, DTYPE_t* zz,
DTYPE_t* coeff,
DTYPE_t* target,
float logmxcoeff) nogil:
float logmxcoeff) noexcept nogil:
cdef float X = shell.X
cdef float Y = shell.Y
cdef float Z = shell.Z
Expand Down

0 comments on commit 3593096

Please sign in to comment.