[vtkusers] Contour, ContourWidget and triangles filler
Cory Quammen
cory.quammen at kitware.com
Thu Jul 16 15:28:32 EDT 2015
Oleg,
Yes, I think this is approach is fine. I'm not familiar with another way to
do what you are doing.
Best regards,
Cory
On Thu, Jul 16, 2015 at 2:56 PM, Oleg Krivosheev <
oleg.krivosheev at xcision.com> wrote:
> Hi, Cory
>
> thank you for the reply
>
> > You must be using VTK 5-something?
>
> yes, it is 5.10
>
> > Otherwise your example is pretty nice and compact in my opinion.
>
> thank you. General question, before I start implementing your suggestions,
> is it a right approach? Basically, we draw contour on top of the image. Now
> we want contour to have semi-transparent fill, and keep it up with, say,
> moved point or added point. Is it a good idea to do it with triangle strip?
> Maybe it is already done, and I'm reinventing the wheel, or there is an
> obvious and simpler way to do so
>
> thank you
>
> Oleg
>
> On Thu, Jul 16, 2015 at 10:41 AM, Cory Quammen <cory.quammen at kitware.com>
> wrote:
>
>> Hi Oleg,
>>
>> Welcome to VTK!
>>
>> Thanks for providing the code sample. You must be using VTK 5-something?
>> In 6 and above, your SetInput() calls need to be changed to SetInputData().
>> Also, as a general note about using VTK, you can use
>>
>> algorithm2.SetInputConnection(algorithm1.GetOutputPort())
>>
>> to create pipelines rather than pass vtkPolyData objects around. This is
>> usually preferable as any changes to your upstream algorithms will
>> propagate down to the renderer automatically. That might save you some code.
>>
>> Otherwise your example is pretty nice and compact in my opinion.
>>
>> To update the surface triangles, you need to set up an observer on the
>> contourWidget's InteractionEvent. You can do this with
>>
>> contourWidget.AddObserver('InteractionEvent', my_callback)
>>
>> where my_callback is defined with
>>
>> def my_callback(contourWidget, unused):
>> global contourWidget, mapper
>>
>> cd =
>> contourWidget.GetRepresentation().GetContourRepresentationAsPolyData()
>>
>> td = gen_triangles(cd)
>> mapper.SetInputData(td)
>>
>> Note that I've made the mapper global so you can access it in the
>> callback. The first argument is the contour widget and the second is just
>> the event type, which you don't need in this callback.
>>
>> By the way, you will likely get better results for the surface if you use
>> the following definition of gen_triangles:
>>
>> def gen_triangles(cd):
>> clsdPoly = vtk.vtkPolyData()
>> clsdPoly.Allocate()
>> clsdPoly.SetPoints(cd.GetPoints())
>>
>> numPts = cd.GetNumberOfPoints()
>> idList = vtk.vtkIdList()
>> idList.SetNumberOfIds(numPts)
>> [idList.SetId(i, i) for i in xrange(numPts)]
>>
>> clsdPoly.InsertNextCell(vtk.VTK_POLYGON, idList)
>>
>> triangles = vtk.vtkTriangleFilter()
>> triangles.SetInputData(clsdPoly)
>> triangles.Update()
>>
>> return triangles.GetOutput()
>>
>> This creates a VTK polygon cell which works better with the
>> vtkTriangleFilter than the line cells from the contour widget
>> representation.
>>
>> Hope that helps,
>> Cory
>>
>> On Wed, Jul 15, 2015 at 1:01 AM, Oleg Krivosheev <
>> oleg.krivosheev at xcision.com> wrote:
>>
>>> Hi, All
>>>
>>> what I'm trying to do is to have editable contour in vtkContourWidget,
>>> with internal
>>> area filled with somewhat transparent color. What I managed to do is to
>>> make contour,
>>> put it into a widget, generate triangles strip from the contour via
>>> vtkTriangleFilter and
>>> draw it all together, Python code at the link
>>>
>>> http://codepad.org/VPOa13St
>>>
>>> Now questions. Is it a good way to proceed? Looks very cumbersome to me,
>>> but I'm new to VTK.
>>>
>>> Another big question is how to connect contour edit action (say, moving
>>> or adding point)
>>> with triangle strip update. Right now as soon as I move point, contour
>>> is updated
>>> but triangles filler is not
>>>
>>> Any help is greatly appreciated
>>>
>>> regards
>>>
>>> OK
>>>
>>>
>>> _______________________________________________
>>> Powered by 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
>>>
>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>>
>>>
>>
>>
>> --
>> Cory Quammen
>> R&D Engineer
>> Kitware, Inc.
>>
>
>
--
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150716/be9e800b/attachment.html>
More information about the vtkusers
mailing list