[vtkusers] Bug with the java wrapper

David Gobbi david.gobbi at gmail.com
Thu Mar 17 14:32:07 EDT 2016


Hi Galera,

This doesn't look like a bug.  This is related to numerical precision.

 10000000000.0 - 1.0 -> 9999999999.0
 1.7976931348623157e+308 - 1.0 -> 1.7976931348623157e+308

If you subtract 1 from Double.MAX_VALUE, the result is Double.MAX_VALUE.
Floating point math is not exact, a double only has around 16 significant
digits.

In other words, instead of subtracting 1, you should do this:

  threshold.ThresholdByLower(thresholdValue - thresholdValue*eps);

where eps=2.220446049250313e-16 is the double epsilon.

 - David


On Thu, Mar 17, 2016 at 12:07 PM, galera <tonio.guillen at gmail.com> wrote:

> Hi all,
>
> I found a bug with the java wrapper for example:
>
>                         double thresholdValue = Math.pow(10, 10);
>                         vtkRectilinearGrid input = (vtkRectilinearGrid)
> this.getInput().getValue();
>                         vtkDataArray values =
> input.GetCellData().GetScalars();
>
>                         int k;
>                         for(int i = 0; i < input.GetNumberOfCells(); i++) {
>                                 double x = 0, y = 0, z = 0;
>                                 for(k = 0; k <
> input.GetCell(i).GetPoints().GetNumberOfPoints(); k++) {
>                                         double[] pcoords =
> input.GetCell(i).GetPoints().GetPoint(k);
>                                         x += pcoords[0];
>                                         y += pcoords[1];
>                                         z += pcoords[2];
>                                 }
>                                 Point3D p = new Point3D(x/k, y/k, z/k);
>                                 int rank = model.rank(p, true);
>                                 if
> (!this.getEntities().contains(model.getFormationWithRank(rank ))) {
>                                         values.SetTuple1(i,
> thresholdValue);
>                                 }
>                         }
>                         input.GetCellData().SetScalars(values);
>                         vtkThreshold threshold = new vtkThreshold();
>                         threshold.SetInputData(input);
>                         threshold.ThresholdByLower(thresholdValue-1.);
>
>                         threshold.Update();
>
>                         vtkUnstructuredGrid output = threshold.GetOutput();
>                         Pipe<vtkUnstructuredGrid> pipe =
> FilterFactory.eINSTANCE.createPipe();
>                         pipe.setValue(output);
>                         this.getOutput().add(pipe);
>
>
> This code work fine if you set:
>  double thresholdValue = Math.pow(10, 10);
>
> if you set:
> double thresholdValue = Double.MAX_VALUE;
>
> you have a bug.
>
> Galera
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160317/94baafb4/attachment.html>


More information about the vtkusers mailing list