[vtkusers] Cell data in a vtkPolyData object
Sander Niemeijer
niemeijer at science-and-technology.nl
Fri Aug 27 07:46:55 EDT 2004
Hi John,
As far as I can see you will still get incorrect behavior if you mix
cell types, even if you do it in the specific order you say. For
instance, in the example of my bug report (which is the same as the one
in my e-mail of January 2004), if I replace the order of the
initialization by:
---
points = vtk.vtkPoints()
# points for line 1 (line)
points.InsertNextPoint(0.5, 0.3, 0)
points.InsertNextPoint(0.5, 0.8, 0)
# points for triangle 1 (triangle)
points.InsertNextPoint(0.2, 0.3, 0)
points.InsertNextPoint(0.4, 0.55, 0)
points.InsertNextPoint(0.2, 0.8, 0)
# points for poly 2 (bar)
points.InsertNextPoint(0.6, 0.3, 0)
points.InsertNextPoint(0.8, 0.3, 0)
points.InsertNextPoint(0.8, 0.8, 0)
points.InsertNextPoint(0.6, 0.8, 0)
polydata.SetPoints(points)
# set scalar cell data
colors = vtk.vtkFloatArray()
polydata.GetCellData().SetScalars(colors)
# create line 1
ids = vtk.vtkIdList()
ids.InsertNextId(0)
ids.InsertNextId(1)
cell = polydata.InsertNextCell(VTK_LINE, ids)
# line 1 should get the second color (green)
colors.InsertTuple1(cell, 0.0)
# create poly 1
ids.Reset()
ids.InsertNextId(2)
ids.InsertNextId(3)
ids.InsertNextId(4)
cell = polydata.InsertNextCell(VTK_POLYGON, ids)
# poly 1 should get the first color (red)
colors.InsertTuple1(cell, 1.0)
# create poly 2
ids.Reset()
ids.InsertNextId(5)
ids.InsertNextId(6)
ids.InsertNextId(7)
ids.InsertNextId(8)
cell = polydata.InsertNextCell(VTK_POLYGON, ids)
# poly 2 should get the third color (blue)
colors.InsertTuple1(cell, 2.0)
---
So first the single line, and then the two polygons. I still get a
problem with the coloring of my cells (both with the 2D and 3D mapper).
If you know of a way to get this example showing proper colors using
just a single vtkpolydata object I would be very interested!
Best regards,
Sander
On vrijdag, aug 27, 2004, at 13:12 Europe/Amsterdam, John Biddiscombe
wrote:
>
> It's not so much that that the design of the polydata is bad, (well,
> it is
> really), but you need to know that all filters operate on cells in
> order of
> verts/lines/polys/strips and so all cell data needs to be stored in
> this
> order. Its extremely annoying and everyone who's used vtk for some
> length of
> time will have been bitten by this one - however, once you know about
> it,
> you always write your filters/importers/etc to operate like this and
> all is
> well.
>
> JB
>
> ----- Original Message -----
> From: "Sander Niemeijer" <niemeijer at science-and-technology.nl>
> To: "Charles Boivin" <Charles.Boivin at rwdiwest.com>
> Cc: <vtkusers at vtk.org>
> Sent: Friday, August 27, 2004 11:39 AM
> Subject: Re: [vtkusers] Cell data in a vtkPolyData object
>
>
>> Hi Charles,
>>
>> It's no wonder that it's puzzling you. The fact is that there is
>> something very wrong with the design of the vtkPolyData class.
>>
>> If you use a vtkPolyData object to store only one type of cells (i.e.
>> only vertices, or only lines, etc.) then everything goes well. But
>> once
>> you start to mix different types of cells in a vtkPolyData object you
>> will get into all kinds of trouble.
>>
>> See for instance my bug report:
>> http://www.vtk.org/Bug/bug.php?op=show&bugid=564&pos=0
>>
>> And the e-mail I send to the list about this:
>> http://public.kitware.com/pipermail/vtkusers/2004-January/071326.html
>>
>> The only advice I can give you is to use a different vtkPolyData
>> object
>> for each cell type you have.
>>
>> Best regards,
>> Sander
>>
>> On donderdag, aug 26, 2004, at 23:32 Europe/Amsterdam, Charles Boivin
>> wrote:
>>
>>> Hello everyone,
>>>
>>> Well, I am still working on my custom reader, and thanks to everyone
>>> here, a lot of progress has been made. I am able to load my geometry
>>> and
>>> connectivity properly using various types of cells (vertices, lines,
>>> and
>>> polygons), and that works pretty well. I have also been able to load
>>> any
>>> kind of point data (i.e. combinations of scalars, vectors, etc..)
>>> successfully.
>>>
>>> I then turned my attention to cell data. Cells are stored in the
>>> vtkPolyData class using different containers for vertices, lines and
>>> polygons, i.e. there is a separate vtkCellArray array for vertices,
>>> lines, and polygons. Those are set in vtkPolyData using
>>> vtkPolyData::SetVertices(), SetLines() and SetPolys(). (I don't mean
>>> to
>>> lecture anyone here, but I figured I would explain how I understand
>>> things; that way it would be easy for you to point out a flaw in my
>>> reasoning).
>>>
>>> I store my cell data in a vtkDoubleArray, and later set the cell data
>>> to it using a call to
>>> vtkPolyData::GetCellData()->AddArray(myCellDataArray). This is pretty
>>> much the same process that I (successfully) use for node data.
>>> However,
>>> things to do not look right for cell data if I have different types
>>> of
>>> cells (i.e. verts, lines, and polys) in my geometry.
>>>
>>> When I set the data, I need to specify an index to the cell, and then
>>> the data. How do I know what the index of the different cells are
>>> when
>>> stored in vtkPolyData if they are not all in the same container? I
>>> know
>>> the vtkCellArray::InsertCell() function returns an index to its
>>> position, but, for example, the vertices array does not know about
>>> the
>>> line array, and vice-versa. When I then have only *one* array for my
>>> data, how do I arrange it properly so that it matches the cells?
>>>
>>> I hope I made myself clear... this is a bit puzzling to me!
>>>
>>> Thank you in advance,
>>>
>>> Charles Boivin
>>> _______________________________________________
>>> This is the private VTK discussion list.
>>> Please keep messages on-topic. Check the FAQ at:
>>> <http://public.kitware.com/cgi-bin/vtkfaq>
>>> 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://public.kitware.com/cgi-bin/vtkfaq>
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>
More information about the vtkusers
mailing list