Skip to content

Commit

Permalink
Merge branch 'visualize3d' into realistic
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Feb 18, 2022
2 parents ec72617 + ee086b7 commit 7f768c1
Show file tree
Hide file tree
Showing 12 changed files with 115,085 additions and 4 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
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.

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


class polysurface:
"""A model of a self-gravitating small body"""
def __init__(self):
self.polyfile = ""
#used for Open3d module
self.mesh = open3d.geometry.TriangleMesh()
return

def ctem2mesh(self, surface_file):

# 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_file
self.dem = ctem_io_readers.read_unformatted_binary(dem_file, parameters['gridsize'])
# Build mesh grid
s = parameters['gridsize']
pix = parameters['pix']
ygrid, xgrid = np.mgrid[-s / 2:s / 2, -s / 2:s / 2] * pix

xvals = xgrid.flatten()
yvals = ygrid.flatten()
zvals = self.dem.flatten()
verts = np.array((xvals, yvals, zvals)).T
faces = np.empty([2 * (s - 1) ** 2, 3], dtype=np.int64)
for j in range(s - 1):
for i in range(s - 1):
idx = (s - 1) * j + i
# faces[idx,:] = [ j*s+i, j*s+i+1, (j+1)*s+i+1, (j+1)*s+i ]
faces[idx, :] = [j * s + i, j * s + i + 1, (j + 1) * s + i]
idx += (s - 1) ** 2
faces[idx, :] = [j * s + i + 1, (j + 1) * s + i + 1, (j + 1) * s + i]
self.mesh.vertices = open3d.utility.Vector3dVector(verts)
self.mesh.triangles = open3d.utility.Vector3iVector(faces)
self.mesh.compute_vertex_normals()


if __name__ == '__main__':
import matplotlib.pyplot as plt

surf = polysurface()
surf.ctem2mesh(surface_file="surface_dem.dat")

zmax = np.amax(surf.dem)
zmin = np.amin(surf.dem)
cnorm = (surf.dem.flatten() - zmin) / (zmax - zmin)
cval = plt.cm.terrain(cnorm)[:,:3]
surf.mesh.vertex_colors = open3d.utility.Vector3dVector(cval)
open3d.visualization.draw_geometries([surf.mesh])


6,153 changes: 6,153 additions & 0 deletions python/ctem/tests/viewer3d/216kleopatra-mesh.ply

Large diffs are not rendered by default.

Loading

0 comments on commit 7f768c1

Please sign in to comment.