2018-01-12:VTK相關(guān)資源列表

官方文檔:https://www.vtk.org/doc/nightly/html/index.html
VTK相關(guān)實(shí)例:https://lorensen.github.io/VTKExamples/site/Python/
VTK源碼倉(cāng)庫(kù):https://github.com/Kitware/VTK


基于Anaconda安裝Python3.6版本的VTK7.1.0:

conda install -c clinicalgraphics vtk=7.1.0

基于ROS-Kinetic-Desktop-Full的VTK6.2
只需要完整安裝了ros-kinetic,那么就會(huì)自動(dòng)安裝好VTK6.2版本的.

一條命令就安裝好了VTK的Python開發(fā)環(huán)境.
現(xiàn)在,我們來(lái)通過(guò)VTK版本的hello world實(shí)例來(lái)測(cè)試是否安裝成功.
vtk_01.py

import vtk
# The colors module defines various useful colors.
from vtk.util.colors import tomato

# This creates a polygonal cylinder model with eight circumferential
# facets.
cylinder = vtk.vtkCylinderSource()
cylinder.SetResolution(8)

# The mapper is responsible for pushing the geometry into the graphics
# library. It may also do color mapping, if scalars or other
# attributes are defined.
cylinderMapper = vtk.vtkPolyDataMapper()
cylinderMapper.SetInputConnection(cylinder.GetOutputPort())

# The actor is a grouping mechanism: besides the geometry (mapper), it
# also has a property, transformation matrix, and/or texture map.
# Here we set its color and rotate it -22.5 degrees.
cylinderActor = vtk.vtkActor()
cylinderActor.SetMapper(cylinderMapper)
cylinderActor.GetProperty().SetColor(tomato)
cylinderActor.RotateX(30.0)
cylinderActor.RotateY(-45.0)

# Create the graphics structure. The renderer renders into the render
# window. The render window interactor captures mouse events and will
# perform appropriate camera or actor manipulation depending on the
# nature of the events.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Add the actors to the renderer, set the background and size
ren.AddActor(cylinderActor)
ren.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(200, 200)

# This allows the interactor to initalize itself. It has to be
# called before an event loop.
iren.Initialize()

# We'll zoom in a little by accessing the camera and invoking a "Zoom"
# method on it.
ren.ResetCamera()
ren.GetActiveCamera().Zoom(1.5)
renWin.Render()

# Start the event loop.
iren.Start()

運(yùn)行結(jié)果為:


Screenshot from 2018-01-12 09-11-43.png

可以看出旨巷,我們運(yùn)行成功了.

Python版本的實(shí)例運(yùn)行成功橄杨,現(xiàn)在我們來(lái)實(shí)現(xiàn)基于c++版本的.
vtk_01.cpp

#include <vtkCylinderSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkSmartPointer.h>

int main(int, char *[])
{
  // This creates a polygonal cylinder model with eight circumferential facets
  // (i.e, in practice an octagonal prism).
  vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
  cylinder->SetResolution(8);

  // The mapper is responsible for pushing the geometry into the graphics library.
  // It may also do color mapping, if scalars or other attributes are defined.
  vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

  // The actor is a grouping mechanism: besides the geometry (mapper), it
  // also has a property, transformation matrix, and/or texture map.
  // Here we set its color and rotate it around the X and Y axes.
  vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
  cylinderActor->SetMapper(cylinderMapper);
  cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
  cylinderActor->RotateX(30.0);
  cylinderActor->RotateY(-45.0);

  // The renderer generates the image
  // which is then displayed on the render window.
  // It can be thought of as a scene to which the actor is added
  vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(cylinderActor);
  renderer->SetBackground(0.1, 0.2, 0.4);
  // Zoom in a little by accessing the camera and invoking its "Zoom" method.
  renderer->ResetCamera();
  renderer->GetActiveCamera()->Zoom(1.5);

  // The render window is the actual GUI window
  // that appears on the computer screen
  vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->SetSize(200, 200);
  renderWindow->AddRenderer(renderer);

  // The render window interactor captures mouse events
  // and will perform appropriate camera or actor manipulation
  // depending on the nature of the events.
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // This starts the event loop and as a side effect causes an initial render.
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

接著編寫CMakeLists.txt文件
CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(CylinderRenderingProperties)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(CylinderRenderingProperties main.cpp )

target_link_libraries(CylinderRenderingProperties ${VTK_LIBRARIES})

最終運(yùn)行的結(jié)果跟Python版本實(shí)現(xiàn)的是一樣的猜极,這里就不再截圖.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末秋秤,一起剝皮案震驚了整個(gè)濱河市拖刃,隨后出現(xiàn)的幾起案子址貌,更是在濱河造成了極大的恐慌铐拐,老刑警劉巖徘键,帶你破解...
    沈念sama閱讀 216,544評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異遍蟋,居然都是意外死亡吹害,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,430評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門虚青,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)它呀,“玉大人,你說(shuō)我怎么就攤上這事棒厘∽荽” “怎么了?”我有些...
    開封第一講書人閱讀 162,764評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵奢人,是天一觀的道長(zhǎng)谓媒。 經(jīng)常有香客問(wèn)我,道長(zhǎng)何乎,這世上最難降的妖魔是什么句惯? 我笑而不...
    開封第一講書人閱讀 58,193評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮支救,結(jié)果婚禮上抢野,老公的妹妹穿的比我還像新娘。我一直安慰自己各墨,他們只是感情好指孤,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,216評(píng)論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著贬堵,像睡著了一般邓厕。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上扁瓢,一...
    開封第一講書人閱讀 51,182評(píng)論 1 299
  • 那天,我揣著相機(jī)與錄音补君,去河邊找鬼引几。 笑死,一個(gè)胖子當(dāng)著我的面吹牛挽铁,可吹牛的內(nèi)容都是我干的伟桅。 我是一名探鬼主播,決...
    沈念sama閱讀 40,063評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼叽掘,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼楣铁!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起更扁,我...
    開封第一講書人閱讀 38,917評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤盖腕,失蹤者是張志新(化名)和其女友劉穎赫冬,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體溃列,經(jīng)...
    沈念sama閱讀 45,329評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡劲厌,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,543評(píng)論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了听隐。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片补鼻。...
    茶點(diǎn)故事閱讀 39,722評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖雅任,靈堂內(nèi)的尸體忽然破棺而出风范,到底是詐尸還是另有隱情,我是刑警寧澤沪么,帶...
    沈念sama閱讀 35,425評(píng)論 5 343
  • 正文 年R本政府宣布硼婿,位于F島的核電站,受9級(jí)特大地震影響成玫,放射性物質(zhì)發(fā)生泄漏加酵。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,019評(píng)論 3 326
  • 文/蒙蒙 一哭当、第九天 我趴在偏房一處隱蔽的房頂上張望猪腕。 院中可真熱鬧,春花似錦钦勘、人聲如沸陋葡。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,671評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)腐缤。三九已至,卻和暖如春肛响,著一層夾襖步出監(jiān)牢的瞬間岭粤,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,825評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工特笋, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留剃浇,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,729評(píng)論 2 368
  • 正文 我出身青樓猎物,卻偏偏與公主長(zhǎng)得像虎囚,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子蔫磨,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,614評(píng)論 2 353