예제 #1
0
            IntPtr m_ptr; //CArgsRhinoSweep2*
            public static ArgsSweep2 Construct(Curve rail1, Curve rail2, IEnumerable <Curve> crossSections,
                                               IEnumerable <double> crossSectionParameters1, IEnumerable <double> crossSectionParameters2,
                                               bool closed, double sweep_tol, double angle_tol, bool maintain_height)
            {
                ArgsSweep2    rc      = new ArgsSweep2();
                List <Curve>  xsec    = new List <Curve>(crossSections);
                List <double> xsec_t1 = new List <double>(crossSectionParameters1);
                List <double> xsec_t2 = new List <double>(crossSectionParameters2);

                if (xsec.Count < 1)
                {
                    throw new ArgumentException("must have at least one cross section");
                }
                if (xsec.Count != xsec_t1.Count || xsec.Count != xsec_t2.Count)
                {
                    throw new ArgumentException("must have same number of elements in crossSections and crossSectionParameters");
                }

                IntPtr pConstRail1 = rail1.ConstPointer();
                IntPtr pConstRail2 = rail2.ConstPointer();

                using (var sections = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(crossSections))
                {
                    IntPtr   pSections = sections.ConstPointer();
                    double[] tvals1    = xsec_t1.ToArray();
                    double[] tvals2    = xsec_t2.ToArray();
                    rc.m_ptr = UnsafeNativeMethods.CArgsRhinoSweep2_New(pConstRail1, pConstRail2, pSections, tvals1, tvals2, closed, sweep_tol, angle_tol, maintain_height);
                }
                return(rc);
            }
예제 #2
0
        /// <summary>
        /// Constructs an array of <see cref="Hatch">hatches</see> from a set of curves.
        /// </summary>
        /// <param name="curves">An array, a list or any enumarable set of <see cref="Curve"/>.</param>
        /// <param name="hatchPatternIndex">The index of the hatch pattern in the document hatch pattern table.</param>
        /// <param name="rotationRadians">The relative rotation of the pattern.</param>
        /// <param name="scale">A scaling factor.</param>
        /// <returns>An array of hatches. The array might be empty on error.</returns>
        /// <exception cref="ArgumentNullException">If curves is null.</exception>
        public static Hatch[] Create(IEnumerable <Curve> curves, int hatchPatternIndex, double rotationRadians, double scale)
        {
            if (curves == null)
            {
                throw new ArgumentNullException("curves");
            }

            Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer curvearray = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(curves);
            IntPtr pCurveArray = curvearray.NonConstPointer();

            Rhino.Runtime.InteropWrappers.SimpleArrayGeometryPointer hatcharray = new Rhino.Runtime.InteropWrappers.SimpleArrayGeometryPointer();
            IntPtr pOutput = hatcharray.NonConstPointer();

            UnsafeNativeMethods.RHC_RhinoCreateHatches(pCurveArray, hatchPatternIndex, rotationRadians, scale, pOutput);
            GeometryBase[] g = hatcharray.ToNonConstArray();
            if (g == null)
            {
                return(new Hatch[0]);
            }
            List <Hatch> hatches = new List <Hatch>();

            for (int i = 0; i < g.Length; i++)
            {
                Hatch hatch = g[i] as Hatch;
                if (hatch != null)
                {
                    hatches.Add(hatch);
                }
            }
            return(hatches.ToArray());
        }
예제 #3
0
            IntPtr m_ptr; //CArgsRhinoSweep1*
            public static ArgsSweep1 Construct(Curve rail, IEnumerable <Curve> crossSections, IEnumerable <double> crossSectionParameters,
                                               Vector3d roadlike_up, bool closed, double sweep_tol, double angle_tol, int miter_type)
            {
                ArgsSweep1    rc     = new ArgsSweep1();
                List <Curve>  xsec   = new List <Curve>(crossSections);
                List <double> xsec_t = new List <double>(crossSectionParameters);

                if (xsec.Count < 1)
                {
                    throw new ArgumentException("must have at least one cross section");
                }
                if (xsec.Count != xsec_t.Count)
                {
                    throw new ArgumentException("must have same number of elements in crossSections and crossSectionParameters");
                }

                IntPtr pConstRail = rail.ConstPointer();

                Runtime.InteropWrappers.SimpleArrayCurvePointer sections = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(crossSections);
                IntPtr pSections = sections.ConstPointer();

                double[] tvals = xsec_t.ToArray();
                rc.m_ptr = UnsafeNativeMethods.CArgsRhinoSweep1_New(pConstRail, pSections, tvals, roadlike_up, closed, sweep_tol, angle_tol, miter_type);
                sections.Dispose();
                return(rc);
            }
예제 #4
0
    /// <summary>
    /// Constructs an array of <see cref="Hatch">hatches</see> from a set of curves.
    /// </summary>
    /// <param name="curves">An array, a list or any enumarable set of <see cref="Curve"/>.</param>
    /// <param name="hatchPatternIndex">The index of the hatch pattern in the document hatch pattern table.</param>
    /// <param name="rotationRadians">The relative rotation of the pattern.</param>
    /// <param name="scale">A scaling factor.</param>
    /// <returns>An array of hatches. The array might be empty on error.</returns>
    /// <exception cref="ArgumentNullException">If curves is null.</exception>
    public static Hatch[] Create(IEnumerable<Curve> curves, int hatchPatternIndex, double rotationRadians, double scale)
    {
      if (curves == null) throw new ArgumentNullException("curves");

      Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer curvearray = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(curves);
      IntPtr pCurveArray = curvearray.NonConstPointer();
      Rhino.Runtime.InteropWrappers.SimpleArrayGeometryPointer hatcharray = new Rhino.Runtime.InteropWrappers.SimpleArrayGeometryPointer();
      IntPtr pOutput = hatcharray.NonConstPointer();
      UnsafeNativeMethods.RHC_RhinoCreateHatches(pCurveArray, hatchPatternIndex, rotationRadians, scale, pOutput);
      GeometryBase[] g = hatcharray.ToNonConstArray();
      if( g==null )
        return new Hatch[0];
      List<Hatch> hatches = new List<Hatch>();
      for (int i = 0; i < g.Length; i++)
      {
        Hatch hatch = g[i] as Hatch;
        if (hatch != null)
          hatches.Add(hatch);
      }
      return hatches.ToArray();
    }
예제 #5
0
        /// <summary>
        /// Executes unrolling operations.
        /// </summary>
        /// <param name="unrolledCurves">An array of unrolled curves is assigned during the call in this out parameter.</param>
        /// <param name="unrolledPoints">An array of unrolled points is assigned during the call in this out parameter.</param>
        /// <param name="unrolledDots">An array of unrolled text dots is assigned during the call in this out parameter.</param>
        /// <returns>An array of breps. This array can be empty.</returns>
        public Brep[] PerformUnroll(out Curve[] unrolledCurves, out Point3d[] unrolledPoints, out TextDot[] unrolledDots)
        {
            unrolledCurves = new Curve[0];
            unrolledPoints = new Point3d[0];
            unrolledDots   = new TextDot[0];

            IntPtr pUnroller = IntPtr.Zero;

            if (m_surface != null)
            {
                IntPtr pSurface = m_surface.ConstPointer();
                pUnroller = UnsafeNativeMethods.CRhinoUnroll_NewSrf(pSurface, m_dAbsoluteTolerance, m_dRelativeTolerance);
            }
            else if (m_brep != null)
            {
                IntPtr pBrep = m_brep.ConstPointer();
                pUnroller = UnsafeNativeMethods.CRhinoUnroll_NewBrp(pBrep, m_dAbsoluteTolerance, m_dRelativeTolerance);
            }
            if (pUnroller == IntPtr.Zero)
            {
                throw new Exception("Unable to access input surface or brep");
            }

            Brep[] rc = new Brep[0];
            if (0 == UnsafeNativeMethods.CRhinoUnroll_PrepareFaces(pUnroller))
            {
                if (m_curves.Count > 0)
                {
                    Runtime.InteropWrappers.SimpleArrayCurvePointer crvs = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(m_curves);
                    IntPtr pCrvs = crvs.ConstPointer();
                    UnsafeNativeMethods.CRhinoUnroll_PrepareCurves(pUnroller, pCrvs);
                }
                if (m_points.Count > 0)
                {
                    Point3d[] pts = m_points.ToArray();
                    UnsafeNativeMethods.CRhinoUnroll_PreparePoints(pUnroller, pts.Length, pts);
                }
                if (m_dots.Count > 0)
                {
                    using (Rhino.Runtime.InteropWrappers.SimpleArrayGeometryPointer dots = new Runtime.InteropWrappers.SimpleArrayGeometryPointer(m_dots))
                    {
                        IntPtr pDots = dots.ConstPointer();
                        UnsafeNativeMethods.CRhinoUnroll_PrepareDots(pUnroller, pDots);
                    }
                }

                int    brepCount    = 0;
                int    curveCount   = 0;
                int    pointCount   = 0;
                int    dotCount     = 0;
                double explode_dist = -1;
                if (m_bExplodeOutput)
                {
                    explode_dist = m_dExplodeSpacing;
                }
                IntPtr pResults = UnsafeNativeMethods.CRhinoUnroll_CreateFlatBreps(pUnroller,
                                                                                   explode_dist, ref brepCount, ref curveCount, ref pointCount, ref dotCount);
                if (pResults != IntPtr.Zero)
                {
                    if (brepCount > 0)
                    {
                        rc = new Brep[brepCount];
                        for (int i = 0; i < brepCount; i++)
                        {
                            IntPtr pBrep = UnsafeNativeMethods.CRhinoUnrollResults_GetBrep(pResults, i);
                            if (pBrep != IntPtr.Zero)
                            {
                                rc[i] = new Brep(pBrep, null);
                            }
                        }
                    }
                    if (curveCount > 0)
                    {
                        unrolledCurves = new Curve[curveCount];
                        for (int i = 0; i < curveCount; i++)
                        {
                            IntPtr pCurve = UnsafeNativeMethods.CRhinoUnrollResults_GetCurve(pResults, i);
                            if (pCurve != IntPtr.Zero)
                            {
                                unrolledCurves[i] = new Curve(pCurve, null);
                            }
                        }
                    }
                    if (pointCount > 0)
                    {
                        unrolledPoints = new Point3d[pointCount];
                        UnsafeNativeMethods.CRhinoUnrollResults_GetPoints(pResults, pointCount, unrolledPoints);
                    }
                    if (dotCount > 0)
                    {
                        unrolledDots = new TextDot[dotCount];
                        for (int i = 0; i < dotCount; i++)
                        {
                            IntPtr pDot = UnsafeNativeMethods.CRhinoUnrollResults_GetDot(pResults, i);
                            if (pDot != IntPtr.Zero)
                            {
                                unrolledDots[i] = new TextDot(pDot, null);
                            }
                        }
                    }

                    UnsafeNativeMethods.CRhinoUnrollResults_Delete(pResults);
                }
            }
            UnsafeNativeMethods.CRhinoUnroll_Delete(pUnroller);
            return(rc);
        }
예제 #6
0
      IntPtr m_ptr; //CArgsRhinoSweep1*
      public static ArgsSweep1 Construct(Curve rail, IEnumerable<Curve> crossSections, IEnumerable<double> crossSectionParameters,
        Vector3d roadlike_up, bool closed, double sweep_tol, double angle_tol, int miter_type)
      {
        ArgsSweep1 rc = new ArgsSweep1();
        List<Curve> xsec = new List<Curve>(crossSections);
        List<double> xsec_t = new List<double>(crossSectionParameters);
        if (xsec.Count < 1)
          throw new ArgumentException("must have at least one cross section");
        if (xsec.Count != xsec_t.Count)
          throw new ArgumentException("must have same number of elements in crossSections and crossSectionParameters");

        IntPtr pConstRail = rail.ConstPointer();
        Runtime.InteropWrappers.SimpleArrayCurvePointer sections = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(crossSections);
        IntPtr pSections = sections.ConstPointer();
        double[] tvals = xsec_t.ToArray();
        rc.m_ptr = UnsafeNativeMethods.CArgsRhinoSweep1_New(pConstRail, pSections, tvals, roadlike_up, closed, sweep_tol, angle_tol, miter_type);
        sections.Dispose();
        return rc;
      }
예제 #7
0
      IntPtr m_ptr; //CArgsRhinoSweep2*
      public static ArgsSweep2 Construct(Curve rail1, Curve rail2, IEnumerable<Curve> crossSections,
        IEnumerable<double> crossSectionParameters1, IEnumerable<double> crossSectionParameters2,
        bool closed, double sweep_tol, double angle_tol, bool maintain_height)
      {
        ArgsSweep2 rc = new ArgsSweep2();
        List<Curve> xsec = new List<Curve>(crossSections);
        List<double> xsec_t1 = new List<double>(crossSectionParameters1);
        List<double> xsec_t2 = new List<double>(crossSectionParameters2);
        if (xsec.Count < 1)
          throw new ArgumentException("must have at least one cross section");
        if (xsec.Count != xsec_t1.Count || xsec.Count != xsec_t2.Count)
          throw new ArgumentException("must have same number of elements in crossSections and crossSectionParameters");

        IntPtr pConstRail1 = rail1.ConstPointer();
        IntPtr pConstRail2 = rail2.ConstPointer();
        using (var sections = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(crossSections))
        {
          IntPtr pSections = sections.ConstPointer();
          double[] tvals1 = xsec_t1.ToArray();
          double[] tvals2 = xsec_t2.ToArray();
          rc.m_ptr = UnsafeNativeMethods.CArgsRhinoSweep2_New(pConstRail1, pConstRail2, pSections, tvals1, tvals2, closed, sweep_tol, angle_tol, maintain_height);
        }
        return rc;
      }
예제 #8
0
    /// <summary>
    /// Executes unrolling operations.
    /// </summary>
    /// <param name="unrolledCurves">An array of unrolled curves is assigned during the call in this out parameter.</param>
    /// <param name="unrolledPoints">An array of unrolled points is assigned during the call in this out parameter.</param>
    /// <param name="unrolledDots">An array of unrolled text dots is assigned during the call in this out parameter.</param>
    /// <returns>An array of breps. This array can be empty.</returns>
    public Brep[] PerformUnroll(out Curve[] unrolledCurves, out Point3d[] unrolledPoints, out TextDot[] unrolledDots)
    {
      unrolledCurves = new Curve[0];
      unrolledPoints = new Point3d[0];
      unrolledDots = new TextDot[0];

      IntPtr pUnroller = IntPtr.Zero;
      if (m_surface != null)
      {
        IntPtr pSurface = m_surface.ConstPointer();
        pUnroller = UnsafeNativeMethods.CRhinoUnroll_NewSrf(pSurface, m_dAbsoluteTolerance, m_dRelativeTolerance);
      }
      else if (m_brep != null)
      {
        IntPtr pBrep = m_brep.ConstPointer();
        pUnroller = UnsafeNativeMethods.CRhinoUnroll_NewBrp(pBrep, m_dAbsoluteTolerance, m_dRelativeTolerance);
      }
      if (pUnroller == IntPtr.Zero)
        throw new Exception("Unable to access input surface or brep");

      Brep[] rc = new Brep[0];
      if (0 == UnsafeNativeMethods.CRhinoUnroll_PrepareFaces(pUnroller))
      {
        if (m_curves.Count > 0)
        {
          Runtime.InteropWrappers.SimpleArrayCurvePointer crvs = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer(m_curves);
          IntPtr pCrvs = crvs.ConstPointer();
          UnsafeNativeMethods.CRhinoUnroll_PrepareCurves(pUnroller, pCrvs);
        }
        if (m_points.Count > 0)
        {
          Point3d[] pts =  m_points.ToArray();
          UnsafeNativeMethods.CRhinoUnroll_PreparePoints(pUnroller, pts.Length, pts);
        }
        if (m_dots.Count > 0)
        {
          Runtime.INTERNAL_GeometryArray dots = new Rhino.Runtime.INTERNAL_GeometryArray(m_dots);
          IntPtr pDots = dots.ConstPointer();
          UnsafeNativeMethods.CRhinoUnroll_PrepareDots(pUnroller, pDots);
        }

        int brepCount = 0;
        int curveCount = 0;
        int pointCount = 0;
        int dotCount = 0;
        double explode_dist = -1;
        if (m_bExplodeOutput)
          explode_dist = m_dExplodeSpacing;
        IntPtr pResults = UnsafeNativeMethods.CRhinoUnroll_CreateFlatBreps(pUnroller,
          explode_dist, ref brepCount, ref curveCount, ref pointCount, ref dotCount);
        if (pResults != IntPtr.Zero)
        {
          if (brepCount > 0)
          {
            rc = new Brep[brepCount];
            for (int i = 0; i < brepCount; i++)
            {
              IntPtr pBrep = UnsafeNativeMethods.CRhinoUnrollResults_GetBrep(pResults, i);
              if (pBrep != IntPtr.Zero) rc[i] = new Brep(pBrep, null);
            }
          }
          if (curveCount > 0)
          {
            unrolledCurves = new Curve[curveCount];
            for (int i = 0; i < curveCount; i++)
            {
              IntPtr pCurve = UnsafeNativeMethods.CRhinoUnrollResults_GetCurve(pResults, i);
              if (pCurve != IntPtr.Zero) unrolledCurves[i] = new Curve(pCurve, null);
            }
          }
          if (pointCount > 0)
          {
            unrolledPoints = new Point3d[pointCount];
            UnsafeNativeMethods.CRhinoUnrollResults_GetPoints(pResults, pointCount, unrolledPoints);
          }
          if (dotCount > 0)
          {
            unrolledDots = new TextDot[dotCount];
            for (int i = 0; i < dotCount; i++)
            {
              IntPtr pDot = UnsafeNativeMethods.CRhinoUnrollResults_GetDot(pResults, i);
              if (pDot != IntPtr.Zero) unrolledDots[i] = new TextDot(pDot, null);
            }
          }

          UnsafeNativeMethods.CRhinoUnrollResults_Delete(pResults);
        }
      }
      UnsafeNativeMethods.CRhinoUnroll_Delete(pUnroller);
      return rc;
    }