[vtkusers] How to use vtkMath functions in ActiViz.NET for data of type double?

csumushu csumushu at 126.com
Wed Nov 8 20:22:49 EST 2017


Hello, guys and ladies
Is there anybody using ActiViz.NET? I am confused about using vtkMath
functions in ActiViz.NET. Take Distance2BetweenPoints as an example, with
double type data can not get the correct result,but it is OK to use float
type. 

The following code is from 
http://lorensen.github.io/VTKExamples/site/CSharp/SimpleOperations/DistanceBetweenPoints/
<http://lorensen.github.io/VTKExamples/site/CSharp/SimpleOperations/DistanceBetweenPoints/>  

using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Kitware.VTK;

void DistanceBetweenPoints() {
   // Create two points.
   double[] p0 = new double[] { 0.0, 0.0, 0.0 };
   double[] p1 = new double[] { 1.0, 1.0, 1.0 };

   IntPtr pP0 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3);
   IntPtr pP1 = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * 3);
   Marshal.Copy(p0, 0, pP0, 3);
   Marshal.Copy(p1, 0, pP1, 3);

   // Find the squared distance between the points.
   double squaredDistance = vtkMath.Distance2BetweenPoints(pP0, pP1);

   // Take the square root to get the Euclidean distance between the points.
   double distance = Math.Sqrt(squaredDistance);

   // Output the results.
   Console.WriteLine("SquaredDistance = " + squaredDistance);
   Console.WriteLine("Distance = " + distance);
   Marshal.FreeHGlobal(pP0);
   Marshal.FreeHGlobal(pP1);
}

The result is SquaredDistance = 3.515625, Distance = 1.875 with double type,
and SquaredDistance = 3, Distance = 1.73205080756888 for float.

Can anyone tell me where the problem is?



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


More information about the vtkusers mailing list