VTk显示样式设置

显示样式

  在vtk中,显示样式是通过vtkProperty来控制的。这里介绍三种基本的属性设置方式:点方式,网格方式和面方式。其设置方法为

  • actor->GetProperty()->SetRepresentationToPoints()
  • actor->GetProperty()->SetRepresentationToWireframe()
  • actor->GetProperty()->SetRepresentationToSurface()

示例说明

CMakeLists.txt文件代码如下:

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT( Representation )
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
ADD_EXECUTABLE(Representation Representation.cpp)
TARGET_LINK_LIBRARIES(Representation ${VTK_LIBRARIES})

Representation.cpp文件代码如下:

#include <vtkConeSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
#include <iostream>

int main(int argc, char *argv[])
{
    vtkSmartPointer<vtkConeSource> coneSource =
        vtkSmartPointer<vtkConeSource>::New();
    coneSource->Update();

    vtkSmartPointer<vtkPolyData> cone = coneSource->GetOutput();
    int nPoints = cone->GetNumberOfPoints();
    int nCells  = cone->GetNumberOfCells();

    std::cout<<"Points number:"<<nPoints<<std::endl;
    std::cout<<"Cells  number:"<<nCells<<std::endl;

    vtkSmartPointer<vtkPolyDataMapper> mapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputData(cone);

    vtkSmartPointer<vtkActor> actor =
        vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(1.0, 0, 0);  //设置颜色属性
    actor->GetProperty()->SetRepresentationToPoints();      //点方式
    //actor->GetProperty()->SetRepresentationToWireframe();  //网格方式
    //actor->GetProperty()->SetRepresentationToSurface();   //默认设置,面方式

    vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);
    renderer->SetBackground(0.0,0.0,0.0);

    vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);
    renderWindow->SetSize( 640, 480 );
    renderWindow->Render();
    renderWindow->SetWindowName("Representation");

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);

    renderWindow->Render();
    renderWindowInteractor->Start();

    return EXIT_SUCCESS;
}

运行结果:

这里写图片描述

这里写图片描述

这里写图片描述

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值