Esempio n. 1
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;
            }
        }
Esempio n. 2
0
        public List <Brep> ComputeAnchorGeometry()
        {
            Vector3d NormNormalVec = NormalVec / NormalVec.Length;
            Point3d  A             = Origin + NormNormalVec * Height1 / 2;
            Point3d  B             = Origin - NormNormalVec * Height1 / 2;
            Point3d  C             = Origin - NormNormalVec * (Height1 / 2 + Height2);

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

            Rhino.Geometry.Plane planea = new Rhino.Geometry.Plane(A, NormNormalVec);
            Rhino.Geometry.Plane planeb = new Rhino.Geometry.Plane(B, NormNormalVec);
            Rhino.Geometry.Plane planec = new Rhino.Geometry.Plane(C, NormNormalVec);

            Rhino.Geometry.Circle circlea = new Rhino.Geometry.Circle(planea, Radius2);
            Rhino.Geometry.Circle circleb = new Rhino.Geometry.Circle(planeb, Radius1);
            Rhino.Geometry.Circle circlec = new Rhino.Geometry.Circle(planec, Radius2);

            Rhino.Geometry.Cylinder cylindera = new Rhino.Geometry.Cylinder(circlea, Height2);
            Rhino.Geometry.Brep     brepa     = cylindera.ToBrep(true, true);
            displayGeometry.Add(brepa);

            Rhino.Geometry.Cylinder cylinderb = new Rhino.Geometry.Cylinder(circleb, Height1);
            Rhino.Geometry.Brep     brepb     = cylinderb.ToBrep(true, true);
            displayGeometry.Add(brepb);

            Rhino.Geometry.Cylinder cylinderc = new Rhino.Geometry.Cylinder(circlec, Height2);
            Rhino.Geometry.Brep     brepc     = cylinderc.ToBrep(true, true);
            displayGeometry.Add(brepc);

            return(displayGeometry);
        }
Esempio n. 3
0
        public static string ToSVG(this Rg.Circle input)
        {
            Rg.Vector3d axisX = input.Plane.XAxis;
            axisX.Unitize();
            axisX = axisX * input.Radius;

            Rg.Vector3d axisY = input.Plane.YAxis;
            axisY.Unitize();
            axisY = axisY * input.Radius;

            Rg.Point3d A = input.Plane.Origin + axisX;
            Rg.Point3d B = input.Plane.Origin + axisY;

            axisX.Reverse();
            axisY.Reverse();

            Rg.Point3d C = input.Plane.Origin + axisX;
            Rg.Point3d D = input.Plane.Origin + axisY;

            double radians = Rg.Vector3d.VectorAngle(input.Plane.YAxis, Rg.Vector3d.YAxis, Rg.Plane.WorldXY);
            double degrees = 180.0 - (radians / Math.PI) * 180.0;
            int    flip    = Convert.ToInt32(!(Rg.Vector3d.VectorAngle(input.Plane.ZAxis, Rg.Vector3d.ZAxis) > 1));

            return("M " + A.ToSVG()
                   + " A " + input.Radius + ", " + input.Radius + " " + degrees + " 0," + flip + " " + B.ToSVG()
                   + " A " + input.Radius + ", " + input.Radius + " " + degrees + " 0," + flip + " " + C.ToSVG()
                   + " A " + input.Radius + ", " + input.Radius + " " + degrees + " 0," + flip + " " + D.ToSVG()
                   + " A " + input.Radius + ", " + input.Radius + " " + degrees + " 0," + flip + " " + A.ToSVG());
        }
 protected override void OnDynamicDraw(GetPointDrawEventArgs e)
 {
   base.OnDynamicDraw(e);
   var cplane = e.RhinoDoc.Views.ActiveView.ActiveViewport.ConstructionPlane();
   var radius = m_center_point.DistanceTo(e.CurrentPoint);
   var circle = new Circle(cplane, m_center_point, radius);
   e.Display.DrawCircle(circle, System.Drawing.Color.Black);
 }
Esempio n. 5
0
        /// <summary>
        /// Returns a Windows Shapes Path from a Rhinocommon Circle
        /// </summary>
        /// <param name="input">Rhinocommon Circle</param>
        /// <returns>System Windows Shapes Path</returns>
        public static Sh.Path ToPath(this Rg.Circle input)
        {
            Sh.Path path = new Sh.Path();

            path.Data = input.ToGeometry();

            return(path);
        }
Esempio n. 6
0
        private string ShootScene(Point3d loc, int res, double lens)
        {
            // Generate list of point targets in circle around basepoint
            var circ     = new Rhino.Geometry.Circle(loc, 1);
            var circCast = circ.ToNurbsCurve();
            var ptParams = circCast.DivideByCount(res, false);

            // Get the active vpt
            var av = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;

            // Set viewport props
            av.ActiveViewport.Camera35mmLensLength = lens;

            // Create temp directory
            var appdpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            var myPath   = appdpath + @"\aviary\";

            System.IO.Directory.CreateDirectory(myPath);

            // Clear existing in temp directory
            System.IO.DirectoryInfo di = new DirectoryInfo(myPath);
            foreach (FileInfo file in di.GetFiles())
            {
                file.Delete();
            }


            int nameIterator = 0;

            foreach (var par in ptParams)
            {
                // Convert par to target point
                var tar = circCast.PointAt(par);

                // Set the camera
                av.ActiveViewport.SetCameraLocations(tar, loc);

                // Capture the active viewport
                using (Bitmap map = av.CaptureToBitmap(new Size(800, 600)))
                {
                    string outputFileName = myPath + "_" + nameIterator.ToString() + ".jpg";
                    using (MemoryStream memory = new MemoryStream())
                    {
                        using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
                        {
                            map.Save(memory, System.Drawing.Imaging.ImageFormat.Jpeg);
                            byte[] bytes = memory.ToArray();
                            fs.Write(bytes, 0, bytes.Length);
                        }
                    }
                }
                nameIterator++;
            }
            return(myPath);
        }
Esempio n. 7
0
        /***************************************************/

        public static bool IsEqual(this BHG.Circle bhCircle, RHG.Circle rhCircle, double tolerance = BHG.Tolerance.Distance)
        {
            if (bhCircle == null & rhCircle.Equals(default(RHG.Circle)))
            {
                return(true);
            }

            return(bhCircle.Centre.IsEqual(rhCircle.Center, tolerance) &&
                   bhCircle.Normal.IsEqual(rhCircle.Normal, tolerance) &&
                   Math.Abs(bhCircle.Radius - rhCircle.Radius) < tolerance);
        }
Esempio n. 8
0
 public static Rhino.Commands.Result AddCircle(Rhino.RhinoDoc doc)
 {
   Rhino.Geometry.Point3d center = new Rhino.Geometry.Point3d(0, 0, 0);
   const double radius = 10.0;
   Rhino.Geometry.Circle c = new Rhino.Geometry.Circle(center, radius);
   if (doc.Objects.AddCircle(c) != Guid.Empty)
   {
     doc.Views.Redraw();
     return Rhino.Commands.Result.Success;
   }
   return Rhino.Commands.Result.Failure;
 }
Esempio n. 9
0
        /***************************************************/

        public static RHG.Cylinder ToRhino(this BHG.Cylinder cylinder)
        {
            if (cylinder == null)
            {
                return(default(RHG.Cylinder));
            }

            RHG.Plane  plane  = new RHG.Plane(cylinder.Centre.ToRhino(), cylinder.Axis.ToRhino());
            RHG.Circle circle = new RHG.Circle(plane, cylinder.Radius);

            return(new RHG.Cylinder(circle, cylinder.Height));
        }
Esempio n. 10
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());
            }
        }
Esempio n. 11
0
    public static Rhino.Commands.Result AddCircle(Rhino.RhinoDoc doc)
    {
        Rhino.Geometry.Point3d center = new Rhino.Geometry.Point3d(0, 0, 0);
        const double           radius = 10.0;

        Rhino.Geometry.Circle c = new Rhino.Geometry.Circle(center, radius);
        if (doc.Objects.AddCircle(c) != Guid.Empty)
        {
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
Esempio n. 12
0
 /// <summary>
 /// Constructs a new cylinder with a finite height.
 /// </summary>
 /// <param name="baseCircle">Base circle for cylinder.</param>
 /// <param name="height">Height of cylinder (zero for infinite cylinder).</param>
 /// <example>
 /// <code source='examples\vbnet\ex_addcylinder.vb' lang='vbnet'/>
 /// <code source='examples\cs\ex_addcylinder.cs' lang='cs'/>
 /// <code source='examples\py\ex_addcylinder.py' lang='py'/>
 /// </example>
 public Cylinder(Circle baseCircle, double height)
 {
   m_basecircle = baseCircle;
   if (height > 0.0)
   {
     m_height1 = 0.0;
     m_height2 = height;
   }
   else
   {
     m_height1 = height;
     m_height2 = 0.0;
   }
 }
Esempio n. 13
0
        public static string ToSVG(this Hp.Geometry input)
        {
            string path = string.Empty;

            switch (input.CurveType)
            {
            case Geometry.CurveTypes.Arc:
                Rg.Arc arc = new Rg.Arc();
                input.Curve.TryGetArc(out arc);
                path = arc.ToSVG();
                break;

            case Geometry.CurveTypes.Circle:
                Rg.Circle circle = new Rg.Circle();
                input.Curve.TryGetCircle(out circle);
                path = circle.ToSVG();
                break;

            case Geometry.CurveTypes.Ellipse:
                Rg.Ellipse ellipse = new Rg.Ellipse();
                input.Curve.TryGetEllipse(out ellipse);
                path = ellipse.ToSVG();
                break;

            case Geometry.CurveTypes.Line:
                Rg.Line line = new Rg.Line(input.Curve.PointAtStart, input.Curve.PointAtEnd);
                path = line.ToSVG();
                break;

            case Geometry.CurveTypes.Polyline:
                Rg.Polyline polyline = new Rg.Polyline();
                input.Curve.TryGetPolyline(out polyline);
                path = polyline.ToSVG();
                break;

            case Geometry.CurveTypes.Rectangle:
                Rg.Polyline pline = new Rg.Polyline();
                input.Curve.TryGetPolyline(out pline);
                path = pline.ToSVG();
                break;

            default:
                path = input.Curve.ToSVG();
                break;
            }

            return(path);
        }
Esempio n. 14
0
        public static Sm.Geometry ToGeometry(this Geometry input)
        {
            Sm.Geometry geometry = null;
            switch (input.CurveType)
            {
            case Geometry.CurveTypes.Arc:
                Rg.Arc arc = new Rg.Arc();
                input.Curve.TryGetArc(out arc);
                geometry = arc.ToGeometry();
                break;

            case Geometry.CurveTypes.Circle:
                Rg.Circle circle = new Rg.Circle();
                input.Curve.TryGetCircle(out circle);
                geometry = circle.ToGeometry();
                break;

            case Geometry.CurveTypes.Ellipse:
                Rg.Ellipse ellipse = new Rg.Ellipse();
                input.Curve.TryGetEllipse(out ellipse);
                geometry = ellipse.ToGeometry();
                break;

            case Geometry.CurveTypes.Line:
                Rg.Line line = new Rg.Line(input.Curve.PointAtStart, input.Curve.PointAtEnd);
                geometry = line.ToGeometry();
                break;

            case Geometry.CurveTypes.Polyline:
                Rg.Polyline polyline = new Rg.Polyline();
                input.Curve.TryGetPolyline(out polyline);
                geometry = polyline.ToGeometry();
                break;

            case Geometry.CurveTypes.Rectangle:
                Rg.Polyline pline = new Rg.Polyline();
                input.Curve.TryGetPolyline(out pline);
                Rg.Rectangle3d rectangle = new Rg.Rectangle3d(Rg.Plane.WorldXY, pline[0], pline[2]);
                geometry = rectangle.ToGeometry();
                break;

            default:
                geometry = input.Curve.ToGeometry();
                break;
            }
            return(geometry);
        }
Esempio n. 15
0
 public static Rhino.Commands.Result AddCylinder(Rhino.RhinoDoc doc)
 {
   Rhino.Geometry.Point3d center_point = new Rhino.Geometry.Point3d(0, 0, 0);
   Rhino.Geometry.Point3d height_point = new Rhino.Geometry.Point3d(0, 0, 10);
   Rhino.Geometry.Vector3d zaxis = height_point - center_point;
   Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(center_point, zaxis);
   double radius = 5;
   Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, radius);
   Rhino.Geometry.Cylinder cylinder = new Rhino.Geometry.Cylinder(circle, zaxis.Length);
   Rhino.Geometry.Brep brep = cylinder.ToBrep(true, true);
   if (brep != null)
   {
     doc.Objects.AddBrep(brep);
     doc.Views.Redraw();
   }
   return Rhino.Commands.Result.Success;
 }
        public override void InitializeControls(RhinoObject rhObj)
        {
            var rc = false;
              m_control.ClearRadius();

              var circle = new Circle();
              if (null != rhObj)
              {
            rc = GetCircle(rhObj, ref circle);
            if (rc)
              m_control.Radius = circle.Radius;
              }
              else
              {
            var radius = Rhino.RhinoMath.UnsetValue;
            var varies = false;
            foreach (var rh_obj in SelectedObjects)
            {
              if (GetCircle(rh_obj, ref circle))
              {
            if (Rhino.RhinoMath.IsValidDouble(radius))
            {
              if (System.Math.Abs(radius - circle.Radius) > Rhino.RhinoMath.SqrtEpsilon)
              {
                radius = Rhino.RhinoMath.UnsetValue;
                varies = true;
                break;
              }
            }
            else
            {
              radius = circle.Radius;
            }
              }
            }
            if (!varies && Rhino.RhinoMath.IsValidDouble(radius))
            {
              m_control.Radius = radius;
            }
              }
        }
        static System.Xml.XmlElement SvgCircle(Rhino.Geometry.Circle c, System.Xml.XmlDocument doc)
        {
            var elem   = doc.CreateElement("circle");
            var attrib = doc.CreateAttribute("cx");

            attrib.Value = $"{c.Center.X}";
            elem.Attributes.Append(attrib);
            attrib       = doc.CreateAttribute("cy");
            attrib.Value = $"{c.Center.Y}";
            elem.Attributes.Append(attrib);
            attrib       = doc.CreateAttribute("r");
            attrib.Value = $"{c.Radius}";
            elem.Attributes.Append(attrib);
            attrib       = doc.CreateAttribute("fill-opacity");
            attrib.Value = "0";
            elem.Attributes.Append(attrib);
            attrib       = doc.CreateAttribute("stroke");
            attrib.Value = "#000000";
            elem.Attributes.Append(attrib);
            return(elem);
        }
Esempio n. 18
0
        static internal Rhino.Geometry.Curve ToRhino(this Autodesk.Revit.DB.Curve curve)
        {
            switch (curve)
            {
            case Autodesk.Revit.DB.Line line:
                return(line.IsBound ? new Rhino.Geometry.LineCurve(line.GetEndPoint(0).ToRhino(), line.GetEndPoint(1).ToRhino()) : null);

            case Autodesk.Revit.DB.Arc arc:
                var plane = new Rhino.Geometry.Plane(arc.Center.ToRhino(), new Vector3d(arc.XDirection.ToRhino()), new Vector3d(arc.YDirection.ToRhino()));
                var c     = new Rhino.Geometry.Circle(plane, arc.Radius);
                if (arc.IsBound)
                {
                    var a = new Rhino.Geometry.Arc(c, new Interval(arc.GetEndParameter(0), arc.GetEndParameter(1)));
                    return(new Rhino.Geometry.ArcCurve(a));
                }
                else
                {
                    return(new Rhino.Geometry.ArcCurve(c));
                }
            }

            return(null);
        }
Esempio n. 19
0
        public void SetInputs(List <DataTree <ResthopperObject> > values)
        {
            foreach (var tree in values)
            {
                if (!_input.TryGetValue(tree.ParamName, out var inputGroup))
                {
                    continue;
                }

                if (inputGroup.AlreadySet(tree))
                {
                    LogDebug("Skipping input tree... same input");
                    continue;
                }

                inputGroup.CacheTree(tree);

                IGH_ContextualParameter contextualParameter = inputGroup.Param as IGH_ContextualParameter;
                if (contextualParameter != null)
                {
                    switch (ParamTypeName(inputGroup.Param))
                    {
                    case "Number":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            double[] doubles = new double[entree.Value.Count];
                            for (int i = 0; i < doubles.Length; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                doubles[i] = JsonConvert.DeserializeObject <double>(restobj.Data);
                            }
                            contextualParameter.AssignContextualData(doubles);
                            break;
                        }
                    }
                    break;

                    case "Integer":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            int[] integers = new int[entree.Value.Count];
                            for (int i = 0; i < integers.Length; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                integers[i] = JsonConvert.DeserializeObject <int>(restobj.Data);
                            }
                            contextualParameter.AssignContextualData(integers);
                            break;
                        }
                    }
                    break;

                    case "Point":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            Point3d[] points = new Point3d[entree.Value.Count];
                            for (int i = 0; i < entree.Value.Count; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                points[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                            }
                            contextualParameter.AssignContextualData(points);
                            break;
                        }
                    }
                    break;

                    case "Line":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            Line[] lines = new Line[entree.Value.Count];
                            for (int i = 0; i < entree.Value.Count; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                lines[i] = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                            }
                            contextualParameter.AssignContextualData(lines);
                            break;
                        }
                    }
                    break;

                    case "Text":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            string[] strings = new string[entree.Value.Count];
                            for (int i = 0; i < entree.Value.Count; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                strings[i] = restobj.Data.Trim(new char[] { '"' });
                            }
                            contextualParameter.AssignContextualData(strings);
                            break;
                        }
                    }
                    break;

                    case "Geometry":
                    {
                        foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                        {
                            GeometryBase[] geometries = new GeometryBase[entree.Value.Count];
                            for (int i = 0; i < entree.Value.Count; i++)
                            {
                                ResthopperObject restobj = entree.Value[i];
                                var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data);
                                geometries[i] = Rhino.Runtime.CommonObject.FromJSON(dict) as GeometryBase;
                            }
                            contextualParameter.AssignContextualData(geometries);
                            break;
                        }
                    }
                    break;
                    }
                    continue;
                }

                inputGroup.Param.VolatileData.Clear();
                inputGroup.Param.ExpireSolution(false); // mark param as expired but don't recompute just yet!

                if (inputGroup.Param is Param_Point)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj = entree.Value[i];
                            Rhino.Geometry.Point3d rPt     = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                            GH_Point data = new GH_Point(rPt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Vector)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject        restobj  = entree.Value[i];
                            Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data);
                            GH_Vector data = new GH_Vector(rhVector);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Integer)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            int        rhinoInt      = JsonConvert.DeserializeObject <int>(restobj.Data);
                            GH_Integer data          = new GH_Integer(rhinoInt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Number)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_String)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = restobj.Data;
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Line)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Line rhLine  = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                            GH_Line             data    = new GH_Line(rhLine);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Curve)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            GH_Curve         ghCurve;
                            try
                            {
                                Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data);
                                Rhino.Geometry.Curve    c    = new Rhino.Geometry.PolylineCurve(data);
                                ghCurve = new GH_Curve(c);
                            }
                            catch
                            {
                                var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data);
                                var c    = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict);
                                ghCurve = new GH_Curve(c);
                            }
                            inputGroup.Param.AddVolatileData(path, i, ghCurve);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Circle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject      restobj  = entree.Value[i];
                            Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data);
                            GH_Circle             data     = new GH_Circle(rhCircle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Plane)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject     restobj = entree.Value[i];
                            Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data);
                            GH_Plane             data    = new GH_Plane(rhPlane);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Rectangle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject           restobj     = entree.Value[i];
                            Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data);
                            GH_Rectangle data = new GH_Rectangle(rhRectangle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Box)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject   restobj = entree.Value[i];
                            Rhino.Geometry.Box rhBox   = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data);
                            GH_Box             data    = new GH_Box(rhBox);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Surface)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj   = entree.Value[i];
                            Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data);
                            GH_Surface             data      = new GH_Surface(rhSurface);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Brep)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Brep rhBrep  = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data);
                            GH_Brep             data    = new GH_Brep(rhBrep);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Mesh)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Mesh rhMesh  = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data);
                            GH_Mesh             data    = new GH_Mesh(rhMesh);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_NumberSlider)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            bool             boolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                            GH_Boolean       data    = new GH_Boolean(boolean);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_Panel)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }
            }
        }
Esempio n. 20
0
 /// <summary>Constrains the picked point to lie on a circle.</summary>
 /// <param name="circle">A circle to use as constraint.</param>
 /// <returns>true if constraint could be applied.</returns>
 public bool Constrain(Circle circle)
 {
   IntPtr ptr = NonConstPointer();
   return UnsafeNativeMethods.CRhinoGetPoint_Constrain3(ptr, ref circle);
 }
Esempio n. 21
0
 /// <summary>
 /// Initializes a circle from two 3d points and a tangent at the first point.
 /// The start/end of the circle is at point "startPoint".
 /// </summary>
 /// <param name="startPoint">Start point of circle.</param>
 /// <param name="tangentAtP">Tangent vector at start.</param>
 /// <param name="pointOnCircle">Point coincident with desired circle.</param>
 /// <remarks>May create an Invalid circle</remarks>
 public Circle(Point3d startPoint, Vector3d tangentAtP, Point3d pointOnCircle)
   : this()
 {
   if (!UnsafeNativeMethods.ON_Circle_CreatePtVecPt(ref this, startPoint, tangentAtP, pointOnCircle))
   {
     this = new Circle();
   }
 }
Esempio n. 22
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List<DHr> hours = new List<DHr>();
            string alt_key = "solar_altitude";
            Interval alt_ival = new Interval(0, Math.PI / 2);
            string azm_key = "solar_azimuth";
            Interval azm_ival = new Interval(0, Math.PI * 2);
            bool cull_night = true;

            if (DA.GetDataList(0, hours)) {

                this.plot_type = PType.Invalid;
                String p_type_string = "";
                DA.GetData(4, ref p_type_string);
                p_type_string = p_type_string.ToLowerInvariant().Trim();
                if (p_type_string.Contains("stereo")) { this.plot_type = PType.Stereo; }
                if (p_type_string.Contains("ortho")) { this.plot_type = PType.Ortho; }
                if (this.plot_type == PType.Invalid) {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Plot type not recognized. Choose 'Ortho' or 'Stereo'.");
                    return;
                }

                Plane plane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1));
                DA.GetData(1, ref plane);

                Grasshopper.Kernel.Types.UVInterval ival2d = new Grasshopper.Kernel.Types.UVInterval();
                if (!DA.GetData(2, ref ival2d)) {
                    ival2d.U0 = 0.0;
                    ival2d.U1 = 1.0;
                    ival2d.V0 = 0.0;
                    ival2d.V1 = 1.0;
                }
                double radius_gr = 3.0;
                DA.GetData(3, ref radius_gr);

                DA.GetData(5, ref alt_key);
                DA.GetData(6, ref azm_key);
                DA.GetData(7, ref cull_night);

                List<Point3d> points = new List<Point3d>();

                Plane drawPlane = new Plane(plane);

                if (this.plot_type == PType.Ortho) DA.SetData(5, new Rectangle3d(drawPlane, ival2d.U, ival2d.V)); // set the trimming boundary
                if (this.plot_type == PType.Stereo)
                {
                    drawPlane.Origin = new Point3d(plane.Origin.X, plane.Origin.Y + ival2d.V.Mid, plane.Origin.Z);
                    drawPlane.Rotate(-Math.PI / 2, drawPlane.ZAxis);
                    ival2d.V0 = radius_gr; // sets the radius of stereographic plots
                    ival2d.V1 = 0.0;

                    Circle circ = new Circle(drawPlane, Math.Abs(ival2d.V.Length));
                    DA.SetData(5, circ); // set the trimming boundary
                }

                for (int h = 0; h < hours.Count; h++) {
                    double x = 0;
                    double y = 0;
                    switch (this.plot_type) {
                        case PType.Ortho:
                            x = ival2d.U.ParameterAt(azm_ival.NormalizedParameterAt(hours[h].val(azm_key)));
                            y = ival2d.V.ParameterAt(alt_ival.NormalizedParameterAt(hours[h].val(alt_key)));
                            break;

                        case PType.Stereo:
                            double radius = ival2d.V.ParameterAt(alt_ival.NormalizedParameterAt(hours[h].val(alt_key)));
                            double theta = -hours[h].val(azm_key); // reversed theta to ensure clockwise direction
                            x = radius * Math.Cos(theta);
                            y = radius * Math.Sin(theta);
                            break;
                    }
                    Point3d pt = drawPlane.PointAt(x, y);
                    points.Add(pt);
                    hours[h].pos = pt; // TODO: solar plots currently record the point in world space, switch to graph space
                }

                List<Polyline> plines = new List<Polyline>();
                List<Color> colors = new List<Color>();
                for (int h = 0; h < points.Count; h++)
                {
                    List<Point3d> pts = new List<Point3d>();
                    DHr prev_hr; if (h > 0) prev_hr = hours[h - 1]; else prev_hr = hours[hours.Count - 1];
                    DHr this_hr = hours[h];
                    DHr next_hr; if (h < hours.Count - 1) next_hr = hours[h + 1]; else next_hr = hours[0];

                    switch (this.plot_type) {
                        case PType.Ortho:
                            if ((this_hr.hr - 1 == prev_hr.hr) && (this_hr.pos_x > prev_hr.pos_x)) pts.Add(interp(this_hr.pos, prev_hr.pos, 0.5));
                            pts.Add(this_hr.pos);
                            if ((this_hr.hr + 1 == next_hr.hr) && (this_hr.pos_x < next_hr.pos_x)) pts.Add(interp(this_hr.pos, next_hr.pos, 0.5));
                            break;

                        case PType.Stereo:
                            pts.Add(interp(this_hr.pos, prev_hr.pos, 0.5));
                            pts.Add(this_hr.pos);
                            pts.Add(interp(this_hr.pos, next_hr.pos, 0.5));
                            break;
                    }

                    plines.Add(new Polyline(pts));
                    colors.Add(hours[h].color);
                }

                Mesh mesh = CreateColoredMesh(hours, points, plines, cull_night, alt_key);
                mesh.Compact();
                mesh.Weld(0.1);

                if (cull_night) {
                    List<DHr> day_hours = new List<DHr>();
                    List<Point3d> day_points = new List<Point3d>();
                    List<Polyline> day_plines = new List<Polyline>();

                    List<Color> day_colors = new List<Color>();
                    for (int h = 1; h < hours.Count - 1; h++)
                    {
                        if (hour_contains_day(hours, h, alt_key))
                        {
                            day_hours.Add(hours[h]);
                            day_points.Add(points[h]);
                            day_plines.Add(plines[h]);
                            day_colors.Add(colors[h]);
                        }
                    }
                    hours = day_hours;
                    points = day_points;
                    plines = day_plines;
                    colors = day_colors;

                    #region failed attempt to trim mesh
                    //trim mesh
                    /*
                    Plane trimPlane = new Plane(plane);
                    trimPlane.Rotate(Math.PI/2,plane.XAxis);
                    Mesh trimMesh = Mesh.CreateFromPlane(trimPlane, ival2d.U, new Interval(-0.1, 0.1), 10, 10);
                    //Mesh[] result = Mesh.CreateBooleanSplit(new Mesh[] { mesh }, new Mesh[] { trimMesh });
                    Mesh[] result = mesh.Split(trimPlane);
                    if (result.Length == 1) mesh = result[0];
                    else if (result.Length == 2) {
                        Point3d pt = plane.PointAt(0, 1);
                        Point3d p0 = result[0].ClosestPoint(pt);
                        Point3d p1 = result[1].ClosestPoint(pt);

                        if (p0.DistanceTo(pt) < p1.DistanceTo(pt)) mesh = result[0];
                        else mesh = result[1];
                    }
                     */

                    #endregion

                }

                DA.SetDataList(0, new List<DHr>(hours));
                DA.SetDataList(1, points);
                DA.SetDataList(2, plines);
                DA.SetDataList(3, colors);
                DA.SetData(4, mesh);
            }
        }
Esempio n. 23
0
 public PackingCircle(Point3d center, double radius)
 {
     m_circle = new Circle(center, radius);
 }
 /// <summary>
 /// Draw a single circle object.
 /// </summary>
 /// <param name="circle">Circle to draw.</param>
 /// <param name="color">Color to draw with.</param>
 /// <param name="thickness">Thickness (in pixels) of circle.</param>
 public void DrawCircle(Circle circle, System.Drawing.Color color, int thickness)
 {
   int argb = color.ToArgb();
   UnsafeNativeMethods.CRhinoDisplayPipeline_DrawCircle(m_ptr, ref circle, argb, thickness);
 }
Esempio n. 25
0
 /// <summary>
 /// Convert a Rhino circle to a Nucleus one
 /// </summary>
 /// <param name="circle"></param>
 /// <returns></returns>
 public static Circle Convert(RC.Circle circle)
 {
     return(new Circle(circle.Radius, Convert(circle.Plane)));
 }
Esempio n. 26
0
 public Geometry(Rg.Circle circle)
 {
     curveType = CurveTypes.Circle;
     curve     = circle.ToNurbsCurve();
 }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new <see cref="ArcCurve"/> instance,
 /// copying values from a <see cref="Circle"/> and specifying the 
 /// needed parametrization of the arc.
 /// <para>Circle will not be newly cut at these parameterizations.</para>
 /// </summary>
 /// <param name="circle">A circle.</param>
 /// <param name="t0">A new Domain.T0 value.</param>
 /// <param name="t1">A new Domain.T1 value.</param>
 public ArcCurve(Circle circle, double t0, double t1)
 {
   IntPtr ptr = UnsafeNativeMethods.ON_ArcCurve_New5(ref circle, t0, t1);
   ConstructNonConstObject(ptr);
 }
Esempio n. 28
0
    private void GenerateGeo()
    {
        model = new Rhino.FileIO.File3dm();

        int   num      = 10;
        float outerRad = 2f;
        var   curves   = new List <Rhino.Geometry.NurbsCurve>();

        for (int i = 0; i < num; i++)
        {
            var pt      = new Rhino.Geometry.Point3d(0, 0, height / (num - 1) * i);
            var circle  = new Rhino.Geometry.Circle(pt, pipeRad);
            var polygon = Rhino.Geometry.Polyline.CreateInscribedPolygon(circle, segments);
            var curve   = polygon.ToNurbsCurve();
            curve.Rotate(i * Mathf.Deg2Rad * angle, new Rhino.Geometry.Vector3d(0, 0, 1), new Rhino.Geometry.Point3d(0, 0, 0));
            curve.Translate(new Rhino.Geometry.Vector3d(Mathf.Cos(Mathf.Deg2Rad * angle * i), Mathf.Sin(Mathf.Deg2Rad * angle * i), 0) * outerRad);
            curves.Add(curve);
        }

        var breps = BrepCompute.CreateFromLoft(curves, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.Point3d.Unset, Rhino.Geometry.LoftType.Normal, false);

        var meshList = new List <Rhino.Geometry.Mesh>();

        foreach (var brep in breps)
        {
            var brep2 = brep.CapPlanarHoles(0.001);
            // generates two additional breps
            var meshes = MeshCompute.CreateFromBrep(brep2);
            meshList.AddRange(meshes.ToList());

            model.Objects.AddBrep(brep2);
        }

        foreach (var mesh in meshList)
        {
            Mesh meshObj = new Mesh();

            var vertices = new List <Vector3>();
            foreach (var meshVertex in mesh.Vertices)
            {
                var vertex = new Vector3(meshVertex.X, meshVertex.Z, meshVertex.Y);
                vertices.Add(vertex);
            }

            var triangles = new List <int>();
            foreach (var meshFace in mesh.Faces)
            {
                if (meshFace.IsTriangle)
                {
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.B);
                    triangles.Add(meshFace.A);
                }
                else if (meshFace.IsQuad)
                {
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.B);
                    triangles.Add(meshFace.A);
                    triangles.Add(meshFace.D);
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.A);
                }
            }

            var normals = new List <Vector3>();
            foreach (var normal in mesh.Normals)
            {
                normals.Add(new Vector3(normal.X, normal.Z, normal.Y));
            }

            meshObj.vertices  = vertices.ToArray();
            meshObj.triangles = triangles.ToArray();
            meshObj.normals   = normals.ToArray();

            GameObject gb = new GameObject();
            gb.AddComponent <MeshFilter>().mesh       = meshObj;
            gb.AddComponent <MeshRenderer>().material = mat;
        }
    }
Esempio n. 29
0
        private void createModel()
        {
            /*
             * Rhino.Geometry.Point3d origin = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, 0)));
             * Rhino.Geometry.Point3d normalP1 = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, -0.05f)));
             * Rhino.Geometry.Point3d normalP2 = Util.openTkToRhinoPoint(Util.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(0, 0, -1)));
             * Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(normalP2.X - normalP1.X, normalP2.Y - normalP1.Y, normalP2.Z - normalP1.Z);
             * Plane plane = new Plane(origin, normal);
             * float radius = 20;
             * Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(plane, origin, radius);
             * NurbsCurve circleCurve = circle.ToNurbsCurve();
             *
             * //compute transform to follow controllers
             * OpenTK.Matrix4 tansform = mScene.robotToPlatform * mScene.vrToRobot * Util.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx);
             * Transform t = Util.OpenTKToRhinoTransform(tansform);
             * circleCurve.Transform(t);
             * Brep[] shapes = Brep.CreatePlanarBreps(circleCurve);
             * Brep circle_s = shapes[0];
             * Brep circleBrep = circle_s;
             *
             * Guid renderObjId = Util.addSceneNode(ref mScene, circleBrep, ref mesh_m, "circle");
             */


            //offset the point a little bit to make the plane better
            OpenTK.Vector4 controller_p      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -0.05f, 1);
            OpenTK.Vector4 controller_pZ     = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, -1, 1);
            Point3d        controller_pRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_p.X, controller_p.Y, controller_p.Z)));
            Point3d        controller_pZRhin = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_pZ.X, controller_pZ.Y, controller_pZ.Z)));


            //fix the x and y axis of the model Plane
            OpenTK.Vector4 controller_x1      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(1, 0, 0, 1);
            OpenTK.Vector4 controller_y1      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 1, 0, 1);
            Point3d        controller_x1Rhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_x1.X, controller_x1.Y, controller_x1.Z)));
            Point3d        controller_y1Rhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_y1.X, controller_y1.Y, controller_y1.Z)));

            OpenTK.Vector4 controller_o      = UtilOld.getControllerTipPosition(ref mScene, primaryControllerIdx == mScene.leftControllerIdx) * new OpenTK.Vector4(0, 0, 0, 1);
            Point3d        controller_oRhino = UtilOld.openTkToRhinoPoint(UtilOld.vrToPlatformPoint(ref mScene, new OpenTK.Vector3(controller_o.X, controller_o.Y, controller_o.Z)));

            Rhino.Geometry.Vector3d normal = new Rhino.Geometry.Vector3d(controller_pZRhin.X - controller_oRhino.X, controller_pZRhin.Y - controller_oRhino.Y, controller_pZRhin.Z - controller_oRhino.Z);
            normal.Unitize();
            modelPlane = new Plane(controller_oRhino, normal);

            if (shapeType == ShapeType.Circle)
            {
                Rhino.Geometry.Circle circle = new Rhino.Geometry.Circle(modelPlane, controller_oRhino, radius);
                modelcurve = circle.ToNurbsCurve();
            }
            else if (shapeType == ShapeType.Rect)
            {
                Rhino.Geometry.Vector3d xAxis = new Rhino.Geometry.Vector3d(controller_x1Rhino.X - controller_oRhino.X, controller_x1Rhino.Y - controller_oRhino.Y, controller_x1Rhino.Z - controller_oRhino.Z);
                xAxis.Unitize();
                Rhino.Geometry.Vector3d yAxis = new Rhino.Geometry.Vector3d(controller_y1Rhino.X - controller_oRhino.X, controller_y1Rhino.Y - controller_oRhino.Y, controller_y1Rhino.Z - controller_oRhino.Z);
                yAxis.Unitize();

                modelPlane.XAxis = xAxis;
                modelPlane.YAxis = yAxis;

                //Rectangle3d rect = new Rectangle3d(modelPlane, width, height);
                Rectangle3d rect = new Rectangle3d(modelPlane, new Interval(-width / 2, width / 2), new Interval(-height / 2, height / 2));
                modelcurve = rect.ToNurbsCurve();
            }

            if (modelcurve != null)
            {
                Brep[] shapes = Brep.CreatePlanarBreps(modelcurve);
                modelBrep = shapes[0];
                UtilOld.updateSceneNode(ref mScene, modelBrep, ref mesh_m, "3D-" + shapeType.ToString(), ref previewObjSN);
            }
        }
Esempio n. 30
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Curve c = null;

            if (!DA.GetData(0, ref c))
            {
                return;
            }
            double t     = c.GetLength() / 300;
            double check = t;
            bool   fg    = false;

            switch (flag)
            {
            case 1:
                Rhino.Geometry.Arc arcs = new Arc();
                for (int i = 0; i < 301; i++)    //循环300次
                {
                    fg = c.TryGetArc(out arcs, check);
                    if (fg)
                    {
                        DA.SetData(0, arcs);
                        return;
                    }
                    check += t;
                }
                return;

            case 2:
                Rhino.Geometry.Circle circles = new Rhino.Geometry.Circle();
                for (int i = 0; i < 301; i++)    //循环300次
                {
                    fg = c.TryGetCircle(out circles, check);
                    if (fg)
                    {
                        DA.SetData(0, circles);
                        return;
                    }
                    check += t;
                }
                return;

            case 3:
                Rhino.Geometry.Ellipse ellipse = new Ellipse();
                for (int i = 0; i < 301; i++)    //循环300次
                {
                    fg = c.TryGetEllipse(out ellipse, check);
                    if (fg)
                    {
                        DA.SetData(0, ellipse);
                        return;
                    }
                    check += t;
                }
                return;

            case 4:
                double        minseg = c.GetLength() / 400;
                double        maxseg = c.GetLength() / 10;
                PolylineCurve pl     = c.ToPolyline(0, 0, Math.PI, 1, 1, 1, minseg, maxseg, true);
                DA.SetData(0, pl);
                return;
            }
        }
Esempio n. 31
0
 public static Commands.Result GetCircle(out Rhino.Geometry.Circle circle)
 {
   circle = new Circle();
   uint rc = UnsafeNativeMethods.RHC_RhinoGetCircle(ref circle);
   Rhino.Commands.Result cmdRc = (Rhino.Commands.Result)rc;
   if (cmdRc != Rhino.Commands.Result.Success)
     circle = new Circle();
   return cmdRc;
 }
Esempio n. 32
0
 /// <summary>
 /// Transforms this sphere. Note that non-similarity preserving transformations 
 /// cannot be applied to a sphere as that would result in an ellipsoid.
 /// </summary>
 /// <param name="xform">Transformation matrix to apply.</param>
 /// <returns>true on success, false on failure.</returns>
 public bool Transform(Transform xform)
 {
   Circle xc = new Circle(m_plane, m_radius);
   bool rc = xc.Transform(xform);
   if (rc)
   {
     m_plane = xc.m_plane;
     m_radius = xc.m_radius;
   }
   return rc;
 }
Esempio n. 33
0
        protected override void onClickOculusTrigger(ref VREvent_t vrEvent)
        {
            primaryDeviceIndex = vrEvent.trackedDeviceIndex;
            if (currentState != State.READY || targetPRhObjID == Guid.Empty)
            {
                return;
            }

            pointOnObjRef = new ObjRef(targetPRhObjID);
            //chage to only raycasting to the obj where we draw, if not snap to the origin
            if (!(projectP.X == 0 && projectP.Y == 0 && projectP.Z == 0))
            {
                rayCastingObjs.Clear();
                rayCastingObjs.Add(pointOnObjRef);
            }

            //testing
            Vector3 projectPVR = UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(projectP));

            mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, projectPVR)); //not use at the current version, point is VR coordinate
            pointsList.Add(projectP);

            //render edit points in VR
            Geometry.Geometry geo = new Geometry.DrawPointMarker(new Vector3(0, 0, 0));
            Material.Material m   = new Material.SingleColorMaterial(0, 1, 0, 1);
            SceneNode         editPointSN;

            UtilOld.MarkPointVR(ref mScene, projectPVR, ref geo, ref m, out editPointSN);
            pointMarkers.Add(editPointSN);

            //TODO-hide two other design plane
            if (pointMarkers.Count == 1)
            {
                if (pointOnObjRef != null && drawnType == DrawnType.Plane)
                {
                    if (!(projectP.X == 0 && projectP.Y == 0 && projectP.Z == 0))
                    {
                        UtilOld.hideOtherPlanes(ref mScene, pointOnObjRef.Object().Attributes.Name);
                    }
                    computeContourCurve();
                }
                //TODO- how to find the curvePlane on the surface like teapot body, using the normal of first point?
                //do we need to use different ways for patch surface and other generated surface
                else if (pointOnObjRef != null && drawnType == DrawnType.Surface)
                {
                    computeContourCurve();
                }
            }

            if (maxNumPoint == pointMarkers.Count)
            {
                //Assume we always can find a curvePlane sicnce we use a huge tolerance
                NurbsCurve modelcurve = null;
                Brep       modelBrep;
                string     modelName = "";
                if (shapeType == ShapeType.Circle)
                {
                    float  radius = (float)Math.Sqrt(Math.Pow(pointsList[1].X - pointsList[0].X, 2) + Math.Pow(pointsList[1].Y - pointsList[0].Y, 2) + Math.Pow(pointsList[1].Z - pointsList[0].Z, 2));
                    Circle circle = new Rhino.Geometry.Circle(curvePlane, pointsList[0], radius);
                    modelcurve = circle.ToNurbsCurve();
                    modelName  = "Circle";
                }
                else if (shapeType == ShapeType.Rect)
                {
                    Vector3 rectDiagonalV = new Vector3((float)(pointsList[0].X - pointsList[1].X), (float)(pointsList[0].Y - pointsList[1].Y), (float)(pointsList[0].Z - pointsList[1].Z));
                    float   lenDiagonal   = rectDiagonalV.Length;
                    Vector3 rectLeftTop   = new Vector3((float)pointsList[0].X, (float)pointsList[0].Y, (float)pointsList[0].Z) + lenDiagonal * rectDiagonalV.Normalized();
                    Point3d topLeftP      = new Point3d(rectLeftTop.X, rectLeftTop.Y, rectLeftTop.Z);

                    Rectangle3d rect = new Rectangle3d(curvePlane, topLeftP, pointsList[1]);

                    //using top-left cornel and bottom right

                    //Rectangle3d rect = new Rectangle3d(curvePlane, pointsList[0], pointsList[1]);

                    modelcurve = rect.ToNurbsCurve();
                    modelName  = "Rect";
                }

                /*
                 * Brep[] shapes = Brep.CreatePlanarBreps(modelcurve);
                 * modelBrep = shapes[0];
                 * Guid guid = Util.addRhinoObjectSceneNode(ref mScene, ref modelBrep, ref profile_m, modelName, out renderObjSN);
                 */

                //generate new curveOnObj for mvoingPlane cases sicne and move the XYZPlanes to origial positons
                if (drawnType == DrawnType.Plane)
                {
                    Rhino.Geometry.Vector3d newNormal = new Rhino.Geometry.Vector3d();;
                    Point3d newOrigin   = new Point3d();
                    String  planeName   = pointOnObjRef.Object().Attributes.Name;
                    Point3d planeOrigin = pointOnObjRef.Object().Geometry.GetBoundingBox(true).Center;
                    if (planeName.Contains("planeXY"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(0, 0, 1);
                        newOrigin = new Point3d(0, 0, planeOrigin.Z);
                    }
                    else if (planeName.Contains("planeYZ"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(1, 0, 0);
                        newOrigin = new Point3d(planeOrigin.X, 0, 0);
                    }
                    else if (planeName.Contains("planeXZ"))
                    {
                        newNormal = new Rhino.Geometry.Vector3d(0, 1, 0);
                        newOrigin = new Point3d(0, planeOrigin.Y, 0);
                    }

                    Plane        newPlane      = new Plane(newOrigin, newNormal);
                    int          size          = 240;
                    PlaneSurface plane_surface = new PlaneSurface(newPlane, new Interval(-size, size), new Interval(-size, size));
                    Brep         newPlaneBrep  = Brep.CreateFromSurface(plane_surface);

                    Guid newPlaneID = UtilOld.addRhinoObject(ref mScene, ref newPlaneBrep, "MoveP");
                    //might be better to use Replace(), just need to be careful about the referece count
                    pointOnObjRef = null;
                    pointOnObjRef = new ObjRef(newPlaneID);

                    modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), newPlaneID.ToString());
                    modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), newPlane.Origin.ToString());
                    modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), newPlane.Normal.ToString());
                }
                else if (drawnType == DrawnType.Surface)
                {
                    modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), pointOnObjRef.ObjectId.ToString());
                    modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString());
                    modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString());
                }

                mScene.iCurveList.Add(modelcurve);

                //call next interaction in the chain
                afterCurveCount = mScene.iCurveList.Count;
                mScene.pushInteractionFromChain();
                currentState = State.READY;
            }
        }
    // Start is called before the first frame update
    void Start()
    {
        ComputeServer.AuthToken = authToken;

        var model  = new Rhino.FileIO.File3dm();
        var curves = new List <Rhino.Geometry.NurbsCurve>();

        for (int i = 0; i < 20; i++)
        {
            var s  = 10f;
            var pt = new Rhino.Geometry.Point3d(Random.Range(-s, s), Random.Range(-s, s), 0);
            // model.Objects.AddPoint(pt);
            var r      = Random.Range(1f, 3f);
            var circle = new Rhino.Geometry.Circle(pt, r);
            var curve  = circle.ToNurbsCurve();
            curves.Add(curve);
        }

        var unionCrvsC = CurveCompute.CreateBooleanUnion(curves);

        var height     = Random.Range(1f, 5f);
        var extrusions = new List <Rhino.Geometry.Extrusion>();

        foreach (var unionCrvC in unionCrvsC)
        {
            var extrusion = Rhino.Geometry.Extrusion.Create(unionCrvC, height, true);
            model.Objects.AddExtrusion(extrusion);
            extrusions.Add(extrusion);
        }

        var meshList = new List <Rhino.Geometry.Mesh>();

        foreach (var extrusion in extrusions)
        {
            var brep   = extrusion.ToBrep();
            var meshes = MeshCompute.CreateFromBrep(brep);
            meshList.AddRange(meshes.ToList());
        }

        foreach (var mesh in meshList)
        {
            Mesh meshObj = new Mesh();

            var vertices = new List <Vector3>();
            // mesh.RebuildNormals();
            foreach (var meshVertex in mesh.Vertices)
            {
                var vertex = new Vector3(meshVertex.X, meshVertex.Z, meshVertex.Y);
                vertices.Add(vertex);
            }

            var triangles = new List <int>();
            foreach (var meshFace in mesh.Faces)
            {
                if (meshFace.IsTriangle)
                {
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.B);
                    triangles.Add(meshFace.A);
                }
                else if (meshFace.IsQuad)
                {
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.B);
                    triangles.Add(meshFace.A);
                    triangles.Add(meshFace.D);
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.A);
                }
            }


            meshObj.vertices  = vertices.ToArray();
            meshObj.triangles = triangles.ToArray();


            meshObj.RecalculateNormals();

            GameObject gb = new GameObject();
            gb.AddComponent <MeshFilter>().mesh       = meshObj;
            gb.AddComponent <MeshRenderer>().material = mat;
        }


        var path = Application.dataPath + "/../Outputs/model.3dm";

        model.Write(path, 5);
    }
        // compute plate and output polyline
        public void ComputePlates()
        {
            // set up second type of plate
            for (int i = 0; i < oSpringMesh.Vertices.Count; i++)
            {
                Point3d vertexPosition = oSpringMesh.Vertices[i].Position;
                Point3d closeVertice = Point3dList.ClosestPointInList(iClosedPanelPts, vertexPosition);
                if (ICD.Utils.Distance(closeVertice, vertexPosition) < iClosePanelDist)
                    oVertexPanel2[i] = true;
            }

            // attractor thickness
            for (int i = 0; i < oSpringMesh.Vertices.Count; i++)
            {
                Point3d vertexPosition = oSpringMesh.Vertices[i].Position;

                // different thickness
                Point3d closestPt = Point3dList.ClosestPointInList(iAttrThicknessPts, vertexPosition);
                double distValue = ICD.Utils.Distance(vertexPosition, closestPt);

                if (iHeightThickness)  // adding z coordinate as account
                {
                    double k = vertexPosition.Z * 0.125;
                    distValue *= k * iMinThickness + (0.5 - k) * iMaxThickness;
                }
                othickness.Add(distValue);
            }

            // fix the second type plate area thickness
            for (int i = 0; i < oSpringMesh.Vertices.Count; i++)
            {
                Vertex vt = oSpringMesh.Vertices[i];
                //List<int> Neighbours = v.NeighborVertexIndices;
                oInfo += "i = " + i.ToString() + ", value = " + oVertexPanel2[i] + "\n";
                foreach (int n in vt.NeighborVertexIndices)
                {
                    if (oVertexPanel2[n] == true)
                    {
                        oInfo += "n = " + n.ToString() + ", value = " + oVertexPanel2[n] + "\n";
                        oInfo += n.ToString() + " get it \n";
                        double temp = othickness[n];
                        othickness[i] = temp;
                    }
                }
                oInfo += "==============================\n";
            }

            // remap
            double max = othickness.Max();
            double min = othickness.Min();

            // map(value, low1, high1, low2, high2) = > low2 + (value - low1) * (high2 - low2) / (high1 - low1)
            for (int i = 0; i < othickness.Count; i++)
                othickness[i] = iMinThickness + (othickness[i] - min) * (iMaxThickness - iMinThickness) / (max - min);
            // ------------------------- end attractors --------------------------------------------------------------------------

            // test
            foreach (int id in iID)
            {
                Circle c = new Circle(oSpringMesh.Vertices[id].Position, 0.2);
                oDebugList.Add(NurbsCurve.CreateFromCircle(c));
            }

            // create plate using TPI
            DualTPI(false);
            DualTPI(true);
        }
Esempio n. 36
0
 /// <summary>
 /// Try to convert this curve into a circle using RhinoMath.ZeroTolerance.
 /// </summary>
 /// <param name="circle">On success, the Circle will be filled in.</param>
 /// <returns>true if the curve could be converted into a Circle.</returns>
 public bool TryGetCircle(out Circle circle)
 {
   return TryGetCircle(out circle, RhinoMath.ZeroTolerance);
 }
 private bool GetCircle(RhinoObject rhObj, ref Circle circle)
 {
     var rc = false;
       if (null != rhObj)
       {
     var curve_obj = rhObj as CurveObject;
     if (null != curve_obj)
     {
       var arc_curve = curve_obj.CurveGeometry as ArcCurve;
       if (null != arc_curve && arc_curve.IsCompleteCircle)
       {
     circle = new Circle(arc_curve.Arc);
     rc = true;
       }
     }
       }
       return rc;
 }
 /// <summary>
 /// Construct a radial dimension from 3d input
 /// </summary>
 /// <param name="circle"></param>
 /// <param name="arrowTip">3d point on the circle at the dimension arrow tip</param>
 /// <param name="offsetDistance">distance from arrow tip to knee point</param>
 public RadialDimension(Circle circle, Point3d arrowTip, double offsetDistance)
 {
   IntPtr pThis = UnsafeNativeMethods.ON_RadialDimension2_New();
   ConstructNonConstObject(pThis);
   Point3d center = circle.Center;
   Vector3d xAxis = circle.Plane.XAxis;
   Vector3d normal = circle.Normal;
   UnsafeNativeMethods.ON_RadialDimension2_CreateFromPoints(pThis, center, arrowTip, xAxis, normal, offsetDistance);
 }
Esempio n. 39
0
 public bool SetFromCircle(Circle circle)
 {
   IntPtr pThis = NonConstPointer();
   return UnsafeNativeMethods.CRhinoGumball_SetFromCircle(pThis, ref circle);
 }
Esempio n. 40
0
 /// <summary>
 /// Returns a Windows Media Ellipse from a Rhinocommon Circle
 /// </summary>
 /// <param name="input">Rhinocommon Circle</param>
 /// <returns>System Windows Media Circle</returns>
 public static Sm.EllipseGeometry ToGeometry(this Rg.Circle input)
 {
     return(new Sm.EllipseGeometry(input.Center.ToWindowsPoint(), input.Radius, input.Radius));
 }
Esempio n. 41
0
        public void CaculateAm()
        {
            for (int i = 0; i < mesh.Faces.Count; i++)
            {
                int[] f = vs.IndicesFromFace(i);
                Point3d p1 = vs[f[0]];
                Point3d p2 = vs[f[1]];
                Point3d p3 = vs[f[2]];
                Circle circle = new Circle(p1, p2, p3);
                double a = p1.DistanceTo(p2);
                double b = p1.DistanceTo(p3);
                double c = p2.DistanceTo(p3);
                // Print(f.Length.ToString());
                // Print(a.ToString() + "/" + b.ToString() + "/" + c.ToString());
                Point3d ci = new Point3d();
                int sign = 0;
                if (c >= a && c >= b)
                {
                    if ((c * c) < (a * a + b * b))
                    {
                        ci = circle.Center;
                    }
                    else { ci = (p2 + p3) / 2; sign = 1; }
                }
                else if (a >= c && a >= b)
                {
                    if ((a * a) < (c * c + b * b))
                    {
                        ci = circle.Center;
                    }
                    else { ci = (p2 + p1) / 2; sign = 2; }
                }
                else if (b >= a && b >= c)
                {
                    if ((b * b) < (a * a + c * c))
                    {
                        ci = circle.Center;
                    }
                    else { ci = (p1 + p3) / 2; sign = 3; }
                }
                else
                { //Print("error");
                }

                Point3d p1p2 = (p1 + p2) / 2;
                Point3d p1p3 = (p1 + p3) / 2;
                Point3d p2p3 = (p3 + p2) / 2;

                if (sign == 0)
                {
                    ps[f[0]].Am += areaTri(ci, p1, p1p2) + areaTri(ci, p1, p1p3);
                    ps[f[1]].Am += areaTri(ci, p2, p1p2) + areaTri(ci, p2, p2p3);
                    ps[f[2]].Am += areaTri(ci, p3, p1p3) + areaTri(ci, p3, p2p3);
                }
                else if (sign == 1)
                {
                    ps[f[1]].Am += areaTri(ci, p2, p1p2);
                    ps[f[2]].Am += areaTri(ci, p3, p1p3);
                    ps[f[0]].Am += areaTri(ci, p1, p1p2) + areaTri(ci, p1, p1p3);
                }
                else if (sign == 2)
                {
                    ps[f[1]].Am += areaTri(ci, p2, p2p3);
                    ps[f[0]].Am += areaTri(ci, p1, p1p3);
                    ps[f[2]].Am += areaTri(ci, p3, p1p3) + areaTri(ci, p3, p2p3);
                }
                else if (sign == 3)
                {
                    ps[f[0]].Am += areaTri(ci, p1, p1p2);
                    ps[f[2]].Am += areaTri(ci, p3, p2p3);
                    ps[f[1]].Am += areaTri(ci, p2, p1p2) + areaTri(ci, p2, p2p3);
                }
                else
                {// Print("error");
                }
                //////////////////
                ps[f[0]].KG += Vector3d.VectorAngle(p2 - p1, p3 - p1);
                ps[f[1]].KG += Vector3d.VectorAngle(p1 - p2, p3 - p2);
                ps[f[2]].KG += Vector3d.VectorAngle(p2 - p3, p1 - p3);
                /////////////////
            }
            for (int i = 0; i < el.Count; i++)
            {
                int[] f = el.GetConnectedFaces(i);
                if (f.Length == 2)
                {
                    ///////////////
                    int pi1 = el.GetTopologyVertices(i).I;
                    int pi2 = el.GetTopologyVertices(i).J;
                    int pf1 = 0; int pf2 = 0;

                    int[] vi1 = vs.IndicesFromFace(f[0]);
                    for (int j = 0; j < 3; j++)
                    {
                        if (vi1[j] != pi1 && vi1[j] != pi2)
                        {
                            pf1 = vi1[j]; break;
                        }
                    }
                    int[] vi2 = vs.IndicesFromFace(f[1]);
                    for (int j = 0; j < 3; j++)
                    {
                        if (vi2[j] != pi1 && vi2[j] != pi2)
                        {
                            pf2 = vi2[j]; break;
                        }
                    }
                    double ang1 = Vector3d.VectorAngle(vs[pi1] - vs[pf1], vs[pi2] - vs[pf1]);
                    double ang2 = Vector3d.VectorAngle(vs[pi1] - vs[pf2], vs[pi2] - vs[pf2]);
                    if (ang1 == Math.PI / 2) { ang1 = 0; } else { ang1 = 1 / Math.Tan(ang1); }
                    if (ang2 == Math.PI / 2) { ang2 = 0; } else { ang2 = 1 / Math.Tan(ang2); }
                    double total = ang1 + ang2;
                    double t1 = Vector3d.Multiply(ps[pi1].n, (vs[pi1] - vs[pi2]));
                    double t2 = Vector3d.Multiply(ps[pi2].n, (vs[pi2] - vs[pi1]));
                    ps[pi1].KH += t1 * total;
                    ps[pi2].KH += t2 * total;
                    ////////////////
                }
            }
        }
Esempio n. 42
0
 private void setoutPutData(int i3, string p, IGH_DataAccess DA)
 {
     //Rhino.Geometry.NurbsSurface.CreateFromCorners()
     //Line input
     if (matchLine.Match(p).Value != "")
     {
         if (p.Contains(@")', 'gCPy.Line("))
         {
             p = p.Replace("'gCPy.Line(", "'(").Replace("'", "").Replace("[", "").Replace("]", "").Replace("(", "").Replace("),", "#").Replace(")", "");
             string[] lines = p.Split('#');
             List <Rhino.Geometry.Line> lns = new List <Rhino.Geometry.Line>();
             for (int i = 0; i < lines.Length; i++)
             {
                 var thisL = lines[i].Split(',');
                 Rhino.Geometry.Line lx = new Rhino.Geometry.Line(double.Parse(thisL[0].Trim()),
                                                                  double.Parse(thisL[1].Trim()),
                                                                  double.Parse(thisL[2].Trim()),
                                                                  double.Parse(thisL[3].Trim()),
                                                                  double.Parse(thisL[4].Trim()),
                                                                  double.Parse(thisL[5].Trim()));
                 lns.Add(lx);
             }
             DA.SetDataList(i3, lns);
         }
         // Single Point input
         else
         {
             var  numbers = matchLine.Match(p).Value.Split(',');
             Line lx      = new Line(double.Parse(numbers[0]), double.Parse(numbers[1]), double.Parse(numbers[2]),
                                     double.Parse(numbers[3]), double.Parse(numbers[4]), double.Parse(numbers[5]));
             DA.SetData(i3, lx);
         }
     }
     //Point input
     else if (matchPoint.Match(p).Value != "")
     {
         // Point List input
         if (p.Contains(@")', 'gCPy.Point("))
         {
             p = p.Replace("'gCPy.Point(", "'(").Replace("'", "").Replace("[", "").Replace("]", "").Replace("(", "").Replace("),", "#").Replace(")", "");
             string[] points = p.Split('#');
             List <Rhino.Geometry.Point3d> pts = new List <Rhino.Geometry.Point3d>();
             for (int i = 0; i < points.Length; i++)
             {
                 var thisP = points[i].Split(',');
                 Rhino.Geometry.Point3d px = new Rhino.Geometry.Point3d(new Point3d(double.Parse(thisP[0].Trim()), double.Parse(thisP[1].Trim()), double.Parse(thisP[2].Trim())));
                 pts.Add(px);
             }
             DA.SetDataList(i3, pts);
         }
         // Single Point input
         else
         {
             var numbers             = matchPoint.Match(p).Value.Split(',');
             Rhino.Geometry.Point px = new Rhino.Geometry.Point(new Point3d(double.Parse(numbers[0]), double.Parse(numbers[1]), double.Parse(numbers[2])));
             DA.SetData(i3, px);
         }
     }
     else if (matchCircle.Match(p).Value != "")
     {
         var numbers             = matchCircle.Match(p).Value.Split(',');
         Rhino.Geometry.Plane pl = new Plane(new Point3d(double.Parse(numbers[0]), double.Parse(numbers[1]), double.Parse(numbers[2])),
                                             new Vector3d(double.Parse(numbers[4]), double.Parse(numbers[5]), double.Parse(numbers[6])),
                                             new Vector3d(double.Parse(numbers[7]), double.Parse(numbers[8]), double.Parse(numbers[9])));
         Rhino.Geometry.Circle cx = new Rhino.Geometry.Circle(pl, double.Parse(numbers[3]));
         DA.SetData(i3, cx);
     }
     else if (matchSurface.Match(p).Value != "")
     {
         var          numbers = matchSurface.Match(p).Value.Split(',');
         NurbsSurface srf     = NurbsSurface.CreateFromCorners(new Point3d(double.Parse(numbers[0]), double.Parse(numbers[1]), double.Parse(numbers[2])),
                                                               new Point3d(double.Parse(numbers[3]), double.Parse(numbers[4]), double.Parse(numbers[5])),
                                                               new Point3d(double.Parse(numbers[6]), double.Parse(numbers[7]), double.Parse(numbers[8])),
                                                               new Point3d(double.Parse(numbers[9]), double.Parse(numbers[10]), double.Parse(numbers[11])));
         DA.SetData(i3, srf);
     }
     else
     {
         DA.SetData(i3, p);
     }
 }
Esempio n. 43
0
 /// <summary>
 /// Initializes a new <see cref="ArcCurve"/> instance,
 /// copying the shape of a <see cref="Circle"/>.
 /// <para>Parameterization will be [0;circle.Circumference]</para>
 /// </summary>
 /// <param name="circle">The original circle.</param>
 public ArcCurve(Circle circle)
 {
   IntPtr ptr = UnsafeNativeMethods.ON_ArcCurve_New4(ref circle);
   ConstructNonConstObject(ptr);
 }
Esempio n. 44
0
        /***************************************************/

        public static void RenderRhinoWires(RHG.Circle circle, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness)
        {
            pipeline.DrawCircle(circle, bhColour, thickness);
        }
Esempio n. 45
0
    // If m_height1 == m_height2, the cylinder is infinite,
    // Otherwise, m_height1 < m_height2 and the center of
    // the "bottom" cap is 
    //   m_basecircle.plane.origin + m_height1*m_basecircle.plane.zaxis,
    // and the center of the top cap is 
    //   m_basecircle.plane.origin + m_height2*m_basecircle.plane.zaxis.

    /// <summary>
    /// Constructs a new cylinder with infinite height.
    /// </summary>
    /// <param name="baseCircle">Base circle for infinite cylinder.</param>
    public Cylinder(Circle baseCircle)
    {
      m_basecircle = baseCircle;
      m_height1 = 0.0;
      m_height2 = 0.0;
    }
 /// <summary>
 /// Adds a new, colored arc to the display list.
 /// </summary>
 /// <param name="circle">Circle to add.</param>
 /// <param name="color">Color of circle.</param>
 public void AddCircle(Circle circle, Color color)
 {
   if (m_disposed) { throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified"); }
   AddCircle(circle, color, 1);
 }
        public void SetInputs(List <DataTree <ResthopperObject> > values)
        {
            foreach (var tree in values)
            {
                if (!_input.TryGetValue(tree.ParamName, out var inputGroup))
                {
                    continue;
                }

                if (inputGroup.AlreadySet(tree))
                {
                    Console.WriteLine("Skipping input tree... same input");
                    continue;
                }

                inputGroup.CacheTree(tree);
                inputGroup.Param.VolatileData.Clear();
                inputGroup.Param.ExpireSolution(true);

                if (inputGroup.Param is Param_Point)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj = entree.Value[i];
                            Rhino.Geometry.Point3d rPt     = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                            GH_Point data = new GH_Point(rPt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Vector)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject        restobj  = entree.Value[i];
                            Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data);
                            GH_Vector data = new GH_Vector(rhVector);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Integer)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            int        rhinoInt      = JsonConvert.DeserializeObject <int>(restobj.Data);
                            GH_Integer data          = new GH_Integer(rhinoInt);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Number)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_String)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = restobj.Data;
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Line)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Line rhLine  = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                            GH_Line             data    = new GH_Line(rhLine);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Curve)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            GH_Curve         ghCurve;
                            try
                            {
                                Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data);
                                Rhino.Geometry.Curve    c    = new Rhino.Geometry.PolylineCurve(data);
                                ghCurve = new GH_Curve(c);
                            }
                            catch
                            {
                                var dict = JsonConvert.DeserializeObject <Dictionary <string, string> >(restobj.Data);
                                var c    = (Rhino.Geometry.Curve)Rhino.Runtime.CommonObject.FromJSON(dict);
                                ghCurve = new GH_Curve(c);
                            }
                            inputGroup.Param.AddVolatileData(path, i, ghCurve);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Circle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject      restobj  = entree.Value[i];
                            Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data);
                            GH_Circle             data     = new GH_Circle(rhCircle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Plane)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject     restobj = entree.Value[i];
                            Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data);
                            GH_Plane             data    = new GH_Plane(rhPlane);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Rectangle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject           restobj     = entree.Value[i];
                            Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data);
                            GH_Rectangle data = new GH_Rectangle(rhRectangle);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Box)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject   restobj = entree.Value[i];
                            Rhino.Geometry.Box rhBox   = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data);
                            GH_Box             data    = new GH_Box(rhBox);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Surface)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject       restobj   = entree.Value[i];
                            Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data);
                            GH_Surface             data      = new GH_Surface(rhSurface);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Brep)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Brep rhBrep  = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data);
                            GH_Brep             data    = new GH_Brep(rhBrep);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Mesh)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject    restobj = entree.Value[i];
                            Rhino.Geometry.Mesh rhMesh  = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data);
                            GH_Mesh             data    = new GH_Mesh(rhMesh);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_NumberSlider)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                            GH_Number        data     = new GH_Number(rhNumber);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is Param_Boolean || inputGroup.Param is GH_BooleanToggle)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj = entree.Value[i];
                            bool             boolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                            GH_Boolean       data    = new GH_Boolean(boolean);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }

                if (inputGroup.Param is GH_Panel)
                {
                    foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                    {
                        GH_Path path = new GH_Path(GhPath.FromString(entree.Key));
                        for (int i = 0; i < entree.Value.Count; i++)
                        {
                            ResthopperObject restobj  = entree.Value[i];
                            string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                            GH_String        data     = new GH_String(rhString);
                            inputGroup.Param.AddVolatileData(path, i, data);
                        }
                    }
                    continue;
                }
            }
        }
    /// <summary>
    /// Adds a new, colored circle to the display list.
    /// </summary>
    /// <param name="circle">Circle to add.</param>
    /// <param name="color">Color of circle.</param>
    /// <param name="thickness">Thickness of circle.</param>
    public void AddCircle(Circle circle, Color color, int thickness)
    {
      if (m_disposed) { throw new ObjectDisposedException("This CustomDisplay instance has been disposed and cannot be modified"); }
      if (!circle.IsValid) { return; }

      AddArc(new Arc(circle, 2.0 * Math.PI), color, thickness);
    }
Esempio n. 49
0
    /// <summary>
    /// Try to convert this curve into a Circle using a custom tolerance.
    /// </summary>
    /// <param name="circle">On success, the Circle will be filled in.</param>
    /// <param name="tolerance">Tolerance to use when checking.</param>
    /// <returns>true if the curve could be converted into a Circle within tolerance.</returns>
    /// <example>
    /// <code source='examples\vbnet\ex_circlecenter.vb' lang='vbnet'/>
    /// <code source='examples\cs\ex_circlecenter.cs' lang='cs'/>
    /// <code source='examples\py\ex_circlecenter.py' lang='py'/>
    /// </example>
    public bool TryGetCircle(out Circle circle, double tolerance)
    {
      circle = new Circle();

      Arc arc;
      if (TryGetArc(out arc, tolerance))
      {
        if (arc.IsCircle)
        {
          circle = new Circle(arc);
          return true;
        }
      }
      return false;
    }
        public static Response Grasshopper(NancyContext ctx)
        {
            // load grasshopper file
            var archive = new GH_Archive();
            // TODO: stream to string
            var body = ctx.Request.Body.ToString();

            string json = string.Empty;

            using (var reader = new StreamReader(ctx.Request.Body))
            {
                json = reader.ReadToEnd();
            }

            //GrasshopperInput input = Newtonsoft.Json.JsonConvert.DeserializeObject<GrasshopperInput>(json);
            //JsonSerializerSettings settings = new JsonSerializerSettings();
            //settings.ContractResolver = new DictionaryAsArrayResolver();
            Schema input = JsonConvert.DeserializeObject <Schema>(json);

            string grasshopperXml = string.Empty;

            if (input.Algo != null)
            {
                // If request contains markup
                byte[] byteArray = Convert.FromBase64String(input.Algo);
                grasshopperXml = System.Text.Encoding.UTF8.GetString(byteArray);
            }
            else
            {
                // If request contains pointer
                string pointer = input.Pointer;
                grasshopperXml = GetGhxFromPointer(pointer);
            }
            if (!archive.Deserialize_Xml(grasshopperXml))
            {
                throw new Exception();
            }

            var definition = new GH_Document();

            if (!archive.ExtractObject(definition, "Definition"))
            {
                throw new Exception();
            }

            // Set input params
            foreach (var obj in definition.Objects)
            {
                var group = obj as GH_Group;
                if (group == null)
                {
                    continue;
                }

                if (group.NickName.Contains("RH_IN"))
                {
                    // It is a RestHopper input group!
                    GHTypeCodes code  = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]);
                    var         param = group.Objects()[0];
                    //GH_Param<IGH_Goo> goo = obj as GH_Param<IGH_Goo>;

                    // SetData
                    foreach (Resthopper.IO.DataTree <ResthopperObject> tree in input.Values)
                    {
                        string paramname = tree.ParamName;
                        if (group.NickName == paramname)
                        {
                            switch (code)
                            {
                            case GHTypeCodes.Boolean:
                                //PopulateParam<GH_Boolean>(goo, tree);
                                Param_Boolean boolParam = param as Param_Boolean;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path           path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Boolean> objectList = new List <GH_Boolean>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj = entree.Value[i];
                                        bool             boolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                                        GH_Boolean       data    = new GH_Boolean(boolean);
                                        boolParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Point:
                                //PopulateParam<GH_Point>(goo, tree);
                                Param_Point ptParam = param as Param_Point;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path         path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Point> objectList = new List <GH_Point>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject       restobj = entree.Value[i];
                                        Rhino.Geometry.Point3d rPt     = JsonConvert.DeserializeObject <Rhino.Geometry.Point3d>(restobj.Data);
                                        GH_Point data = new GH_Point(rPt);
                                        ptParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Vector:
                                //PopulateParam<GH_Vector>(goo, tree);
                                Param_Vector vectorParam = param as Param_Vector;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Vector> objectList = new List <GH_Vector>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject        restobj  = entree.Value[i];
                                        Rhino.Geometry.Vector3d rhVector = JsonConvert.DeserializeObject <Rhino.Geometry.Vector3d>(restobj.Data);
                                        GH_Vector data = new GH_Vector(rhVector);
                                        vectorParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Integer:
                                //PopulateParam<GH_Integer>(goo, tree);
                                Param_Integer integerParam = param as Param_Integer;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path           path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Integer> objectList = new List <GH_Integer>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj = entree.Value[i];
                                        int        rhinoInt      = JsonConvert.DeserializeObject <int>(restobj.Data);
                                        GH_Integer data          = new GH_Integer(rhinoInt);
                                        integerParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Number:
                                //PopulateParam<GH_Number>(goo, tree);
                                Param_Number numberParam = param as Param_Number;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Number> objectList = new List <GH_Number>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj  = entree.Value[i];
                                        double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                                        GH_Number        data     = new GH_Number(rhNumber);
                                        numberParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Text:
                                //PopulateParam<GH_String>(goo, tree);
                                Param_String stringParam = param as Param_String;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_String> objectList = new List <GH_String>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj  = entree.Value[i];
                                        string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                                        GH_String        data     = new GH_String(rhString);
                                        stringParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Line:
                                //PopulateParam<GH_Line>(goo, tree);
                                Param_Line lineParam = param as Param_Line;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path        path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Line> objectList = new List <GH_Line>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject    restobj = entree.Value[i];
                                        Rhino.Geometry.Line rhLine  = JsonConvert.DeserializeObject <Rhino.Geometry.Line>(restobj.Data);
                                        GH_Line             data    = new GH_Line(rhLine);
                                        lineParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Curve:
                                //PopulateParam<GH_Curve>(goo, tree);
                                Param_Curve curveParam = param as Param_Curve;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path         path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Curve> objectList = new List <GH_Curve>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj = entree.Value[i];
                                        GH_Curve         ghCurve;
                                        try
                                        {
                                            Rhino.Geometry.Polyline data = JsonConvert.DeserializeObject <Rhino.Geometry.Polyline>(restobj.Data);
                                            Rhino.Geometry.Curve    c    = new Rhino.Geometry.PolylineCurve(data);
                                            ghCurve = new GH_Curve(c);
                                        }
                                        catch
                                        {
                                            Rhino.Geometry.NurbsCurve data = JsonConvert.DeserializeObject <Rhino.Geometry.NurbsCurve>(restobj.Data);
                                            Rhino.Geometry.Curve      c    = new Rhino.Geometry.NurbsCurve(data);
                                            ghCurve = new GH_Curve(c);
                                        }
                                        curveParam.AddVolatileData(path, i, ghCurve);
                                    }
                                }
                                break;

                            case GHTypeCodes.Circle:
                                //PopulateParam<GH_Circle>(goo, tree);
                                Param_Circle circleParam = param as Param_Circle;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Circle> objectList = new List <GH_Circle>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject      restobj  = entree.Value[i];
                                        Rhino.Geometry.Circle rhCircle = JsonConvert.DeserializeObject <Rhino.Geometry.Circle>(restobj.Data);
                                        GH_Circle             data     = new GH_Circle(rhCircle);
                                        circleParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.PLane:
                                //PopulateParam<GH_Plane>(goo, tree);
                                Param_Plane planeParam = param as Param_Plane;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path         path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Plane> objectList = new List <GH_Plane>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject     restobj = entree.Value[i];
                                        Rhino.Geometry.Plane rhPlane = JsonConvert.DeserializeObject <Rhino.Geometry.Plane>(restobj.Data);
                                        GH_Plane             data    = new GH_Plane(rhPlane);
                                        planeParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Rectangle:
                                //PopulateParam<GH_Rectangle>(goo, tree);
                                Param_Rectangle rectangleParam = param as Param_Rectangle;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path             path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Rectangle> objectList = new List <GH_Rectangle>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject           restobj     = entree.Value[i];
                                        Rhino.Geometry.Rectangle3d rhRectangle = JsonConvert.DeserializeObject <Rhino.Geometry.Rectangle3d>(restobj.Data);
                                        GH_Rectangle data = new GH_Rectangle(rhRectangle);
                                        rectangleParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Box:
                                //PopulateParam<GH_Box>(goo, tree);
                                Param_Box boxParam = param as Param_Box;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path       path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Box> objectList = new List <GH_Box>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject   restobj = entree.Value[i];
                                        Rhino.Geometry.Box rhBox   = JsonConvert.DeserializeObject <Rhino.Geometry.Box>(restobj.Data);
                                        GH_Box             data    = new GH_Box(rhBox);
                                        boxParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Surface:
                                //PopulateParam<GH_Surface>(goo, tree);
                                Param_Surface surfaceParam = param as Param_Surface;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path           path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Surface> objectList = new List <GH_Surface>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject       restobj   = entree.Value[i];
                                        Rhino.Geometry.Surface rhSurface = JsonConvert.DeserializeObject <Rhino.Geometry.Surface>(restobj.Data);
                                        GH_Surface             data      = new GH_Surface(rhSurface);
                                        surfaceParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Brep:
                                //PopulateParam<GH_Brep>(goo, tree);
                                Param_Brep brepParam = param as Param_Brep;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path        path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Brep> objectList = new List <GH_Brep>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject    restobj = entree.Value[i];
                                        Rhino.Geometry.Brep rhBrep  = JsonConvert.DeserializeObject <Rhino.Geometry.Brep>(restobj.Data);
                                        GH_Brep             data    = new GH_Brep(rhBrep);
                                        brepParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Mesh:
                                //PopulateParam<GH_Mesh>(goo, tree);
                                Param_Mesh meshParam = param as Param_Mesh;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path        path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Mesh> objectList = new List <GH_Mesh>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject    restobj = entree.Value[i];
                                        Rhino.Geometry.Mesh rhMesh  = JsonConvert.DeserializeObject <Rhino.Geometry.Mesh>(restobj.Data);
                                        GH_Mesh             data    = new GH_Mesh(rhMesh);
                                        meshParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Slider:
                                //PopulateParam<GH_Number>(goo, tree);
                                GH_NumberSlider sliderParam = param as GH_NumberSlider;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path          path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Number> objectList = new List <GH_Number>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj  = entree.Value[i];
                                        double           rhNumber = JsonConvert.DeserializeObject <double>(restobj.Data);
                                        GH_Number        data     = new GH_Number(rhNumber);
                                        sliderParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.BooleanToggle:
                                //PopulateParam<GH_Boolean>(goo, tree);
                                GH_BooleanToggle toggleParam = param as GH_BooleanToggle;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path           path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Boolean> objectList = new List <GH_Boolean>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj   = entree.Value[i];
                                        bool             rhBoolean = JsonConvert.DeserializeObject <bool>(restobj.Data);
                                        GH_Boolean       data      = new GH_Boolean(rhBoolean);
                                        toggleParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;

                            case GHTypeCodes.Panel:
                                //PopulateParam<GH_String>(goo, tree);
                                GH_Panel panelParam = param as GH_Panel;
                                foreach (KeyValuePair <string, List <ResthopperObject> > entree in tree)
                                {
                                    GH_Path         path       = new GH_Path(GhPath.FromString(entree.Key));
                                    List <GH_Panel> objectList = new List <GH_Panel>();
                                    for (int i = 0; i < entree.Value.Count; i++)
                                    {
                                        ResthopperObject restobj  = entree.Value[i];
                                        string           rhString = JsonConvert.DeserializeObject <string>(restobj.Data);
                                        GH_String        data     = new GH_String(rhString);
                                        panelParam.AddVolatileData(path, i, data);
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }

            Schema OutputSchema = new Schema();

            OutputSchema.Algo = Utils.Base64Encode(string.Empty);

            // Parse output params
            foreach (var obj in definition.Objects)
            {
                var group = obj as GH_Group;
                if (group == null)
                {
                    continue;
                }

                if (group.NickName.Contains("RH_OUT"))
                {
                    // It is a RestHopper output group!
                    GHTypeCodes code  = (GHTypeCodes)Int32.Parse(group.NickName.Split(':')[1]);
                    var         param = group.Objects()[0] as IGH_Param;
                    if (param == null)
                    {
                        continue;
                    }

                    try
                    {
                        param.CollectData();
                        param.ComputeData();
                    }
                    catch (Exception)
                    {
                        param.Phase = GH_SolutionPhase.Failed;
                        // TODO: throw something better
                        throw;
                    }

                    // Get data
                    Resthopper.IO.DataTree <ResthopperObject> OutputTree = new Resthopper.IO.DataTree <ResthopperObject>();
                    OutputTree.ParamName = group.NickName;

                    var volatileData = param.VolatileData;
                    for (int p = 0; p < volatileData.PathCount; p++)
                    {
                        List <ResthopperObject> ResthopperObjectList = new List <ResthopperObject>();
                        foreach (var goo in volatileData.get_Branch(p))
                        {
                            if (goo == null)
                            {
                                continue;
                            }
                            else if (goo.GetType() == typeof(GH_Boolean))
                            {
                                GH_Boolean ghValue = goo as GH_Boolean;
                                bool       rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <bool>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Point))
                            {
                                GH_Point ghValue = goo as GH_Point;
                                Point3d  rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Point3d>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Vector))
                            {
                                GH_Vector ghValue = goo as GH_Vector;
                                Vector3d  rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Vector3d>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Integer))
                            {
                                GH_Integer ghValue = goo as GH_Integer;
                                int        rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <int>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Number))
                            {
                                GH_Number ghValue = goo as GH_Number;
                                double    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <double>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_String))
                            {
                                GH_String ghValue = goo as GH_String;
                                string    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <string>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Line))
                            {
                                GH_Line ghValue = goo as GH_Line;
                                Line    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Line>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Curve))
                            {
                                GH_Curve ghValue = goo as GH_Curve;
                                Curve    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Curve>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Circle))
                            {
                                GH_Circle ghValue = goo as GH_Circle;
                                Circle    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Circle>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Plane))
                            {
                                GH_Plane ghValue = goo as GH_Plane;
                                Plane    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Plane>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Rectangle))
                            {
                                GH_Rectangle ghValue = goo as GH_Rectangle;
                                Rectangle3d  rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Rectangle3d>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Box))
                            {
                                GH_Box ghValue = goo as GH_Box;
                                Box    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Box>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Surface))
                            {
                                GH_Surface ghValue = goo as GH_Surface;
                                Brep       rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Brep))
                            {
                                GH_Brep ghValue = goo as GH_Brep;
                                Brep    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Brep>(rhValue));
                            }
                            else if (goo.GetType() == typeof(GH_Mesh))
                            {
                                GH_Mesh ghValue = goo as GH_Mesh;
                                Mesh    rhValue = ghValue.Value;
                                ResthopperObjectList.Add(GetResthopperObject <Mesh>(rhValue));
                            }
                        }

                        GhPath path = new GhPath(new int[] { p });
                        OutputTree.Add(path.ToString(), ResthopperObjectList);
                    }

                    OutputSchema.Values.Add(OutputTree);
                }
            }


            if (OutputSchema.Values.Count < 1)
            {
                throw new System.Exceptions.PayAttentionException("Looks like you've missed something..."); // TODO
            }
            string returnJson = JsonConvert.SerializeObject(OutputSchema);

            return(returnJson);
        }
Esempio n. 51
0
 public Mesh MeshTorus(Circle c, double t)
 {
     double cut = 64;
     List<Polyline> ls2 = new List<Polyline>();
     for (int i = 0; i < cut; i++)
     {
         List<Point3d> ls = new List<Point3d>();
         ls.Add(new Point3d(1, 0, 0));
         ls.Add(new Point3d(0.707, 0, 0.707));
         ls.Add(new Point3d(0, 0, 1));
         ls.Add(new Point3d(-0.707, 0, 0.707));
         ls.Add(new Point3d(-1, 0, 0));
         ls.Add(new Point3d(-0.707, 0, -0.707));
         ls.Add(new Point3d(0, 0, -1));
         ls.Add(new Point3d(0.707, 0, -0.707));
         Polyline l1 = new Polyline();
         l1.AddRange(ls);
         l1.Reverse();
         l1.Transform(Transform.Scale(Point3d.Origin, t));
         //l1.Transform(Transform.Translation(new Vector3d(c.Radius - t, 0, 0)));
         l1.Transform(Transform.Translation(new Vector3d(c.Radius, 0, 0)));
         l1.Transform(Transform.Rotation(Math.PI / (double)cut * 2 * i, Point3d.Origin));
         ls2.Add(l1);
     }
     Mesh mesh1 = MeshLoft(ls2, true, true);
     mesh1.Transform(Transform.PlaneToPlane(Plane.WorldXY, c.Plane));
     return mesh1;
 }
Esempio n. 52
0
        /***************************************************/

        public static BHG.Circle FromRhino(this RHG.Circle circle)
        {
            return(new BHG.Circle {
                Centre = circle.Center.FromRhino(), Normal = circle.Normal.FromRhino(), Radius = circle.Radius
            });
        }