Example #1
0
        //public static string _GetName(this BrepFace face)
        //{
        //    var brep = face._Brep();
        //    if (brep == null) return "";
        //    how to get Object ???
        //    return face._GetName(brep._GetFaceName,
        //}

        public static string _GetName(this BrepFace face, string objectName, Brep brep, bool shortNameIfPossible = true)
        {
            var facesCount = brep.Faces.Count;

            if (facesCount == 1 && shortNameIfPossible)
            {
                return(objectName);
            }

            int nameLength = 1;

            if (facesCount >= 10)
            {
                nameLength = 2;
            }
            if (facesCount >= 100)
            {
                nameLength = 3;
            }
            if (facesCount >= 1000)
            {
                nameLength = 4;
            }
            if (facesCount >= 10000)
            {
                nameLength = 5;
            }
            return(objectName + ":" + (face.FaceIndex + 1).ToString("D" + nameLength));
        }
Example #2
0
 public static SurfacePoint _FindTrimSurfacePoint(this BrepVertex v, BrepFace face)
 {
     foreach (var loop in face.Loops_ThreadSafe())
     {
         foreach (var trim in loop.Trims_ThreadSafe())
         {
             if (trim.Edge != null)
             {
                 var indexStart = trim.Edge._GetStartVertex().VertexIndex;
                 var indexEnd   = trim.Edge._GetEndVertex().VertexIndex;
                 if (v.VertexIndex == indexStart ||
                     v.VertexIndex == indexEnd)
                 {
                     var trimStartPoint = face.PointAt(trim.PointAtStart.X, trim.PointAtStart.Y);
                     var trimEndPoint   = face.PointAt(trim.PointAtEnd.X, trim.PointAtEnd.Y);
                     if (v.Location._DistanceTo(trimStartPoint) < v.Location._DistanceTo(trimEndPoint))
                     {
                         return(new SurfacePoint(trim.PointAtStart));
                     }
                     else
                     {
                         return(new SurfacePoint(trim.PointAtEnd));
                     }
                 }
             }
         }
     }
     throw new Exception("Cannot find UV for BrepVertex (in method _BrepVertex._ToSurfacePoint)");
 }
Example #3
0
        public List <Brep> CreateWallBrep()
        {
            double      offsetDistance1 = this.thickness / 2 + offset;
            double      offsetDistance2 = this.thickness / 2 - offset;
            List <Brep> solids          = new List <Brep>();
            Brep        solid           = new Brep();

            for (int i = 0; i < this.wall.Surfaces.Count; i++)
            {
                Surface offsetSurface1 = this.wall.Surfaces[i].Offset(offsetDistance1, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                Surface offsetSurface2 = this.wall.Surfaces[i].Offset(-1 * offsetDistance2, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

                List <Brep> solidBreps = new List <Brep>();

                Brep         wallBrep1  = offsetSurface1.ToBrep();
                BrepEdgeList brepEdges1 = wallBrep1.Edges;

                Brep         wallBrep2  = offsetSurface2.ToBrep();
                BrepEdgeList brepEdges2 = wallBrep2.Edges;

                solidBreps.Add(wallBrep1);
                solidBreps.Add(wallBrep2);

                BrepFace wallSurface = wallBrep1.Faces[0];
                solids.Add(Brep.CreateFromOffsetFace(wallSurface, -1 * this.thickness, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, false, true));
            }

            return(solids);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Brep trimmed = null;
            bool shouhui = false;

            if (!DA.GetData(0, ref trimmed) || !DA.GetData(1, ref shouhui))
            {
                return;
            }
            //////////////////////////////////////////////////
            if (shouhui)
            {
                Rhino.Geometry.Collections.BrepFaceList bf = trimmed.Faces;
                bf.ShrinkFaces();
                List <Surface> sfs = new List <Surface>();
                for (int i = 0; i < bf.Count; i++)
                {
                    BrepFace bb = bf[i];
                    Surface  sf = bb.DuplicateSurface();
                    sfs.Add(sf);
                }
                DA.SetDataList(0, sfs);
            }
            else
            {
                trimmed.Faces.ShrinkFaces();
                DA.SetData(0, trimmed);
            }
        }
Example #5
0
        /// <summary>
        /// Save as '_GetNormal' but also returns midPoint of face
        /// </summary>
        /// <param name="face"></param>
        /// <param name="midPoint"></param>
        /// <returns></returns>
        public static Vector3d _GetNormalAndMidPoint3d(this BrepFace face, out Point3d midPoint)
        {
            var mid = face._GetMidPoint2d();

            midPoint = face.PointAt(mid.X, mid.Y);
            return(face._NormalAt(mid));
        }
Example #6
0
    /// <summary>
    /// This procedure contains the user code. Input parameters are provided as regular arguments,
    /// Output parameters as ref arguments. You don't have to assign output parameters,
    /// they will have a default value.
    /// </summary>
    private void RunScript(Brep brep, object void0, int fate, int mode, double rot, object void1, int divX, int divY, double stepZ, int inX, int inY, ref object DucatiumPanigaleumAmamusDumSpiramus, ref object Elapsed, ref object baseBoxWire, ref object baseGrid, ref object baseColumns, ref object xStruts, ref object yStruts)
    {
        if (brep == null || !brep.IsValid)
        {
            return;
        }

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();

        BrepFace baseFace = brep.Faces.Where(x => x.IsPlanar()).ToList()[0];
        Curve    bound    = baseFace.OuterLoop.To3dCurve();

        Plane  plane    = Plane.WorldXY;
        double rotPlane = RhinoMath.ToRadians(rot);

        plane.Rotate(rotPlane, plane.ZAxis);

        Box box = new Box(plane, bound);

        baseBoxWire = box.ToBrep().GetWireframe(-1);

        GetElements(box, divX, divY, baseFace, brep, stepZ, inX, inY);
        baseGrid    = grid;
        baseColumns = columns;
        xStruts     = xConn;
        yStruts     = yConn;

        sw.Stop();
        Elapsed = (string.Format("Elapsed: {0}ms", sw.Elapsed.TotalMilliseconds));
    }
Example #7
0
        public BRepBuilderSurfaceGeometry BrepFaceToNative(BrepFace face)
        {
            var surface = face.Surface;
            var uvBox   = new DB.BoundingBoxUV(surface.knotsU[0], surface.knotsV[0], surface.knotsU[surface.knotsU.Count - 1], surface.knotsV[surface.knotsV.Count - 1]);
            var surfPts = surface.GetControlPoints();
            var uKnots  = SurfaceKnotsToNative(surface.knotsU);
            var vKnots  = SurfaceKnotsToNative(surface.knotsV);
            var cPts    = ControlPointsToNative(surfPts);

            BRepBuilderSurfaceGeometry result;

            if (!surface.rational)
            {
                result = DB.BRepBuilderSurfaceGeometry.CreateNURBSSurface(surface.degreeU, surface.degreeV, uKnots,
                                                                          vKnots, cPts, false, uvBox);
            }
            else
            {
                var weights = ControlPointWeightsToNative(surfPts);
                result = DB.BRepBuilderSurfaceGeometry.CreateNURBSSurface(surface.degreeU, surface.degreeV, uKnots,
                                                                          vKnots, cPts, weights, false, uvBox);
            }

            return(result);
        }
Example #8
0
        public Guid AddNormal(BrepFace face)
        {
            if (!IS_ENABLED)
            {
                return(Guid.Empty);
            }

            if (face.OuterLoop == null)
            {
                return(Guid.Empty);
            }

            Point3d midPoint3d;
            var     normal     = face._GetNormalAndMidPoint3d(out midPoint3d);
            var     multiplier = face._GetTotalLengthOfEdges() / 6;

            normal.Unitize();
            normal *= multiplier;
            var name = face.OrientationIsReversed ? "Face normal" : "normal";

            if (face.OrientationIsReversed)
            {
                var srf       = face._Srf();
                var u         = srf.Domain(0).Mid;
                var v         = srf.Domain(1).Mid;
                var srfNormal = srf.NormalAt(u, v);
                srfNormal.Unitize();
                srfNormal *= multiplier * 0.8;
                AddNormal(srf.PointAt(u, v), srfNormal, Color.BurlyWood, "Surface normal");
            }

            return(AddNormal(midPoint3d, normal, Color.Brown, name));
        }
Example #9
0
        public Guid AddFaceName(string name, BrepFace face, Color color = default(Color))
        {
            if (!IS_ENABLED)
            {
                return(Guid.Empty);
            }

            if (color == default(Color))
            {
                color = Color.White;
            }

            color = DefColor(color);
            var textDot = new TextDot(name, face._GetCentroid())
            {
                FontHeight = 10,
                FontFace   = "Tahoma",
            };

            Guid id = Doc.Objects.AddTextDot(textDot, new ObjectAttributes
            {
                LayerIndex = LayerIndex,
                Name       = name,
                //Mode = ObjectMode.Locked,
                ColorSource = ObjectColorSource.ColorFromObject,
                ObjectColor = color,
                Visible     = true,
            }, null, true);

            return(id);
        }
        private GH_Brep NonPlanarBrep(double depth, IList <PolylineCurve> curveList)
        {
            var nonPlanarBrep = new List <Brep>();
            var topBrep       = Brep.CreatePatch(new[] { curveList[0] }, 5, 5, _tolerance[0]);

            nonPlanarBrep.Add(topBrep);

            BrepFace face       = topBrep.Faces[0];
            Vector3d faceNormal = face.NormalAt(face.Domain(0).Mid, face.Domain(1).Mid);

            if (Vector3d.VectorAngle(faceNormal, Vector3d.ZAxis) < Vector3d.VectorAngle(faceNormal, -Vector3d.ZAxis))
            {
                faceNormal = -faceNormal;
            }

            Brep bottomBrep = topBrep.DuplicateBrep();

            bottomBrep.Translate(faceNormal * depth);
            nonPlanarBrep.Add(bottomBrep);

            IEnumerable <Curve> edgeCurveList = topBrep.Edges.Select(edge => edge.DuplicateCurve());

            nonPlanarBrep.AddRange(edgeCurveList.Select(edgeCurve =>
                                                        Surface.CreateExtrusion(edgeCurve, faceNormal * depth).ToBrep()));
            return(new GH_Brep(Brep.JoinBreps(nonPlanarBrep, _tolerance[0])[0] ?? topBrep));
        }
        public static bool TryGetExtrusion(this BrepFace face, out Extrusion extrusion)
        {
            if (face.UnderlyingSurface().TryGetExtrusion(out extrusion))
            {
                if (face.OrientationIsReversed)
                {
                    var profile = extrusion.Profile3d(new ComponentIndex(ComponentIndexType.ExtrusionBottomProfile, 0));
                    profile.Reverse();

                    if (!extrusion.GetProfileTransformation(0.0).TryGetInverse(out var WCStoECS))
                    {
                        return(false);
                    }

                    if (!profile.Transform(WCStoECS))
                    {
                        return(false);
                    }

                    return(extrusion.SetOuterProfile(profile, false));
                }

                return(true);
            }

            extrusion = null;
            return(false);
        }
        public static bool IsCoplanar(this BrepFace face, BrepFace otherFace, double tolerance, bool sameNormal = true, bool fliptedNormal = false)
        {
            if (!face.IsValid || !otherFace.IsValid)
            {
                return(false);
            }

            if (!face.IsPlanar() || !otherFace.IsPlanar())
            {
                return(false);
            }

            face.TryGetPlane(out Plane plane, tolerance);
            otherFace.TryGetPlane(out Plane testPlane, tolerance);

            //Ensure the plane's normal is real normal
            if (face.OrientationIsReversed)
            {
                plane.Flip();
            }

            if (otherFace.OrientationIsReversed)
            {
                testPlane.Flip();
            }

            return(plane.IsCoplanar(testPlane, tolerance, sameNormal, fliptedNormal));
        }
Example #13
0
    protected override void SolveInstance(IGH_DataAccess DA)
    {
        List <Brep> cboxlist = new List <Brep>();

        if (!DA.GetDataList(0, cboxlist))
        {
            return;
        }

        List <Box> outlist = new List <Box>();

        foreach (Brep cbox in cboxlist)
        {
            BrepFace bf = cbox.Faces[0];

            Plane thisplane = new Plane();
            if (!bf.TryGetPlane(out thisplane, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Are you sure it's a box ?");
                return;
            }

            if (cbox.DuplicateVertices().Length != 8)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Are you sure it's a box ?");
                return;
            }

            outlist.Add(new Box(thisplane, cbox));
        }

        DA.SetData(0, new Instr_BoxCrop2(outlist));
    }
Example #14
0
        public static BrepLoopList Loops_ThreadSafe(this BrepFace face)
        {
            var res = face.Loops;

            res._InitThreadSafe();
            return(res);
        }
Example #15
0
        // Legacy Builder Patch
        public static void ExtrusionInfo(Brep extrusion, out Brep ftPlanar, out Brep capPlanar, out double height)
        {
            Point3d centroid = ComputeCentroid(extrusion);

            BrepFace ftFace      = null;
            BrepFace capFace     = null;
            Point3d  ftCentroid  = centroid;
            Point3d  capCentroid = centroid;

            // Analyze each face. Not the optimal solution for what we need here.
            foreach (BrepFace bf in extrusion.Faces)
            {
                double u, v;
                bf.ClosestPoint(centroid, out u, out v);
                Point3d cloestPoint = bf.PointAt(u, v);
                if (cloestPoint.Z <= ftCentroid.Z)
                {
                    ftCentroid = cloestPoint;
                    ftFace     = bf;
                }

                if (cloestPoint.Z >= capCentroid.Z)
                {
                    capCentroid = cloestPoint;
                    capFace     = bf;
                }
            }
            ftPlanar  = ftFace.DuplicateFace(true);
            capPlanar = capFace.DuplicateFace(true);
            height    = Math.Abs(capCentroid.Z - ftCentroid.Z);
        }
Example #16
0
        private void AppendSurfaceBoundary(StringBuilder sb, BrepFace fc)
        {
            foreach (var loop in fc.Loops)
            {
                string type;
                if (loop.LoopType == BrepLoopType.Outer)
                {
                    type = "OUT";
                }
                else if (loop.LoopType == BrepLoopType.Inner)
                {
                    type = "IN";
                }
                else
                {
                    continue;
                }

                foreach (var tr in loop.Trims)
                {
                    var ed = tr.Edge;
                    if (ed != null)
                    {
                        sb.AppendFormat("SARB {0}", type);
                        sb.AppendLine();
                        AppendCurveGeometry(sb, ed.EdgeCurve);
                    }
                }
            }
        }
Example #17
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve    cv1 = null; DA.GetData("curve", ref cv1);
            Curve    cv2 = null;
            Curve    cv3 = null;
            Surface  srf = null; DA.GetData("srf", ref srf); //srf.ToBrep();
            Brep     b   = null; b = srf.ToBrep();
            BrepFace bf  = null; bf = b.Faces[0];

            Curve[] cvs = new Curve[0];

            double s = new double();

            if ((DA.GetData("strength", ref s)) == false)
            {
                s = 0.05;
            }
            double it = new double(); DA.GetData("iterations", ref it);
            // double r = new double(); DA.GetData("range", ref r);
            SmoothingCoordinateSystem sm = new SmoothingCoordinateSystem();



            for (int i = 0; i < it; i++)
            {
                //int num = new int(); num = cv1.SpanCount;
                cv2 = cv1.Smooth(s, true, true, true, true, sm);
                //cv2 = cv1;
                cvs = Curve.PullToBrepFace(cv2, bf, 0.01);
                cv1 = cvs[0];
                cv1 = cv1.Fit(3, 0.1, 0.0);
            }
            DA.SetData("curve", cv1);
        }
Example #18
0
        public static Point3d _ClosestPointToOutherLoop(this BrepFace face, Point3d p, List <Curve> outherLoopEdges = null)
        {
            if (outherLoopEdges == null)
            {
                outherLoopEdges = face.OuterLoop._Trims_ThreadSafe()
                                  .Where(o => o.Edge != null)
                                  .Select(o => o.Edge.DuplicateCurve()).ToList();
            }

            var closestPoints = outherLoopEdges.Select(o =>
            {
                double t;
                o.ClosestPoint(p, out t);
                return(o.PointAt(t));
            }).ToList();

            double minDistPow2 = Double.MaxValue;
            var    closest     = p;

            foreach (var pi in closestPoints)
            {
                var distPow2 = pi._DistanceTo_Pow2(p);
                if (distPow2 < minDistPow2)
                {
                    minDistPow2 = distPow2;
                    closest     = pi;
                }
            }
            return(closest);
        }
Example #19
0
        public static Vector3d ClosestNormal(this Brep brep, Point3d testPoint)
        {
            double   u, v;
            BrepFace bf = BrepFaceFromPoint(brep, testPoint);

            bf.ClosestPoint(testPoint, out u, out v);
            return(bf.NormalAt(u, v));
        }
 public PlanarBrepFace(BrepFace f)
 {
     Face = f;
     Face.TryGetPlane(out Plane);
     loop     = null;
     area     = double.NaN;
     centroid = new Point3d(double.NaN, double.NaN, double.NaN);
 }
Example #21
0
        private Face ByBrepFace(BrepFace ghBrepFace)
        {
            Rhino.Geometry.Surface ghSurface = ghBrepFace.UnderlyingSurface();

            Face untrimmedFace = BySurface(ghSurface);

            BrepLoop     ghOuterLoop = ghBrepFace.OuterLoop;
            Wire         outerWire   = null;
            BrepLoopList ghLoops     = ghBrepFace.Loops;
            List <Wire>  innerWires  = new List <Wire>();

            foreach (BrepLoop ghLoop in ghLoops)
            {
                BrepTrimList ghTrims       = ghLoop.Trims;
                List <Edge>  trimmingEdges = new List <Edge>();
                foreach (BrepTrim ghTrim in ghTrims)
                {
                    BrepEdge ghEdge = ghTrim.Edge;
                    if (ghEdge == null)
                    {
                        continue;
                        //throw new Exception("An invalid Rhino edge is encountered.");
                    }

                    Topology topology = ByCurve(ghEdge.DuplicateCurve());

                    // Edge or Wire?
                    Edge trimmingEdge = topology as Edge;
                    if (trimmingEdge != null)
                    {
                        trimmingEdges.Add(trimmingEdge);
                    }

                    Wire partialTrimmingWire = topology as Wire;
                    if (partialTrimmingWire != null)
                    {
                        List <Edge> partialTrimmingEdges = partialTrimmingWire.Edges;
                        trimmingEdges.AddRange(partialTrimmingEdges);
                    }
                }
                Wire          trimmingWire     = Wire.ByEdges(trimmingEdges);
                List <Vertex> trimmingVertices = trimmingWire.Vertices;

                if (ghLoop == ghOuterLoop)
                {
                    outerWire = trimmingWire;
                }
                else
                {
                    innerWires.Add(trimmingWire);
                }
            }

            Face outerTrimmedFace = Topologic.Utilities.FaceUtility.TrimByWire(untrimmedFace, outerWire, true);
            Face finalFace        = outerTrimmedFace.AddInternalBoundaries(innerWires);

            return(finalFace);
        }
Example #22
0
        public static bool _Trim(this Surface srf, Curve[] crvs3d, out Brep newBrep, out string fixFailReason)
        {
            newBrep       = null;
            fixFailReason = "";

            var joins = Curve.JoinCurves(crvs3d, 0.1, true);

            if (joins.Length != 1)
            {
                fixFailReason = "Failed to join {0} edges into loop"._Format(crvs3d.Length);
                return(false);
            }

            var srfBrep = srf.ToBrep();

            if (srfBrep.Faces.Count != 1)
            {
                fixFailReason = "Failed to convert surface to brep";
                return(false);
            }

            var b = srf._Split_ThreadSafe(crvs3d, 0.1);

            if (b == null || b.Faces.Count == 0)
            {
                fixFailReason = "Failed to split surface using 3D curves";
                return(false);
            }

            BrepFace bestFace    = b.Faces[0];
            double   bestMinDist = Double.MaxValue;

            if (b.Faces.Count > 1)
            {
                var centroid = srf._GetCentroid(crvs3d, false);
                foreach (var f in b.Faces_ThreadSafe())
                {
                    if (f.Loops.Count == 1 && f.OuterLoop != null)
                    {
                        var centroidNew = f.OuterLoop._GetCentroid(false);
                        var dist        = centroid._DistanceTo(centroidNew);
                        if (dist < bestMinDist)
                        {
                            bestMinDist = dist;
                            bestFace    = f;
                        }
                    }
                }
            }
            if (bestFace == null)
            {
                fixFailReason = "Failed to extract splited face after splitting 3D curves";
                return(false);
            }

            newBrep = bestFace.DuplicateFace(true);
            return(true);
        }
Example #23
0
        public Vector3d GetBrepFaceNormal(BrepFace bf)
        {
            Point3d point0 = new Point3d(0, 0, 0);
            double  u, v;

            bf.ClosestPoint(point0, out u, out v);
            Vector3d normal = bf.NormalAt(u, v);

            return(normal);
        }
Example #24
0
        public static Plane BrepFacePlane(BrepFace brepFace, bool pointInside)
        {
            Plane plane = new Plane(FaceCentroid(brepFace), NormalCentroid(brepFace));

            if (pointInside)
            {
                plane.Flip();
            }
            return(plane);
        }
Example #25
0
        public static Surface _Srf(this BrepFace face)
        {
            //var loops = face.Loops_ThreadSafe();
            //if (loops == null || loops.Count == 0) return face;
            //var trims = loops[0].Trims_ThreadSafe();
            //if (trims == null || trims.Count == 0) return face;
            //return trims[0]._Srf();

            return(face.UnderlyingSurface());
        }
Example #26
0
        public static Plane GetPlaneAtAreaPoint(Point3d areaPoint, BrepFace bf)
        {
            double u;
            double v;

            bf.ClosestPoint(areaPoint, out u, out v);
            Plane oPlane = new Plane();

            bf.FrameAt(u, v, out oPlane);
            return(oPlane);
        }
Example #27
0
        //Computing Floor Edges
        private List <Curve> ComputeFloorEdges(BrepFace face)
        {
            List <Curve> OuterEdges = new List <Curve>();
            int          counter    = 0;

            OuterEdges.AddRange(face.DuplicateFace(true).DuplicateEdgeCurves());
            counter = OuterEdges.Count;

            Console.Write("Edge Count = " + counter.ToString());
            return(OuterEdges);
        }
Example #28
0
 // split face using 3d curves or return null if fail
 public static Brep _Split_ThreadSafe(this BrepFace face, Curve[] curves, double tol)
 {
     using (var faceDUPLICATED = face.DuplicateFace(false)) // must be here to avoid System.AccessViolationException
     {
         if (faceDUPLICATED.Faces.Count == 0)
         {
             return(null);
         }
         var splitedBreps = faceDUPLICATED.Faces[0].Split(curves, tol);
         return(splitedBreps);
     }
 }
Example #29
0
            public PlanarBrepFace(BrepFace f)
            {
                Face = f;
                if (!Face.TryGetPlane(out Plane, RhinoMath.ZeroTolerance))
                {
                    Plane = Plane.Unset;
                }

                loop     = null;
                area     = double.NaN;
                centroid = new Point3d(double.NaN, double.NaN, double.NaN);
            }
Example #30
0
        private List <Plane> GetPlanes(BrepFace bf, List <double[]> uvs)
        {
            var frames = new List <Plane>();

            foreach (var uv in uvs)
            {
                Plane frame = Plane.Unset;
                bf.FrameAt(uv[0], uv[1], out frame);
                frames.Add(frame);
            }
            return(frames);
        }
Example #31
0
    /// <summary>
    /// Offset a curve on a brep face surface. This curve must lie on the surface.
    /// <para>This overload allows to specify different offsets for different curve parameters.</para>
    /// </summary>
    /// <param name="face">The brep face on which to offset.</param>
    /// <param name="curveParameters">Curve parameters corresponding to the offset distances.</param>
    /// <param name="offsetDistances">distances to offset (+)left, (-)right.</param>
    /// <param name="fittingTolerance">A fitting tolerance.</param>
    /// <returns>Offset curves on success, or null on failure.</returns>
    /// <exception cref="ArgumentNullException">If face, curveParameters or offsetDistances are null.</exception>
    public Curve[] OffsetOnSurface(BrepFace face, double[] curveParameters, double[] offsetDistances, double fittingTolerance)
    {
      if (face == null) throw new ArgumentNullException("face");
      if (curveParameters == null) throw new ArgumentNullException("curveParameters");
      if (offsetDistances == null) throw new ArgumentNullException("offsetDistances");

      int array_count = curveParameters.Length;
      if (offsetDistances.Length != array_count)
        throw new ArgumentException("curveParameters and offsetDistances must be the same length");

      int fid = face.m_index;
      IntPtr pConstBrep = face.m_brep.ConstPointer();
      SimpleArrayCurvePointer offsetCurves = new SimpleArrayCurvePointer();
      IntPtr pCurveArray = offsetCurves.NonConstPointer();
      IntPtr pConstCurve = ConstPointer();
      int count = UnsafeNativeMethods.RHC_RhinoOffsetCurveOnSrf3(pConstCurve, pConstBrep, fid, array_count, curveParameters, offsetDistances, fittingTolerance, pCurveArray);
      Curve[] curves = offsetCurves.ToNonConstArray();
      offsetCurves.Dispose();
      if (count < 1)
        return null;
      return curves;
    }
Example #32
0
    /// <summary>
    /// Pulls this curve to a brep face and returns the result of that operation.
    /// </summary>
    /// <param name="face">A brep face.</param>
    /// <param name="tolerance">A tolerance value.</param>
    /// <returns>An array containing the resulting curves after pulling. This array could be empty.</returns>
    /// <exception cref="ArgumentNullException">If face is null.</exception>
    public Curve[] PullToBrepFace(BrepFace face, double tolerance)
    {
      if (face == null)
        throw new ArgumentNullException("face");

      IntPtr pConstCurve = ConstPointer();
      IntPtr pConstBrepFace = face.ConstPointer();
      using (Runtime.InteropWrappers.SimpleArrayCurvePointer curves = new SimpleArrayCurvePointer())
      {
        IntPtr pCurves = curves.NonConstPointer();
        UnsafeNativeMethods.RHC_RhinoPullCurveToFace(pConstCurve, pConstBrepFace, pCurves, tolerance);
        return curves.ToNonConstArray();
      }
    }
Example #33
0
    /// <summary>
    /// Offset a curve on a brep face surface. This curve must lie on the surface.
    /// <para>This overload allows to specify a surface point at which the offset will pass.</para>
    /// </summary>
    /// <param name="face">The brep face on which to offset.</param>
    /// <param name="throughPoint">2d point on the brep face to offset through.</param>
    /// <param name="fittingTolerance">A fitting tolerance.</param>
    /// <returns>Offset curves on success, or null on failure.</returns>
    /// <exception cref="ArgumentNullException">If face is null.</exception>
    public Curve[] OffsetOnSurface(BrepFace face, Point2d throughPoint, double fittingTolerance)
    {
      if (face == null)
        throw new ArgumentNullException("face");

      int fid = face.m_index;
      IntPtr pConstBrep = face.m_brep.ConstPointer();
      SimpleArrayCurvePointer offsetCurves = new SimpleArrayCurvePointer();
      IntPtr pCurveArray = offsetCurves.NonConstPointer();
      IntPtr pConstCurve = ConstPointer();
      int count = UnsafeNativeMethods.RHC_RhinoOffsetCurveOnSrf2(pConstCurve, pConstBrep, fid, throughPoint, fittingTolerance, pCurveArray);
      Curve[] curves = offsetCurves.ToNonConstArray();
      offsetCurves.Dispose();
      if (count < 1)
        return null;
      return curves;
    }
Example #34
0
    /// <summary>
    /// Extends a curve on a surface.
    /// </summary>
    /// <param name="side">The end of the curve to extend.</param>
    /// <param name="face">BrepFace that contains the curve.</param>
    /// <returns>New extended curve result on success, null on failure.</returns>
    public Curve ExtendOnSurface(CurveEnd side, BrepFace face)
    {
      if (face == null) { throw new ArgumentNullException("face"); }

      if (CurveEnd.None == side)
        return null;
      int _side = 0;
      if (CurveEnd.End == side)
        _side = 1;
      else if (CurveEnd.Both == side)
        _side = 2;

      IntPtr pConstCurve = ConstPointer();
      IntPtr pConstFace = face.ConstPointer();

      IntPtr rc = UnsafeNativeMethods.RHC_RhinoExtendCrvOnSrf(pConstCurve, pConstFace, _side);
      return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
    }
Example #35
0
    /// <summary>
    /// Pull a curve to a BrepFace using closest point projection.
    /// </summary>
    /// <param name="curve">Curve to pull.</param>
    /// <param name="face">Brepface that pulls.</param>
    /// <param name="tolerance">Tolerance to use for pulling.</param>
    /// <returns>An array of pulled curves, or an empty array on failure.</returns>
    public static Curve[] PullToBrepFace(Curve curve, BrepFace face, double tolerance)
    {
      IntPtr brep_ptr = face.m_brep.ConstPointer();
      IntPtr curve_ptr = curve.ConstPointer();

      using (SimpleArrayCurvePointer rc = new SimpleArrayCurvePointer())
      {
        IntPtr rc_ptr = rc.NonConstPointer();
        if (UnsafeNativeMethods.RHC_RhinoPullCurveToBrep(brep_ptr, face.FaceIndex, curve_ptr, tolerance, rc_ptr))
        {
          return rc.ToNonConstArray();
        }
        return new Curve[0];
      }
    }
  static void MakeTwistedCubeTrimmingLoop( ref Brep brep, ref BrepFace face, // Indices of corner vertices listed in SW, SE, NW, NE order
  int eSi,     // index of edge on south side of surface
  int eS_dir,  // orientation of edge with respect to surface trim
  int eEi,     // index of edge on south side of surface
  int eE_dir,  // orientation of edge with respect to surface trim
  int eNi,     // index of edge on south side of surface
  int eN_dir,  // orientation of edge with respect to surface trim
  int eWi,     // index of edge on south side of surface
  int eW_dir   // orientation of edge with respect to surface trim
                               )
  {
    Surface srf = brep.Surfaces[face.SurfaceIndex];
    var loop = brep.Loops.Add(BrepLoopType.Outer, face);

    // Create trimming curves running counter clockwise around the surface's domain.
    // Start at the south side
    // side: 0=south, 1=east, 2=north, 3=west
    for (int side = 0; side < 4; side++)
    {
      Curve trimming_curve = TwistedCubeTrimmingCurve(srf, side);
      int curve_index = brep.Curves2D.Add(trimming_curve);

      int ei = 0;
      bool reverse = false;
      IsoStatus iso = IsoStatus.None;
      switch (side)
      {
        case 0: // south
          ei = eSi;
          reverse = (eS_dir == -1);
          iso = IsoStatus.South;
          break;
        case 1: // east
          ei = eEi;
          reverse = (eE_dir == -1);
          iso = IsoStatus.East;
          break;
        case 2: // north
          ei = eNi;
          reverse = (eN_dir == -1);
          iso = IsoStatus.North;
          break;
        case 3: // west
          ei = eWi;
          reverse = (eW_dir == -1);
          iso = IsoStatus.West;
          break;
      }

      BrepEdge edge = brep.Edges[ei];
      BrepTrim trim = brep.Trims.Add(edge, reverse, loop, curve_index);
      trim.IsoStatus = iso;
      trim.TrimType = BrepTrimType.Mated; // This b-rep is closed, so all trims have mates.
      trim.SetTolerances(0, 0); // This simple example is exact - for models with
      // non-exact data, set tolerance as explained in
      // definition of BrepTrim.
    }
  }
    /// <summary>
    /// Intersects a curve with a Brep face.
    /// </summary>
    /// <param name="curve">A curve.</param>
    /// <param name="face">A brep face.</param>
    /// <param name="tolerance">Fitting and near miss tolerance.</param>
    /// <param name="overlapCurves">A overlap curves array argument. This out reference is assigned during the call.</param>
    /// <param name="intersectionPoints">A points array argument. This out reference is assigned during the call.</param>
    /// <returns>true on success, false on failure.</returns>
    public static bool CurveBrepFace(Curve curve, BrepFace face, 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 facePtr = face.ConstPointer();

      bool rc = UnsafeNativeMethods.RHC_RhinoCurveFaceIntersect(curvePtr, facePtr, tolerance, outputCurvesPtr, outputPointsPtr);

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

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

      return rc;
    }