• vtk类之vtkTextureMapToSphere:纹理映射算法, 映射球体纹理


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

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

    特别的伊娃控制 s 坐标如何生成的。如果将 PreventSeam 设置为 true,s-纹理异 0-> 1,然后 1-> 0 (对应于角度 0-> 180 和 180-> 360)。
    使用流程:
    1. 球体的PolyData
    2. 为该球体polyData应用,映射算法过滤器 vtkTextureMapToSphere 
    3. 生产新的mapper,连接Input为vtkTextureMapToSphere的输出,
    4. 产生新的actor,即是映射后的图像。
    例子:
    #-*- coding: UTF-8 -*-
    #-------------------------------------------------------------------------------
    # Name:        模块2
    # Purpose:
    #
    # Author:      ankier
    #
    # Created:     06-01-2013
    # Copyright:   (c) Ankier 2012
    # Licence:     <your licence>
    #-------------------------------------------------------------------------------
    from ActorFactory import ActorFactory
    
    from vtk import *
    
    class TextureMapToShpereActorFactory(ActorFactory):
        def __init__(self):
            ActorFactory.__init__(self)
            
            self.__SphereSource = vtkSphereSource()
            self.__SphereSource.SetThetaResolution(12)
            self.__SphereSource.SetPhiResolution(12)
            
            self.__TextureMapToSphere = vtkTextureMapToSphere()
            
            #设置被映射的polydata
            self.__TextureMapToSphere.SetInput(self.__SphereSource.GetOutput())
            self.__TextureMapToSphere.PreventSeamOn()
            
            #设置Poly Data,从纹理映射器重,得到被filter的输出数据
            self.__PolyDataMapper = vtkPolyDataMapper()
            self.__PolyDataMapper.SetInput(self.__TextureMapToSphere.GetOutput())
            
            
            #设置纹理类。
            self.__Texture = vtkTexture()
        
        def __ReadJPEG(self):
            read = vtkJPEGReader()
            read.SetFileName("D:\\girl.jpg")
            self.__Texture.SetInput(read.GetOutput())
            
        
        def __del__(self):
            del self.__SphereSource 
            del self.__TextureMapToSphere
            del self.__TextureMapToSphere
            del self.__PolyDataMapper
            del self.__Texture
            
            
            
        
        def _MakeActors(self):
            self.__ReadJPEG()
            actor = self._NewActor()
            actor.SetMapper(self.__PolyDataMapper)
            actor.SetTexture(self.__Texture)
            return [actor]
            

    运行结果:

     

  • 相关阅读:
    Docker 清理命令汇总
    Apache2.4.x版wampserver本地php服务器如何让外网访问及启用.htaccess
    github访问受限,通过更改host进行直接访问
    Python开发qq批量登陆
    Window安装Anaconda后,conda不是内部或者外部命令
    linux清空文件夹命令问题
    discuz添加管理员,找回管理员方法
    discuz论坛模板文件目录
    PyCharm创建文件时自动添加头注释
    python跳一跳辅助学习
  • 原文地址:https://www.cnblogs.com/ankier/p/2848282.html
Copyright © 2020-2023  润新知