[vtkusers] streamlines in a vtkUnstructuredGrid

Carlos Rafael Giani e0325834 at student.tuwien.ac.at
Sun Nov 18 09:30:57 EST 2007


Hi,

I have an unstructured grid, which contains points (vertices).
Each vertex has a vector as value, therefore the grid contains a vector 
field. I want to extract streamlines, however the resulting polydata 
structure is empty! I have no idea why. Any suggestions?

Code:



	vtkPointSource *seeds = vtkPointSource::New();
	seeds->SetRadius(0.15);
	seeds->SetCenter(0, 0, 0);
	seeds->SetNumberOfPoints(6);

	vtkUnstructuredGrid *grid = vtkUnstructuredGrid::New();
	vtkRungeKutta4 *integ = vtkRungeKutta4::New();
	vtkStreamTracer *streamline = vtkStreamTracer::New();
	streamline->SetSource(seeds->GetOutput());
	streamline->SetIntegrationDirectionToBoth();
	streamline->SetIntegrator(integ);

	vtkAssignAttribute *aa = vtkAssignAttribute::New();
	aa->SetInput(grid);
	aa->Assign(vtkDataSetAttributes::SCALARS, 
vtkDataSetAttributes::VECTORS, vtkAssignAttribute::POINT_DATA);

	streamline->SetInputConnection(aa->GetOutputPort());

	// Enter vector field data

	vtkPoints *points = vtkPoints::New();
	vtkFloatArray *vectors = vtkFloatArray::New();
	vtkCellArray *cell_array = vtkCellArray::New();
	vectors->SetNumberOfComponents(3);

	// test field... a uniform grid with (1,0,0) vectors
	for (vtkIdType i = 0; i < 1000; ++i)
	{
		int ii = i % 30;
		int jj = i / 30;
		points->InsertNextPoint(
			float(ii) / 30.0f,
			float(jj) / 30.0f,
			0
		);

		cell_array->InsertNextCell(1, &i);

		vectors->InsertNextValue(1);
		vectors->InsertNextValue(0);
		vectors->InsertNextValue(0);
	}

	grid->SetCells(VTK_VERTEX, cell_array);
	grid->SetPoints(points);
	grid->GetPointData()->SetVectors(vectors);

	streamline->Update();

	// debug output
	grid->Print(std::cout);
	aa->Print(std::cout);
	streamline->Print(std::cout);
	streamline->GetOutput()->Print(std::cout);

	cell_array->Delete();
	vectors->Delete();
	points->Delete();



More information about the vtkusers mailing list