Esempio n. 1
0
        protected CustomBrepObject(Brep brep)
            : base(true)
        {
            IntPtr pConstBrep = brep.ConstPointer();

            m_pRhinoObject = UnsafeNativeMethods.CRhinoCustomObject_New2(pConstBrep);
        }
Esempio n. 2
0
        protected CustomBrepObject(Brep brep)
            : base(true)
        {
            Guid   type_id        = GetType().GUID;
            IntPtr const_ptr_brep = brep.ConstPointer();

            m_pRhinoObject = UnsafeNativeMethods.CRhinoCustomObject_New2(type_id, const_ptr_brep);
        }
Esempio n. 3
0
        /// <summary>
        /// Compute the VolumeMassProperties for a single Brep.
        /// </summary>
        /// <param name="brep">Brep to measure.</param>
        /// <returns>The VolumeMassProperties for the given Brep or null on failure.</returns>
        /// <exception cref="System.ArgumentNullException">When brep is null.</exception>
        public static VolumeMassProperties Compute(Brep brep)
        {
            if (brep == null)
            {
                throw new ArgumentNullException("brep");
            }

            IntPtr       pBrep             = brep.ConstPointer();
            const double relativeTolerance = 1.0e-6;
            const double absoluteTolerance = 1.0e-6;
            IntPtr       rc = UnsafeNativeMethods.ON_Brep_MassProperties(false, pBrep, relativeTolerance, absoluteTolerance);

            return(IntPtr.Zero == rc ? null : new VolumeMassProperties(rc, false));
        }
        /// <summary>
        /// Compute the VolumeMassProperties for a single Brep.
        /// </summary>
        /// <param name="brep">Brep to measure.</param>
        /// <param name="volume">true to calculate volume.</param>
        /// <param name="firstMoments">true to calculate volume first moments, volume, and volume centroid.</param>
        /// <param name="secondMoments">true to calculate volume second moments.</param>
        /// <param name="productMoments">true to calculate volume product moments.</param>
        /// <returns>The VolumeMassProperties for the given Brep or null on failure.</returns>
        /// <exception cref="System.ArgumentNullException">When brep is null.</exception>
        /// <since>6.3</since>
        public static VolumeMassProperties Compute(Brep brep, bool volume, bool firstMoments, bool secondMoments, bool productMoments)
        {
            if (brep == null)
            {
                throw new ArgumentNullException(nameof(brep));
            }

            IntPtr       pBrep = brep.ConstPointer();
            const double relative_tolerance = 1.0e-6;
            const double absolute_tolerance = 1.0e-6;
            IntPtr       rc = UnsafeNativeMethods.ON_Brep_MassProperties(false, pBrep, volume, firstMoments, secondMoments, productMoments, relative_tolerance, absolute_tolerance);

            GC.KeepAlive(brep);
            return(IntPtr.Zero == rc ? null : new VolumeMassProperties(rc, false));
        }
Esempio n. 5
0
    /// <summary>
    /// Projects a Curve onto a Brep along a given direction.
    /// </summary>
    /// <param name="curve">Curve to project.</param>
    /// <param name="brep">Brep to project onto.</param>
    /// <param name="direction">Direction of projection.</param>
    /// <param name="tolerance">Tolerance to use for projection.</param>
    /// <returns>An array of projected curves or empty array if the projection set is empty.</returns>
    public static Curve[] ProjectToBrep(Curve curve, Brep brep, Vector3d direction, double tolerance)
    {
      IntPtr brep_ptr = brep.ConstPointer();
      IntPtr curve_ptr = curve.ConstPointer();

      using (SimpleArrayCurvePointer rc = new SimpleArrayCurvePointer())
      {
        IntPtr rc_ptr = rc.NonConstPointer();
        return UnsafeNativeMethods.RHC_RhinoProjectCurveToBrep(brep_ptr, curve_ptr, direction, tolerance, rc_ptr) ? rc.ToNonConstArray() : new Curve[0];
      }
    }
Esempio n. 6
0
    /// <summary>
    /// Splits a curve into pieces using a polysurface.
    /// </summary>
    /// <param name="cutter">A cutting surface or polysurface.</param>
    /// <param name="tolerance">A tolerance for computing intersections.</param>
    /// <returns>An array of curves. This array can be empty.</returns>
    public Curve[] Split(Brep cutter, double tolerance)
    {
      if (cutter == null) throw new ArgumentNullException("cutter");

      IntPtr pConstThis = ConstPointer();
      IntPtr pConstBrep = cutter.ConstPointer();
      using (Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer pieces = new SimpleArrayCurvePointer())
      {
        IntPtr pPieces = pieces.NonConstPointer();
        UnsafeNativeMethods.RHC_RhinoCurveSplit(pConstThis, pConstBrep, tolerance, pPieces);
        return pieces.ToNonConstArray();
      }
    }
 /// <summary>
 /// Draws all the wireframe curves of a brep object.
 /// </summary>
 /// <param name="brep">Brep to draw.</param>
 /// <param name="color">Color of Wireframe curves.</param>
 /// <param name="wireDensity">
 /// "Density" of wireframe curves.
 /// <para>-1 = no internal wires.</para>
 /// <para> 0 = default internal wires.</para>
 /// <para>>0 = custom high density.</para>
 /// </param>
 public void DrawBrepWires(Brep brep, System.Drawing.Color color, int wireDensity)
 {
   int argb = color.ToArgb();
   IntPtr pBrep = brep.ConstPointer();
   UnsafeNativeMethods.CRhinoDisplayPipeline_DrawBrep(m_ptr, pBrep, argb, wireDensity);
 }
 /// <summary>
 /// Draws a shaded mesh representation of a brep.
 /// </summary>
 /// <param name="brep">Brep to draw.</param>
 /// <param name="material">Material to draw faces with.</param>
 public void DrawBrepShaded(Brep brep, DisplayMaterial material)
 {
   IntPtr pBrep = brep.ConstPointer();
   IntPtr pMaterial = IntPtr.Zero;
   if (null != material)
     pMaterial = material.ConstPointer();
   UnsafeNativeMethods.CRhinoDisplayPipeline_DrawShadedBrep(m_ptr, pBrep, pMaterial);
 }
Esempio n. 9
0
    /// <summary>
    /// Compute the VolumeMassProperties for a single Brep.
    /// </summary>
    /// <param name="brep">Brep to measure.</param>
    /// <returns>The VolumeMassProperties for the given Brep or null on failure.</returns>
    /// <exception cref="System.ArgumentNullException">When brep is null.</exception>
    public static VolumeMassProperties Compute(Brep brep)
    {
      if (brep == null)
        throw new ArgumentNullException("brep");

      IntPtr pBrep = brep.ConstPointer();
      const double relativeTolerance = 1.0e-6;
      const double absoluteTolerance = 1.0e-6;
      IntPtr rc = UnsafeNativeMethods.ON_Brep_MassProperties(false, pBrep, relativeTolerance, absoluteTolerance);
      return IntPtr.Zero == rc ? null : new VolumeMassProperties(rc, false);
    }
Esempio n. 10
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>
        /// <since>5.0</since>
        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 ptr_unroller = IntPtr.Zero;

            if (m_surface != null)
            {
                IntPtr const_ptr_surface = m_surface.ConstPointer();
                ptr_unroller = UnsafeNativeMethods.CRhinoUnroll_NewSrf(const_ptr_surface, m_absolute_tolerance, m_relative_tolerance);
            }
            else if (m_brep != null)
            {
                IntPtr const_ptr_brep = m_brep.ConstPointer();
                ptr_unroller = UnsafeNativeMethods.CRhinoUnroll_NewBrp(const_ptr_brep, m_absolute_tolerance, m_relative_tolerance);
            }
            if (ptr_unroller == IntPtr.Zero)
            {
                throw new Exception("Unable to access input surface or brep");
            }

            var rc = new Brep[0];

            if (0 == UnsafeNativeMethods.CRhinoUnroll_PrepareFaces(ptr_unroller))
            {
                if (m_curves.Count > 0)
                {
                    var    crvs             = new Runtime.InteropWrappers.SimpleArrayCurvePointer(m_curves);
                    IntPtr const_ptr_curves = crvs.ConstPointer();
                    UnsafeNativeMethods.CRhinoUnroll_PrepareCurves(ptr_unroller, const_ptr_curves);
                }
                if (m_points.Count > 0)
                {
                    Point3d[] pts = m_points.ToArray();
                    UnsafeNativeMethods.CRhinoUnroll_PreparePoints(ptr_unroller, pts.Length, pts);
                }
                if (m_dots.Count > 0)
                {
                    using (var dots = new Runtime.InteropWrappers.SimpleArrayGeometryPointer(m_dots))
                    {
                        IntPtr const_ptr_dots = dots.ConstPointer();
                        UnsafeNativeMethods.CRhinoUnroll_PrepareDots(ptr_unroller, const_ptr_dots);
                    }
                }

                int    brep_count   = 0;
                int    curve_count  = 0;
                int    point_count  = 0;
                int    dot_count    = 0;
                double explode_dist = -1;
                if (m_explode_output)
                {
                    explode_dist = m_explode_spacing;
                }
                IntPtr ptr_results = UnsafeNativeMethods.CRhinoUnroll_CreateFlatBreps(ptr_unroller,
                                                                                      explode_dist, ref brep_count, ref curve_count, ref point_count, ref dot_count);
                if (ptr_results != IntPtr.Zero)
                {
                    if (brep_count > 0)
                    {
                        rc = new Brep[brep_count];
                        for (int i = 0; i < brep_count; i++)
                        {
                            IntPtr ptr_brep = UnsafeNativeMethods.CRhinoUnrollResults_GetBrep(ptr_results, i);
                            if (ptr_brep != IntPtr.Zero)
                            {
                                rc[i] = new Brep(ptr_brep, null);
                            }
                        }
                    }
                    if (curve_count > 0)
                    {
                        unrolledCurves = new Curve[curve_count];
                        for (int i = 0; i < curve_count; i++)
                        {
                            IntPtr ptr_curve = UnsafeNativeMethods.CRhinoUnrollResults_GetCurve(ptr_results, i);
                            if (ptr_curve != IntPtr.Zero)
                            {
                                unrolledCurves[i] = new Curve(ptr_curve, null);
                            }
                        }
                    }
                    if (point_count > 0)
                    {
                        unrolledPoints = new Point3d[point_count];
                        UnsafeNativeMethods.CRhinoUnrollResults_GetPoints(ptr_results, point_count, unrolledPoints);
                    }
                    if (dot_count > 0)
                    {
                        unrolledDots = new TextDot[dot_count];
                        for (int i = 0; i < dot_count; i++)
                        {
                            IntPtr ptr_dots = UnsafeNativeMethods.CRhinoUnrollResults_GetDot(ptr_results, i);
                            if (ptr_dots != IntPtr.Zero)
                            {
                                unrolledDots[i] = new TextDot(ptr_dots, null);
                            }
                        }
                    }

                    UnsafeNativeMethods.CRhinoUnrollResults_Delete(ptr_results);
                }
            }
            UnsafeNativeMethods.CRhinoUnroll_Delete(ptr_unroller);
            return(rc);
        }
Esempio n. 11
0
    /// <summary>
    /// Intersects a Brep and a Surface.
    /// </summary>
    /// <param name="brep">A brep to be intersected.</param>
    /// <param name="surface">A surface to be intersected.</param>
    /// <param name="tolerance">A tolerance value.</param>
    /// <param name="intersectionCurves">The intersection curves array argument. This out reference is assigned during the call.</param>
    /// <param name="intersectionPoints">The intersection points array argument. This out reference is assigned during the call.</param>
    /// <returns>true on success; false on failure.</returns>
    public static bool BrepSurface(Brep brep, Surface surface, double tolerance, out Curve[] intersectionCurves, out Point3d[] intersectionPoints)
    {
      intersectionCurves = new Curve[0];
      intersectionPoints = new Point3d[0];

      Runtime.InteropWrappers.SimpleArrayPoint3d outputPoints = new Runtime.InteropWrappers.SimpleArrayPoint3d();
      IntPtr outputPointsPtr = outputPoints.NonConstPointer();

      Runtime.InteropWrappers.SimpleArrayCurvePointer outputCurves = new Runtime.InteropWrappers.SimpleArrayCurvePointer();
      IntPtr outputCurvesPtr = outputCurves.NonConstPointer();

      IntPtr brepPtr = brep.ConstPointer();
      IntPtr surfacePtr = surface.ConstPointer();

      bool rc = UnsafeNativeMethods.ON_Intersect_BrepSurface(brepPtr, surfacePtr, tolerance, outputCurvesPtr, outputPointsPtr);

      if (rc)
      {
        intersectionCurves = outputCurves.ToNonConstArray();
        intersectionPoints = outputPoints.ToArray();
      }

      outputPoints.Dispose();
      outputCurves.Dispose();

      return rc;
    }
Esempio n. 12
0
    /// <summary>
    /// Intersects a curve with a Brep. This function returns the 3D points of intersection
    /// and 3D overlap curves. If an error occurs while processing overlap curves, this function 
    /// will return false, but it will still provide partial results.
    /// </summary>
    /// <param name="curve">Curve for intersection.</param>
    /// <param name="brep">Brep for intersection.</param>
    /// <param name="tolerance">Fitting and near miss tolerance.</param>
    /// <param name="overlapCurves">The overlap curves will be returned here.</param>
    /// <param name="intersectionPoints">The intersection points will be returned here.</param>
    /// <returns>true on success, false on failure.</returns>
    /// <example>
    /// <code source='examples\vbnet\ex_elevation.vb' lang='vbnet'/>
    /// <code source='examples\cs\ex_elevation.cs' lang='cs'/>
    /// <code source='examples\py\ex_elevation.py' lang='py'/>
    /// </example>
    public static bool CurveBrep(Curve curve, Brep brep, double tolerance, out Curve[] overlapCurves, out Point3d[] intersectionPoints)
    {
      overlapCurves = new Curve[0];
      intersectionPoints = new Point3d[0];

      Runtime.InteropWrappers.SimpleArrayPoint3d outputPoints = new Runtime.InteropWrappers.SimpleArrayPoint3d();
      IntPtr outputPointsPtr = outputPoints.NonConstPointer();

      Runtime.InteropWrappers.SimpleArrayCurvePointer outputCurves = new Runtime.InteropWrappers.SimpleArrayCurvePointer();
      IntPtr outputCurvesPtr = outputCurves.NonConstPointer();

      IntPtr curvePtr = curve.ConstPointer();
      IntPtr brepPtr = brep.ConstPointer();

      bool rc = UnsafeNativeMethods.ON_Intersect_CurveBrep(curvePtr, brepPtr, tolerance, outputCurvesPtr, outputPointsPtr);

      if (rc)
      {
        overlapCurves = outputCurves.ToNonConstArray();
        intersectionPoints = outputPoints.ToArray();
      }

      outputPoints.Dispose();
      outputCurves.Dispose();

      return rc;
    }
 protected CustomBrepObject(Brep brep)
   : base(true)
 {
   Guid type_id = GetType().GUID;
   IntPtr pConstBrep = brep.ConstPointer();
   m_pRhinoObject = UnsafeNativeMethods.CRhinoCustomObject_New2(type_id, pConstBrep);
 }
Esempio n. 14
0
 protected CustomBrepObject(Brep brep)
   : base(true)
 {
   IntPtr pConstBrep = brep.ConstPointer();
   m_pRhinoObject = UnsafeNativeMethods.CRhinoCustomObject_New2(pConstBrep);
 }