日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

VTK笔记-图形相关-圆锥体-vtkConeSoure类

發布時間:2024/1/8 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VTK笔记-图形相关-圆锥体-vtkConeSoure类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

圓錐體

文章目錄

  • 圓錐體
  • 前言
  • 一、代碼
    • 1.1流程
  • 二、遇到的問題
    • 1.運行時異常
    • 2.在ThinkPad E530C筆記本上出現的異常
    • 3.運行結果
  • 三、相機旋轉
  • 四、vtkConeSource
    • 4.1類圖
    • 4.2常用接口說明
  • 五、資料

前言

使用VTK構建一個圓錐體展示;
執行的具體步驟為:
1.創建一個vtkConeSoure類的實例cone;
表示一個圓錐(正棱錐,有棱數目),有三個屬性:高度、半徑、分辨率(棱數目);
2.創建一個映射器,vtkPolyDataMapper實例;
cone的輸出可以作為映射器的輸入,
vtk中使用GetOutputPort()作為輸出;
VTK常見使用方法:將一個對象的輸出當另一個對象的輸入;
常見用來作為數據流的處理:將多個對象串聯在一起形成一條鏈,稱之為可視化流水線;
3.渲染部分
通過方法SetMapper將vtkActor對象和映射器關聯在一起;之后渲染過程暫時省略,在以后的部分單獨說明;

一、代碼

#include "vtkConeSource.h" #include "vtkPolyDataMapper.h" #include "vtkRenderWindow.h" #include "vtkActor.h" #include "vtkRenderer.h" #include "vtkAutoInit.h" #include "vtkAutoInit.h" VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2 VTK_MODULE_INIT(vtkInteractionStyle); int main() {vtkConeSource *cone = vtkConeSource::New();cone->SetHeight(3.0);cone->SetRadius(1.0);cone->SetResolution(10);vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();coneMapper->SetInputConnection(cone->GetOutputPort());vtkActor *coneActor = vtkActor::New();coneActor->SetMapper(coneMapper);vtkRenderer *ren1 = vtkRenderer::New();ren1->AddActor(coneActor);ren1->SetBackground(0.1, 0.2, 0.4);vtkRenderWindow *renWin = vtkRenderWindow::New();renWin->AddRenderer(ren1);renWin->SetSize(300, 300);for (size_t i = 0; i < 360; i++){renWin->Render();}cone->Delete();coneMapper->Delete();coneActor->Delete();ren1->Delete();renWin->Delete(); }

1.1流程

#mermaid-svg-w8260LfJzGzxFn1O .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-w8260LfJzGzxFn1O .label text{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .node rect,#mermaid-svg-w8260LfJzGzxFn1O .node circle,#mermaid-svg-w8260LfJzGzxFn1O .node ellipse,#mermaid-svg-w8260LfJzGzxFn1O .node polygon,#mermaid-svg-w8260LfJzGzxFn1O .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-w8260LfJzGzxFn1O .node .label{text-align:center;fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .node.clickable{cursor:pointer}#mermaid-svg-w8260LfJzGzxFn1O .arrowheadPath{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-w8260LfJzGzxFn1O .flowchart-link{stroke:#333;fill:none}#mermaid-svg-w8260LfJzGzxFn1O .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-w8260LfJzGzxFn1O .edgeLabel rect{opacity:0.9}#mermaid-svg-w8260LfJzGzxFn1O .edgeLabel span{color:#333}#mermaid-svg-w8260LfJzGzxFn1O .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-w8260LfJzGzxFn1O .cluster text{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-w8260LfJzGzxFn1O .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-w8260LfJzGzxFn1O text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-w8260LfJzGzxFn1O .actor-line{stroke:grey}#mermaid-svg-w8260LfJzGzxFn1O .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-w8260LfJzGzxFn1O .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-w8260LfJzGzxFn1O #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-w8260LfJzGzxFn1O .sequenceNumber{fill:#fff}#mermaid-svg-w8260LfJzGzxFn1O #sequencenumber{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O #crosshead path{fill:#333;stroke:#333}#mermaid-svg-w8260LfJzGzxFn1O .messageText{fill:#333;stroke:#333}#mermaid-svg-w8260LfJzGzxFn1O .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-w8260LfJzGzxFn1O .labelText,#mermaid-svg-w8260LfJzGzxFn1O .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-w8260LfJzGzxFn1O .loopText,#mermaid-svg-w8260LfJzGzxFn1O .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-w8260LfJzGzxFn1O .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-w8260LfJzGzxFn1O .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-w8260LfJzGzxFn1O .noteText,#mermaid-svg-w8260LfJzGzxFn1O .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-w8260LfJzGzxFn1O .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-w8260LfJzGzxFn1O .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-w8260LfJzGzxFn1O .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-w8260LfJzGzxFn1O .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O .section{stroke:none;opacity:0.2}#mermaid-svg-w8260LfJzGzxFn1O .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-w8260LfJzGzxFn1O .section2{fill:#fff400}#mermaid-svg-w8260LfJzGzxFn1O .section1,#mermaid-svg-w8260LfJzGzxFn1O .section3{fill:#fff;opacity:0.2}#mermaid-svg-w8260LfJzGzxFn1O .sectionTitle0{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .sectionTitle1{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .sectionTitle2{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .sectionTitle3{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-w8260LfJzGzxFn1O .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O .grid path{stroke-width:0}#mermaid-svg-w8260LfJzGzxFn1O .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-w8260LfJzGzxFn1O .task{stroke-width:2}#mermaid-svg-w8260LfJzGzxFn1O .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O .taskText:not([font-size]){font-size:11px}#mermaid-svg-w8260LfJzGzxFn1O .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-w8260LfJzGzxFn1O .task.clickable{cursor:pointer}#mermaid-svg-w8260LfJzGzxFn1O .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-w8260LfJzGzxFn1O .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-w8260LfJzGzxFn1O .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-w8260LfJzGzxFn1O .taskText0,#mermaid-svg-w8260LfJzGzxFn1O .taskText1,#mermaid-svg-w8260LfJzGzxFn1O .taskText2,#mermaid-svg-w8260LfJzGzxFn1O .taskText3{fill:#fff}#mermaid-svg-w8260LfJzGzxFn1O .task0,#mermaid-svg-w8260LfJzGzxFn1O .task1,#mermaid-svg-w8260LfJzGzxFn1O .task2,#mermaid-svg-w8260LfJzGzxFn1O .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-w8260LfJzGzxFn1O .taskTextOutside0,#mermaid-svg-w8260LfJzGzxFn1O .taskTextOutside2{fill:#000}#mermaid-svg-w8260LfJzGzxFn1O .taskTextOutside1,#mermaid-svg-w8260LfJzGzxFn1O .taskTextOutside3{fill:#000}#mermaid-svg-w8260LfJzGzxFn1O .active0,#mermaid-svg-w8260LfJzGzxFn1O .active1,#mermaid-svg-w8260LfJzGzxFn1O .active2,#mermaid-svg-w8260LfJzGzxFn1O .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-w8260LfJzGzxFn1O .activeText0,#mermaid-svg-w8260LfJzGzxFn1O .activeText1,#mermaid-svg-w8260LfJzGzxFn1O .activeText2,#mermaid-svg-w8260LfJzGzxFn1O .activeText3{fill:#000 !important}#mermaid-svg-w8260LfJzGzxFn1O .done0,#mermaid-svg-w8260LfJzGzxFn1O .done1,#mermaid-svg-w8260LfJzGzxFn1O .done2,#mermaid-svg-w8260LfJzGzxFn1O .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-w8260LfJzGzxFn1O .doneText0,#mermaid-svg-w8260LfJzGzxFn1O .doneText1,#mermaid-svg-w8260LfJzGzxFn1O .doneText2,#mermaid-svg-w8260LfJzGzxFn1O .doneText3{fill:#000 !important}#mermaid-svg-w8260LfJzGzxFn1O .crit0,#mermaid-svg-w8260LfJzGzxFn1O .crit1,#mermaid-svg-w8260LfJzGzxFn1O .crit2,#mermaid-svg-w8260LfJzGzxFn1O .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-w8260LfJzGzxFn1O .activeCrit0,#mermaid-svg-w8260LfJzGzxFn1O .activeCrit1,#mermaid-svg-w8260LfJzGzxFn1O .activeCrit2,#mermaid-svg-w8260LfJzGzxFn1O .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-w8260LfJzGzxFn1O .doneCrit0,#mermaid-svg-w8260LfJzGzxFn1O .doneCrit1,#mermaid-svg-w8260LfJzGzxFn1O .doneCrit2,#mermaid-svg-w8260LfJzGzxFn1O .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-w8260LfJzGzxFn1O .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-w8260LfJzGzxFn1O .milestoneText{font-style:italic}#mermaid-svg-w8260LfJzGzxFn1O .doneCritText0,#mermaid-svg-w8260LfJzGzxFn1O .doneCritText1,#mermaid-svg-w8260LfJzGzxFn1O .doneCritText2,#mermaid-svg-w8260LfJzGzxFn1O .doneCritText3{fill:#000 !important}#mermaid-svg-w8260LfJzGzxFn1O .activeCritText0,#mermaid-svg-w8260LfJzGzxFn1O .activeCritText1,#mermaid-svg-w8260LfJzGzxFn1O .activeCritText2,#mermaid-svg-w8260LfJzGzxFn1O .activeCritText3{fill:#000 !important}#mermaid-svg-w8260LfJzGzxFn1O .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-w8260LfJzGzxFn1O g.classGroup text .title{font-weight:bolder}#mermaid-svg-w8260LfJzGzxFn1O g.clickable{cursor:pointer}#mermaid-svg-w8260LfJzGzxFn1O g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-w8260LfJzGzxFn1O g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-w8260LfJzGzxFn1O .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-w8260LfJzGzxFn1O .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-w8260LfJzGzxFn1O .dashed-line{stroke-dasharray:3}#mermaid-svg-w8260LfJzGzxFn1O #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O .commit-id,#mermaid-svg-w8260LfJzGzxFn1O .commit-msg,#mermaid-svg-w8260LfJzGzxFn1O .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-w8260LfJzGzxFn1O g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-w8260LfJzGzxFn1O g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-w8260LfJzGzxFn1O g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-w8260LfJzGzxFn1O .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-w8260LfJzGzxFn1O .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-w8260LfJzGzxFn1O .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-w8260LfJzGzxFn1O .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-w8260LfJzGzxFn1O .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-w8260LfJzGzxFn1O .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-w8260LfJzGzxFn1O .edgeLabel text{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-w8260LfJzGzxFn1O .node circle.state-start{fill:black;stroke:black}#mermaid-svg-w8260LfJzGzxFn1O .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-w8260LfJzGzxFn1O #statediagram-barbEnd{fill:#9370db}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-state .divider{stroke:#9370db}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-w8260LfJzGzxFn1O .note-edge{stroke-dasharray:5}#mermaid-svg-w8260LfJzGzxFn1O .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-w8260LfJzGzxFn1O .error-icon{fill:#522}#mermaid-svg-w8260LfJzGzxFn1O .error-text{fill:#522;stroke:#522}#mermaid-svg-w8260LfJzGzxFn1O .edge-thickness-normal{stroke-width:2px}#mermaid-svg-w8260LfJzGzxFn1O .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-w8260LfJzGzxFn1O .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-w8260LfJzGzxFn1O .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-w8260LfJzGzxFn1O .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-w8260LfJzGzxFn1O .marker{fill:#333}#mermaid-svg-w8260LfJzGzxFn1O .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-w8260LfJzGzxFn1O {color: rgba(0, 0, 0, 0.75);font: ;} vtkConeSource vtkPolyDataMapper vtkActor vtkRenderer vtkRenderWindow

二、遇到的問題

1.運行時異常

按照《醫學圖像編程技術》的代碼錄入編譯成功后,執行是出現異常:

VTK的錯誤調試日志窗口顯示如下:

網上找到的回答為https://stackoverflow.com/questions/18642155/no-override-found-for-vtkpolydatamapper
Stackoverflow上的回答為:
I too was getting this error. The error means that the linker can’t find the definition for the vtkPolyDataMapper method. One has to note which vtk rendering backend they used, during build. It will probably be either vtkRenderingOpenGL, or vtkRenderingOpenGL2. Go to your build/lib folder and search for either one of these. I have VS 2015 Community and had the vtkRenderingOpenGL2, with vtk-7.1 built on Windows 8.1, x86_64 Platform, Release configuration.
I fixed the issue by inserting the 3 following lines at the very top of my source files, before any other preprocessor directives:

#include "vtkAutoInit.h" VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2 VTK_MODULE_INIT(vtkInteractionStyle);

This initializes the specified VTK modules. CMake includes these by default, but other compilers such as VS do not.
The last two lines can be combined into the following:

#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)

還有另外一個回答:
I had the same issue at my platform; Visual Studio 2015 Windows 7 VTK 6.3
I followed VTK/Build System Migration from Marcus D. Hanwell’s post, and it works. My additonal lines are;

#include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL); VTK_MODULE_INIT(vtkInteractionStyle);

on the top of preprocessor. The difference from RestlessC0bra’s post is probably OpenGL version.

采用第一個回答,在main之前增加:
#include “vtkAutoInit.h”
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);

2.在ThinkPad E530C筆記本上出現的異常

在家里12年的老筆記本Thinpad E530C上運行這個例子,提示
搜索到的資料是“VTK7.0要求OPENGL3.2以上,很多筆記本集成顯卡都達不到要求,換成獨顯就可以了”;
使用臺式機(有獨立顯卡),可以運行不會報錯;

3.運行結果

運行結果圖如下:

三、相機旋轉

在上面一代碼中,增加對相機方位角設置,可以使得相機圍繞圓錐體拍攝,在窗口內可以觀察到圓錐體在旋轉;大家自己在代碼上修改,觀察一下效果;

int main() {vtkConeSource *cone = vtkConeSource::New();cone->SetHeight(3.0);cone->SetRadius(1.0);cone->SetResolution(10);vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();coneMapper->SetInputConnection(cone->GetOutputPort());vtkActor *coneActor = vtkActor::New();coneActor->SetMapper(coneMapper);vtkRenderer *ren1 = vtkRenderer::New();ren1->AddActor(coneActor);ren1->SetBackground(0.1, 0.2, 0.4);vtkRenderWindow *renWin = vtkRenderWindow::New();renWin->AddRenderer(ren1);renWin->SetSize(300, 300);for (size_t i = 0; i < 360; i++){renWin->Render();ren1->GetActiveCamera()->Azimuth(1);}cone->Delete();coneMapper->Delete();coneActor->Delete();ren1->Delete();renWin->Delete();system("pause");return 0; }

四、vtkConeSource

類說明:
vtkConeSource創建一個以指定點為中心并指向指定方向的錐。(默認情況下,中心是原點,方向是x軸。)根據此對象的分辨率,系統會創建不同的表示形式。
如果創建分辨率=0,則創建一條直線;
如果分辨率=1,則創建一個三角形;
如果分辨率=2,則創建兩個交叉三角形。如果分辨率大于2,創建一個3D cone(分辨率邊邊)。也可以控制圓錐的底部是否有一個(分辨率面的)多邊形,并指定圓錐的高度和半徑。

4.1類圖

4.2常用接口說明

virtual void vtkConeSource::SetHeight(double):設置圓錐高度;
virtual void vtkConeSource::SetRadius(double) :設置圓錐底部基礎半徑;
virtual void vtkConeSource::SetResolution (int):設置分辨率(棱)個數;
virtual void vtkConeSource::SetCenter(double,double,double);
virtual void vtkConeSource::SetCenter(double[3]);設置圓錐體中心點,而不是底部圓半徑的中心點,默認坐標是(0,0,0);
virtual void vtkConeSource::SetDirection(double[3]):設置圓錐體的朝向,參數應該是一個向量,可以是XYZ軸的余弦值,也可以不是歸一化的值,這個朝向是從底部的半徑中心點指向圓錐頂部尖端位置,默認值為(1,0,0),即方向是向著X軸的的正向;
void vtkConeSource::SetAngle(double angle):這是錐軸和總線之間的角度。警告:這不是光圈!棱邊旋轉的角度是這個角度的兩倍。作為一個副作用,角度加高度設置了圓錐的基本半徑。角度用度表示。

五、資料

1.《醫學圖像編程技術》
2.https://stackoverflow.com/questions/18642155/no-override-found-for-vtkpolydatamapper
本文完整項目代碼在百度網盤,失效請回復;
鏈接:https://pan.baidu.com/s/1b6EJFH4UtTy9EXsk_5eKEA
提取碼:kej8

總結

以上是生活随笔為你收集整理的VTK笔记-图形相关-圆锥体-vtkConeSoure类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。