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 ...
随机推荐
- WPF 开源Chart控件
控件: Icon URL Supplier Dynamic Data Display 2009
- cefsharp重写默认js弹窗(alert/confirm/prompt)
1.设置js弹窗控制器 webView.JsDialogHandler = this; //js弹窗控制 this表示本类对象,所以本类要实现IJsDialogHandler接口 2.实现IJsDi ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- list去从复
for(int i=0;i<queryList.size();i++){//去重 String time =queryList.get(i); i ...
- 不封装ajax 带url参数调用接口
html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- .jshintrc配置
在root目录创建一个.jshintrc文件插入下面的代码即可.也可以自行配置. { // // 强制选项 // // When set to true, these options will mak ...
- NOI2018准备Day14晚
1个小时调处了前天晚上卡了一个晚上的数独,果然还是dfs回溯的问题. 1个小时做codevs2500城堡,然而并没有做出来 剩下1个小时,做了一道字符串的STL,空格和换行符 ,真心累啊...... ...
- JS数组去重比较
数组去重复是一个常见的需求,我们暂时考虑同类型的数组去重复.主要是理清思路和考虑执行性能. for循环删除后面重复的 var uniqueFor = function(arr) { for (var ...
- [转]MIDI常识20条
原文链接:http://www.midifan.com/modulearticle-detailview-488.htm Keyboard杂志老资格编辑Jim Aikin在纪念MIDI诞生20的时候发 ...
- 【JavaScript】冒泡排序,字符串排序,数字排序
原理:是临近的数字两两进行比较,按照从小到大或者从大到小的顺序进行交换, function bubbleClick() { var str = "50,1,4,6,9,76,43,22,2, ...