VTK Learning Four
引言
生成一个圆柱,并设置颜色、角度。设置窗口背景颜色和窗口大小。
代码
#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkProperty.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
int main()
{
/Visualize Pipeline: Source->Mapper->Actor
//
vtkCylinderSource* cylinder = vtkCylinderSource::New();
cylinder->SetResolution(4);
vtkPolyDataMapper* cylinderMapper = vtkPolyDataMapper::New();
cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
vtkActor* cylinderActor = vtkActor::New();
cylinderActor->SetMapper(cylinderMapper);
///Actor property
cylinderActor->GetProperty()->SetColor(1.0,0.32,0.27);
cylinderActor->RotateX(30.0);
cylinderActor->RotateY(-45);
//Render Engine:Renderer->RenderWindow->RenderWindowInteractor
//
vtkRenderer* cylinderRenderer = vtkRenderer::New();
vtkRenderWindow* cylinderRenderWindow = vtkRenderWindow::New();
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
cylinderRenderWindow->AddRenderer(cylinderRenderer);
iren->SetRenderWindow(cylinderRenderWindow);
//Visualize Pipeline -> Render Engine
//
cylinderRenderer->AddActor(cylinderActor);
cylinderRenderer->SetBackground(0.1,0.2,0.4); // render background property
cylinderRenderWindow->SetSize(400,400); //render window size
//Camera
// 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.
cylinderRenderer->ResetCamera();
cylinderRenderer->GetActiveCamera()->Zoom(1.5); //focus
/Window Hold On
iren->Start();
/Clear Memory
iren->Delete();
cylinderRenderWindow->Delete();
cylinderRenderer->Delete();
cylinderActor->Delete();
cylinderMapper->Delete();
cylinder->Delete();
return 0;
}
构建CMakeLists
#cmake . ./build -G "Visual Studio 14 2015 Win64"
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(ProceduralSourceObject)
find_package(VTK required)
include(${VTK_USE_FILE})
add_executable(ProceduralSourceObject ProceduralSourceObject.cxx )
target_link_libraries(ProceduralSourceObject ${VTK_LIBRARIES})