<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2653.12">
<TITLE>[vtkusers]  (Resend) PlaneWidget and InteractorStyle in vtkBorlandRenderWindow</TITLE>
</HEAD>
<BODY>
<BR>

<P><FONT SIZE=2>Hi vtkusers,</FONT>
</P>

<P><FONT SIZE=2>The code appended below is adapted from \VTK\Hybrid\Testing\Cxx\TestPlaneWidget.cxx. Here are the problems associated with InteractorStyle and PlaneWidget in vtkBorlandRenderWindow. vtkWindow1 below is a vtkBorlandRenderWindow.</FONT></P>

<P><FONT SIZE=2>(1) With default InteractorStyle (trackballcamera??), the outlineActor shows up normally. But when I press &quot;i&quot; key to bring up the planewidget, I get an &quot;Access Violation&quot; in </FONT></P>

<P><FONT SIZE=2>&nbsp;</FONT>
<BR><FONT SIZE=2>//----------- vtk source --------</FONT>
<BR><FONT SIZE=2>void vtkInteractorObserver::ProcessEvents(vtkObject* vtkNotUsed(object), </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned long event, void* clientdata, void* vtkNotUsed(calldata)) {</FONT>
<BR><FONT SIZE=2>&nbsp; vtkInteractorObserver* self </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; = reinterpret_cast&lt;vtkInteractorObserver *&gt;( clientdata );</FONT>
</P>

<P><FONT SIZE=2>&nbsp; //look for char and delete events</FONT>
<BR><FONT SIZE=2>&nbsp; switch(event)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; case vtkCommand::CharEvent:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self-&gt;OnChar();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt;=========&nbsp; Access Violation here =======</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; case vtkCommand::DeleteEvent:</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //self-&gt;Interactor = NULL; //commented out, can't write to a </FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //self-&gt;Enabled = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //deleted object</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>//-------------------------</FONT>
</P>

<P><FONT SIZE=2>(2) With vtkWindow1-&gt;GetInteractor()-&gt;SetInteractorStyle(planeWidget), outlineActor becomes static (frozen). After pressing &quot;I&quot; key, the planewidget shows up normally and interaction is OK, but outlineActor remains static.</FONT></P>

<P><FONT SIZE=2>FYI, after some minor changes, \VTK\Hybrid\Testing\Cxx\TestPlaneWidget.cxx was compiled successfully with my Borland bcc32.exe and it worked as expected without any problems. </FONT></P>

<P><FONT SIZE=2>Thanks a lot for your help.</FONT>
</P>

<P><FONT SIZE=2>Yang&nbsp; </FONT>
</P>
<BR>

<P><FONT SIZE=2>&nbsp; </FONT>
<BR><FONT SIZE=2>// ========= Code ===================</FONT>
</P>

<P><FONT SIZE=2>class vtkTPWCallback : public vtkCommand</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2>public:</FONT>
<BR><FONT SIZE=2>&nbsp; static vtkTPWCallback *New()</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; { return new vtkTPWCallback; }</FONT>
<BR><FONT SIZE=2>&nbsp; virtual void Execute(vtkObject *caller, unsigned long, void*)</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; {</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vtkPlaneWidget *planeWidget = reinterpret_cast&lt;vtkPlaneWidget*&gt;(caller);</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; planeWidget-&gt;GetPolyData(this-&gt;PolyData);</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this-&gt;Actor-&gt;VisibilityOn();</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; }</FONT>
<BR><FONT SIZE=2>&nbsp; vtkTPWCallback():PolyData(0),Actor(0) {}</FONT>
<BR><FONT SIZE=2>&nbsp; vtkPolyData *PolyData;</FONT>
<BR><FONT SIZE=2>&nbsp; vtkActor *Actor;</FONT>
<BR><FONT SIZE=2>};</FONT>
</P>

<P><FONT SIZE=2>//---------------------------------------------------------------------------</FONT>
<BR><FONT SIZE=2>void __fastcall TVTK_Form::Button1Click(TObject *Sender)</FONT>
<BR><FONT SIZE=2>{</FONT>
<BR><FONT SIZE=2>&nbsp; vtkPLOT3DReader *pl3d = vtkPLOT3DReader::New();</FONT>
<BR><FONT SIZE=2>&nbsp; pl3d-&gt;SetXYZFileName(&quot;combxyz.bin&quot;);</FONT>
<BR><FONT SIZE=2>&nbsp; pl3d-&gt;SetQFileName(&quot;combq.bin&quot;);</FONT>
<BR><FONT SIZE=2>&nbsp; pl3d-&gt;SetScalarFunctionNumber(100);</FONT>
<BR><FONT SIZE=2>&nbsp; pl3d-&gt;SetVectorFunctionNumber(202);</FONT>
<BR><FONT SIZE=2>&nbsp; pl3d-&gt;Update();</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkPolyData *plane = vtkPolyData::New();</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkProbeFilter *probe = vtkProbeFilter::New();</FONT>
<BR><FONT SIZE=2>&nbsp; probe-&gt;SetInput(plane);</FONT>
<BR><FONT SIZE=2>&nbsp; probe-&gt;SetSource(pl3d-&gt;GetOutput());</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkPolyDataMapper *probeMapper = vtkPolyDataMapper::New();</FONT>
<BR><FONT SIZE=2>&nbsp; probeMapper-&gt;SetInput(probe-&gt;GetPolyDataOutput());</FONT>
<BR><FONT SIZE=2>&nbsp; probeMapper-&gt;SetScalarRange(pl3d-&gt;GetOutput()-&gt;GetScalarRange());</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkActor *probeActor = vtkActor::New();</FONT>
<BR><FONT SIZE=2>&nbsp; probeActor-&gt;SetMapper(probeMapper);</FONT>
<BR><FONT SIZE=2>&nbsp; probeActor-&gt;VisibilityOff();</FONT>
</P>

<P><FONT SIZE=2>&nbsp; // An outline is shown for context.</FONT>
<BR><FONT SIZE=2>&nbsp; vtkStructuredGridOutlineFilter *outline =</FONT>
<BR><FONT SIZE=2>&nbsp;&nbsp;&nbsp; vtkStructuredGridOutlineFilter::New();</FONT>
<BR><FONT SIZE=2>&nbsp; outline-&gt;SetInput(pl3d-&gt;GetOutput());</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();</FONT>
<BR><FONT SIZE=2>&nbsp; outlineMapper-&gt;SetInput(outline-&gt;GetOutput());</FONT>
<BR><FONT SIZE=2>&nbsp; vtkActor *outlineActor = vtkActor::New();</FONT>
<BR><FONT SIZE=2>&nbsp; outlineActor-&gt;SetMapper(outlineMapper);</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkTPWCallback *myCallback = vtkTPWCallback::New();</FONT>
<BR><FONT SIZE=2>&nbsp; myCallback-&gt;PolyData = plane;</FONT>
<BR><FONT SIZE=2>&nbsp; myCallback-&gt;Actor = probeActor;</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkPlaneWidget *planeWidget = vtkPlaneWidget::New();</FONT>
<BR><FONT SIZE=2>&nbsp; //vtkWindow1-&gt;GetInteractor()-&gt;SetInteractorStyle(planeWidget);</FONT>
<BR><FONT SIZE=2>&nbsp; planeWidget-&gt;SetInteractor(vtkWindow1-&gt;GetInteractor());</FONT>
<BR><FONT SIZE=2>&nbsp; planeWidget-&gt;SetInput(pl3d-&gt;GetOutput());</FONT>
<BR><FONT SIZE=2>&nbsp; planeWidget-&gt;NormalToXAxisOn();</FONT>
<BR><FONT SIZE=2>&nbsp; planeWidget-&gt;SetResolution(20);</FONT>
<BR><FONT SIZE=2>&nbsp; planeWidget-&gt;SetRepresentationToOutline();</FONT>
<BR><FONT SIZE=2>&nbsp; planeWidget-&gt;PlaceWidget();</FONT>
<BR><FONT SIZE=2>&nbsp; planeWidget-&gt;AddObserver(vtkCommand::InteractionEvent,myCallback);</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkWindow1-&gt;GetRenderer()-&gt;AddActor(probeActor);</FONT>
<BR><FONT SIZE=2>&nbsp; vtkWindow1-&gt;GetRenderer()-&gt;AddActor(outlineActor);</FONT>
</P>

<P><FONT SIZE=2>&nbsp; vtkWindow1-&gt;Invalidate();</FONT>
<BR><FONT SIZE=2>&nbsp; vtkWindow1-&gt;GetInteractor()-&gt;Initialize();</FONT>
<BR><FONT SIZE=2>&nbsp; vtkWindow1-&gt;GetInteractor()-&gt;Start();</FONT>
</P>

<P><FONT SIZE=2>&nbsp; // Delete() ....</FONT>
</P>

<P><FONT SIZE=2>}</FONT>
</P>
<BR>
<BR>

<P><FONT SIZE=2>-----Original Message-----</FONT>
<BR><FONT SIZE=2>From: Dean Inglis [<A HREF="mailto:dean.inglis@camris.ca">mailto:dean.inglis@camris.ca</A>] </FONT>
<BR><FONT SIZE=2>Sent: Thursday, November 06, 2003 1:49 PM</FONT>
<BR><FONT SIZE=2>To: vtkusers archive</FONT>
<BR><FONT SIZE=2>Subject: Re: [vtkusers] InteractorStyle in vtkBorlandRenderWindow</FONT>
</P>
<BR>

<P><FONT SIZE=2>Hi Yang,</FONT>
</P>
<BR>

<P><FONT SIZE=2>&gt;I use a vtkPlaneWidget to &quot;probe&quot; a volume data set and render my image</FONT>
<BR><FONT SIZE=2>&gt;on a vtkBorlandRenderWindow (RenWin). This works OK and I could </FONT>
<BR><FONT SIZE=2>&gt;interact with the planewidget (see attachment). The problem is that I </FONT>
<BR><FONT SIZE=2>&gt;had to set</FONT>
</P>

<P><FONT SIZE=2>&gt;RenWin-&gt;GetInteractor()-&gt;SetInteractorStyle(planeWidget);</FONT>
</P>

<P><FONT SIZE=2>this should not be done and it would be surprising if wierd behaviour were not happening.&nbsp; You should only be doing:</FONT>
</P>

<P><FONT SIZE=2>planeWidget-&gt;SetInteractor(RenWin-&gt;GetInteractor());</FONT>
</P>

<P><FONT SIZE=2>the other actors are static wehn you set the interactorstyle to the widget because planeWidget is not an interactorstyle in the usual sense.</FONT></P>

<P><FONT SIZE=2>&gt;But other actors are static and never respond to any mouse action after</FONT>
<BR><FONT SIZE=2>&gt;I</FONT>
<BR><FONT SIZE=2>press &quot;i&quot;</FONT>
<BR><FONT SIZE=2>&gt;key to exit planewidget interaction.</FONT>
</P>

<P><FONT SIZE=2>Were the actors interactive before you activated the plane widget with the &quot;i&quot; key?&nbsp; Why do you have to disable the rotation?&nbsp; You could set the interactorstyle of the borland renderwindow component to vtkInteractorStyleImage which has no left mouse button rotation capability.</FONT></P>

<P><FONT SIZE=2>Dean</FONT>
</P>
<BR>
<BR>
<BR>

<P><FONT SIZE=2>_______________________________________________</FONT>
<BR><FONT SIZE=2>This is the private VTK discussion list. </FONT>
<BR><FONT SIZE=2>Please keep messages on-topic. Check the FAQ at: &lt;<A HREF="http://public.kitware.com/cgi-bin/vtkfaq" TARGET="_blank">http://public.kitware.com/cgi-bin/vtkfaq</A>&gt;</FONT>
<BR><FONT SIZE=2>Follow this link to subscribe/unsubscribe: <A HREF="http://www.vtk.org/mailman/listinfo/vtkusers" TARGET="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</A></FONT>
</P>

</BODY>
</HTML>