Dear Flo, I have had a similar problem and the solution I adopted may
not be elegant but it works. Use a static attribute ( i.e., "This",
note the uppercase "T") that you can use in the callback. The
attribute is a pointer to a class PLUS. PLUSīs constructor would
initialize it to "this" (something like "This = this"). Another
solution would be to make static all the pointer attributes you need to
use in your callback (iren ren, picker and so on...). I also tried this
second path but I found it is a lit more messy.<br>
<br>
Hope this help<br>
<br>
Luca<br>
<br>
<br><br><div><span class="gmail_quote">On 7/10/07, <b class="gmail_sendername">Flo</b> <<a href="mailto:snrf@no-log.org">snrf@no-log.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Dear all:<br><br>I'm using vtk 5.0 on MaxosX and with Qt 4.0.<br><br>I'm trying to convert the annotatePick.cxx example (also attached),<br>that works as a single app, to something that would fit in a broader<br>
application (i.e. at least within classes and methods !).<br>However, I can't handle the fact that the callback function must be<br>static within the class while the callback function needs some<br>private object of the class PLUS, the fact that the
<br>vtkCallbackCommand->SetCallback() method need a function pointer.<br><br>So far, I have the following error:<br><br>error: invalid use of member 'SimpleView::MouseMotion' in static<br>member function ....... same for iren, ren and picker !
<br><br>Can someone point me to some directions or give me a better way to<br>get pixel coordinates.<br><br>Thanks.<br><br>Flo.<br><br>Code -<br><br>Method that should start the callback<br><br>void SimpleView::on_ButStart_clicked()
<br>{<br><br> MouseMotion = 0;<br><br> sphere = vtkSphereSource::New();<br><br> sphereMapper = vtkPolyDataMapper::New();<br> sphereMapper->SetInput(sphere->GetOutput());<br> sphereMapper->GlobalImmediateModeRenderingOn();
<br><br> //VTKF.Load_Sphere *sphereMapper = new VTKF.Load_Sphere ();<br><br> sphereActor = vtkActor::New();<br> sphereActor->SetMapper(sphereMapper);<br><br>// create the spikes by glyphing the sphere with a cone. Create the
<br>mapper<br>// and actor for the glyphs.<br> cone = vtkConeSource::New();<br> glyph = vtkGlyph3D::New();<br> glyph->SetInput(sphere->GetOutput());<br> glyph->SetSource(cone->GetOutput());<br>
glyph->SetVectorModeToUseNormal();<br> glyph->SetScaleModeToScaleByVector();<br> glyph->SetScaleFactor(0.25);<br> vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();<br> spikeMapper->SetInput(glyph->GetOutput());
<br> spikeActor = vtkActor::New();<br> spikeActor->SetMapper(spikeMapper);<br><br><br>// Create a cell picker.<br><br> picker2 = vtkCellPicker::New();<br> pickObserver = PickCommand::New();<br><br>
//pickObserver->SetPtr(/*picker2,*/ textActor, textMapper, renWin);<br><br> picker2->AddObserver( vtkCommand::EndPickEvent, pickObserver );<br><br>// Create a text mapper and actor to display the results of picking.
<br> textMapper = vtkTextMapper::New();<br> tprop = textMapper->GetTextProperty();<br> tprop->SetFontFamilyToArial();<br> tprop->SetFontSize(12);<br> tprop->BoldOn();<br>// tprop->ShadowOn();
<br> tprop->SetColor(1, 0, 0);<br> textActor = vtkActor2D::New();<br> textActor->VisibilityOff();<br> textActor->SetMapper(textMapper);<br><br>// Create the Renderer, RenderWindow, and RenderWindowInteractor
<br><br> style = vtkInteractorStyleTrackballCamera::New();<br> pickerCommand = vtkCallbackCommand::New();<br> //pickerCommand->SetCallback(&PickerInteractionCallback);<br> pickerCommand->SetCallback(&Test);
<br> style->AddObserver(vtkCommand::LeftButtonPressEvent,<br>pickerCommand);<br> style->AddObserver(vtkCommand::MouseMoveEvent, pickerCommand);<br> style->AddObserver(vtkCommand::LeftButtonReleaseEvent,
<br>pickerCommand);<br><br><br> iren->SetInteractorStyle(style);<br> iren->SetPicker(picker2);<br><br>// Add the actors to the renderer, set the background and size<br><br> ren->AddActor2D(textActor);
<br><br> ren->AddActor(sphereActor);<br> ren->AddActor(spikeActor);<br> ren->SetBackground(1, 1, 1);<br><br><br> ren->AddActor(sphereActor);<br> ren->AddActor(spikeActor);<br><br> renWin->Render();
<br><br><br><br><br><br>}<br><br>------------------------------------------<br>-----------------------------------------<br><br>Header file<br><br>class SimpleView : public QMainWindow, private Ui_MainWindow<br>{<br> Q_OBJECT
<br><br>static void Test(vtkObject* vtkNotUsed(object),unsigned long<br>event,void* clientdata, void* vtkNotUsed(calldata))<br>{<br><br> vtkInteractorStyleTrackballCamera * style =<br>(vtkInteractorStyleTrackballCamera*)clientdata;
<br><br><br> switch( event )<br> {<br> case vtkCommand::LeftButtonPressEvent:<br> MouseMotion = 0;<br> style->OnLeftButtonDown();<br> break;<br> case vtkCommand::LeftButtonReleaseEvent:
<br> if (MouseMotion == 0)<br> {<br> int *pick = iren->GetEventPosition();<br>
picker2->Pick((double)pick[0], (double)pick[1], 0.0, ren);<br> }<br> style->OnLeftButtonUp();<br> break;<br> case vtkCommand::MouseMoveEvent:<br> MouseMotion = 1;<br> style->OnMouseMove();
<br> break;<br> }<br><br><br>}<br><br>public:<br><br> // Constructor/Destructor<br> SimpleView(QWidget* parent = 0);<br> ~SimpleView() {};<br><br>public slots:<br> //virtual void vtkTest();<br>
<br>private slots:<br> void on_ButStart_clicked();<br><br>private:<br> vtkSphereSource* sphere;<br> vtkPolyDataMapper *sphereMapper, *spikeMapper;<br> vtkActor *sphereActor, *spikeActor;<br> vtkConeSource* cone;
<br> vtkGlyph3D* glyph;<br><br> PickCommand* pickObserver;<br> vtkTextProperty *tprop;<br> vtkInteractorStyleTrackballCamera *style;<br> vtkCallbackCommand *pickerCommand;<br><br> vtkActor2D *textActor;
<br> vtkTextMapper *textMapper;<br><br> vtkRenderWindow *renWin;<br><br> vtkCamera *cam1;<br><br> int MouseMotion;<br> vtkRenderWindowInteractor *iren;<br> vtkRenderer *ren;<br> vtkCellPicker *picker2;
<br><br><br>};<br><br><br><br>class PickCommand : public vtkCommand<br>{<br><br>public:<br> static PickCommand *New() { return new PickCommand; }<br> void Delete() { delete this; }<br><br><br> virtual void Execute(vtkObject *caller, unsigned long l, void
<br>*callData)<br> {<br> if (picker->GetCellId() < 0 )<br> {<br> textActor->VisibilityOff();<br> }<br> else<br> {<br> double selpt[3];<br> picker->GetSelectionPoint(selpt);
<br> double x = selpt[0];<br> double y = selpt[1];<br> double pickPos[3];<br> picker->GetPickPosition( pickPos );<br> double xp = pickPos[0];<br> double yp = pickPos[1];
<br> double zp = pickPos[2];<br><br> char text[120];<br>
sprintf( text, "(%5.5f, %5.5f, %5.5f)", xp, yp,
zp );<br> textMapper->SetInput( text );<br> textActor->SetPosition(x, y);<br> textActor->VisibilityOn();<br> }<br><br> renWin->Render(); // faire un pointeur de meme que pour
<br>picker !!!!<br><br><br> }<br><br> void SetPtr(vtkCellPicker *pickerptr, vtkActor2D *textActorptr,<br>vtkTextMapper *textMapperptr, vtkRenderWindow *renWinptr)<br> {<br> picker = pickerptr;
<br> textActor = textActorptr;<br> textMapper = textMapperptr;<br> renWin = renWinptr;<br> }<br><br> private:<br> vtkCellPicker *picker;<br> vtkActor2D *textActor;
<br> vtkTextMapper *textMapper;<br> vtkRenderWindow *renWin;<br> vtkRenderWindowInteractor *iren;<br>};<br><br>--------------------------------<br>-------------------------------------
<br><br>Annotate EXAMPLE<br><br>#include "vtkSphereSource.h"<br>#include "vtkPolyDataMapper.h"<br>#include "vtkLODActor.h"<br>#include "vtkConeSource.h"<br>#include "vtkGlyph3D.h
"<br>#include "vtkCellPicker.h"<br>#include "vtkTextMapper.h"<br>#include "vtkActor2D.h"<br>#include "vtkInteractorStyleTrackballCamera.h"<br>#include "vtkRenderer.h"
<br>#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>#include "vtkTextProperty.h"<br>#include "vtkCallbackCommand.h"<br>#include "vtkCamera.h"<br>
<br>int MouseMotion;<br>vtkRenderer *ren1;<br>vtkRenderWindow *renWin;<br>vtkRenderWindowInteractor *iren;<br>vtkCellPicker *picker;<br>vtkActor2D *textActor;<br>vtkTextMapper *textMapper;<br><br>class PickCommand : public vtkCommand
<br>{<br>public:<br><br> static PickCommand *New() { return new PickCommand; }<br> void Delete() { delete this; }<br><br> virtual void Execute(vtkObject *caller, unsigned long l, void<br>*callData)<br> {<br>
if (picker->GetCellId() < 0 )<br> {<br> textActor->VisibilityOff();<br> }<br> else<br> {<br> double selpt[3];<br> picker->GetSelectionPoint(selpt);
<br> double x = selpt[0];<br> double y = selpt[1];<br> double pickPos[3];<br> picker->GetPickPosition( pickPos );<br> double xp = pickPos[0];<br> double yp = pickPos[1];
<br> double zp = pickPos[2];<br><br> char text[120];<br>
sprintf( text, "(%5.5f, %5.5f, %5.5f)", xp, yp,
zp );<br> textMapper->SetInput( text );<br> textActor->SetPosition(x, y);<br> textActor->VisibilityOn();<br> }<br><br> renWin->Render();<br> }<br>};<br>
<br>void PickerInteractionCallback( vtkObject* vtkNotUsed(object),<br> unsigned
long event,<br> void*
clientdata,<br> void*
vtkNotUsed(calldata) )<br>{<br> vtkInteractorStyleTrackballCamera * style =<br>(vtkInteractorStyleTrackballCamera*)clientdata;<br> switch( event )<br> {<br> case vtkCommand::LeftButtonPressEvent:<br> MouseMotion = 0;
<br> style->OnLeftButtonDown();<br> break;<br> case vtkCommand::LeftButtonReleaseEvent:<br> if (MouseMotion == 0)<br> {<br> int *pick = iren->GetEventPosition();<br>
picker->Pick((double)pick[0], (double)pick[1], 0.0, ren1);<br> }<br> style->OnLeftButtonUp();<br> break;<br> case vtkCommand::MouseMoveEvent:<br> MouseMotion = 1;<br> style->OnMouseMove();
<br> break;<br> }<br>}<br><br><br>int main(int argc, char* argv)<br>{<br> MouseMotion = 0;<br> vtkSphereSource *sphere = vtkSphereSource::New();<br><br> vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
<br> sphereMapper->SetInput(sphere->GetOutput());<br> sphereMapper->GlobalImmediateModeRenderingOn();<br> vtkLODActor *sphereActor = vtkLODActor::New();<br> sphereActor->SetMapper(sphereMapper);
<br><br>// create the spikes by glyphing the sphere with a cone. Create the<br>mapper<br>// and actor for the glyphs.<br> vtkConeSource *cone = vtkConeSource::New();<br> vtkGlyph3D *glyph = vtkGlyph3D::New();<br>
glyph->SetInput(sphere->GetOutput());<br> glyph->SetSource(cone->GetOutput());<br> glyph->SetVectorModeToUseNormal();<br> glyph->SetScaleModeToScaleByVector();<br> glyph->SetScaleFactor(
0.25);<br> vtkPolyDataMapper *spikeMapper = vtkPolyDataMapper::New();<br> spikeMapper->SetInput(glyph->GetOutput());<br> vtkLODActor *spikeActor = vtkLODActor::New();<br> spikeActor->SetMapper(spikeMapper);
<br><br>// Create a cell picker.<br> PickCommand* pickObserver = PickCommand::New();<br> picker = vtkCellPicker::New();<br> picker->AddObserver( vtkCommand::EndPickEvent, pickObserver );<br><br>// Create a text mapper and actor to display the results of picking.
<br> textMapper = vtkTextMapper::New();<br> vtkTextProperty *tprop = textMapper->GetTextProperty();<br> tprop->SetFontFamilyToArial();<br> tprop->SetFontSize(12);<br> tprop->BoldOn();<br>// tprop->ShadowOn();
<br> tprop->SetColor(1, 0, 0);<br> textActor = vtkActor2D::New();<br> textActor->VisibilityOff();<br> textActor->SetMapper(textMapper);<br><br>// Create the Renderer, RenderWindow, and RenderWindowInteractor
<br><br> vtkInteractorStyleTrackballCamera *style =<br>vtkInteractorStyleTrackballCamera::New();<br> vtkCallbackCommand * pickerCommand = vtkCallbackCommand::New();<br> pickerCommand->SetClientData(style);<br>
pickerCommand->SetCallback(&PickerInteractionCallback);<br> style->AddObserver(vtkCommand::LeftButtonPressEvent,<br>pickerCommand);<br> style->AddObserver(vtkCommand::MouseMoveEvent, pickerCommand);
<br> style->AddObserver(vtkCommand::LeftButtonReleaseEvent,<br>pickerCommand);<br> ren1 = vtkRenderer::New();<br> renWin = vtkRenderWindow::New();<br> renWin->AddRenderer(ren1);<br> iren = vtkRenderWindowInteractor::New();
<br> iren->SetRenderWindow(renWin);<br> iren->SetInteractorStyle(style);<br> iren->SetPicker(picker);<br><br>// Add the actors to the renderer, set the background and size<br><br> ren1->AddActor2D(textActor);
<br> ren1->AddActor(sphereActor);<br> ren1->AddActor(spikeActor);<br> ren1->SetBackground(1, 1, 1);<br> renWin->SetSize(300, 300);<br><br>// Get the camera and zoom in closer to the image.<br> vtkCamera *cam1 = ren1->GetActiveCamera();
<br> cam1->Zoom(1.4);<br><br> iren->Initialize();<br> iren->Start();<br><br> picker->RemoveObserver( pickObserver );<br> sphere->Delete();<br> sphereMapper->Delete();<br> sphereActor->Delete();
<br> cone->Delete();<br> glyph->Delete();<br> spikeMapper->Delete();<br> spikeActor->Delete();<br> picker->Delete();<br> textMapper->Delete();<br> textActor->Delete();<br> pickerCommand->Delete();
<br> style->Delete();<br> ren1->Delete();<br> renWin->Delete();<br> pickObserver->Delete();<br>// iren->Delete();<br>}<br><br><br>_______________________________________________<br>This is the private VTK discussion list.
<br>Please keep messages on-topic. Check the FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.vtk.org/mailman/listinfo/vtkusers">
http://www.vtk.org/mailman/listinfo/vtkusers</a><br></blockquote></div><br>