internal IfcRationalBSplineCurveWithKnots(DatabaseIfc db, NurbsCurve nc, bool twoD)
     : base(db, nc, twoD)
 {
     mWeightsData = new List<double>(nc.Points.Count);
     for (int icounter = 0; icounter < nc.Points.Count; icounter++)
         mWeightsData.Add(nc.Points[icounter].Weight);
 }
Esempio n. 2
0
 public void init(NurbsCurve C, double scaleT)
 {
     Point3d P;
         P=C.PointAt(t);
         x = P.X;
         y = P.Y;
         z = 0;
 }
Esempio n. 3
0
        /// <summary>
        /// Elevate the degree of a Bezier curve (represented in NURBS form) to a given degree
        /// without changing the shape
        /// </summary>
        /// <param name="crv">The curve</param>
        /// <param name="finalDegree">The requested degree</param>
        /// <returns></returns>
        public static NurbsCurve ElevateBezierDegree(NurbsCurve crv, int finalDegree)
        {
            if (crv.ControlPoints().Count() != crv.Degree + 1 || crv.IsRational)
            {
                throw new Exception("The supplied curve for degree elevation must be a bezier curve");
            }

            if (crv.Degree > finalDegree)
            {
                throw new Exception("The supplied curve for degree elevation must have a " +
                    "lesser degree than that required");
            }

            while (crv.Degree < finalDegree)
            {
                crv = ElevateBezierDegreeBy1(crv);
            }

            return crv;
        }
Esempio n. 4
0
        private static NurbsCurve ElevateBezierDegreeBy1(NurbsCurve crv)
        {
            var cpts = crv.ControlPoints();
            var n = crv.Degree + 1;

            var cptsFinal = new List<Point>();

            cptsFinal.Add(cpts.First());

            for (var i = 1; i < cpts.Length; i++)
            {
                cptsFinal.Add(Interp(cpts[i - 1], cpts[i], (double)i / n));
            }

            cptsFinal.Add(cpts.Last());

            var oldKnots = crv.Knots();

            var knots = HermiteToNurbs.Clamp(new[] { oldKnots.First(), oldKnots.Last() }, n);
            var weights = Enumerable.Repeat(1.0, cptsFinal.Count).ToArray();

            return NurbsCurve.ByControlPointsWeightsKnots(cptsFinal, weights, knots, n);
        }
Esempio n. 5
0
 public static NurbsCurve Extend(this NurbsCurve curve, double start = 0.0, double end = 0.0, bool tangentExtensions = false, double tolerance = Tolerance.Distance)
 {
     throw new NotImplementedException();
 }
Esempio n. 6
0
 public static Point Centroid(this NurbsCurve nurbsCurve, double tolerance = Tolerance.Distance)
 {
     throw new NotImplementedException();
 }
 internal IfcBSplineCurveWithKnots(DatabaseIfc m, NurbsCurve nc, bool twoD)
     : base(m, nc, twoD)
 {
     if (mDatabase.mModelView != ModelView.Ifc4NotAssigned)
         throw new Exception("Invalid Model View for IfcRationalBSplineCurveWithKnots : " + mDatabase.ModelView.ToString());
     ClosedCurve = nc.IsClosed ? IfcLogicalEnum.TRUE : IfcLogicalEnum.FALSE;
     adoptKnotsAndMultiplicities(nc);
 }
        public BezierPatchForeignEdge(ForeignShell parent, ControlPoint[] points, int index)
            : base(parent)
        {
            Debug.Assert(points != null);

            NurbsData data = new NurbsData(4, false, false, new Knot[] { new Knot(0, 4), new Knot(1, 4) });
            nurbsCurve = NurbsCurve.CreateFromControlPoints(data, points);
            this.index = index;
        }
Esempio n. 9
0
        internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobjectIndex)
        {
            if (IntPtr.Zero == pGeometry)
            {
                return(null);
            }

            var type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry);

            if (type < 0)
            {
                return(null);
            }
            GeometryBase rc = null;

            switch (type)
            {
            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Curve: //1
                rc = new Curve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsCurve: //2
                rc = new NurbsCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolyCurve: // 3
                rc = new PolyCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PolylineCurve: //4
                rc = new PolylineCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ArcCurve: //5
                rc = new ArcCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_LineCurve: //6
                rc = new LineCurve(pGeometry, parent, subobjectIndex);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Mesh: //7
                rc = new Mesh(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Point: //8
                rc = new Point(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_TextDot: //9
                rc = new TextDot(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Surface: //10
                rc = new Surface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Brep: //11
                rc = new Brep(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_NurbsSurface: //12
                rc = new NurbsSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_RevSurface: //13
                rc = new RevSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PlaneSurface: //14
                rc = new PlaneSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_ClippingPlaneSurface: //15
                rc = new ClippingPlaneSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Hatch: // 17
                rc = new Hatch(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SumSurface: //19
                rc = new SumSurface(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepFace: //20
            {
                int    faceindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex);
                if (ptr_brep != IntPtr.Zero && faceindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Faces[faceindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepEdge: // 21
            {
                int    edgeindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex);
                if (ptr_brep != IntPtr.Zero && edgeindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Edges[edgeindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_InstanceReference: // 23
                rc = new InstanceReferenceGeometry(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Extrusion: //24
                rc = new Extrusion(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointCloud: // 26
                rc = new PointCloud(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DetailView: // 27
                rc = new DetailView(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Light: //32
                rc = new Light(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_PointGrid: //33
                rc = new Point3dGrid(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_MorphControl: //34
                rc = new MorphControl(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepLoop: //35
            {
                int    loopindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex);
                if (ptr_brep != IntPtr.Zero && loopindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Loops[loopindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_BrepTrim: // 36
            {
                int    trimindex = -1;
                IntPtr ptr_brep  = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex);
                if (ptr_brep != IntPtr.Zero && trimindex >= 0)
                {
                    Brep b = new Brep(ptr_brep, parent);
                    rc = b.Trims[trimindex];
                }
            }
            break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Leader: // 38
                rc = new Leader(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_SubD: // 39
                rc = new SubD(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimLinear: //40
                rc = new LinearDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimAngular: //41
                rc = new AngularDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimRadial: //42
                rc = new RadialDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_DimOrdinate: //43
                rc = new OrdinateDimension(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Centermark: //44
                rc = new Centermark(pGeometry, parent);
                break;

            case UnsafeNativeMethods.OnGeometryTypeConsts.ON_Text: //45
                rc = new TextEntity(pGeometry, parent);
                break;

            default:
                rc = new UnknownGeometry(pGeometry, parent, subobjectIndex);
                break;
            }

            return(rc);
        }
Esempio n. 10
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static int Degree(this NurbsCurve curve)
        {
            return(curve.Knots.Count - curve.ControlPoints.Count + 1);
        }
Esempio n. 11
0
        /// <summary>
        /// Remove zig-zags from curve
        /// WARNING: could have problems in Singularity
        /// </summary>
        /// <param name="crv"></param>
        /// <param name="srf"></param>
        /// <param name="tol"></param>
        /// <returns></returns>
        public static bool _ZigZagDeformations_TryRemove_old(this Curve crv, Surface srf, double tol, out NurbsCurve newCrvNurb)
        {
            newCrvNurb = null;

            NurbsCurve crvNurb = crv._ToNurbsCurve();

            // Linear crv's can't have deformations - so return original curve
            if (crvNurb.Degree == 1)
            {
                return(false);
            }

            var zigzagIndexes = crvNurb._ZigZagDeformationsFind();

            if (zigzagIndexes == null)
            {
                return(false);
            }

            //
            // Project all points on surface
            //
            List <SurfacePoint2d3dSrf> srfPoints;

            if (!crvNurb._TryProjectOnSrf(srf, tol, out srfPoints))
            {
                return(false);
            }
            var savesrfPointsCount = srfPoints.Count;

            //
            // Remove wrong Control Points
            //
            // remove from left to right
            RemoveZigZagIndexes(ref srfPoints, 5);
            // remove from right to left
            srfPoints.Reverse();
            RemoveZigZagIndexes(ref srfPoints, 5);
            // back to original order
            srfPoints.Reverse();

            //
            // Apply fix
            //
            if (srfPoints.Count == savesrfPointsCount)
            {
                //
            }

            // deformation present - recreate curve base on new control points (without deformed ones)
            var newPoints = srfPoints.Select(o => o.LocationSrf);
            var res       = srf.InterpolatedCurveOnSurface(newPoints, tol);

            newCrvNurb = res;
            return(true);
        }
Esempio n. 12
0
        public static void ToMaya(Curve CurveToSend, string name)
        {
            NurbsCurve ctsAsNurb = null;

            if (CurveToSend is Rectangle)
            {
                Rectangle rec = (Rectangle)CurveToSend;
                ctsAsNurb = NurbsCurve.ByControlPoints(rec.Points, 1, true);
            }
            else if (CurveToSend is Polygon)
            {
                Polygon rec = (Polygon)CurveToSend;
                ctsAsNurb = NurbsCurve.ByControlPoints(rec.Points, 1, true);
            }
            else
            {
                ctsAsNurb = CurveToSend.ToNurbsCurve();
            }

            var ncd = new MFnNurbsCurveData();


            MFnNurbsCurveForm mfnform;

            if (ctsAsNurb.IsClosed)
            {
                mfnform = MFnNurbsCurveForm.kClosed;
            }
            else
            {
                mfnform = MFnNurbsCurveForm.kOpen;
            }

            var mayaCurve = new MFnNurbsCurve();

            var vtxs = new MPointArray();

            var cvs = ctsAsNurb.ControlPoints();
            var yUp = MGlobal.isYAxisUp;

            if (yUp)
            {
                foreach (var cv in cvs)
                {
                    var pt = new MPoint(cv.X, cv.Z, -cv.Y);
                    vtxs.Add(pt);
                    //pt.Dispose();
                }
            }
            else
            {
                foreach (var cv in cvs)
                {
                    var pt = new MPoint(cv.X, cv.Y, cv.Z);
                    vtxs.Add(pt);
                    //pt.Dispose();
                }
            }

            var knots    = ctsAsNurb.Knots();
            var crvKnots = new MDoubleArray(knots);

            crvKnots.RemoveAt(0);
            crvKnots.RemoveAt(crvKnots.Count - 1);

            MDagPath node       = null;
            var      nodeExists = false;

            Task checkNode  = null;
            Task deleteNode = null;

            try
            {
                node       = DMInterop.getDagNode(name);
                nodeExists = true;
            }
            catch (Exception)
            {
                nodeExists = false;
            }

            MObject obj;

            if (nodeExists)
            {
                MDagPath nodeShape = node;
                nodeShape.extendToShape();
                var modifyCrv = new MDGModifier();
                mayaCurve = new MFnNurbsCurve(nodeShape);

                try
                {
                    MFnNurbsCurveData dataCreator  = new MFnNurbsCurveData();
                    MObject           outCurveData = dataCreator.create();
                    var    span   = (vtxs.Count - ctsAsNurb.Degree);
                    string rblCmd = $"rebuildCurve -rt 0 -s {span} -d {ctsAsNurb.Degree} {name}";

                    if (mayaCurve.numCVs != vtxs.Count || mayaCurve.degree != ctsAsNurb.Degree)
                    {
                        MGlobal.executeCommand(rblCmd);
                    }

                    mayaCurve.setCVs(vtxs);
                    mayaCurve.setKnots(crvKnots, 0, crvKnots.length - 1);
                    mayaCurve.updateCurve();
                    modifyCrv.doIt();

                    if (CurveToSend.GetType() == typeof(Circle))
                    {
                        span   = 8;
                        rblCmd = $"rebuildCurve -rt 0 -s {span} {name}";
                        MGlobal.executeCommand(rblCmd);
                    }
                }
                catch (Exception e)
                {
                    MGlobal.displayWarning(e.Message);
                }
            }

            else
            {
                obj = mayaCurve.create(vtxs, crvKnots, (uint)ctsAsNurb.Degree, (MFnNurbsCurve.Form)mfnform,
                                       false, ctsAsNurb.IsRational);
                MFnDependencyNode nodeFn = new MFnDagNode(obj);
                nodeFn.setName(name);
            }
        }
        private void adoptKnotsAndMultiplicities(NurbsCurve nc)
        {
            double tol = (nc.Knots[nc.Knots.Count - 1] - nc.Knots[0]) / Math.Max(1000, nc.Knots.Count) / 1000;

            if (nc.IsPeriodic)
            {
                int kc = 1;
                if (nc.Knots[1] - nc.Knots[0] < tol)
                {
                    kc = 2;
                }
                else
                {
                    mKnots.Add(nc.Knots[0] - (nc.Knots[1] - nc.Knots[0]));
                    mKnotMultiplicities.Add(1);
                }
                double knot = nc.Knots[0];
                for (int icounter = 1; icounter < nc.Knots.Count; icounter++)
                {
                    double t = nc.Knots[icounter];
                    if ((t - knot) > tol)
                    {
                        mKnots.Add(knot);
                        mKnotMultiplicities.Add(kc);
                        knot = t;
                        kc   = 1;
                    }
                    else
                    {
                        kc++;
                    }
                }
                mKnots.Add(knot);
                if (kc > 1)
                {
                    mKnotMultiplicities.Add(kc + 1);
                }
                else
                {
                    mKnotMultiplicities.Add(1);
                    mKnots.Add(knot + (knot - nc.Knots[nc.Knots.Count - 2]));
                    mKnotMultiplicities.Add(1);
                }
            }
            else
            {
                int    kc   = 2;
                double knot = nc.Knots[0];
                for (int icounter = 1; icounter < nc.Knots.Count; icounter++)
                {
                    double t = nc.Knots[icounter];
                    if ((t - knot) > tol)
                    {
                        mKnots.Add(knot);
                        mKnotMultiplicities.Add(kc);
                        knot = t;
                        kc   = 1;
                    }
                    else
                    {
                        kc++;
                    }
                }
                mKnots.Add(knot);
                mKnotMultiplicities.Add(kc + 1);
            }
        }
Esempio n. 14
0
        private static NurbsCurve _ZigZagDeformations_TryRemove__by_removing_diapasons(NurbsCurve crv, Surface srf, int[] zigzagIndexes, List <ZigZagDiapason> diapasons)
        {
            //
            // Split curve on segments
            //
            Point3d[] allCrvPoints;
            //Try1
            var divby = crv._GetDivBy(srf);
            var ts    = crv._DivideByCount_ThreadSafe(divby, true, out allCrvPoints);

            if (allCrvPoints == null)
            {
                //Try2
                ts = crv._DivideByCount_ThreadSafe(100, true, out allCrvPoints);
                if (allCrvPoints == null)
                {
                    //Try3
                    var length = crv._Get3dLength(srf);
                    if (length < 0.001)
                    {
                        allCrvPoints = new[] { crv.PointAtStart, crv.PointAtEnd };
                        ts           = new[] { crv.Domain.T0, crv.Domain.T1 };
                    }
                    else
                    {
                        return(null);
                    }
                }
            }

            //
            // Fix curve by extending diapasons until we get fixed curve
            //
            NurbsCurve res = null;

            var    diapasonExtensionMax = crv.Domain.Length * 0.05; // 5%
            double diapasonExtension    = 0;

            while (diapasonExtension <= diapasonExtensionMax)
            {
                //Layers.Debug.AddPoint(crvNurb._PX3d(diapasons[0].StartIgnoreAtT - diapasonExtension, srf), Color.Red);
                //Layers.Debug.AddPoint(crvNurb._PX3d(diapasons[0].EndIgnoreAtT + diapasonExtension, srf), Color.Red);
                var crvFixed = _ZigZagDeformations_Remove(crv, srf, ts, diapasons, diapasonExtension);
                if (crvFixed == null)
                {
                    break;                   //break tries - return what we found till now :(
                }
                // if no more zigzags - set result

                if (!crvFixed._ZigZagDeformationExists(srf))
                {
                    res = crvFixed;
                    break;
                }

                // if we here - zigzags still exists after fix - so lets increaese cut length and lets try once again
                diapasonExtension += crv.Domain.Length * 0.01;  // 1%
            }

            return(res);
        }
Esempio n. 15
0
 public static NurbsCurve Scale(this NurbsCurve curve, Point origin, Vector scaleVector)
 {
     throw new NotImplementedException();
 }
Esempio n. 16
0
 public static Vector TangentAtLength(this NurbsCurve curve, double length, double tolerance = Tolerance.Distance)
 {
     throw new NotImplementedException();
 }
Esempio n. 17
0
        /***************************************************/

        public static ICurve SetGeometry(this NurbsCurve curve, ICurve newCurve)
        {
            return(newCurve.IClone());
        }
Esempio n. 18
0
 public static Vector StartDir(this NurbsCurve curve)
 {
     throw new NotImplementedException();
 }
Esempio n. 19
0
 public static NurbsCurve Mirror(this NurbsCurve curve, Plane p)
 {
     throw new NotImplementedException();
 }
 public NurbsCurve ToNurbsCurve(int degree, int cvCount)
 {
     return(NurbsCurve.CreateFromCircle(this, degree, cvCount));
 }
Esempio n. 21
0
 public static Point Centroid(this NurbsCurve nurbsCurve)
 {
     return(nurbsCurve.Centroid(Tolerance.Distance));
 }
Esempio n. 22
0
        private static NurbsCurve _ZigZagDeformations_Remove(this NurbsCurve crvNurb, Surface srf, double[] ts, List <ZigZagDiapason> diapasons, double diapasonExtension)
        {
            //
            // Filter segmens - remove those segments what is close to zigzag control points
            //
            var filteredCrvPoints = new List <Point3d>();

            filteredCrvPoints.Add(crvNurb.PointAt(ts[0])); // add 1-st point (PointAtStart)
            for (int i = 1; i < ts.Length - 1; i++)
            {
                var t = ts[i];
                var isCloseToZigzag = false;
                foreach (var d in diapasons)
                {
                    var minT = d.StartIgnoreAtT - diapasonExtension;
                    var maxT = d.EndIgnoreAtT + diapasonExtension;
                    if (minT <= t && t <= maxT)
                    {
                        isCloseToZigzag = true;
                        break;
                    }
                }
                if (!isCloseToZigzag)
                {
                    filteredCrvPoints.Add(crvNurb.PointAt(t));
                    //Layers.Debug.AddPoint(crvNurb._PX3d(t, srf), Color.Green);
                }
                else
                {
                    //Layers.Debug.AddPoint(crvNurb._PX3d(t, srf), Color.Red);
                }


                //DEBUG
                //var p3d = crvNurb.PointAt(t);
                //if (crvNurb.Dimension == 2)
                //{
                //    p3d = srf.PointAt(crvNurb.PointAt(t).X, crvNurb.PointAt(t).Y);
                //}
                //Layers.Debug.AddPoint(p3d, isCloseToZigzag ? Color.Red : Color.Blue);
                //ENDDEBUG
            }
            filteredCrvPoints.Add(crvNurb.PointAt(ts[ts.Length - 1]));// add last point (PointAtEnd)


            //DEBUG
            //log.temp("Adding debig point for ZigZag");
            //Viewport.Redraw(RhinoDoc.ActiveDoc, "Layers.Debug.AddPoints(filteredCrvPoints)");
            //foreach (var p in filteredCrvPoints)
            //{
            //    var p3d = p;
            //    if (crvNurb.Dimension == 2)
            //    {
            //        p3d = srf.PointAt(p.X, p.Y);
            //    }
            //    Layers.Debug.AddPoint(p3d, Color.Blue);
            //}
            //ENDDEBUG

            //
            // Approximate and simplfy new crv
            //
            var res = Curve.CreateControlPointCurve(filteredCrvPoints, 3);

            //var res = Curve.CreateInterpolatedCurve(filteredCrvPoints, 3); - works bad - creates zigzags
            if (res != null)
            {
                if (crvNurb.Dimension == 2)
                {
                    res = res._SetDimension(2);
                }

                // it is incorrect to fix control point here!
                //////////if (crvNurb.Dimension == 2 && srf != null)
                //////////{
                //////////    res = res._Fix2dContorlPoints(srf); // - shall we do fix 2d control points ??? - NO!!!
                //////////}


                res = res._Simplify(srf, true);
            }

            return(res == null ? null : res._ToNurbsCurve());
        }
Esempio n. 23
0
 public NurbsExtrudedSurface(NurbsCurve profile, NurbsCurve rail)
 {
     this.ProfileCurve  = profile;
     this.ExtrusionRail = rail;
 }
Esempio n. 24
0
            protected override void SolveInstance(IGH_DataAccess DA)
            {
                try {
                    //Input
                    Surface S = s;
                    //if (!DA.GetData(0, ref S)) { return; }
                    DA.GetData(0, ref S);
                    Point3d P = Point3d.Unset;

                    if (!DA.GetData(1, ref P))
                    {
                        P = S.PointAt(S.Domain(0).Mid, S.Domain(1).Mid);
                    }

                    double R = Rhino.RhinoMath.UnsetValue;
                    if (!DA.GetData(2, ref R))
                    {
                        return;
                    }

                    double A = Rhino.RhinoMath.UnsetValue;
                    if (!DA.GetData(3, ref A))
                    {
                        return;
                    }

                    int max = 0;
                    if (!DA.GetData(4, ref max))
                    {
                        return;
                    }

                    Boolean extend = false;
                    if (!DA.GetData(5, ref extend))
                    {
                        return;
                    }

                    if (R <= 0)
                    {
                        this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Mesh edge length must be a positive, non-zero number.");
                        return;
                    }

                    Mesh cutter = new Mesh();
                    //DA.GetData(8, ref cutter);

                    Surface Sold = S;
                    Sold.SetDomain(0, new Interval(0, 1));
                    Sold.SetDomain(1, new Interval(0, 1));
                    PointCloud cornerPoints = new PointCloud(new Point3d[] { Sold.PointAt(0, 0), Sold.PointAt(0, 1), Sold.PointAt(1, 0), Sold.PointAt(1, 1) });


                    if (extend)   //Extend more and trim edges?
                    {
                        S = S.Extend(IsoStatus.North, R * 2, true);
                        S = S.Extend(IsoStatus.East, R * 2, true);
                        S = S.Extend(IsoStatus.South, R * 2, true);
                        S = S.Extend(IsoStatus.West, R * 2, true);
                    }

                    //int L = 0;
                    //int W = 0;
                    //DA.GetData(6, ref L);
                    //DA.GetData(7, ref W);

                    //----------------------------------------------------------------------------------------------------------//
                    //Solution

                    // starting point
                    double u0, v0;
                    S.ClosestPoint(P, out u0, out v0);

                    //Create plane on surface by point and surface normal, plane x,y axis are directions for the net
                    Plane plane = new Plane(S.PointAt(u0, v0), S.NormalAt(u0, v0));
                    plane.Rotate(Rhino.RhinoMath.ToRadians(A), S.NormalAt(u0, v0));
                    Vector3d[] dir = new Vector3d[] { plane.XAxis *R, plane.YAxis *R, plane.XAxis * -R, plane.YAxis * -R };

                    //Surface
                    Curve[] MyNakedEdges     = Sold.ToBrep().DuplicateNakedEdgeCurves(true, false);
                    Curve   SurfaceNakedEdge = Curve.JoinCurves(MyNakedEdges)[0];
                    Mesh[]  meshes           = new Mesh[] { new Mesh(), new Mesh(), new Mesh(), new Mesh() };

                    //----------------------------------------------------------------------------------------------------------//
                    //Create axis
                    // for each direction, walk out (and store list of points)

                    double           u, v;
                    List <Point3d>[] axis = new List <Point3d> [4];
                    List <Arc>[]     arcs = new List <Arc> [4];
                    polylines = new List <Polyline>();

                    for (int i = 0; i < 4; i++)
                    {
                        // set u and v to starting point
                        u = u0;
                        v = v0;
                        List <Point3d> pts        = new List <Point3d>();
                        List <Arc>     arcCurrent = new List <Arc>();


                        for (int j = 0; j < max + 1; j++)
                        {
                            Point3d pt = S.PointAt(u, v); // get point and normal for uv
                            pts.Add(pt);

                            Vector3d srfNormal = S.NormalAt(u, v) * R;

                            Arc arc = new Arc(pt + srfNormal, pt + dir[i], pt - srfNormal); // create forward facing arc and find intersection point with surface (as uv)
                            arcCurrent.Add(arc);
                            CurveIntersections isct = Intersection.CurveSurface(arc.ToNurbsCurve(), S, 0.01, 0.01);


                            if (isct.Count > 0)
                            {
                                isct[0].SurfacePointParameter(out u, out v);
                            }
                            else
                            {
                                break;
                            }

                            // adjust direction vector (new position - old position)
                            dir[i] = S.PointAt(u, v) - pt;
                        }

                        axis[i] = pts;
                        arcs[i] = arcCurrent;
                    }



                    //----------------------------------------------------------------------------------------------------------//
                    //Build up the mesh quads in between
                    Rhino.RhinoApp.ClearCommandHistoryWindow();

                    GH_PreviewUtil preview = new GH_PreviewUtil(GetValue("Animate", false));

                    Mesh         mesh                = new Mesh();                                                                                                                                                   // target mesh
                    Mesh[]       fourMeshes          = new Mesh[4];
                    List <int>[] faceID              = new List <int>[] { new List <int>(), new List <int>(), new List <int>(), new List <int>() };                                                                  //columns lengths
                    List <List <Polyline> >[] strips = new List <List <Polyline> >[] { new List <List <Polyline> >(), new List <List <Polyline> >(), new List <List <Polyline> >(), new List <List <Polyline> >() }; //columns lengths
                    //List<Polyline> cuts = new List<Polyline>();

                    for (int k = 0; k < 4; k++)   //Loop through each axis

                    {
                        Mesh qmesh = new Mesh();                                                         // local mesh for quadrant

                        Point3d[,] quad = new Point3d[axis[k].Count + 10, axis[(k + 1) % 4].Count + 10]; // 2d array of points
                        int[,] qindex   = new int[axis[k].Count + 10, axis[(k + 1) % 4].Count + 10];     // 2d array of points' indices in local mesh

                        int count = 0;

                        //Add 2nd axis particles
                        for (int i = 0; i < axis[(k + 1) % 4].Count; i++)
                        {
                            quad[0, i] = axis[(k + 1) % 4][i];        //store 2nd axis points in point array
                            qmesh.Vertices.Add(axis[(k + 1) % 4][i]); //also add 2nd axis points to mesh
                            qindex[0, i] = count++;                   //store indicies
                        }


                        for (int i = 1; i < quad.GetLength(0); i++)
                        {
                            if (i < axis[k].Count)              // add axis vertex
                            {
                                quad[i, 0] = axis[k][i];        //store 1st axis points in point array
                                qmesh.Vertices.Add(axis[k][i]); //also add 1st axis points to mesh
                                qindex[i, 0] = count++;         //store indicies
                            }


                            int counter = 0;

                            List <Polyline> currentStrip = new List <Polyline>();
                            // for each column attempt to locate a new vertex in the grid
                            for (int j = 1; j < quad.GetLength(1); j++)
                            {
                                // if quad[i - 1, j] doesn't exist, try to add it and continue (or else break the current row)
                                if (quad[i - 1, j] == new Point3d())
                                {
                                    if (j < 2)
                                    {
                                        break;
                                    }

                                    CurveIntersections isct = this.ArcIntersect(S, quad[i - 1, j - 1], quad[i - 1, j - 2], R);

                                    if (isct.Count > 0)
                                    {
                                        quad[i - 1, j] = isct[0].PointB;
                                        qmesh.Vertices.Add(quad[i - 1, j]);
                                        qindex[i - 1, j] = count++;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                // if quad[i, j - 1] doesn't exist, try to create quad[i, j] by projection and skip mesh face creation
                                if (quad[i, j - 1] == new Point3d())
                                {
                                    if (i < 2)
                                    {
                                        break;
                                    }

                                    CurveIntersections isct = this.ArcIntersect(S, quad[i - 1, j], quad[i - 2, j], R);

                                    if (isct.Count > 0)
                                    {
                                        quad[i, j] = isct[0].PointB;
                                        qmesh.Vertices.Add(quad[i, j]);
                                        qindex[i, j] = count++;

                                        continue;
                                    }
                                }

                                // construct a sphere at each neighbouring vertex ([i,j-1] and [i-1,j]) and intersect

                                Sphere sph1 = new Sphere(quad[i, j - 1], R);
                                Sphere sph2 = new Sphere(quad[i - 1, j], R);
                                Circle cir;

                                if (Intersection.SphereSphere(sph1, sph2, out cir) == SphereSphereIntersection.Circle)
                                {
                                    CurveIntersections cin = Intersection.CurveSurface(NurbsCurve.CreateFromCircle(cir), S, 0.01, 0.01);// intersect circle with surface

                                    // attempt to find the new vertex (i.e not [i-1,j-1])

                                    foreach (IntersectionEvent ie in cin)
                                    {
                                        if ((ie.PointA - quad[i - 1, j - 1]).Length > 0.2 * R)  // compare with a tolerance, rather than exact comparison

                                        {
                                            quad[i, j] = ie.PointA;
                                            qmesh.Vertices.Add(quad[i, j]);
                                            qindex[i, j] = count++;

                                            Point3d[] facePt = new Point3d[] { quad[i, j], quad[i - 1, j], quad[i - 1, j - 1], quad[i, j - 1] };

                                            Sold.ClosestPoint(quad[i, j], out double u1, out double v1);
                                            Sold.ClosestPoint(quad[i - 1, j], out double u2, out double v2);
                                            Sold.ClosestPoint(quad[i - 1, j - 1], out double u3, out double v3);
                                            Sold.ClosestPoint(quad[i, j - 1], out double u4, out double v4);

                                            double tolerance = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance * 10;
                                            bool[] flag      = new bool[] {
                                                Sold.PointAt(u1, v1).DistanceTo(quad[i, j]) < tolerance,
                                                Sold.PointAt(u2, v2).DistanceTo(quad[i - 1, j]) < tolerance,
                                                Sold.PointAt(u3, v3).DistanceTo(quad[i - 1, j - 1]) < tolerance,
                                                Sold.PointAt(u4, v4).DistanceTo(quad[i, j - 1]) < tolerance
                                            };



                                            if (flag[0] && flag[1] && flag[2] && flag[3])
                                            {
                                                qmesh.Faces.AddFace(qindex[i, j], qindex[i - 1, j], qindex[i - 1, j - 1], qindex[i, j - 1]);// create quad-face
                                                currentStrip.Add(new Polyline()
                                                {
                                                    quad[i, j], quad[i - 1, j], quad[i - 1, j - 1], quad[i, j - 1], quad[i, j]
                                                });
                                                counter++;
                                            }
                                            else if (flag[0] || flag[1] || flag[2] || flag[3])
                                            {
                                                Polyline temp = new Polyline()
                                                {
                                                    quad[i, j], quad[i - 1, j], quad[i - 1, j - 1], quad[i, j - 1]
                                                };
                                                Polyline trimmedTemp = new Polyline();
                                                //temp = new Polyline() { quad[i, j], quad[i - 1, j], quad[i - 1, j - 1], quad[i, j - 1], quad[i, j] };

                                                double        t = R * 0.1;
                                                HashSet <int> intersectedSurfaceEdgeId = new HashSet <int>();


                                                for (int l = 0; l < 4; l++)
                                                {
                                                    //If point is ons surface
                                                    Sold.ClosestPoint(temp[l], out double cpu, out double cpv);
                                                    if (Sold.PointAt(cpu, cpv).DistanceTo(temp[l]) < Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance)
                                                    {
                                                        trimmedTemp.Add(temp[l]);
                                                    }


                                                    //Intersect line segment with closed brep
                                                    Line faceSegment = new Line(temp[l], temp[MathUtil.Wrap(l + 1, 4)]);

                                                    Point3d[] meshLinePts = Intersection.MeshLine(cutter, faceSegment, out int[] faceIds);
                                                    if (meshLinePts.Length > 0)
                                                    {
                                                        trimmedTemp.Add(meshLinePts[0]);
                                                    }
                                                }


                                                trimmedTemp.Close();
                                                //cuts.Add(trimmedTemp);
                                            }

                                            break;
                                        }
                                    }

                                    if (preview.Enabled)
                                    {
                                        preview.Clear();
                                        preview.AddMesh(mesh);
                                        preview.AddMesh(qmesh);
                                        preview.Redraw();
                                    }
                                } //if sphere intersection
                            }     //for j

                            if (currentStrip.Count > 0)
                            {
                                strips[k].Add(currentStrip);
                            }
                        }//for i



                        mesh.Append(qmesh);// add local mesh to target
                        fourMeshes[k] = qmesh;
                    }//for k



                    //----------------------------------------------------------------------------------------------------------//
                    //Output



                    mesh.Weld(Math.PI);
                    mesh.Compact();
                    mesh.Normals.ComputeNormals();

                    DA.SetData(0, mesh);
                    DA.SetDataTree(1, NGonsCore.GrasshopperUtil.IE2(axis, 0));

                    this.PreparePreview(mesh, DA.Iteration, null, true, null, mesh.GetEdges());
                    //DA.SetDataList(2, cuts);
                    //DA.SetDataTree(3, NGonsCore.GrasshopperUtil.IE4(patches.ToList(), 0));
                    //DA.SetDataList(4, fourMeshes);
                    //DA.SetDataTree(5, GrasshopperUtil.IE3(strips, 0));

                    preview.Clear();
                }catch (Exception e) {
                    GrasshopperUtil.Debug(e);
                }
            }
Esempio n. 25
0
 public static double Area(this NurbsCurve curve)
 {
     throw new NotImplementedException();
 }
Esempio n. 26
0
 public static double DerivativeFunction(this NurbsCurve curve, int i, int n, double t)
 {
     throw new NotImplementedException();
 }
Esempio n. 27
0
        /***************************************************/

        public static NurbsCurve Clone(this NurbsCurve curve)
        {
            return(new NurbsCurve {
                ControlPoints = curve.ControlPoints.Select(x => x.Clone()).ToList(), Weights = curve.Weights.ToList(), Knots = curve.Knots.ToList()
            });
        }
Esempio n. 28
0
 public static double ParameterAtPoint(this NurbsCurve curve, Point point, double tolerance = Tolerance.Distance)
 {
     throw new NotImplementedException();
 }
Esempio n. 29
0
        /***************************************************/

        public static BoundingBox Bounds(this NurbsCurve curve)
        {
            return(curve == null ? null : curve.ControlPoints.Bounds());
        }
Esempio n. 30
0
 protected IfcBSplineCurve(DatabaseIfc m, NurbsCurve nonRationalCurve, bool twoD)
     : this(m, nonRationalCurve.Degree, IfcBSplineCurveForm.UNSPECIFIED)
 {
     int ilast = nonRationalCurve.Points.Count - (nonRationalCurve.IsPeriodic ? mDegree : 0);
     if (twoD)
     {
         for (int icounter = 0; icounter < ilast; icounter++)
         {
             Point3d p3 = nonRationalCurve.Points[icounter].Location;
             mControlPointsList.Add(new IfcCartesianPoint(m, new Point2d(p3.X, p3.Y)).mIndex);
         }
         if (nonRationalCurve.IsPeriodic)
         {
             for (int icounter = 0; icounter < mDegree; icounter++)
                 mControlPointsList.Add(mControlPointsList[icounter]);
         }
     }
     else
     {
         for (int icounter = 0; icounter < ilast; icounter++)
             mControlPointsList.Add(new IfcCartesianPoint(m, nonRationalCurve.Points[icounter].Location).mIndex);
         if (nonRationalCurve.IsPeriodic)
         {
             for (int icounter = 0; icounter < mDegree; icounter++)
                 mControlPointsList.Add(mControlPointsList[icounter]);
         }
     }
 }
 public static List <Point> LineIntersections(this NurbsCurve curve, Line line, bool useInfiniteLine = false, double tolerance = Tolerance.Distance)
 {
     throw new NotImplementedException();
 }
Esempio n. 32
0
 private void adoptKnotsAndMultiplicities(NurbsCurve nc)
 {
     double tol = (nc.Knots[nc.Knots.Count - 1] - nc.Knots[0]) / Math.Max(1000, nc.Knots.Count) / 1000;
     if (nc.IsPeriodic)
     {
         int kc = 1;
         if (nc.Knots[1] - nc.Knots[0] < tol)
             kc = 2;
         else
         {
             mKnots.Add(nc.Knots[0] - (nc.Knots[1] - nc.Knots[0]));
             mMultiplicities.Add(1);
         }
         double knot = nc.Knots[0];
         for (int icounter = 1; icounter < nc.Knots.Count; icounter++)
         {
             double t = nc.Knots[icounter];
             if ((t - knot) > tol)
             {
                 mKnots.Add(knot);
                 mMultiplicities.Add(kc);
                 knot = t;
                 kc = 1;
             }
             else
                 kc++;
         }
         mKnots.Add(knot);
         if (kc > 1)
             mMultiplicities.Add(kc + 1);
         else
         {
             mMultiplicities.Add(1);
             mKnots.Add(knot + (knot - nc.Knots[nc.Knots.Count - 2]));
             mMultiplicities.Add(1);
         }
     }
     else
     {
         int kc = 2;
         double knot = nc.Knots[0];
         for (int icounter = 1; icounter < nc.Knots.Count; icounter++)
         {
             double t = nc.Knots[icounter];
             if ((t - knot) > tol)
             {
                 mKnots.Add(knot);
                 mMultiplicities.Add(kc);
                 knot = t;
                 kc = 1;
             }
             else
                 kc++;
         }
         mKnots.Add(knot);
         mMultiplicities.Add(kc + 1);
     }
 }
Esempio n. 33
0
        /***************************************************/

        public static bool IsInPlane(this NurbsCurve curve, Plane plane, double tolerance = Tolerance.Distance)
        {
            return(curve.ControlPoints.IsInPlane(plane, tolerance));
        }
Esempio n. 34
0
    public bool findCurve(leaf leaf,ref branch target, List<branch> listBranch, NurbsCurve curve)
    {
        var Points = curve.Points;
            var rPoints = curve.Points.Reverse().ToList();

            foreach (var branch in listBranch)
            {
                if (branch.crv.Points[0].Location.DistanceTo(Points[0].Location) < 0.0001)
                {
                    if (branch.crv.Points[1].Location.DistanceTo(Points[1].Location) < 0.0001)
                    {
                        target = branch;
                        if (branch.branchType != branch.type.kink)
                        {
                            branch.target = leaf;
                        }
                        else
                        {
                            if (branch.left == null) branch.left = leaf; else branch.right = leaf;
                        }
                        return false;
                    }
                }
                else if (branch.crv.Points[0].Location.DistanceTo(rPoints[0].Location) < 0.0001)
                {
                    if (branch.crv.Points[1].Location.DistanceTo(rPoints[1].Location) < 0.0001)
                    {
                        target = branch;
                        if (branch.branchType != branch.type.kink)
                        {
                            branch.target = leaf;
                        }
                        else
                        {
                            if (branch.left == null) branch.left = leaf; else branch.right = leaf;
                        }
                        return true;
                    }
                }
            }
            ttt++;
            AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "cannot find:"+ttt.ToString());
            listError.Add(curve);
            return false;
    }
Esempio n. 35
0
        /***************************************************/

        public static ICurve Geometry(this NurbsCurve curve)
        {
            return(curve);
        }
Esempio n. 36
0
 public static Commands.Result GetHelix(out Rhino.Geometry.NurbsCurve helix)
 {
   helix = null;
   Rhino.Geometry.NurbsCurve nc = new NurbsCurve();
   IntPtr pCurve = nc.NonConstPointer();
   uint rc = UnsafeNativeMethods.RHC_RhinoGetSpiralHelix(pCurve, false);
   Rhino.Commands.Result cmdRc = (Rhino.Commands.Result)rc;
   if (cmdRc == Rhino.Commands.Result.Success)
     helix = nc;
   return cmdRc;
 }
Esempio n. 37
0
        /***************************************************/

        public static Plane FitPlane(this NurbsCurve curve, double tolerance = Tolerance.Distance)
        {
            return(curve.ControlPoints.FitPlane());
        }
Esempio n. 38
0
    internal static GeometryBase CreateGeometryHelper(IntPtr pGeometry, object parent, int subobject_index)
    {
      if (IntPtr.Zero == pGeometry)
        return null;

      int type = UnsafeNativeMethods.ON_Geometry_GetGeometryType(pGeometry);
      if (type < 0)
        return null;
      GeometryBase rc = null;

      switch (type)
      {
        case idxON_Curve: //1
          rc = new Curve(pGeometry, parent, subobject_index);
          break;
        case idxON_NurbsCurve: //2
          rc = new NurbsCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_PolyCurve: // 3
          rc = new PolyCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_PolylineCurve: //4
          rc = new PolylineCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_ArcCurve: //5
          rc = new ArcCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_LineCurve: //6
          rc = new LineCurve(pGeometry, parent, subobject_index);
          break;
        case idxON_Mesh: //7
          rc = new Mesh(pGeometry, parent);
          break;
        case idxON_Point: //8
          rc = new Point(pGeometry, parent);
          break;
        case idxON_TextDot: //9
          rc = new TextDot(pGeometry, parent);
          break;
        case idxON_Surface: //10
          rc = new Surface(pGeometry, parent);
          break;
        case idxON_Brep: //11
          rc = new Brep(pGeometry, parent);
          break;
        case idxON_NurbsSurface: //12
          rc = new NurbsSurface(pGeometry, parent);
          break;
        case idxON_RevSurface: //13
          rc = new RevSurface(pGeometry, parent);
          break;
        case idxON_PlaneSurface: //14
          rc = new PlaneSurface(pGeometry, parent);
          break;
        case idxON_ClippingPlaneSurface: //15
          rc = new ClippingPlaneSurface(pGeometry, parent);
          break;
        case idxON_Annotation2: // 16
          rc = new AnnotationBase(pGeometry, parent);
          break;
        case idxON_Hatch: // 17
          rc = new Hatch(pGeometry, parent);
          break;
        case idxON_TextEntity2: //18
          rc = new TextEntity(pGeometry, parent);
          break;
        case idxON_SumSurface: //19
          rc = new SumSurface(pGeometry, parent);
          break;
        case idxON_BrepFace: //20
          {
            int faceindex = -1;
            IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref faceindex);
            if (pBrep != IntPtr.Zero && faceindex >= 0)
            {
              Brep b = new Brep(pBrep, parent);
              rc = b.Faces[faceindex];
            }
          }
          break;
        case idxON_BrepEdge: // 21
          {
            int edgeindex = -1;
            IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref edgeindex);
            if (pBrep != IntPtr.Zero && edgeindex >= 0)
            {
              Brep b = new Brep(pBrep, parent);
              rc = b.Edges[edgeindex];
            }
          }
          break;
        case idxON_InstanceDefinition: // 22
          rc = new InstanceDefinitionGeometry(pGeometry, parent);
          break;
        case idxON_InstanceReference: // 23
          rc = new InstanceReferenceGeometry(pGeometry, parent);
          break;
#if USING_V5_SDK
        case idxON_Extrusion: //24
          rc = new Extrusion(pGeometry, parent);
          break;
#endif
        case idxON_LinearDimension2: //25
          rc = new LinearDimension(pGeometry, parent);
          break;
        case idxON_PointCloud: // 26
          rc = new PointCloud(pGeometry, parent);
          break;
        case idxON_DetailView: // 27
          rc = new DetailView(pGeometry, parent);
          break;
        case idxON_AngularDimension2: // 28
          rc = new AngularDimension(pGeometry, parent);
          break;
        case idxON_RadialDimension2: // 29
          rc = new RadialDimension(pGeometry, parent);
          break;
        case idxON_Leader: // 30
          rc = new Leader(pGeometry, parent);
          break;
        case idxON_OrdinateDimension2: // 31
          rc = new OrdinateDimension(pGeometry, parent);
          break;
        case idxON_Light: //32
          rc = new Light(pGeometry, parent);
          break;
        case idxON_PointGrid: //33
          rc = new Point3dGrid(pGeometry, parent);
          break;
        case idxON_MorphControl: //34
          rc = new MorphControl(pGeometry, parent);
          break;
        case idxON_BrepLoop: //35
          {
            int loopindex = -1;
            IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref loopindex);
            if (pBrep != IntPtr.Zero && loopindex >= 0)
            {
              Brep b = new Brep(pBrep, parent);
              rc = b.Loops[loopindex];
            }
          }
          break;
        case idxON_BrepTrim: // 36
          {
            int trimindex = -1;
            IntPtr pBrep = UnsafeNativeMethods.ON_BrepSubItem_Brep(pGeometry, ref trimindex);
            if (pBrep != IntPtr.Zero && trimindex >= 0)
            {
              Brep b = new Brep(pBrep, parent);
              rc = b.Trims[trimindex];
            }
          }
          break;
        default:
          rc = new UnknownGeometry(pGeometry, parent, subobject_index);
          break;
      }

      return rc;
    }
Esempio n. 39
0
 public static NurbsCurve Transform(this NurbsCurve curve, TransformMatrix transform)
 {
     throw new NotImplementedException();
 }
Esempio n. 40
0
        private static NurbsCurve _ZigZagDeformations_TryRemove__by_sorting_controlPoints(NurbsCurve crv, Surface srf, int[] zigzagIndexes, List <ZigZagDiapason> diapasons)
        {
            NurbsCurve res      = null;
            var        points3d = crv._Locations3d();

            // set default all points are valid
            var indexes = new List <int>();

            for (int i = 0; i < points3d.Length; i++)
            {
                indexes.Add(i);
            }

            // clear bad control points
            for (int di = 0; di < diapasons.Count; di++)
            {
                var d = diapasons[di];
                for (int i = d.IndexStart + 1; i < d.IndexEnd; i++)
                {
                    indexes[i] = -1;
                }
            }

            //
            // v1  - just remove - at least we will have some result if v2 fails
            //
            var res1 = _ZigZagDeformations_GetCurveFromPoints(crv, srf, points3d, false, indexes);

            if (res1 != null)
            {
                res = res1;
            }


            //
            // v2  - sort bad control points - try get better result
            //
            for (int di = 0; di < diapasons.Count; di++)
            {
                var d         = diapasons[di];
                var subPoints = new List <Point3d>();
                for (int i = d.IndexStart; i <= d.IndexEnd; i++)
                {
                    subPoints.Add(points3d[i]);
                }
                var subIndexesSorted = _Point3d._Sort(subPoints);
                for (int i = 0; i < d.IndexEnd - d.IndexStart + 1; i++)
                {
                    var index       = d.IndexStart + i;
                    var indexSorted = d.IndexStart + subIndexesSorted[i];
                    indexes[index] = indexSorted;
                }
            }
            var res2 = _ZigZagDeformations_GetCurveFromPoints(crv, srf, points3d, false, indexes);

            if (res2 != null)
            {
                res = res2;
            }



            return(res);
        }
 public NurbsCurve ToNurbsCurve()
 {
     return(NurbsCurve.CreateFromCircle(this));
 }