• vtk类之vtkPlaneSource:创建一个平面的poly data


    vtkPlaneSource

    创建一个平面的四边形的数组。
    vtkPlaneSource创建一个m×n阵列表示的一个平面上的四边形。改平面指通过指定一个起点,然后和其他两个点,定义了两个轴的向量。这两个向量不一定是正交的,但是必须不平行的一个四边形。 可以控制的ivars XResolution和YResolution来调节平面的分辨率(即,细分数)。
    缺省情况下,平面的中心在原点并垂直于z轴,长度为1和分辨率设置为1的宽度和高度。
    有三种方便的方法,让您可以轻松设置平面。第一,SetNormal(),允许指定平面的法向量。沿着法向量旋转平面。第二,SetCenter(),平移到指定的中心点。第三种方法,Push(),可以让你沿着平面法向量平移一定的距离。

    基本用法:

    1. 使用 SetOrigin() SetPoint1() 和SetPoint2()确定不在一条直线上的三个点,决定一个四边形平面。

    2. 使用SetCenter(), SetNormal()和 Push()等 对平面的空间位置做旋转,平移等变换。

    例子:

    #-*- coding: UTF-8 -*-
    #-------------------------------------------------------------------------------
    # Name:        planeActorFactory package
    # Purpose:     创建一条平面的
    #
    # Author:      ankier
    #
    # Created:     12-12-2012
    # Copyright:   (c) ankier 2012
    # Licence:     <your licence>
    #-------------------------------------------------------------------------------
    
    from ActorFactory import ActorFactory 
    from glo import Global
    from vtk import *
    
    ## @brief 直线的actor factory
    class PlaneActorFactory(ActorFactory):
        def __init__(self):
            ActorFactory.__init__(self)
            self.__PlaneSource = vtkPlaneSource()
            
           
        def __del__(self):
            del self.__PlaneSource
        
        ## @brief 更新线的poly data
        def __UpdateData(self):
            globalInstance = Global.GetInstance()   
            self.__PlaneSource.SetOrigin(-50, -50, 0)
            self.__PlaneSource.SetPoint1(50, -50 , 0)
            self.__PlaneSource.SetPoint2(-50 , 50 , 0) 
            self.__PlaneSource.SetXResolution(50)
            self.__PlaneSource.SetYResolution(50)
        
        ## @brief 平移平面 到指定的position 位置
        def SetCenter(self, position):
            self.__PlaneSource.SetCenter(position[0], position[1], position[2])    
            
        def GetCenter(self):
            return self.__PlaneSource.GetCenter()
        
        ## @brief 设置平面 新的法向量
        def SetNormal(self, normal):
            self.__PlaneSource.SetNormal(normal[0], normal[1], normal[2])
        
        ## @brief 沿着平面的法向量方向上, 移动distance距离   
        def Push(self, distance):
            self.__PlaneSource.Push(distance)
            
        def GetNormal(self):
            return self.__PlaneSource.GetNormal()
        
        ## @brief 重写基类方法
        #  see    ActorFactory._MakeActors
        def _MakeActors(self): 
            self.__UpdateData()       
            polyDataMapper = vtkPolyDataMapper()
            polyDataMapper.SetInputConnection(self.__PlaneSource.GetOutputPort())
            actor = self._NewActor()
            actor.SetMapper(polyDataMapper)
            actor.GetProperty().SetColor((1, 0.1, 0.5))
            del polyDataMapper
            return [actor]
            
            

    运行效果:

  • 相关阅读:
    jquery $.post specification
    鸟语2010.5.5
    不使用ubuntu代理
    how to check network's stablity?
    python float decimal issue
    how to check network's stablity?
    session的作用是什么?
    bottle json issure
    我强烈建议,不要想念komdo的ctrl+r
    how to count files in directory
  • 原文地址:https://www.cnblogs.com/ankier/p/2811837.html
Copyright © 2020-2023  润新知