Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added restructured Python code to new branch
  • Loading branch information
daminton committed Feb 17, 2022
1 parent c043406 commit 6fd430a
Show file tree
Hide file tree
Showing 13 changed files with 115,094 additions and 104 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,5 @@ examples/global-lunar-bombardment/scale.ipynb

*.m4
*.code-workspace

*.png
104 changes: 0 additions & 104 deletions python/NPF.py

This file was deleted.

3 changes: 3 additions & 0 deletions python/ctem/.idea/.gitignore

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

3 changes: 3 additions & 0 deletions python/ctem/ctem/.idea/.gitignore

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

3 changes: 3 additions & 0 deletions python/ctem/ctem/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# from ctem.ctem_io_readers import *
# from ctem.ctem_io_writers import *
# from ctem.ctem_driver import *
101 changes: 101 additions & 0 deletions python/ctem/ctem/ctem_viewer_3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import numpy as np
import open3d as o3d
import trimesh

class surf:
"""A model of a self-gravitating small body"""
def __init__(self):
self.polyfile = ""
self.mesh = trimesh.Trimesh()
#used for Open3d module
self.o3d_mesh = o3d.geometry.TriangleMesh()
self.nface = 0
self.nvert = 0
return

def io_read_ply(self,filename):
"""Reads in PLY file into Open3d triangular mesh object and computes normals"""
self.polyfile = filename
self.mesh = trimesh.load(f"{self.polyfile}")
trimesh.repair.fix_normals(self.mesh)
self.mesh.vertex_colors = np.full((self.nvert,4),1.0)
self.nvert = len(self.mesh.vertices)
self.nface = len(self.mesh.faces)
self.convert_trimesh_to_o3d()
return

def render(self):
"""Renders output"""
self.convert_trimesh_to_o3d()
o3d.visualization.draw_geometries([self.o3d_mesh])
return

def convert_trimesh_to_o3d(self):
"""Update Open3D mesh with new vertices and faces, and recompute all normals"""
self.o3d_mesh.vertices = o3d.utility.Vector3dVector(self.mesh.vertices)
self.o3d_mesh.triangles = o3d.utility.Vector3iVector(self.mesh.faces)
self.o3d_mesh.compute_vertex_normals()
self.o3d_mesh.compute_triangle_normals()
self.o3d_mesh.vertex_colors = o3d.utility.Vector3dVector(self.mesh.vertex_colors[:,0:3])
return

if __name__ == '__main__':
import os
import ctem_io_readers
import open3d

#Create and initialize data dictionaries for parameters and options from CTEM.in
notset = '-NOTSET-'
currentdir = os.getcwd() + os.sep

parameters={'restart': notset,
'runtype': notset,
'popupconsole': notset,
'saveshaded': notset,
'saverego': notset,
'savepres': notset,
'savetruelist': notset,
'seedn': 1,
'totalimpacts': 0,
'ncount': 0,
'curyear': 0.0,
'fracdone': 1.0,
'masstot': 0.0,
'interval': 0.0,
'numintervals': 0,
'pix': -1.0,
'gridsize': -1,
'seed': 0,
'maxcrat': 1.0,
'shadedminhdefault': 1,
'shadedmaxhdefault': 1,
'shadedminh': 0.0,
'shadedmaxh': 0.0,
'workingdir': currentdir,
'ctemfile': 'ctem.in',
'datfile': 'ctem.dat',
'impfile': notset,
'sfdcompare': notset,
'sfdfile': notset}

#Read ctem.in to initialize parameter values based on user input
ctem_io_readers.read_ctemin(parameters,notset)
#Read surface dem(shaded relief) and ejecta data files
dem_file = parameters['workingdir'] + 'surface_dem.dat'
surface_dem = ctem_io_readers.read_unformatted_binary(dem_file, parameters['gridsize'])
# Build mesh grid
gridsize = parameters['gridsize']
pix = parameters['pix']
ygrid, xgrid = np.mgrid[-gridsize / 2:gridsize / 2,
-gridsize / 2:gridsize / 2] * pix

xvals = xgrid.flatten()
yvals = ygrid.flatten()
zvals = surface_dem.flatten()
dem_vec = np.array((xvals, yvals, zvals*10)).T
pcd = open3d.geometry.PointCloud()
pcd.points = open3d.utility.Vector3dVector(dem_vec)

o3d.visualization.draw_geometries([pcd])


Loading

0 comments on commit 6fd430a

Please sign in to comment.