vtk 显示属性设置

tt posted @ 2007年9月11日 23:19 in vtk , 13268 阅读

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

actor->GetProperty()->SetRepresentationToPoints()

actor->GetProperty()->SetRepresentationToWireframe()

actor->GetProperty()->SetRepresentationToSurface()

看下面的这个例子:

 

  1. #include "vtkPolyDataMapper.h"
  2. #include "vtkActor.h"
  3. #include "vtkRenderer.h"
  4. #include "vtkRenderWindow.h"
  5. #include "vtkRenderWindowInteractor.h"
  6. #include "vtkProperty.h"
  7. #include "vtkInteractorStyleTrackballCamera.h"
  8. #include "vtkSphereSource.h"
  9. #include "vtkPoints.h"
  10. #include "vtkPolyVertex.h"
  11. #include "vtkUnstructuredGrid.h"
  12. #include "vtkDataSetMapper.h"
  13. #include "vtkCamera.h"
  14. #include "vtkDecimatePro.h"
  15. #include "vtkPolyDataReader.h"
  16. #include "vtkSmoothPolyDataFilter.h"
  17. #include "vtkProperty.h"
  18. #include "vtkPolyDataMapper.h"
  19. #include "vtkPolyDataNormals.h"
  20.  
  21. int main(int argc, char* argv[])
  22. {
  23.     vtkRenderer *ren=vtkRenderer::New();
  24.  
  25.     vtkPolyDataReader *reader = vtkPolyDataReader::New() ;
  26.     reader->SetFileName("venus.vtk");       /*读取网格数据文件*/
  27.     vtkDecimatePro *deci = vtkDecimatePro::New();    //进行精简
  28.     deci->SetInputConnection(reader->GetOutputPort());
  29.     deci->SetTargetReduction(0.9);
  30.     deci->PreserveTopologyOn();
  31.    
  32. //设置优化
  33.     vtkSmoothPolyDataFilter *smoother= vtkSmoothPolyDataFilter::New();
  34.     smoother->SetInputConnection(deci->GetOutputPort());
  35.     smoother->SetNumberOfIterations(50);
  36.     vtkPolyDataNormals *normals= vtkPolyDataNormals::New();
  37.     normals->SetInputConnection(smoother->GetOutputPort());
  38.     normals->FlipNormalsOn();
  39.    
  40.     vtkPolyDataMapper *map1 = vtkPolyDataMapper::New();
  41.     map1->SetInput(normals->GetOutput());
  42.  
  43.     vtkActor *actor1 = vtkActor::New();
  44.     actor1->SetMapper(map1);
  45.     actor1->GetProperty()->SetColor(1.0000, 0, 0);  //设定曲面背面颜色
  46.     map1->ScalarVisibilityOff();
  47.     actor1->GetProperty()->SetRepresentationToWireframe();/*设定网格显示方式*/

  48.  
  49.     vtkProperty *back_prop=vtkProperty::New();     //新建属性,设定曲面前面颜色
  50.     back_prop->SetDiffuseColor(1,1,0);
  51.     actor1->SetBackfaceProperty(back_prop);
  52.  
  53.     ren->AddActor(actor1);
  54.  
  55.     ren->SetBackground(0.6, 0.8, 0.8);          //设定背景色
  56.  
  57.  
  58.     vtkRenderWindow* win=vtkRenderWindow::New();
  59.     win->AddRenderer(ren);
  60.     win->SetSize(400,400);

     

  61.     //建立交互窗口,设定交互方式
  62.     vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  63.     iren->SetRenderWindow(win);
  64.     vtkInteractorStyleTrackballCamera *style =
  65.         vtkInteractorStyleTrackballCamera::New();
  66.     iren->SetInteractorStyle(style);   
  67.  
  68.     iren->Start();
  69.     ren->Delete();
  70.     win->Delete();
  71.     iren->Delete();
  72.  
  73.     return 0;
  74. }
  75.  

文件venus.vtk是用gts对venus头像进行处理,得到的网格数据

 

显示效果如下:

如果要以点集或者面显示方式显示,只需要用下面其中一段代码替换第47行即可

actor1->GetProperty()->SetRepresentationToPoints();/*设定点显示方式*/

actor1->GetProperty()->SetRepresentationToSurface();/*设定面显示方式*/

面方式显示效果如下:

Avatar_small
cyb 说:
2013年4月18日 22:20

Thanks!背面颜色设置


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter