[vtk-developers] custom parametric function, java

Grzegorz Pytel bioinfguy at gmail.com
Tue Apr 14 10:48:16 EDT 2009


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);
 }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20090414/6975b672/attachment.html>


More information about the vtk-developers mailing list