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 ...
随机推荐
- 你们信不信一句Console.WriteLine就能让你的控制台程序失去响应
好久没更新博客了,今天是扒衣见君节,难得闲下来就来说说一个最近有趣的发现吧. 首先废话不多说,直接上代码吧 class Program { static void Main(string[] args ...
- Learn Python The Hard Way ex41中的程序
import random from urllib import urlopen import sys WORD_URL = "http://learncodethehardway.org/ ...
- github
学习github的不错的资源 http://gitref.org/zh/index.html https://wuyuans.com/2012/05/github-simple-tutorial/#t ...
- HTML5中支持新的媒体元素有这些
HTML5对媒体的支持性很强,支持以下媒体元素: · audio 定义音频 · video 定义视频 · embed 作为外部应用的容器 · source 多种媒体源的支持 · track ...
- iOS关于XML解析请求数据
XML数据的请求: 和json请求几乎一样,只有请求参数修改为xml即可: AFHTTPSessionManager *manager = [AFHTTPSessionManager manager] ...
- 《JavaScript高级程序设计》笔记整理
欢迎各位指导与讨论 : ) -------------------------待续------------------------------- 本文为笔者在学习时整理的笔记,如有错漏,恳请各位指出, ...
- GO语言总结(1)——基本知识
1.注释(与C++一样) 行注释:// 块注释:/* ... */ 2.标识符 可以这么说,除了数字开头的不允许,符号开头的不允许,关键字不允许,其他的Unicode字符组合都可以.“_33”也可以是 ...
- 分布式光伏系列:分布式光伏电站 运行与维护方案一览(zz)
原文:http://www.toutiao.com/a6353487210709516546/ 中小型光伏电站的特点是占地面积小.安装位置灵活且日常维护量少.由于光伏电站不同的运行环境,为了能够使光伏 ...
- RapidJSON 代码剖析(四):优化 Grisu
我曾经在知乎的一个答案里谈及到 V8 引擎里实现了 Grisu 算法,我先引用该文的内容简单介绍 Grisu.然后,再谈及 RapidJSON 对它做了的几个底层优化. (配图中的<Grisù& ...
- H5项目常见问题汇总及解决方案(果断复制粘贴,不解释)
H5项目常见问题及注意事项 Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 //一.HTML页面结构 <meta name="viewport" co ...