Esempio n. 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Mesh mesh = null;

            if (!DA.GetData <Mesh>(0, ref mesh))
            {
                return;
            }
            var list = new System.Collections.Generic.List <object>();

            checked
            {
                var circles = new SurfaceComponents.MeshComponents.Component_MeshFaceCircles();
                var param   = circles.Params.Input[0] as Grasshopper.Kernel.GH_PersistentGeometryParam <Grasshopper.Kernel.Types.GH_Mesh>;
                param.PersistentData.ClearData();
                param.PersistentData.Append(new GH_Mesh(mesh));

                circles.ExpireSolution(true);

                //add to a dummy document so we can read outputs
                var doc = new Grasshopper.Kernel.GH_Document();
                doc.AddObject(circles, false);

                //read output circles
                circles.Params.Output[0].CollectData();

                for (int i = 0; i < mesh.Faces.Count; ++i)
                {
                    list.Add(circles.Params.Output[0].VolatileData.get_Branch(0)[i]);
                }

                DA.SetDataList(0, list);
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            checked
            {
                var Points = new List <Point3d>();

                DA.GetDataList(0, Points);

                var attrition = 1.0;

                DA.GetData("Attrition", ref attrition);

                var nodeTwoList   = new Grasshopper.Kernel.Geometry.Node2List(Points);
                var delaunayFaces = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Faces(nodeTwoList, 1);
                var delaunayMesh  = Grasshopper.Kernel.Geometry.Delaunay.Solver.Solve_Mesh(nodeTwoList, 1, ref delaunayFaces);
                delaunayMesh.Weld(Math.PI);

                var list = new List <object>();

                var circles = new SurfaceComponents.MeshComponents.Component_MeshFaceCircles();
                var param   = circles.Params.Input[0] as Grasshopper.Kernel.GH_PersistentGeometryParam <Grasshopper.Kernel.Types.GH_Mesh>;
                param.PersistentData.ClearData();
                param.PersistentData.Append(new GH_Mesh(delaunayMesh));

                circles.ExpireSolution(true);

                //add to a dummy document so we can read outputs
                var doc = new Grasshopper.Kernel.GH_Document();
                doc.AddObject(circles, false);

                //read output circles
                circles.Params.Output[0].CollectData();
                var ratio = new double[circles.Params.Output[1].VolatileDataCount];
                for (int i = 0; i < circles.Params.Output[0].VolatileDataCount; ++i)
                {
                    //ratio[i] = circles.Params.Output[1].VolatileData.get_Branch(0)[i];
                    GH_Convert.ToDouble(circles.Params.Output[1].VolatileData.get_Branch(0)[i], out ratio[i], GH_Conversion.Both);
                    list.Add(circles.Params.Output[0].VolatileData.get_Branch(0)[i]);
                }

                var arcsList = new double[list.Count];

                var arcs      = new AnalysisComponents.Component_DeconstructArc();
                var arcParams = arcs.Params.Input[0] as Grasshopper.Kernel.GH_PersistentParam <Grasshopper.Kernel.Types.GH_Arc>;
                arcParams.PersistentData.ClearData();
                var circle = new Arc[delaunayMesh.Faces.Count];
                for (int i = 0; i < list.Count; ++i)
                {
                    GH_Convert.ToArc(list[i], ref circle[i], GH_Conversion.Both);
                    arcParams.PersistentData.Append(new GH_Arc(circle[i]));
                }

                arcs.ExpireSolution(true);
                var docOne = new Grasshopper.Kernel.GH_Document();
                docOne.AddObject(arcs, false);

                arcs.Params.Output[0].CollectData();
                for (int i = 0; i < arcs.Params.Output[1].VolatileDataCount; ++i)
                {
                    GH_Convert.ToDouble(arcs.Params.Output[1].VolatileData.get_Branch(0)[i], out arcsList[i], GH_Conversion.Both);
                    //arcsList.Add(arcs.Params.Output[1].VolatileData.get_Branch(0)[i]);
                }

                var faceMesh     = new List <object>();
                var verticesMesh = new List <object>();

                var deMesh     = new SurfaceComponents.MeshComponents.Component_DeconstructMesh();
                var meshParams = deMesh.Params.Input[0] as Grasshopper.Kernel.GH_PersistentParam <Grasshopper.Kernel.Types.GH_Mesh>;
                meshParams.PersistentData.ClearData();
                meshParams.PersistentData.Append(new GH_Mesh(delaunayMesh));

                deMesh.ExpireSolution(true);
                var docTwo = new Grasshopper.Kernel.GH_Document();
                docTwo.AddObject(deMesh, false);

                deMesh.Params.Output[0].CollectData();

                for (int i = 0; i < deMesh.Params.Output[0].VolatileDataCount; ++i)
                {
                    verticesMesh.Add(deMesh.Params.Output[0].VolatileData.get_Branch(0)[i]);
                }

                for (int i = 0; i < deMesh.Params.Output[1].VolatileDataCount; ++i)
                {
                    faceMesh.Add(deMesh.Params.Output[1].VolatileData.get_Branch(0)[i]);
                }

                var faceCullRadius = RadiusSorting(faceMesh, arcsList);

                Array.Sort(ratio);

                var splitListIndex = Convert.ToInt32((ratio[ratio.Length - 1] * faceMesh.Count) * attrition);
                //var splitListIndex = Convert.ToInt32(Attrition);

                var splitList = SplitList(faceCullRadius, splitListIndex);

                var constructMesh = new Mesh();
                var meshPoints    = new Point3d[verticesMesh.Count];
                for (int i = 0; i < verticesMesh.Count; ++i)
                {
                    GH_Convert.ToPoint3d(verticesMesh[i], ref meshPoints[i], GH_Conversion.Both);
                    constructMesh.Vertices.Add(meshPoints[i]);
                }

                var meshFaces = new Grasshopper.Kernel.Types.GH_MeshFace[splitList.Count];
                for (int i = 0; i < splitList.Count; ++i)
                {
                    GH_Convert.ToGHMeshFace(splitList[i], GH_Conversion.Both, ref meshFaces[i]);
                    constructMesh.Faces.AddFace(meshFaces[i].Value);
                }

                var ConcaveHull = constructMesh.GetNakedEdges();

                DA.SetDataList(0, ConcaveHull);
            }
        }
Esempio n. 3
0
        List <Polyline> RegionUnion(DataTree <Polyline> listOfCurves, List <Plane> frames)
        {
            int curveCount = listOfCurves.BranchCount;

            var regionUnion            = new SurfaceComponents.SolidComponents.Component_CurveBooleanUnion();
            var regionUnionInputCurves = regionUnion.Params.Input[0] as Grasshopper.Kernel.GH_PersistentParam <Grasshopper.Kernel.Types.GH_Curve>;

            regionUnionInputCurves.PersistentData.ClearData();

            var regionUnionInputPlanes = regionUnion.Params.Input[1] as Grasshopper.Kernel.GH_PersistentParam <Grasshopper.Kernel.Types.GH_Plane>;

            regionUnionInputPlanes.PersistentData.ClearData();

            var ghPlane = new GH_Plane();

            for (int i = 0; i < curveCount; ++i)
            {
                for (int j = 0; j < listOfCurves.Branch(i).Count; ++j)
                {
                    regionUnionInputCurves.PersistentData.Append(new GH_Curve(listOfCurves.Branch(i)[j].ToNurbsCurve()));

                    if (i == 0)
                    {
                        GH_Convert.ToGHPlane(frames[j], GH_Conversion.Both, ref ghPlane);
                        regionUnionInputPlanes.PersistentData.Append(new GH_Plane(ghPlane));
                    }
                }
            }

            regionUnion.ExpireSolution(true);

            var doc = new Grasshopper.Kernel.GH_Document();

            doc.AddObject(regionUnion, false);

            regionUnion.Params.Output[0].CollectData();

            int countOfUnions = regionUnion.Params.Output[0].VolatileData.PathCount;

            var listOfUnionObjs = new object();

            Curve temp     = null;
            var   polyOut  = new Polyline[countOfUnions][];
            var   polyList = new List <Polyline>();

            for (int i = 0; i < countOfUnions; ++i)
            {
                int item = regionUnion.Params.Output[0].VolatileData.get_Branch(i).Count;

                polyOut[i] = new Polyline[item];

                for (int j = 0; j < item; ++j)
                {
                    listOfUnionObjs = regionUnion.Params.Output[0].VolatileData.get_Branch(i)[j];
                    GH_Convert.ToCurve(listOfUnionObjs, ref temp, GH_Conversion.Both);
                    temp.TryGetPolyline(out polyOut[i][j]);
                    polyList.Add(polyOut[i][j]);
                }
            }

            doc.RemoveObject(regionUnion.Attributes, false);

            return(polyList);
        }