1.在绘制窗口中绘制出物体(静态的)
vtkRenderWindow * w=vtkRenderWindow::New();
w->AddRenderer(r);
for(int i=0;i<65535;i++)
w->Render();
2.在绘制窗口里面直接绘制出物体(演员),并通过自动旋转照相机来旋转物体
vtkRenderWindow *w = vtkRenderWindow::New();
w->AddRenderer( r );
for (i = 0; i < 360; ++i)
{
w->Render();
r->GetActiveCamera()->Azimuth( 1 );
}
3.对绘制窗口添加一个观察者,没有交互
class vtkMyCallback : public vtkCommand
{
public:
static vtkMyCallback *New()
{ return new vtkMyCallback; }
virtual void Execute(vtkObject *caller, unsigned long, void*)
{
vtkRenderer *renderer = reinterpret_cast<vtkRenderer*>(caller);
cout << renderer->GetActiveCamera()->GetPosition()[0] << " "
<< renderer->GetActiveCamera()->GetPosition()[1] << " "
<< renderer->GetActiveCamera()->GetPosition()[2] << "\n";
}
};
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer( ren1 );
vtkMyCallback *Observer = vtkMyCallback::New();
ren1->AddObserver(vtkCommand::StartEvent,Observer);
for (int i = 0; i < 360; ++i)
{
renWin->Render();
ren1->GetActiveCamera()->Azimuth( 1 );
}
4.对绘制窗添加一个交互器,实现对物体(演员)的控制
vtkRenderWindow *w = vtkRenderWindow::New();
w->AddRenderer( r );
vtkRenderWindowInteractor *i=vtkRenderWindowInteractor::New();
i->SetRenderWindow(w);
i->Initialize();
i->Start();
i->Delete();
vtkInteractorObserver *p=(vtkInteractorObserver *)vtkInteractorObserver::New();
p->EnabledOff ();
5.将观察者注册到交互器上
vtkRenderWindow *w = vtkRenderWindow::New();
w->AddRenderer( r );
vtkRenderWindowInteractor *i=vtkRenderWindowInteractor::New();
i->SetRenderWindow(w);
vtkPointWidget * c=vtkPointWidget::New(); //vtkInteractorObserver的子类
c->SetInteractor(i);
i->Initialize();
i->Start();