vtk 显示属性设置
tt
posted @ 2007年9月11日 23:19
in vtk
, 13268 阅读
在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();/*设定面显示方式*/
面方式显示效果如下:
2013年4月18日 22:20
Thanks!背面颜色设置