[vtkusers] FW: colour mapping stress ellipsoids
Ugur BOZKAYA
u.bozkaya at fmcon.com
Wed Aug 2 16:46:44 EDT 2006
Hi,
I suggest you not to use vtkTensorGlyph. Here is what is confusing, you
need 400 values for each tensor but vtkTensorGlyph accepts only one for
each tensor.(I might be wrong since I did not use it for sometime) May
be it can be manipulated but this will be more complicated.
You will need to create each tensor by your own. Normally in vtk, you
can just take a vtkSphereSource and define its axes and resolution to
create a polydata that results a tensor elipsoid. One way is you can
modify this class and add a dataarray to this class that will hold a
value for each point in the elipsoid. Anyway if you want to create your
own class vtkSphereSource should guide you.
About holding the data values; the geometry and data values of this
object is two independent things. Simply if you have a gray level image,
the geometry is a rectangular grid MxN (say 100x200). So you have MxN
points with 3D coordinates such as pnt0(0,0,0), pnt1(1,0,0),
pnt2(2,0,0)...pntM-1(M-1,0,0) in the first row.(assuming unit spacing
with 0,0,0 origin). Of course how this points are connected is important
this is done by inserting cells to data. But this is not an image yet,
we have to define data values(grey values). So you create a dataarray
such as vtkDoubleArray. Since this is a grey level image only one
component is necessary for each point. The vtkDoubleArray should be MxN
in size. If this was an RGB image the dataarray would have 3 components.
The point and the data values are matched according to their order. So
pnt0 will have the value of first value in vtkDoubleArray and so on...
You do this by setscalars() function.
In your case you will create a tensor in a specific coordinate. You have
to calculate the location of 400 pnts for this tensor. For each of these
pnts just calculate the color value and add it to your dataarray. Then
you have to define cells to construct the surface.(briefly create
triangles from 3 closest pnts on the surface and add it as a cell)
This whole process will be done for each tensor of course.
For the calculation of color values, you can use vnl which is included
in itk to allow matlab like operations. Otherwise just write or find a
function that will handle tensor product. dot product and norm can be
found in vtkMath class.
good luck
Mecit Yaman wrote:
>
> hi, thanks for the replies.
>
> i need to clarify one thing straight. the coloring i am trying is not
> restricted to three orthogonal dimension as ugur assumed. for each
> tensor, i need a set of colors calculated for each theta and phi
> direction (in the spherical coordinates.) assuming a thetaResolution
> of 20 and phiresolution of 20, color scalar array will be 400 scalars.
> i tried to explain how i get the colors in the first message.
> basically a colour is calculated from the surface normal and vector at
> that location (the vector is calculated from the tensor by a scalar
> product of the tensor and the surface normal) (see my first message
> below.) although the visualization idea is complicated, i know that
> vtk script should not necessarily be as complex.
>
> a visualization task with vtk follows
>
> source > filters> mapper > actor >rendering
>
> i understand i need to scale and aling a vtkTensorGlyph using my
> tensor. then i need to create a vtkDoubleArray with 400 components
> using the same tensor and vtkTensorGlpyh surface normals. what is not
> clear to me is: how to calculate the color array and store them in a
> vtkDoubleArray from the tensor and surface normals. i suppose i need
> to getSurfaceNormals and multiply them component by component with my
> tensor to obtain another set of vectors. and with this new set i need
> to do scalar multiplication with the surface normals to get the scalar
> color array.
>
> once i have a scalar array i assign them to the vtkTensorGlyph, as
> luca wrote, with vtkPolyData::GetPointData::SetScalars(array).
>
> i am familiar with vtk theoretically and used it for straightforward
> tasks. i will appreciate any help regarding how to practically create
> the color array. btw i’m using java to write the scripts.
>
> cheers,
>
> mecit yaman
>
> university of cape town
>
> ------------------------------------------------------------------------
>
> *From:* Luca Pallozzi Lavorante [mailto:lplavorante at gmail.com]
> *Sent:* 25 July 2006 01:55 PM
> *To:* yaman at myhorizon.org
> *Subject:* Re: [vtkusers] colour mapping stress ellipsoids
>
> Yaman, I do agree with Ugur.
> I have used the vtkTensorGlyph class in order to get strain
> ellipsoids. I also have tried to color the deformed object and, as far
> as I know, the only way is to associate scalar values to the object´s
> points through the vtkFloatArray or vtkDoubleArray. Once you created
> the array, the association is made via a call like
> vtkPolyData::GetPointData::SetScalars(array).
> I hope this helps
>
> Luca
>
> On 7/24/06, *Ugur BOZKAYA* <u.bozkaya at fmcon.com
> <mailto:u.bozkaya at fmcon.com>> wrote:
>
> Selam Mecit,
>
> As far as I know, there is no class for this purpose in VTK currently.
> vtkTensorGlyph and vtkGlyph3D can be used for typical tensor
> visualization. But the tensors are shown only in one color(RGB is also
> possible I guess, but it will not solve your problem). If you are
> familiar enough with VTK, you can change these classes for your purpose.
> Those glyph shapes such as ellipsoids (deformed spheres) are already
> defined as vtkPolyData, so you can use other shapes.
>
> I assume you are planning to use 3 orthogonal directions for coloring.
> You only need a vtkDataArray (e.g. vtkDoubleArray) with 3 components. So
> for each tensor location you will have 3 values.
>
> I guess it will be easier to write your own class which looks simpler.
> You will have your output as vtkPolyData, which is actually composed of
> your tensors. May be you can have a function which calculates a
> tensorshape(multicolored vtkPolyData) for a given location then you can
> add the output of this function to your volume output for each location.
>
> Good Luck,
> Ugur
>
> Mecit Yaman wrote:
> > hi,
> >
> > i am trying to visualize second order tensors using stress ellipsoids
> with a
> > different color mapping. the usual colouring is to map a scalar
> value, e.g.
> > components, effective stress, trace or other scalars on the surface.
> i want
> > to do a colouring where each point/polygon on the ellipsoid will be
> coloured
> > differently. the color scheme is defined as follows:
> >
> > the color along direction n(i) of the ellipsoid is obtained from the
> angle
> > between the n(i), direction vector, and the stress vector along n(i).
> (the
> > stress vector along a direction can be obtained by multiplying the stress
> > tensor, T(ij) with the direction vector, n(i)). Thus:
> >
> > T(ij) tensor
> > n(i) direction vector
> >
> > stress vector(i) = T(ij) . n(i)
> >
> > angle between stress vector and direction vector
> >
> > cos(angle) = stress vector (i) . n(i) / ( |stress vector(i)| | n(i)|)
> >
> > how does one colour map these angles, which are different for every
> > direction on an ellipsoid? do I need to change stress ellipsoid into a
> > polygonal data type? how do I calculate and store the angles in VTK?
> >
> > i am able to render the icons in Mathematica, and will be happy to share
> > information with anyone interested.
> >
> > thanks,
> >
> > M Yaman
> > University of Cape Town
> >
> >
> >
> > _______________________________________________
> > 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
> >
> >
>
> _______________________________________________
> 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
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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
>
More information about the vtkusers
mailing list