close

   1: renWin->SetSize(300, 200);
image

image

C:\VTK 5.6\VTK\Widgets;C:\VTK 5.6\VTK\Rendering;C:\VTK 5.6\VTK\IO;C:\VTK 5.6\VTK\Imaging;C:\VTK 5.6\VTK\Graphics;C:\VTK 5.6\VTK\Geovis;C:\VTK 5.6\VTK\GenericFiltering;C:\VTK 5.6\VTK\Filtering;C:\VTK 5.6\VTK\Common;C:\VTK 5.6\release\x86;

image

C:\VTK 5.6\lib

image

vtkWidgets.lib
vtkHybrid.lib
vtkRendering.lib
vtkGraphics.lib
vtkImaging.lib
vtkIO.lib
vtkFiltering.lib
vtkCommon.lib
vtksys.lib

image

   1: // This creates a polygonal cylinder model with eight circumferential facets.
   2:  
   3: kCylinderSource *cylinder = vtkCylinderSource::New();
   4: linder->SetResolution(3);

image

cylinder->SetResolution(4);

image

  cylinder->SetResolution(5);

image

將上面的多邊形的幾何圖形映射至圖像上

即將 cylinder的輸出  接到 cylinderMapper的輸入

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

創建一個cylinderActor, 類似剛才作法

將 cylinderMapper的輸出  接到 cylinderActor的輸入

同時設定cylinderActor的顏色, 擺放的角度

   1:  
   2:  
   3: // The actor is a grouping mechanism: besides the geometry (mapper), it
   4: // also has a property, transformation matrix, and/or texture map.
   5: // Here we set its color and rotate it -22.5 degrees.
   6: vtkActor *cylinderActor = vtkActor::New();
   7: cylinderActor->SetMapper(cylinderMapper);
   8: cylinderActor->GetProperty()->SetColor(1.0000, 0.0000, 0.0000);
   9: cylinderActor->RotateX(30.0);
  10: cylinderActor->RotateY(-45.0);

image

創建一個rend1和renWin

將ren1加入renWin  即 renWin->AddRender(ren1)

加入視窗互動 iren, 可以接收滑鼠相關事件 iren->SetRenderWindow(renWin)

   1: // Create the graphics structure. The renderer renders into the
   2:   // render window. The render window interactor captures mouse events
   3:   // and will perform appropriate camera or actor manipulation
   4:   // depending on the nature of the events.
   5:   //
   6:   vtkRenderer *ren1 = vtkRenderer::New();
   7:   vtkRenderWindow *renWin = vtkRenderWindow::New();
   8:   renWin->AddRenderer(ren1);
   9:   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  10:   iren->SetRenderWindow(renWin);


ren1加入主角cylinderActor

設定ren1的背景顏色及renWin大小

   1:  
   2: // Add the actors to the renderer, set the background and size
   3: //
   4: ren1->AddActor(cylinderActor);
   5: ren1->SetBackground(0.1, 0.2, 0.4);
   6: renWin->SetSize(300, 200);

image

將攝影機靠近(放大效果), ren1->GetActiveCamera()->Zoom(1.5)

並開始顯示 renWin->Render()

   1: // We'll zoom in a little by accessing the camera and invoking a "Zoom"
   2: // method on it.
   3: ren1->ResetCamera();
   4: ren1->GetActiveCamera()->Zoom(1.5);
   5: renWin->Render();

開始iren

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

當關閉視窗, 釋放資源

   1: // Exiting from here, we have to delete all the instances that
   2: // have been created.
   3: cylinder->Delete();
   4: cylinderMapper->Delete();
   5: cylinderActor->Delete();
   6: ren1->Delete();
   7: renWin->Delete();
   8: iren->Delete();


範例程式: VTKHelloWolrd

資料來源:

http://www.vtk.org/Wiki/VTK/Examples/Cxx/Rendering/Cylinder

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()