I want to save a vtu file as X3D format through vtkX3DExporter, this is my code, but the result is only 1kb.
import vtk
def main():
colors = vtk.vtkNamedColors()
file_name = ‘C:\Users\jcc\Desktop\test.vtu’
reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(file_name)
reader.Update()
output = reader.GetOutput()
scalar_range = output.GetScalarRange()
lut = vtk.vtkLookupTable()
lut.SetNumberOfColors(256)
lut.SetHueRange(0,1)
lut.SetSaturationRange(1,1)
lut.SetTableRange(reader.GetOutput().GetScalarRange())
lut.SetVectorModeToMagnitude()
lut.Build()
bar = vtk.vtkScalarBarActor()
bar.SetTitle(‘Displacment X’)
bar.SetLookupTable(lut)
mapper = vtk.vtkDataSetMapper()
mapper.SetInputData(output)
mapper.SetScalarRange(scalar_range)
mapper.SetLookupTable(lut)
mapper.ScalarVisibilityOn()
mapper.SetScalarModeToDefault()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().EdgeVisibilityOff()
actor.GetProperty().SetLineWidth(1.0)
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.AddActor(bar)
renderer.SetBackground(1, 1, 1)
renderer.SetBackground(colors.GetColor3d(“White”))
renderer_window = vtk.vtkRenderWindow()
renderer_window.AddRenderer(renderer)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderer_window)
interactor.Initialize()
interactor.Start()
x3dExporter = vtk.vtkX3DExporter()
x3dExporter.SetInput(renderer_window)
x3dExporter.SetFileName(‘qqqqq.x3d’)
x3dExporter.Update()
x3dExporter.Write()
if name == ‘main’:
main()