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); } }
private DataTree <object> CorrectMesh( Dictionary <string, Mesh> meshes, Dictionary <string, List <List <double> > > points, double distance ) { var newMeshes = new DataTree <object>(); var j = 0; foreach (var key in meshes.Keys) { if (!points.ContainsKey(key)) { continue; } var patchPoints = points[key]; var ghPoints = patchPoints.Select(point => new Point3d(point[0], point[1], point[2])).ToList(); var mesh = new Mesh(); // Check mesh normal. If the normal direction is fx Z, check that the points and mesh have the same value. If not throw an error. GH_Convert.ToMesh(meshes[key], ref mesh, GH_Conversion.Primary); var faceCenters = Enumerable.Range(0, mesh.Faces.Count()) .Select(index => mesh.Faces.GetFaceCenter(index)).ToList(); var faceIndices = RTree.Point3dClosestPoints(faceCenters, ghPoints, distance); var newMesh = new Mesh(); newMesh.Vertices.AddVertices(mesh.Vertices); foreach (var face in faceIndices) { if (face.Length > 0) { newMesh.Faces.AddFace(mesh.Faces[face[0]]); } } newMesh.Normals.ComputeNormals(); newMesh.UnifyNormals(); newMesh.Compact(); var path = new GH_Path(j); newMeshes.Add(newMesh, path); j++; } return(newMeshes); }
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); } }
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); } }
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); } }