Пример #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);
            }
        }