[vtk-developers] custom parametric function, java

Jeff Baumes jeff.baumes at kitware.com
Tue Apr 14 11:25:40 EDT 2009


Hello Gregory,

Unfortunately, the VTK Java wrappers do not support subclassing in
Java. The main issue is that the wrapped objects interally hold a C++
pointer to a class. Even though you are subclassing in Java, the
internal C++ pointer is still a superclass pointer (i.e.
vtkParametricFunction). So anytime your instance is used outside Java
calls, it will think the object is a vtkParametricFunction, and will
not call your overridden methods. Your errors are probably related to
this inconsistency.

You might search the VTK bugs for allowing wrapper subclassing, and
enter one if there is not already a bug there. It would take
significant changes to get this working, however.

What would work is to add a parametric function subclass in your local
VTK checkout, (say in VTK/Common), which could then be wrapped and
used in Java.

Jeff

On Tue, Apr 14, 2009 at 10:48 AM, Grzegorz Pytel <bioinfguy at gmail.com> wrote:
> Hi, I have been trying to develop special surface model using java and vtk
> 5.4.0. Therefore I have created class that derives from
> vtkParametricFunction. I have overriden required virtual methods from
> vtkParametricFunction class, that's: Evaluate, EvaluateScalar and
> GetDimension(). Variables like MinimumU, MaximumV etc, according to
> documentation, are protected in  my base class (vtkParametricFunction).
> MySurface should then be available for using it. Source code of all these
> functions look as below main message. In my opinion I probably have
> faultless object intialization in the constructor. The problem is: the
> program execution fails at object initializations lines in constructor. That
> is: the execution of virtual machine breaks with error message:The crash
> happened outside the Java Virtual Machine in native code,
> EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x5c2e2e5c, pid=5264,
> tid=4908. The mystical lines are:
>
> this.SetMinimumU(-Math.PI);
>   this.SetMaximumU(Math.PI);
>   this.SetMaximumV(Math.PI);
>   this.SetMinimumV(-Math.PI);
>   this.SetJoinU(1);
>   this.SetJoinV(1);
>
>   this.SetTwistU(0);
>   this.SetTwistV(0);
>   this.ClockwiseOrderingOn();
>   this.DerivativesAvailableOn();
> If I comment out these lines and setup custom initialization on all required
> variables(like MinimumU) the break up problem still exists, but objects
> initialization completes with success. Even then have I never observed the
> execution of code in Evaluate method what is strange for me ( program
> breakup before calling evaluate method).
>
> Well at first sight it seems to be problem with JNI. Can anyone say me what
> I am doing wrong so that executions is brought up while initializing this
> class? How to implement custom surface? What I am doing wrong in this code
> and this method (inheritance from vtkParametricFunction). Is there another
> mechanism to provide to vtk custom surface?
>
> Gregory
>
> This is my class code:
>
> package Surfaces;
>
> import java.lang.Math;
>
>
> import vtk.vtkMath;
> import vtk.vtkParametricFunction;
> import vtk.vtkParametricMobius;
>
> public class MySurface extends vtkParametricFunction {
>  protected int a;
>
>
>  public MySurface()
>  {
>   super();
>   this.SetMinimumU(-Math.PI);
>   this.SetMaximumU(Math.PI);
>   this.SetMaximumV(Math.PI);
>   this.SetMinimumV(-Math.PI);
>   this.SetJoinU(1);
>   this.SetJoinV(1);
>
>   this.SetTwistU(0);
>   this.SetTwistV(0);
>   this.ClockwiseOrderingOn();
>   this.DerivativesAvailableOn();
>   this.a=2;
>  }
>
>  @Override
>  public void Evaluate(double[] id0, double[] id1, double[] id2) {
>   // TODO Auto-generated method stub
>   double u = id0[0];
>   double v = id0[1];
>   id1[0] = f(u,v);
>   id1[1] = g(u,v);
>   id1[2] = h(u,v);
>
>   id2[0] = xu(u,v);
>   id2[1] = xv(u,v);
>   id2[3] = yu(u,v);
>   id2[4] = yv(u,v);
>   id2[6] = zu(u,v);
>   id2[7] = zu(u,v);
>  }
>
>  @Override
>  public double EvaluateScalar(double[] id0, double[] id1, double[] id2) {
>   // TODO Auto-generated method stub
>   return 0;
>  }
>
>  protected double f(double u,double v)
>  {
>   return Math.cos(u)*(a+ Math.sin(v)* Math.cos(u)- Math.sin(2*v)*
> Math.sin(u)/2);
>  }
>
>  protected double g(double u,double v)
>  {
>   return Math.sin(u)*(a+ Math.sin(v)* Math.cos(u)- Math.sin(2*v)*
> Math.sin(u)/2);
>  }
>
>  protected double h(double u,double v)
>  {
>   return Math.sin(u)*Math.sin(v)+Math.cos(u)*Math.sin(2 * v)/2;
>  }
>
>  /**
>   * Computes derivative of f function over x variable and along u axis
>   * @param u
>   * @param v
>   * @return Derivative
>   */
>  protected double xu(double u,double v)
>  {
>   return -g(u,v) +
> Math.cos(u)*(-Math.sin(v)*Math.sin(u)-Math.sin(2*v)*Math.cos(u)/2);
>  }
>
>  /**
>   * Computes derivative of f function over x variable and along v axis
>   * @param u
>   * @param v
>   * @return
>   */
>  protected double xv(double u,double v)
>  {
>   return Math.cos(u)*(Math.cos(v)*Math.cos(u)-Math.cos(2*v)*Math.sin(u));
>  }
>
>  protected double yu(double u,double v)
>  {
>   return
> f(u,v)+Math.sin(u)*(-Math.sin(v)*Math.sin(u)-Math.sin(2*v)*Math.cos(u)/2);
>  }
>
>  /**
>   * Computes derivative of f function over y variable and along v axis
>   * @param u
>   * @param v
>   * @return
>   */
>  protected double yv(double u,double v)
>  {
>   return Math.sin(u)*(Math.cos(v)*Math.cos(u)-Math.cos(2*v)*Math.sin(u));
>  }
>
>  protected double zu(double u,double v)
>  {
>   return Math.sin(v)*Math.cos(u)-Math.sin(2*v)*Math.sin(u)/2;
>  }
>
>  protected double zv(double u,double v)
>  {
>   return Math.cos(v)*Math.sin(u)+Math.cos(2*v)*Math.cos(u);
>  }
> }
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
>



More information about the vtk-developers mailing list