[vtkusers] How to close VTKRenderWindow automatically

alykhantejani alykhan.tejani06 at imperial.ac.uk
Tue Nov 26 09:13:12 EST 2013


I am using some simple code to render a mesh in a loop. In practice on each
iteration I will change the viewpoint and save an image of the rendering. I
have reduced this to a small compilable example below:

/    int main(int argc, char **argv) {
	vtkSmartPointer<vtkPLYReader> fileReader =
vtkSmartPointer<vtkPLYReader>::New();

	fileReader->SetFileName("benchvise_mesh.ply");
	fileReader->Update();
	vtkSmartPointer<vtkPolyData> polydata_ = fileReader->GetOutput();
	
	vtkSmartPointer<vtkRenderWindow> render_win =
vtkSmartPointer<vtkRenderWindow>::New();
	vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkActor> actor_view = vtkSmartPointer<vtkActor>::New();
	vtkSmartPointer<vtkCamera> cam = vtkSmartPointer<vtkCamera>::New();
	vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
	
	for (int i = 0; i < 100; i++) {
		
		mapper->SetInput(polydata_);
		mapper->Update();
		
	
		cam->SetViewAngle(58);
		cam->SetClippingRange(0.00001, 10000);
		//Invert view Up
		cam->SetViewUp(0, -1, 0);
		cam->SetPosition(0, 0, -500);
		cam->SetFocalPoint(0, 0, 1);
		cam->Modified();
		
		actor_view->SetMapper(mapper);
		actor_view->Modified();
		
		renderer->SetActiveCamera(cam);
		renderer->AddActor(actor_view);
		renderer->SetBackground(1.0, 1.0, 1.0);
		renderer->Modified();
		
		
		render_win->AddRenderer(renderer);
		render_win->SetSize(640, 480);
		//white
		render_win->Modified();
		

		render_win->Start();
		render_win->Render();
		render_win->Finalize();
		
	}
}/

The problem is, when I run this many vtkWindow icons appear on my taskbar
and eventually bring the pc to a halt. It appears as though on each loop the
rendering window stays alive. However, when I click on an icon the window
doesn't actually appear. 

Is there something I am missing that will clean up the render windows on
each iteration.

Thanks,
Aly

BTW, I am running under Ubntu with vtk 5.8



--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-close-VTKRenderWindow-automatically-tp5724647.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list