[vtkusers] Strange behavior in vtkPlaneSource (maybe bug?)

Marco Sambin m.sambin at gmail.com
Tue Apr 16 16:26:15 EDT 2013


I would really appreciate a comment about this.
Thanks in advance,

Marco
 Il giorno 05/apr/2013 12:40, "Marco Sambin" <m.sambin at gmail.com> ha
scritto:

> Hi Berk,
>
> thank you for your message and explanation, which makes perfect sense.
>
> However, in this case I believe there may be an issue in the source code
> of the vtkImagePlaneWidget class. In particular, in the method
> vtkImagePlaneWidget::OnMouseMove(), I see:
>
> void vtkImagePlaneWidget::OnMouseMove()
> {
> [...]
>     else if ( this->State == vtkImagePlaneWidget::Rotating )
>     {
>     camera->GetViewPlaneNormal(vpn);
>     this->Rotate(prevPickPoint, pickPoint, vpn);
>     this->UpdatePlane();
>     this->UpdateMargins();
>     this->BuildRepresentation();
>     }
> [...]
> }
>
> The Rotate() method, in turn, ends with the following calls:
>
> void vtkImagePlaneWidget::Rotate(double *p1, double *p2, double *vpn)
> {
> [...]
>   double newpt[3];
>   this->Transform->TransformPoint(this->PlaneSource->GetPoint1(),newpt);
>   this->PlaneSource->SetPoint1(newpt);
>   this->Transform->TransformPoint(this->PlaneSource->GetPoint2(),newpt);
>   this->PlaneSource->SetPoint2(newpt);
>   this->Transform->TransformPoint(this->PlaneSource->GetOrigin(),newpt);
>   this->PlaneSource->SetOrigin(newpt);
> }
>
> Hence, the Point1, Point2, and Origin of the vtkPlaneSource are changed in
> this order.
> Now, the OnMouseMove() method calls UpdatePlane() immediately after
> Rotate(), and UpdatePlane in turn calls GetNormal() on PlaneSource without
> calling any Update() on it first:
>
> void vtkImagePlaneWidget::UpdatePlane()
> {
> [...] // No call to "this->PlaneSource->Update()" is present in the
> omitted code...
>
>   double normal[3];
>   this->PlaneSource->GetNormal(normal); // At this point the retrieved
> normal may be incorrect
> [...]
> }
>
> Maybe a "this->PlaneSource->Update()" call is missing somewhere?
> Thanks again for your comments.
>
> Best regards,
>
> Marco Sambin
>
>
> On Tue, Apr 2, 2013 at 5:19 PM, Berk Geveci <berk.geveci at kitware.com>wrote:
>
>> Please note that this is not a utility class. It is an algorithm. ALL
>> output that matters is produced after Update(). The fact that the normal is
>> updated in some cases before Update() is coincidental and you should not
>> rely on this behavior. If you are interested in calculating the normal of a
>> plane given 2 vectors, I suggest using a cross product as provided by
>> vtkMath.
>>
>> Best,
>> -berk
>>
>>
>>
>> On Thu, Mar 28, 2013 at 7:15 AM, Marco Sambin <m.sambin at gmail.com> wrote:
>>
>>> Hi all.
>>>
>>> I am using the vtkPlaneSource class in a VTK-derived class. I noticed
>>> that the following simple sequence of calls:
>>>
>>> =========================
>>> CODE A:
>>>
>>> double newO[3];
>>> double newP1[3];
>>> double newP2[3];
>>> double newNormal[3];
>>>
>>> // [...] set new values...
>>>
>>> myPlaneSource->SetPoint1(newP1);
>>> myPlaneSource->SetPoint2(newP2);
>>> myPlaneSource->SetOrigin(newO);
>>> myPlaneSource->GetNormal(newNormal);
>>> =========================
>>>
>>> finally returns a normal which seems INCORRECT to me.
>>> On the other side, the following sequence of calls (which differs from
>>> CODE A in the position of the SetOrigin() call):
>>>
>>> =========================
>>> CODE B:
>>>
>>> double newO[3];
>>> double newP1[3];
>>> double newP2[3];
>>> double newNormal[3];
>>>
>>> // [...] set new values...
>>>
>>> myPlaneSource->SetOrigin(newO);
>>> myPlaneSource->SetPoint1(newP1);
>>> myPlaneSource->SetPoint2(newP2);
>>> myPlaneSource->GetNormal(newNormal);
>>> =========================
>>>
>>> finally returns a normal which seems CORRECT.
>>> After taking a look at vtkPlaneSource.cxx source, I believe that the
>>> problem is that while the implementation of the SetPoint1() and SetPoint2()
>>> methods finally calls UpdatePlane(), which also updates the normal, the
>>> implementation of SetOrigin() does not update the normal. Hence, if
>>> SetOrigin() is the last call, the resulting normal is incorrect in my
>>> opinion.
>>>
>>> Can you please comment?
>>> Thanks in advance,
>>>
>>> Marco
>>>
>>>
>>> _______________________________________________
>>> 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
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130416/9083c029/attachment.htm>


More information about the vtkusers mailing list