一剑行天下's Blog
Happy coding
首页
留言板
管理
一剑行天下
大学一角
分类
学习
生活
数值分析
gtk编程
系统知识
一般程序
vtk
二叉数
点云数据处理
排序
最新评论
read more : I can...
토토안전나라 : Great su...
information : I w...
totocommunity24 :...
온카맨 : Great write...
最新留言
Healthpet : Asses...
Healthpet : Stree...
Leonardmeday : Gr...
Eddiegom : кайт с...
Marjolein Barral ...
链接
LiYanrui
liujian
数值分析网站
田师兄
UG加工仿真
autotools学习
叶轮设计与加工
功能
注册
登录
忘记密码?
文章 RSS
评论 RSS
留言 RSS
vtk点云数据的显示
vtk动态显示多边形网格数据(转http://tzc.is-programmer.com)
vtk 盒子的显示
一剑行天下
posted @ 2008年11月16日 00:24 in
vtk
, 3175 阅读
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkCubeSource.h"
#include "vtkAxes.h"
#include "vtkTubeFilter.h"
#include "vtkSphereSource.h"
int
main
(
int
argc,
char
* argv
[
]
)
{
FILE *fp =
NULL
;
if
(
argc==
1
)
{
if
(
(
fp=fopen
(
"mbr.asc"
,
"r"
)
)
==
NULL
)
{
printf
(
"Error in open file mbr.asc
\n
"
)
;
return
1
;
}
}
else
{
if
(
(
fp=fopen
(
argv
[
1
]
,
"r"
)
)
==
NULL
)
{
printf
(
"Error in open file %s
\n
"
, argv
[
1
]
)
;
return
1
;
}
}
vtkRenderer * ren=vtkRenderer::
New
(
)
;
double
arr
[
6
]
;
while
(
!feof
(
fp
)
)
{
int
ret = fscanf
(
fp,
"%lf%lf%lf%lf%lf%lf"
, &arr
[
0
]
, &arr
[
1
]
, &arr
[
2
]
,
&arr
[
3
]
, &arr
[
4
]
, &arr
[
5
]
)
;
if
(
ret!=
6
)
break
;
vtkCubeSource *cube=vtkCubeSource::
New
(
)
;
cube->SetBounds
(
arr
[
0
]
,arr
[
3
]
,arr
[
1
]
,arr
[
4
]
,arr
[
2
]
,arr
[
5
]
)
;
vtkPolyDataMapper * map=vtkPolyDataMapper::
New
(
)
;
map->SetInputConnection
(
cube->GetOutputPort
(
)
)
;
vtkActor *actor=vtkActor::
New
(
)
;
actor->SetMapper
(
map
)
;
/*-----------------------------*/
actor->GetProperty
(
)
->SetColor
(
0.194
,
0.562
,
0.75
)
;
//actor->GetProperty()->SetLineStipplePattern(1);
//actor->GetProperty()->SetOpacity(0.4);//设定透明度
//actor->GetProperty()->SetRepresentationToWireframe();
//设定显示方式为线框模式
ren->AddActor
(
actor
)
;
}
fclose
(
fp
)
;
ren->SetBackground
(
1
,
1
,
1
)
;
// ren->WorldToView();
ren->Transparent
(
)
;
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
;
}
编译命令为:
gcc -o cube cubes.
cxx
-I /usr/include/vtk
-5.0
/usr/lib/libvtkRendering.
so
-Wno-deprecated
运行并查看结果:
./cube cube.
asc
[取消回复评论]
昵称
登录
E-mail:
*
Web:
Twitter:
当有新评论通过 E-mail 通知我
(输入验证码)
or Ctrl+Enter