/// <summary> /// Calls a more complicated, exported function /// </summary> public static int MooseFunction(Brep brep, int x, int y, out Point3d[] points, out Line[] lines) { if (null == brep) { throw new ArgumentNullException("brep"); } // Get the native ON_Brep pointer var const_ptr_brep = Interop.NativeGeometryConstPointer(brep); // Creates a ON_3dPointArray wrapper class instance var points_array = new Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d(); // Get a non-const point to this class var ptr_points_array = points_array.NonConstPointer(); // Creates a ON_SimpleArray<ON_Line> wrapper class instance var lines_array = new Rhino.Runtime.InteropWrappers.SimpleArrayLine(); // Get a non-const point to this class var ptr_lines_array = lines_array.NonConstPointer(); var rc = Environment.Is64BitProcess ? UnsafeNativeMethods64.MooseFunction(const_ptr_brep, x, y, ptr_points_array, ptr_lines_array) : UnsafeNativeMethods32.MooseFunction(const_ptr_brep, x, y, ptr_points_array, ptr_lines_array); if (rc > 0) { points = points_array.ToArray(); lines = lines_array.ToArray(); } else { points = new Point3d[0]; lines = new Line[0]; } points_array.Dispose(); lines_array.Dispose(); return(rc); }
/// <summary> /// Retrieves a Polyline at a given array index. /// </summary> /// <param name="index">THe index</param> /// <returns>The Polyline if successful, null otherwise.</returns> public Polyline Get(int index) { if (index < 0 || index >= Count) { return(null); } var points_array = new Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d(); var ptr_points_array = points_array.NonConstPointer(); var cnt = UnsafeNativeMethods.ON_PolylineArray_Get(m_ptr, index, ptr_points_array); Polyline rc = null; if (cnt > 0) { rc = new Polyline(points_array.ToArray()); } points_array.Dispose(); return(rc); }
//public static Point3d[] RaySurfaces(Ray3d ray, IEnumerable<Surface> surfaces, int maxReflections) //{ // if (maxReflections < 1 || maxReflections > 1000) // throw new ArgumentException("maxReflections must be between 1-1000"); // Rhino.Runtime.INTERNAL_GeometryArray srfs = new Rhino.Runtime.INTERNAL_GeometryArray(surfaces); // IntPtr pSrfs = srfs.ConstPointer(); // Point3d[] rc = null; // using (Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d points = new Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d()) // { // IntPtr pPoints = points.NonConstPointer(); // int count = UnsafeNativeMethods.ON_RayShooter_MultiSurface(ray.Position, ray.Direction, pSrfs, pPoints, maxReflections); // if (count > 0) rc = points.ToArray(); // } // srfs.Dispose(); // return rc; //} #endregion #if RHINO_SDK /// <summary> /// Projects points onto meshes. /// </summary> /// <param name="meshes">the meshes to project on to.</param> /// <param name="points">the points to project.</param> /// <param name="direction">the direction to project.</param> /// <param name="tolerance"> /// Projection tolerances used for culling close points and for line-mesh intersection. /// </param> /// <returns> /// Array of projected points, or null in case of any error or invalid input. /// </returns> public static Point3d[] ProjectPointsToMeshes(IEnumerable<Mesh> meshes, IEnumerable<Point3d> points, Vector3d direction, double tolerance) { Point3d[] rc = null; if (meshes != null && points != null) { Rhino.Runtime.InteropWrappers.SimpleArrayMeshPointer mesh_array = new Rhino.Runtime.InteropWrappers.SimpleArrayMeshPointer(); foreach (Mesh mesh in meshes) mesh_array.Add(mesh, true); Rhino.Collections.Point3dList inputpoints = new Rhino.Collections.Point3dList(points); if (inputpoints.Count > 0) { IntPtr pConstMeshArray = mesh_array.ConstPointer(); using (Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d output = new Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d()) { IntPtr pOutput = output.NonConstPointer(); if (UnsafeNativeMethods.RHC_RhinoProjectPointsToMeshes(pConstMeshArray, direction, tolerance, inputpoints.Count, inputpoints.m_items, pOutput)) rc = output.ToArray(); } } } return rc; }
/// <summary> /// Computes point intersections that occur when shooting a ray to a collection of surfaces. /// </summary> /// <param name="ray">A ray used in intersection.</param> /// <param name="geometry">Only Surface and Brep objects are currently supported. Trims are ignored on Breps.</param> /// <param name="maxReflections">The maximum number of reflections. This value should be any value between 1 and 1000, inclusive.</param> /// <returns>An array of points: one for each face that was passed by the faceIds out reference.</returns> /// <exception cref="ArgumentNullException">geometry is null.</exception> /// <exception cref="ArgumentOutOfRangeException">maxReflections is strictly outside the [1-1000] range.</exception> public static Point3d[] RayShoot(Ray3d ray, IEnumerable<GeometryBase> geometry, int maxReflections) { if (geometry == null) throw new ArgumentNullException("geometry"); if (maxReflections < 1 || maxReflections > 1000) throw new ArgumentOutOfRangeException("maxReflections", "maxReflections must be between 1-1000"); // We should handle better the case of a null entry inside the geometry collection. // Currently a NullReferenceException occurs. using (Rhino.Runtime.InteropWrappers.SimpleArrayGeometryPointer geom = new Runtime.InteropWrappers.SimpleArrayGeometryPointer(geometry)) { IntPtr pGeometry = geom.ConstPointer(); Point3d[] rc = null; using (Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d points = new Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d()) { IntPtr pPoints = points.NonConstPointer(); int count = UnsafeNativeMethods.ON_RayShooter_ShootRay(ray.Position, ray.Direction, pGeometry, pPoints, maxReflections); if (count > 0) rc = points.ToArray(); } return rc; } }
/// <summary> /// Projects points onto breps. /// </summary> /// <param name="breps">The breps projection targets.</param> /// <param name="points">The points to project.</param> /// <param name="direction">The direction to project.</param> /// <param name="tolerance">The tolerance used for intersections.</param> /// <returns> /// Array of projected points, or null in case of any error or invalid input. /// </returns> /// <example> /// <code source='examples\vbnet\ex_projectpointstobreps.vb' lang='vbnet'/> /// <code source='examples\cs\ex_projectpointstobreps.cs' lang='cs'/> /// <code source='examples\py\ex_projectpointstobreps.py' lang='py'/> /// </example> public static Point3d[] ProjectPointsToBreps(IEnumerable<Brep> breps, IEnumerable<Point3d> points, Vector3d direction, double tolerance) { Point3d[] rc = null; if (breps != null && points != null) { Rhino.Runtime.InteropWrappers.SimpleArrayBrepPointer brep_array = new Rhino.Runtime.InteropWrappers.SimpleArrayBrepPointer(); foreach (Brep brep in breps) brep_array.Add(brep, true); Rhino.Collections.Point3dList inputpoints = new Rhino.Collections.Point3dList(points); if (inputpoints.Count > 0) { IntPtr pConstBrepArray = brep_array.ConstPointer(); using (Runtime.InteropWrappers.SimpleArrayPoint3d output = new Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d()) { IntPtr pOutput = output.NonConstPointer(); if (UnsafeNativeMethods.RHC_RhinoProjectPointsToBreps(pConstBrepArray, direction, tolerance, inputpoints.Count, inputpoints.m_items, pOutput)) rc = output.ToArray(); } } } return rc; }
/// <summary> /// Gets current construction points. /// </summary> /// <returns>An array of points.</returns> /// <remarks> /// Construction points are like snap points except that they get snapped to /// even when point osnap is off. Typically, there are only a few construction /// points while there can be many snap points. For example, when polylines /// are drawn the start point is a construction point and the other points are /// snap points. /// </remarks> public Point3d[] GetConstructionPoints() { Runtime.InteropWrappers.SimpleArrayPoint3d pts = new Rhino.Runtime.InteropWrappers.SimpleArrayPoint3d(); IntPtr pGetPoint = ConstPointer(); IntPtr pArray = pts.NonConstPointer(); UnsafeNativeMethods.CRhinoGetPoint_GetSnapPoints(pGetPoint, pArray, false); Point3d[] rc = pts.ToArray(); pts.Dispose(); return rc; }