/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { Mesh M = new Mesh(); if (!DA.GetData(0, ref M)) return; P_mesh PlanktonMesh = new P_mesh(M); DA.SetData(0, PlanktonMesh); }
// public void ReIndex() //clear away all the dead elements to save space // //maybe it is better to just create a fresh one rather than trying to shuffle the existing // { // } public P_mesh Dual() { // can later add options for other ways of defining face centres (barycenter/circumcenter etc) // won't work yet with naked boundaries P_mesh P = this; P_mesh D = new P_mesh(); //for every primal face, add the barycenter to the dual's vertex list //dual vertex outgoing HE is primal face's start HE //for every vertex of the primal, add a face to the dual //dual face's startHE is primal vertex's outgoing's pair for (int i = 0; i < P.Faces.Count; i++) { D.Vertices.Add(new P_vertex(P.FaceCentroid(i))); List<int> FaceHalfedges = P.FaceHEs(i); for (int j = 0; j < FaceHalfedges.Count; j++) { if (P.HalfEdges[P.PairHalfEdge(FaceHalfedges[j])].AdjacentFace != -1) { // D.Vertices[i].OutgoingHalfEdge = FaceHalfedges[j]; D.Vertices[D.Vertices.Count-1].OutgoingHalfEdge = P.PairHalfEdge(FaceHalfedges[j]); break; } } } for (int i = 0; i < P.Vertices.Count; i++) { if (P.VertexNakedEdgeCount(i) == 0) { D.Faces.Add(new P_face()); // D.Faces[i].FirstHalfEdge = P.PairHalfEdge(P.Vertices[i].OutgoingHalfEdge); D.Faces[D.Faces.Count-1].FirstHalfEdge = P.Vertices[i].OutgoingHalfEdge; } } // dual halfedge start V is primal AdjacentFace // dual halfedge AdjacentFace is primal end V // dual nextHE is primal's pair's prev // dual prevHE is primal's next's pair // halfedge pairs stay the same int newIndex = 0; for (int i = 0; i < P.HalfEdges.Count; i++) { if ((P.HalfEdges[i].AdjacentFace != -1) & (P.HalfEdges[P.PairHalfEdge(i)].AdjacentFace != -1)) { P_halfedge DualHE = new P_halfedge(); P_halfedge PrimalHE = P.HalfEdges[i]; //DualHE.StartVertex = PrimalHE.AdjacentFace; DualHE.StartVertex = P.HalfEdges[P.PairHalfEdge(i)].AdjacentFace; if (P.VertexNakedEdgeCount(PrimalHE.StartVertex) == 0) { //DualHE.AdjacentFace = P.HalfEdges[P.PairHalfEdge(i)].StartVertex; DualHE.AdjacentFace = PrimalHE.StartVertex; } else { DualHE.AdjacentFace = -1; } //This will currently fail with open meshes... //one option could be to build the dual with all halfedges, but mark some as dead //if they connect to vertex -1 //mark the 'external' faces all as -1 (the ones that are dual to boundary verts) //then go through and if any next or prevs are dead hes then replace them with the next one around //this needs to be done repeatedly until no further change //DualHE.NextHalfEdge = P.HalfEdges[P.PairHalfEdge(i)].PrevHalfEdge; DualHE.NextHalfEdge = P.PairHalfEdge(PrimalHE.PrevHalfEdge); //DualHE.PrevHalfEdge = P.PairHalfEdge(PrimalHE.NextHalfEdge); DualHE.PrevHalfEdge = P.HalfEdges[P.PairHalfEdge(i)].NextHalfEdge; DualHE.Index = newIndex; D.HalfEdges.Add(DualHE); newIndex += 1; } } return D; }