Spherical Harmonic (SPHARM) Analysis#
import numpy as np
import plotly.graph_objects as go
import vtk
from vtk.numpy_interface import dataset_adapter as dsa
from ktch.harmonic import SphericalHarmonicAnalysis, xyz2spherical
from ktch.datasets import fetch
Load 3D potato surface data#
# parameter mesh
para_path = fetch("danshaku_08_allSegments_para.vtp")
print(para_path)
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(para_path)
reader.Update()
obj_para = dsa.WrapDataObject(reader.GetOutput())
# surface mesh
surf_path = fetch("danshaku_08_allSegments_surf.vtp")
print(surf_path)
reader = vtk.vtkXMLPolyDataReader()
reader.SetFileName(surf_path)
reader.Update()
obj_surf = dsa.WrapDataObject(reader.GetOutput())
Downloading data from 'https://pub-c1d6dba6c94843f88f0fd096d19c0831.r2.dev/examples/danshaku_08_allSegments_para/v1/danshaku_08_allSegments_para.vtp' to file '/home/runner/.cache/ktch-examples/danshaku_08_allSegments_para/v1/danshaku_08_allSegments_para.vtp'.
Downloading data from 'https://pub-c1d6dba6c94843f88f0fd096d19c0831.r2.dev/examples/danshaku_08_allSegments_surf/v1/danshaku_08_allSegments_surf.vtp' to file '/home/runner/.cache/ktch-examples/danshaku_08_allSegments_surf/v1/danshaku_08_allSegments_surf.vtp'.
/home/runner/.cache/ktch-examples/danshaku_08_allSegments_para/v1/danshaku_08_allSegments_para.vtp
/home/runner/.cache/ktch-examples/danshaku_08_allSegments_surf/v1/danshaku_08_allSegments_surf.vtp
arr_para_faces = np.array(obj_para.Polygons.reshape(-1, 4)[:, 1:])
arr_para = np.array(obj_para.Points)
arr_surf_faces = np.array(obj_surf.Polygons.reshape(-1, 4)[:, 1:])
arr_surf = np.array(obj_surf.Points)
Parameter mesh#
I, J, K = arr_para_faces.T
x_surf, y_surf, z_surf = arr_para.T
fig = go.Figure(
data=[
go.Mesh3d(
x=x_surf,
y=y_surf,
z=z_surf,
i=I,
j=J,
k=K,
opacity=0.3,
showscale=False,
),
]
)
fig.update_layout(
width=700,
height=700,
autosize=False,
scene=dict(
camera=dict(
up=dict(x=0, y=0, z=1),
eye=dict(
x=1.1,
y=1.1,
z=1.1,
),
),
aspectmode="data",
),
)
fig.show()