zoukankan      html  css  js  c++  java
  • vtk类之vtkRotationalExtrusionFilter:建模筛选器, 它采用多边形数据作为输入,并生成输出的多边形数据

    vtkRotationalExtrusionFilter 是一个建模筛选器。它采用多边形数据作为输入,并生成输出的多边形数据。输入数据集是围绕 z 轴扫描出来的,以创建新的多边形基元。这些基元构成一个"裙边"或扫掠的曲面。例如,扫描一个线作为输入数据,环绕z轴扫描一圈就创建圆环的多边形的数据。

    此筛选器有许多参数可以设置。您可以控制是否 2D 对象 (即,多边形或三角地带) 的扫描上铺的生成几何通过"旋盖"的实例变量。另外,您可以控制旋转,角度和旋转以及是否执行沿 z 轴的平移。(平移是以创建类似"弹簧"的螺旋样式模型非常有用)。您还可以调整"DeltaRotation"来生成渐变的半径(形如始终发条模型)。

    这条裙子是由定位某些拓扑功能生成的。自由边 (多边形或仅由一个多边形或三角带使用三角形条带的边缘) 生成曲面。这是真正还的直线或折线。顶点生成行。

    此筛选器可用于模型轴对称的物体,如气瓶、 瓶、 和葡萄酒杯 ;或平移/旋转对称的物体,如弹簧或 corkscrews。

    基本方法:

    SetResolution() 设置生成瓶子表面的光滑度参数,瓶子的表面由多少个面构成
    SetAngle() 置旋转生产新的poly data的最大角度
    SetTranslation(0) 设置旋转产生沿着z轴方向,生产新的一列poly data 的时候,对该列沿着z方向的平移量,默认是0 不坐平移
    SetDeltaRadius(0) 设置旋转产生新的列polydata 的时候,在x-y平面上,向外围扩展半径长度,每列比上一列半径加2, 默认是0

    例:

    #-*- coding: UTF-8 -*-
    #-------------------------------------------------------------------------------
    # Name:        rotationalExtrusionFilterActorFactory package
    # Purpose:     测试 旋转filter
    #
    # Author:      ankier
    #
    # Created:     13-12-2012
    # Copyright:   (c) ankier 2012
    # Licence:     <Copyright©2004-2012 ankier>
    #-------------------------------------------------------------------------------
    
    from ActorFactory import ActorFactory 
    from glo import Global
    from vtk import *
    
    ## @brief 直线的actor factory
    class RotationalExtrusionFilterActorFactory(ActorFactory):
        def __init__(self):
            ActorFactory.__init__(self)
            self.__PolyDataPoints = vtkPoints()
            self.__PolyDataCells = vtkCellArray()
            self.__PolyData = vtkPolyData()
            self.__RotationalExtrusionFilter = vtkRotationalExtrusionFilter()
            self.__PolyDataMapper = vtkPolyDataMapper()
            self.__initialize()        
           
        def __del__(self):
            del self.__PolyDataPoints
            del self.__PolyDataCells
            del self.__PolyData
            del self.__RotationalExtrusionFilter
            del self.__PolyDataMapper
        
        def __initialize(self):
            #定义瓶子轮廓线的点坐标
            self.__PolyDataPoints.InsertPoint(0, 0.01,0.0,0.0)
            self.__PolyDataPoints.InsertPoint(1, 1.5,0.0,0.0)
            self.__PolyDataPoints.InsertPoint(2, 1.5,0.0,3.5)
            self.__PolyDataPoints.InsertPoint(3, 1.25,0.0,3.75)
            self.__PolyDataPoints.InsertPoint(4, 0.75,0.0,4.00)
            self.__PolyDataPoints.InsertPoint(5, 0.6,0.0,4.35)
            self.__PolyDataPoints.InsertPoint(6, 0.7,0.0,4.65)
            self.__PolyDataPoints.InsertPoint(7, 1.0,0.0,4.75)
            self.__PolyDataPoints.InsertPoint(8, 1.0,0.0,5.0)
            self.__PolyDataPoints.InsertPoint(9, 0.5,0.0,5.0)
            
            #构建线单元,绘制轮廓线
            self.__PolyDataCells.InsertNextCell(10)
            self.__PolyDataCells.InsertCellPoint(0)
            self.__PolyDataCells.InsertCellPoint(1)
            self.__PolyDataCells.InsertCellPoint(2)
            self.__PolyDataCells.InsertCellPoint(3)
            self.__PolyDataCells.InsertCellPoint(4)
            self.__PolyDataCells.InsertCellPoint(5)
            self.__PolyDataCells.InsertCellPoint(6)
            self.__PolyDataCells.InsertCellPoint(7)
            self.__PolyDataCells.InsertCellPoint(8)
            self.__PolyDataCells.InsertCellPoint(9)
            
            #使用点集合和 cell集合组成poly data
            self.__PolyData.SetPoints(self.__PolyDataPoints)
            self.__PolyData.SetLines(self.__PolyDataCells)
            
            #压制轮廓线,形成瓶子实体
            self.__RotationalExtrusionFilter.SetInput(self.__PolyData)
            
            #设置生成瓶子表面的光滑度参数,瓶子的表面由多少个面构成
            self.__RotationalExtrusionFilter.SetResolution(10)
            
            #设置旋转生产新的poly data的最大角度
            #self.__RotationalExtrusionFilter.SetAngle(90)
            
            #设置旋转产生沿着z轴方向,生产新的一列poly data 的时候,对该列沿着z方向的平移量,默认是0 不坐平移
            self.__RotationalExtrusionFilter.SetTranslation(0)
            
            #设置旋转产生新的列polydata 的时候,在x-y平面上,向外围扩展半径长度,每列比上一列半径加2, 默认是0
            self.__RotationalExtrusionFilter.SetDeltaRadius(0)
            self.__PolyDataMapper.SetInput(self.__RotationalExtrusionFilter.GetOutput())
            
    
        
        ## @brief 更新线的poly data
        def __UpdateData(self):
            pass
           
        
        ## @brief 重写基类方法
        #  see    ActorFactory._MakeActors
        def _MakeActors(self):
            actor = self._NewActor()
            actor.SetMapper(self.__PolyDataMapper)
            actor.GetProperty().SetColor((0.1, 0.1, 0.5))
            return [actor]
            
            

    运行效果:

     如果以如下3个点作为filter的输入,

    修改初始化函数如下:

    def __initialize(self):
            #定义瓶子轮廓线的点坐标
            self.__PolyDataPoints.InsertPoint(0, 1.0,0.0,0.0)
            self.__PolyDataPoints.InsertPoint(1, 1,0.0, 0.5)
            self.__PolyDataPoints.InsertPoint(2, 1,0.0, 1)
    
            #构建线单元,绘制轮廓线
            self.__PolyDataCells.InsertNextCell(3)
            self.__PolyDataCells.InsertCellPoint(0)
            self.__PolyDataCells.InsertCellPoint(1)
            self.__PolyDataCells.InsertCellPoint(2)
    
            #使用点集合和 cell集合组成poly data
            self.__PolyData.SetPoints(self.__PolyDataPoints)
            self.__PolyData.SetLines(self.__PolyDataCells)
            
            #压制轮廓线,形成瓶子实体
            self.__RotationalExtrusionFilter.SetInput(self.__PolyData)
            
            #设置生成瓶子表面的光滑度参数,瓶子的表面由多少个面构成
            self.__RotationalExtrusionFilter.SetResolution(1000)
            
            #设置旋转生产新的poly data的最大角度
            self.__RotationalExtrusionFilter.SetAngle(760)
            
            #设置旋转产生沿着z轴方向,生产新的一列poly data 的时候,对该列沿着z方向的平移量,默认是0 不坐平移
            self.__RotationalExtrusionFilter.SetTranslation(0)
            
            #设置旋转产生新的列polydata 的时候,在x-y平面上,向外围扩展半径长度,每列比上一列半径加2, 默认是0
            self.__RotationalExtrusionFilter.SetDeltaRadius(2)
            self.__PolyDataMapper.SetInput(self.__RotationalExtrusionFilter.GetOutput())

    运行效果如下:

  • 相关阅读:
    抽取一个简单的按钮方法
    一些iOS笔试题目
    使用第三方框架 Masonry 实现自动布局
    AutoLayout适配
    iOS面试小题集锦
    大牛们的技术博客
    5、过滤流
    3、过滤文件夹
    1、File类简介
    贪婪模式和非贪婪模式
  • 原文地址:https://www.cnblogs.com/ankier/p/2816881.html
Copyright © 2011-2022 走看看