<!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"><<a moz-do-not-send="true"
href="mailto:sebastian.gatzka@stud.tu-darmstadt.de">sebastian.gatzka@stud.tu-darmstadt.de</a>></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">
vtkTextActor *ta = reinterpret_cast<vtkTextActor*>(caller);<br>
ta->SetInput("TEST");</font><br>
<br>
or like this?<br>
<br>
<font color="#ff0000" face="Courier New, Courier, monospace">
this->TextActor->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 <sstream></div>
<div><br>
</div>
<div>#include <vtkSmartPointer.h></div>
<div>#include <vtkProperty.h></div>
<div>#include <vtkTextProperty.h></div>
<div><br>
</div>
<div>#include <vtkXMLPolyDataReader.h></div>
<div>#include <vtkSphereSource.h></div>
<div>#include <vtkClipPolyData.h></div>
<div>#include <vtkPlane.h></div>
<div><br>
</div>
<div>#include <vtkCommand.h></div>
<div>#include <vtkImplicitPlaneWidget2.h></div>
<div>#include <vtkImplicitPlaneRepresentation.h></div>
<div> </div>
<div>#include <vtkPolyDataMapper.h></div>
<div>#include <vtkProperty.h></div>
<div>#include <vtkActor.h></div>
<div>#include <vtkTextActor.h></div>
<div>#include <vtkRenderWindow.h></div>
<div>#include <vtkRenderer.h></div>
<div>#include <vtkRenderWindowInteractor.h></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> public:</div>
<div> static vtkIPWCallback *New() </div>
<div> {</div>
<div> return new vtkIPWCallback; </div>
<div> }</div>
<div> </div>
<div> virtual void Execute(vtkObject *caller, unsigned long, void*)</div>
<div> {</div>
<div> vtkImplicitPlaneWidget2 *planeWidget = </div>
<div>
reinterpret_cast<vtkImplicitPlaneWidget2*>(caller);</div>
<div> vtkImplicitPlaneRepresentation *rep = </div>
<div>
reinterpret_cast<vtkImplicitPlaneRepresentation*>(planeWidget->GetRepresentation());</div>
<div> rep->GetPlane(this->Plane);</div>
<div> </div>
<div> std::stringstream ss;</div>
<div> ss << this->counter;</div>
<div> this->TextActor->SetInput (ss.str().c_str());</div>
<div> this->counter++;</div>
<div> }</div>
<div> vtkIPWCallback():Plane(0),TextActor(0),counter(0) {}</div>
<div> </div>
<div> void SetPlane(vtkPlane* plane) { this->Plane = plane;}</div>
<div> void SetTextActor(vtkTextActor* textActor) {
this->TextActor = textActor;}</div>
<div> </div>
<div> private:</div>
<div> unsigned int counter;</div>
<div> vtkPlane* Plane;</div>
<div> vtkTextActor* TextActor;</div>
<div><br>
</div>
<div>};</div>
<div><br>
</div>
<div>int main(int argc, char *argv[])</div>
<div>{</div>
<div> vtkSmartPointer<vtkSphereSource> sphereSource =</div>
<div> vtkSmartPointer<vtkSphereSource>::New();</div>
<div> sphereSource->SetRadius(10.0);</div>
<div><br>
</div>
<div> vtkSmartPointer<vtkXMLPolyDataReader> reader =</div>
<div> vtkSmartPointer<vtkXMLPolyDataReader>::New();</div>
<div><br>
</div>
<div> // Setup a visualization pipeline</div>
<div><br>
</div>
<div> vtkSmartPointer<vtkPlane> plane =</div>
<div> vtkSmartPointer<vtkPlane>::New();</div>
<div> vtkSmartPointer<vtkClipPolyData> clipper =</div>
<div> vtkSmartPointer<vtkClipPolyData>::New();</div>
<div> clipper->SetClipFunction(plane);</div>
<div> clipper->InsideOutOn();</div>
<div> if (argc < 2)</div>
<div> {</div>
<div>
clipper->SetInputConnection(sphereSource->GetOutputPort());</div>
<div> }</div>
<div> else</div>
<div> {</div>
<div> reader->SetFileName(argv[1]);</div>
<div> clipper->SetInputConnection(reader->GetOutputPort());</div>
<div> }</div>
<div> //Create a mapper and actor</div>
<div> vtkSmartPointer<vtkPolyDataMapper> mapper =</div>
<div> vtkSmartPointer<vtkPolyDataMapper>::New();</div>
<div> mapper->SetInputConnection(clipper->GetOutputPort());</div>
<div> vtkSmartPointer<vtkActor> actor =</div>
<div> vtkSmartPointer<vtkActor>::New();</div>
<div> actor->SetMapper(mapper);</div>
<div><br>
</div>
<div> vtkSmartPointer<vtkProperty> backFaces =</div>
<div> vtkSmartPointer<vtkProperty>::New();</div>
<div> backFaces->SetDiffuseColor(.8, .8, .4);</div>
<div><br>
</div>
<div> actor->SetBackfaceProperty(backFaces);</div>
<div> </div>
<div> // a renderer and render window</div>
<div> vtkSmartPointer<vtkRenderer> renderer =</div>
<div> vtkSmartPointer<vtkRenderer>::New();</div>
<div> vtkSmartPointer<vtkRenderWindow> renderWindow =</div>
<div> vtkSmartPointer<vtkRenderWindow>::New();</div>
<div> renderWindow->AddRenderer(renderer);</div>
<div> renderer->AddActor(actor);</div>
<div> </div>
<div> // an interactor</div>
<div> vtkSmartPointer<vtkRenderWindowInteractor>
renderWindowInteractor =</div>
<div> vtkSmartPointer<vtkRenderWindowInteractor>::New();</div>
<div> renderWindowInteractor->SetRenderWindow(renderWindow);</div>
<div> </div>
<div> renderWindow->Render();</div>
<div><br>
</div>
<div> // The callback will do the work</div>
<div> vtkSmartPointer<vtkIPWCallback> myCallback = </div>
<div> vtkSmartPointer<vtkIPWCallback>::New();</div>
<div> myCallback->SetPlane(plane);</div>
<div> </div>
<div> vtkSmartPointer<vtkTextActor> textActor = </div>
<div> vtkSmartPointer<vtkTextActor>::New();</div>
<div> textActor->SetInput ( "Hello world" );</div>
<div> textActor->GetTextProperty()->SetColor ( 1.0,0.0,0.0 );</div>
<div> myCallback->SetTextActor(textActor);</div>
<div> renderer->AddActor2D ( textActor );</div>
<div><br>
</div>
<div> vtkSmartPointer<vtkImplicitPlaneRepresentation> rep = </div>
<div>
vtkSmartPointer<vtkImplicitPlaneRepresentation>::New();</div>
<div> rep->SetPlaceFactor(1.25); // This must be set prior to
placing the widget</div>
<div> rep->PlaceWidget(actor->GetBounds());</div>
<div> rep->SetNormal(plane->GetNormal());</div>
<div> rep->SetOrigin(0,0,50);</div>
<div> </div>
<div> vtkSmartPointer<vtkImplicitPlaneWidget2> planeWidget =</div>
<div> vtkSmartPointer<vtkImplicitPlaneWidget2>::New();</div>
<div> planeWidget->SetInteractor(renderWindowInteractor);</div>
<div> planeWidget->SetRepresentation(rep);</div>
<div> planeWidget->AddObserver(vtkCommand::InteractionEvent,myCallback);</div>
<div><br>
</div>
<div> // render an image (lights and cameras are created
automatically)</div>
<div> </div>
<div> renderWindowInteractor->Initialize();</div>
<div> renderWindow->Render();</div>
<div> planeWidget->On();</div>
<div> </div>
<div> // begin mouse interaction</div>
<div> renderWindowInteractor->Start();</div>
<div> </div>
<div> return EXIT_SUCCESS;;</div>
<div>}</div>
<div><br>
</div>
Thanks,<br>
<br>
David</div>
</blockquote>
</body>
</html>