[vtkusers] How to customize a vtkPolyLineWidget?

pnt1614 minpu.code at gmail.com
Sun Aug 12 21:42:06 EDT 2018


I am trying to customize the vtkPolyLineWidget, so I a class
(MyPolyLineWidget) derived from the vtkPolyLineWidget. However, there is a
problem about accessing and casting. I cannot access the Interactor member
and I cannot cast from vtkAbstractWidget the MyPolyLineWidget.

Is there anyway to solve these two problems? Thank you.

-----------In the header (.h) file-----------
class MyPolyLineWidget : public vtkPolyLineWidget
{
public:

	static MyPolyLineWidget *New() { return new MyPolyLineWidget; };

	MyPolyLineWidget();
	~MyPolyLineWidget();

protected:	
	static void MySelectAction(vtkAbstractWidget*);
	static void MyEndSelectAction(vtkAbstractWidget*);
	static void MyTranslateAction(vtkAbstractWidget*);
	static void MyScaleAction(vtkAbstractWidget*);
	static void MyMoveAction(vtkAbstractWidget*);
};

//---------In the implementation (.cpp) file--------
vtkStandardNewMacro(vtkPolyLineWidget);
//----------------------------------------------------------------------------
vtkPolyLineWidget::vtkPolyLineWidget()
{
  this->WidgetState = vtkPolyLineWidget::Start;
  this->ManagesCursor = 1;

  // Define widget events
  this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonPressEvent,
                                          vtkWidgetEvent::Select,
                                          this,
vtkPolyLineWidget::SelectAction);
 
this->CallbackMapper->SetCallbackMethod(vtkCommand::LeftButtonReleaseEvent,
                                          vtkWidgetEvent::EndSelect,
                                          this,
vtkPolyLineWidget::EndSelectAction);
										  
 
this->CallbackMapper->SetCallbackMethod(vtkCommand::MiddleButtonPressEvent,
                                          vtkWidgetEvent::Translate,
                                          this,
vtkPolyLineWidget::TranslateAction);
 
this->CallbackMapper->SetCallbackMethod(vtkCommand::MiddleButtonReleaseEvent,
                                          vtkWidgetEvent::EndTranslate,
                                          this,
vtkPolyLineWidget::EndSelectAction);
										  
  this->CallbackMapper->SetCallbackMethod(vtkCommand::RightButtonPressEvent,
                                          vtkWidgetEvent::Scale,
                                          this,
vtkPolyLineWidget::ScaleAction);
 
this->CallbackMapper->SetCallbackMethod(vtkCommand::RightButtonReleaseEvent,
                                          vtkWidgetEvent::EndScale,
                                          this,
vtkPolyLineWidget::EndSelectAction);
										  
  this->CallbackMapper->SetCallbackMethod(vtkCommand::MouseMoveEvent,
                                          vtkWidgetEvent::Move,
                                          this,
vtkPolyLineWidget::MoveAction);
}

//----------------------------------------------------------------------------
vtkPolyLineWidget::~vtkPolyLineWidget()
{
}

//----------------------------------------------------------------------
void vtkPolyLineWidget::SelectAction(vtkAbstractWidget *w)
{
  // I cannot cast from the vtkAbstractWidget to MyPolyLineWidget  
  vtkPolyLineWidget *self = vtkPolyLineWidget::SafeDownCast(w);

  // There is an error in the two following statement
  // since Interactor is a protected member in the vtkPolyLineWidget
  int X = self->Interactor->GetEventPosition()[0];
  int Y = self->Interactor->GetEventPosition()[1];

  // Okay, make sure that the pick is in the current renderer
  if ( !self->CurrentRenderer ||
       !self->CurrentRenderer->IsInViewport(X,Y) )
  {
    self->WidgetState = vtkPolyLineWidget::Start;
    return;
  }
 //...
}

// Other empty static functions





--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list