[vtkusers] Stream lines from custom data

Gomez, Alberto alberto.gomez at kcl.ac.uk
Wed Apr 14 10:05:02 EDT 2010


Hi all,

I have been looking for a way to represent a vector field with stream 
lines, but I have not found a solution so far. My case differs from the 
example in http://www.itk.org/Wiki/VTK/Examples/StreamLines in two things:

I would like to use vtkStreamTracer as vtkStreamLine may be deprecated soon.
I am using custom data and not reading from a file.

So I have my points in the variable positions[][] ( size n x 3) and my 
vectors in the variable directions[][] (size n x 3 also).

I have tried  both StreamTracer and StreamLines but all I see is a black 
background. When using vtkStreamLines I get the error :

Debug: In /data/workspace/vtk-5.4.2/src/Filtering/vtkAlgorithm.h, line 150
vtkStreamLine (0x22a0880): vtkStreamLine (0x22a0880): setting 
AbortExecute to 0

Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.cxx, line 475
vtkStreamLine (0x22a0880): Generating streamers

ERROR: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.cxx, line 488
vtkStreamLine (0x22a0880): No vector data defined!

But I actually define the vectors, so I do not know what I am doing wrong.

This is my source code (an extract of it)


vtkSmartPointer<vtkPoints> pts = vtkSmartPointer<vtkPoints>::New();

    vtkSmartPointer<vtkDoubleArray> vecArr =    
vtkSmartPointer<vtkDoubleArray>::New();
    vecArr->SetNumberOfComponents(3);

    for (int i = 0; i < n; i++) {
        pts->InsertNextPoint(positions[i][0], positions[i][1], 
positions[i][2]);
        vecArr->InsertNextTuple3(directions[i][0] , directions[i][1] , 
directions[i][2] );
    }

// Generate the vector field
    vtkSmartPointer<vtkStructuredGrid> sGrid = 
vtkSmartPointer<vtkStructuredGrid>::New();
    sGrid->GetCellData()->SetVectors(vecArr);
    sGrid->SetPoints(pts);
//Generate start points
    vtkSmartPointer<vtkPointSource> seeds = 
vtkSmartPointer<vtkPointSource>::New();
        seeds->SetRadius(20.0);
        seeds->SetCenter(positions[0][0], positions[0][1], positions[0][2]);
        seeds->SetNumberOfPoints(100);

//vtkSmartPointer<vtkStreamTracer> streamer = 
vtkSmartPointer<vtkStreamTracer>::New();
    vtkSmartPointer<vtkStreamLine> streamer = 
vtkSmartPointer<vtkStreamLine>::New();

        streamer->SetInput(sGrid);
        streamer->SetSource(seeds->GetOutput());
  streamer->SetIntegrationDirection(0);
 streamer->DebugOn();
            streamer->Update();
    vtkSmartPointer<vtkPolyDataMapper> gMapper = vtkSmartPointer<
            vtkPolyDataMapper>::New();
    gMapper->SetInputConnection(streamer->GetOutputPort());
...


Many thanks!!!!

-- 

Alberto Gómez

/Division of Imaging Sciences
The Rayne Institute
4th Floor, Lambeth Wing
St Thomas' Hospital
London SE1 7EH /

phone: +44 (0) 20 718 88364
email: alberto.gomez at kcl.ac.uk <mailto:alberto.gomez at kcl.ac.uk>




More information about the vtkusers mailing list