예제 #1
0
    /// <summary>
    /// Projects a collection of Curves onto a collection of Breps along a given direction.
    /// </summary>
    /// <param name="curves">Curves to project.</param>
    /// <param name="breps">Breps to project onto.</param>
    /// <param name="direction">Direction of projection.</param>
    /// <param name="tolerance">Tolerance to use for projection.</param>
    /// <param name="curveIndices">Index of which curve in the input list was the source for a curve in the return array.</param>
    /// <param name="brepIndices">Index of which brep was used to generate a curve in the return array.</param>
    /// <returns>An array of projected curves. Array is empty if the projection set is empty.</returns>
    public static Curve[] ProjectToBrep(IEnumerable<Curve> curves, IEnumerable<Brep> breps, Vector3d direction, double tolerance, out int[] curveIndices, out int[] brepIndices)
    {
      curveIndices = null;
      brepIndices = null;

      foreach (Curve crv in curves) { if (crv == null) { throw new ArgumentNullException("curves"); } }
      foreach (Brep brp in breps) { if (brp == null) { throw new ArgumentNullException("breps"); } }

      SimpleArrayCurvePointer crv_array = new SimpleArrayCurvePointer(curves);
      Runtime.InteropWrappers.SimpleArrayBrepPointer brp_array = new Runtime.InteropWrappers.SimpleArrayBrepPointer();
      foreach (Brep brp in breps) { brp_array.Add(brp, true); }

      IntPtr ptr_crv_array = crv_array.ConstPointer();
      IntPtr ptr_brp_array = brp_array.ConstPointer();

      SimpleArrayInt brp_top = new SimpleArrayInt();
      SimpleArrayInt crv_top = new SimpleArrayInt();

      SimpleArrayCurvePointer rc = new SimpleArrayCurvePointer();
      IntPtr ptr_rc = rc.NonConstPointer();

      if (UnsafeNativeMethods.RHC_RhinoProjectCurveToBrepEx(ptr_brp_array,
                                                            ptr_crv_array,
                                                            direction,
                                                            tolerance,
                                                            ptr_rc,
                                                            brp_top.m_ptr,
                                                            crv_top.m_ptr))
      {
        brepIndices = brp_top.ToArray();
        curveIndices = crv_top.ToArray();
        return rc.ToNonConstArray();
      }
      return new Curve[0];
    }
예제 #2
0
    /// <summary>
    /// Projects a curve to a set of meshes using a direction and tolerance.
    /// </summary>
    /// <param name="curves">A list, an array or any enumerable of curves.</param>
    /// <param name="meshes">A list, an array or any enumerable of meshes.</param>
    /// <param name="direction">A direction vector.</param>
    /// <param name="tolerance">A tolerance value.</param>
    /// <returns>A curve array.</returns>
    public static Curve[] ProjectToMesh(IEnumerable<Curve> curves, IEnumerable<Mesh> meshes, Vector3d direction, double tolerance)
    {
      foreach (Curve crv in curves)
      {
        if (crv == null)
          throw new ArgumentNullException("curves");
      }
      List<GeometryBase> g = new List<GeometryBase>();
      foreach (Mesh msh in meshes)
      {
        if (msh == null)
          throw new ArgumentNullException("meshes");
        g.Add(msh);
      }

      using (SimpleArrayCurvePointer crv_array = new SimpleArrayCurvePointer(curves))
      using (Runtime.InteropWrappers.SimpleArrayGeometryPointer mesh_array = new Runtime.InteropWrappers.SimpleArrayGeometryPointer(g))
      using (SimpleArrayCurvePointer curves_out = new SimpleArrayCurvePointer())
      {
        IntPtr pCurvesIn = crv_array.ConstPointer();
        IntPtr pMeshes = mesh_array.ConstPointer();
        IntPtr pCurvesOut = curves_out.NonConstPointer();

        Curve[] rc = new Curve[0];
        if (UnsafeNativeMethods.RHC_RhinoProjectCurveToMesh(pMeshes, pCurvesIn, direction, tolerance, pCurvesOut))
          rc = curves_out.ToNonConstArray();
        return rc;
      }
    }
예제 #3
0
    /// <summary>
    /// Calculates the boolean difference between a closed planar curve, and a list of closed planar curves. 
    /// Note, curves must be co-planar.
    /// </summary>
    /// <param name="curveA">The first closed, planar curve.</param>
    /// <param name="subtractors">curves to subtract from the first closed curve.</param>
    /// <returns>Result curves on success, empty array if no difference could be calculated.</returns>
    public static Curve[] CreateBooleanDifference(Curve curveA, IEnumerable<Curve> subtractors)
    {
      if (null == curveA || null == subtractors)
        throw new ArgumentNullException(null == curveA ? "curveA" : "subtractors");

      List<Curve> curves = new List<Curve> { curveA };
      curves.AddRange(subtractors);
      SimpleArrayCurvePointer input = new SimpleArrayCurvePointer(curves);
      IntPtr inputPtr = input.ConstPointer();
      SimpleArrayCurvePointer output = new SimpleArrayCurvePointer();
      IntPtr outputPtr = output.NonConstPointer();
      int rc = UnsafeNativeMethods.ON_Curve_BooleanOperation(inputPtr, outputPtr, idxBooleanDifference);
      return rc < 1 ? new Curve[0] : output.ToNonConstArray();
    }
예제 #4
0
    /// <summary>
    /// Calculates the boolean intersection of two closed, planar curves. 
    /// Note, curves must be co-planar.
    /// </summary>
    /// <param name="curveA">The first closed, planar curve.</param>
    /// <param name="curveB">The second closed, planar curve.</param>
    /// <returns>Result curves on success, empty array if no intersection could be calculated.</returns>
    public static Curve[] CreateBooleanIntersection(Curve curveA, Curve curveB)
    {
      if (null == curveA || null == curveB)
        throw new ArgumentNullException(null == curveA ? "curveA" : "curveB");

      SimpleArrayCurvePointer input = new SimpleArrayCurvePointer(new Curve[] { curveA, curveB });
      IntPtr inputPtr = input.ConstPointer();
      SimpleArrayCurvePointer output = new SimpleArrayCurvePointer();
      IntPtr outputPtr = output.NonConstPointer();
      int rc = UnsafeNativeMethods.ON_Curve_BooleanOperation(inputPtr, outputPtr, idxBooleanIntersection);
      return rc < 1 ? new Curve[0] : output.ToNonConstArray();
    }
예제 #5
0
    /// <summary>
    /// Calculates the boolean union of two or more closed, planar curves. 
    /// Note, curves must be co-planar.
    /// </summary>
    /// <param name="curves">The co-planar curves to union.</param>
    /// <returns>Result curves on success, empty array if no union could be calculated.</returns>
    public static Curve[] CreateBooleanUnion(IEnumerable<Curve> curves)
    {
      if (null == curves)
        throw new ArgumentNullException("curves");

      SimpleArrayCurvePointer input = new SimpleArrayCurvePointer(curves);
      IntPtr inputPtr = input.ConstPointer();
      SimpleArrayCurvePointer output = new SimpleArrayCurvePointer();
      IntPtr outputPtr = output.NonConstPointer();

      int rc = UnsafeNativeMethods.ON_Curve_BooleanOperation(inputPtr, outputPtr, idxBooleanUnion);
      return rc < 1 ? new Curve[0] : output.ToNonConstArray();
    }
예제 #6
0
    /// <summary>
    /// Joins a collection of curve segments together.
    /// </summary>
    /// <param name="inputCurves">An array, a list or any enumerable set of curve segments to join.</param>
    /// <param name="joinTolerance">Joining tolerance, 
    /// i.e. the distance between segment end-points that is allowed.</param>
    /// <param name="preserveDirection">
    /// <para>If true, curve endpoints will be compared to curve startpoints.</para>
    /// <para>If false, all start and endpoints will be compared and copies of input curves may be reversed in output.</para>
    /// </param>
    /// <returns>An array of joint curves. This array can be empty.</returns>
    /// <exception cref="ArgumentNullException">If inputCurves is null.</exception>
    public static Curve[] JoinCurves(IEnumerable<Curve> inputCurves, double joinTolerance, bool preserveDirection)
    {
      // 1 March 2010 S. Baer
      // JoinCurves calls the unmanaged RhinoMergeCurves function which appears to be a "better"
      // implementation of ON_JoinCurves. We removed the wrapper for ON_JoinCurves for this reason.
      if (null == inputCurves)
        throw new ArgumentNullException("inputCurves");

      SimpleArrayCurvePointer input = new SimpleArrayCurvePointer(inputCurves);
      IntPtr inputPtr = input.ConstPointer();
      SimpleArrayCurvePointer output = new SimpleArrayCurvePointer();
      IntPtr outputPtr = output.NonConstPointer();

      bool rc = UnsafeNativeMethods.RHC_RhinoMergeCurves(inputPtr,
        outputPtr, joinTolerance, preserveDirection);

      return rc ? output.ToNonConstArray() : new Curve[0];
    }