vtk 显示属性设置

tt posted @ 2007年9月11日 23:19 in vtk , 2601 阅读在vtk中,显示样式的显示,是通过vtkProperty来控制的,这里介绍三种基本的属性设置方式,点方式,网格方式和面方式,这里以venus头像三角网格的显示为例介绍其显示。其设置方法为actor->GetProperty()->SetRepresentationToPoints()actor->GetProperty()->SetRepresentationToWireframe()actor->GetProperty()->SetRepresentationToSurface()看下面的这个例子: #include "vtkPolyDataMapper.h"#include "vtkActor.h"#include "vtkRenderer.h"#include "vtkRenderWindow.h"#include "vtkRenderWindowInteractor.h"#include "vtkProperty.h"#include "vtkInteractorStyleTrackballCamera.h"#include "vtkSphereSource.h"#include "vtkPoints.h"#include "vtkPolyVertex.h"#include "vtkUnstructuredGrid.h"#include "vtkDataSetMapper.h"#include "vtkCamera.h"#include "vtkDecimatePro.h"#include "vtkPolyDataReader.h"#include "vtkSmoothPolyDataFilter.h"#include "vtkProperty.h"#include "vtkPolyDataMapper.h"#include "vtkPolyDataNormals.h" int main(int argc, char* argv[]){ vtkRenderer *ren=vtkRenderer::New(); vtkPolyDataReader *reader = vtkPolyDataReader::New() ; reader->SetFileName("venus.vtk"); /*读取网格数据文件*/ vtkDecimatePro *deci = vtkDecimatePro::New(); //进行精简 deci->SetInputConnection(reader->GetOutputPort()); deci->SetTargetReduction(0.9); deci->PreserveTopologyOn(); //设置优化 vtkSmoothPolyDataFilter *smoother= vtkSmoothPolyDataFilter::New(); smoother->SetInputConnection(deci->GetOutputPort()); smoother->SetNumberOfIterations(50); vtkPolyDataNormals *normals= vtkPolyDataNormals::New(); normals->SetInputConnection(smoother->GetOutputPort()); normals->FlipNormalsOn(); vtkPolyDataMapper *map1 = vtkPolyDataMapper::New(); map1->SetInput(normals->GetOutput()); vtkActor *actor1 = vtkActor::New(); actor1->SetMapper(map1); actor1->GetProperty()->SetColor(1.0000, 0, 0); //设定曲面背面颜色 map1->ScalarVisibilityOff(); actor1->GetProperty()->SetRepresentationToWireframe();/*设定网格显示方式*/ vtkProperty *back_prop=vtkProperty::New(); //新建属性,设定曲面前面颜色 back_prop->SetDiffuseColor(1,1,0); actor1->SetBackfaceProperty(back_prop); ren->AddActor(actor1); ren->SetBackground(0.6, 0.8, 0.8); //设定背景色 vtkRenderWindow* win=vtkRenderWindow::New(); win->AddRenderer(ren); win->SetSize(400,400); //建立交互窗口,设定交互方式 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); iren->SetRenderWindow(win); vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New(); iren->SetInteractorStyle(style); iren->Start(); ren->Delete(); win->Delete(); iren->Delete(); return 0;} 文件venus.vtk是用gts对venus头像进行处理,得到的网格数据 显示效果如下:如果要以点集或者面显示方式显示,只需要用下面其中一段代码替换第47行即可actor1->GetProperty()->SetRepresentationToPoints();/*设定点显示方式*/actor1->GetProperty()->SetRepresentationToSurface();/*设定面显示方式*/面方式显示效果如下:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值