[vtkusers] Can we add a check to see if we have at least 2 nodes when vtkContourWidget is in Manipulate state?

Yumin Yuan yumin.yuan at kitware.com
Mon Jan 25 13:46:32 EST 2016


Hi Mengda,

Since you are using the vtkImagePlaneWidget to get the points and then
inserting them programmatically into the vtkContourWidget, the
vtkContourWidget should not be enabled while you are doing this. It seems
like when you click in the render window, the vtkContourWidget::SelectAction
is also invoked (from your first email), which is not what you want. Try to
disable the vtkContourWidget while you are interacting with the plane
widget and inserting points into contour widget. You can enable the contour
widget after you have done inserting points.

HTH,
Yumin

On Fri, Jan 22, 2016 at 11:20 PM, Mengda Wu <wumengda at gmail.com> wrote:

> OK. I did not initialize it with a polydata but just used the method
> vtkContourWidget::Initialize(). I believe it means that there is no point
> in it.
> Then I set the state to Manipulate immediately with SetWidgetState(
> vtkContourWidget::Manipulate);
>
> After that, using some other code, I got the point from the pick point on
> vtkImagePlaneWidget and added it to vtkContourWidget with vtkContourWidget->
> GetContourRepresentation()->AddNodeAtWorldPosition(point);
>
> The first point is fine but it crashes when I tried to add the second
> point. The crashes happened in vtkLine::Intersection with the call stack as
> follows:
>
> vtkLine::Intersection(double * a1, double * a2, double * b1, double * b2,
> double & u, double & v) Line 117
> vtkContourRepresentation::FindClosestPointOnContour(int X, int Y, double
> * closestWorldPos, int * idx) Line 808
> vtkContourRepresentation::AddNodeOnContour(int X, int Y) Line 896
>
> Mengda
>
> On Fri, Jan 22, 2016 at 3:07 PM, Yumin Yuan <yumin.yuan at kitware.com>
> wrote:
>
>> Hi Mengda,
>>
>> I will suggest to figure out why it is crashing first. Even with only one
>> node, it should still work.
>>
>> Also, assuming you are using this method vtkContourWidget::Initialize(
>> vtkPolyData * poly, int state = 1, vtkIdList *idList = NULL ), your input
>> poly doesn't have any points?
>>
>> Yumin
>>
>> On Fri, Jan 22, 2016 at 10:40 AM, Mengda Wu <wumengda at gmail.com> wrote:
>>
>>> Hi all,
>>>
>>>    I would like to set the state of vtkContourWidget to Manipulate at
>>> initialize and add the nodes programmably instead of interactively.
>>> Everything is fine but I have to check the there are at least 2 nodes in
>>> the following, otherwise AddNodeOnContour will crash
>>>
>>> So I hope you can change the following function to
>>>
>>> void vtkContourWidget::SelectAction( vtkAbstractWidget *w )
>>> {
>>>
>>> ................
>>> ................
>>>
>>>   switch ( self->WidgetState )
>>>     {
>>>     case vtkContourWidget::Start:
>>>     case vtkContourWidget::Define:
>>> ................
>>> ................
>>>     case vtkContourWidget::Manipulate:
>>>       {
>>>       if ( rep->ActivateNode( X, Y ) )
>>>         {
>>> ................
>>> ................
>>>         }
>>>       else if ( rep->GetNumberOfNodes()>1 && rep->AddNodeOnContour( X, Y
>>> ) )   //Ensure the number of nodes is at least 2
>>>         {
>>> ................
>>> ................
>>>         }
>>> ................
>>> ................
>>> }
>>>
>>>
>>>
>>> _______________________________________________
>>> 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
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160125/bf0743b7/attachment.html>


More information about the vtkusers mailing list