// general curve
        public static Model3D RhinoToHelixCurve(Rhino.Geometry.Curve curve, double diameter, int resolution, int resolutiontube, System.Windows.Media.Media3D.Material mat)
        {
            int curvedegree = curve.Degree;
            var modelGroup  = new Model3DGroup();

            Console.WriteLine("BS");

            if (curve.IsLinear()) // if line-like curve
            {
                Console.WriteLine("blabla");
                return(RhinoToHelixLine(curve, diameter, resolutiontube, mat));
            }

            else
            {
                var meshBuilder = new MeshBuilder(false, false);

                //Point3d[] pts = new Point3d[resolution];
                List <Point3D> path = new List <Point3D>();
                //curve.DivideByCount(resolution, true, out pts);
                path.Add(RhinoToHelixPoint(curve.PointAtEnd));
                path.Add(RhinoToHelixPoint(curve.PointAtStart));
                //foreach (Point3d pt in pts)
                //{
                //    path.Add(RhinoToHelixPoint(pt));
                //}
                meshBuilder.AddTube(path, diameter, resolutiontube, false);
                var meshHelix = meshBuilder.ToMesh(true);
                modelGroup.Children.Add(new GeometryModel3D {
                    Geometry = meshHelix, Material = mat, BackMaterial = mat
                });
            }
            return(modelGroup);
        }
Beispiel #2
0
        private void SetCurveType(Rg.Curve curve)
        {
            Rg.Circle   R = new Rg.Circle();
            Rg.Arc      A = new Rg.Arc();
            Rg.Ellipse  S = new Rg.Ellipse();
            Rg.Polyline P = new Rg.Polyline();

            if (curve.TryGetCircle(out R))
            {
                curveType = CurveTypes.Circle;
            }
            else if (curve.TryGetArc(out A))
            {
                curveType = CurveTypes.Arc;
            }
            else if (curve.TryGetEllipse(out S))
            {
                curveType = CurveTypes.Ellipse;
            }
            else if (curve.IsLinear())
            {
                curveType = CurveTypes.Line;
            }
            else if (curve.TryGetPolyline(out P))
            {
                curveType = CurveTypes.Polyline;
            }
            else
            {
                curveType = CurveTypes.Spline;
            }
        }
Beispiel #3
0
        /***************************************************/

        public static BHG.ICurve FromRhino(this RHG.Curve rCurve)
        {
            if (rCurve == null)
            {
                return(null);
            }

            Type curveType = rCurve.GetType();

            if (rCurve.IsLinear() && rCurve.SpanCount < 2)
            {
                return(new BHG.Line {
                    Start = rCurve.PointAtStart.FromRhino(), End = rCurve.PointAtEnd.FromRhino(), Infinite = false
                });
            }
            if (rCurve.IsCircle())
            {
                RHG.Circle circle = new RHG.Circle();
                rCurve.TryGetCircle(out circle);
                return(circle.FromRhino());
            }
            else if (rCurve.IsArc() || typeof(RHG.ArcCurve).IsAssignableFrom(curveType))
            {
                RHG.Arc arc = new RHG.Arc();
                rCurve.TryGetArc(out arc);
                return(arc.FromRhino());
            }
            else if (rCurve.IsPolyline() || typeof(RHG.PolylineCurve).IsAssignableFrom(curveType))
            {
                RHG.Polyline polyline = new RHG.Polyline();
                rCurve.TryGetPolyline(out polyline);
                return(polyline.FromRhino());
            }
            else if (rCurve.IsClosed && rCurve.IsEllipse())
            {
                RHG.Ellipse ellipse = new RHG.Ellipse();
                rCurve.TryGetEllipse(out ellipse);
                return(ellipse.FromRhino());
            }
            else if (rCurve is RHG.NurbsCurve)
            {
                return(((RHG.NurbsCurve)rCurve).FromRhino());
            }
            else if (rCurve is RHG.PolyCurve)
            {
                return(((RHG.PolyCurve)rCurve).FromRhino());  //The test of IsPolyline above is very important to make sure we can cast to PolyCurve here
            }
            else
            {
                return((rCurve.ToNurbsCurve()).FromRhino());
            }
        }
 public static IfcBoundedCurve ConvertRhinoCommonCurve(DatabaseIfc db, Curve crv)
 {
     double tol = db.Tolerance, angTol = Math.PI / 1800;
     if (crv.IsLinear(tol))
         return new IfcPolyline(new List<IfcCartesianPoint>() { new IfcCartesianPoint(db, crv.PointAtStart), new IfcCartesianPoint(db, crv.PointAtEnd) });
     Plane pln = new Plane();
     if (crv.TryGetPlane(out pln, tol))
     {
         if (Math.Abs(pln.Origin.Z) < tol && pln.ZAxis.IsParallelTo(Vector3d.ZAxis, angTol) != 0)
             return convCurve(db, crv, true);
     }
     return convCurve(db, crv, false);
 }
Beispiel #5
0
 /// <summary>
 /// Convert a Rhino curve to a Nucleus one
 /// </summary>
 /// <param name="curve"></param>
 /// <returns></returns>
 public static Curve Convert(RC.Curve curve)
 {
     if (curve == null)
     {
         return(null);
     }
     if (curve is RC.LineCurve)
     {
         return(Convert((RC.LineCurve)curve));
     }
     else if (curve.IsLinear())
     {
         return(Convert(new RC.Line(curve.PointAtStart, curve.PointAtEnd)));
     }
     else if (curve.IsPolyline())
     {
         RC.Polyline pLine;
         if (curve.TryGetPolyline(out pLine))
         {
             return(Convert(pLine));
         }
     }
     else if (curve is RC.PolyCurve)
     {
         return(Convert((RC.PolyCurve)curve));
     }
     else if (curve.IsArc())
     {
         RC.Arc arc;
         if (curve.TryGetArc(out arc))
         {
             return(Convert(arc));
         }
     }
     throw new NotImplementedException();
 }
        private LyrebirdCurve GetLBCurve(Curve crv)
        {
            LyrebirdCurve lbc = null;

            List<LyrebirdPoint> points = new List<LyrebirdPoint>();
            if (crv.IsLinear())
            {
                // standard linear element
                points.Add(new LyrebirdPoint(crv.PointAtStart.X, crv.PointAtStart.Y, crv.PointAtStart.Z));
                points.Add(new LyrebirdPoint(crv.PointAtEnd.X, crv.PointAtEnd.Y, crv.PointAtEnd.Z));
                lbc = new LyrebirdCurve(points, "Line");
            }
            else if (crv.IsCircle())
            {
                crv.Domain = new Interval(0, 1);
                points.Add(new LyrebirdPoint(crv.PointAtStart.X, crv.PointAtStart.Y, crv.PointAtStart.Z));
                points.Add(new LyrebirdPoint(crv.PointAt(0.25).X, crv.PointAt(0.25).Y, crv.PointAt(0.25).Z));
                points.Add(new LyrebirdPoint(crv.PointAt(0.5).X, crv.PointAt(0.5).Y, crv.PointAt(0.5).Z));
                points.Add(new LyrebirdPoint(crv.PointAt(0.75).X, crv.PointAt(0.75).Y, crv.PointAt(0.75).Z));
                points.Add(new LyrebirdPoint(crv.PointAtEnd.X, crv.PointAtEnd.Y, crv.PointAtEnd.Z));
                lbc = new LyrebirdCurve(points, "Circle");
            }
            else if (crv.IsArc())
            {
                crv.Domain = new Interval(0, 1);
                // standard arc element
                points.Add(new LyrebirdPoint(crv.PointAtStart.X, crv.PointAtStart.Y, crv.PointAtStart.Z));
                points.Add(new LyrebirdPoint(crv.PointAt(0.5).X, crv.PointAt(0.5).Y, crv.PointAt(0.5).Z));
                points.Add(new LyrebirdPoint(crv.PointAtEnd.X, crv.PointAtEnd.Y, crv.PointAtEnd.Z));
                lbc = new LyrebirdCurve(points, "Arc");
            }
            else
            {
                // Spline
                // Old line: if (crv.Degree >= 3)
                if (crv.Degree == 3)
                {
                    NurbsCurve nc = crv as NurbsCurve;
                    if (nc != null)
                    {
                        List<LyrebirdPoint> lbPoints = new List<LyrebirdPoint>();
                        List<double> weights = new List<double>();
                        List<double> knots = new List<double>();

                        foreach (ControlPoint cp in nc.Points)
                        {
                            LyrebirdPoint pt = new LyrebirdPoint(cp.Location.X, cp.Location.Y, cp.Location.Z);
                            double weight = cp.Weight;
                            lbPoints.Add(pt);
                            weights.Add(weight);
                        }
                        for (int k = 0; k < nc.Knots.Count; k++)
                        {
                            double knot = nc.Knots[k];
                            // Add a duplicate knot for the first and last knot in the Rhino curve.
                            // Revit needs 2 more knots than Rhino to define a spline.
                            if (k == 0 || k == nc.Knots.Count - 1)
                            {
                                knots.Add(knot);
                            }
                            knots.Add(knot);
                        }

                        lbc = new LyrebirdCurve(lbPoints, weights, knots, nc.Degree, nc.IsPeriodic) { CurveType = "Spline" };
                    }
                }
                else
                {
                    const double incr = 1.0 / 100;
                    List<LyrebirdPoint> pts = new List<LyrebirdPoint>();
                    List<double> weights = new List<double>();
                    for (int i = 0; i <= 100; i++)
                    {
                        Point3d pt = crv.PointAtNormalizedLength(i * incr);
                        LyrebirdPoint lbp = new LyrebirdPoint(pt.X, pt.Y, pt.Z);
                        weights.Add(1.0);
                        pts.Add(lbp);
                    }

                    lbc = new LyrebirdCurve(pts, "Spline") { Weights = weights, Degree = crv.Degree };
                }
            }

            return lbc;
        }
Beispiel #7
0
        /***************************************************/
        /**** Private methods                           ****/
        /***************************************************/

        private static void AddBrepTrim(this RHG.Brep brep, RHG.BrepFace face, BHG.SurfaceTrim trim, RHG.BrepLoopType loopType)
        {
            RHG.BrepLoop      loop       = brep.Loops.Add(loopType, face);
            List <BHG.ICurve> subParts3d = trim.Curve3d.ISubParts().ToList();
            List <BHG.ICurve> subParts2d = trim.Curve2d.ISubParts().ToList();

            double rhinoTolerance = Query.DocumentTolerance();

            for (int i = 0; i < subParts3d.Count; i++)
            {
                BHG.ICurve bhc = subParts3d[i];
                RHG.Curve  rhc = bhc.IToRhino();

                int startId = brep.AddVertex(rhc.PointAtStart);
                int endId   = brep.AddVertex(rhc.PointAtEnd);

                RHG.BrepTrim rhTrim;
                RHG.Curve    rhc2d = subParts2d[i].IToRhino();
                rhc2d.ChangeDimension(2);
                int crv2d = brep.Curves2D.Add(rhc2d);
                if (rhc.IsValid)
                {
                    bool         rev3d = true;
                    RHG.BrepEdge edge  = null;
                    foreach (RHG.BrepEdge e in brep.Edges)
                    {
                        if (e.StartVertex.VertexIndex == endId && e.EndVertex.VertexIndex == startId && rhc.IsSameEdge(e))
                        {
                            edge = e;
                            break;
                        }
                    }

                    if (edge == null)
                    {
                        int crv = brep.Curves3D.Add(rhc);
                        edge  = brep.Edges.Add(startId, endId, crv, rhinoTolerance);
                        rev3d = false;
                    }

                    rhTrim = brep.Trims.Add(edge, rev3d, loop, crv2d);
                }
                else
                {
                    rhTrim = brep.Trims.AddSingularTrim(brep.Vertices[startId], loop, RHG.IsoStatus.None, crv2d);
                }

                rhTrim.SetTolerances(rhinoTolerance, rhinoTolerance);

                //TODO: In Rhino 6 this could be replaced with Surface.IsIsoParametric(Curve)
                RHG.Point3d start = rhc2d.PointAtStart;
                RHG.Point3d end   = rhc2d.PointAtEnd;

                if (rhc2d.IsLinear())
                {
                    if (Math.Abs(start.X - end.X) <= rhinoTolerance)
                    {
                        RHG.Interval domainU = brep.Surfaces[face.SurfaceIndex].Domain(0);
                        if (Math.Abs(start.X - domainU.Min) <= rhinoTolerance)
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.West;
                        }
                        else if (Math.Abs(start.X - domainU.Max) <= rhinoTolerance)
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.East;
                        }
                        else
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.X;
                        }
                    }
                    else if (Math.Abs(start.Y - end.Y) <= rhinoTolerance)
                    {
                        RHG.Interval domainV = brep.Surfaces[face.SurfaceIndex].Domain(1);
                        if (Math.Abs(start.Y - domainV.Min) <= rhinoTolerance)
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.South;
                        }
                        else if (Math.Abs(start.Y - domainV.Max) <= rhinoTolerance)
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.North;
                        }
                        else
                        {
                            rhTrim.IsoStatus = RHG.IsoStatus.Y;
                        }
                    }
                }
            }
        }