StripFran
Repository source: StripFran
Other languages
See (Cxx), (PythonicAPI)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
StripFran.py
#!/usr/bin/env python
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersCore import (
vtkDecimatePro,
vtkMaskPolyData,
vtkPolyDataNormals,
vtkStripper
)
from vtkmodules.vtkIOLegacy import vtkPolyDataReader
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkCamera,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer
)
def main():
colors = vtkNamedColors()
fileName = get_program_parameters()
renderer1 = vtkRenderer()
renderer1.SetViewport(0.0, 0.0, 0.5, 1.0)
renderer2 = vtkRenderer()
renderer2.SetViewport(0.5, 0.0, 1.0, 1.0)
renderWindow = vtkRenderWindow()
renderWindow.AddRenderer(renderer1)
renderWindow.AddRenderer(renderer2)
renderWindow.SetWindowName('StripFran')
interactor = vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
# Create a cyberware source.
#
cyber = vtkPolyDataReader()
cyber.SetFileName(fileName)
deci = vtkDecimatePro()
deci.SetInputConnection(cyber.GetOutputPort())
deci.SetTargetReduction(0.7)
deci.PreserveTopologyOn()
normals = vtkPolyDataNormals()
normals.SetInputConnection(deci.GetOutputPort())
mask = vtkMaskPolyData()
mask.SetInputConnection(deci.GetOutputPort())
mask.SetOnRatio(2)
cyberMapper = vtkPolyDataMapper()
cyberMapper.SetInputConnection(mask.GetOutputPort())
cyberActor = vtkActor()
cyberActor.SetMapper(cyberMapper)
cyberActor.GetProperty().SetColor(colors.GetColor3d('Flesh'))
stripper = vtkStripper()
stripper.SetInputConnection(cyber.GetOutputPort())
stripperMask = vtkMaskPolyData()
stripperMask.SetInputConnection(stripper.GetOutputPort())
stripperMask.SetOnRatio(2)
stripperMapper = vtkPolyDataMapper()
stripperMapper.SetInputConnection(stripperMask.GetOutputPort())
stripperActor = vtkActor()
stripperActor.SetMapper(stripperMapper)
stripperActor.GetProperty().SetColor(colors.GetColor3d('Flesh'))
# Add the actors to the renderer, set the background and size.
#
renderer1.AddActor(stripperActor)
renderer2.AddActor(cyberActor)
renderer1.SetBackground(colors.GetColor3d('Wheat'))
renderer2.SetBackground(colors.GetColor3d('Papaya_Whip'))
renderWindow.SetSize(1024, 640)
# Render the image.
#
cam1 = vtkCamera()
cam1.SetFocalPoint(0, 0, 0)
cam1.SetPosition(1, 0, 0)
cam1.SetViewUp(0, 1, 0)
renderer1.SetActiveCamera(cam1)
renderer2.SetActiveCamera(cam1)
renderer1.ResetCamera()
cam1.Azimuth(30)
cam1.Elevation(30)
cam1.Dolly(1.4)
renderer1.ResetCameraClippingRange()
interactor.Start()
def get_program_parameters():
import argparse
description = 'Triangle strip examples.'
epilogue = '''
a) Structured triangle mesh consisting of 134 strips each of 390 triangles (stripF.tcl).
b) Unstructured triangle mesh consisting of 2227 strips of average length 3.94,
longest strip 101 triangles.
Images are generated by displaying every other triangle strip (uStripeF.tcl).
'''
parser = argparse.ArgumentParser(description=description, epilog=epilogue,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('filename', help='fran_cut.vtk')
args = parser.parse_args()
return args.filename
if __name__ == '__main__':
main()