private static Rhino.Geometry.NurbsCurve GetSpirial0()
  {
    var axisStart = new Rhino.Geometry.Point3d(0, 0, 0);
    var axisDir = new Rhino.Geometry.Vector3d(1, 0, 0);
    var radiusPoint = new Rhino.Geometry.Point3d(0, 1, 0);

    return Rhino.Geometry.NurbsCurve.CreateSpiral(axisStart, axisDir, radiusPoint, 1, 10, 1.0, 1.0);
  }
示例#2
0
 public static Rhino.Commands.Result AddSphere(Rhino.RhinoDoc doc)
 {
   Rhino.Geometry.Point3d center = new Rhino.Geometry.Point3d(0, 0, 0);
   double radius = 5.0;
   Rhino.Geometry.Sphere sphere = new Rhino.Geometry.Sphere(center, radius);
   if( doc.Objects.AddSphere(sphere) != Guid.Empty )
   {
     doc.Views.Redraw();
     return Rhino.Commands.Result.Success;
   }
   return Rhino.Commands.Result.Failure;
 }
示例#3
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;
 }
  private static Rhino.Geometry.NurbsCurve GetSpirial1()
  {
    var railStart = new Rhino.Geometry.Point3d(0, 0, 0);
    var railEnd = new Rhino.Geometry.Point3d(0, 0, 10);
    var railCurve = new Rhino.Geometry.LineCurve(railStart, railEnd);

    double t0 = railCurve.Domain.Min;
    double t1 = railCurve.Domain.Max;

    var radiusPoint = new Rhino.Geometry.Point3d(1, 0, 0);

    return Rhino.Geometry.NurbsCurve.CreateSpiral(railCurve, t0, t1, radiusPoint, 1, 10, 1.0, 1.0, 12);
  }
 public static Rhino.Commands.Result AddBrepBox(Rhino.RhinoDoc doc)
 {
     Rhino.Geometry.Point3d pt0 = new Rhino.Geometry.Point3d(0, 0, 0);
     Rhino.Geometry.Point3d pt1 = new Rhino.Geometry.Point3d(10, 10, 10);
     Rhino.Geometry.BoundingBox box = new Rhino.Geometry.BoundingBox(pt0, pt1);
     Rhino.Geometry.Brep brep = box.ToBrep();
     Rhino.Commands.Result rc = Rhino.Commands.Result.Failure;
     if( doc.Objects.AddBrep(brep) != System.Guid.Empty )
     {
       rc = Rhino.Commands.Result.Success;
       doc.Views.Redraw();
     }
     return rc;
 }
            private void Calculate_Click(object sender, System.EventArgs e)
            {
                FC = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                if (!Rm.Complete) return;

                if (P == null) P = new WaveConduit(scale, new double[2] { (double)this.Param_Min.Value, (double)this.Param_Max.Value });
                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = new Rhino.Geometry.Point3d[0];//PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null) Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");

                Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Dirac_Pulse;

                switch (SourceSelect.Text)
                {
                    case "Dirac Pulse":
                        s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Dirac_Pulse;
                        break;
                    case "Sine Wave":
                        s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Tone;
                        break;
                    case "Sine Pulse":
                        s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse;
                        break;
                }

                Numeric.TimeDomain.Signal_Driver_Compact SD = new Numeric.TimeDomain.Signal_Driver_Compact(s_type, (double)Frequency_Selection.Value, 1, PachTools.GetSource());
                Numeric.TimeDomain.Microphone_Compact Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);

                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, (double)Freq_Max.Value, (double)CO_TIME.Value);
                M = new Rhino.Geometry.Mesh[3][] { FDTD.m_templateX, FDTD.m_templateY, FDTD.m_templateZ };

                P.SetColorScale(new Pach_Graphics.HSV_colorscale(Param_Scale.Height, Param_Scale.Width, 0, 4.0 / 3.0, 1, 0, 1, 1, false, 12), new double[] { (double)Param_Min.Value, (double)Param_Max.Value });
                P.Enabled = true;

                if (AxisSelect.SelectedIndex == 0) Pos_Select.Maximum = FDTD.xDim - 1;
                else if (AxisSelect.SelectedIndex == 1) Pos_Select.Maximum = FDTD.yDim - 1;
                else if (AxisSelect.SelectedIndex == 2) Pos_Select.Maximum = FDTD.zDim - 1;

                if (Map_Planes.Items.Count == 0)
                {
                    Pos_Select.Value = Pos_Select.Maximum / 2;
                    AddPlane_Click(new object(), new EventArgs());
                }

                Loop_Click(new object(), new EventArgs());
            }
示例#7
0
 public static Rhino.Commands.Result AddAnnotationText(Rhino.RhinoDoc doc)
 {
   Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(10, 0, 0);
   string text = "Hello RhinoCommon";
   double height = 2.0;
   string font = "Arial";
   Rhino.Geometry.Plane plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
   plane.Origin = pt;
   Guid id = doc.Objects.AddText(text, plane, height, font, false, false);
   if( id != Guid.Empty )
   {
     doc.Views.Redraw();
     return Rhino.Commands.Result.Success;
   }
   return Rhino.Commands.Result.Failure;
 }
示例#8
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;
 }
 /// <summary>
 /// Converts an object to a list of Rhino.Geometry.Point3d 
 /// </summary>
 static public bool ConvertToPoint3dList(object pointsObj, ref List<Rhino.Geometry.Point3d> points)
 {
   bool rc = false;
   int pointsCount = points.Count;
   Array pointsArr = pointsObj as Array;
   if (null != pointsArr)
   {
     for (int i = 0; i < pointsArr.Length; i++)
     {
       Rhino.Geometry.Point3d point = new Rhino.Geometry.Point3d();
       if (SampleRhinoHelpers.ConvertToPoint3d(pointsArr.GetValue(i), ref point))
         points.Add(point);
     }
     rc = (points.Count - pointsCount > 0);
   }
   return rc;
 }
  public static Rhino.Commands.Result CreateSpiral(Rhino.RhinoDoc doc)
  {
    var axisStart = new Rhino.Geometry.Point3d(0, 0, 0);
    var axisDir = new Rhino.Geometry.Vector3d(1, 0, 0);
    var radiusPoint = new Rhino.Geometry.Point3d(0, 1, 0);

    Rhino.Geometry.NurbsCurve curve0 = GetSpirial0();
    if (null != curve0)
      doc.Objects.AddCurve(curve0);

    Rhino.Geometry.NurbsCurve curve1 = GetSpirial1();
    if (null != curve1)
      doc.Objects.AddCurve(curve1);

    doc.Views.Redraw();

    return Rhino.Commands.Result.Success;
  }
    protected override Result RunCommand(RhinoDoc doc, RunMode mode)
    {
      var result = Result.Failure;
      var view = doc.Views.ActiveView;
      if (view == null) return result;

      System.Drawing.Point windows_drawing_point;
      if (!GetCursorPos(out windows_drawing_point) || !ScreenToClient(view.Handle, ref windows_drawing_point))
        return result;

      var xform = view.ActiveViewport.GetTransform(CoordinateSystem.Screen, CoordinateSystem.World);
      var point = new Rhino.Geometry.Point3d(windows_drawing_point.X, windows_drawing_point.Y, 0.0);
      RhinoApp.WriteLine("screen point: ({0})", point);
      point.Transform(xform);
      RhinoApp.WriteLine("world point: ({0})", point);
      result = Result.Success;
      return result;
    }
 /// <summary>
 /// LateralPan of a viewport between two points
 /// </summary>
 public static void LateralPan(this ViewportInfo viewport, CGPoint fromPoint, CGPoint toPoint, bool flipX, bool flipY)
 {
     double deltaX, deltaY, s;
       Rhino.Geometry.Transform s2c = viewport.GetXform (CoordinateSystem.Screen, CoordinateSystem.Clip);
       Rhino.Geometry.Point3d screenPoint0 = new Rhino.Geometry.Point3d (fromPoint.X, fromPoint.Y, 0.0);
       Rhino.Geometry.Point3d screenPoint1 = new Rhino.Geometry.Point3d (toPoint.X, toPoint.Y, 0.0);
       Rhino.Geometry.Point3d clipPoint0 = s2c * screenPoint0;
       Rhino.Geometry.Point3d clipPoint1 = s2c * screenPoint1;
       deltaX = 0.5 * (clipPoint1.X - clipPoint0.X);
       deltaY = 0.5 * (clipPoint1.Y - clipPoint0.Y);
       deltaX *= (viewport.FrustumRight - viewport.FrustumLeft);
       deltaY *= (viewport.FrustumBottom - viewport.FrustumTop);
       if (viewport.IsPerspectiveProjection) {
     s = viewport.TargetPoint.DistanceTo (viewport.CameraLocation) / viewport.FrustumNear;
     deltaX *= flipX ? -s : s;
     deltaY *= flipY ? -s : s;
       }
       Rhino.Geometry.Vector3d dollyVector = (deltaX * viewport.CameraX) + (deltaY * viewport.CameraY);
       viewport.TargetPoint = viewport.TargetPoint - dollyVector;
       viewport.SetCameraLocation (viewport.CameraLocation - dollyVector);
 }
    public bool Cone(int index, ref Rhino.Geometry.Cone cone, ref Rhino.Geometry.Plane truncation)
    {
      Rhino.Geometry.Point3d origin = new Rhino.Geometry.Point3d();
      Rhino.Geometry.Vector3d xaxis = new Rhino.Geometry.Vector3d();
      Rhino.Geometry.Vector3d yaxis = new Rhino.Geometry.Vector3d();

      double height = 0.0;
      double radius = 0.0;

      Rhino.Geometry.Point3d t_origin = new Rhino.Geometry.Point3d();
      Rhino.Geometry.Vector3d t_xaxis = new Rhino.Geometry.Vector3d();
      Rhino.Geometry.Vector3d t_yaxis = new Rhino.Geometry.Vector3d();


      if (UnsafeNativeMethods.Rdk_CustomMeshes_Cone(ConstPointer(), index, 
                                                       ref origin, 
                                                       ref xaxis, 
                                                       ref yaxis, 
                                                       ref height, ref radius,
                                                       ref t_origin, ref t_xaxis, ref t_yaxis))
      {
        cone = new Rhino.Geometry.Cone(new Rhino.Geometry.Plane(origin, xaxis, yaxis), height, radius);
        truncation = new Rhino.Geometry.Plane(t_origin, t_xaxis, t_yaxis);
        return true;
      }
      return false;
    }
    public bool Box(int index, ref Rhino.Geometry.Box box)
    {
      Rhino.Geometry.Point3d origin = new Rhino.Geometry.Point3d();
      Rhino.Geometry.Vector3d xaxis = new Rhino.Geometry.Vector3d();
      Rhino.Geometry.Vector3d yaxis = new Rhino.Geometry.Vector3d();
      double minX = 0.0, maxX = 0.0;
      double minY = 0.0, maxY = 0.0;
      double minZ = 0.0, maxZ = 0.0;

      if (UnsafeNativeMethods.Rdk_CustomMeshes_Box(ConstPointer(), index, ref origin, ref xaxis, ref yaxis, ref minX, ref maxX, ref minY, ref maxY, ref minZ, ref maxZ))
      {
        box = new Rhino.Geometry.Box(new Rhino.Geometry.Plane(origin, xaxis, yaxis),
                                                        new Rhino.Geometry.Interval(minX, maxX),
                                                        new Rhino.Geometry.Interval(minY, maxY),
                                                        new Rhino.Geometry.Interval(minZ, maxZ));
        return true;
      }
      return false;
    }
示例#15
0
 /// <summary>
 /// Get Grevit Point
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public static Grevit.Types.Point ToGrevitPoint(this Rhino.Geometry.Point3d point)
 {
     return(new Grevit.Types.Point(point.X, point.Y, point.Z));
 }
示例#16
0
 /// <summary>
 /// Draws the lines in a control polygons.
 /// <para>This is an helper function.</para>
 /// </summary>
 /// <param name="start">The point start.</param>
 /// <param name="end">The point end.</param>
 /// <param name="startStatus">Index of Grip status at start of line defined by start and end.</param>
 /// <param name="endStatus">Index if Grip status at end of line defined by start and end.</param>
 public void DrawControlPolygonLine(Rhino.Geometry.Point3d start, Rhino.Geometry.Point3d end, int startStatus, int endStatus)
 {
     UnsafeNativeMethods.CRhinoDrawGripsSettings_DrawControlPolygonLine(m_pGripsDrawSettings, start, end, startStatus, endStatus);
 }
示例#17
0
        public Rhino.Commands.Result IntersectSurfaces(Rhino.RhinoDoc doc)
        {
            // Input interval
            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input slicing interval");
            input.Get();
            if (input.CommandResult() != Rhino.Commands.Result.Success)
            {
                RhinoApp.WriteLine("Can't obtain interval number");
                return(input.CommandResult());
            }
            double SlicingInterval = input.Number();

            // Select two curves to intersect
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            go.GetMultiple(2, 2);

            Rhino.Geometry.Surface surfaceA = go.Object(0).Surface();
            Rhino.Geometry.Surface surfaceB = go.Object(1).Surface();

            // Calculate the intersection
            RhinoApp.WriteLine("Executing the intersection between surfaces");
            const double intersection_tolerance = 0.001;

            Rhino.Geometry.Curve[]   intersectionCurves = null;
            Rhino.Geometry.Point3d[] intersectionPoints = null;
            bool ret = Rhino.Geometry.Intersect.Intersection.SurfaceSurface(surfaceA, surfaceB, intersection_tolerance, out intersectionCurves, out intersectionPoints);

            if (ret)
            {
                List <PlanePoint> PlanePoints = new List <PlanePoint>();
                RhinoApp.WriteLine("Success - {0} curves", intersectionCurves.Length);
                for (int i = 0; i < intersectionCurves.Length; i++)
                {
                    Rhino.Geometry.Curve curve = intersectionCurves[i];
                    doc.Objects.AddCurve(curve);
                    RhinoApp.WriteLine("Curve is added");

                    Utility.CreateSections(doc, surfaceA, surfaceB, curve, SlicingInterval, ref PlanePoints);
                }

                RhinoApp.WriteLine("Success - {0} points", intersectionPoints.Length);
                for (int i = 0; i < intersectionPoints.Length; i++)
                {
                    Rhino.Geometry.Point3d point = intersectionPoints[i];
                    doc.Objects.AddPoint(point);
                    RhinoApp.WriteLine("Point is added");
                }

                if (Utility.SavePlanePoints(@"c:\SlicerPlanePoints.csv", PlanePoints))
                {
                    RhinoApp.WriteLine("Saved SlicerPlanePoints.csv");
                }
            }

            return(Rhino.Commands.Result.Success);
        }
                private void Build_Mesh_Sections()
                {
                    int ct = -1;

                    m_templateX    = new Rhino.Geometry.Mesh[2];
                    m_templateX[0] = new Rhino.Geometry.Mesh();
                    m_templateX[1] = new Rhino.Geometry.Mesh();
                    m_templateY    = new Rhino.Geometry.Mesh[2];
                    m_templateY[0] = new Rhino.Geometry.Mesh();
                    m_templateY[1] = new Rhino.Geometry.Mesh();
                    m_templateZ    = new Rhino.Geometry.Mesh[2];
                    m_templateZ[0] = new Rhino.Geometry.Mesh();
                    m_templateZ[1] = new Rhino.Geometry.Mesh();

                    double rt2 = Math.Sqrt(2);

                    Hare.Geometry.Point min = RDD_Location(Bounds.Min_PT, 0, 0, 0, dx, dy, dz);

                    for (int i = 0; i < 2; i++)
                    {
                        ct = -1;
                        for (int y = 0; y < PFrame[i].Length; y++)
                        {
                            for (int z = 0; z < PFrame[i][y].Length; z++)
                            {
                                ct++;
                                Rhino.Geometry.Point3d pt = Utilities.RC_PachTools.HPttoRPt(RDD_Location(Bounds.Min_PT, i, y, z, dx, dy, dz)); //new Rhino.Geometry.Point3d(PFrame[0][0][0].Pt.x, PFrame[i][y][z].Pt.y, PFrame[i][y][z].Pt.z);
                                pt.X = min.x;
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, dy, dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, dy, -dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, -dy, -dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, -dy, dz)));
                                int ct4 = ct * 4;
                                m_templateX[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        ct = -1;

                        for (int x = 0; x < PFrame.Length; x++)
                        {
                            for (int z = 0; z < PFrame[x][i].Length; z++)
                            {
                                ct++;
                                Rhino.Geometry.Point3d pt = Utilities.RC_PachTools.HPttoRPt(RDD_Location(Bounds.Min_PT, x, i, z, dx, dy, dz)); //new Rhino.Geometry.Point3d(PFrame[x][i][z].Pt.x, PFrame[0][0][0].Pt.y, PFrame[x][i][z].Pt.z);
                                pt.Y = min.y;
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(dx, 0, 0)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, 0, -dz)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(-dx, 0, 0)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, 0, dz)));
                                int ct4 = ct * 4;
                                m_templateY[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        ct = -1;

                        for (int x = 0; x < PFrame.Length; x++)
                        {
                            for (int y = 0; y < PFrame[x].Length; y++)
                            {
                                ct++;

                                Rhino.Geometry.Point3d pt = Utilities.RC_PachTools.HPttoRPt(RDD_Location(Bounds.Min_PT, x, y, i, dx, dy, dz)); //new Rhino.Geometry.Point3d(PFrame[x][y][i].Pt.x, PFrame[x][y][i].Pt.y, PFrame[0][0][0].Pt.z);
                                pt.Z = min.z;
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(dx, 0, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(0, -dy, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(-dx, 0, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(0, dy, 0)));
                                int ct4 = ct * 4;
                                m_templateZ[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        m_templateX[i].Normals.ComputeNormals();
                        m_templateX[i].FaceNormals.ComputeFaceNormals();
                        m_templateY[i].Normals.ComputeNormals();
                        m_templateY[i].FaceNormals.ComputeFaceNormals();
                        m_templateZ[i].Normals.ComputeNormals();
                        m_templateZ[i].FaceNormals.ComputeFaceNormals();
                    }
                }
示例#19
0
 /// <summary>
 /// Gets the corners of far clipping plane rectangle.
 /// 4 points are returned in the order of bottom left, bottom right,
 /// top left, top right.
 /// </summary>
 /// <returns>
 /// Four corner points on success.
 /// Empty array if viewport is not valid.
 /// </returns>
 public Rhino.Geometry.Point3d[] GetFarPlaneCorners()
 {
   Rhino.Geometry.Point3d leftBottom = new Rhino.Geometry.Point3d();
   Rhino.Geometry.Point3d rightBottom = new Rhino.Geometry.Point3d();
   Rhino.Geometry.Point3d leftTop = new Rhino.Geometry.Point3d();
   Rhino.Geometry.Point3d rightTop = new Rhino.Geometry.Point3d();
   IntPtr pConstThis = ConstPointer();
   if (!UnsafeNativeMethods.ON_Viewport_GetNearFarRect(pConstThis, false, ref leftBottom, ref rightBottom, ref leftTop, ref rightTop))
     return new Rhino.Geometry.Point3d[0];
   return new Rhino.Geometry.Point3d[] { leftBottom, rightBottom, leftTop, rightTop };
 }
示例#20
0
 protected static bool SolveOptionalLevel(DB.Document doc, Rhino.Geometry.Point3d point, ref Optional <DB.Level> level, out Rhino.Geometry.BoundingBox bbox)
 {
     bbox = new Rhino.Geometry.BoundingBox(point, point);
     return(SolveOptionalLevel(doc, point.IsValid ? point.Z : double.NaN, ref level));
 }
示例#21
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input String
            string filename = null;
            bool   activate = false;

            Rhino.Geometry.Point3d point = Rhino.Geometry.Point3d.Unset;
            // 1. Declare placeholder variables and assign initial invalid data.
            //    This way, if the input parameters fail to supply valid data, we know when to abort.

            // 2. Retrieve input data.
            if (!DA.GetData(0, ref filename))
            {
                return;
            }
            if (!DA.GetData(1, ref activate))
            {
                return;
            }
            if (!DA.GetData(2, ref point))
            {
                return;
            }

            // If the retrieved data is Nothing, we need to abort.
            if (filename == null)
            {
                return;
            }
            if (!File.Exists(filename))
            {
                return;
            }

            if (activate)
            {
                GH_Cluster cluster = new GH_Cluster();
                cluster.CreateFromFilePath(filename);

                GH_Document doc = OnPingDocument();
                doc.AddObject(cluster, false);

                Grasshopper.Kernel.Parameters.Param_Point    paramIn  = new Grasshopper.Kernel.Parameters.Param_Point();
                Grasshopper.Kernel.Parameters.Param_Geometry paramOut = new Grasshopper.Kernel.Parameters.Param_Geometry();

                paramIn.SetPersistentData(point);

                cluster.Params.RegisterInputParam(paramIn);
                cluster.Params.RegisterOutputParam(paramOut);

                cluster.CollectData();

                cluster.ComputeData();


                //Grasshopper.DataTree<object> test = new DataTree<object>();
                //test.Add(paramIn, 0);



                DA.SetData(1, paramOut);
            }
        }
示例#22
0
        public void SetValue(Rhino.Geometry.Point3d p)
        {
            var value = new Geometry.Vector3d(p.X, p.Y, p.Z);

            UnsafeNativeMethods.Rdk_Variant_Set3dVectorValue(NonConstPointer(), value);
        }
示例#23
0
文件: Class1.cs 项目: sbaer/ExposeSdk
 /// <summary>
 /// 
 /// </summary>
 /// <param name="point"></param>
 /// <returns></returns>
 public Rhino.Geometry.Vector3d VectorTo(Rhino.Geometry.Point3d point)
 {
     MyPlugInSdk.SdkTest(true);
       Rhino.Geometry.Point3d from = new Rhino.Geometry.Point3d(m_x, m_y, m_z);
       Rhino.Geometry.Vector3d rc = new Rhino.Geometry.Vector3d();
       UnsafeNativeMethods.Expose_CreateVector(from, point, ref rc);
       return rc;
 }
示例#24
0
        public Rhino.Commands.Result AddPoints(Rhino.RhinoDoc doc)
        {
            // Input interval
            double _interval = 0.1;
            double _noise    = 1; // 1% noise

            var input = new Rhino.Input.Custom.GetNumber();

            input.SetCommandPrompt("Input interval(0.0 ~ 1.0)<0.1>");
            Rhino.Input.GetResult res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _interval = input.Number();
            }
            if (_interval == 0.0)
            {
                _interval = 0.1;
            }

            input.SetCommandPrompt("Noise factor(0.0 ~ 100.0)");
            res = input.Get();
            if (res == Rhino.Input.GetResult.Number)
            {
                _noise = input.Number();
            }

            // Select surface
            var go = new Rhino.Input.Custom.GetObject();

            go.SetCommandPrompt("Select surface");
            go.GeometryFilter = Rhino.DocObjects.ObjectType.Surface;
            res = go.GetMultiple(1, 1024);
            if (res == Rhino.Input.GetResult.Nothing)
            {
                return(Rhino.Commands.Result.Failure);
            }

            Utility.SetOutputCount(10);
            for (int i = 0; i < go.ObjectCount; i++)
            {
                Rhino.Geometry.Surface surfaceA = go.Object(i).Surface();
                if (surfaceA == null)
                {
                    return(Rhino.Commands.Result.Failure);
                }

                Rhino.Geometry.Interval domU = surfaceA.Domain(0);
                Rhino.Geometry.Interval domV = surfaceA.Domain(1);

                double u, v;
                u = v = 0.0;
                for (u = domU.Min; u <= domU.Max; u += _interval)
                {
                    for (v = domV.Min; v <= domV.Max; v += _interval)
                    {
                        Rhino.Geometry.Point3d  pt  = surfaceA.PointAt(u, v);
                        Rhino.Geometry.Vector3d n   = surfaceA.NormalAt(u, v);
                        Rhino.Geometry.Point3d  pt2 = randomPoint(surfaceA, u, v, _interval, _noise);
                        doc.Objects.AddPoint(pt2);
                    }
                }
            }
            return(Rhino.Commands.Result.Success);
        }
 /// <summary>
 /// Add a 3-D point to the document
 /// </summary>
 public object AddPoint(object pointObj)
 {
   Rhino.Geometry.Point3d point = new Rhino.Geometry.Point3d();
   if (SampleRhinoHelpers.ConvertToPoint3d(pointObj, ref point))
   {
     Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
     if (null != doc)
     {
       System.Guid objectId = doc.Objects.AddPoint(point);
       if (!objectId.Equals(System.Guid.Empty))
       {
         doc.Views.Redraw();
         return objectId.ToString();
       }
     }
   }
   return null;
 }
示例#26
0
 /// <summary>
 /// Blend color with the decal color at a given point.
 /// </summary>
 /// <param name="point">The point in space or, if the decal is uv-mapped, the uv-coordinate of that point.</param>
 /// <param name="normal">The face normal of the given point.</param>
 /// <param name="colInOut">The color to blend the decal color to.</param>
 /// <param name="uvOut">the UV on the texture that the color point was read from.</param>
 /// <returns>true if the given point hits the decal, else false.</returns>
 public bool Color(Rhino.Geometry.Point3d point, Rhino.Geometry.Vector3d normal, ref Rhino.Display.Color4f colInOut, ref Rhino.Geometry.Point2d uvOut)
 {
     return(1 == UnsafeNativeMethods.Rdk_Decal_Color(ConstPointer(), point, normal, ref colInOut, ref uvOut));
 }
 public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Point3d dir)
 {
     Rhino.Geometry.Vector3d V = rec - dir;
     V.Unitize();
     Dir = new Rhino.Geometry.Line(rec, rec + dir);
 }
示例#28
0
 public void drawExtrusion(Rhino.Geometry.Point3d point1, double height, double width, double thickness)
 {
     Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(point1,Rhino.Geometry.Vector3d.ZAxis);
     Rhino.Geometry.Point3d cornerA = new Rhino.Geometry.Point3d(point1.X - width / 2, point1.Y - height / 2, point1.Z);
     Rhino.Geometry.Point3d cornerB = new Rhino.Geometry.Point3d(point1.X + width / 2, point1.Y + height / 2, point1.Z);
     Rhino.Geometry.Rectangle3d rect = new Rhino.Geometry.Rectangle3d(plane, cornerA, cornerB);
     Rhino.Geometry.Surface srf = Rhino.Geometry.Surface.CreateExtrusion(rect.ToNurbsCurve(), new Rhino.Geometry.Vector3d(0, 0, thickness));
     SetPreview(srf.ToBrep());
 }
 public void set_direction(Rhino.Geometry.Point3d rec, Rhino.Geometry.Vector3d V)
 {
     V.Unitize();
     Dir = new Rhino.Geometry.Line(rec, rec + V);
 }
示例#30
0
        /// <summary>
        /// Convert ArcGIS Polyline to Rhino Polyline
        /// </summary>
        /// <param name="layer">FeatureLayer</param>
        /// <param name="feature">Feature</param>
        /// <param name="polygon">Polygon</param>
        /// <param name="rhinoDoc">RhinoDoc</param>
        private static void convertPolyline(FeatureLayer layer, Feature feature, Polyline polyline, RhinoDoc rhinoDoc, Rhino.Geometry.Point3d origin)
        {
            var rhinoPoints = polyline.Points.ToList().Select(p => convertToRhinoPoint(p, origin)).ToList();
            var attrs       = getLayerAttrs(layer, rhinoDoc);
            var guid        = rhinoDoc.Objects.AddPolyline(rhinoPoints, attrs);
            var obj         = rhinoDoc.Objects.FindId(guid);

            bindAttrs(obj, feature);
        }
示例#31
0
            private void Calculate_Click(object sender, System.EventArgs e)
            {
                FC = new ForCall(Forw_proc);

                Polygon_Scene Rm = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);

                if (!Rm.Complete)
                {
                    return;
                }

                if (P == null)
                {
                    P = new WaveConduit(scale, new double[2] {
                        (double)this.Param_Min.Value, (double)this.Param_Max.Value
                    });
                }
                Rhino.Geometry.Point3d[] Src = PachTools.GetSource();
                Rhino.Geometry.Point3d[] Rec = new Rhino.Geometry.Point3d[0];//PachTools.GetReceivers().ToArray();
                if (Src.Length < 1 || Rm == null)
                {
                    Rhino.RhinoApp.WriteLine("Model geometry not specified... Exiting calculation...");
                }

                Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Dirac_Pulse;

                switch (SourceSelect.Text)
                {
                case "Dirac Pulse":
                    s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Dirac_Pulse;
                    break;

                case "Sine Wave":
                    s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Tone;
                    break;

                case "Sine Pulse":
                    s_type = Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse;
                    break;
                }

                Numeric.TimeDomain.Signal_Driver_Compact SD  = new Numeric.TimeDomain.Signal_Driver_Compact(s_type, (double)Frequency_Selection.Value, 1, PachTools.GetSource());
                Numeric.TimeDomain.Microphone_Compact    Mic = new Numeric.TimeDomain.Microphone_Compact(Rec);

                FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, (double)Freq_Max.Value, (double)CO_TIME.Value, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.Freefield, null, 0, 0, 0);
                //FDTD = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, (double)Freq_Max.Value, (double)CO_TIME.Value, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, new Hare.Geometry.Point(0,0,0), 8, 6, 5);
                M = new Rhino.Geometry.Mesh[3][] { FDTD.m_templateX, FDTD.m_templateY, FDTD.m_templateZ };

                P.SetColorScale(new Pach_Graphics.HSV_colorscale(Param_Scale.Height, Param_Scale.Width, 0, 4.0 / 3.0, 1, 0, 1, 1, false, 12), new double[] { (double)Param_Min.Value, (double)Param_Max.Value });
                P.Enabled = true;

                if (AxisSelect.SelectedIndex == 0)
                {
                    Pos_Select.Maximum = FDTD.xDim - 1;
                }
                else if (AxisSelect.SelectedIndex == 1)
                {
                    Pos_Select.Maximum = FDTD.yDim - 1;
                }
                else if (AxisSelect.SelectedIndex == 2)
                {
                    Pos_Select.Maximum = FDTD.zDim - 1;
                }

                if (Map_Planes.Items.Count == 0)
                {
                    Pos_Select.Value = Pos_Select.Maximum / 2;
                    AddPlane_Click(new object(), new EventArgs());
                }

                Loop_Click(new object(), new EventArgs());
            }
示例#32
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!DA.GetData(3, ref v))
            {
                return;
            }
            if (!FriedChiken.isInitialized)
            {
                Rhino.Geometry.Surface s = null;
                if (!DA.GetData(0, ref s))
                {
                    return;
                }
                Rhino.Geometry.Interval uDomain = s.Domain(0);
                Rhino.Geometry.Interval vDomain = s.Domain(1);
                int[] nEdgeNodes = new int[_dim];
                DA.GetData(1, ref nEdgeNodes[0]);
                DA.GetData(2, ref nEdgeNodes[1]);
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                newNodes.Clear();
                for (int i = 0; i < nEdgeNodes[1]; i++)
                {
                    for (int j = 0; j < nEdgeNodes[0]; j++)
                    {
                        newNodes.Add(s.PointAt(uDomain.T0 + (uDomain.T1 - uDomain.T0) / (nEdgeNodes[0] - 1) * j, vDomain.T0 + (vDomain.T1 - vDomain.T0) / (nEdgeNodes[1] - 1) * i));
                    }
                }
                int nNewNodes = newNodes.Count;

                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]);
                }
                pS = new GH_particleSystem(particles);

                node[] lNodes = new node[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                nF = new nodalForce(v.X, v.Y, v.Z);
                for (int i = 0; i < nNewNodes; i++)
                {
                    nF.addNode(lNodes[i]);
                }
                pS.Value.addObject(nF);
                lGeometry = new Rhino.Geometry.Point3d[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
            }
            else
            {
                nF.forceX = v.X;
                nF.forceY = v.Y;
                nF.forceZ = v.Z;
            }

            DA.SetData(0, pS);
        }
示例#33
0
            private void CalculateScattering_Click(object sender, EventArgs e)
            {
                Chosenfreq = 0;
                double radius = (double)ScatteringRadius.Value;
                double t      = 4 * (radius + (double)Sample_Depth.Value) / C_Sound() * 1000;

                if (LabCenter == null)
                {
                    return;
                }

                Polygon_Scene Rm      = PachTools.Get_Poly_Scene((double)Rel_Humidity.Value, (double)Air_Temp.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked);
                Empty_Scene   Rm_Ctrl = new Empty_Scene((double)Air_Temp.Value, (double)Rel_Humidity.Value, (double)Air_Pressure.Value, Atten_Method.SelectedIndex, EdgeFreq.Checked, true, Rm.Min(), Rm.Max());

                Rm_Ctrl.PointsInScene(new List <Hare.Geometry.Point> {
                    Rm.Min(), Rm.Max()
                });
                Rm_Ctrl.partition();

                if (!Rm.Complete && Rm_Ctrl.Complete)
                {
                    return;
                }

                Rhino.Geometry.Point3d ArrayCenter = new Rhino.Geometry.Point3d(LabCenter.X, LabCenter.Y, LabCenter.Z + (double)Sample_Depth.Value);

                Rhino.Geometry.Point3d[] Src = new Rhino.Geometry.Point3d[1] {
                    new Rhino.Geometry.Point3d(LabCenter.X, LabCenter.Y, LabCenter.Z + radius + (double)Sample_Depth.Value)
                };
                List <Rhino.Geometry.Point3d> Rec = new List <Rhino.Geometry.Point3d>();

                for (int phi = 0; phi < 18; phi++)
                {
                    for (int theta = 0; theta < 36; theta++)
                    {
                        double anglePhi   = phi * Math.PI / 18;
                        double angleTheta = theta * Utilities.Numerics.PiX2 / 36;
                        Rec.Add(ArrayCenter + radius * new Rhino.Geometry.Point3d(Math.Cos(angleTheta) * Math.Cos(anglePhi), Math.Sin(angleTheta) * Math.Cos(anglePhi), Math.Sin(anglePhi)));
                    }
                }

                //for (int phi = 0; phi < 18; phi++)
                //    {
                //        double anglePhi = phi * Math.PI / 18;
                //        Rec.Add(ArrayCenter + radius * new Rhino.Geometry.Point3d(Math.Cos(anglePhi), 0, Math.Sin(anglePhi)));
                //    }

                double fs = 62.5 * Utilities.Numerics.rt2 * Math.Pow(2, Scatter_Extent.SelectedIndex);

                Numeric.TimeDomain.Microphone_Compact    Mic   = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                Numeric.TimeDomain.Signal_Driver_Compact SD    = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDS = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm, ref SD, ref Mic, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.PachTools.RPttoHPt(LabCenter), radius * 2, radius * 2, radius * 1.2 + (double)Sample_Depth.Value);
                FDTDS.RuntoCompletion();

                Numeric.TimeDomain.Microphone_Compact    Micf  = new Numeric.TimeDomain.Microphone_Compact(Rec.ToArray());
                Numeric.TimeDomain.Signal_Driver_Compact SDf   = new Numeric.TimeDomain.Signal_Driver_Compact(Numeric.TimeDomain.Signal_Driver_Compact.Signal_Type.Sine_Pulse, fs, 1, Src);
                Numeric.TimeDomain.Acoustic_Compact_FDTD FDTDF = new Numeric.TimeDomain.Acoustic_Compact_FDTD(Rm_Ctrl, ref SDf, ref Micf, fs, t, Numeric.TimeDomain.Acoustic_Compact_FDTD.GridType.ScatteringLab, Utilities.PachTools.RPttoHPt(LabCenter) + new Hare.Geometry.Point(0, 0, (double)Sample_Depth.Value), radius * 2, radius * 2, radius * 1.2 + (double)Sample_Depth.Value);
                FDTDF.RuntoCompletion();

                samplefrequency = FDTDS.SampleFrequency;

                Mic.reset();
                result_signals = Mic.Recordings[0];
                Micf.reset();
                result_signals = Micf.Recordings[0];

                //Calculate Scattering Coefficients
                double[][] TimeS = Mic.Recordings[0];
                double[][] TimeF = Micf.Recordings[0];

                System.Numerics.Complex[][] FS = new System.Numerics.Complex[TimeS.Length][];
                System.Numerics.Complex[][] FF = new System.Numerics.Complex[TimeS.Length][];

                for (int i = 0; i < TimeS.Length; i++)
                {
                    FS[i] = Audio.Pach_SP.FFT_General(TimeS[i], 0);
                    FF[i] = Audio.Pach_SP.FFT_General(TimeF[i], 0);
                }

                Scattering = new double[FS[0].Length];

                for (int i = 0; i < FS[0].Length; i++)
                {
                    System.Numerics.Complex sumFS2  = 0;
                    System.Numerics.Complex sumFF2  = 0;
                    System.Numerics.Complex sumFSFF = 0;

                    for (int j = 0; j < FS.Length; j++)
                    {
                        sumFS2  += System.Numerics.Complex.Pow(FS[j][i].Magnitude, 2);
                        sumFF2  += System.Numerics.Complex.Pow(FF[j][i].Magnitude, 2);
                        sumFSFF += FS[j][i] * System.Numerics.Complex.Conjugate(FF[j][i]);
                        //sumFS2 += System.Numerics.Complex.Pow(FS[j][i], 2);
                        //sumFF2 += System.Numerics.Complex.Pow(FF[j][i], 2);
                        //sumFSFF += FS[j][i] * System.Numerics.Complex.Conjugate(FF[j][i]);
                    }

                    System.Numerics.Complex sumReflected = sumFSFF / sumFF2;
                    System.Numerics.Complex Ratio        = sumFF2 / sumFS2;
                    Scattering[i] = 1 - System.Numerics.Complex.Abs(sumReflected * sumReflected * Ratio);
                }

                Update_Scattering_Graph(null, null);
            }
示例#34
0
        /// <summary>
        /// Convert ArcGIS MapPoint to Rhino Point3d
        /// </summary>
        /// <param name="layer">FeatureLayer</param>
        /// <param name="feature">Feature</param>
        /// <param name="point">MapPoint</param>
        /// <param name="rhinoDoc">RhinoDoc</param>
        private static void convertPoint(FeatureLayer layer, Feature feature, MapPoint point, RhinoDoc rhinoDoc, Rhino.Geometry.Point3d origin)
        {
            var rhinoPoint = convertToRhinoPoint(point, origin);
            var attrs      = getLayerAttrs(layer, rhinoDoc);
            var guid       = rhinoDoc.Objects.AddPoint(rhinoPoint, attrs);
            var obj        = rhinoDoc.Objects.FindId(guid);

            bindAttrs(obj, feature);
        }
            /// <summary>
            /// reads a file and populates the map receiver instance.
            /// </summary>
            /// <returns></returns>
            public static bool Read_pachm(out Mapping.PachMapReceiver[] Map)
            {
                System.Windows.Forms.OpenFileDialog of = new System.Windows.Forms.OpenFileDialog();
                of.DefaultExt   = ".pachm";
                of.AddExtension = true;
                of.Filter       = "Pachyderm Mapping Data File (*.pachm)|*.pachm|" + "All Files|";
                if (of.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    Map = null;
                    return(false);
                }
                System.IO.BinaryReader sr = new System.IO.BinaryReader(System.IO.File.Open(of.FileName, System.IO.FileMode.Open));
                //1. Write calculation type. (string)
                string CalcType = sr.ReadString();

                if (CalcType != "Type;Map_Data" && CalcType != "Type;Map_Data_NoDir")
                {
                    throw new Exception("Map Data File Expected");
                }
                bool Directional = (CalcType == "Type;Map_Data");

                //2. Write the number of samples in each histogram. (int)
                int SampleCT = (int)sr.ReadUInt32();
                //3. Write the sample rate. (int)
                int SampleRate = (int)sr.ReadUInt32();
                //4. Write the number of Receivers (int)
                int Rec_CT = (int)sr.ReadUInt32();
                //4.5 Write the version number
                double version = 1.1;
                double rev     = 0;
                //5. Announce that the following data pertains to the form of the analysis mesh. (string)
                int s_ct = 1;

                Rhino.Geometry.Mesh Map_Mesh = new Rhino.Geometry.Mesh();
                Map = new Mapping.PachMapReceiver[1];
                //Map[0] = new Pach_Map_Receiver();
                //double[] Rho_C = null;
                double[] delay;

                do
                {
                    switch (sr.ReadString())
                    {
                    case "Version":
                        //Pach1.7 = Versioning functionality added.
                        string v = sr.ReadString();
                        version = double.Parse(v.Substring(0, 3));
                        rev     = int.Parse(v.Split(new char[1] {
                            '.'
                        })[3]);
                        break;

                    case "Mesh Information":
                        //6. Announce Mesh Vertices (string)
                        //Write the number of vertices & faces (int) (int)
                        if (sr.ReadString() != "Mesh Vertices")
                        {
                            throw new Exception("Mesh Vertices Expected");
                        }

                        int VC = (int)sr.ReadUInt32();
                        int FC = (int)sr.ReadUInt32();
                        for (int i = 0; i < VC; i++)
                        {
                            //Write Vertex: (double) (double) (double)
                            Map_Mesh.Vertices.Add(new Rhino.Geometry.Point3d(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()));
                        }

                        //7. Announce Mesh Faces (string)
                        if (sr.ReadString() != "Mesh Faces")
                        {
                            throw new Exception("Mesh Faces Expected");
                        }

                        for (int i = 0; i < FC; i++)
                        {
                            // Write mesh vertex indices: (int) (int) (int) (int)
                            Map_Mesh.Faces.AddFace((int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32(), (int)sr.ReadUInt32());
                        }
                        break;

                    case "Sources":
                        //7.5: Announce the number of sources.
                        s_ct  = sr.ReadInt32();
                        delay = new double[s_ct];
                        Map   = new Mapping.PachMapReceiver[s_ct];
                        //7.5a Announce the type of source.

                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s]            = new Mapping.PachMapReceiver();
                            Map[s].CutOffTime = (double)SampleCT / (double)SampleRate;
                            Map[s].SampleCT   = SampleCT;
                            Map[s].SampleRate = SampleRate;
                            Map[s].Map_Mesh   = Map_Mesh;
                            Map[s].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[s].SrcType    = sr.ReadString();
                            //4.4 Source delay (ms)
                            if (version > 2.0 || (version == 2.0 && rev >= 1))
                            {
                                delay[s] = sr.ReadDouble();
                            }
                        }
                        break;

                    case "SourceswLoc":
                        //7.5: Announce the number of sources.
                        s_ct  = sr.ReadInt32();
                        delay = new double[s_ct];
                        Map   = new Mapping.PachMapReceiver[s_ct];
                        //7.5a Announce the type of source.

                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s]            = new Mapping.PachMapReceiver();
                            Map[s].CutOffTime = (double)SampleCT / (double)SampleRate * 1000;
                            Map[s].SampleCT   = SampleCT;
                            Map[s].SampleRate = SampleRate;
                            Map[s].Map_Mesh   = Map_Mesh;
                            Map[s].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[s].Src        = new Rhino.Geometry.Point3d(sr.ReadDouble(), sr.ReadDouble(), sr.ReadDouble());
                            Map[s].SrcType    = sr.ReadString();
                            //4.4 Source delay (ms)
                            if (version > 2.0 || (version == 2.0 && rev >= 1))
                            {
                                delay[s] = sr.ReadDouble();
                            }
                        }
                        break;

                    case "Receiver Hit Data":
                        if (Map[0] == null)
                        {
                            Map               = new Mapping.PachMapReceiver[1];
                            Map[0]            = new Mapping.PachMapReceiver();
                            Map[0].CutOffTime = (double)SampleCT / (double)SampleRate;
                            Map[0].SampleRate = SampleRate;
                            Map[0].SampleCT   = SampleCT;
                            Map[0].Map_Mesh   = Map_Mesh;
                            Map[0].Rec_List   = new Mapping.PachMapReceiver.Map_Receiver[Rec_CT];
                            Map[0].SrcType    = "Geodesic";
                        }

                        //8. Announce that the following data pertains to the receiver histograms (string)
                        //8a. Announce whether or not data is linked to vertices rather than faces (bool)
                        bool vert_Receiver = sr.ReadBoolean();
                        for (int s = 0; s < s_ct; s++)
                        {
                            Map[s].Rec_Vertex = vert_Receiver;
                            for (int i = 0; i < Map[s].Rec_List.Length; i++)
                            {
                                //for version 1.7 and up, write direct sound arrival time.
                                //Write Receiver Index (int)
                                int j = (int)sr.ReadUInt32();
                                //Write Direct Sound Arrival Time.
                                double Direct_Time;
                                if (version >= 1.7)
                                {
                                    Direct_Time = sr.ReadDouble();
                                }
                                else
                                {
                                    Direct_Time = (Utilities.PachTools.RPttoHPt(Map[s].Src) - Map[s].Rec_List[i].H_Origin).Length() / 343f;
                                }
                                //Write Impedance of Air
                                double Rho_C = version >= 2.0 ? sr.ReadDouble() : 400;

                                if (vert_Receiver)
                                {
                                    Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(Map_Mesh.Vertices[i], new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                }
                                else
                                {
                                    Rhino.Geometry.Point3d RecLoc = Map_Mesh.Faces.GetFaceCenter(i);
                                    Map[s].Rec_List[i] = new Mapping.PachMapReceiver.Map_Receiver(new Rhino.Geometry.Point3f((float)RecLoc.X, (float)RecLoc.Y, (float)RecLoc.Z), new Rhino.Geometry.Point3f((float)Map[s].Src.X, (float)Map[s].Src.Y, (float)Map[s].Src.Z), Direct_Time, Rho_C, i, SampleRate, SampleCT, Directional);
                                }

                                for (int Octave = 0; Octave < 8; Octave++)
                                {
                                    //Write Octave (int)
                                    int Oct_out = (int)sr.ReadUInt32();
                                    if (Oct_out != Octave)
                                    {
                                        throw new Exception(string.Format("Octave {0} Expected", Octave));
                                    }
                                    double[] Hist = Map[s].Rec_List[i].GetEnergyHistogram(Octave);
                                    if (Directional)
                                    {
                                        if (version < 1.7)
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                        else
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), new Hare.Geometry.Vector(sr.ReadSingle(), sr.ReadSingle(), sr.ReadSingle()), Octave);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (version < 1.7)
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                        }
                                        else
                                        {
                                            for (int e = 0; e < SampleCT; e++)
                                            {
                                                Map[s].Rec_List[i].Combine_Sample(e, sr.ReadDouble(), new Hare.Geometry.Vector(0, 0, 0), new Hare.Geometry.Vector(0, 0, 0), Octave);
                                            }
                                        }
                                    }
                                }
                                if (sr.ReadString() != "End_Receiver_Hits")
                                {
                                    throw new Exception("End of Receiver Hits Expected");
                                }
                            }
                        }
                        break;

                    case "End_of_File":
                        sr.Close();
                        return(true);
                    }
                } while (true);
                throw new Exception("Unsuccessful Read");
            }
    public bool Sphere(int index, ref Rhino.Geometry.Sphere sphere)
    {
      Rhino.Geometry.Point3d origin = new Rhino.Geometry.Point3d();
      Rhino.Geometry.Vector3d xaxis = new Rhino.Geometry.Vector3d();
      Rhino.Geometry.Vector3d yaxis = new Rhino.Geometry.Vector3d();
      double radius = 0.0;

      if (UnsafeNativeMethods.Rdk_CustomMeshes_Sphere(ConstPointer(), index, ref origin, ref xaxis, ref yaxis, ref radius))
      {
        sphere = new Rhino.Geometry.Sphere(new Rhino.Geometry.Plane(origin, xaxis, yaxis), radius);
        return true;
      }
      return false;
    }
示例#37
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            stw.Stop();
            string dbg = stw.ElapsedMilliseconds.ToString();

            stw.Reset();
            double dist = 0;

            if (!DA.GetData(1, ref dist))
            {
                return;
            }
            if (_go == false)
            {
                t = 0;
                FriedChiken.clear();
                lpS = new List <GH_particleSystem>();

                if (fixedPointsGuids != null)
                {
                    foreach (Guid[] gs in fixedPointsGuids)
                    {
                        foreach (Guid g in gs)
                        {
                            Rhino.RhinoDoc.ActiveDoc.Objects.Delete(g, true);
                        }
                    }
                    fixedPointsGuids = null;
                }

                if (!DA.GetDataList(0, lpS))
                {
                    return;
                }
                particleSystem[] _ps = null;
                _ps = new particleSystem[lpS.Count];
                for (int i = 0; i < lpS.Count; i++)
                {
                    _ps[i] = lpS[i].Value;
                }
                FriedChiken.addParticleSystems(_ps);
                //FriedChiken.begin();
                __dist = dist;
                lS     = new List <Rhino.Geometry.GeometryBase>();
                lPC    = new List <Rhino.Geometry.PointCloud>();

                lfN = new List <NumericalMethodHelper.objects.fixedNodes>();
                fixedPointsGuids = new List <Guid[]>();

                foreach (GH_particleSystem pS in lpS)
                {
                    if (pS != null)
                    {
                        if (pS.UPGR != null)
                        {
                            pS.UPGR(dist, 0, 0);
                        }
                    }
                }
            }
            else
            {
                double dt = full.getDt();
                if (t == 0)
                {
                    output = new List <string>();
                    //firstAction(DA);
                    FriedChiken.clear();
                    lpS = new List <GH_particleSystem>();
                    if (!DA.GetDataList(0, lpS))
                    {
                        return;
                    }
                    particleSystem[] _ps = null;
                    _ps = new particleSystem[lpS.Count];
                    for (int i = 0; i < lpS.Count; i++)
                    {
                        _ps[i] = lpS[i].Value;
                    }
                    FriedChiken.addParticleSystems(_ps);
                    if (fixedPointsGuids != null)
                    {
                        foreach (Guid[] gs in fixedPointsGuids)
                        {
                            foreach (Guid g in gs)
                            {
                                Rhino.RhinoDoc.ActiveDoc.Objects.Delete(g, true);
                            }
                        }
                    }
                    FriedChiken.begin();
                    refX   = DoubleArray.From(FriedChiken.x.rawData);
                    __dist = dist;
                    if (FriedChiken.numCond > 0)
                    {
                        lambda = new vector(FriedChiken.numCond).zeros();
                        dx     = new vector(FriedChiken.q.nElem);
                        qo     = new vector(FriedChiken.q.nElem);
                        qr     = new vector(FriedChiken.numCond).zeros();
                    }
                    lS  = new List <Rhino.Geometry.GeometryBase>();
                    lPC = new List <Rhino.Geometry.PointCloud>();

                    lfN = new List <NumericalMethodHelper.objects.fixedNodes>();
                    fixedPointsGuids = new List <Guid[]>();
                    for (int i = 0; i < FriedChiken.particleSystems.Count; i++)
                    {
                        for (int j = 0; j < FriedChiken.particleSystems[i].objList.Count; j++)
                        {
                            if (FriedChiken.particleSystems[i].objList[j] is mikity.NumericalMethodHelper.objects.fixedNodes)
                            {
                                mikity.NumericalMethodHelper.objects.fixedNodes fN = (mikity.NumericalMethodHelper.objects.fixedNodes)FriedChiken.particleSystems[i].objList[j];
                                lfN.Add(fN);
                                fixedPointsGuids.Add(new Guid[fN.nNodes]);
                                Rhino.Geometry.Point3d[] ps = new Rhino.Geometry.Point3d[fN.nNodes];
                                Guid[] gs = fixedPointsGuids[fixedPointsGuids.Count - 1];

                                for (int k = 0; k < fN.nNodes; k++)
                                {
                                    ps[k] = new Rhino.Geometry.Point3d(fN.nodeList[k].getNodes()[0, 0] + dist, fN.nodeList[k].getNodes()[0, 1], fN.nodeList[k].getNodes()[0, 2]);
                                    gs[k] = Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(ps[k]);
                                }
                                Rhino.RhinoDoc.ActiveDoc.Groups.Add(gs);
                            }
                        }
                    }
                }
                //Computation

                while (stw.ElapsedMilliseconds < 25)
                {
                    stw.Start();
                    FriedChiken.Tick(t); //要素アップデート、勾配の計算
                    FriedChiken.Tack(t); //マスク等後処理
                    if (_IF)
                    {
                        FriedChiken.omega.zeros();
                    }
                    double resid = 0;
                    if (FriedChiken.numCond > 0)
                    {
                        resid = FriedChiken.getResidual().norm;
                        phi();
                    }
                    string tmp = "\t" + t.ToString() + "\t";
                    tmp += FriedChiken.omega.norm.ToString() + "\t";

                    if (_geodesic)
                    {
                        if (FriedChiken.numCond > 0)
                        {
                            varphi();
                        }
                    }
                    var    v     = DoubleArray.From(FriedChiken.q.rawData);
                    double normW = FriedChiken.omega.norm;
                    if (_normalize == true)
                    {
                        if (normW != 0)
                        {
                            FriedChiken.omega.dividedby(normW);//力を正規化
                        }
                        normW = FriedChiken.omega.norm;
                    }
                    var a = DoubleArray.From(FriedChiken.omega.rawData);

                    FriedChiken.omega.MinusTo(FriedChiken.r);//力を加速度に
                    double norm1 = (v * v.T)[0, 0];
                    double norm2 = (v * a.T)[0, 0];
                    double norm3 = (a * a.T)[0, 0];
                    double f     = 0;
                    if (norm1 * norm3 != 0)
                    {
                        f = -norm2 / Math.Sqrt(norm1 * norm3);
                    }
                    else if (norm1 == 0)
                    {
                        f = 1;
                    }
                    else
                    {
                        f = -1;
                    }
                    double damping = 0;
                    if (_drift1)
                    {
                        damping = Drift1(f);
                    }
                    else if (_drift2)
                    {
                        damping = Drift2(f);
                    }
                    else if (_drift3)
                    {
                        damping = Drift3(f);
                    }
                    else
                    {
                        damping = Drift0(f);
                    }
                    //damping = 0;
                    full.move(f);
                    dbg = "damping:" + damping.ToString() + "\n" + "dt:" + dt.ToString() + "\n" + "Step#:" + t.ToString();
                    full.setDbgText(dbg);
                    FriedChiken.q.times(damping).Add(dt, FriedChiken.r);
                    double normQ = FriedChiken.q.norm;
                    double K     = normQ * normQ * 0.5;
                    double P     = FriedChiken.energy;
                    double E     = K + P;
                    int    itr   = 0;
                    FriedChiken.x.Add(dt, FriedChiken.q);
                    if (FriedChiken.numCond > 0)
                    {
                        itr = psi();
                    }
                    full.addNorm(K, E, itr, normW, resid);

                    stw.Stop();
                    t++;
                    if (_RP == false)
                    {
                        break;
                    }
                }
                stw.Reset();

                //////////////
                for (int i = 0; i < lfN.Count; i++)
                {
                    Guid[] gs = fixedPointsGuids[i];
                    for (int j = 0; j < gs.Count(); j++)
                    {
                        Rhino.DocObjects.PointObject obj = (Rhino.DocObjects.PointObject)Rhino.RhinoDoc.ActiveDoc.Objects.Find(gs[j]);
                        Rhino.Geometry.Point3d       p   = new Rhino.Geometry.Point3d(obj.PointGeometry.Location.X, obj.PointGeometry.Location.Y, obj.PointGeometry.Location.Z);
                        if (lfN[i].fixX)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 0] = lfN[i].nodeList[j].getNodes()[0, 0] * 0.95 + (p.X - dist) * 0.05; //*
                            if (dist != __dist)
                            {
                                p.X = p.X + dist - __dist;
                            }
                        }
                        else
                        {
                            p.X = lfN[i].nodeList[j].getNodes()[0, 0] + dist;
                        }
                        if (lfN[i].fixY)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 1] = lfN[i].nodeList[j].getNodes()[0, 1] * 0.95 + p.Y * 0.05;//*
                        }
                        else
                        {
                            p.Y = lfN[i].nodeList[j].getNodes()[0, 1];
                        }
                        if (lfN[i].fixZ)
                        {
                            lfN[i].nodeList[j].getNodes()[0, 2] = lfN[i].nodeList[j].getNodes()[0, 2] * 0.95 + p.Z * 0.05; //*
                        }
                        else
                        {
                            p.Z = lfN[i].nodeList[j].getNodes()[0, 2];
                        }
                        double x = 0, y = 0, z = 0;
                        x = p.X - obj.PointGeometry.Location.X;
                        y = p.Y - obj.PointGeometry.Location.Y;
                        z = p.Z - obj.PointGeometry.Location.Z;

                        Rhino.Geometry.Transform tx = Rhino.Geometry.Transform.Translation(x, y, z);
                        gs[j] = Rhino.RhinoDoc.ActiveDoc.Objects.Transform(gs[j], tx, true);
                    }
                }
                if (dist != __dist)
                {
                    __dist = dist;
                }


                foreach (GH_particleSystem pS in lpS)
                {
                    if (pS != null)
                    {
                        if (pS.UPGR != null)
                        {
                            pS.UPGR(dist, 0, 0);
                        }
                    }
                }
            }

            return;
        }
    public bool Plane(int index, ref Rhino.Geometry.PlaneSurface plane)
    {
      Rhino.Geometry.Point3d origin = new Rhino.Geometry.Point3d();
      Rhino.Geometry.Vector3d xaxis = new Rhino.Geometry.Vector3d();
      Rhino.Geometry.Vector3d yaxis = new Rhino.Geometry.Vector3d();
      double minX = 0.0, maxX = 0.0;
      double minY = 0.0, maxY = 0.0;

      if (UnsafeNativeMethods.Rdk_CustomMeshes_Plane(ConstPointer(), index, ref origin, ref xaxis, ref yaxis, ref minX, ref maxX, ref minY, ref maxY))
      {
        plane = new Rhino.Geometry.PlaneSurface(new Rhino.Geometry.Plane(origin, xaxis, yaxis),
                                                        new Rhino.Geometry.Interval(minX, maxX),
                                                        new Rhino.Geometry.Interval(minY, maxY));
        return true;
      }
      return false;
    }
示例#39
0
 /// <summary>
 /// Convert ArcGIS MapPoint to Rhino Point3d
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 internal static Rhino.Geometry.Point3d convertToRhinoPoint(MapPoint p, Rhino.Geometry.Point3d origin) =>
 new Rhino.Geometry.Point3d(p.X - origin.X, p.Y - origin.Y, p.Z - origin.Z);
示例#40
0
        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            //base.DrawViewportWires(args);
            int defaultPointRadius = 2;

            for (int n = 0; n < m_obj.Count; n++)
            {
                object obj = m_obj[n];
                Rhino.DocObjects.ObjectAttributes att = m_att[n].Value;
                if (obj == null)
                {
                    continue;
                }
                Type objectType = obj.GetType();
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Vector))
                {
                    Rhino.Geometry.Vector3d rh_vec = ((Grasshopper.Kernel.Types.GH_Vector)obj).Value;
                    args.Display.DrawArrow(new Rhino.Geometry.Line(new Rhino.Geometry.Point3d(0, 0, 0), new Rhino.Geometry.Point3d(rh_vec)), att.ObjectColor);
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Point))
                {
                    Rhino.Geometry.Point3d rh_point = ((Grasshopper.Kernel.Types.GH_Point)obj).Value;
                    if (att.PlotWeight == 0)
                    {
                        args.Display.DrawPoint(rh_point, Rhino.Display.PointStyle.Simple, defaultPointRadius, att.ObjectColor);
                    }
                    else
                    {
                        args.Display.DrawPoint(rh_point, Rhino.Display.PointStyle.Simple, (int)att.PlotWeight, att.ObjectColor);
                    }
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Line))
                {
                    Rhino.Geometry.Line rh_line = ((Grasshopper.Kernel.Types.GH_Line)obj).Value;
                    if (att.PlotWeight == 0)
                    {
                        args.Display.DrawLine(rh_line, att.ObjectColor);
                    }
                    else
                    {
                        args.Display.DrawLine(rh_line, att.ObjectColor, (int)att.PlotWeight);
                    }
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Mesh))
                {
                    Rhino.Geometry.Mesh           rh_mesh = ((Grasshopper.Kernel.Types.GH_Mesh)obj).Value;
                    Rhino.Display.DisplayMaterial mat     = new Rhino.Display.DisplayMaterial(att.ObjectColor, 0.5);
                    args.Display.DrawMeshShaded(rh_mesh, mat);
                    continue;
                }
                if (objectType == typeof(Grasshopper.Kernel.Types.GH_Curve))
                {
                    //TODO: deal with open polylines, curves, non-planar polycurves, etc
                    Rhino.Geometry.Curve rh_curve = ((Grasshopper.Kernel.Types.GH_Curve)obj).Value;

                    Rhino.Geometry.Polyline rh_pline = new Rhino.Geometry.Polyline();
                    if ((rh_curve.IsClosed) && (rh_curve.IsPlanar()) && (rh_curve.TryGetPolyline(out rh_pline)))
                    {
                        bool fill = true;
                        Rhino.Geometry.Intersect.CurveIntersections iev = Rhino.Geometry.Intersect.Intersection.CurveSelf(rh_curve, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
                        if (iev.Count > 0)
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Found a self-intersecting polygon.  Fills will not be applied.");
                            fill = false;
                        }
                        args.Display.DrawPolygon(rh_pline, att.ObjectColor, false);

                        if (fill)
                        {
                            Rhino.Geometry.Mesh m = Rhino.Geometry.Mesh.CreateFromPlanarBoundary(rh_curve, Rhino.Geometry.MeshingParameters.Smooth);
                            args.Display.DrawMeshShaded(m, new Rhino.Display.DisplayMaterial(att.ObjectColor, 0.5));
                        }
                        continue;
                    }
                }

                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The component does not know how to handle this type of gh_geometry: " + objectType.FullName);
            }
        }
            public Finite_Material(Smart_Material Mat, Rhino.Geometry.Brep Br, Rhino.Geometry.Mesh M, int face_id, Medium_Properties med)
            {
                //Strictly for the flat X,Y case - oversimplified for now.
                Inf_Mat  = Mat;
                Azimuth  = new double[36];
                Altitude = new double[Mat.Angles.Length / 2];
                alpha    = new double[Altitude.Length][][];
                for (int i = 0; i < Altitude.Length; i++)
                {
                    Altitude[i] = Mat.Angles[i].Magnitude;
                }
                for (int i = 0; i < Azimuth.Length; i++)
                {
                    Azimuth[i] = i * 360f / Azimuth.Length;
                }

                //Set up a frequency interpolated Zr for each direction individually.
                Rhino.Geometry.Point3d pt = M.Faces.GetFaceCenter(face_id);

                double[][][] ZrR = new double[Altitude.Length][][], ZrI = new double[Altitude.Length][][];
                double[]     fr  = new double[9];
                for (int k = 0; k < Altitude.Length; k++)
                {
                    ZrR[k]   = new double[Azimuth.Length][];
                    ZrI[k]   = new double[Azimuth.Length][];
                    alpha[k] = new double[Azimuth.Length][];
                    for (int j = 0; j < Azimuth.Length; j++)
                    {
                        ZrR[k][j]   = new double[9];
                        ZrI[k][j]   = new double[9];
                        alpha[k][j] = new double[8];
                    }
                }

                for (int oct = 0; oct < 9; oct++)
                {
                    fr[oct] = 62.5 * Math.Pow(2, oct) / Utilities.Numerics.rt2;
                    System.Numerics.Complex[][] Zr = AbsorptionModels.Operations.Finite_Radiation_Impedance_Rect_Longhand(pt.X, pt.Y, Br, fr[oct], Altitude, Azimuth, med.Sound_Speed(pt));

                    for (int k = 0; k < Zr.Length; k++)
                    {
                        for (int j = 0; j < Zr[k].Length; j++)
                        {
                            ZrR[k][j][oct] = Zr[k][j].Real;
                            ZrI[k][j][oct] = Zr[k][j].Imaginary;
                        }
                    }
                }

                MathNet.Numerics.Interpolation.CubicSpline[][] Zr_r = new MathNet.Numerics.Interpolation.CubicSpline[Altitude.Length][];
                MathNet.Numerics.Interpolation.CubicSpline[][] Zr_i = new MathNet.Numerics.Interpolation.CubicSpline[Altitude.Length][];

                for (int k = 0; k < Zr_r.Length; k++)
                {
                    Zr_r[k] = new MathNet.Numerics.Interpolation.CubicSpline[Azimuth.Length];
                    Zr_i[k] = new MathNet.Numerics.Interpolation.CubicSpline[Azimuth.Length];
                    for (int j = 0; j < Zr_r[k].Length; j++)
                    {
                        //Interpolate over curve real and imaginary Zr here...
                        Zr_r[k][j] = MathNet.Numerics.Interpolation.CubicSpline.InterpolateAkima(fr, ZrR[k][j]);
                        Zr_i[k][j] = MathNet.Numerics.Interpolation.CubicSpline.InterpolateAkima(fr, ZrI[k][j]);
                    }
                }

                for (int k = 0; k < Zr_r.Length; k++)
                {
                    for (int j = 0; j < Zr_r[k].Length; j++)
                    {
                        List <double> freq         = new List <double>();
                        List <double> alpha_interp = new List <double>();
                        for (int l = 0; l < Mat.frequency.Length; l++)
                        {
                            if (Mat.frequency[l] > 10000)
                            {
                                break;
                            }
                            freq.Add(Mat.frequency[l]);
                            alpha_interp.Add(AbsorptionModels.Operations.Finite_Unit_Absorption_Coefficient(Mat.Z[k][j], new System.Numerics.Complex(Zr_r[k][j].Interpolate(Mat.frequency[l]), Zr_i[k][j].Interpolate(Mat.frequency[l])), med.Rho(Utilities.PachTools.RPttoHPt(pt)), med.Sound_Speed(pt)));
                        }
                        MathNet.Numerics.Interpolation.CubicSpline a = MathNet.Numerics.Interpolation.CubicSpline.InterpolateAkima(freq, alpha_interp);
                        for (int oct = 0; oct < 8; oct++)
                        {
                            alpha[k][j][oct] = 1 - a.Integrate(fr[oct], fr[oct + 1]) / (fr[oct + 1] - fr[oct]);
                        }
                    }
                }
            }
    // 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);
    }
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            if (!FriedChiken.isInitialized)
            {
                GH_Point[]      pointList    = new GH_Point[2];
                List <GH_Point> tmpPointList = new List <GH_Point>();
                GH_Curve        c            = new GH_Curve();
                int[]           nEdgeNodes   = new int[_dim];
                DA.GetData(0, ref c);
                DA.GetData(1, ref nEdgeNodes[0]);
                bool x = true, y = true, z = true;
                if (!DA.GetData(2, ref x))
                {
                    return;
                }
                if (!DA.GetData(3, ref y))
                {
                    return;
                }
                if (!DA.GetData(4, ref z))
                {
                    return;
                }
                for (int i = 0; i < _dim; i++)
                {
                    if (nEdgeNodes[i] < 2)
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Integers must be greater than or equal to 2");
                        return;
                    }
                }
                //点群生成
                int nNewNodes = nEdgeNodes[0];
                nElements = nNewNodes - 1;
                mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    Rhino.Geometry.Point3d p = c.Value.PointAt(c.Value.Domain.T0 + (c.Value.Domain.T1 - c.Value.Domain.T0) / nElements * i);
                    particles[i] = new particle(p.X, p.Y, p.Z);
                }
                pS = new GH_particleSystem(particles);
                node[] lNodes = new node[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lNodes[i] = new node(i);
                    lNodes[i].copyFrom(pS.Value.particles);
                }
                fixedNodes fN = new fixedNodes(x, y, z);

                for (int i = 0; i < nNewNodes; i++)
                {
                    fN.addNode(lNodes[i]);
                }
                pS.Value.addObject(fN);
                lGeometry = new Rhino.Geometry.Point3d[nNewNodes];
                for (int i = 0; i < nNewNodes; i++)
                {
                    lGeometry[i] = new Rhino.Geometry.Point3d(particles[i][0], particles[i][1], particles[i][2]);
                }
            }

            DA.SetData(0, pS);
        }
示例#44
0
 /// <summary>
 /// Gets location and vectors of this camera.
 /// </summary>
 /// <param name="location">An out parameter that will be filled with a point during the call.</param>
 /// <param name="cameraX">An out parameter that will be filled with the X vector during the call.</param>
 /// <param name="cameraY">An out parameter that will be filled with the Y vector during the call.</param>
 /// <param name="cameraZ">An out parameter that will be filled with the Z vector during the call.</param>
 /// <returns>true if current camera orientation is valid; otherwise false.</returns>
 public bool GetCameraFrame(out Rhino.Geometry.Point3d location,  out Rhino.Geometry.Vector3d cameraX, out Rhino.Geometry.Vector3d cameraY, out Rhino.Geometry.Vector3d cameraZ)
 {
   location = new Rhino.Geometry.Point3d(0, 0, 0);
   cameraX = new Rhino.Geometry.Vector3d(0, 0, 0);
   cameraY = new Rhino.Geometry.Vector3d(0, 0, 0);
   cameraZ = new Rhino.Geometry.Vector3d(0, 0, 0);
   IntPtr pConstThis = ConstPointer();
   return UnsafeNativeMethods.ON_Viewport_GetCameraFrame(pConstThis, ref location, ref cameraX, ref cameraY, ref cameraZ);
 }
                private void Build_Mesh_Sections()
                {
                    int ct = -1;
                    m_templateX = new Rhino.Geometry.Mesh[2];
                    m_templateX[0] = new Rhino.Geometry.Mesh();
                    m_templateX[1] = new Rhino.Geometry.Mesh();
                    m_templateY = new Rhino.Geometry.Mesh[2];
                    m_templateY[0] = new Rhino.Geometry.Mesh();
                    m_templateY[1] = new Rhino.Geometry.Mesh();
                    m_templateZ = new Rhino.Geometry.Mesh[2];
                    m_templateZ[0] = new Rhino.Geometry.Mesh();
                    m_templateZ[1] = new Rhino.Geometry.Mesh();

                    double rt2 = Math.Sqrt(2);

                    for (int i = 0; i < 2; i++)
                    {
                        ct = -1;
                        for (int y = 0; y < PFrame[i].Length; y++)
                        {
                            for (int z = 0; z < PFrame[i][y].Length; z++)
                            {
                                ct++;
                                Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(PFrame[0][0][0].Pt.x, PFrame[i][y][z].Pt.y, PFrame[i][y][z].Pt.z);
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, dy, dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, dy, -dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, -dy, -dz)));
                                m_templateX[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, -dy, dz)));
                                int ct4 = ct * 4;
                                m_templateX[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        ct = -1;

                        for (int x = 0; x < PFrame.Length; x++)
                        {
                            for (int z = 0; z < PFrame[x][i].Length; z++)
                            {
                                ct++;
                                Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(PFrame[x][i][z].Pt.x, PFrame[0][0][0].Pt.y, PFrame[x][i][z].Pt.z);
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(2 * dx / rt2, 0, 0)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, 0, -dz)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(2 * -dx / rt2, 0, 0)));
                                m_templateY[i].Vertices.Add((Rhino.Geometry.Point3d)(pt + new Rhino.Geometry.Point3d(0, 0, dz)));
                                int ct4 = ct * 4;
                                m_templateY[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        ct = -1;

                        for (int x = 0; x < PFrame.Length; x++)
                        {
                            for (int y = 0; y < PFrame[x].Length; y++)
                            {
                                ct++;

                                Rhino.Geometry.Point3d pt = new Rhino.Geometry.Point3d(PFrame[x][y][i].Pt.x, PFrame[x][y][i].Pt.y, PFrame[0][0][0].Pt.z);

                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(2 * dx / rt2, 0, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(0, -dy, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(-2 * dx / rt2, 0, 0)));
                                m_templateZ[i].Vertices.Add((Rhino.Geometry.Point3d)(pt - new Rhino.Geometry.Point3d(0, dy, 0)));
                                int ct4 = ct * 4;
                                m_templateZ[i].Faces.AddFace(ct4, ct4 + 1, ct4 + 2, ct4 + 3);
                            }
                        }

                        m_templateX[i].Normals.ComputeNormals();
                        m_templateX[i].FaceNormals.ComputeFaceNormals();
                        m_templateY[i].Normals.ComputeNormals();
                        m_templateY[i].FaceNormals.ComputeFaceNormals();
                        m_templateZ[i].Normals.ComputeNormals();
                        m_templateZ[i].FaceNormals.ComputeFaceNormals();
                    }
                }
示例#46
0
    private void GenerateGeo()
    {
        model = new Rhino.FileIO.File3dm();

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

        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);

            //model.Objects.AddCurve(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)
        {
            model.Objects.AddBrep(brep);

            var brep2  = brep.CapPlanarHoles(0.001);
            var meshes = MeshCompute.CreateFromBrep(brep2);
            meshList.AddRange(meshes);
        }

        //convert rhino mesh into unity mesh
        foreach (var mesh in meshList)
        {
            Mesh meshObj = new Mesh();

            var vertices  = new List <Vector3>();
            var triangles = new List <int>();
            var normals   = new List <Vector3>();

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

            foreach (var meshFace in mesh.Faces)
            {
                if (meshFace.IsTriangle)
                {
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.B);
                    triangles.Add(meshFace.A); //incase for the backward
                }
                else if (meshFace.IsQuad)      //two triangles to see quad
                {
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.B);
                    triangles.Add(meshFace.A);
                    triangles.Add(meshFace.D);
                    triangles.Add(meshFace.C);
                    triangles.Add(meshFace.A);
                }
            }

            foreach (var meshNormal in mesh.Normals)
            {
                normals.Add(new Vector3(meshNormal.X, meshNormal.Z, meshNormal.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;
        }

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

        model.Write(path, 6);
    }
示例#47
0
        private void AnimateRestoreView()
        {
            FastDrawing = true;
            var restoreViewCurrentTime = DateTime.Now;

            var    currentTime              = restoreViewCurrentTime;
            var    startTime                = RestoreViewStartTime;
            var    timeElapsed              = currentTime.Subtract(startTime);
            var    timeElapsedInMs          = timeElapsed.TotalMilliseconds;
            var    totalTimeOfAnimationInMs = RestoreViewTotalTime.TotalMilliseconds;
            double percentCompleted         = timeElapsedInMs / totalTimeOfAnimationInMs;

            if (percentCompleted > 1)
            {
                // Animation is completed. Perform one last draw.
                percentCompleted            = 1;
                IsInAnimatedRestoreView     = false;
                View.UserInteractionEnabled = true;
                CameraIsAtInitialPosition   = !ShouldStartRestoreToInitialPosition;
                AnimationTimer.Invalidate();
            }

            // Get some data from the starting view
            Rhino.Geometry.Point3d sourceTarget = RestoreViewStartViewport.TargetPoint;
            Rhino.Geometry.Point3d sourceCamera = RestoreViewStartViewport.CameraLocation;
            double sourceDistance = sourceCamera.DistanceTo(sourceTarget);

            Rhino.Geometry.Vector3d sourceUp = RestoreViewStartViewport.CameraUp;
            sourceUp.Unitize();

            // Get some data from the ending view
            Rhino.Geometry.Point3d targetTarget = RestoreViewFinishViewport.TargetPoint;
            Rhino.Geometry.Point3d targetCamera = RestoreViewFinishViewport.CameraLocation;
            double targetDistance = targetCamera.DistanceTo(targetTarget);

            Rhino.Geometry.Vector3d targetCameraDir = targetCamera - targetTarget;
            Rhino.Geometry.Vector3d targetUp        = RestoreViewFinishViewport.CameraUp;
            targetUp.Unitize();

            // Adjust the target camera location so that the starting camera to target distance
            // and the ending camera to target distance are the same.  Doing this will calculate
            // a constant rotational angular momentum when tweening the camera location.
            // Further down we independently tween the camera to target distance.
            targetCameraDir.Unitize();
            targetCameraDir *= sourceDistance;
            targetCamera     = targetCameraDir + targetTarget;

            // calculate interim viewport values
            double frameDistance = ViewportInfoExtensions.CosInterp(sourceDistance, targetDistance, percentCompleted);

            Rhino.Geometry.Point3d frameTarget = new Rhino.Geometry.Point3d();

            frameTarget.X = ViewportInfoExtensions.CosInterp(sourceTarget.X, targetTarget.X, percentCompleted);
            frameTarget.Y = ViewportInfoExtensions.CosInterp(sourceTarget.Y, targetTarget.Y, percentCompleted);
            frameTarget.Z = ViewportInfoExtensions.CosInterp(sourceTarget.Z, targetTarget.Z, percentCompleted);

            var origin = Rhino.Geometry.Point3d.Origin;

            Rhino.Geometry.Point3d  frameCamera    = origin + (ViewportInfoExtensions.Slerp((sourceCamera - origin), (targetCamera - origin), percentCompleted));
            Rhino.Geometry.Vector3d frameCameraDir = frameCamera - frameTarget;

            // adjust the camera location along the camera direction vector to preserve the target location and the camera distance
            frameCameraDir.Unitize();
            frameCameraDir *= frameDistance;
            frameCamera     = frameCameraDir + frameTarget;

            Rhino.Geometry.Vector3d frameUp = new Rhino.Geometry.Vector3d(ViewportInfoExtensions.Slerp(sourceUp, targetUp, percentCompleted));

            if (percentCompleted >= 1)
            {
                // put the last redraw at the exact end point to eliminate any rounding errors
                Camera.SetTarget(RestoreViewFinishViewport.TargetPoint, RestoreViewFinishViewport.CameraLocation, RestoreViewFinishViewport.CameraUp);
            }
            else
            {
                Camera.SetTarget(frameTarget, frameCamera, frameUp);
            }

            SetFrustum(Camera, App.Manager.CurrentModel.BBox);

            View.SetNeedsDisplay();

            if (!IsInAnimatedRestoreView)
            {
                // FastDrawing is still enabled and we just scheduled a draw of the model at the final location.
                // This entirely completes the animation. Now schedule one more redraw of the model with FastDrawing disabled
                // and this redraw will be done at exactly the same postion.  This prevents the final animation frame
                // from jumping to the final location because the final draw will take longer with FastDrawing disabled.
                PerformSelector(new Selector("RedrawDetailed"), null, 0.05);
            }
        }
示例#48
0
 /// <summary>
 /// Rotates a viewport about an axis relative to a center point
 /// </summary>
 public static void RotateView(this ViewportInfo viewport, Rhino.Geometry.Vector3d axis, Rhino.Geometry.Point3d center, double angle)
 {
     Rhino.Geometry.Point3d   cameraLocation = viewport.CameraLocation;
     Rhino.Geometry.Vector3d  cameraY        = viewport.CameraY;
     Rhino.Geometry.Vector3d  cameraZ        = viewport.CameraZ;
     Rhino.Geometry.Transform rotation       = Rhino.Geometry.Transform.Rotation(angle, axis, center);
     cameraLocation = rotation * cameraLocation;
     cameraY        = rotation * cameraY;
     cameraZ        = -(rotation * cameraZ);
     viewport.SetCameraLocation(cameraLocation);
     viewport.SetCameraDirection(cameraZ);
     viewport.SetCameraUp(cameraY);
 }
示例#49
0
        public static string makeDocBox()
        {
            try
            {
                //If docBox has not been created, create it and place it on its natalus layer.

                /* Abandoning layer idea for now. Not working as intended.
                 * Rhino.DocObjects.Layer layer_D10 = new Rhino.DocObjects.Layer();
                 * int layer_D10_index = -1;
                 *
                 * if (RhinoDoc.ActiveDoc.Layers.FindName("D10").Index < 0)
                 * {
                 *  RhinoDoc.ActiveDoc.Layers.Add(layer_D10);
                 *  layer_D10_index = layer_D10.Index;
                 * }
                 * else
                 * {
                 *  layer_D10 = RhinoDoc.ActiveDoc.Layers.FindName("D10");
                 *  layer_D10_index = layer_D10.Index;
                 * }
                 */

                //Set initial dimensions and record to D01 if D01 does not exist.
                string D01_Path = utils.file_structure.getPathFor("D01");
                string D20_Path = utils.file_structure.getPathFor("D20");

                double docBox_width  = 12;
                double docBox_height = 12;

                Rhino.Geometry.Point3d refPoint = new Rhino.Geometry.Point3d(0, 0, 0);

                //Check if previous dim configuration existed.
                if (System.IO.File.Exists(D01_Path) == true)
                {
                    string[] dims = System.IO.File.ReadAllText(D01_Path).Split('|');

                    docBox_width  = Convert.ToDouble(dims[0]);
                    docBox_height = Convert.ToDouble(dims[1]);
                }
                else
                {
                    System.IO.File.WriteAllText(D01_Path, "12|12");
                }

                double adjust = 0;

                if (System.IO.File.Exists(D20_Path) == true)
                {
                    string[] coords = System.IO.File.ReadAllText(D20_Path).Split(',');

                    refPoint.X = Convert.ToDouble(coords[0]);
                    refPoint.Y = Convert.ToDouble(coords[1]);

                    adjust = docBox_height;
                }
                else if (System.IO.File.Exists(D20_Path) == false)
                {
                    adjust = 0;
                }

                Rhino.Geometry.Plane docBox_plane = Rhino.Geometry.Plane.WorldXY;
                docBox_plane.OriginX = refPoint.X;
                docBox_plane.OriginY = refPoint.Y - adjust;

                Rhino.Geometry.Rectangle3d docBox = new Rhino.Geometry.Rectangle3d(docBox_plane, docBox_width, docBox_height);

                Rhino.DocObjects.ObjectAttributes docBox_attributes = new Rhino.DocObjects.ObjectAttributes();

                //Until layer process resolved, docBox to be on any layer.
                int activeIndex = RhinoDoc.ActiveDoc.Layers.CurrentLayerIndex;
                docBox_attributes.LayerIndex = activeIndex;

                //(Rhino 5) Convert docBox Rectangle3D to polyline curve.
                Rhino.Geometry.Polyline docBoxPolyline = docBox.ToPolyline();

                //Freeze updating while docBox is created.
                string x10_path = utils.file_structure.getPathFor("x10");
                System.IO.File.WriteAllText(x10_path, "false");

                //Determine GUID and record to D10.
                Guid newGuid = RhinoDoc.ActiveDoc.Objects.AddPolyline(docBoxPolyline);

                Rhino.DocObjects.ObjRef      docBoxObj   = new Rhino.DocObjects.ObjRef(newGuid);
                Rhino.DocObjects.CurveObject docBoxCurve = docBoxObj.Object() as Rhino.DocObjects.CurveObject;

                string docBoxGUID = newGuid.ToString();

                string D10_Path = utils.file_structure.getPathFor("D10");
                if (System.IO.File.Exists(D10_Path) && System.IO.File.ReadAllText(D10_Path) != "")
                {
                    string D11_Path = utils.file_structure.getPathFor("D11");
                    System.IO.File.WriteAllText(D11_Path, System.IO.File.ReadAllText(D10_Path));
                }
                System.IO.File.WriteAllText(D10_Path, docBoxGUID);

                //Set curve to Illustrator orange.
                System.Drawing.Color docBoxColor = System.Drawing.Color.FromArgb(240, 120, 6);

                docBoxCurve.Attributes.ColorSource      = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
                docBoxCurve.Attributes.ObjectColor      = docBoxColor;
                docBoxCurve.Attributes.PlotColorSource  = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject;
                docBoxCurve.Attributes.PlotColor        = docBoxColor;
                docBoxCurve.Attributes.PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject;
                docBoxCurve.Attributes.PlotWeight       = 1.5;

                docBoxCurve.CommitChanges();

                //Label it!
                Rhino.Geometry.TextEntity label = new Rhino.Geometry.TextEntity();

                label.TextHeight = .4;

                Rhino.Geometry.Plane label_plane = Rhino.Geometry.Plane.WorldXY;
                label_plane.OriginX = docBox_plane.OriginX;
                label_plane.OriginY = docBox_plane.OriginY - .4 - .1;
                label.Plane         = label_plane;

                label.Text = ("Linked Illustrator Artboard");

                Guid docBoxLabel = RhinoDoc.ActiveDoc.Objects.AddText(label);

                Rhino.DocObjects.ObjRef     labelObj  = new Rhino.DocObjects.ObjRef(docBoxLabel);
                Rhino.DocObjects.TextObject labelText = labelObj.Object() as Rhino.DocObjects.TextObject;

                labelText.Attributes.ColorSource     = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
                labelText.Attributes.ObjectColor     = docBoxColor;
                labelText.Attributes.PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject;
                labelText.Attributes.PlotColor       = docBoxColor;

                labelText.CommitChanges();

                string docBoxLabelGUID = docBoxLabel.ToString();

                string D30_Path = utils.file_structure.getPathFor("D30");
                if (System.IO.File.Exists(D30_Path) && System.IO.File.ReadAllText(D30_Path) != "")
                {
                    string D31_Path = utils.file_structure.getPathFor("D31");
                    System.IO.File.WriteAllText(D31_Path, System.IO.File.ReadAllText(D30_Path));
                }
                System.IO.File.WriteAllText(D30_Path, docBoxLabelGUID);


                //Unfreeze updating.
                System.IO.File.WriteAllText(x10_path, "true");

                //Update illustrator boundaries.
                int    conversion = utils.units.conversion();
                string jsxPath    = utils.file_structure.getJavascriptPath();

                echo.interop echo = new echo.interop();
                echo.docBounds(docBox_width, System.Math.Abs(docBox_height), conversion, jsxPath);

                return(docBoxGUID);
            }
            catch (Exception e)
            {
                debug.alert(e.Message + " | " + e.Source);

                return("error");
            }
        }
示例#50
0
        /// <summary>
        /// Sets the viewport's camera location, target and up vector
        /// </summary>
        public static void SetTarget(this ViewportInfo viewport, Rhino.Geometry.Point3d targetLocation, Rhino.Geometry.Point3d cameraLocation, Rhino.Geometry.Vector3d cameraUp)
        {
            Rhino.Geometry.Vector3d cameraDirection = targetLocation - cameraLocation;
            cameraDirection.Unitize();

            if (!viewport.CameraDirection.IsTiny())
            {
                Rhino.Geometry.Vector3d cameraDirection0 = -viewport.CameraZ;
                Rhino.Geometry.Vector3d cameraY          = viewport.CameraY;
                const double            tiltAngle        = 0;

                viewport.SetCameraLocation(cameraLocation);
                viewport.SetCameraDirection(cameraDirection);

                bool didSetTarget = false;
                didSetTarget = viewport.SetCameraUp(cameraUp);

                if (!didSetTarget)
                {
                    didSetTarget = viewport.SetCameraUp(cameraY);
                    cameraUp     = cameraY;
                }

                if (!didSetTarget)
                {
                    Rhino.Geometry.Vector3d rotationAxis = Rhino.Geometry.Vector3d.CrossProduct(cameraDirection0, cameraDirection);
                    double sinAngle = rotationAxis.Length;
                    double cosAngle = cameraDirection0 * cameraDirection;
                    Rhino.Geometry.Transform rot = Rhino.Geometry.Transform.Rotation(sinAngle, cosAngle, rotationAxis, Rhino.Geometry.Point3d.Origin);
                    cameraUp     = rot * cameraY;
                    didSetTarget = viewport.SetCameraUp(cameraUp);
                }

                if (didSetTarget)
                {
                    // Apply tilt angle to new camera and target location
                    if (Math.Abs(tiltAngle) > 1.0e-6)
                    {
                        Rhino.Geometry.Transform rot = Rhino.Geometry.Transform.Rotation(tiltAngle, -cameraDirection0, cameraLocation);
                        cameraUp     = rot * cameraUp;
                        didSetTarget = viewport.SetCameraUp(cameraUp);
                    }

                    if (didSetTarget)
                    {
                        viewport.TargetPoint = targetLocation;
                    }
                }
            }
        }
示例#51
0
        /// <summary>
        /// Use SetFirstPoint to specify the line's starting point and skip
        /// the start point interactive picking
        /// </summary>
        /// <param name="point"></param>
        public void SetFirstPoint(Rhino.Geometry.Point3d point)
        {
            IntPtr pThis = NonConstPointer();

            UnsafeNativeMethods.CArgsRhinoGetLine_SetFirstPoint(pThis, point);
        }