Skip to content

Commit

Permalink
v3.4 a leaner voxelmap (removed pygame & openGL package dependencies …
Browse files Browse the repository at this point in the history
…-> replaced by PyVista)
  • Loading branch information
andrewrgarcia committed Feb 25, 2023
1 parent 3907519 commit f1119bf
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 382 deletions.
104 changes: 5 additions & 99 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "voxelmap"
version = "3.3.0"
version = "3.4.0"
description = "A Python library for making voxel and 3D models from NumPy arrays."
authors = ["andrewrgarcia <[email protected]>"]
license = "MIT"
Expand All @@ -13,9 +13,7 @@ pytest = "^7.2.0"
matplotlib = "^3.6.2"
pandas = "^1.5.2"
opencv-python = "^4.7.0.68"
pygame = "^2.1.2"
scipy = "^1.10.0"
pyopengl = "^3.1.6"
scikit-image = "^0.19.3"
pyvista = "^0.38.2"
colorcet = "^3.0.1"
Expand Down
24 changes: 12 additions & 12 deletions tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from matplotlib import cm


def test_pickle():
def tedst_pickle():
'''test pickle save and load of made-up array'''
arr = np.random.randint(0,10,(7,7,7))
vxm.save_array(arr,'random-array')
Expand All @@ -17,7 +17,7 @@ def test_pickle():

print(loaded_arr)

def test_custom_voxel_colormap_save():
def tedst_custom_voxel_colormap_save():
'''test the custom voxel colormap (dictionary) generation and drawing
model.hashblocksAdd() adds dictionary entries to custom voxel
colormap to draw model with `voxels` coloring scheme
Expand All @@ -35,7 +35,7 @@ def test_custom_voxel_colormap_save():
model.save('myModel.json')


def test_custom_voxel_colormap_load():
def tedst_custom_voxel_colormap_load():

model = vxm.Model()
model.load('myModel.json')
Expand All @@ -45,7 +45,7 @@ def test_custom_voxel_colormap_load():
model.draw('voxels')


def test_gradient_voxel_colormap1():
def tedst_gradient_voxel_colormap1():
'''test the nuclear gradient voxel colormap (dictionary) drawing'''

arr = np.random.randint(0,10,(7,7,7))
Expand All @@ -56,7 +56,7 @@ def test_gradient_voxel_colormap1():

model.draw('cool')

def test_gradient_voxel_colormap2():
def tedst_gradient_voxel_colormap2():
'''test the linear gradient voxel colormap (dictionary) drawing'''

arr = np.random.randint(0,10,(7,7,7))
Expand All @@ -67,7 +67,7 @@ def test_gradient_voxel_colormap2():

model.draw('fire')

def test_voxelcrds():
def tedst_voxelcrds():

model= vxm.Model()
model.XYZ = np.random.randint(-1,1,(10,3))+np.random.random((10,3))
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_goxeldog():

model.draw('none')

def test_sphere():
def tedst_sphere():
'sphere: stress graphics'

'-- MAKE SPHERE MODEL --'
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_sphere():
wedge.draw('voxels')


def test_image():
def tedst_image():

img = vxm.Image('extra/land.png') # incorporate fake land topography .png file
# img = vxm.Image('extra/donut_lores.png') # incorporate fake land topography .png file
Expand All @@ -169,19 +169,19 @@ def test_image():



def test_ImageMesh():
def tedst_ImageMesh():

img = vxm.Image('extra/land2.png') # incorporate fake land topography .png file

img.make() # resized to 1.0x original size i.e. not resized (default)

img.ImageMesh('land.obj', 12, 3, 3, False, figsize=(10,10))
# img.ImageMesh('land.obj', 12, 0.52, 1, True, verbose=True)
# img.ImageMesh('land.obj', 12, 3, 3, False, figsize=(10,10))
img.ImageMesh('land.obj', 12, 0.52, 1, True, verbose=True)

# img.MeshView(wireframe=False, viewport=(1152, 1152))


def test_MarchingMesh():
def tedst_MarchingMesh():

model = vxm.Model()
model.load('extra/island.json')
Expand Down
6 changes: 3 additions & 3 deletions voxelmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from voxelmap.image import *
from voxelmap.annex import *

from voxelmap.objloader import OBJ
__all__ = ['OBJ']
from voxelmap.objviewer import *
# from __old__.objloader import OBJ
# __all__ = ['OBJ']
# from voxelmap.objviewer import *
45 changes: 25 additions & 20 deletions voxelmap/annex.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from skimage import measure
from skimage.draw import ellipsoid
from scipy import ndimage

import pyvista as pv

def findcrossover(array,low,high,value):
'finds crossover index of array for `value` value'
Expand Down Expand Up @@ -349,39 +349,44 @@ def MarchingMesh(
# Display resulting triangular mesh using Matplotlib. This can also be done
# with mayavi (see skimage.measure.marching_cubes_lewiner docstring).
if plot:
fig = plt.figure(figsize=figsize)
ax = fig.add_subplot(111, projection='3d')

# Fancy indexing: `verts[faces]` to generate a collection of triangles
print(verts[faces-1])
mesh = Poly3DCollection(verts[faces-1])
mesh.set_edgecolor('k')
ax.add_collection3d(mesh)
# fig = plt.figure(figsize=figsize)
# ax = fig.add_subplot(111, projection='3d')

def maxmin(arr): return np.min(arr), np.max(arr)
# # Fancy indexing: `verts[faces]` to generate a collection of triangles
# print(verts[faces-1])
# mesh = Poly3DCollection(verts[faces-1])
# mesh.set_edgecolor('k')
# ax.add_collection3d(mesh)

ax.set_xlim(*maxmin(verts.T[0]))
ax.set_ylim(*maxmin(verts.T[1]))
ax.set_zlim(*maxmin(verts.T[2]))
# def maxmin(arr): return np.min(arr), np.max(arr)

plt.tight_layout()
plt.show()
# ax.set_xlim(*maxmin(verts.T[0]))
# ax.set_ylim(*maxmin(verts.T[1]))
# ax.set_zlim(*maxmin(verts.T[2]))

# plt.tight_layout()
# plt.show()

MeshView(out_file)

import voxelmap.objviewer as viewer

def MeshView(objfile='model.obj', wireframe=False, viewport=(2048, 1152)):
def MeshView(objfile='model.obj',wireframe=False,color='pink',alpha=0.5,background_color='#333333', viewport = [1024, 768]):
'''[GLOBAL_METHOD]
MeshView: triangulated mesh view with OpenGL [ uses pygame ]
MeshView: triangulated mesh view with PyVista
Parameters
----------
objfile: string
.obj file to process with MeshView [in GLOBAL function only]
wireframe: bool
Represent mesh as wireframe instead of solid polyhedron if True (default: False).
color : string / hexadecimal
mesh color. default: 'pink'
alpha : float
opacity transparency range: 0 - 1.0. Default: 0.5
background_color : string / hexadecimal
color of background. default: 'pink'
viewport : (int,int)
viewport / screen (width, height) for display window (default: 80% your screen's width & height)
'''
viewer.objview(objfile, wireframe=wireframe, usemtl=False, viewport=viewport)
mesh = pv.read(objfile)
mesh.plot(show_edges=True if wireframe else False, color=color,opacity=alpha,background=background_color,window_size = viewport)
Loading

0 comments on commit f1119bf

Please sign in to comment.