Not able to export 3d volume rendering created using vtk library to .obj or .stl file format

48 views Asked by At

I am using vtkmodules library, to create a 3D model of a heart. I have appended all the images into a list and converted it into an array. The shape of the array is (221,512,512). I am using the following code to generate a 3D volume. The 3D volume is getting generated, but I am not able to export it into .obj or .stl file format.Can someone help me with this

import vtkmodules.all as vtk

data_spacing = (1.0, 1.0, 1.0)
data_extent = (0, image_array.shape[2] - 1, 0, image_array.shape[1] - 1, 0, image_array.shape[0] - 1)

structured_points = vtk.vtkImageData()
structured_points.SetDimensions(image_array.shape[2], image_array.shape[1], image_array.shape[0])
structured_points.SetSpacing(data_spacing)
structured_points.SetExtent(data_extent)
structured_points.GetPointData().SetScalars(vtk.vtkFloatArray())
structured_points.GetPointData().GetScalars().SetArray(image_array.ravel(), image_array.size, 1)

volume_mapper = vtk.vtkFixedPointVolumeRayCastMapper()
volume_mapper.SetInputData(structured_points)

volume_property = vtk.vtkVolumeProperty()
color_func = vtk.vtkColorTransferFunction()

color_func.AddRGBPoint(0, 0.0, 0.0, 0.0)  
color_func.AddRGBPoint(1, 0.0, 0.0, 1.0)  
color_func.AddRGBPoint(2, 0.0, 1.0, 0.0)  
color_func.AddRGBPoint(3, 0.0, 1.0, 1.0)
color_func.AddRGBPoint(4, 1.0, 0.0, 0.0)  
color_func.AddRGBPoint(5, 1.0, 0.0, 1.0)  
color_func.AddRGBPoint(6, 1.0, 1.0, 0.0)  
color_func.AddRGBPoint(7, 1.0, 1.0, 1.0)  

volume_property.SetColor(color_func)

opacity_func = vtk.vtkPiecewiseFunction()
opacity_func.AddPoint(0, 0.0)
opacity_func.AddPoint(255, 0.7)
volume_property.SetScalarOpacity(opacity_func)

volume_actor = vtk.vtkVolume()
volume_actor.SetMapper(volume_mapper)
volume_actor.SetProperty(volume_property)

renderer = vtk.vtkRenderer()
renderer.SetBackground(0,0,0)
render_window = vtk.vtkRenderWindow()
render_window.SetWindowName("CT Volume Rendering")
render_window.AddRenderer(renderer)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(render_window)

renderer.AddViewProp(volume_actor)

renderer.ResetCamera()
render_window.Render()

iren.Start()
0

There are 0 answers