<!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 "i" key to bring up the planewidget, I get an "Access Violation" in </FONT></P>
<P><FONT SIZE=2> </FONT>
<BR><FONT SIZE=2>//----------- vtk source --------</FONT>
<BR><FONT SIZE=2>void vtkInteractorObserver::ProcessEvents(vtkObject* vtkNotUsed(object), </FONT>
<BR><FONT SIZE=2> unsigned long event, void* clientdata, void* vtkNotUsed(calldata)) {</FONT>
<BR><FONT SIZE=2> vtkInteractorObserver* self </FONT>
<BR><FONT SIZE=2> = reinterpret_cast<vtkInteractorObserver *>( clientdata );</FONT>
</P>
<P><FONT SIZE=2> //look for char and delete events</FONT>
<BR><FONT SIZE=2> switch(event)</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> case vtkCommand::CharEvent:</FONT>
<BR><FONT SIZE=2> self->OnChar(); <<========= Access Violation here =======</FONT>
<BR><FONT SIZE=2> break;</FONT>
<BR><FONT SIZE=2> case vtkCommand::DeleteEvent:</FONT>
<BR><FONT SIZE=2> //self->Interactor = NULL; //commented out, can't write to a </FONT>
<BR><FONT SIZE=2> //self->Enabled = 0; //deleted object</FONT>
<BR><FONT SIZE=2> break;</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2>}</FONT>
<BR><FONT SIZE=2>//-------------------------</FONT>
</P>
<P><FONT SIZE=2>(2) With vtkWindow1->GetInteractor()->SetInteractorStyle(planeWidget), outlineActor becomes static (frozen). After pressing "I" 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 </FONT>
</P>
<BR>
<P><FONT SIZE=2> </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> static vtkTPWCallback *New()</FONT>
<BR><FONT SIZE=2> { return new vtkTPWCallback; }</FONT>
<BR><FONT SIZE=2> virtual void Execute(vtkObject *caller, unsigned long, void*)</FONT>
<BR><FONT SIZE=2> {</FONT>
<BR><FONT SIZE=2> vtkPlaneWidget *planeWidget = reinterpret_cast<vtkPlaneWidget*>(caller);</FONT>
<BR><FONT SIZE=2> planeWidget->GetPolyData(this->PolyData);</FONT>
<BR><FONT SIZE=2> this->Actor->VisibilityOn();</FONT>
<BR><FONT SIZE=2> }</FONT>
<BR><FONT SIZE=2> vtkTPWCallback():PolyData(0),Actor(0) {}</FONT>
<BR><FONT SIZE=2> vtkPolyData *PolyData;</FONT>
<BR><FONT SIZE=2> 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> vtkPLOT3DReader *pl3d = vtkPLOT3DReader::New();</FONT>
<BR><FONT SIZE=2> pl3d->SetXYZFileName("combxyz.bin");</FONT>
<BR><FONT SIZE=2> pl3d->SetQFileName("combq.bin");</FONT>
<BR><FONT SIZE=2> pl3d->SetScalarFunctionNumber(100);</FONT>
<BR><FONT SIZE=2> pl3d->SetVectorFunctionNumber(202);</FONT>
<BR><FONT SIZE=2> pl3d->Update();</FONT>
</P>
<P><FONT SIZE=2> vtkPolyData *plane = vtkPolyData::New();</FONT>
</P>
<P><FONT SIZE=2> vtkProbeFilter *probe = vtkProbeFilter::New();</FONT>
<BR><FONT SIZE=2> probe->SetInput(plane);</FONT>
<BR><FONT SIZE=2> probe->SetSource(pl3d->GetOutput());</FONT>
</P>
<P><FONT SIZE=2> vtkPolyDataMapper *probeMapper = vtkPolyDataMapper::New();</FONT>
<BR><FONT SIZE=2> probeMapper->SetInput(probe->GetPolyDataOutput());</FONT>
<BR><FONT SIZE=2> probeMapper->SetScalarRange(pl3d->GetOutput()->GetScalarRange());</FONT>
</P>
<P><FONT SIZE=2> vtkActor *probeActor = vtkActor::New();</FONT>
<BR><FONT SIZE=2> probeActor->SetMapper(probeMapper);</FONT>
<BR><FONT SIZE=2> probeActor->VisibilityOff();</FONT>
</P>
<P><FONT SIZE=2> // An outline is shown for context.</FONT>
<BR><FONT SIZE=2> vtkStructuredGridOutlineFilter *outline =</FONT>
<BR><FONT SIZE=2> vtkStructuredGridOutlineFilter::New();</FONT>
<BR><FONT SIZE=2> outline->SetInput(pl3d->GetOutput());</FONT>
</P>
<P><FONT SIZE=2> vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();</FONT>
<BR><FONT SIZE=2> outlineMapper->SetInput(outline->GetOutput());</FONT>
<BR><FONT SIZE=2> vtkActor *outlineActor = vtkActor::New();</FONT>
<BR><FONT SIZE=2> outlineActor->SetMapper(outlineMapper);</FONT>
</P>
<P><FONT SIZE=2> vtkTPWCallback *myCallback = vtkTPWCallback::New();</FONT>
<BR><FONT SIZE=2> myCallback->PolyData = plane;</FONT>
<BR><FONT SIZE=2> myCallback->Actor = probeActor;</FONT>
</P>
<P><FONT SIZE=2> vtkPlaneWidget *planeWidget = vtkPlaneWidget::New();</FONT>
<BR><FONT SIZE=2> //vtkWindow1->GetInteractor()->SetInteractorStyle(planeWidget);</FONT>
<BR><FONT SIZE=2> planeWidget->SetInteractor(vtkWindow1->GetInteractor());</FONT>
<BR><FONT SIZE=2> planeWidget->SetInput(pl3d->GetOutput());</FONT>
<BR><FONT SIZE=2> planeWidget->NormalToXAxisOn();</FONT>
<BR><FONT SIZE=2> planeWidget->SetResolution(20);</FONT>
<BR><FONT SIZE=2> planeWidget->SetRepresentationToOutline();</FONT>
<BR><FONT SIZE=2> planeWidget->PlaceWidget();</FONT>
<BR><FONT SIZE=2> planeWidget->AddObserver(vtkCommand::InteractionEvent,myCallback);</FONT>
</P>
<P><FONT SIZE=2> vtkWindow1->GetRenderer()->AddActor(probeActor);</FONT>
<BR><FONT SIZE=2> vtkWindow1->GetRenderer()->AddActor(outlineActor);</FONT>
</P>
<P><FONT SIZE=2> vtkWindow1->Invalidate();</FONT>
<BR><FONT SIZE=2> vtkWindow1->GetInteractor()->Initialize();</FONT>
<BR><FONT SIZE=2> vtkWindow1->GetInteractor()->Start();</FONT>
</P>
<P><FONT SIZE=2> // 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>>I use a vtkPlaneWidget to "probe" a volume data set and render my image</FONT>
<BR><FONT SIZE=2>>on a vtkBorlandRenderWindow (RenWin). This works OK and I could </FONT>
<BR><FONT SIZE=2>>interact with the planewidget (see attachment). The problem is that I </FONT>
<BR><FONT SIZE=2>>had to set</FONT>
</P>
<P><FONT SIZE=2>>RenWin->GetInteractor()->SetInteractorStyle(planeWidget);</FONT>
</P>
<P><FONT SIZE=2>this should not be done and it would be surprising if wierd behaviour were not happening. You should only be doing:</FONT>
</P>
<P><FONT SIZE=2>planeWidget->SetInteractor(RenWin->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>>But other actors are static and never respond to any mouse action after</FONT>
<BR><FONT SIZE=2>>I</FONT>
<BR><FONT SIZE=2>press "i"</FONT>
<BR><FONT SIZE=2>>key to exit planewidget interaction.</FONT>
</P>
<P><FONT SIZE=2>Were the actors interactive before you activated the plane widget with the "i" key? Why do you have to disable the rotation? 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: <<A HREF="http://public.kitware.com/cgi-bin/vtkfaq" TARGET="_blank">http://public.kitware.com/cgi-bin/vtkfaq</A>></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>