コード例 #1
0
ファイル: FromRhino.cs プロジェクト: BHoM/Rhinoceros_Toolkit
        /***************************************************/

        public static BHG.Cylinder FromRhino(this RHG.Cylinder cylinder)
        {
            BHG.Point centre = cylinder.Center.FromRhino() + cylinder.Axis.FromRhino() * cylinder.Height1;
            return(new BHG.Cylinder {
                Centre = centre, Axis = cylinder.Axis.FromRhino(), Height = cylinder.TotalHeight, Radius = cylinder.CircleAt(0.0).Radius
            });
        }
コード例 #2
0
        public List <Brep> ComputeAnchorGeometry()
        {
            Vector3d NormNormalVec = NormalVec / NormalVec.Length;
            Point3d  A             = Origin + NormNormalVec * Height1 / 2;
            Point3d  B             = Origin - NormNormalVec * Height1 / 2;
            Point3d  C             = Origin - NormNormalVec * (Height1 / 2 + Height2);

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

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

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

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

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

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

            return(displayGeometry);
        }
コード例 #3
0
        static NurbsSurface ToRhinoCylindricalSurface(NXOpen.Face face, FaceEx.FaceData faceData)
        {
            NXOpen.Point3d top;           // 圆柱顶点

            double radius;                // 圆柱半径

            NXOpen.Point3d bottom;        // 圆柱底面中心点

            var faceBoundingBox = face.GetAlignedBoundingBox(faceData.Direction);

            double totalHeight = faceBoundingBox.Height;          // 圆柱总高度

            if (face.GetEdges().Length == 2 && face.GetEdges().All(obj => obj.SolidEdgeType == NXOpen.Edge.EdgeType.Circular))
            {
                // 未修剪的圆柱
                TheUfSession.Eval.Initialize2(face.GetEdges()[0].Tag, out var edgeEvaluator);
                TheUfSession.Eval.AskArc(edgeEvaluator, out var arc1);
                TheUfSession.Eval.Free(edgeEvaluator);

                TheUfSession.Eval.Initialize2(face.GetEdges()[1].Tag, out edgeEvaluator);
                TheUfSession.Eval.AskArc(edgeEvaluator, out var arc2);
                TheUfSession.Eval.Free(edgeEvaluator);

                if (arc2.center.ToPoint3d().Subtract(arc1.center.ToPoint3d()).GetUnitVector().EqualsTo(faceData.Direction.GetUnitVector()))
                {
                    bottom = arc1.center.ToPoint3d();
                }
                else
                {
                    bottom = arc2.center.ToPoint3d();
                }

                top = bottom.Move(faceBoundingBox.HeightDirection, totalHeight);

                radius = arc1.radius;
            }
            else
            {
                var topExtremePt = WorkPart.MeasureManager.MeasureRectangularExtreme(face, faceBoundingBox.HeightDirection, faceBoundingBox.LengthDirection, faceBoundingBox.WidthDirection);

                var distToFacePoint = topExtremePt.DistanceTo(faceData.Point, faceData.Direction);

                top = faceData.Point.Move(faceBoundingBox.HeightDirection, distToFacePoint);

                bottom = top.Move(faceBoundingBox.HeightDirection.Reverse(), totalHeight);

                radius = faceData.Radius;
            }

            Circle baseCircle = new Circle(new Plane(bottom.ToRhino(), faceBoundingBox.HeightDirection.ToRhino()), radius);

            var cyl = new Rhino.Geometry.Cylinder(baseCircle, totalHeight);

            return(cyl.ToNurbsSurface());
        }
コード例 #4
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;
 }
コード例 #5
0
 /// <summary>
 /// Draw a wireframe cylinder.
 /// </summary>
 /// <param name="cylinder">Cylinder to draw.</param>
 /// <param name="color">Color to draw with.</param>
 /// <param name="thickness">Thickness (in pixels) of cylinder wires.</param>
 public void DrawCylinder(Cylinder cylinder, System.Drawing.Color color, int thickness)
 {
   int argb = color.ToArgb();
   UnsafeNativeMethods.CRhinoDisplayPipeline_DrawCylinder(m_ptr, ref cylinder, argb, thickness);
 }
コード例 #6
0
 /// <summary>
 /// Gets an extrusion form of a pipe.
 /// </summary>
 /// <param name="cylinder">IsFinite must be true.</param>
 /// <param name="otherRadius">
 /// If cylinder.Radius is less than other radius, then the cylinder will be the inside
 /// of the pipe.
 /// </param>
 /// <param name="capBottom">If true, the end at cylinder.Height1 will be capped.</param>
 /// <param name="capTop">If true, the end at cylinder.Height2 will be capped.</param>
 /// <returns>Extrusion on success. null on failure.</returns>
 public static Extrusion CreatePipeExtrusion(Cylinder cylinder, double otherRadius, bool capTop, bool capBottom)
 {
   IntPtr pExtrusion = UnsafeNativeMethods.ON_Extrusion_CreatePipe(ref cylinder, otherRadius, capBottom, capTop);
   return IntPtr.Zero == pExtrusion ? null : new Extrusion(pExtrusion, null);
 }
コード例 #7
0
 /// <summary>
 /// Gets an extrusion form of a cylinder.
 /// </summary>
 /// <param name="cylinder">IsFinite must be true.</param>
 /// <param name="capBottom">If true, the end at cylinder.Height1 will be capped.</param>
 /// <param name="capTop">If true, the end at cylinder.Height2 will be capped.</param>
 /// <returns>Extrusion on success. null on failure.</returns>
 public static Extrusion CreateCylinderExtrusion(Cylinder cylinder, bool capBottom, bool capTop)
 {
   IntPtr pExtrusion = UnsafeNativeMethods.ON_Extrusion_CreateCylinder(ref cylinder, capBottom, capTop);
   return IntPtr.Zero == pExtrusion ? null : new Extrusion(pExtrusion, null);
 }
コード例 #8
0
ファイル: rhinosdkgetpoint.cs プロジェクト: kalvo/rhinocommon
 /// <summary>Constrains the picked point to lie on a cylinder.</summary>
 /// <param name="cylinder">A cylinder to use as constraint.</param>
 /// <returns>true if constraint could be applied.</returns>
 public bool Constrain(Cylinder cylinder)
 {
   IntPtr ptr = NonConstPointer();
   return UnsafeNativeMethods.CRhinoGetPoint_Constrain6(ptr, ref cylinder);
 }
コード例 #9
0
 /// <summary>Create a cylindrical projection texture mapping.</summary>
 /// <param name="cylinder">
 /// cylinder in world space used to define a cylindrical coordinate system.
 /// The angular parameter maps (0,2pi) to texture "u" (0,1), The height
 /// parameter maps (height[0],height[1]) to texture "v" (0,1), and the
 /// radial parameter maps (0,r) to texture "w" (0,1).
 /// </param>
 /// <param name="capped">
 /// If true, the cylinder is treated as a finite capped cylinder
 /// </param>
 /// <remarks>
 /// When the cylinder is capped and m_texture_space = divided, the
 /// cylinder is mapped to texture space as follows:
 /// The side is mapped to 0 &lt;= "u" &lt;= 2/3.
 /// The bottom is mapped to 2/3 &lt;= "u" &lt;= 5/6.
 /// The top is mapped to 5/6 &lt;= "u" &lt;= 5/6.
 /// This is the same convention box mapping uses.
 /// </remarks>
 /// <returns>TextureMapping instance if input is valid</returns>
 public static TextureMapping CreateCylinderMapping(Cylinder cylinder, bool capped)
 {
   TextureMapping rc = new TextureMapping();
   IntPtr pMapping = rc.NonConstPointer();
   if (!UnsafeNativeMethods.ON_TextureMapping_SetCylinderMapping(pMapping, ref cylinder, capped))
   {
     rc.Dispose();
     rc = null;
   }
   return rc;
 }
コード例 #10
0
 /// <summary>Tests a surface to see if it is a portion of a cylinder within RhinoMath.ZeroTolerance and return the cylinder.</summary>
 /// <param name="cylinder">On success, the cylinder parameters are filled in.</param>
 /// <returns>true if the surface is a portion of a cylinder.</returns>
 public bool TryGetCylinder(out Cylinder cylinder)
 {
   return TryGetCylinder(out cylinder, RhinoMath.ZeroTolerance);
 }
コード例 #11
0
        /// <summary>
        /// Gets an extrusion form of a pipe.
        /// </summary>
        /// <param name="cylinder">IsFinite must be true.</param>
        /// <param name="otherRadius">
        /// If cylinder.Radius is less than other radius, then the cylinder will be the inside
        /// of the pipe.
        /// </param>
        /// <param name="capBottom">If true, the end at cylinder.Height1 will be capped.</param>
        /// <param name="capTop">If true, the end at cylinder.Height2 will be capped.</param>
        /// <returns>Extrusion on success. null on failure.</returns>
        public static Extrusion CreatePipeExtrusion(Cylinder cylinder, double otherRadius, bool capTop, bool capBottom)
        {
            IntPtr ptr_new_extrusion = UnsafeNativeMethods.ON_Extrusion_CreatePipe(ref cylinder, otherRadius, capBottom, capTop);

            return(IntPtr.Zero == ptr_new_extrusion ? null : new Extrusion(ptr_new_extrusion, null));
        }
コード例 #12
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //declare and set primary variables

            List<Curve> L = new List<Curve>();
            int S = 0;
            List<double> Rs = new List<double>();
            List<double> Re = new List<double>();
            double D = 0;
            double ND = 0;
            bool O = false;

            if (!DA.GetDataList(0, L)) { return; }
            if (!DA.GetData(1, ref S)) { return; }
            if (!DA.GetDataList(2, Rs)) { return; }
            if (!DA.GetDataList(3, Re)) { return; }
            if (!DA.GetData(4, ref ND)) { return; }
            if (!DA.GetData(5, ref D)) { return; }
            if (!DA.GetData(6, ref O)) { return; }

            if (L == null || L.Count == 0) { return; }
            if (S < 3) { return; }
            if (Rs == null || Rs.Count == 0 || Rs.Contains(0)) { return; }
            if (Re == null || Re.Count == 0 || Rs.Contains(0)) { return; }
            if (D == 0) { return; }

            //declare node and strut lists and reference lookups

            double Sides = (double)S;

            List<Point3d> Nodes = new List<Point3d>();
            List<List<int>> NodeStruts = new List<List<int>>();

            List<Curve> Struts = new List<Curve>();
            List<int> StrutNodes = new List<int>();
            List<double> StrutRadii = new List<double>();

            double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

            //set the index counter for matching start and end radii from input list
            int IdxL = 0;

            //register unique nodes and struts, with reference lookups
            //each full strut is broken into two half-struts, with the even-indexed
            //element being the start point, and the odd-indexed element being the end point

            //initialise first node
            Nodes.Add(L[0].PointAtStart);
            NodeStruts.Add(new List<int>());

            Rhino.Collections.Point3dList NodeLookup = new Rhino.Collections.Point3dList(Nodes);

            foreach (Curve StartL in L)
            {
                double StrutStartRadius = 0;
                if (Rs.Count - 1 > IdxL) StrutStartRadius = Rs[IdxL];
                else StrutStartRadius = Rs.Last();

                double StrutEndRadius = 0;
                if (Re.Count - 1 > IdxL) StrutEndRadius = Re[IdxL];
                else StrutEndRadius = Re.Last();

                Point3d StrutCenter = new Point3d((StartL.PointAtStart + StartL.PointAtEnd) / 2);

                int StartTestIdx = NodeLookup.ClosestIndex(StartL.PointAtStart);
                if (Nodes[StartTestIdx].DistanceTo(StartL.PointAtStart) < tol)
                {
                    NodeStruts[StartTestIdx].Add(Struts.Count);
                    StrutNodes.Add(StartTestIdx);
                }
                else
                {
                    StrutNodes.Add(Nodes.Count);
                    Nodes.Add(StartL.PointAtStart);
                    NodeLookup.Add(StartL.PointAtStart);
                    NodeStruts.Add(new List<int>());
                    NodeStruts.Last().Add(Struts.Count());
                }
                Struts.Add(new LineCurve(StartL.PointAtStart, StrutCenter));
                StrutRadii.Add(StrutStartRadius);

                int EndTestIdx = NodeLookup.ClosestIndex(StartL.PointAtEnd);
                if (Nodes[EndTestIdx].DistanceTo(StartL.PointAtEnd) < tol)
                {
                    NodeStruts[EndTestIdx].Add(Struts.Count);
                    StrutNodes.Add(EndTestIdx);
                }
                else
                {
                    StrutNodes.Add(Nodes.Count);
                    Nodes.Add(StartL.PointAtEnd);
                    NodeLookup.Add(StartL.PointAtEnd);
                    NodeStruts.Add(new List<int>());
                    NodeStruts.Last().Add(Struts.Count);
                }
                Struts.Add(new LineCurve(StartL.PointAtEnd, StrutCenter));
                StrutRadii.Add(StrutEndRadius);

                IdxL += 1;
            }

            Plane[] StrutPlanes = new Plane[Struts.Count]; //base plane for each strut
            double[] PlaneOffsets = new double[Struts.Count]; //distance for each base plane to be set from node
            Point3d[,] StrutHullVtc = new Point3d[Struts.Count, S]; //two-dimensional array for vertices along each strut for executing hull
            bool[] StrutSolo = new bool[Struts.Count]; //tag for struts that don't share a node with other struts (ends)

            Mesh Hulls = new Mesh(); //main output mesh

            //cycle through each node to generate hulls
            for (int NodeIdx = 0; NodeIdx < Nodes.Count; NodeIdx++)
            {
                List<int> StrutIndices = NodeStruts[NodeIdx];
                double MinOffset = 0;
                double MaxRadius = 0;

                //orientation & size drivers for knuckle vertices
                List<Vector3d> Knuckles = new List<Vector3d>();
                double KnuckleMin = 0;

                //compare all unique combinations of struts in a given node to calculate plane offsets for
                //hulling operations and for adjusting vertices to potential non-convex hulls
                for (int I1 = 0; I1 < StrutIndices.Count - 1; I1++)
                {
                    for (int I2 = I1 + 1; I2 < StrutIndices.Count; I2++)
                    {
                        //identify minimum offset distances for calculating hulls by comparing each outgoing strut to each other
                        double R1 = StrutRadii[StrutIndices[I1]] / Math.Cos(Math.PI / S);
                        double R2 = StrutRadii[StrutIndices[I2]] / Math.Cos(Math.PI / S);
                        double Radius = Math.Max(R1, R2);
                        double Theta = Vector3d.VectorAngle(Struts[StrutIndices[I1]].TangentAtStart, Struts[StrutIndices[I2]].TangentAtStart);
                        double TestOffset = Radius * Math.Cos(Theta * 0.5) / Math.Sin(Theta * 0.5);
                        if (TestOffset > MinOffset) MinOffset = TestOffset;
                        if (MaxRadius < Radius) MaxRadius = Radius;
                        //set offsets for shrinking hull vertices into a non-convex hull based on desired node offsets (ND) and adjacent struts
                        double Offset1 = 0;
                        double Offset2 = 0;

                        //calculates final offsets for potential shrinking of nodes into non-convex hull
                        ExoTools.OffsetCalculator(Theta, R1, R2, ref Offset1, ref Offset2);

                        if (PlaneOffsets[StrutIndices[I1]] < Offset1) PlaneOffsets[StrutIndices[I1]] = Math.Max(Offset1, ND);
                        if (PlaneOffsets[StrutIndices[I2]] < Offset2) PlaneOffsets[StrutIndices[I2]] = Math.Max(Offset2, ND);

                        //set offsets for knuckle to be the size of the smallest outgoing strut radius
                        double KnuckleMinSet = Math.Min(StrutRadii[StrutIndices[I1]], StrutRadii[StrutIndices[I2]]);
                        if (I1 == 0 || KnuckleMin > KnuckleMinSet) KnuckleMin = KnuckleMinSet;
                    }
                }

                //ensures that if a two struts are linear to one another in a two-strut node that there is an offset for hulling
                if (MinOffset < RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) MinOffset = MaxRadius * 0.5;

                //direction for dealing with struts at ends
                if (StrutIndices.Count == 1)
                {
                    PlaneOffsets[StrutIndices[0]] = 0;
                    //PlaneOffsets[StrutIndices[0]] = ND;
                    if (O) StrutSolo[StrutIndices[0]] = true;
                }

                //build base planes, offset them for hulling, and array hull vertices for each strut
                for (int I1 = 0; I1 < StrutIndices.Count; I1++)
                {
                    //build base planes
                    Curve Strut = Struts[StrutIndices[I1]];
                    Plane StrutPlane;

                    //sets the strut plane
                    if (StrutIndices[I1] % 2 == 0) Strut.PerpendicularFrameAt(0, out StrutPlane);
                    else
                    {
                        Curve LookupStrut = Struts[StrutIndices[I1] - 1];
                        LookupStrut.PerpendicularFrameAt(0, out StrutPlane);
                    }

                    //offset planes for hulling
                    StrutPlane.Origin = Strut.PointAtStart + Strut.TangentAtStart * MinOffset;
                    double StrutRadius = StrutRadii[StrutIndices[I1]];

                    //add strut tangent to list of knuckle orientation vectors
                    Knuckles.Add(-Strut.TangentAtStart);

                    //add hulling vertices
                    for (int HV = 0; HV < S; HV++) StrutHullVtc[StrutIndices[I1], HV] = StrutPlane.PointAt(Math.Cos((HV / Sides) * Math.PI * 2) * StrutRadius, Math.Sin((HV / Sides) * Math.PI * 2) * StrutRadius);

                    double OffsetMult = PlaneOffsets[StrutIndices[I1]];
                    if (ND > OffsetMult) OffsetMult = ND;
                    if (StrutIndices[I1] % 2 != 0) StrutPlane.Rotate(Math.PI, StrutPlane.YAxis, StrutPlane.Origin);

                    if (StrutIndices.Count ==1) OffsetMult = 0;

                    StrutPlanes[StrutIndices[I1]] = StrutPlane;
                    StrutPlanes[StrutIndices[I1]].Origin = Strut.PointAtStart + Strut.TangentAtStart * OffsetMult;

                }

                //collect all of the hull points from each strut in a given node for hulling, including knuckle points

                if (StrutIndices.Count > 1)
                {
                    List<Point3d> HullPts = new List<Point3d>();
                    List<int> PlaneIndices = new List<int>();

                    double KnuckleOffset = MinOffset * 0.5;

                    for (int HV = 0; HV < S; HV++)
                    {
                        for (int I1 = 0; I1 < StrutIndices.Count; I1++)
                        {
                            HullPts.Add(StrutHullVtc[StrutIndices[I1], HV]);
                            PlaneIndices.Add(StrutIndices[I1]);
                            if (HV == 0)
                            {
                                HullPts.Add(Nodes[NodeIdx] + (Knuckles[I1] * KnuckleOffset));
                                PlaneIndices.Add(-1);
                            }
                        }
                        double Angle = ((double)HV / S) * (Math.PI * 2);
                    }

                    Rhino.Collections.Point3dList LookupPts = new Rhino.Collections.Point3dList(HullPts);

                    //execute the hulling operation
                    Mesh HullMesh = new Mesh();
                    ExoTools.Hull(HullPts, ref HullMesh);
                    ExoTools.NormaliseMesh(ref HullMesh);

                    Point3d[] HullVertices = HullMesh.Vertices.ToPoint3dArray();
                    List<int> FaceVertices = new List<int>();

                    //relocate vertices to potentially non-convex configurations
                    for (int HullVtx = 0; HullVtx < HullVertices.Length; HullVtx++)
                    {
                        int CloseIdx = LookupPts.ClosestIndex(HullVertices[HullVtx]);
                        if (PlaneIndices[CloseIdx] > -1)
                        {
                            double OffsetMult = 0;
                            if (ND > PlaneOffsets[PlaneIndices[CloseIdx]]) OffsetMult = ND - MinOffset;
                            else OffsetMult = PlaneOffsets[PlaneIndices[CloseIdx]] - MinOffset;

                            HullVertices[HullVtx] += StrutPlanes[PlaneIndices[CloseIdx]].ZAxis * OffsetMult;
                            HullMesh.Vertices[HullVtx] = new Point3f((float)HullVertices[HullVtx].X, (float)HullVertices[HullVtx].Y, (float)HullVertices[HullVtx].Z);
                            FaceVertices.Add(PlaneIndices[CloseIdx]);
                        }
                        else
                        {
                            Vector3d KnuckleVector = new Vector3d(HullVertices[HullVtx] - Nodes[NodeIdx]);
                            KnuckleVector.Unitize();
                            Point3d KnucklePt = Nodes[NodeIdx] + (KnuckleVector * KnuckleMin);
                            HullMesh.Vertices[HullVtx] = new Point3f((float)KnucklePt.X, (float)KnucklePt.Y, (float)KnucklePt.Z);
                            FaceVertices.Add(PlaneIndices[CloseIdx]);
                        }
                    }

                    //delete all faces whose vertices are associated with the same plane
                    List<int> DeleteFaces = new List<int>();

                    for (int FaceIdx = 0; FaceIdx < HullMesh.Faces.Count; FaceIdx++)
                    {
                        if ((FaceVertices[HullMesh.Faces[FaceIdx].A] !=-1) && (FaceVertices[HullMesh.Faces[FaceIdx].A] == FaceVertices[HullMesh.Faces[FaceIdx].B]) &&
                            (FaceVertices[HullMesh.Faces[FaceIdx].B] == FaceVertices[HullMesh.Faces[FaceIdx].C]))  DeleteFaces.Add(FaceIdx);
                    }
                    HullMesh.Faces.DeleteFaces(DeleteFaces);
                    ExoTools.NormaliseMesh(ref HullMesh);
                    Hulls.Append(HullMesh);
                }
                else if (!O)
                {
                        Mesh EndMesh = new Mesh();

                        double KnuckleOffset = ND * 0.5;
                        EndMesh.Vertices.Add(Nodes[NodeIdx] + (Knuckles[0] * KnuckleOffset));

                        for (int HullVtx = 0; HullVtx < S; HullVtx++)
                        {
                            EndMesh.Vertices.Add(StrutHullVtc[StrutIndices[0], HullVtx]);
                            int StartVtx = HullVtx + 1;
                            int EndVtx = HullVtx + 2;
                            if (HullVtx == S - 1)  EndVtx = 1;
                            EndMesh.Faces.AddFace(0, StartVtx, EndVtx);
                        }
                        Hulls.Append(EndMesh);
                }
            }

            //add stocking meshes between struts
            Rhino.Collections.Point3dList MatchPts = new Rhino.Collections.Point3dList(Hulls.Vertices.ToPoint3dArray());
            Mesh StrutMeshes = new Mesh();

            //if a strut is overwhelmed by its nodes then output a sphere centered on the failing strut
            Mesh FailStruts = new Mesh();

            for (int I1 = 0; I1 <= Struts.Count; I1++)
            {
                if (I1 % 2 !=0)
                {

                    if (StrutPlanes[I1-1].Origin.DistanceTo(Struts[I1-1].PointAtStart) + StrutPlanes[I1].Origin.DistanceTo(Struts[I1].PointAtStart) > Struts[I1-1].GetLength()*2)
                    {
                        Plane FailPlane = new Plane(Struts[I1 - 1].PointAtStart, Struts[I1 - 1].TangentAtStart);
                        Cylinder FailCylinder = new Cylinder(new Circle(FailPlane, (StrutRadii[I1] + StrutRadii[I1 - 1]) / 2), Struts[I1 - 1].GetLength()*2);
                        FailStruts.Append(Mesh.CreateFromCylinder(FailCylinder,5,10));
                    }

                    Mesh StrutMesh = new Mesh();
                    double StrutLength = StrutPlanes[I1 - 1].Origin.DistanceTo(StrutPlanes[I1].Origin);

                    //calculate the number of segments between nodes
                    int Segments =(int)(Math.Round((StrutLength * 0.5) / D, 0) * 2) + 2;
                    double PlnZ = StrutLength / Segments;

                    bool Match = true;
                    if (O && StrutSolo[I1 - 1]) Match = false;

                    //build up vertices
                    ExoTools.VertexAdd(ref StrutMesh, StrutPlanes[I1 - 1], (double)S, StrutRadii[I1 - 1], Match, MatchPts, Hulls);
                    double StrutIncrement = (StrutRadii[I1] - StrutRadii[I1 - 1]) / Segments;

                    for (int PlnIdx = 1; PlnIdx <= Segments; PlnIdx++)
                    {
                        Plane PlnSet = new Plane(StrutPlanes[I1-1]);
                        PlnSet.Rotate((PlnIdx % 2) * -(Math.PI / (double)S), PlnSet.ZAxis);
                        PlnSet.Origin = PlnSet.PointAt(0, 0, PlnIdx * PlnZ);
                        bool Affix = false;
                        if (PlnIdx == Segments && (!StrutSolo[I1] || (StrutSolo[I1] && !O))) Affix = true;
                        ExoTools.VertexAdd(ref StrutMesh, PlnSet, (double)S, StrutRadii[I1 - 1] + (StrutIncrement * PlnIdx), Affix, MatchPts, Hulls);
                    }

                    //build up faces
                    ExoTools.StockingStitch(ref StrutMesh, Segments, S);
                    ExoTools.NormaliseMesh(ref StrutMesh);
                    Hulls.Append(StrutMesh);
                }
            }

            if (FailStruts.Vertices.Count > 0)
            {
                DA.SetData(0, FailStruts);
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "One or more struts is engulfed by its nodes");
                return;
            }

            Hulls.Faces.CullDegenerateFaces();
            Hulls.Vertices.CullUnused();

            Mesh[] OutMeshes = Hulls.SplitDisjointPieces();
            for (int SplitMesh = 0; SplitMesh < OutMeshes.Length; SplitMesh++) { ExoTools.NormaliseMesh(ref OutMeshes[SplitMesh]); }

            //ExoTools.NormaliseMesh(ref Hulls);

            DA.SetDataList(0, OutMeshes);
        }
コード例 #13
0
        /***************************************************/

        public static void RenderRhinoMeshes(RHG.Cylinder cylinder, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material)
        {
            pipeline.DrawBrepShaded(cylinder.ToBrep(cylinder.IsFinite, cylinder.IsFinite), material);
        }
コード例 #14
0
        /***************************************************/

        public static RHG.Mesh CreatePreviewMesh(RHG.Cylinder cylinder, RHG.MeshingParameters parameters)
        {
            return(CreatePreviewMesh(cylinder.ToBrep(cylinder.IsFinite, cylinder.IsFinite), parameters));
        }
コード例 #15
0
ファイル: ViewerComponent.cs プロジェクト: samuto/Silkworm
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and 
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            #region INPUTS
            // INPUTS

            // import Silkworm Movement
            List<GH_ObjectWrapper> s_Movement = new List<GH_ObjectWrapper>();

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

            int res = new int();
            //if (!DA.GetData(4, ref res)) { }

            double startPrev = 0.0;
            if (!DA.GetData(1, ref startPrev)) { }
            double endPrev = 1.0;
            if (!DA.GetData(2, ref endPrev)) { }

            bool showlogistics = false;
            if (!DA.GetData(3, ref showlogistics)) { }

            bool showvalues = false;
            if (!DA.GetData(4, ref showvalues)) { }

            bool showmesh = false;
            if (!DA.GetData(5, ref showmesh)) { }

            bool showprinter = false;
            if (!DA.GetData(6, ref showprinter)) { }
            #endregion

            //Initialise these properties as soon as solveinstance begins
            if (DA.Iteration == 0)
            {
                //Visualise Print Logistics
                displayLogistics = new bool();
                startPoints = new List<Line>();
                endPoints = new List<Line>();
                DelimitMarkers = new List<Line>();

                //Visualise Print Values
                displayValues = new bool();
                lineThicknesses = new List<double>();
                Colors = new List<Color>();
                Movements = new List<Line>();
                blobPts = new List<Point3d>();
                blobDiameter = new List<double>();

                //Visualise Print Realistic
                displayMesh = new bool();
                //m_meshes = new List<Mesh>();

                //Visualise Printer
                displayPrinter = new bool();
                bboxAll = new BoundingBox();
                extclearance = new Mesh();
                xcarriage = new List<Mesh>();
                vizmaterial = new DisplayMaterial(Color.Yellow, 0.5);
                printArea = new List<Point3d>();

            }

            //Output Holders

            Mesh sMesh = new Mesh();

            displayLogistics = showlogistics;
            displayValues = showvalues;
            displayMesh = showmesh;
            displayPrinter = showprinter;

            List<Point3d>  startPts = new List<Point3d>();
            List<Point3d> endPts = new List<Point3d>();

            //Sort through input geometry, check that it is a Silkworm Model
            foreach (GH_ObjectWrapper movement in s_Movement)
            {
                if (movement.Value is SilkwormModel)
                {
                    SilkwormModel sModel = (SilkwormModel)movement.Value;
                    printArea.Add(new Point3d(0,0,0));
                    printArea.Add(new Point3d(0, sModel.bed_size.Y, 0));
                    printArea.Add(new Point3d(sModel.bed_size.X, sModel.bed_size.Y, 0));
                    printArea.Add(new Point3d(sModel.bed_size.X, 0, 0));

                    bboxAll = new BoundingBox(new Point3d(0, 0, 0), new Point3d(sModel.bed_size.X, sModel.bed_size.Y, sModel.bed_size.Z));
                    sModel.displayModel(startPrev, endPrev, showmesh, res,
                        out Movements,
                        out lineThicknesses,
                        out DelimitMarkers,
                        out blobPts,
                        out blobDiameter,
                        out Colors,
                        out sMesh,
                        out startPts,
                        out endPts);

                    //Create Clearance Visualisation Geometry
                    Point3d endPt = Movements[Movements.Count - 1].To;

                    Plane plane = new Plane(endPt,Plane.WorldXY.ZAxis);
                    Cone extcl = new Cone(plane, sModel.extruder_clearance_height, sModel.extruder_clearance_radius);
                    extclearance = Mesh.CreateFromCone(extcl, 12, 30);

                    double roddiameter = 8;
                    Point3d PtA1 = new Point3d(0, endPt.Y + ((sModel.xbar_width / 2) - (roddiameter / 2)), endPt.Z + (roddiameter / 2) + sModel.extruder_clearance_height);
                    Point3d PtA2 = new Point3d(0, endPt.Y - ((sModel.xbar_width / 2) - (roddiameter / 2)), endPt.Z + (roddiameter / 2)+sModel.extruder_clearance_height);

                    Cylinder clyA = new Cylinder(new Circle(new Plane(PtA1, Plane.WorldYZ.ZAxis), roddiameter/2), sModel.bed_size.X);
                    Cylinder clyB = new Cylinder(new Circle(new Plane(PtA2, Plane.WorldYZ.ZAxis), roddiameter/2), sModel.bed_size.X);

                    Mesh cylA = Mesh.CreateFromCylinder(clyA,12,30);
                    Mesh cylB = Mesh.CreateFromCylinder(clyB, 12,30);
                    xcarriage.AddRange(new Mesh[] {cylA,cylB});

                    foreach (Point3d point in startPts)
                    {
                        startPoints.Add(new Line(point, Plane.WorldXY.ZAxis, 0.01));
                    }
                    foreach (Point3d point in endPts)
                    {
                        endPoints.Add(new Line(point, Plane.WorldXY.ZAxis, 0.01));
                    }

               }

                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Please Input Only Silkworm Models");
                    continue;
                }

            }

            //GH_Mesh outPipes = new GH_Mesh(sMesh);

            //DA.SetData(0, outPipes);
        }
コード例 #16
0
        /// <summary>
        /// Gets an extrusion form of a cylinder.
        /// </summary>
        /// <param name="cylinder">IsFinite must be true.</param>
        /// <param name="capBottom">If true, the end at cylinder.Height1 will be capped.</param>
        /// <param name="capTop">If true, the end at cylinder.Height2 will be capped.</param>
        /// <returns>Extrusion on success. null on failure.</returns>
        public static Extrusion CreateCylinderExtrusion(Cylinder cylinder, bool capBottom, bool capTop)
        {
            IntPtr ptr_new_extrusion = UnsafeNativeMethods.ON_Extrusion_CreateCylinder(ref cylinder, capBottom, capTop);

            return(IntPtr.Zero == ptr_new_extrusion ? null : new Extrusion(ptr_new_extrusion, null));
        }
コード例 #17
0
        /***************************************************/

        public static void RenderRhinoWires(RHG.Cylinder cylinder, Rhino.Display.DisplayPipeline pipeline, Color bhColour, int thickness)
        {
            pipeline.DrawCylinder(cylinder, bhColour);
        }
コード例 #18
0
 /// <summary>Determines if the surface is a portion of a cylinder within a given tolerance.</summary>
 /// <param name="tolerance">tolerance to use when checking.</param>
 /// <returns>true if the surface is a portion of a cylinder.</returns>
 public bool IsCylinder(double tolerance)
 {
   Cylinder cylinder = new Cylinder();
   IntPtr pThis = ConstPointer();
   return UnsafeNativeMethods.ON_Surface_IsCylinder(pThis, ref cylinder, tolerance, false);
 }
コード例 #19
0
 /// <summary>
 /// Constructs a new surface of revolution from the values of a cylinder.
 /// </summary>
 /// <param name="cylinder">A cylinder.</param>
 /// <returns>A new surface of revolution, or null if any of the inputs is invalid or on error.</returns>
 public static RevSurface CreateFromCylinder(Cylinder cylinder)
 {
   IntPtr pRevSurface = UnsafeNativeMethods.ON_Cylinder_RevSurfaceForm(ref cylinder);
   if (IntPtr.Zero == pRevSurface)
     return null;
   return new RevSurface(pRevSurface, null);
 }
コード例 #20
0
 /// <summary>Tests a surface to see if it is a portion of a cylinder and return the cylinder.</summary>
 /// <param name="cylinder">On success, the cylinder parameters are filled in.</param>
 /// <param name="tolerance">tolerance to use when checking.</param>
 /// <returns>true if the surface is a portion of a cylinder.</returns>
 public bool TryGetCylinder(out Cylinder cylinder, double tolerance)
 {
   cylinder = new Cylinder();
   IntPtr pThis = ConstPointer();
   return UnsafeNativeMethods.ON_Surface_IsCylinder(pThis, ref cylinder, tolerance, true);
 }
コード例 #21
0
 /// <summary>
 /// Get a cylindrical projection parameters from this texture mapping.
 /// </summary>
 /// <param name="cylinder"></param>
 /// <returns>
 /// Returns true if a valid cylinder is returned.
 /// </returns>
 /// <remarks>
 /// Generally, GetMappingCylinder will not return the same parameters passed
 /// to SetCylinderMapping.  However, the location of the cylinder will be
 /// the same.  If this mapping is not cylindrical, the cylinder will
 /// approximate the actual mapping primitive.
 /// </remarks>
 public bool TryGetMappingCylinder(out Cylinder cylinder)
 {
   var ptr = ConstPointer();
   cylinder = Cylinder.Unset;
   var success = UnsafeNativeMethods.ON_TextureMapping_GetMappingCylinder(ptr, ref cylinder);
   return success;
 }