def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkTextureMapToCylinder(), 'Processing.', ('vtkDataSet',), ('vtkDataSet',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkTextureMapToCylinder(), 'Processing.', ('vtkDataSet', ), ('vtkDataSet', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def test_vtk_shananigans(self): sphere = vtk.vtkPointSource() sphere.SetNumberOfPoints(25) mesh = Mesh("data/wing_off_files/synth_wing_v3.off") # Triangulate the points with vtkDelaunay3D. This generates a convex hull # of tetrahedron. delny = vtk.vtkDelaunay3D() delny.SetInputConnection(sphere.GetOutputPort()) delny.SetTolerance(0.01) print(dir(mesh.pv_mesh)) # The triangulation has texture coordinates generated so we can map # a texture onto it. tmapper = vtk.vtkTextureMapToCylinder() tmapper.SetInputDataObject(mesh.pv_mesh.GetPointData().GetOutputPort()) tmapper.PreventSeamOn() # We scale the texture coordinate to get some repeat patterns. xform = vtk.vtkTransformTextureCoords() xform.SetInputConnection(tmapper.GetOutputPort()) xform.SetScale(4, 4, 1) # vtkDataSetMapper internally uses a vtkGeometryFilter to extract the # surface from the triangulation. The output (which is vtkPolyData) is # then passed to an internal vtkPolyDataMapper which does the # rendering. mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(xform.GetOutputPort()) # A texture is loaded using an image reader. Textures are simply images. # The texture is eventually associated with an actor. bmpReader = vtk.vtkPNGReader() bmpReader.SetFileName("data/textures/checkers.png") atext = vtk.vtkTexture() atext.SetInputConnection(bmpReader.GetOutputPort()) atext.InterpolateOn() triangulation = vtk.vtkActor() triangulation.SetMapper(mapper) triangulation.SetTexture(atext) # Create the standard rendering stuff. ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Add the actors to the renderer, set the background and size ren.AddActor(triangulation) ren.SetBackground(1, 1, 1) renWin.SetSize(300, 300) iren.Initialize() renWin.Render() iren.Start()
def assignTexture(actor, name, scale=1, falsecolors=False, mapTo=1): '''Assign a texture to actor from file or name in /textures directory''' if mapTo == 1: tmapper = vtk.vtkTextureMapToCylinder() elif mapTo == 2: tmapper = vtk.vtkTextureMapToSphere() elif mapTo == 3: tmapper = vtk.vtkTextureMapToPlane() setInput(tmapper, polydata(actor)) if mapTo == 1: tmapper.PreventSeamOn() xform = vtk.vtkTransformTextureCoords() xform.SetInputConnection(tmapper.GetOutputPort()) xform.SetScale(scale, scale, scale) if mapTo == 1: xform.FlipSOn() xform.Update() mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(xform.GetOutputPort()) mapper.ScalarVisibilityOff() cdir = os.path.dirname(__file__) if cdir == '': cdir = '.' fn = cdir + '/textures/' + name + ".jpg" if os.path.exists(name): fn = name elif not os.path.exists(fn): colors.printc(('Texture', name, 'not found in', cdir + '/textures'), 'r') colors.printc('Available textures:', c='m', end=' ') for ff in os.listdir(cdir + '/textures'): colors.printc(ff.split('.')[0], end=' ', c='m') print() return jpgReader = vtk.vtkJPEGReader() jpgReader.SetFileName(fn) atext = vtk.vtkTexture() atext.RepeatOn() atext.EdgeClampOff() atext.InterpolateOn() if falsecolors: atext.MapColorScalarsThroughLookupTableOn() atext.SetInputConnection(jpgReader.GetOutputPort()) actor.GetProperty().SetColor(1, 1, 1) actor.SetMapper(mapper) actor.SetTexture(atext)
from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() # Generate texture coordinates on a "random" sphere. # create some random points in a sphere # sphere = vtk.vtkPointSource() sphere.SetNumberOfPoints(25) # triangulate the points # del1 = vtk.vtkDelaunay3D() del1.SetInputConnection(sphere.GetOutputPort()) del1.SetTolerance(0.01) # texture map the sphere (using cylindrical coordinate system) # tmapper = vtk.vtkTextureMapToCylinder() tmapper.SetInputConnection(del1.GetOutputPort()) tmapper.PreventSeamOn() xform = vtk.vtkTransformTextureCoords() xform.SetInputConnection(tmapper.GetOutputPort()) xform.SetScale(4, 4, 1) mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(xform.GetOutputPort()) # load in the texture map and assign to actor # bmpReader = vtk.vtkBMPReader() bmpReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/masonry.bmp") atext = vtk.vtkTexture() atext.SetInputConnection(bmpReader.GetOutputPort()) atext.InterpolateOn() triangulation = vtk.vtkActor()
VTK_DATA_ROOT = vtkGetDataRoot() # Begin by generating 25 random points in the unit sphere. sphere = vtk.vtkPointSource() sphere.SetNumberOfPoints(25) # Triangulate the points with vtkDelaunay3D. This generates a convex hull # of tetrahedron. delny = vtk.vtkDelaunay3D() delny.SetInputConnection(sphere.GetOutputPort()) delny.SetTolerance(0.01) # The triangulation has texture coordinates generated so we can map # a texture onto it. tmapper = vtk.vtkTextureMapToCylinder() tmapper.SetInputConnection(delny.GetOutputPort()) tmapper.PreventSeamOn() # We scale the texture coordinate to get some repeat patterns. xform = vtk.vtkTransformTextureCoords() xform.SetInputConnection(tmapper.GetOutputPort()) xform.SetScale(4, 4, 1) # vtkDataSetMapper internally uses a vtkGeometryFilter to extract the # surface from the triangulation. The output (which is vtkPolyData) is # then passed to an internal vtkPolyDataMapper which does the # rendering. mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(xform.GetOutputPort())
actor2.SetMapper(mapper2) actor2.GetProperty().SetOpacity(0.8) actor2.GetProperty().SetAmbient(0.5) actor2.GetProperty().SetDiffuse(0.5) actor2.GetProperty().SetSpecular(1.0) actor2.GetProperty().SetSpecularPower(10.0) actor2.SetScale(1.2, 1.2, 0.8) actor2.AddPosition(100, 0, 0) actor2.GetProperty().SetColor(1.0, 0.0, 0.0) actor2.RotateX(90) actor2.RotateZ(90) # actor 3 #gen = vtk.vtkTextureMapToPlane() gen = vtk.vtkTextureMapToCylinder() #gen = vtk.vtkTextureMapToSphere() # gen.PreventSeamOn() gen.SetInputConnection(reader.GetOutputPort()) # gen.PreventSeamOn() xform = vtk.vtkTransformTextureCoords() xform.SetInputConnection(gen.GetOutputPort()) xform.SetScale(3, -3, 0) bmpReader = vtk.vtkBMPReader() bmpReader.SetFileName('bouteille.bmp') texture = vtk.vtkTexture() texture.SetInputConnection(bmpReader.GetOutputPort()) texture.InterpolateOn()
cylinder.SetRadius(4) cylinder.SetResolution(12) # Read the image data from a file reader = vtk.vtkJPEGReader() reader.SetFileName(jpegfile) # Create texture object texture = vtk.vtkTexture() if vtk.VTK_MAJOR_VERSION <= 5: texture.SetInput(reader.GetOutput()) else: texture.SetInputConnection(reader.GetOutputPort()) # Map texture coordinates map_to_cylinder = vtk.vtkTextureMapToCylinder() if vtk.VTK_MAJOR_VERSION <= 5: map_to_cylinder.SetInput(cylinder.GetOutput()) else: map_to_cylinder.SetInputConnection(cylinder.GetOutputPort()) map_to_cylinder.PreventSeamOn() # Create mapper and set the mapped texture as input mapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: mapper.SetInput(map_to_cylinder.GetOutput()) else: mapper.SetInputConnection(map_to_cylinder.GetOutputPort()) # Create actor and set the mapper and the texture actor = vtk.vtkActor()
def main(): # Read from file stlreader = vtk.vtkSTLReader() stlreader.SetFileName( r"D:\DT-cat_Synthetic_Data_Generation\vtk_generation\mino_3d_model\demo_part\F58001104949503200002.stl" ) tmapper = vtk.vtkTextureMapToCylinder() tmapper.SetInputConnection(stlreader.GetOutputPort()) tmapper.PreventSeamOn() xform = vtk.vtkTransformTextureCoords() xform.SetInputConnection(tmapper.GetOutputPort()) xform.SetScale(0.5, 0.5, 0.5) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(xform.GetOutputPort()) # A texture is loaded using an image reader. Textures are simply images. # The texture is eventually associated with an actor. #bmpReader = vtk.vtkBMPReader() #bmpReader.SetFileName("D:\DT-cat_Synthetic_Data_Generation\\texture\\2.bmp") #atext = vtk.vtkTexture() #atext.SetInputConnection(bmpReader.GetOutputPort()) #atext.InterpolateOn() cylinderActor = vtk.vtkActor() cylinderActor.RotateWXYZ(0, 1, 0, 0) cylinderActor.GetProperty().SetColor(0.2, 0.3, 0.7) cylinderActor.SetMapper( mapper) # 设置生成几何图元的Mapper。即连接一个Actor到可视化管线的末端(可视化管线的末端就是Mapper)。 #cylinderActor.SetTexture(atext) renderer = vtk.vtkRenderer() # 负责管理场景的渲染过程 renderer.AddActor(cylinderActor) light = vtk.vtkLight() light.SetPosition(400, 0, 00) renderer.AddLight(light) renderer.SetBackground(0.1, 0.2, 0.4) renWin = vtk.vtkRenderWindow() # 将操作系统与VTK渲染引擎连接到一起。 renWin.AddRenderer(renderer) renWin.SetSize(300, 300) iren = vtk.vtkRenderWindowInteractor() # 提供平台独立的响应鼠标、键盘和时钟事件的交互机制 iren.SetRenderWindow(renWin) # 交互器样式的一种,该样式下,用户是通过控制相机对物体作旋转、放大、缩小等操作 style = vtk.vtkInteractorStyleTrackballCamera() axes = vtk.vtkAxesActor() renderer.AddActor(axes) iren.SetInteractorStyle(style) iren.Initialize() iren.Start() # Clean up # del cylinder del stlreader del cylinderActor del renderer del renWin del iren