Ejemplo n.º 1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //container for errors/messages passed by controller, partition, etc.
            List <String> errorContainer = new List <String>();

            GH_PreviewUtil preview = new GH_PreviewUtil(true);

            //declare placeholder variables and assign initial empty mesh
            Mesh baseMesh             = new Rhino.Geometry.Mesh();
            int  errorMetricIdentifer = -1;
            int  numPanels            = -1;

            //Retrieve input data
            if (!DA.GetData(0, ref baseMesh))
            {
                return;
            }
            if (!DA.GetData(1, ref errorMetricIdentifer))
            {
                return;
            }
            if (!DA.GetData(2, ref numPanels))
            {
                return;
            }

            if (baseMesh.DisjointMeshCount > 1)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Problem with mesh input - disjoint mesh");
            }
            else
            {
                //compute and unify normal
                baseMesh.Normals.ComputeNormals();
                baseMesh.UnifyNormals();

                //create wingedmesh from rhinomesh
                WingedMesh myMesh = new WingedMesh(errorContainer, baseMesh);

                PlanarMesher controller = new PlanarMesher(errorContainer, myMesh, baseMesh, numPanels, errorMetricIdentifer, preview);

                controller.createFirstCluster();

                for (int i = 0; i < 40; i++)
                {
                    controller.iterateCluster();
                    //controller.currentPartition.drawProxies(preview);
                }

                controller.createConnectivityMesh();

                //creating voronoi
                WingedMesh voronoiMesh = new WingedMesh(errorContainer, controller.currentPartition.proxyToMesh.convertWingedMeshToPolylines());

                //set all the output data
                DA.SetDataList(0, voronoiMesh.convertWingedMeshToPolylines());
            }

            foreach (var item in errorContainer)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, item);
            }
        }
Ejemplo n.º 2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //container for errors/messages
            List <String> errorContainer = new List <String>();

            GH_PreviewUtil preview = new GH_PreviewUtil(true);

            //declare placeholder variables and assign initial empty mesh
            Mesh    baseMesh             = new Rhino.Geometry.Mesh();
            int     errorMetricIdentifer = -1;
            int     numPanels            = -1;
            Boolean run = false;

            //Retrieve input data
            if (!DA.GetData(0, ref baseMesh))
            {
                return;
            }
            if (!DA.GetData(1, ref errorMetricIdentifer))
            {
                return;
            }
            if (!DA.GetData(2, ref numPanels))
            {
                return;
            }
            if (!DA.GetData(3, ref run))
            {
                return;
            }

            if (run)
            {
                if (baseMesh.DisjointMeshCount > 1)
                {
                    errorContainer.Add("Problem with mesh input - disjoint mesh");
                }
                else
                {
                    //compute and unify normal
                    baseMesh.Normals.ComputeNormals();
                    baseMesh.UnifyNormals();

                    //create wingedmesh from rhinomesh
                    WingedMesh myMesh = new WingedMesh(errorContainer, baseMesh);

                    PlanarMesher controller = new PlanarMesher(errorContainer, myMesh, baseMesh, numPanels, errorMetricIdentifer, preview);

                    controller.createFirstCluster();

                    for (int i = 0; i < 40; i++)
                    {
                        controller.iterateCluster();
                        controller.currentPartition.drawProxies(preview);
                    }

                    controller.createConnectivityMesh();

                    //creating voronoi
                    WingedMesh voronoiMesh = new WingedMesh(errorContainer, controller.currentPartition.proxyToMesh.convertWingedMeshToPolylines());

                    controller.planariseConnectivityMesh();

                    //convert faces edges to polylines for viewing
                    List <Polyline> boundaryEdges = controller.currentPartition.proxyToMesh.convertWingedMeshToPolylines();

                    List <Plane> proxyPlanes = new List <Plane>();
                    foreach (Proxy proxy in controller.currentPartition.proxies)
                    {
                        proxyPlanes.Add(proxy.rhinoPlane);
                    }
                    List <Mesh> proxyMeshes = new List <Mesh>();
                    foreach (Proxy proxy in controller.currentPartition.proxies)
                    {
                        proxyMeshes.Add(proxy.proxyAsMesh);
                    }

                    List <Vector3d> faceNormals = new List <Vector3d>();
                    List <Point3d>  faceCentres = new List <Point3d>();
                    for (int i = 0; i < controller.currentPartition.proxyToMesh.faces.Count; i++)
                    {
                        faceNormals.Add(new Vector3d(controller.currentPartition.proxyToMesh.faces[i].faceNormal));
                        faceCentres.Add(new Point3d(controller.currentPartition.proxyToMesh.faces[i].faceCentre));
                    }

                    //set all the output data
                    DA.SetDataList(1, proxyPlanes);
                    DA.SetDataList(2, boundaryEdges);
                    DA.SetData(3, controller.currentPartition.proxyToMesh);
                    DA.SetDataList(4, faceNormals);
                    DA.SetDataList(5, faceCentres);
                    DA.SetDataList(6, voronoiMesh.convertWingedMeshToPolylines());
                }
                DA.SetDataList(0, errorContainer);
            }
        }