[Numpy-discussion] constant shaded triangle mesh in mayavi2

Geoffrey Irving irving at naml.us
Fri Oct 1 00:04:19 EDT 2010


On Fri, Oct 1, 2010 at 11:39 AM, Robert Kern <robert.kern at gmail.com> wrote:
> On Thu, Sep 30, 2010 at 16:26, Geoffrey Irving <irving at naml.us> wrote:
>> On Fri, Oct 1, 2010 at 10:18 AM, Robert Kern <robert.kern at gmail.com> wrote:
>>> On Thu, Sep 30, 2010 at 16:00, Geoffrey Irving <irving at naml.us> wrote:
>>>> On Fri, Oct 1, 2010 at 9:38 AM, Robert Kern <robert.kern at gmail.com> wrote:
>>>>> On Thu, Sep 30, 2010 at 15:30, Geoffrey Irving <irving at naml.us> wrote:
>>>>>> Hello,
>>>>>>
>>>>>> I'm not sure where the correct place to ask questions about Mayavi, so
>>>>>> feel free to redirect me elsewhere.
>>>>>
>>>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>>>>
>>>>>> I have a triangle mesh with a bunch of data on each face.  The only
>>>>>> color-relevant argument to triangular_mesh I know about is scalars,
>>>>>> which is one value per vertex.  Is there a way to set color per
>>>>>> triangle, ideally with control over rgb separately so I can visualize
>>>>>> three different fields at once?
>>>>>
>>>>> Pretty difficult, unfortunately. The only way I have found is to
>>>>> assign UV texture coordinates to the vertices and slap on a texture.
>>>>> Assigning the UV coordinates is usually not easy.
>>>>
>>>> Is this a limitation in VTK, TVTK, or the Mayavi python code?  The VTK
>>>> documentation seems to imply it supports cell data on polygon meshes
>>>> (though I don't know how one would set them):
>>>>
>>>>    http://www.vtk.org/doc/release/5.6/html/a01445.html
>>>>    "Point and cell attribute values (e.g., scalars, vectors, etc.)
>>>> also are represented"
>>>>
>>>> I'm happy to hack TVTK or Mayavi (in order of happiness) to support
>>>> cell data if VTK supports it.
>>>
>>> It's a VTK restriction. You can store whatever data you like on the on
>>> the vertices or cells. There is no mapper (that I am aware of) that
>>> takes that data and interprets them as RGB values on a per-vertex or
>>> per-cell basis. There are mappers that turn scalar vertex and cell
>>> attribute values into colors through a colormap table, but that's not
>>> what you are asking for.
>>
>> Visualizing a signle cell scalar field is still quite useful (the data
>> doesn't correspond to color).  In other words, the per-cell part of
>> the question is more important than than the RGB part.  Is there a
>> current way to set a cell attribute value on a Mayavi triangular_mesh?
>
> You're better off not using triangular_mesh(). Construct the mesh
> separately from the surface.
>
>  s = mlab.pipeline.triangular_mesh_source(x,y,z,triangles)
>  s.data.cell_data.scalars = .... # Your data here.
>  surf = mlab.pipeline.surface(s)
>  surf.contours.filled_contours = True

Cool, that seems to work for static plots (with "contours" replaced
with "contour").  However, it breaks dynamic updates if I change data
interactively on trait changes.  For vertex data, I'm using the
following code for interactive updates:

    @on_trait_change('threshold')
    def update_plot(self):
        self.plot.mlab_source.set(scalars=self.scalars())

borrowed from

    http://code.enthought.com/projects/mayavi/docs/development/html/mayavi/auto/example_mlab_interactive_dialog.html#example-mlab-interactive-dialog

where plot is generated with triangular_mesh().  How do I force an
update of the surface if I generate it myself and use cell data?

Thanks,
Geoffrey



More information about the NumPy-Discussion mailing list