[vtkusers] ploting an array of points to represent magnetic field intensity with VTK

Meisam Aliroteh meisam.aliroteh at gmail.com
Fri Aug 17 13:43:57 EDT 2007


Hi,

I'm not that familiar with magnetic fields stuff so I've re-worded the
problem as follows (to the best that I could understand) and I've also
presented a solution:

Let say we have the coordinates of a few points and we also have vectors
(direction and magnitude) that emanate from each point. How do we visualize
them?

There are different ways of doing this. One would be using Glyph3D and
ArrowSource in vtk but there is a trick to getting the magnitude of each
arrow to be the magnitude of the each force vector. So I have not presented
this approach. You can have a look at vtk documentation and examples to see
how this works. The other way is to present the vectors as line segments
whose length is equal to the force magnitude.
Here is how this is done:

1) We create a poly data
2) Loop over the points and:
    2.1) add it to the poly data (this will the starting point of a line
segment)
    2.2) compute the end point of the line segment (start point + force) and
add it to the poly data
    2.3) add the line segment to the poly data that joins these two points

Here is a partial C++ code:


int i; // used in a for-loop
int numPoints; // the number of points
double x[], y[], z[]; // x,y,z coordinate of the points
double vx[], vy[], vz[]; // the x,y,z coordinate of each vector

vtkPolyData *vecField = vtkPolyData::New();
vtkPoints *pnts = vtkPoints::New();

vecField->SetPoints( pnts );
vecField->Allocate();
int numAddedPoints = 0;
for(i=0; i<numPoints; i++)
{
    double start[] = { x[i], y[i], z[i] };
    double end[] = { x[i]+vx[i], y[i]+vy[i], z[i]+vz[i] };
    pnts->InsertNextPoint ( start );
    pnts->InsertNextPoint ( end );

    int ids[] = { numAddedPoints, numAddedPoints+1 };
    vecField->InsertNextCell( VTK_LINE, 2, ids );

    numAddedPoints += 2;
}
vecField->Squeeze();
All you need to do now is to use an actor to add the poly data to your scene
and render it :)


On 8/17/07, yadin Bocuma Rivas <conra2004 at yahoo.com> wrote:
>
> hi!
> i am planning to plot electromagnetic fiels using vtk
> at the mooment i got the x,y,z coordinates into arrays and i have the
> magnitude
> or intensity of the fields ; that is at every point(x,y,z) i have the
> value of the corresponding  component of the magnetic field in the x,y,z
> direction ;
> how can i visualise this magnetidc field with vtk ;  which commands can i
> use?
> i matlab I used quiver3(x,y,z,Ex,Ey,Ez) how can i do this with VTK
>
> is an array of points(x,y,z) and the field is (Ex,Ey,Ez) please how can i
> start doing these
>
> thanks
>
> __________________________________________________
> Correo Yahoo!
> Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
> Regístrate ya - http://correo.espanol.yahoo.com/
>
> _______________________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070817/5eb47f8d/attachment.htm>


More information about the vtkusers mailing list