[vtkusers] Simple ContextView (2D API) problem
Eric E. Monson
emonson at cs.duke.edu
Mon May 24 10:49:35 EDT 2010
Hey Marcus,
Thanks -- that clarifies things a bit.
So, it looks like each ContextItem has access to it's own scene, and so it's up to us to make sure when we implement any new context item to make sure to set the scene to Dirty after we make any changes?
Maybe something like this patch should be applied to vtkBlockItem?:
diff --git a/Charts/vtkBlockItem.cxx b/Charts/vtkBlockItem.cxx
index 84cf15a..603284f 100644
--- a/Charts/vtkBlockItem.cxx
+++ b/Charts/vtkBlockItem.cxx
@@ -96,6 +96,7 @@ bool vtkBlockItem::Hit(const vtkContextMouseEvent &mouse)
bool vtkBlockItem::MouseEnterEvent(const vtkContextMouseEvent &)
{
this->MouseOver = true;
+ this->GetScene()->SetDirty(true);
return true;
}
@@ -112,6 +113,7 @@ bool vtkBlockItem::MouseMoveEvent(const vtkContextMouseEvent &mouse)
// Move the block by this amount
this->Dimensions[0] += deltaX;
this->Dimensions[1] += deltaY;
+ this->GetScene()->SetDirty(true);
return true;
}
@@ -122,6 +124,7 @@ bool vtkBlockItem::MouseMoveEvent(const vtkContextMouseEvent &mouse)
this->Dimensions[1] += deltaY;
this->Dimensions[2] -= deltaX;
this->Dimensions[3] -= deltaY;
+ this->GetScene()->SetDirty(true);
return true;
}
@@ -130,6 +133,7 @@ bool vtkBlockItem::MouseMoveEvent(const vtkContextMouseEvent &mouse)
// Resize the block by this amount
this->Dimensions[2] += deltaX;
this->Dimensions[3] += deltaY;
+ this->GetScene()->SetDirty(true);
return true;
}
@@ -140,6 +144,7 @@ bool vtkBlockItem::MouseMoveEvent(const vtkContextMouseEvent &mouse)
bool vtkBlockItem::MouseLeaveEvent(const vtkContextMouseEvent &)
{
this->MouseOver = false;
+ this->GetScene()->SetDirty(true);
return true;
}
I was also playing around with overlaying 2D API stuff over a normal 3D render window, so when I get back to that I may have some more questions.
Thanks for the quick reply,
-Eric
On May 24, 2010, at 9:44 AM, Marcus D. Hanwell wrote:
> On Mon, May 24, 2010 at 8:52 AM, Eric E. Monson <emonson at cs.duke.edu> wrote:
> Hello,
>
> I was trying to figure out something with the 2D API, but I'm having trouble with the mouse events. In this simple example, the block I create doesn't seem to actively respond to mouse events. Really it does, but they're just not rendered until I spin the scroll wheel on my mouse, and then you see the block suddenly move or turn red or resize as it's supposed to...
>
> #======================
> #!/usr/bin/env python
> import vtk
>
> cView = vtk.vtkContextView()
> cItem = vtk.vtkBlockItem()
> cItem.SetLabel('x')
> cItem.SetDimensions(60,100,60,30)
> cView.GetScene().AddItem(cItem)
>
> iren = cView.GetRenderWindow().GetInteractor()
> iren.Initialize()
> iren.Start()
> #======================
>
> Can anyone point me to what's going wrong? I'm sure most things work fine since I use the parallel coordinates charts almost every day which are based on the same 2D API, but I must be leaving out some step.
>
> It is tough for the scene to know when to re-render. I also wanted to allow batch operations before rendering again. You want to call SetDirty(true) on the context scene. This sets an ivar in the scene, and when mouse interaction is done it will trigger a render.
>
> It was pointed out to me that you should never unset a scene to dirty. And so the bool argument will probably disappear/be ignored.
>
> Hope that helps.
>
> Marcus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100524/2c8e6930/attachment.htm>
More information about the vtkusers
mailing list