[vtkusers] custom vtkAbstractWidget + vtkWidgetRepresentation in Java

Petr Matoušek p3tr.matousek at gmail.com
Thu Sep 7 10:08:36 EDT 2017


Hello,

can anybody suggest how to implement custom vtkAbstractWidget and 
vtkWidgetRepresentation in Java? Is it even possible?

I tried it but failed.

1. The first problem I encountered was that vtkAbstractWidget uses its 
protected field WidgetRep, but there is no way how to set it from Java 
code. Only public methods are accessible from Java. So I introduced my 
own field in the Java class and overrided the GetRepresentation() method 
to return it. So far so good:

public class CoordRangeVtkLineWidget extends vtkAbstractWidget {

     private final vtkLineRepresentation representation;

     public CoordRangeVtkLineWidget(final CoordRange coordRange) {
         super();
         this.representation = new vtkLineRepresentation();
     }

     @Override
     public vtkWidgetRepresentation GetRepresentation() {
         return this.representation;
     }
}

2. But then the SetInteractor() method started to fail for my widget 
with SIGSEGV crash. I guess this is due to the fact that the observer 
mechanism is implemented a bit differently in Java. So it is not 
possible to call the original AddObserver() methods with Java object 
instances.

So I skipped the interactor for the moment:

@Override
public void SetInteractor(final vtkRenderWindowInteractor interactor) {
     // TODO
}

3. Then vtkAbstractWidget::SetEnabled() started to fail with SIGSEGV of 
course.

So I stopped and start to think: this would be quite difficult. In fact 
I will probably have to reimplement the whole vtkAbstractWidget in Java 
to make it work.

So does anybody any experience with this. Any suggestions? Am I going 
wrong direction? Please.

Best regards, Petr Matousek


More information about the vtkusers mailing list