[vtkusers] Is it possible to interact with the (vtk) data at the opengl/cuda level?

Micha Feigin michf at post.tau.ac.il
Fri Sep 11 21:45:41 EDT 2009


I'm looking for a minimum hassle way to display data I'm creating in cuda.

The data at the moment consists of a 2d array which represents wave flow
(numerical calculation of the 2d wave equation), later on it will go 3d though.
Currently I display it as a surface with color (the equivalent of the matlab
surf command).

The data is calculated on the gpu via cuda, but in order to transfer it to vtk
at the moment for display it goes via the host (cpu) memory which means a copy
back and fourth.

Cuda can work on opengl pixel buffer objects (pbo), vertex buffer objects (vbo)
and frame buffer objects (fbo). 

Is it possible to use any of these to communicate between cuda and opengl?
Is there a better way to achieve the same end result?

My current method of animation/data creation is:

attach a float array to data buffer
use structured grid attached to float array 
warp using a warp scalar
render the result

for animation, update the data buffer, call
	data->Modified(); // the float array, attached to the data buffer
	renderWinow->Render();

clifnotes:

------------ code -----------------------
(dataBuffer, contains the data which I later update)

	data = vtkFloatArray::New();
	data->SetArray(dataBuffer, width*height, 1);

	// ---------------
	// Create the grid
	// ---------------

	points = vtkPoints::New();
	points->SetNumberOfPoints(width*height*1);

	grid = vtkStructuredGrid::New();
	grid->SetDimensions(width, height, 1);

	for (int y = 0, index = 0 ; y < height ; y++)
	{
		for (int x = 0 ; x < width ; x++, index++)
		{
			points->SetPoint(index, ((width - 1 - x)*X0 + x*X1)/(width - 1),
				((height - 1 - y)*Y0 + y*Y1)/(height - 1), 0);
		}
	}

	grid->SetPoints(points);
	grid->GetPointData()->SetScalars(data);

	// -----------------
	// Create the filter
	// -----------------

	filter = vtkDataSetSurfaceFilter::New();
	filter->SetInput(grid);

	// ------------------------------------------------------------------------
	// Add a warp
	// This is an alternative to setting the height as part of the points array
	// ------------------------------------------------------------------------

	warp = vtkWarpScalar::New();
	warp->SetInputConnection(filter->GetOutputPort());
	warp->SetScaleFactor(scaleFactor);

	// -------------------------
	// Convert grid to polygons?
	// -------------------------

	mapper = vtkPolyDataMapper::New();
	mapper->SetInputConnection(warp->GetOutputPort());
	mapper->SetScalarRange(rangeLow, rangeHigh);

	// ----------------
	// Create the actor
	// ----------------

	actor = vtkActor::New();
	actor->SetMapper(mapper);

	// ------------------
	// Create the renerer
	// ------------------

	renderer = vtkRenderer::New();
	renderer->AddActor(actor);
	renderer->SetBackground(0.0, 0.0, 0.0);

	// ------------------------
	// Create the render window
	// ------------------------

	renderWinow = vtkRenderWindow::New();
	renderWinow->AddRenderer(renderer);
	renderWinow->SetSize(1000, 1000);

	// -----------------------------------
	// Create the render window interactor
	// -----------------------------------

	renderer->ResetCamera();

	light1 = vtkLight::New();
	light1->SetColor(1.0, 1.0, 1.0);
	light1->SetPosition(0, 0, -15.0 - rangeHigh);
	renderer->AddLight(light1);

	light2 = vtkLight::New();
	light2->SetColor(0.5, 0.5, 0.5);
	light2->SetPosition(0.0, 0.0, 15 - rangeLow);
	renderer->AddLight(light2);

	renderer->GetActiveCamera()->Roll(20);
	renderer->GetActiveCamera()->Elevation(230);
	renderer->GetActiveCamera()->Zoom(1.2);
	renderer->GetActiveCamera()->SetClippingRange(clippingNear, clippingFar);

	renderWinow->Render();



More information about the vtkusers mailing list