VTK草稿1

VTK是什么

實(shí)際上是基于OpenGL的圖形開發(fā)函數(shù)庫。

  • OpenGL + OOP
  • C++作為核心搂蜓, 有Tcl狼荞、Python、Java的接口
  • 支持多種數(shù)據(jù)類型
  • Open Source

VTK典型流程

** Data --> Geometry --> Image **

直觀流程
程序流程.png

左邊一縱列對(duì)應(yīng)Data --> Gemoetry
右邊一縱列對(duì)應(yīng)Gemotry --> Image

Data --> Geometry

包括vtkSource, vtkFilter, vtkMapper

  • vtkSource : 各類圖形的數(shù)字構(gòu)成帮碰,以及各種圖像文件的讀寫數(shù)據(jù)等
  • vtkFilter : 以數(shù)據(jù)對(duì)象作為輸入相味,輸出處理后的數(shù)據(jù)對(duì)象。實(shí)現(xiàn)各種圖像處理算法殉挽。
  • vtkMapper : 將Data轉(zhuǎn)換為Gemoetry數(shù)據(jù)丰涉,作為下一步顯示的圖形來源。vtkMapper接收Filter的輸入斯碌,但不產(chǎn)生輸出一死。整體作為下一步處理的基礎(chǔ)。

Geometry --> Image

包括vtkActor, vtkRenderer, vtkRenderWindow

Geometry --> Image
  • vtkActor : 代表了一個(gè)在場(chǎng)景中被渲染的物體傻唾,例如一個(gè)錐體或一個(gè)立方體投慈,自身可以設(shè)定多個(gè)屬性,如坐標(biāo)、旋轉(zhuǎn)角度伪煤、表明材質(zhì)加袋、反光效果、透明度等等
  • vtkRenderer : 負(fù)責(zé)渲染物體的進(jìn)程带族,可以設(shè)置顯示角度锁荔、光照角度等等屬性
  • vtkRenderWindow : 在操作系統(tǒng)上顯示的一個(gè)窗口,可以包含一個(gè)或者多個(gè)vtkRenderer蝙砌,上圖中左邊那個(gè)窗口中就有兩個(gè)Renderer

整體流水線

Pipeline.png

Example

/*=========================================================================

  Program:   Visualization Toolkit
  Module:    Cone.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
//
// This example creates a polygonal model of a cone, and then renders it to
// the screen. It will rotate the cone 360 degrees and then exit. The basic
// setup of source -> mapper -> actor -> renderer -> renderwindow is
// typical of most VTK programs.
//

// First include the required header files for the VTK classes we are using.
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"

int main()
{
  //
  // Next we create an instance of vtkConeSource and set some of its
  // properties. The instance of vtkConeSource "cone" is part of a
  // visualization pipeline (it is a source process object); it produces data
  // (output type is vtkPolyData) which other filters may process.
  //
  vtkConeSource *cone = vtkConeSource::New();
  cone->SetHeight( 3.0 );
  cone->SetRadius( 1.0 );
  cone->SetResolution( 10 );

  //
  // In this example we terminate the pipeline with a mapper process object.
  // (Intermediate filters such as vtkShrinkPolyData could be inserted in
  // between the source and the mapper.)  We create an instance of
  // vtkPolyDataMapper to map the polygonal data into graphics primitives. We
  // connect the output of the cone souece to the input of this mapper.
  //
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInputConnection( cone->GetOutputPort() );

  //
  // Create an actor to represent the cone. The actor orchestrates rendering
  // of the mapper's graphics primitives. An actor also refers to properties
  // via a vtkProperty instance, and includes an internal transformation
  // matrix. We set this actor's mapper to be coneMapper which we created
  // above.
  //
  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );

  //
  // Create the Renderer and assign actors to it. A renderer is like a
  // viewport. It is part or all of a window on the screen and it is
  // responsible for drawing the actors it has.  We also set the background
  // color here.
  //
  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->SetBackground( 0.1, 0.2, 0.4 );

  //
  // Finally we create the render window which will show up on the screen.
  // We put our renderer into the render window using AddRenderer. We also
  // set the size to be 300 pixels by 300.
  //
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 300, 300 );

  //
  // Now we loop over 360 degreeees and render the cone each time.
  //
  int i;
  for (i = 0; i < 360; ++i)
    {
    // render the image
    renWin->Render();
    // rotate the active camera by one degree
    ren1->GetActiveCamera()->Azimuth( 1 );
    }

  //
  // Free up any objects we created. All instances in VTK are deleted by
  // using the Delete() method.
  //
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  ren1->Delete();
  renWin->Delete();

  return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末阳堕,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子择克,更是在濱河造成了極大的恐慌恬总,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,843評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件肚邢,死亡現(xiàn)場(chǎng)離奇詭異壹堰,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)骡湖,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,538評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門贱纠,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人响蕴,你說我怎么就攤上這事谆焊。” “怎么了浦夷?”我有些...
    開封第一講書人閱讀 163,187評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵辖试,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我劈狐,道長(zhǎng)罐孝,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,264評(píng)論 1 292
  • 正文 為了忘掉前任肥缔,我火速辦了婚禮莲兢,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘续膳。我一直安慰自己怒见,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,289評(píng)論 6 390
  • 文/花漫 我一把揭開白布姑宽。 她就那樣靜靜地躺著,像睡著了一般闺阱。 火紅的嫁衣襯著肌膚如雪炮车。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,231評(píng)論 1 299
  • 那天,我揣著相機(jī)與錄音瘦穆,去河邊找鬼纪隙。 笑死,一個(gè)胖子當(dāng)著我的面吹牛扛或,可吹牛的內(nèi)容都是我干的绵咱。 我是一名探鬼主播,決...
    沈念sama閱讀 40,116評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼熙兔,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼悲伶!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起住涉,我...
    開封第一講書人閱讀 38,945評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤麸锉,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后舆声,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體花沉,經(jīng)...
    沈念sama閱讀 45,367評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,581評(píng)論 2 333
  • 正文 我和宋清朗相戀三年媳握,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了碱屁。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,754評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡蛾找,死狀恐怖娩脾,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情腋粥,我是刑警寧澤晦雨,帶...
    沈念sama閱讀 35,458評(píng)論 5 344
  • 正文 年R本政府宣布,位于F島的核電站隘冲,受9級(jí)特大地震影響闹瞧,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜展辞,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,068評(píng)論 3 327
  • 文/蒙蒙 一奥邮、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧罗珍,春花似錦洽腺、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,692評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至扣唱,卻和暖如春藕坯,著一層夾襖步出監(jiān)牢的瞬間团南,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,842評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工炼彪, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留吐根,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,797評(píng)論 2 369
  • 正文 我出身青樓辐马,卻偏偏與公主長(zhǎng)得像拷橘,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子喜爷,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,654評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容