The instance of vtkImporter contains vtkRenderWindow and vtkRenderer objects.
It supports to recover original scene including lights, cameras, actors, etc.
Here is a simple example which imports 3D studio file and shows the whole scene.

import vtk

DataRoot = "/Users/weiyang/Downloads/VTKData"

importer = vtk.vtk3DSImporter()
importer.ComputeNormalsOn()
importer.SetFileName( DataRoot + "/Data/iflamigm.3ds" )
importer.Read()

vtkRenderWindowInteractor = vtk.vtkRenderWindowInteractor()
vtkRenderWindowInteractor.SetRenderWindow( importer.GetRenderWindow() )
vtkRenderWindowInteractor.Start()



Now let’s try another way to export and import the 3D model.
I choose vtkOBJImporter and vtkOBJExporter to handle the I/O operations.
The initial scene is like the following:

import vtk

source = vtk.vtkPlaneSource()
source.SetCenter( 0, 0, 0 )
source.SetPoint1( 0.5, -0.5, 0 )
source.SetPoint2( -0.5, 0.5, 0 )
source.Update()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection( source.GetOutputPort() )

actor = vtk.vtkActor()
actor.SetMapper( mapper )

axesActor = vtk.vtkAxesActor()

renderer = vtk.vtkRenderer()
renderer.AddActor( actor )
renderer.AddActor( axesActor )
renderer.SetBackground( 0, 0, 0 )

renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer( renderer )

renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow( renderWindow )

renderer.ResetCamera()
renderWindow.Render()
renderWindowInteractor.Start()



Relevant I/O operations are simple for us to use.

Writing part:

exporter = vtk.vtkOBJExporter()
exporter.SetRenderWindow( renderWindow )
exporter.SetFilePrefix( "/Users/weiyang/Desktop/axisAndPlane" ) #create mtl and obj file.
exporter.Write()

Reading part:

import vtk

importer = vtk.vtkOBJImporter()
importer.SetFileName( "/Users/weiyang/Desktop/axisAndPlane.obj" )
importer.SetFileNameMTL( "/Users/weiyang/Desktop/axisAndPlane.mtl" )
importer.Read()

vtkRenderWindowInteractor = vtk.vtkRenderWindowInteractor()
vtkRenderWindowInteractor.SetRenderWindow( importer.GetRenderWindow() )
vtkRenderWindowInteractor.Start()
Categories: PythonVTK

4 1 vote
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x