Created
October 28, 2012 22:13
-
-
Save sbaer/3970130 to your computer and use it in GitHub Desktop.
marshaling points in RhinoCommon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C++ portion | |
// Declare a struct that directly maps to an ON_3dPoint | |
struct ON_3DPOINT_STRUCT{ double val[3]; }; | |
extern "C" __declspec(dllexport) | |
void ComputeMeshPoints(int resX, int resY, int resZ, | |
double* data_array, int data_count, double iso, | |
ON_3DPOINT_STRUCT min_corner, ON_3DPOINT_STRUCT max_corner, | |
ON_SimpleArray<ON_3dPoint>* output_points) | |
{ | |
if( data_array && output_points ) | |
{ | |
ON_3dPoint minCorner(min_corner.val); | |
ON_3dPoint maxCorner(max_corner.val); | |
// perform calculations and add points to output_points | |
} | |
} | |
//////////////////////////////////////////////////////////////// | |
// C# portion | |
using System; | |
using System.Runtime.InteropServices; | |
using Rhino.Geometry; | |
static class UnsafeNativeMethods | |
{ | |
[DllImport("my_c_library", CallingConvention=CallingConvention.Cdecl )] | |
public static void ComputeMeshPoints(int resX, int resY, int resZ, | |
double[] data_array, int data_count, double iso, Point3d min_corner, | |
Point3d max_corner, IntPtr pPointArray); | |
} | |
static class MyFunctions | |
{ | |
// Use the pInvoke function in your function | |
public static Point3d[] MyMeshPointsFunction(int resX, int resY, int resZ, | |
double[] data, double iso, | |
Point3d minCorner, Point3d maxCorner) | |
{ | |
using( var pointArray = new Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d() ) | |
{ | |
IntPtr pNativePointArray = pointArray.NonConstPointer(); | |
UnsafeNativeMethods.ComputeMeshPoints(resX, resY, resZ, data, data.Length, | |
iso, minCorner, maxCorner, pNativePointArray); | |
return pointArray.ToArray(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment