/// <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) { PlanktonMesh mesh = null; DA.GetData(0, ref mesh); DA.SetDataList(0, mesh.ToPolylines()); }
protected override void SolveInstance(IGH_DataAccess DA) { //bool inputLock = false; string key = "Leopard(" + this.InstanceGuid + ")"; GH_Structure <IGH_GeometricGoo> inGeoTree; if (!DA.GetDataTree <IGH_GeometricGoo>(0, out inGeoTree)) { return; } GH_Structure <IGH_GeometricGoo> facesGoo = new GH_Structure <IGH_GeometricGoo>(); for (int i = 0; i < inGeoTree.PathCount; i++) { for (int j = 0; j < inGeoTree.Branches[i].Count; j++) { Mesh mesh; if (!inGeoTree.Branches[i][j].CastTo <Mesh>(out mesh)) { continue; } else { GH_Path path = inGeoTree.get_Path(i); List <int> newPath = new List <int>(); for (int p = 0; p < path.Indices.Length; p++) { newPath.Add(path.Indices[p]); } PlanktonMesh pMesh = mesh.ToPlanktonMesh(); Polyline[] faces = pMesh.ToPolylines(); foreach (Polyline f in faces) { if (inGeoTree.PathCount == 1) { facesGoo.Append(GH_Convert.ToGeometricGoo(f), inGeoTree.get_Path(i)); } else { facesGoo.Append(GH_Convert.ToGeometricGoo(f), new GH_Path(newPath.ToArray())); } } } } } //ptsGoo.Simplify(GH_SimplificationMode.CollapseLeadingOverlaps); //clear all stored selection if (resetStoredPath) { storedPath.Clear(); } //delete the preview baked objects if (!freezePreviewObjects) { RemovePreviewObjects(); } //generate the preview baked objects if (!inputLock && (generatePreview || !freezePreviewObjects)) { GeneratePreViewObjectsI(facesGoo); // && !freezePreviewObjects) } //happens when unlock //if (addSelection) // SelectStoredPathObj(storedPath); GH_Structure <GH_String> pathTree = new GH_Structure <GH_String>(); //a tree that the data stored is its path for (int i = 0; i < facesGoo.PathCount; i++) { string path = facesGoo.Paths[i].ToString(); for (int j = 0; j < facesGoo.Branches[i].Count; j++) { string str = path + "(" + j.ToString() + ")"; pathTree.Append(new GH_String(str)); } } List <string> pathOrder = new List <string>(); foreach (GH_String s in pathTree.AllData(false)) { pathOrder.Add(s.ToString()); } GH_Structure <GH_Integer> orderTree = new GH_Structure <GH_Integer>(); //a tree that the data is the order of each data, this tree is reference for sorting for (int i = 0; i < pathOrder.Count; i++) { string[] pathSeg; string indSeg; GH_Path.SplitPathLikeString(pathOrder[i], out pathSeg, out indSeg); int[] pInd = System.Array.ConvertAll(pathSeg, str => System.Convert.ToInt32(str)); int index = System.Convert.ToInt32(indSeg); orderTree.Insert(new GH_Integer(i), new GH_Path(pInd), index); } GH_Structure <IGH_Goo> outGeoTree = new GH_Structure <IGH_Goo>(); GH_Structure <IGH_Goo> outIndTree = new GH_Structure <IGH_Goo>(); GH_Structure <GH_Integer> outOrderTree = new GH_Structure <GH_Integer>(); for (int i = 0; i < storedPath.Count; i++) { string p = pathOrder[System.Convert.ToInt32(storedPath[i])]; string[] pathSeg; string indSeg; if (GH_Path.SplitPathLikeString(p, out pathSeg, out indSeg)) { int[] pInd = System.Array.ConvertAll(pathSeg, str => System.Convert.ToInt32(str)); GH_Path path = new GH_Path(pInd); int index = System.Convert.ToInt32(indSeg); outGeoTree.Append((IGH_GeometricGoo)facesGoo.get_Branch(path)[index], path); outIndTree.Append(new GH_Integer(index), path); outOrderTree.Append((GH_Integer)(orderTree.get_Branch(path)[index]), path); } } if (this.sortByIndex) { outGeoTree = SortTreeByIndex(outGeoTree, outOrderTree); outIndTree = SortTreeByIndex(outIndTree, outOrderTree); } DA.SetDataTree(0, outGeoTree); DA.SetDataTree(1, outIndTree); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Structure<IGH_GeometricGoo> iMeshTree = new GH_Structure<IGH_GeometricGoo>(); GH_Structure<GH_Integer> iFaceIndices = new GH_Structure<GH_Integer>(); DA.GetDataTree<IGH_GeometricGoo>(0, out iMeshTree); DA.GetDataTree<GH_Integer>(1, out iFaceIndices); GH_Structure<IGH_GeometricGoo> oFaceTree = new GH_Structure<IGH_GeometricGoo>(); GH_Structure<IGH_Goo> oFaceVerticesTree = new GH_Structure<IGH_Goo>(); GH_Structure<IGH_Goo> oFacesEdgesTree = new GH_Structure<IGH_Goo>(); GH_Structure<IGH_Goo> oVertexNFTree = new GH_Structure<IGH_Goo>(); for (int i = 0; i < iMeshTree.PathCount; i++) { GH_Path path = iMeshTree.get_Path(i); for (int j = 0; j < iMeshTree.Branches[i].Count; j++) { Mesh mesh; if (!iMeshTree.Branches[i][j].CastTo<Mesh>(out mesh)) continue; else { PlanktonMesh pMesh = mesh.ToPlanktonMesh(); Polyline[] polyFaces = pMesh.ToPolylines(); for (int vi = 0; vi < iFaceIndices.PathCount; vi++) { int id; GH_Path pathFaces = iFaceIndices.get_Path(vi); if (path != pathFaces) continue; for (int vj = 0; vj < iFaceIndices.Branches[vi].Count; vj++) { iFaceIndices.Branches[vi][vj].CastTo<int>(out id); // getting neighbouring vertices oFaceTree.Append( GH_Convert.ToGeometricGoo(polyFaces[id]), path); List<int> newPath = new List<int>(); for (int p = 0; p < path.Indices.Length; p++) newPath.Add(path.Indices[p]); newPath.Add(vj); GH_Path vertexPath = new GH_Path(newPath.ToArray()); //vertices on face foreach (int fv in pMesh.Faces.GetFaceVertices(id)) oFaceVerticesTree.Append(GH_Convert.ToGeometricGoo(pMesh.Vertices[fv].ToPoint3d()), vertexPath); //edges on face and neighbour face of face foreach (int fe in pMesh.Faces.GetHalfedges(id)) { if (pMesh.Halfedges.IsBoundary(fe)) continue; int fae = pMesh.Halfedges.GetPairHalfedge(fe); if (fae != -1) { int[] vts = pMesh.Halfedges.GetVertices(fae); oFacesEdgesTree.Append(GH_Convert.ToGeometricGoo( new LineCurve(pMesh.Vertices[vts[0]].ToPoint3d(), pMesh.Vertices[vts[1]].ToPoint3d())), path); int f = pMesh.Halfedges[fae].AdjacentFace; Polyline facePoly = Leopard.MeshEdit.getFacePolyline(pMesh, f); oVertexNFTree.Append(GH_Convert.ToGeometricGoo(facePoly), vertexPath); } } } } } } } DA.SetDataTree(0, oFaceTree); DA.SetDataTree(1, oFaceVerticesTree); DA.SetDataTree(2, oFacesEdgesTree); DA.SetDataTree(3, oVertexNFTree); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Structure <IGH_GeometricGoo> iMeshTree = new GH_Structure <IGH_GeometricGoo>(); DA.GetDataTree <IGH_GeometricGoo>(0, out iMeshTree); GH_Structure <IGH_Goo> oFaceCentersTree = new GH_Structure <IGH_Goo>(); GH_Structure <IGH_Goo> oFaceBoundarysTree = new GH_Structure <IGH_Goo>(); GH_Structure <IGH_Goo> oNakedFacesTree = new GH_Structure <IGH_Goo>(); GH_Structure <GH_Integer> oNakedIndicesTree = new GH_Structure <GH_Integer>(); GH_Structure <IGH_Goo> oClosedFacesTree = new GH_Structure <IGH_Goo>(); GH_Structure <GH_Integer> oClosedIndicesTree = new GH_Structure <GH_Integer>(); for (int i = 0; i < iMeshTree.PathCount; i++) { GH_Path path = iMeshTree.get_Path(i); for (int j = 0; j < iMeshTree.Branches[i].Count; j++) { Mesh mesh; if (!iMeshTree.Branches[i][j].CastTo <Mesh>(out mesh)) { continue; } else { PlanktonMesh pMesh = mesh.ToPlanktonMesh(); for (int f = 0; f < pMesh.Faces.Count; f++) { // get face centers PlanktonXYZ center = pMesh.Faces.GetFaceCenter(f); oFaceCentersTree.Append(GH_Convert.ToGeometricGoo(center.ToPoint3d()), path); } // get face boundarys Polyline[] boundaryCurves = pMesh.ToPolylines(); for (int p = 0; p < boundaryCurves.Length; p++) { oFaceBoundarysTree.Append(GH_Convert.ToGeometricGoo(boundaryCurves[p]), path); if (pMesh.Faces.NakedEdgeCount(p) > 0) { oNakedFacesTree.Append(GH_Convert.ToGeometricGoo(boundaryCurves[p]), path); oNakedIndicesTree.Append(new GH_Integer(p), path); } else { oClosedFacesTree.Append(GH_Convert.ToGeometricGoo(boundaryCurves[p]), path); oClosedIndicesTree.Append(new GH_Integer(p), path); } } //for (int e = 0; e < pMesh.Halfedges.Count; e++) //{ // if (pMesh.Halfedges.GetPairHalfedge(e) > e) continue; // int[] vts = pMesh.Halfedges.GetVertices(e); // oEdgesTree.Append( // GH_Convert.ToGeometricGoo(new LineCurve( // pMesh.Vertices[vts[0]].ToPoint3d(), // pMesh.Vertices[vts[1]].ToPoint3d())), path); // if (pMesh.Halfedges.IsBoundary(e)) // { // oNakedEdgesTree.Append( // GH_Convert.ToGeometricGoo(new LineCurve( // pMesh.Vertices[vts[0]].ToPoint3d(), // pMesh.Vertices[vts[1]].ToPoint3d())), path); // oNakedIndicesTree.Append(new GH_Integer(e / 2), path); // } // else // { // oClosedEdgesTree.Append( // GH_Convert.ToGeometricGoo(new LineCurve( // pMesh.Vertices[vts[0]].ToPoint3d(), // pMesh.Vertices[vts[1]].ToPoint3d())), path); // oClosedIndicesTree.Append(new GH_Integer(e / 2), path); // } //} } } } DA.SetDataTree(0, oFaceCentersTree); DA.SetDataTree(1, oFaceBoundarysTree); DA.SetDataTree(2, oNakedFacesTree); DA.SetDataTree(3, oNakedIndicesTree); DA.SetDataTree(4, oClosedFacesTree); DA.SetDataTree(5, oClosedIndicesTree); //DA.GetData<Mesh>("Mesh", ref iMesh); //pMesh = iMesh.ToPlanktonMesh(); //for (int i = 0; i < pMesh.Faces.Count; i++) //{ // // get face centers // PlanktonXYZ center = pMesh.Faces.GetFaceCenter(i); // oFaceCenters.Add(center.ToPoint3d()); //} //// get face boundarys //Polyline[] boundaryCurves = pMesh.ToPolylines(); //for (int p = 0; p < boundaryCurves.Length; p++) //{ // oFaceBoundarys.Add(boundaryCurves[p]); // if (pMesh.Faces.NakedEdgeCount(p) > 0) // oNakedFaces.Add(boundaryCurves[p]); // else // oClosedFaces.Add(boundaryCurves[p]); //} //DA.SetDataList("Face Centers", oFaceCenters); //DA.SetDataList("Face Boundary Curves", oFaceBoundarys); //DA.SetDataList("Face Naked", oNakedFaces); //DA.SetDataList("Face Closed", oClosedFaces); }