vtk类之vtkTextureMapToCylinder:纹理映射算法, 映射圆柱体纹理

产生映射点集合到圆柱体表面的纹理坐标

vtkTextureMapToCylinder是一个筛选器,将 2D 纹理坐标生成映射输入的纹理数据集点至一个圆柱体上。范围可以是用户指定或自动生成的。(圆柱体是由自动生成计算圆柱体的中心 )。请注意生成的纹理坐标 (0,1) 之间的范围。 

实例:

#-*- coding: UTF-8 -*-
#-------------------------------------------------------------------------------
# Name:        模块2
# Purpose:
#
# Author:      ankier
#
# Created:     06-01-2013
# Copyright:   (c) Ankier 2013
# Licence:     <your licence>
#-------------------------------------------------------------------------------
from ActorFactory import ActorFactory

from vtk import *

class TextureMapToCylinderActorFactory(ActorFactory):
    def __init__(self):
        ActorFactory.__init__(self)
        
        self.__SphereSource = vtkSphereSource()
        self.__SphereSource.SetThetaResolution(100)
        self.__SphereSource.SetPhiResolution(100)
        self.__SphereSource.SetRadius(10)
        
        #定义一个板子
        plane1 = vtkPlane()
        plane1.SetNormal(0, 0, 1)
        plane1.SetOrigin(0, 0, 8)
        
        #定义clip poly data
        clipper = vtkClipPolyData()
        clipper.SetInputConnection(self.__SphereSource.GetOutputPort())
        clipper.SetClipFunction(plane1)
        clipper.InsideOutOff()
        
        #多边形化集合数据
        normals = vtkPolyDataNormals()
        normals.SetInputConnection(clipper.GetOutputPort())
        normals.FlipNormalsOn()
        
        tmapper = vtkTextureMapToCylinder()
        tmapper.SetInput(normals.GetOutput())
        tmapper.PreventSeamOn()
        
        xform=vtkTransformTextureCoords()
        xform.SetInputConnection(tmapper.GetOutputPort())
        xform.SetScale( 1, 1, 1)
        
        
        #设置Poly Data,从纹理映射器重,得到被filter的输出数据
        self.__PolyDataMapper = vtkPolyDataMapper()
        self.__PolyDataMapper.SetInput(xform.GetOutput())
        
        
        #设置纹理类。
        self.__Texture = vtkTexture()
        self.__Texture.InterpolateOn()
    
    def __ReadJPEG(self):
        read = vtkJPEGReader()
        read.SetFileName("D:\\girl.jpg")
        self.__Texture.SetInput(read.GetOutput())
        
    
    def __del__(self):
        del self.__SphereSource 
        
        del self.__PolyDataMapper
        del self.__Texture
        
        
        
    
    def _MakeActors(self):
        self.__ReadJPEG()
        actor = self._NewActor()
        actor.SetMapper(self.__PolyDataMapper)
        actor.SetTexture(self.__Texture)
        return [actor]
                                                                                    

运行结果:

posted on 2013-01-06 21:25  |残阳|露  阅读(795)  评论(0编辑  收藏  举报

导航