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的更多相关文章

  1. 关于vtkCommand的各种事件的解释

    superclass for callback/observer methods vtkCommand is an implementation of the observer/command des ...

  2. 关于tkCommand的各种事件的解释

    superclass for callback/observer methods vtkCommand is an implementation of the observer/command des ...

  3. VTK初学一,动画加AVI录制终于做出来了

      #ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRe ...

  4. 第04章-VTK基础(7)

    [译者:这个系列教程是以Kitware公司出版的<VTK User's Guide -11th edition>一书作的中文翻译(出版时间2010年.ISBN: 978-1-930934- ...

  5. vtkBoxWidget2Example

    This example uses a vtkBoxWidget2 to manipulate an actor. The widget only contains the interaction l ...

  6. vtkPlane和vtkPlaneSource

    1.vtkPlane vtkPlane provides methods for various plane computations. These include projecting points ...

  7. LODProp3D实例

    1. Level of detail(LoD)多细节层次描述(简称LoD)是实时绘制复杂几何场景的一种有效工具.基于层次结构的动态简化方法能够根据视点的变化,实时连续地转换场景细节模型.在本例中,实现 ...

  8. vtk工作流

    要理解VTK的工作原理,首先应明确几个类型: 1.vtkSource(数据源)   这个就好比一个剧本里面的角色,让演员知道要演的是什么人物. 数据源有:vtkConeSource,vtkSphere ...

  9. vtk renderer / rendering 绘制

    1.在绘制窗口中绘制出物体(静态的)vtkRenderWindow * w=vtkRenderWindow::New();  w->AddRenderer(r);        for(int ...

随机推荐

  1. 用最简单的方式在C#中使用多线程加速耗时的图像处理算法的执行(多核机器)。

    图像处理中,有很多算法由于其内在的复杂性是天然的耗时大户,加之图像本身蕴涵的数据量比一般的对象就大,因此,针对这类算法,执行速度的提在很大程度上依赖于硬件的性能,现在流行的CPU都是至少2核的,稍微好 ...

  2. Serial Port Programming using Win32 API(转载)

    In this tutorial we will learn How to communicate with an external device like a microcontroller boa ...

  3. CF733C Epidemic in Monstropolis[模拟 构造 贪心]

    C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. [No000074]C#创建桌面快捷方式

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. ArcGIS10.2.1精简版、ArcGIS_Desktop10_Tutorial、破解文件等下载地址

    原版ArcGIS for Desktop的ISO文件一般都在4.5G以上,一般人用不上里面很多工具,下载回来又浪费时间,现推出ArcGIS10.2.1精简版(里面只包含主程序.Data Interop ...

  6. asp.net(C#)网站发布后 Global.asax 里 Application_Error 不执行的问题

    现象 在 Global.asax 用 Application_Error 捕捉了http的404,500等错误,在本机测试正常,发布后无效,几经周折终于解决了... 程序是这样设计的 Applicat ...

  7. 初学C#和MVC的一些心得,弯路,总结,还有教训(4)--Cache 关于创建多个缓存实例

    asp.net中的数据缓存可以用 HttpRuntime.Cache ,这个是大家都知道的,但如果缓存的数据比较多,又比较杂乱,想要把缓存分开管理(也就是创建多个缓存实例)应该怎么做呢... 于是常规 ...

  8. Android 自定义Dialog类,并在Activity中实现按钮监听。

      实际开发中,经常会用到Dialog,比如退出时候会弹出是否退出,或者还有一些编辑框也会用Dialog实现,效果图如下: 开发中遇到的问题无非在于如果在Activity中监听这个Dialog中实现的 ...

  9. 文件上传---普通文件fileupload.jar和url文件httpUrlConnection

    文件上传---普通文件和url文件 主要用来学习使用common-fileupload.jar和java.net.httpURLConnection 普通文件: //上传xls文件到临时目录 if ( ...

  10. TAC 坦克队

    The Art of Code 团队成员 组长:   031402330吴宇轩 组员:   031402509胡泽善   031402224彭 巍   031402230张建明   031402508 ...