[vtkusers] streamlines in a vtkUnstructuredGrid

Dominik Szczerba domi at vision.ee.ethz.ch
Sun Nov 18 12:51:38 EST 2007


Is your data 2D or 3D?
If the former you can try to convert the data to polydata first.
--Dominik

On Sunday 18 November 2007 15.30:57 Carlos Rafael Giani wrote:
> 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();
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



-- 
Dominik Szczerba, Ph.D.
Computer Vision Lab CH-8092 Zurich
http://www.vision.ee.ethz.ch/~domi



More information about the vtkusers mailing list