[vtkusers] Improving rendering speed

Charl P. Botha c.p.botha at ewi.tudelft.nl
Wed Jun 18 11:53:05 EDT 2003


On Wed, 2003-06-18 at 17:20, Ajit Rajwadé wrote:
> From: "Charl P. Botha" <c.p.botha at its.tudelft.nl>
> >Ajit Rajwadé wrote:
> >>I need some tips for improving rendering speed. I am rendering a 3D 
> >>surface (from 8000 points) and it takes 15 seconds for the Render routine. 
> >>Is this merely a hardware problem?
> >
> >No, this is merely a user problem. :)
> >>   // Create isosurface
> >>vtkContourFilter *cf = vtkContourFilter::New();
> >>  cf->SetInput(surf->GetOutput());
> >>  cf->SetValue(0,0.0);
> >>  cout << "Isosurface construction done..." << endl;
> >
> >Don't you find it strange that when you run your program, this line prints 
> >out very soon after you start the program?  How do you think VTK knows to 
> >execute your surface reconstruction and contouring right here?
> >
> 
> Thanks, yes I should have noticed that in the beginning itself.
> 
> However, I am still facing the same trouble. It just takes too long to 
> render. 15 seconds for 8000 vertices is still bearble.  But I have models 
> consisting of 76000 vertices and they take 3 minutes or more to render.

Please keep this on the mailing list.  How are you measuring the time it
takes to render your frame?  Your code below is STILL performing the
calculation during your render!  In my applications, I routinely display
triangle models of a few hundred thousand vertices (derived from medical
data) and this remains more or less interactive, even on my old GeForce2
GTS.

> 
> Is there anything you could suggest me? I am sorry to disturb you, but I am 
> really stuck with this problem.
> 
> Here is my code again.
> 
> 		// Create the VTK renderer and renderer window
> 	    	vtkRenderer *ren = vtkRenderer::New();
> 		vtkRenderWindow *renWin = vtkRenderWindow::New();
> 		renWin->AddRenderer(ren);
> 		renWin->SetSize (300,300);
> 
> 		// Create the render window interactor
> 	    	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> 		iren->SetRenderWindow(renWin);
> 
> 	    	// Create points
>     		vtkPoints *meanPoints = vtkPoints::New();
> 
> 		// Copy Mean into New
> 		for (i=0;i<SIZE;i++)
> 			for (j=0;j<3;j++)
> 				New[i][j] = Mean [i][j];
> 
> 		// New += alpha * sigma * S - compute the points
> 		for (i=0;i<SIZE;i++)
> 		{
> 			for (j=1;j<=49;j++)
> 			{
> 				New[i][0] += storedPoints[j][i][0]*Alpha[j]*Sigma[j];
> 				New[i][1] += storedPoints[j][i][1]*Alpha[j]*Sigma[j];
> 				New[i][2] += storedPoints[j][i][2]*Alpha[j]*Sigma[j];
> 			}
> 		}
> 
> 		// Inserting the points one by one
> 		for (i=0;i<SIZE;i++)
> 		{
> 			point[0] = New[i][0];
> 			point[1] = New[i][1];
> 			point[2] = New[i][2];
> 
> 			meanPoints->InsertNextPoint(point);
> 		}
>     		printf("\nCalculation of points done...");
> 
>     		// Create a data set. Load the starting points
> 	    	vtkPolyData *inputDataSet = vtkPolyData::New();
> 	    	inputDataSet->SetPoints(meanPoints);
> 
> 		vtkTriangleFilter *vtf = vtkTriangleFilter::New ();
> 		vtf->SetInput (inputDataSet);
> 
> 	    	// Construct the surface
>     		vtkSurfaceReconstructionFilter *surf = 
> vtkSurfaceReconstructionFilter::New();
> 	    	surf->SetInput(inputDataSet);
>     		printf ("\nSurface construction done...");
> 
>     		// Create isosurface (contour value of 0)
> 	    	vtkContourFilter *cf = vtkContourFilter::New();
> 	    	cf->SetInput(surf->GetOutput());
> 	    	cf->SetValue(0,0.0);
> 		cf->UseScalarTreeOn ();
>     		printf("\nIsosurface construction done...");
> 
> 		// PolyNormals Filter to obtain normals for "Smooth Shading"
> 		vtkPolyDataNormals *bNormals = vtkPolyDataNormals::New();
>     		bNormals->SetInput(cf ->GetOutput());
>     		bNormals->SetFeatureAngle(60.0);
> 
> 		// Creates Triangle strips from the Iso-surface
>   		vtkStripper *bStripper = vtkStripper::New();
>     		bStripper->SetInput(bNormals->GetOutput());
> 
> 		// Create the mapper and actor and finish up the visualization pipeline
>     		vtkPolyDataMapper *map = vtkPolyDataMapper::New();
> 		map->SetInput(bStripper->GetOutput());
>     		map->ScalarVisibilityOff();
> 		//map->ImmediateModeRenderingOn ();
> 
> 	    	cout << "Mapper construction done..." << endl;
> 
> 	    	vtkActor *surfaceActor = vtkActor::New();
>     		surfaceActor->SetMapper( map );
> 	    	surfaceActor->GetProperty()->SetDiffuseColor( 1.0000, 0.3882, 0.2784 
> );
>     		surfaceActor->GetProperty()->SetSpecularColor( 1, 1, 1 );
> 	    	surfaceActor->GetProperty()->SetSpecular(0.4);
>     		surfaceActor->GetProperty()->SetSpecularPower(50);
> 
> 	    	ren->AddActor(surfaceActor);
>     		ren->SetBackground(1,1,1);
> 		cout << "Surface actor construction done..." << endl;
> 
> 		printf ("\nBefore the Rendering");
> 	   	renWin->Render();
>     		printf ("\nRendering done...");
> 		iren->Initialize ();
> 	    	iren->Start();
> 
> ===================================================================================
> 
> >Your complete VTK pipeline only starts to execute when you call the 
> >renWin->Render().  The 15 seconds that you're worrying about consists of 
> >the actual surface reconstruction AND rendering.  Try doing a 
> >bStripper->Update() BEFORE you begin to render.
> >
> >You don't have to use the Update(), it's only to illustrate my point. After 
> >your first long Render(), all subsequent Renders() should be much faster.
> >

-- 
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/



More information about the vtkusers mailing list