2018-01-12:VTK相关资源列表

官方文档:https://www.vtk.org/doc/nightly/html/index.html
VTK相关实例:https://lorensen.github.io/VTKExamples/site/Python/
VTK源码仓库:https://github.com/Kitware/VTK


基于Anaconda安装Python3.6版本的VTK7.1.0:

conda install -c clinicalgraphics vtk=7.1.0

基于ROS-Kinetic-Desktop-Full的VTK6.2
只需要完整安装了ros-kinetic,那么就会自动安装好VTK6.2版本的.

一条命令就安装好了VTK的Python开发环境.
现在,我们来通过VTK版本的hello world实例来测试是否安装成功.
vtk_01.py

import vtk
# The colors module defines various useful colors.
from vtk.util.colors import tomato

# This creates a polygonal cylinder model with eight circumferential
# facets.
cylinder = vtk.vtkCylinderSource()
cylinder.SetResolution(8)

# The mapper is responsible for pushing the geometry into the graphics
# library. It may also do color mapping, if scalars or other
# attributes are defined.
cylinderMapper = vtk.vtkPolyDataMapper()
cylinderMapper.SetInputConnection(cylinder.GetOutputPort())

# The actor is a grouping mechanism: besides the geometry (mapper), it
# also has a property, transformation matrix, and/or texture map.
# Here we set its color and rotate it -22.5 degrees.
cylinderActor = vtk.vtkActor()
cylinderActor.SetMapper(cylinderMapper)
cylinderActor.GetProperty().SetColor(tomato)
cylinderActor.RotateX(30.0)
cylinderActor.RotateY(-45.0)

# Create the graphics structure. 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.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Add the actors to the renderer, set the background and size
ren.AddActor(cylinderActor)
ren.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(200, 200)

# This allows the interactor to initalize itself. It has to be
# called before an event loop.
iren.Initialize()

# We'll zoom in a little by accessing the camera and invoking a "Zoom"
# method on it.
ren.ResetCamera()
ren.GetActiveCamera().Zoom(1.5)
renWin.Render()

# Start the event loop.
iren.Start()

运行结果为:


Screenshot from 2018-01-12 09-11-43.png

可以看出,我们运行成功了.

Python版本的实例运行成功,现在我们来实现基于c++版本的.
vtk_01.cpp

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main(int, char *[])
{
  // This creates a polygonal cylinder model with eight circumferential facets
  // (i.e, in practice an octagonal prism).
  vtkSmartPointer cylinder = vtkSmartPointer::New();
  cylinder->SetResolution(8);

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

  // The actor is a grouping mechanism: besides the geometry (mapper), it
  // also has a property, transformation matrix, and/or texture map.
  // Here we set its color and rotate it around the X and Y axes.
  vtkSmartPointer cylinderActor = vtkSmartPointer::New();
  cylinderActor->SetMapper(cylinderMapper);
  cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
  cylinderActor->RotateX(30.0);
  cylinderActor->RotateY(-45.0);

  // The renderer generates the image
  // which is then displayed on the render window.
  // It can be thought of as a scene to which the actor is added
  vtkSmartPointer renderer = vtkSmartPointer::New();
  renderer->AddActor(cylinderActor);
  renderer->SetBackground(0.1, 0.2, 0.4);
  // Zoom in a little by accessing the camera and invoking its "Zoom" method.
  renderer->ResetCamera();
  renderer->GetActiveCamera()->Zoom(1.5);

  // The render window is the actual GUI window
  // that appears on the computer screen
  vtkSmartPointer renderWindow = vtkSmartPointer::New();
  renderWindow->SetSize(200, 200);
  renderWindow->AddRenderer(renderer);

  // The render window interactor captures mouse events
  // and will perform appropriate camera or actor manipulation
  // depending on the nature of the events.
  vtkSmartPointer renderWindowInteractor = vtkSmartPointer::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

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

  return EXIT_SUCCESS;
}

接着编写CMakeLists.txt文件
CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

PROJECT(CylinderRenderingProperties)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(CylinderRenderingProperties main.cpp )

target_link_libraries(CylinderRenderingProperties ${VTK_LIBRARIES})

最终运行的结果跟Python版本实现的是一样的,这里就不再截图.

你可能感兴趣的:(2018-01-12:VTK相关资源列表)