[vtkusers] How to show objects one by one

qxue at jouy.inra.fr qxue at jouy.inra.fr
Wed Jan 16 05:14:01 EST 2008


Hello, All,

    I am writing a program to show balls one by one, such as from 1 to 100.
Until now, I can just get the last 100 balls in the screen. That means the loop
in my program produce the data successfully but the rendering process can not
show the result one by one.
    What should I do to modify the structure?
    Thanks in advance.

Quan

int main(int argc, char * argv[])
{
	// create a GUI rendering
	vtkRenderer * ren = vtkRenderer::New();
	vtkRenderWindow * renWin = vtkRenderWindow::New();
	vtkRenderWindowInteractor * iren = vtkRenderWindowInteractor::New();
	vtkInteractorStyleTrackballCamera * style =
vtkInteractorStyleTrackballCamera::New();

	vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();

	ren->SetBackground(0.95, 0.95, 0.95);

	// create a wrapper class instance of MyVTKPointPlotter referenced from Peter
	MyVTKPointPlotter pointPlotter;

	// generate some random random points to plot
	vtkMath::RandomSeed(time(0));
	double p[3];

	for (int i=0; i<100; i++)
	{
		p[0] = vtkMath::Random(-100,100);
		p[1] = vtkMath::Random(-100,100);
		p[2] = vtkMath::Random(-100,100);
		pointPlotter.PlotPoint(p[0],p[1],p[2],128,0,128);


	//ren->AddActor(pointPlotter.CreateActor());
	vtkPolyData * polyData = pointPlotter.CreatePolyData();

	mapper->SetInput(polyData);
}
	vtkActor * actor = vtkActor::New();
	actor->SetMapper(mapper);


	ren->AddActor(actor);

	// create a render window
	renWin->AddRenderer(ren);
	renWin->SetSize(800,600);

	// create an interactor
	renWin->SetInteractor(iren);

	iren->SetInteractorStyle(style);

	// initialize and enter interactive mode
	iren->Initialize();
	iren->Start();

	return 0;
}



More information about the vtkusers mailing list