[vtkusers] Stream lines from custom data (Partially solved)

Sebastian Gatzka sebastian.gatzka at stud.tu-darmstadt.de
Thu Apr 15 10:10:02 EDT 2010


Thats exactly my problem!
I don't know how to color them, too!

-----Ursprüngliche Nachricht-----
Von: Gomez, Alberto [mailto:alberto.gomez at kcl.ac.uk] 
Gesendet: Donnerstag, 15. April 2010 15:45
An: Darshan Pai
Cc: Sebastian Gatzka; vtkusers
Betreff: Re: [vtkusers] Stream lines from custom data (Partially solved)

Hi, and thanks for the answers,

I somehow achieved to display my stream lines with stream tracer (also 
works with streamlines). The problem is now that they are all white, and 
I don't know how to colour them. Also, some help on how to set the 
different parameters efficiently (step length etc) would be of much 
help. My code is now:

for (int i = 0; i < num_pts; i++) {
        pts->InsertNextPoint(positions[i][0], positions[i][1], 
positions[i][2]);
        float tuple[3] = {(float) directions[i][0] * sf, (float) 
directions[i][1] * sf, (float) directions[i][2] * sf};
        vecArr->InsertNextTuple(tuple);

    }

vtkSmartPointer<vtkStructuredGrid> sGrid = 
vtkSmartPointer<vtkStructuredGrid>::New();
    sGrid->SetDimensions(num_pts,1,1); // Is this correct? if I remove 
this line it does not work
    sGrid->SetPoints(pts);
    sGrid->GetPointData()->SetVectors(vecArr);
//seeds
 vtkSmartPointer<vtkPolyData> startingPointsData = 
vtkSmartPointer<vtkPolyData>::New();
            startingPointsData->SetPoints(pts);

vtkSmartPointer<vtkRungeKutta4> integ = 
vtkSmartPointer<vtkRungeKutta4>::New();
vtkSmartPointer<vtkStreamTracer> streamer = 
vtkSmartPointer<vtkStreamTracer>::New();
        streamer->SetInput(sGrid);
        streamer->SetSource(startingPointsData);
        streamer->SetMaximumPropagation(2, 1); //This defines the length 
of the stream
        streamer->SetMinimumIntegrationStep(2, 0.1);
        streamer->SetMaximumIntegrationStep(2, 1.5);
        streamer->SetIntegrator(integ);
        streamer->SetIntegrationDirectionToForward();
        streamer->DebugOn();
        streamer->Update();

vtkSmartPointer<vtkPolyDataMapper> gMapper = vtkSmartPointer<
            vtkPolyDataMapper>::New();
    gMapper->SetInputConnection(streamer->GetOutputPort());
    gMapper->SetScalarRange(streamer->GetOutput()->GetScalarRange());

vtkSmartPointer<vtkActor> gactor = vtkSmartPointer<vtkActor>::New();
    gactor->SetMapper(gMapper);
    gactor->VisibilityOn();
    ren->AddActor(gactor);


etc.


Thanks!

Darshan Pai wrote:
> I dont see a SetPolys() or some variation of it which suggests that you
have cells in your StructuredGrid . Also If you do have then is thee number
of points equal to number of cells ? because the for loop where you input
your vectors suggest that you have a vector at each point and not at each
cell .
>
> On Wed, Apr 14, 2010 at 11:09 AM, Gomez, Alberto
<alberto.gomez at kcl.ac.uk<mailto:alberto.gomez at kcl.ac.uk>> wrote:
> Thanks for the quick answer,
>
> Unfortunately, it doesn't work for me: the vtkCellToPointData filter
crashes. Would you have a sample code that I can compare to mine? That would
be very useful :-).
>
> Anyway, I found out a tournaround that, I think, gets me closer to the
visualisation of streamlines (but does not work yet):
> ...
> ...
> vtkSmartPointer<vtkPolyData> sGrid = vtkSmartPointer<vtkPolyData>::New();
> sGrid->GetPointData()->SetVectors(vecArr);
>   sGrid->SetPoints(pts);
>
> vtkSmartPointer<vtkStreamLine> streamer =
vtkSmartPointer<vtkStreamLine>::New();
> streamer->SetInput(sGrid);
>
> Then I still see black but I get
>
>
> Debug: In /data/workspace/vtk-5.4.2/src/Filtering/vtkAlgorithm.h, line 150
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): setting AbortExecute
to 0
>
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.cxx, line 475
> vtkStreamLine (0x22fd980): Generating streamers
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 174
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning Integrator
address 0x2300f50
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 174
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning Integrator
address 0x2300f50
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 174
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning Integrator
address 0x2300f50
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 174
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning Integrator
address 0x2300f50
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 149
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
TerminalSpeed of 0
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 107
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
MaximumPropagationTime of 200
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 165
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
SavePointInterval of 0.1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 290
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
NumberOfStreamers of 1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 290
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
NumberOfStreamers of 1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 174
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning Integrator
address 0x2300f50
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 174
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning Integrator
address 0x2300f50
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 149
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
TerminalSpeed of 0
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 107
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
MaximumPropagationTime of 200
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 165
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
SavePointInterval of 0.1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 290
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
NumberOfStreamers of 1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 290
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
NumberOfStreamers of 1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 174
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning Integrator
address 0x2300f50
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 174
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning Integrator
address 0x2300f50
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 149
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
TerminalSpeed of 0
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 107
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
MaximumPropagationTime of 200
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 165
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
SavePointInterval of 0.1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 290
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
NumberOfStreamers of 1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 290
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
NumberOfStreamers of 1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 149
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
TerminalSpeed of 0
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 107
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
MaximumPropagationTime of 200
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 165
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
SavePointInterval of 0.1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 290
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
NumberOfStreamers of 1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamer.h, line 290
> vtkStreamLine (0x22fd980): vtkStreamLine (0x22fd980): returning
NumberOfStreamers of 1
>
> Debug: In /data/workspace/vtk-5.4.2/src/Graphics/vtkStreamLine.cxx, line
178
> vtkStreamLine (0x22fd980): Created 0 points, 0 lines
>
>
> Any clue?
>
> Thanks
> Sebastian Gatzka wrote:
> I had the same problem.
>
> You will have to use the vtkCellDataToPointData filter first!
> Input to the filter should be your structured grid.
>
> And then you can use the output from this filter as input to the stream
> line.
>
> -----Ursprüngliche Nachricht-----
> Von: vtkusers-bounces at vtk.org<mailto:vtkusers-bounces at vtk.org>
[mailto:vtkusers-bounces at vtk.org<mailto:vtkusers-bounces at vtk.org>] Im
Auftrag
> von Gomez, Alberto
> Gesendet: Mittwoch, 14. April 2010 16:05
> Cc: vtkusers
> Betreff: [vtkusers] Stream lines from custom data
>
> 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>
<mailto:alberto.gomez at kcl.ac.uk<mailto:alberto.gomez at kcl.ac.uk>>
>
> _______________________________________________
> Powered by www.kitware.com<http://www.kitware.com>
>
> Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
>   


-- 

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