欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何使用Python?VTK高亮顯示actor

 更新時間:2022年04月18日 13:41:29   作者:派大大大星  
這篇文章主要介紹了如何使用Python?VTK高亮顯示actor,通過Python-VTK在同一個窗口中,高亮顯示選中的actor。本例子中的代碼,當窗口中的圓球actor被選中時,會變成紅色,并且會顯示actor三遍面片邊緣信息,下文相關內容需要的小伙伴可以參考一下

前言:

VTK,(visualizationtoolkit)是一個開放資源的免費軟件系統(tǒng),主要用于三維計算機圖形學、圖像處理和可視化。Vtk是在面向對象原理的基礎上設計和實現的,它的內核是用C++構建的,包含有大約250,000行代碼,2000多個類,還包含有幾個轉換界面,因此也可以自由的通過Java,Tcl/Tk和Python各種語言使用vtk。

主要函數介紹:

NewPickedActor.GetProperty(): 通過該函數,可以設置actor的性質,如顏色、表面樣式等。

vtk.vtkSphereSource(): 創(chuàng)建球體的函數,文中通過一個for循環(huán)創(chuàng)建了10個球體。

vtk.vtkMinimalStandardRandomSequence(): VTK的隨機數生成器,用于代碼中的十個球體,隨機生成球體的大小和位置。

MouseInteractorHighLightActor: 定義actor操作方法,這個是一個鼠標操作控件的控制方法。

leftButtonPressEvent(self, obj, event): 這是一個事件觸發(fā)函數,當鼠標左鍵點擊對應的actor時,會觸發(fā)函數,對點的actor高亮顯示。

主要代碼如下:

#!/usr/bin/env python

# noinspection PyUnresolvedReferences
import vtk

colors = vtk.vtkNamedColors()
NUMBER_OF_SPHERES = 10


class MouseInteractorHighLightActor(vtk.vtkInteractorStyleTrackballCamera):

    def __init__(self, parent=None):
        self.AddObserver("LeftButtonPressEvent", self.leftButtonPressEvent)

        self.LastPickedActor = None
        self.LastPickedProperty = vtk.vtkProperty()

    def leftButtonPressEvent(self, obj, event):
        clickPos = self.GetInteractor().GetEventPosition()

        picker = vtk.vtkPropPicker()
        picker.Pick(clickPos[0], clickPos[1], 0, self.GetDefaultRenderer())

        # 創(chuàng)建一個新的actor
        self.NewPickedActor = picker.GetActor()

        # If something was selected
        if self.NewPickedActor:
            # If we picked something before, reset its property
            if self.LastPickedActor:
                self.LastPickedActor.GetProperty().DeepCopy(self.LastPickedProperty)

            # Save the property of the picked actor so that we can
            # restore it next time
            self.LastPickedProperty.DeepCopy(self.NewPickedActor.GetProperty())
            # 高亮選中球體,并顯示邊緣
            self.NewPickedActor.GetProperty().SetColor(colors.GetColor3d('Red'))
            self.NewPickedActor.GetProperty().SetDiffuse(1.0)
            self.NewPickedActor.GetProperty().SetSpecular(0.0)
            self.NewPickedActor.GetProperty().EdgeVisibilityOn()

            # 保存最后一個選中的actor
            self.LastPickedActor = self.NewPickedActor

        self.OnLeftButtonDown()
        return


def main():
    # 創(chuàng)建render和window
    renderer = vtk.vtkRenderer()
    renderer.SetBackground(colors.GetColor3d('SteelBlue'))

    renwin = vtk.vtkRenderWindow()
    renwin.AddRenderer(renderer)
    renwin.SetSize(640, 480)
    renwin.SetWindowName('HighlightPickedActor')

    # 建立interactor(交互操作)
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renwin)

    # 交互操作方法
    style = MouseInteractorHighLightActor()
    style.SetDefaultRenderer(renderer)
    interactor.SetInteractorStyle(style)

    randomSequence = vtk.vtkMinimalStandardRandomSequence()
    # randomSequence.SetSeed(1043618065)
    # randomSequence.SetSeed(5170)
    randomSequence.SetSeed(8775070)
    # 添加球體
    for i in range(NUMBER_OF_SPHERES):
        source = vtk.vtkSphereSource()

        # random position and radius
        x = randomSequence.GetRangeValue(-5.0, 5.0)
        randomSequence.Next()
        y = randomSequence.GetRangeValue(-5.0, 5.0)
        randomSequence.Next()
        z = randomSequence.GetRangeValue(-5.0, 5.0)
        randomSequence.Next()
        radius = randomSequence.GetRangeValue(0.5, 1.0)
        randomSequence.Next()

        source.SetRadius(radius)
        source.SetCenter(x, y, z)
        source.SetPhiResolution(11)
        source.SetThetaResolution(21)

        mapper = vtk.vtkPolyDataMapper()
        mapper.SetInputConnection(source.GetOutputPort())
        actor = vtk.vtkActor()
        actor.SetMapper(mapper)

        r = randomSequence.GetRangeValue(0.4, 1.0)
        randomSequence.Next()
        g = randomSequence.GetRangeValue(0.4, 1.0)
        randomSequence.Next()
        b = randomSequence.GetRangeValue(0.4, 1.0)
        randomSequence.Next()

        actor.GetProperty().SetDiffuseColor(r, g, b)
        actor.GetProperty().SetDiffuse(.8)
        actor.GetProperty().SetSpecular(.5)
        actor.GetProperty().SetSpecularColor(colors.GetColor3d('White'))
        actor.GetProperty().SetSpecularPower(30.0)

        renderer.AddActor(actor)

    # 運行
    interactor.Initialize()
    renwin.Render()
    interactor.Start()


if __name__ == '__main__':
    main()

顯示結果如下: 未選擇球體: 

image.png

已選取球體后: 

image.png

到此這篇關于如何使用Python VTK高亮顯示actor的文章就介紹到這了,更多相關Python VTK高亮顯示actor內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • tensorflow 初始化未初始化的變量實例

    tensorflow 初始化未初始化的變量實例

    今天小編就為大家分享一篇tensorflow 初始化未初始化的變量實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • python3.7 使用pymssql往sqlserver插入數據的方法

    python3.7 使用pymssql往sqlserver插入數據的方法

    這篇文章主要介紹了python3.7 使用pymssql往sqlserver插入數據的方法,代碼很簡單,感興趣的朋友跟隨小編一起看看吧
    2019-07-07
  • Python中Selenium模擬JQuery滑動解鎖實例

    Python中Selenium模擬JQuery滑動解鎖實例

    這篇文章主要介紹了Python中Selenium模擬JQuery滑動解鎖實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Python元類的進階應用深度探索

    Python元類的進階應用深度探索

    這篇文章主要介紹了Python元類的進階應用深度探索,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-06-06
  • Python實現快速將pdf文件剪切成多個圖片

    Python實現快速將pdf文件剪切成多個圖片

    這篇文章主要為大家詳細介紹了如何使用Python實現快速將pdf文件剪切成多個圖片,文中的示例代碼講解詳細,有需要的小伙伴可以跟隨小編一起學習一下
    2024-01-01
  • 用python打印菱形的實操方法和代碼

    用python打印菱形的實操方法和代碼

    在本篇文章里小編給大家分享了關于用python打印菱形的實操方法和代碼,對此有需要的朋友們可以學習下。
    2019-06-06
  • python利用beautifulSoup實現爬蟲

    python利用beautifulSoup實現爬蟲

    這篇文章主要介紹了python利用beautifulSoup實現爬蟲,需要的朋友可以參考下
    2014-09-09
  • Python 獲取命令行參數內容及參數個數的實例

    Python 獲取命令行參數內容及參數個數的實例

    今天小編就為大家分享一篇Python 獲取命令行參數內容及參數個數的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • python asyncio 協(xié)程庫的使用

    python asyncio 協(xié)程庫的使用

    這篇文章主要介紹了python asyncio 協(xié)程庫的使用,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2021-01-01
  • Django使用原生SQL查詢數據庫詳解

    Django使用原生SQL查詢數據庫詳解

    本文介紹了Django ORM的優(yōu)缺點,然后介紹了使用原生SQL進行查詢的優(yōu)點,包括更靈活、更高效等。接著介紹了如何在Django中使用原生SQL進行查詢,包括利用Django的connection對象進行查詢以及使用Django的CursorWrapper類進行封裝。最后提醒了使用原生SQL查詢的注意事項。
    2023-04-04

最新評論