Exemplo n.º 1
0
        public Curve[] DrawOuterCurves(Brep brep, double angle, Point3d center)
        {
            brep.Rotate(angle, new Vector3d(0, 0, 1), center);
            Curve[] curves = brep.DuplicateEdgeCurves();

            return(curves);
        }
        ConvertPolyBrep(Brep brep, double tolerance = -1)
        {
            List <PolyCurve>       void_crvs     = new List <PolyCurve>();
            List <List <Point3d> > void_topo     = new List <List <Point3d> >();
            List <List <string> >  void_topoType = new List <List <string> >();

            Curve[] edgeSegments = brep.DuplicateEdgeCurves();
            Curve[] edges        = Curve.JoinCurves(edgeSegments);

            for (int i = 0; i < edges.Length; i++)
            {
                if (!edges[i].IsPlanar())
                {
                    List <Point3d> ctrl_pts;
                    if (edges[0].TryGetPolyline(out Polyline temp_crv))
                    {
                        ctrl_pts = temp_crv.ToList();
                    }
                    else
                    {
                        Tuple <PolyCurve, List <Point3d>, List <string> > convertBadSrf = GH.Convert.ConvertPolyCrv(edges[0], tolerance);
                        ctrl_pts = convertBadSrf.Item2;
                    }
                    Plane.FitPlaneToPoints(ctrl_pts, out Plane plane);
                    for (int j = 0; j < edges.Length; j++)
                    {
                        edges[j] = Curve.ProjectToPlane(edges[j], plane);
                    }
                }
            }

            Tuple <PolyCurve, List <Point3d>, List <string> > convert = GH.Convert.ConvertPolyCrv(edges[0], tolerance);
            PolyCurve      edge_crv   = convert.Item1;
            List <Point3d> m_topo     = convert.Item2;
            List <string>  m_topoType = convert.Item3;

            for (int i = 1; i < edges.Length; i++)
            {
                convert = GH.Convert.ConvertPolyCrv(edges[i], tolerance);
                void_crvs.Add(convert.Item1);
                void_topo.Add(convert.Item2);
                void_topoType.Add(convert.Item3);
            }

            return(new Tuple <PolyCurve, List <Point3d>, List <string>, List <PolyCurve>, List <List <Point3d> >, List <List <string> > >
                       (edge_crv, m_topo, m_topoType, void_crvs, void_topo, void_topoType));
        }
Exemplo n.º 3
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //---variables---

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

            //---input---

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

            //---solve---

            Mesh mesh = new Mesh();

            for (int i = 0; i < points.Count; i++)
            {
                mesh.Vertices.Add(points[i]);
            }
            mesh.Faces.AddFace(0, 4, 5, 1); //Front
            mesh.Faces.AddFace(1, 5, 6, 2); //Right
            mesh.Faces.AddFace(2, 6, 7, 3); //Back
            mesh.Faces.AddFace(0, 3, 7, 4); //Left
            mesh.Faces.AddFace(0, 1, 2, 3); //Bottom
            mesh.Faces.AddFace(4, 7, 6, 5); //Top

            Brep brep = Brep.CreateFromMesh(mesh, true);

            Curve[] curves = brep.DuplicateEdgeCurves();

            //---output---

            DA.SetData(0, brep);
        }
Exemplo n.º 4
0
// ===============================================================================================
// Get edges from breps
// ===============================================================================================
        public static DataTree <Curve> BrepEdges(List <Brep> breps)
        {
            DataTree <Curve> faceEdges = new DataTree <Curve>();
            int i = 0;

            foreach (Brep brep in breps)
            {
                int j = 0;
                foreach (var face in brep.Faces)
                {
                    Brep faceBrep = face.DuplicateFace(true);
                    var  crvs     = faceBrep.DuplicateEdgeCurves();

                    for (int k = 0; k < crvs.Length; k++)
                    {
                        GH_Path path = new GH_Path(i, j);
                        faceEdges.Add(crvs[k], path);
                    }
                    j++;
                }
                i++;
            }
            return(faceEdges);
        }
        ConvertPolyBrepInclusion(Brep brep, List <Curve> inclCrvs = null, List <Point3d> inclPts = null, double tolerance = -1)
        {
            List <PolyCurve>       void_crvs     = new List <PolyCurve>();
            List <List <Point3d> > void_topo     = new List <List <Point3d> >();
            List <List <string> >  void_topoType = new List <List <string> >();

            List <PolyCurve>       incl_crvs     = new List <PolyCurve>();
            List <List <Point3d> > incl_topo     = new List <List <Point3d> >();
            List <List <string> >  incl_topoType = new List <List <string> >();

            Curve[] edgeSegments = brep.DuplicateEdgeCurves();
            Curve[] edges        = Curve.JoinCurves(edgeSegments);

            List <Point3d> ctrl_pts;

            if (edges[0].TryGetPolyline(out Polyline temp_crv))
            {
                ctrl_pts = temp_crv.ToList();
            }
            else
            {
                Tuple <PolyCurve, List <Point3d>, List <string> > convertBadSrf = GH.Convert.ConvertPolyCrv(edges[0], tolerance);
                ctrl_pts = convertBadSrf.Item2;
            }
            Plane.FitPlaneToPoints(ctrl_pts, out Plane plane);


            for (int i = 0; i < edges.Length; i++)
            {
                if (!edges[i].IsPlanar())
                {
                    for (int j = 0; j < edges.Length; j++)
                    {
                        edges[j] = Curve.ProjectToPlane(edges[j], plane);
                    }
                }
            }
            Tuple <PolyCurve, List <Point3d>, List <string> > convert = GH.Convert.ConvertPolyCrv(edges[0], tolerance);
            PolyCurve      edge_crv   = convert.Item1;
            List <Point3d> m_topo     = convert.Item2;
            List <string>  m_topoType = convert.Item3;

            for (int i = 1; i < edges.Length; i++)
            {
                convert = GH.Convert.ConvertPolyCrv(edges[i], tolerance);
                void_crvs.Add(convert.Item1);
                void_topo.Add(convert.Item2);
                void_topoType.Add(convert.Item3);
            }

            if (inclCrvs != null)
            {
                for (int i = 0; i < inclCrvs.Count; i++)
                {
                    if (!inclCrvs[i].IsInPlane(plane))
                    {
                        inclCrvs[i] = Curve.ProjectToPlane(inclCrvs[i], plane);
                    }
                    convert = GH.Convert.ConvertPolyCrv(inclCrvs[i], tolerance);
                    incl_crvs.Add(convert.Item1);
                    incl_topo.Add(convert.Item2);
                    incl_topoType.Add(convert.Item3);
                }
            }

            if (inclPts != null)
            {
                for (int i = 0; i < inclPts.Count; i++)
                {
                    inclPts[i] = plane.ClosestPoint(inclPts[i]);
                }
            }

            Tuple <PolyCurve, List <Point3d>, List <string> > edgeTuple = new Tuple <PolyCurve, List <Point3d>, List <string> >(edge_crv, m_topo, m_topoType);
            Tuple <List <PolyCurve>, List <List <Point3d> >, List <List <string> > > voidTuple = new Tuple <List <PolyCurve>, List <List <Point3d> >, List <List <string> > >(void_crvs, void_topo, void_topoType);
            Tuple <List <PolyCurve>, List <List <Point3d> >, List <List <string> >, List <Point3d> > inclTuple = new Tuple <List <PolyCurve>, List <List <Point3d> >, List <List <string> >, List <Point3d> >(incl_crvs, incl_topo, incl_topoType, inclPts);

            return(new Tuple <Tuple <PolyCurve, List <Point3d>, List <string> >, Tuple <List <PolyCurve>, List <List <Point3d> >, List <List <string> > >, Tuple <List <PolyCurve>, List <List <Point3d> >, List <List <string> >, List <Point3d> > >
                       (edgeTuple, voidTuple, inclTuple));
        }
Exemplo n.º 6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Brep   surface  = new Brep();
            double height   = 0;
            double percent  = 0;
            bool   isSwitch = true;

            if (!DA.GetData(0, ref surface))
            {
                return;
            }
            if (!DA.GetData(1, ref height))
            {
                return;
            }
            if (!DA.GetData(2, ref percent))
            {
                return;
            }
            if (!DA.GetData(3, ref isSwitch))
            {
                return;
            }
            Brep   x = surface;
            double h = height;
            double l = percent;
            bool   b = isSwitch;

            if (b == false)
            {
                h = h * (-1);
            }
            if (l > 1 || l < 0)
            {
                l = 1;
            }
            Curve[]        cs    = x.DuplicateEdgeCurves(true);
            Curve[]        joins = Curve.JoinCurves(cs);
            Point3d        pt    = SuperVipersClass.centerPoint(x.DuplicateVertices().ToList());
            Point3d        center;/////中点
            ComponentIndex ci;
            double         s;
            double         t;
            double         dist = 0;
            Vector3d       vc;///////开口方向

            x.ClosestPoint(pt, out center, out ci, out s, out t, dist, out vc);
            center.Transform(Transform.Translation(vc * h));
            Point3d[] ptss = SuperVipersClass.sortPoints(x.DuplicateVertices().ToList(), joins[0]).ToArray();
            for (int i = 0; i < ptss.Length; i++)
            {
                Vector3d vv = Point3d.Subtract(ptss[i], center);
                ptss[i].Transform(Transform.Translation(vv * l * (-1)));
            }
            Point3d[]   ptss2 = SuperVipersClass.sortPoints(x.DuplicateVertices().ToList(), joins[0]).ToArray();
            List <Brep> breps = new List <Brep>();

            for (int i = 0; i < ptss.Length; i++)
            {
                if (i == ptss.Length - 1)
                {
                    NurbsCurve[] n1  = { new Line(ptss[i], ptss[0]).ToNurbsCurve(), new Line(ptss[i], ptss2[i]).ToNurbsCurve(), new Line(ptss2[i], ptss2[0]).ToNurbsCurve(), new Line(ptss[0], ptss2[0]).ToNurbsCurve() };
                    Brep         bbp = Brep.CreateEdgeSurface(n1);
                    breps.Add(bbp);
                    continue;
                }
                NurbsCurve[] n2   = { new Line(ptss[i], ptss[i + 1]).ToNurbsCurve(), new Line(ptss[i], ptss2[i]).ToNurbsCurve(), new Line(ptss2[i], ptss2[i + 1]).ToNurbsCurve(), new Line(ptss[i + 1], ptss2[i + 1]).ToNurbsCurve() };
                Brep         bbp2 = Brep.CreateEdgeSurface(n2);
                breps.Add(bbp2);
            }
            DA.SetDataList(0, breps);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaProfile profile = new GsaProfile();

            #region catalogue
            if (_mode == FoldMode.Catalogue)
            {
                profile.profileType = GsaProfile.ProfileTypes.Catalogue;

                // need to implement the lists of cross sections
                profile.catalogueIndex        = catalogueIndex;
                profile.catalogueProfileIndex = catalogueProfileIndex;
                profile.catalogueTypeIndex    = catalogueTypeIndex;
            }
            #endregion
            #region geometric
            if (_mode == FoldMode.Geometric)
            {
                profile.profileType = GsaProfile.ProfileTypes.Geometric;
                GH_Brep gh_Brep = new GH_Brep();
                if (DA.GetData(0, ref gh_Brep))
                {
                    Brep brep = new Brep();
                    if (GH_Convert.ToBrep(gh_Brep, ref brep, GH_Conversion.Both))
                    {
                        // get edge curves from Brep
                        Curve[] edgeSegments = brep.DuplicateEdgeCurves();
                        Curve[] edges        = Curve.JoinCurves(edgeSegments);

                        // find the best fit plane
                        List <Point3d> ctrl_pts = new List <Point3d>();
                        if (edges[0].TryGetPolyline(out Polyline tempCrv))
                        {
                            ctrl_pts = tempCrv.ToList();
                        }
                        else
                        {
                            this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cannot convert edge to Polyline");
                        }
                        Plane.FitPlaneToPoints(ctrl_pts, out Plane plane);
                        Rhino.Geometry.Transform xform = Rhino.Geometry.Transform.ChangeBasis(Plane.WorldXY, plane);

                        profile.geoType = GsaProfile.GeoTypes.Perim;

                        List <Point2d> pts = new List <Point2d>();
                        foreach (Point3d pt3d in ctrl_pts)
                        {
                            pt3d.Transform(xform);
                            Point2d pt2d = new Point2d(pt3d);
                            pts.Add(pt2d);
                        }
                        profile.perimeterPoints = pts;

                        if (edges.Length > 1)
                        {
                            List <List <Point2d> > voidPoints = new List <List <Point2d> >();
                            for (int i = 1; i < edges.Length; i++)
                            {
                                ctrl_pts.Clear();
                                if (!edges[i].IsPlanar())
                                {
                                    for (int j = 0; j < edges.Length; j++)
                                    {
                                        edges[j] = Curve.ProjectToPlane(edges[j], plane);
                                    }
                                }
                                if (edges[i].TryGetPolyline(out tempCrv))
                                {
                                    ctrl_pts = tempCrv.ToList();
                                    pts      = new List <Point2d>();
                                    foreach (Point3d pt3d in ctrl_pts)
                                    {
                                        pt3d.Transform(xform);
                                        Point2d pt2d = new Point2d(pt3d);
                                        pts.Add(pt2d);
                                    }
                                    voidPoints.Add(pts);
                                }
                                else
                                {
                                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cannot convert internal edge  to Polyline");
                                }
                            }
                            profile.voidPoints = voidPoints;
                        }
                    }
                }
            }
            #endregion
            #region standard section
            if (_mode != FoldMode.Geometric & _mode != FoldMode.Catalogue)
            {
                profile.profileType = GsaProfile.ProfileTypes.Standard;
                GH_Number gh_d   = new GH_Number();
                GH_Number gh_b1  = new GH_Number();
                GH_Number gh_b2  = new GH_Number();
                GH_Number gh_tw1 = new GH_Number();
                GH_Number gh_tw2 = new GH_Number();
                GH_Number gh_tf1 = new GH_Number();
                GH_Number gh_tf2 = new GH_Number();
                switch (selections[1])
                {
                case "Rectangle":
                    profile.stdShape = GsaProfile.StdShapeOptions.Rectangle;

                    // 0 d
                    DA.GetData(0, ref gh_d);

                    // 1 b1
                    DA.GetData(1, ref gh_b1);

                    if (isTapered)
                    {
                        // 2 b2
                        DA.GetData(2, ref gh_b2);
                    }
                    else
                    {
                        if (isHollow)
                        {
                            // 2 tw
                            DA.GetData(2, ref gh_tw1);

                            // 3 tw
                            DA.GetData(3, ref gh_tf1);
                        }
                    }
                    break;

                case "Circle":
                    profile.stdShape = GsaProfile.StdShapeOptions.Circle;

                    // 0 d
                    DA.GetData(0, ref gh_d);

                    if (isHollow)
                    {
                        if (isElliptical)
                        {
                            // 1 b1
                            DA.GetData(1, ref gh_b1);

                            // 2 tw
                            DA.GetData(2, ref gh_tw1);
                        }
                        else
                        {
                            // 1 tw
                            DA.GetData(1, ref gh_tw1);
                        }
                    }
                    else
                    {
                        if (isElliptical)
                        {
                            // 1 b1
                            DA.GetData(1, ref gh_b1);
                        }
                    }

                    break;

                case "I section":
                    profile.stdShape = GsaProfile.StdShapeOptions.I_section;

                    // 0 d
                    DA.GetData(0, ref gh_d);

                    // 1 b1
                    DA.GetData(1, ref gh_b1);

                    // 2 tw1
                    DA.GetData(2, ref gh_tw1);

                    // 3 tf1
                    DA.GetData(3, ref gh_tf1);

                    if (isGeneral)
                    {
                        if (isTapered)
                        {
                            // 4 b2
                            DA.GetData(4, ref gh_b2);

                            // 5 tw2
                            DA.GetData(5, ref gh_tw2);

                            // 6 tf2
                            DA.GetData(6, ref gh_tf2);
                        }
                        else
                        {
                            // 4 b2
                            DA.GetData(4, ref gh_b2);

                            // 5 tf2
                            DA.GetData(5, ref gh_tf2);
                        }
                    }
                    break;

                case "Tee":
                    profile.stdShape = GsaProfile.StdShapeOptions.Tee;
                    // 0 d
                    DA.GetData(0, ref gh_d);

                    // 1 b1
                    DA.GetData(1, ref gh_b1);

                    // 2 tf1
                    DA.GetData(2, ref gh_tf1);

                    // 3 tw1
                    DA.GetData(3, ref gh_tw1);

                    if (isTapered)
                    {
                        // 4 tw2
                        DA.GetData(4, ref gh_tw2);
                    }
                    break;

                case "Channel":
                    profile.stdShape = GsaProfile.StdShapeOptions.Channel;
                    // 0 d
                    DA.GetData(0, ref gh_d);

                    // 1 b1
                    DA.GetData(1, ref gh_b1);

                    // 2 tf1
                    DA.GetData(2, ref gh_tf1);

                    // 3 tw1
                    DA.GetData(3, ref gh_tw1);
                    break;

                case "Angle":
                    profile.stdShape = GsaProfile.StdShapeOptions.Angle;
                    // 0 d
                    DA.GetData(0, ref gh_d);

                    // 1 b1
                    DA.GetData(1, ref gh_b1);

                    // 2 tf1
                    DA.GetData(2, ref gh_tf1);

                    // 3 tw1
                    DA.GetData(3, ref gh_tw1);
                    break;
                }

                if (gh_d != null)
                {
                    if (GH_Convert.ToDouble(gh_d, out double d, GH_Conversion.Both))
                    {
                        profile.d = d;
                    }
                }
                if (gh_b1 != null)
                {
                    if (GH_Convert.ToDouble(gh_b1, out double b1, GH_Conversion.Both))
                    {
                        profile.b1 = b1;
                    }
                }
                if (gh_b2 != null)
                {
                    if (GH_Convert.ToDouble(gh_b2, out double b2, GH_Conversion.Both))
                    {
                        profile.b2 = b2;
                    }
                }
                if (gh_tw1 != null)
                {
                    if (GH_Convert.ToDouble(gh_tw1, out double tw1, GH_Conversion.Both))
                    {
                        profile.tw1 = tw1;
                    }
                }
                if (gh_tw2 != null)
                {
                    if (GH_Convert.ToDouble(gh_tw2, out double tw2, GH_Conversion.Both))
                    {
                        profile.tw2 = tw2;
                    }
                }
                if (gh_tf1 != null)
                {
                    if (GH_Convert.ToDouble(gh_tf1, out double tf1, GH_Conversion.Both))
                    {
                        profile.tf1 = tf1;
                    }
                }
                if (gh_tf2 != null)
                {
                    if (GH_Convert.ToDouble(gh_tf2, out double tf2, GH_Conversion.Both))
                    {
                        profile.tf2 = tf2;
                    }
                }
                profile.isB2B        = isB2B;
                profile.isElliptical = isElliptical;
                profile.isGeneral    = isGeneral;
                profile.isHollow     = isHollow;
                profile.isTapered    = isTapered;
            }
            #endregion
            #region units
            switch (Util.Unit.LengthSection)
            {
            case "mm":
                profile.sectUnit = GsaProfile.SectUnitOptions.u_mm;
                break;

            case "cm":
                profile.sectUnit = GsaProfile.SectUnitOptions.u_cm;
                break;

            case "m":
                profile.sectUnit = GsaProfile.SectUnitOptions.u_m;
                break;

            case "in":
                profile.sectUnit = GsaProfile.SectUnitOptions.u_in;
                break;

            case "ft":
                profile.sectUnit = GsaProfile.SectUnitOptions.u_ft;
                break;
            }
            #endregion

            // build string and output
            DA.SetData(0, ConvertSection.ProfileConversion(profile));
        }
Exemplo n.º 8
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //NOTE: This meshing class only mesh geometry with straight lines as cross-section,
            //but handle geometry which are curved between the cross-sections.
            //This is the meshing component for CASE 2.

            // ---variables-- -

            Brep           brp          = new Brep();
            List <Point3d> cornersList  = new List <Point3d>();
            int            u            = 1;
            int            v            = 1;
            int            w            = 1;
            double         removeVolume = 0;

            // --- input ---

            if (!DA.GetData(0, ref brp))
            {
                return;
            }
            if (!DA.GetDataList(1, cornersList))
            {
                return;
            }
            if (!DA.GetData(2, ref u))
            {
                return;
            }
            if (!DA.GetData(3, ref v))
            {
                return;
            }
            if (!DA.GetData(4, ref w))
            {
                return;
            }
            if (!DA.GetData(5, ref removeVolume))
            {
                return;
            }

            // --- setup ---

            if (u < 1 || v < 1 || w < 1) //None of the sides can be divided in less than one part
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "One of the input parameters is less than one.");
                return;
            }

            Point3d[] cornerPoints = brp.DuplicateVertices();
            cornerPoints = RoundPoints(cornerPoints); //Round off to remove inaccuries

            Curve[] edges = brp.DuplicateEdgeCurves();
            edges = RoundEdgePoints(edges); //Round off to remove inaccuries

            List <Point3d> corners = RoundPointsList(cornersList);

            Curve[] sortedEdges = SortEdges(corners, edges); //Sort edges in correct order according to control points

            // --- solve ---

            var tuple = CreateMesh(sortedEdges, u, v, w, cornerPoints);

            List <List <Point3d> > elementPoints = tuple.Item1;
            List <List <int> >     connectivity  = tuple.Item2;
            List <List <Line> >    edgeMesh      = tuple.Item3;
            List <List <Brep> >    surfacesMesh  = tuple.Item4;
            List <Node>            nodes         = tuple.Item5;
            List <Element>         elements      = tuple.Item6;
            List <Point3d>         globalPoints  = tuple.Item7;

            int sizeOfMatrix = 3 * (u + 1) * (v + 1) * (w + 1);
            //Point3d[] globalPoints = CreatePointList(connectivity, elementPoints, sizeOfMatrix);

            //Setting values for Mesh class
            MeshGeometry mesh = new MeshGeometry(u, v, w);

            mesh.SetConnectivity(connectivity);
            mesh.SetElementPoints(elementPoints);
            mesh.SetEdgesMesh(edgeMesh);
            mesh.SetSurfacesMesh(surfacesMesh);
            mesh.SetSizeOfMatrix(sizeOfMatrix);
            mesh.SetGlobalPoints(globalPoints);
            mesh.SetNodeList(nodes);
            mesh.SetElements(elements);
            mesh.SetOrigBrep(brp);
            mesh.SetBrep(new BrepGeometry(brp));
            mesh.OrderSurfaces(corners);
            mesh.SetOptVolume(removeVolume);

            //---output---

            DA.SetData(0, mesh);
        }
Exemplo n.º 9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            {
                //NOTE: This meshing class can mesh any type of geometry as long as it consist of 8 corners and no holes.
                //This is the meshing component for CASE 3.

                // ---variables-- -

                Brep           brp          = new Brep();
                List <Point3d> corners      = new List <Point3d>();
                int            u            = 1;
                int            v            = 1;
                int            w            = 1;
                double         removeVolume = 0;

                // --- input ---

                if (!DA.GetData(0, ref brp))
                {
                    return;
                }
                if (!DA.GetDataList(1, corners))
                {
                    return;
                }
                if (!DA.GetData(2, ref u))
                {
                    return;
                }
                if (!DA.GetData(3, ref v))
                {
                    return;
                }
                if (!DA.GetData(4, ref w))
                {
                    return;
                }
                if (!DA.GetData(5, ref removeVolume))
                {
                    return;
                }

                Curve[] edges       = brp.DuplicateEdgeCurves();
                Curve[] sortedEdges = SortEdges(corners, edges);

                Surface[] surfaces = CreateSortedSurfaces(brp, edges, corners);

                var tuple = CreateMesh(brp, u, v, w, sortedEdges, surfaces);

                List <List <Point3d> > elementPoints = tuple.Item1;
                List <List <int> >     connectivity  = tuple.Item2;
                List <List <Line> >    edgeMesh      = tuple.Item3;
                List <List <Brep> >    surfacesMesh  = tuple.Item4;
                List <Node>            nodes         = tuple.Item5;
                List <Element>         elements      = tuple.Item6;
                List <Point3d>         globalPoints  = tuple.Item7;
                int sizeOfMatrix = 3 * (u + 1) * (v + 1) * (w + 1);


                //Setting values for Mesh class
                MeshGeometry mesh = new MeshGeometry(u, v, w);
                mesh.SetConnectivity(connectivity);
                mesh.SetElementPoints(elementPoints);
                mesh.SetEdgesMesh(edgeMesh);
                mesh.SetSurfacesMesh(surfacesMesh);
                mesh.SetSizeOfMatrix(sizeOfMatrix);
                mesh.SetGlobalPoints(globalPoints);
                mesh.SetNodeList(nodes);
                mesh.SetElements(elements);
                mesh.SetOrigBrep(brp);
                mesh.SetBrep(new BrepGeometry(brp));
                mesh.OrderSurfaces(corners);
                mesh.SetOptVolume(removeVolume);

                //---output---

                DA.SetData(0, mesh);
            }
        }
Exemplo n.º 10
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaGridAreaLoad gridareaload = new GsaGridAreaLoad();

            // 0 Load case
            int        lc    = 1;
            GH_Integer gh_lc = new GH_Integer();

            if (DA.GetData(0, ref gh_lc))
            {
                GH_Convert.ToInt32(gh_lc, out lc, GH_Conversion.Both);
            }
            gridareaload.GridAreaLoad.Case = lc;

            // Do plane input first as to see if we need to project polyline onto grid plane
            // 2 Plane
            Plane pln      = Plane.WorldXY;
            bool  planeSet = false;
            GsaGridPlaneSurface grdplnsrf = new GsaGridPlaneSurface();
            GH_ObjectWrapper    gh_typ    = new GH_ObjectWrapper();

            if (DA.GetData(2, ref gh_typ))
            {
                if (gh_typ.Value is GsaGridPlaneSurfaceGoo)
                {
                    GsaGridPlaneSurface temppln = new GsaGridPlaneSurface();
                    gh_typ.CastTo(ref temppln);
                    grdplnsrf = temppln.Duplicate();
                    pln       = grdplnsrf.Plane;
                    planeSet  = true;
                }
                else if (gh_typ.Value is Plane)
                {
                    gh_typ.CastTo(ref pln);
                    grdplnsrf = new GsaGridPlaneSurface(pln);
                    planeSet  = true;
                }
                else
                {
                    int id = 0;
                    if (GH_Convert.ToInt32(gh_typ.Value, out id, GH_Conversion.Both))
                    {
                        gridareaload.GridAreaLoad.GridSurface = id;
                        gridareaload.GridPlaneSurface         = null;
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Error in GPS input. Accepted inputs are Grid Plane Surface or Plane. " +
                                          System.Environment.NewLine + "If no input here then the brep's best-fit plane will be used");
                        return;
                    }
                }
            }

            // we wait setting the gridplanesurface until we have run the polyline input

            // 1 Polyline
            Brep brep = new Brep();


            GH_Brep gh_brep = new GH_Brep();

            if (DA.GetData(1, ref gh_brep))
            {
                GH_Convert.ToBrep(gh_brep, ref brep, GH_Conversion.Both);

                // get edge curves
                Curve[] edgeSegments = brep.DuplicateEdgeCurves();
                Curve[] edges        = Curve.JoinCurves(edgeSegments);
                Curve   crv          = edges[0];

                //convert to polyline
                Polyline ln = new Polyline();
                if (crv.TryGetPolyline(out ln))
                {
                    // get control points
                    List <Point3d> ctrl_pts = ln.ToList();

                    // plane
                    if (!planeSet)
                    {
                        // create nice plane from pts
                        pln = Util.GH.Convert.CreateBestFitUnitisedPlaneFromPts(ctrl_pts);

                        // create grid plane surface from best fit plane
                        grdplnsrf = new GsaGridPlaneSurface(pln, true);
                    }

                    // project original curve onto grid plane
                    crv = Curve.ProjectToPlane(crv, pln);

                    // convert to polyline again
                    crv.TryGetPolyline(out ln);

                    //get control points again
                    ctrl_pts = ln.ToList();

                    // string to write polyline description to
                    string desc = "";

                    // loop through all points
                    for (int i = 0; i < ctrl_pts.Count - 1; i++)
                    {
                        if (i > 0)
                        {
                            desc += " ";
                        }

                        // get control points in local plane coordinates
                        Point3d temppt = new Point3d();
                        pln.RemapToPlaneSpace(ctrl_pts[i], out temppt);

                        // write point to string
                        // format accepted by GSA: (0,0) (0,1) (1,2) (3,4) (4,0)(m)
                        desc += "(" + temppt.X + "," + temppt.Y + ")";
                    }
                    // add units to the end
                    desc += "(" + Units.LengthLarge + ")";

                    // set polyline in grid line load
                    gridareaload.GridAreaLoad.Type = GridAreaPolyLineType.POLYGON;
                    gridareaload.GridAreaLoad.PolyLineDefinition = desc;
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Could not convert Brep edge to Polyline");
                }
            }

            // now we can set the gridplanesurface:
            if (gridareaload.GridPlaneSurface != null)
            {
                if (gridareaload.GridPlaneSurface.GridSurfaceID == 0)
                {
                    gridareaload.GridPlaneSurface = grdplnsrf;
                }
            }

            // 3 direction
            string    dir   = "Z";
            Direction direc = Direction.Z;

            GH_String gh_dir = new GH_String();

            if (DA.GetData(3, ref gh_dir))
            {
                GH_Convert.ToString(gh_dir, out dir, GH_Conversion.Both);
            }
            dir = dir.ToUpper();
            if (dir == "X")
            {
                direc = Direction.X;
            }
            if (dir == "Y")
            {
                direc = Direction.Y;
            }

            gridareaload.GridAreaLoad.Direction = direc;

            // 4 Axis
            int axis = 0;

            gridareaload.GridAreaLoad.AxisProperty = 0;
            GH_Integer gh_ax = new GH_Integer();

            if (DA.GetData(4, ref gh_ax))
            {
                GH_Convert.ToInt32(gh_ax, out axis, GH_Conversion.Both);
                if (axis == 0 || axis == -1)
                {
                    gridareaload.GridAreaLoad.AxisProperty = axis;
                }
            }

            // 5 Projected
            bool       proj    = false;
            GH_Boolean gh_proj = new GH_Boolean();

            if (DA.GetData(5, ref gh_proj))
            {
                if (GH_Convert.ToBoolean(gh_proj, out proj, GH_Conversion.Both))
                {
                    gridareaload.GridAreaLoad.IsProjected = proj;
                }
            }

            // 6 Name
            string    name    = "";
            GH_String gh_name = new GH_String();

            if (DA.GetData(6, ref gh_name))
            {
                if (GH_Convert.ToString(gh_name, out name, GH_Conversion.Both))
                {
                    gridareaload.GridAreaLoad.Name = name;
                }
            }

            // 7 load value
            double load1 = 0;

            if (DA.GetData(7, ref load1))
            {
                load1 *= -1000; //convert to kN
            }
            gridareaload.GridAreaLoad.Value = load1;

            // convert to goo
            GsaLoad gsaLoad = new GsaLoad(gridareaload);

            DA.SetData(0, new GsaLoadGoo(gsaLoad));
        }
Exemplo n.º 11
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Brep   surface    = new Brep();
            double tolerance  = 0;
            double angleToler = 0;
            double height     = 0;
            double percent    = 0;
            bool   isSwitch   = false;
            bool   isCap      = false;

            if (!DA.GetData(0, ref surface))
            {
                return;
            }
            if (!DA.GetData(1, ref tolerance))
            {
                return;
            }
            if (!DA.GetData(2, ref angleToler))
            {
                return;
            }
            if (!DA.GetData(3, ref height))
            {
                return;
            }
            if (!DA.GetData(4, ref percent))
            {
                return;
            }
            if (!DA.GetData(5, ref isSwitch))
            {
                return;
            }
            if (!DA.GetData(6, ref isCap))
            {
                return;
            }
            Brep   x = surface;
            double t = tolerance;
            double a = angleToler;
            double h = height;
            double p = percent;

            if (isSwitch)
            {
                h = h * (-1);
            }
            if (p > 1 || p < 0)
            {
                p = 1;
            }
            Curve[] cs = Curve.JoinCurves(x.DuplicateEdgeCurves(true));
            Curve   c  = cs[0].Simplify(CurveSimplifyOptions.All, t, a);

            Curve[] cs2 = c.DuplicateSegments();
            double  xx  = 0;
            double  yy  = 0;
            double  zz  = 0;

            for (int i = 0; i < cs2.Length; i++)
            {
                xx += cs2[i].PointAtStart.X;
                yy += cs2[i].PointAtStart.Y;
                zz += cs2[i].PointAtStart.Z;
            }
            Point3d        center = new Point3d(xx / cs2.Length, yy / cs2.Length, zz / cs2.Length);
            Point3d        pt;
            ComponentIndex ci;
            double         tt;
            double         s;
            Vector3d       vc;

            x.ClosestPoint(center, out pt, out ci, out s, out tt, 0, out vc);
            Plane pln = new Plane(pt, vc);//////切割平面

            pt.Transform(Transform.Translation(vc * h));
            pln.Transform(Transform.Translation(vc * h * p));
            List <Point3d> ptss = new List <Point3d>();///////平面与线段交点

            for (int i = 0; i < cs2.Length; i++)
            {
                double param;
                Line   l = new Line(cs2[i].PointAtStart, pt);
                Rhino.Geometry.Intersect.Intersection.LinePlane(l, pln, out param);
                ptss.Add(l.PointAt(param));
            }
            List <Line>       ls1  = new List <Line>();
            List <NurbsCurve> ls11 = new List <NurbsCurve>(); ///轮廓线2
            List <Line>       ls2  = new List <Line>();
            List <NurbsCurve> ls22 = new List <NurbsCurve>(); ///轮廓线3
            List <Line>       ls3  = new List <Line>();

            for (int i = 0; i < cs2.Length; i++)
            {
                if (i == cs2.Length - 1)
                {
                    ls1.Add(new Line(ptss[i], ptss[0]));
                    ls11.Add(new Line(ptss[i], ptss[0]).ToNurbsCurve());
                    ls2.Add(new Line(cs2[i].PointAtStart, ptss[i]));
                    ls22.Add(new Line(cs2[i].PointAtStart, ptss[i]).ToNurbsCurve());
                    ls3.Add(new Line(cs2[i].PointAtEnd, ptss[0]));
                    continue;
                }
                ls1.Add(new Line(ptss[i], ptss[i + 1]));
                ls11.Add(new Line(ptss[i], ptss[i + 1]).ToNurbsCurve());
                ls2.Add(new Line(cs2[i].PointAtStart, ptss[i]));
                ls22.Add(new Line(cs2[i].PointAtStart, ptss[i]).ToNurbsCurve());
                ls3.Add(new Line(cs2[i].PointAtEnd, ptss[i + 1]));
            }
            List <Brep> sfs = new List <Brep>();

            for (int i = 0; i < cs2.Length; i++)
            {
                Curve[] cc = { cs2[i], ls1[i].ToNurbsCurve(), ls2[i].ToNurbsCurve(), ls3[i].ToNurbsCurve() };
                sfs.Add(Brep.CreateEdgeSurface(cc));
            }
            if (isCap)
            {
                sfs.Add(Brep.CreatePlanarBreps(ls11)[0]);/////加顶盖
            }
            List <Curve> curves = new List <Curve>();

            curves.AddRange(cs2);
            curves.AddRange(ls11);
            curves.AddRange(ls22);
            DA.SetDataList(0, sfs);
            DA.SetDataList(1, curves);
        }