[vtkusers] Callback vtkImagePlaneWidget

agatte agatakrason at gmail.com
Sat Mar 1 13:40:25 EST 2014


Hi,

I am trying to create a callback with vtkPlaneSource.
I want to insert vtkPlaneSource when user click on renderer. (something
similar to vtkSeedWidget)

I created a vtkPlaneCallback, but It doeasn't work correctly. 
PlaneSource add not correctly. It can not display a planeSource.
I don't know exactly, what I am doing wrong ?
Could anyone look at my code ?

#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkCommand.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <vtkSeedWidget.h>
#include <vtkSeedRepresentation.h>
#include <vtkPointHandleRepresentation2D.h>
#include <vtkPointHandleRepresentation3D.h>
#include <vtkProperty2D.h>
#include <vtkProperty.h>
#include <vtkSphereSource.h>
#include <vtkImagePlaneWidget.h>
#include <vtkPlaneSource.h>

class vtkPlaneCallback : public vtkCommand
{
  public:
    static vtkPlaneCallback *New()
    { 
      return new vtkPlaneCallback; 
    }
 
    vtkPlaneCallback() {}
    virtual void Execute(vtkObject*, unsigned long event, void *calldata)
	{
	  if(event == vtkCommand::PlacePointEvent){}
      if(event == vtkCommand::InteractionEvent)
      {
        if(calldata){std::cout << "Add new data : "  << *(static_cast< int *
>(calldata)) << std::endl;}
      }
    }
	

   void SetPlaneSource(vtkSmartPointer<vtkPlaneSource> planeS)
   {
     this->planeSource = planeS;
     planeSource = vtkSmartPointer<vtkPlaneSource>::New();
     planeMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
     planeMapper->SetInputConnection(planeSource->GetOutputPort());
     planeActor = vtkSmartPointer<vtkActor>::New();
     planeActor->SetMapper(planeMapper);
   } 

private :
	vtkSmartPointer<vtkPlaneSource> planeSource;
	vtkSmartPointer<vtkPolyDataMapper> planeMapper;
	vtkSmartPointer<vtkActor> planeActor;
	vtkSmartPointer<vtkRenderer> renderer;
};
 
int main(int, char *[])
{
  // A renderer and render window
  vtkSmartPointer<vtkRenderer> renderer = 
vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer); 
  // An interactor
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  vtkSmartPointer<vtkActor> planeA = vtkSmartPointer<vtkActor>::New();
  vtkSmartPointer<vtkPlaneSource> planeS =
vtkSmartPointer<vtkPlaneSource>::New();
  vtkSmartPointer<vtkPlaneCallback> planeCallback =
vtkSmartPointer<vtkPlaneCallback>::New();
  planeCallback->SetPlaneSource(planeS);
  planeA->AddObserver(vtkCommand::PlacePointEvent,planeCallback);
  planeA->AddObserver(vtkCommand::InteractionEvent,planeCallback);
  renderer->AddActor(planeA);
  renderWindow->Render();
  renderWindowInteractor->Initialize();
  renderWindow->Render();
  renderWindowInteractor->Start();
  
  return EXIT_SUCCESS;
}


I would appreciate for any help please :)





--
View this message in context: http://vtk.1045678.n5.nabble.com/Callback-vtkImagePlaneWidget-tp5726147.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list