VTK笔记-图形相关-圆锥体-vtkConeSoure类
圓錐體
文章目錄
- 圓錐體
- 前言
- 一、代碼
- 1.1流程
- 二、遇到的問(wèn)題
- 1.運(yùn)行時(shí)異常
- 2.在ThinkPad E530C筆記本上出現(xiàn)的異常
- 3.運(yùn)行結(jié)果
- 三、相機(jī)旋轉(zhuǎn)
- 四、vtkConeSource
- 4.1類圖
- 4.2常用接口說(shuō)明
- 五、資料
前言
使用VTK構(gòu)建一個(gè)圓錐體展示;
執(zhí)行的具體步驟為:
1.創(chuàng)建一個(gè)vtkConeSoure類的實(shí)例cone;
表示一個(gè)圓錐(正棱錐,有棱數(shù)目),有三個(gè)屬性:高度、半徑、分辨率(棱數(shù)目);
2.創(chuàng)建一個(gè)映射器,vtkPolyDataMapper實(shí)例;
cone的輸出可以作為映射器的輸入,
vtk中使用GetOutputPort()作為輸出;
VTK常見(jiàn)使用方法:將一個(gè)對(duì)象的輸出當(dāng)另一個(gè)對(duì)象的輸入;
常見(jiàn)用來(lái)作為數(shù)據(jù)流的處理:將多個(gè)對(duì)象串聯(lián)在一起形成一條鏈,稱之為可視化流水線;
3.渲染部分
通過(guò)方法SetMapper將vtkActor對(duì)象和映射器關(guān)聯(lián)在一起;之后渲染過(guò)程暫時(shí)省略,在以后的部分單獨(dú)說(shuō)明;
一、代碼
#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二、遇到的問(wèn)題
1.運(yùn)行時(shí)異常
按照《醫(yī)學(xué)圖像編程技術(shù)》的代碼錄入編譯成功后,執(zhí)行是出現(xiàn)異常:
VTK的錯(cuò)誤調(diào)試日志窗口顯示如下:
網(wǎng)上找到的回答為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:
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:
還有另外一個(gè)回答:
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;
on the top of preprocessor. The difference from RestlessC0bra’s post is probably OpenGL version.
采用第一個(gè)回答,在main之前增加:
#include “vtkAutoInit.h”
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);
2.在ThinkPad E530C筆記本上出現(xiàn)的異常
在家里12年的老筆記本Thinpad E530C上運(yùn)行這個(gè)例子,提示
搜索到的資料是“VTK7.0要求OPENGL3.2以上,很多筆記本集成顯卡都達(dá)不到要求,換成獨(dú)顯就可以了”;
使用臺(tái)式機(jī)(有獨(dú)立顯卡),可以運(yùn)行不會(huì)報(bào)錯(cuò);
3.運(yùn)行結(jié)果
運(yùn)行結(jié)果圖如下:
三、相機(jī)旋轉(zhuǎn)
在上面一代碼中,增加對(duì)相機(jī)方位角設(shè)置,可以使得相機(jī)圍繞圓錐體拍攝,在窗口內(nèi)可以觀察到圓錐體在旋轉(zhuǎn);大家自己在代碼上修改,觀察一下效果;
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
類說(shuō)明:
vtkConeSource創(chuàng)建一個(gè)以指定點(diǎn)為中心并指向指定方向的錐。(默認(rèn)情況下,中心是原點(diǎn),方向是x軸。)根據(jù)此對(duì)象的分辨率,系統(tǒng)會(huì)創(chuàng)建不同的表示形式。
如果創(chuàng)建分辨率=0,則創(chuàng)建一條直線;
如果分辨率=1,則創(chuàng)建一個(gè)三角形;
如果分辨率=2,則創(chuàng)建兩個(gè)交叉三角形。如果分辨率大于2,創(chuàng)建一個(gè)3D cone(分辨率邊邊)。也可以控制圓錐的底部是否有一個(gè)(分辨率面的)多邊形,并指定圓錐的高度和半徑。
4.1類圖
4.2常用接口說(shuō)明
virtual void vtkConeSource::SetHeight(double):設(shè)置圓錐高度;
virtual void vtkConeSource::SetRadius(double) :設(shè)置圓錐底部基礎(chǔ)半徑;
virtual void vtkConeSource::SetResolution (int):設(shè)置分辨率(棱)個(gè)數(shù);
virtual void vtkConeSource::SetCenter(double,double,double);
virtual void vtkConeSource::SetCenter(double[3]);設(shè)置圓錐體中心點(diǎn),而不是底部圓半徑的中心點(diǎn),默認(rèn)坐標(biāo)是(0,0,0);
virtual void vtkConeSource::SetDirection(double[3]):設(shè)置圓錐體的朝向,參數(shù)應(yīng)該是一個(gè)向量,可以是XYZ軸的余弦值,也可以不是歸一化的值,這個(gè)朝向是從底部的半徑中心點(diǎn)指向圓錐頂部尖端位置,默認(rèn)值為(1,0,0),即方向是向著X軸的的正向;
void vtkConeSource::SetAngle(double angle):這是錐軸和總線之間的角度。警告:這不是光圈!棱邊旋轉(zhuǎn)的角度是這個(gè)角度的兩倍。作為一個(gè)副作用,角度加高度設(shè)置了圓錐的基本半徑。角度用度表示。
五、資料
1.《醫(yī)學(xué)圖像編程技術(shù)》
2.https://stackoverflow.com/questions/18642155/no-override-found-for-vtkpolydatamapper
本文完整項(xiàng)目代碼在百度網(wǎng)盤,失效請(qǐng)回復(fù);
鏈接:https://pan.baidu.com/s/1b6EJFH4UtTy9EXsk_5eKEA
提取碼:kej8
總結(jié)
以上是生活随笔為你收集整理的VTK笔记-图形相关-圆锥体-vtkConeSoure类的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: .h5文件的读取
- 下一篇: 作业二:wireshark抓包与ping