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 ...
随机推荐
- 3D坦克大战游戏iOS源码
3D坦克大战游戏源码,该游戏是基于xcode 4.3,ios sdk 5.1开发.在xcode4.3.3上完美无报错.兼容ios4.3-ios6.0 ,一款ios平台上难得的3D坦克大战游戏源码,有2 ...
- jni调试3(线程调试env变量问题)
jni层调试线程死机原因 一,导致死机原因: jni层中 线程函数中 只要添加调用env 的函数 ,,就会死机 二,解决方法 第一我们应该理解: ①(独立性) JNIEnv 是一个与线 ...
- netty4虚拟内存不断飙升
去年升级过一个老的netty3的程序到netty4,近期突然注意到一个问题,就是这个程序随着时间虚拟内存会不断升高.之前升级的时候担心存在内存泄露,所以还特意用jstate跟踪过gc回收的情况,并没有 ...
- 浅谈Java中的equals和==
浅谈Java中的equals和== 在初学Java时,可能会经常碰到下面的代码: String str1 = new String("hello"); String str2 = ...
- java设计模式之状态模式
状态模式 允许一个对象在其内部状态改变时改变它的行为,对象看起来似乎修改了它的类. 状态模式UML图 上下文环境(Context):它定义了客户程序需要的接口并维护一个具体状态角色的实例,将与状态相关 ...
- github
学习github的不错的资源 http://gitref.org/zh/index.html https://wuyuans.com/2012/05/github-simple-tutorial/#t ...
- java 移位运算符
java中有三种移位运算符 << : 左移运算符,num << 1,相当于num乘以2 >> : 右移运算符,num >& ...
- IDEA 和 Eclipse 使用对比
前段时间从 Eclipse 中将开发工作转移到了 IDEA. IDEA 确实有很多地方比 Eclipse 做的好,总结了一些 IDEA 和 Eclipse 的不同. 1.文件和导航关联 经常需要打开某 ...
- 关于 MonoDevelop on Linux 单步调试问题的解决
在 MonoDevelop 中默认是关闭对外部程序集(.dll)的调试,可通过如下步骤来解决这个问题. 通过菜单[Edit]-[Preferences]-[Debugger]进入到调试器的设置页,把“ ...
- Django用已有的数据库
python mysite/manage.py inspectdb 会按照你的数据库生成Model 拷贝进去用就可以了!