vtkAnimationCue、vtkCommand和vtkAVIWriter
1. 用vtkAnimationCue自定义一个vtkCustomAnimationCue类,用来实现球体逐渐张开的过程;
2.用vtkCommand自定义衍生一个vtkCustomAnimationCue,在类中实现动画视频记录的开始,记录每一帧,最后结束记录
3.在场景中添加监听器,监听vtkCustomAnimationCue对象的开始、每一帧的画面和结束,并分别调用vtkCustomAnimationCue中的回调函数
class vtkCustomAnimationCue : public vtkAnimationCue
{
public:
static vtkCustomAnimationCue* New(){return new vtkCustomAnimationCue;}
vtkTypeMacro(vtkCustomAnimationCue,vtkAnimationCue)
vtkTypeRevisionMacro (vtkCustomAnimationCue,vtkAnimationCue); vtkRenderWindow *RenWin;
vtkSphereSource *Sphere;
vtkRenderer *renderer;
protected:
vtkCustomAnimationCue()
{
this->RenWin = ;
this->Sphere = ;
theta=;
}
~vtkCustomAnimationCue(){}
protected:
double theta;
// Overridden to adjust the sphere'sradius depending on the frame we
// are rendering. In this animation wewant to change the StartTheta
// of the sphere from 0 to 180 over thelength of the cue.
virtual void TickInternal(double currenttime, double deltatime, double clocktime)
{
double new_st = currenttime * ;
// since the cue is in normalizedmode, the currenttime will be in the
// range[0,1], where 0 is start ofthe cue and 1 is end of the cue.
this->Sphere->SetStartTheta(new_st);
this->renderer->ResetCamera();
this->RenWin->Render();
} };
class MyCallBackAVI:public vtkCommand
{
public:
static MyCallBackAVI *New(){ return new MyCallBackAVI; } vtkWindowToImageFilter *filter;
vtkAVIWriter *writer;
// vtkRenderWindow *renWin;
virtual void Execute(vtkObject *caller,unsigned long eveventId,void*vtkNotUsed(callData))
{
switch (eveventId)
{
case vtkCommand::StartAnimationCueEvent:
cout<<"timer callback!"<<endl;
writer->Start();
break;
case vtkCommand::AnimationCueTickEvent:
filter->Modified();
writer->Write();
break;
case vtkCommand::EndAnimationCueEvent:
writer->End();
default:
break;
} } vtkTypeMacro(MyCallBackAVI,vtkCommand)
protected:
MyCallBackAVI()
{
// renWin=vtkRenderWindow::New();
filter=vtkWindowToImageFilter::New();
writer=vtkAVIWriter::New();
}
};
int main(int, char *[])
{
// Create the graphics sturctures. Therenderer renders into the
// render window.
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin =vtkRenderWindow::New();
vtkRenderWindowInteractor *iren =vtkRenderWindowInteractor::New();
vtkInteractorStyleTrackballCamera *style=vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
// renWin->SetMultiSamples(0);
renWin->AddRenderer(ren1);
iren->SetRenderWindow(renWin);
vtkSphereSource *sphere =vtkSphereSource::New();
vtkPolyDataMapper *mapper =vtkPolyDataMapper::New();
mapper->SetInputConnection(sphere->GetOutputPort());
/**********沿X轴旋转30度*****************/
vtkTransform *transform;
vtkTransformPolyDataFilter *transformFilter;
transform=vtkTransform::New();
transform->RotateWXYZ(,,,);
transformFilter=vtkTransformPolyDataFilter::New();
transformFilter->SetTransform(transform);
transformFilter->SetInputConnection(sphere->GetOutputPort());
transformFilter->Update();
mapper->SetInputConnection(transformFilter->GetOutputPort());
/**********沿X轴旋转45度*****************/
vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
ren1->AddActor(actor);
ren1->ResetCamera();
renWin->Render(); //Create an Animation Scene
vtkAnimationScene *scene =vtkAnimationScene::New();
scene->SetModeToSequence();
scene->SetFrameRate();
scene->SetStartTime();
scene->SetEndTime(); // Create an Animation Cue to animate thecamera.
vtkCustomAnimationCue *cue1 =vtkCustomAnimationCue::New();
cue1->Sphere = sphere;
cue1->RenWin = renWin;
cue1->renderer=ren1; cue1->SetTimeModeToNormalized();
cue1->SetStartTime();
cue1->SetEndTime(1.0);
scene->AddCue(cue1);
/***********************录制视频******************************/
vtkSmartPointer<MyCallBackAVI> myCallBackAvi=vtkSmartPointer<MyCallBackAVI>::New();
vtkSmartPointer<vtkWindowToImageFilter> filter=vtkSmartPointer<vtkWindowToImageFilter>::New();
vtkSmartPointer<vtkAVIWriter> writer=vtkSmartPointer<vtkAVIWriter>::New();
filter->SetInput(renWin);
writer->SetInputConnection(filter->GetOutputPort());
writer->SetFileName("myVideo.avi");
writer->SetRate(); myCallBackAvi->filter=filter;
myCallBackAvi->writer=writer;
///设置场景的监听器,监听动画的开始事件(StartAnimationCueEvent),调用自定义的回调类MyCallBackAVI,启动记录
/// 监听动画的结束事件(EndAnimationCueEvent),调用自定义的回调类MyCallBackAVI,结束记录
/// 监听动画的Tick事件(AnimationCueTickEvent),调用自定义的回调类MyCallBackAVI,记录一帧视频 scene->AddObserver(vtkCommand::StartAnimationCueEvent,myCallBackAvi);
scene->AddObserver(vtkCommand::AnimationCueTickEvent,myCallBackAvi);
scene->AddObserver(vtkCommand::EndAnimationCueEvent,myCallBackAvi); iren->Initialize();
scene->Play();
scene->Stop();
iren->Start(); ren1->Delete(); renWin->Delete();
scene->Delete();
cue1->Delete(); return EXIT_SUCCESS;
}
vtkAnimationCue、vtkCommand和vtkAVIWriter的更多相关文章
- 关于vtkCommand的各种事件的解释
superclass for callback/observer methods vtkCommand is an implementation of the observer/command des ...
- 关于tkCommand的各种事件的解释
superclass for callback/observer methods vtkCommand is an implementation of the observer/command des ...
- VTK初学一,动画加AVI录制终于做出来了
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRe ...
- 第04章-VTK基础(7)
[译者:这个系列教程是以Kitware公司出版的<VTK User's Guide -11th edition>一书作的中文翻译(出版时间2010年.ISBN: 978-1-930934- ...
- vtkBoxWidget2Example
This example uses a vtkBoxWidget2 to manipulate an actor. The widget only contains the interaction l ...
- vtkPlane和vtkPlaneSource
1.vtkPlane vtkPlane provides methods for various plane computations. These include projecting points ...
- LODProp3D实例
1. Level of detail(LoD)多细节层次描述(简称LoD)是实时绘制复杂几何场景的一种有效工具.基于层次结构的动态简化方法能够根据视点的变化,实时连续地转换场景细节模型.在本例中,实现 ...
- vtk工作流
要理解VTK的工作原理,首先应明确几个类型: 1.vtkSource(数据源) 这个就好比一个剧本里面的角色,让演员知道要演的是什么人物. 数据源有:vtkConeSource,vtkSphere ...
- vtk renderer / rendering 绘制
1.在绘制窗口中绘制出物体(静态的)vtkRenderWindow * w=vtkRenderWindow::New(); w->AddRenderer(r); for(int ...
随机推荐
- Ubuntu PPTP 服务器安装
安装相应的包 sudo apt-get install pptpd 修改配置文件pptpd.conf sudo vim /etc/pptpd.conf 设置对应的VPN网络,localip是服务器的, ...
- 一种可实时处理 O(1)复杂度图像去雾算法的实现。
在我博文的一系列的文章,有不少算法都于去雾有关,比如限制对比度自适应直方图均衡化算法原理.实现及效果.局部自适应自动色阶/对比度算法在图像增强上的应用这两个增强算法都有一定的去雾能力,而最直接的就是& ...
- UVA 11859 Division Game[Nim游戏]
题意:给定一个N*M的矩阵,每次可以选择同一行中的若干个数,把它们变成它们的质因子.问说先手的可否获胜. 同一行相当于1堆,数量就是所有数的质因子个数之和 #include <iostream& ...
- java读取excel文件
package com.execl; import java.io.File; import java.io.FileInputStream; import java.io.IOException; ...
- 2016第二届陕西省网络空间安全大赛WriteUp
2016年5月28号(正式比赛) 有选择题和实践题,俩队员在弄选择题时,我去拿了web1的一血. 0x01 web 是一道代码审计题,发包,返回了源代码: <?php if (isset($_G ...
- HTML 学习笔记 JavaScript(数组)
1.数组的创建 var arrayObj = new Array(); //创建一个数组var arrayObj = new Array([size]); //创建一个数组并指定长度,注意不是上限,是 ...
- [CareerCup] 2.5 Add Two Numbers 两个数字相加
2.5 You have two numbers represented by a linked list, where each node contains a single digit. The ...
- CentOS 6.5 PPTPD VPN服务器安装,解决807等问题。
需要两个组件: ppp pptpd 需要配置的地方有三处: /etc/pptpd.conf /etc/ppp/options.pptpd /etc/ppp/chap-secrets 需要开启IP转发: ...
- AppBox升级进行时 - 关联表查询与更新(Entity Framework)
AppBox 是基于 FineUI 的通用权限管理框架,包括用户管理.职称管理.部门管理.角色管理.角色权限管理等模块. 关联表的查询操作 使用 Include 方法,我们可以在一次数据库查询中将关联 ...
- 轻量级DAO层实践初体验
最近快被 Hibernate 给坑哭了,有了自己动手实现 ORM 映射 DAO 的冲动. 工作之余折腾了快一星期,总算是有点小成就. 现打算将过程记录下来,方便自己后续回顾填补遗漏. 1. 传统 JD ...