示例#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);
            }
        }
示例#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);
            }
        }
示例#3
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
            List<Curve> baseCurves = new List<Curve>();

            //Retrieve input data
            if (!DA.GetDataList(0, baseCurves))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Couldn't infer list of polyline face boundaries from input");
                return;
            }
            //if (!DA.GetData(1, ref run)) { return; }

            List<Polyline> baseMesh = new List<Polyline>();
            for (int i = 0; i < baseCurves.Count; i++)
	        {
                 Polyline pl;
		         if (baseCurves[i].TryGetPolyline(out pl))
                 {
                     baseMesh.Add(pl);
                 }
                 else
                 {
                     this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Couldn't get a polyline from boundary curve #" + i.ToString());
                 }
	        }

            try // catch any unexpected errors
            {
                // TODO: disjoint mesh check

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

                PlanarMesher controller = new PlanarMesher(errorContainer, myMesh, null, myMesh.faces.Count, -1, preview);

                controller.CreateFromInputMesh();
                controller.createConnectivityMesh();
                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);
                }

                //set all the output data
                DA.SetDataList(0, proxyPlanes);
                DA.SetDataList(1, boundaryEdges);
            }
            catch (Exception e)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.StackTrace);
            }

            foreach (var item in errorContainer)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, item);
            }
        }
示例#4
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
            List <Curve> baseCurves = new List <Curve>();

            //Retrieve input data
            if (!DA.GetDataList(0, baseCurves))
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Couldn't infer list of polyline face boundaries from input");
                return;
            }
            //if (!DA.GetData(1, ref run)) { return; }

            List <Polyline> baseMesh = new List <Polyline>();

            for (int i = 0; i < baseCurves.Count; i++)
            {
                Polyline pl;
                if (baseCurves[i].TryGetPolyline(out pl))
                {
                    baseMesh.Add(pl);
                }
                else
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Couldn't get a polyline from boundary curve #" + i.ToString());
                }
            }

            try // catch any unexpected errors
            {
                // TODO: disjoint mesh check

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

                PlanarMesher controller = new PlanarMesher(errorContainer, myMesh, null, myMesh.faces.Count, -1, preview);

                controller.CreateFromInputMesh();
                controller.createConnectivityMesh();
                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);
                }

                //set all the output data
                DA.SetDataList(0, proxyPlanes);
                DA.SetDataList(1, boundaryEdges);
            }
            catch (Exception e)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.StackTrace);
            }

            foreach (var item in errorContainer)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, item);
            }
        }
示例#5
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);
            }
        }
示例#6
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);
            }
        }