Skip to content

Instantly share code, notes, and snippets.

View MarilynKeller's full-sized avatar

Marilyn Keller MarilynKeller

View GitHub Profile
@MarilynKeller
MarilynKeller / ply_2_osim_vtp.py
Created February 14, 2024 15:06
Convert a folder of .ply meshes to a folder of .vtp meshes that can be loaded by OpenSim
import argparse
import os
# import pyvista
# import meshio
import vtk
from pyvista import examples
if __name__ == '__main__':
@MarilynKeller
MarilynKeller / submesh.py
Created February 4, 2024 15:31
Python script to extract a submesh give an input mesh vertices and faces array and a list of vertices or faces to keep.
""" Python script to extract a submesh give an input mesh vertices and faces array and a list of vertices or faces to keep."""
def get_submesh(verts, faces, verts_retained=None, faces_retained=None, min_vert_in_face=2):
'''
Given a mesh, create a (smaller) submesh
indicate faces or verts to retain as indices or boolean
verts : Input mesh vertices (Nx3)
faces : Input mesh faces (Fx3)
verts_retained : list of the vertices indices to keep
@MarilynKeller
MarilynKeller / export_indices.py
Last active February 26, 2024 15:40
Blender python script to export the selected vertices as a list of indices.
"""Blender python script to export the selected vertices as an index list."""
import bpy
import pickle
# Fetch the selected object and list all the selected vertices indices
bpy.ops.object.mode_set(mode = 'OBJECT')
obj = bpy.context.object
bpy.ops.object.mode_set(mode = 'EDIT')
verts_ind = [i.index for i in obj.data.vertices if i.select]
@MarilynKeller
MarilynKeller / pyvista_plot_wraps.py
Last active January 17, 2024 14:48
Pyvista wrapper functions
import pyvista as pv
from pyvista import examples
import data_mri as dd
import numpy as np
def plot_3D_image(arr, resolution, center, p=None, interactive_slice=False, orthogonal_slices=True):
''' Plot of a 3D volume with orthogonal slices slices.'''
values = arr
values.shape
import argparse
import os
import pyvista
from pyvista import examples
if __name__ == '__main__':
# Parse a vtp file and convert it to a ply file
parser = argparse.ArgumentParser(description='Convert a folder of vtp files to a folder of ply files')