[vtkusers] vtk animation and interactor problem!!!!

Gatos Gatos gatos12 at hotmail.com
Fri Feb 4 03:27:37 EST 2005


Hello

I am a begginer with vtk and I am trying to create an animation using 
simultaneously the Interactor.

The following code (I found it from the vtkuser news group) is very similar 
what I want to do but the vtkRenderWindowInteractor does not work during the 
loop.

What changes I need to make for making possible (for example rotate with the 
mouse) the spheres
during the animation?


thank you very much in advance
for your help

kostas

#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkStructuredPointsReader.h"
#include "vtkGlyph3D.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkProperty.h"

int main( int argc, char *argv[] )
{
	vtkPoints *points = vtkPoints::New();
	vtkSphereSource *sphere = vtkSphereSource::New();
	vtkPolyData *data = vtkPolyData::New();
	vtkGlyph3D *verts = vtkGlyph3D::New();
	vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
	vtkActor *sphereActor = vtkActor::New();
	vtkRenderer *ren1= vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();

	const int ni = 20;

	points->SetNumberOfPoints(ni);
	for (int i=0; i <ni; i++) {
		points->SetPoint(i,
				(double)(i%30)*0.1,
				(double)0,
				(double)(i/20));
	}

	sphere->SetRadius(0.04 );
	sphere->SetPhiResolution( 4 );
	sphere->SetThetaResolution( 4 );

	data->SetPoints(points);

	verts->SetSource(sphere->GetOutput());
	verts->SetInput(data);
	verts->ScalingOff();

	sphereMapper->SetInput( verts->GetOutput() );

	sphereActor->SetMapper( sphereMapper );
	sphereActor->GetProperty()->SetOpacity(0.5);
	sphereActor->RotateY(-45.0);

	ren1->AddActor( sphereActor );
	ren1->SetBackground( 1.0, 1.0, 1.0 );

	renWin->AddRenderer( ren1 );
	renWin->SetSize( 300, 300 );

	double u=0.2;
	int uu=0;
	int n=0;
	while (1) {
		for (int i=0; i <ni; i++) {
			points->SetPoint(i,
					 (double)(i%20)*0.1,
					 (double)0.2*sin(u*i/10.0*u),
					 (double)(i/20));
		}
		u+=0.01;
		points->Modified();
		renWin->Render();

	vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
	iren->SetRenderWindow(renWin);
	iren->Initialize();
	iren->Start();
	}
	return 0;
}





More information about the vtkusers mailing list