clatlan / cdiutils

A python package to help Coherent Diffraction Imaging (CDI) practitioners in their analysis.
MIT License
12 stars 7 forks source link

[FEATURE] Export an .obj file for nanoSCULPT #42

Open ccechatelier opened 7 months ago

ccechatelier commented 7 months ago

I propose to add at the end of the postprocess, a small bit of code to export an .obj file, that can be later on used by nanoSCULPT directly. This is to avoid using ParaView.

Here is my idea using the example of a Ni NP (that worked so far) :

from skimage.measure import marching_cubes
import matplotlib.pyplot as plt
import numpy as np

path = '/data/id01/inhouse/corentin/experiments/202202_Ni/cdiutils_analysis/results_new2/B18S2P1_Ni/S497/'
file = 'cdiutils_S497_structural_properties.npz'

bulk = np.load(path + file)['support']

verts, faces, _, _ = marching_cubes(bulk, 0)
faces = faces + 1

obj_file = open('test.obj', 'w')

for item in verts:
      obj_file.write(f"v {item[0]} {item[1]} {item[2]}\n")

for item in faces:
      obj_file.write(f"f {item[0]}//{item[0]} {item[1]}//{item[1]} {item[2]}//{item[2]}\n")  

obj_file.close()

Together with the rotation matrix, we would be able at some point to provide directly the input file for nanoSCULPT.