<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Helvetica, Arial, sans-serif">Sorry to
bother again. Your code is not working as planned.<br>
<br>
It runs, cuts the sphere in half and displays "Hello World".<br>
When interacting with the implicitPlaneWidget (which is possible:
translation, rotation etc.) nothing happens to the sphere and even the
counter does not take effect.<br>
<br>
When pressing "e" the code crashes with a heap corruption.<br>
<br>
Is there something wrong with our compiler, or did you miss to tell me
anything about using callback functions?<br>
By the way: Is there any kind of tutorial about how to handle a
callback function correctly?!<br>
<br>
</font></font><br>
Am 12.03.2010 15:42, schrieb David Doria:
<blockquote
 cite="mid:c19fcadc1003120642h52d70990jbdc9f6aef606d795@mail.gmail.com"
 type="cite">
  <div><br>
  </div>
  <div class="gmail_quote">On Fri, Mar 12, 2010 at 7:17 AM, Sebastian
Gatzka <span dir="ltr">&lt;<a moz-do-not-send="true"
 href="mailto:sebastian.gatzka@stud.tu-darmstadt.de">sebastian.gatzka@stud.tu-darmstadt.de</a>&gt;</span>
wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
    <div bgcolor="#ffffff" text="#000000">
    <font size="-1"><font face="Helvetica, Arial, sans-serif">Or can I
talk
to the textActor like this?<br>
    <br>
    <font color="#ff0000" face="Courier New, Courier, monospace">&nbsp;&nbsp;&nbsp;
vtkTextActor *ta = reinterpret_cast&lt;vtkTextActor*&gt;(caller);<br>
&nbsp;&nbsp;&nbsp; ta-&gt;SetInput("TEST");</font><br>
    <br>
or like this?<br>
    <br>
    <font color="#ff0000" face="Courier New, Courier, monospace">&nbsp;&nbsp;
this-&gt;TextActor-&gt;SetInput("TEST");</font><br>
    <br>
No, does not work either way.<br>
    </font></font></div>
    <div bgcolor="#ffffff" text="#000000"><font size="-1"><font
 face="Helvetica, Arial, sans-serif"><br>
    </font></font></div>
  </blockquote>
  <div><br>
  </div>
  <div>Ok, let's close this question - here is an example that updates
a counter in the lower left corner of the renderwindow every time an
interaction occurs. This should be easy to adapt to do what you want.</div>
  <div><br>
  </div>
  <div>#include &lt;sstream&gt;</div>
  <div><br>
  </div>
  <div>#include &lt;vtkSmartPointer.h&gt;</div>
  <div>#include &lt;vtkProperty.h&gt;</div>
  <div>#include &lt;vtkTextProperty.h&gt;</div>
  <div><br>
  </div>
  <div>#include &lt;vtkXMLPolyDataReader.h&gt;</div>
  <div>#include &lt;vtkSphereSource.h&gt;</div>
  <div>#include &lt;vtkClipPolyData.h&gt;</div>
  <div>#include &lt;vtkPlane.h&gt;</div>
  <div><br>
  </div>
  <div>#include &lt;vtkCommand.h&gt;</div>
  <div>#include &lt;vtkImplicitPlaneWidget2.h&gt;</div>
  <div>#include &lt;vtkImplicitPlaneRepresentation.h&gt;</div>
  <div>&nbsp;</div>
  <div>#include &lt;vtkPolyDataMapper.h&gt;</div>
  <div>#include &lt;vtkProperty.h&gt;</div>
  <div>#include &lt;vtkActor.h&gt;</div>
  <div>#include &lt;vtkTextActor.h&gt;</div>
  <div>#include &lt;vtkRenderWindow.h&gt;</div>
  <div>#include &lt;vtkRenderer.h&gt;</div>
  <div>#include &lt;vtkRenderWindowInteractor.h&gt;</div>
  <div><br>
  </div>
  <div>// Callback for the interaction</div>
  <div>// This does the actual work: updates the vtkPlane implicit
function.</div>
  <div>// This in turn causes the pipeline to update and clip the
object.</div>
  <div>class vtkIPWCallback : public vtkCommand</div>
  <div>{</div>
  <div>&nbsp;&nbsp;public:</div>
  <div>&nbsp;&nbsp; &nbsp;static vtkIPWCallback *New()&nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp;{</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;return new vtkIPWCallback;&nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp;}</div>
  <div>&nbsp;&nbsp; &nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp;virtual void Execute(vtkObject *caller, unsigned long, void*)</div>
  <div>&nbsp;&nbsp; &nbsp;{</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkImplicitPlaneWidget2 *planeWidget =&nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;reinterpret_cast&lt;vtkImplicitPlaneWidget2*&gt;(caller);</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkImplicitPlaneRepresentation *rep =&nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;reinterpret_cast&lt;vtkImplicitPlaneRepresentation*&gt;(planeWidget-&gt;GetRepresentation());</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;rep-&gt;GetPlane(this-&gt;Plane);</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;std::stringstream ss;</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;ss &lt;&lt; this-&gt;counter;</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;this-&gt;TextActor-&gt;SetInput (ss.str().c_str());</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;this-&gt;counter++;</div>
  <div>&nbsp;&nbsp; &nbsp;}</div>
  <div>&nbsp;&nbsp; &nbsp;vtkIPWCallback():Plane(0),TextActor(0),counter(0) {}</div>
  <div>&nbsp;&nbsp; &nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp;void SetPlane(vtkPlane* plane) { this-&gt;Plane = plane;}</div>
  <div>&nbsp;&nbsp; &nbsp;void SetTextActor(vtkTextActor* textActor) {
this-&gt;TextActor = textActor;}</div>
  <div>&nbsp;&nbsp; &nbsp;</div>
  <div>&nbsp;&nbsp;private:</div>
  <div>&nbsp;&nbsp; &nbsp;unsigned int counter;</div>
  <div>&nbsp;&nbsp; &nbsp;vtkPlane* Plane;</div>
  <div>&nbsp;&nbsp; &nbsp;vtkTextActor* TextActor;</div>
  <div><br>
  </div>
  <div>};</div>
  <div><br>
  </div>
  <div>int main(int argc, char *argv[])</div>
  <div>{</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkSphereSource&gt; sphereSource =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkSphereSource&gt;::New();</div>
  <div>&nbsp;&nbsp;sphereSource-&gt;SetRadius(10.0);</div>
  <div><br>
  </div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkXMLPolyDataReader&gt; reader =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkXMLPolyDataReader&gt;::New();</div>
  <div><br>
  </div>
  <div>&nbsp;&nbsp;// Setup a visualization pipeline</div>
  <div><br>
  </div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkPlane&gt; plane =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkPlane&gt;::New();</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkClipPolyData&gt; clipper =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkClipPolyData&gt;::New();</div>
  <div>&nbsp;&nbsp;clipper-&gt;SetClipFunction(plane);</div>
  <div>&nbsp;&nbsp;clipper-&gt;InsideOutOn();</div>
  <div>&nbsp;&nbsp;if (argc &lt; 2)</div>
  <div>&nbsp;&nbsp;{</div>
  <div>&nbsp;&nbsp;
&nbsp;clipper-&gt;SetInputConnection(sphereSource-&gt;GetOutputPort());</div>
  <div>&nbsp;&nbsp;}</div>
  <div>&nbsp;&nbsp;else</div>
  <div>&nbsp;&nbsp;{</div>
  <div>&nbsp;&nbsp; &nbsp;reader-&gt;SetFileName(argv[1]);</div>
  <div>&nbsp;&nbsp; &nbsp;clipper-&gt;SetInputConnection(reader-&gt;GetOutputPort());</div>
  <div>&nbsp;&nbsp;}</div>
  <div>&nbsp;&nbsp;//Create a mapper and actor</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkPolyDataMapper&gt; mapper =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();</div>
  <div>&nbsp;&nbsp;mapper-&gt;SetInputConnection(clipper-&gt;GetOutputPort());</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkActor&gt; actor =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkActor&gt;::New();</div>
  <div>&nbsp;&nbsp;actor-&gt;SetMapper(mapper);</div>
  <div><br>
  </div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkProperty&gt; backFaces =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkProperty&gt;::New();</div>
  <div>&nbsp;&nbsp;backFaces-&gt;SetDiffuseColor(.8, .8, .4);</div>
  <div><br>
  </div>
  <div>&nbsp;&nbsp;actor-&gt;SetBackfaceProperty(backFaces);</div>
  <div>&nbsp;</div>
  <div>&nbsp;&nbsp;// a renderer and render window</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkRenderer&gt; renderer =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkRenderer&gt;::New();</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkRenderWindow&gt; renderWindow =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkRenderWindow&gt;::New();</div>
  <div>&nbsp;&nbsp;renderWindow-&gt;AddRenderer(renderer);</div>
  <div>&nbsp;&nbsp;renderer-&gt;AddActor(actor);</div>
  <div>&nbsp;</div>
  <div>&nbsp;&nbsp;// an interactor</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;
renderWindowInteractor =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkRenderWindowInteractor&gt;::New();</div>
  <div>&nbsp;&nbsp;renderWindowInteractor-&gt;SetRenderWindow(renderWindow);</div>
  <div>&nbsp;</div>
  <div>&nbsp;&nbsp;renderWindow-&gt;Render();</div>
  <div><br>
  </div>
  <div>&nbsp;&nbsp;// The callback will do the work</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkIPWCallback&gt; myCallback =&nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkIPWCallback&gt;::New();</div>
  <div>&nbsp;&nbsp;myCallback-&gt;SetPlane(plane);</div>
  <div>&nbsp;&nbsp;</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkTextActor&gt; textActor =&nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkTextActor&gt;::New();</div>
  <div>&nbsp;&nbsp;textActor-&gt;SetInput ( "Hello world" );</div>
  <div>&nbsp;&nbsp;textActor-&gt;GetTextProperty()-&gt;SetColor ( 1.0,0.0,0.0 );</div>
  <div>&nbsp;&nbsp;myCallback-&gt;SetTextActor(textActor);</div>
  <div>&nbsp;&nbsp;renderer-&gt;AddActor2D ( textActor );</div>
  <div><br>
  </div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkImplicitPlaneRepresentation&gt; rep =&nbsp;</div>
  <div>&nbsp;&nbsp; &nbsp;
&nbsp;vtkSmartPointer&lt;vtkImplicitPlaneRepresentation&gt;::New();</div>
  <div>&nbsp;&nbsp;rep-&gt;SetPlaceFactor(1.25); // This must be set prior to
placing the widget</div>
  <div>&nbsp;&nbsp;rep-&gt;PlaceWidget(actor-&gt;GetBounds());</div>
  <div>&nbsp;&nbsp;rep-&gt;SetNormal(plane-&gt;GetNormal());</div>
  <div>&nbsp;&nbsp;rep-&gt;SetOrigin(0,0,50);</div>
  <div>&nbsp;&nbsp;</div>
  <div>&nbsp;&nbsp;vtkSmartPointer&lt;vtkImplicitPlaneWidget2&gt; planeWidget =</div>
  <div>&nbsp;&nbsp; &nbsp; &nbsp;vtkSmartPointer&lt;vtkImplicitPlaneWidget2&gt;::New();</div>
  <div>&nbsp;&nbsp;planeWidget-&gt;SetInteractor(renderWindowInteractor);</div>
  <div>&nbsp;&nbsp;planeWidget-&gt;SetRepresentation(rep);</div>
  <div>&nbsp;&nbsp;planeWidget-&gt;AddObserver(vtkCommand::InteractionEvent,myCallback);</div>
  <div><br>
  </div>
  <div>&nbsp;&nbsp;// render an image (lights and cameras are created
automatically)</div>
  <div>&nbsp;</div>
  <div>&nbsp;&nbsp;renderWindowInteractor-&gt;Initialize();</div>
  <div>&nbsp;&nbsp;renderWindow-&gt;Render();</div>
  <div>&nbsp;&nbsp;planeWidget-&gt;On();</div>
  <div>&nbsp;</div>
  <div>&nbsp;&nbsp;// begin mouse interaction</div>
  <div>&nbsp;&nbsp;renderWindowInteractor-&gt;Start();</div>
  <div>&nbsp;</div>
  <div>&nbsp;&nbsp;return EXIT_SUCCESS;;</div>
  <div>}</div>
  <div><br>
  </div>
Thanks,<br>
  <br>
David</div>
</blockquote>
</body>
</html>