public bool BuildDataBase() { if (U == 0 || V == 0) { return(false); } else { double stepU = (2 * Math.PI) / (U - 1); double stepV = 1.0 / (V - 1); Point3d pt; // Vertices for (int i = 0; i < U - 1; i++) { for (int j = 0; j < V; j++) { u = stepU * i; v = stepV * j - 0.5; x = r1 * ((1 + (v / 2) * Math.Cos(u / 2)) * Math.Cos(u)); y = r2 * ((1 + (v / 2) * Math.Cos(u / 2)) * Math.Sin(u)); z = h * ((v / 2) * Math.Sin(u / 2)); pt = pl.PointAt(x, y, z); vertices.Add(new ITopologicVertex(pt.X, pt.Y, pt.Z, u, v, 0, keyNode)); keyNode++; } } //Quad-faces for (int i = 0; i < U - 1; i++) { for (int j = 0; j < V - 1; j++) { int[] f = new int[4]; f[0] = (i * V + j) + 1; f[1] = (i * V + (j + 1)) + 1; f[2] = ((i + 1) * V + (j + 1)) + 1; f[3] = ((i + 1) * V + j) + 1; if (i == U - 2) { f[0] = (i * V + j) + 1; f[1] = (i * V + (j + 1)) + 1; f[2] = ((V - 1) - (j + 1)) + 1; f[3] = ((V - 1) - (j)) + 1; } ISurfaceElement iF = new ISurfaceElement(f); iF.Key = keyElement; faces.Add(iF); keyElement++; } } return(true); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <int> vKeys = new List <int>(); DA.GetData(0, ref vKeys); ISurfaceElement e = new ISurfaceElement(vKeys.ToArray()); DA.SetData(0, e); }
/// <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) { int A = 0, B = 0, C = 0; DA.GetData(0, ref A); DA.GetData(1, ref B); DA.GetData(2, ref C); ISurfaceElement e = new ISurfaceElement(A, B, C); DA.SetData(0, e); }
public static IMesh ExtrudeTwoDimensionalElementsEdges(IMesh mesh, IEnumerable <int> eKeys, double length) { IMesh dM = mesh.CleanCopy(); ITopologicVertex v, vv; IVector3D n; IElement e, nE; int next_vKey = mesh.FindNextVertexKey(); int next_eKey = mesh.FindNextElementKey(); foreach (int eK in eKeys) { e = mesh.GetElementWithKey(eK); if (e.TopologicDimension == 2) { List <int> vertices = new List <int>(); foreach (int vK in e.Vertices) { v = mesh.GetVertexWithKey(vK); n = mesh.Topology.ComputeVertexNormal(vK); vv = new ITopologicVertex(v.Position + n, next_vKey); dM.AddVertex(next_vKey, vv); vertices.Add(next_vKey); next_vKey++; } int[] hf; List <int> temp; int next_i, prev_i; for (int i = 1; i <= e.HalfFacetsCount; i++) { e.GetHalfFacet(i, out hf); temp = new List <int>(hf); next_i = i; if (i == e.HalfFacetsCount) { next_i = 0; } prev_i = i - 1; temp.Add(vertices[next_i]); temp.Add(vertices[prev_i]); nE = new ISurfaceElement(temp.ToArray()); dM.AddElement(nE); } } } dM.BuildTopology(true); return(dM); }
public bool BuildDataBase() { if (u == 0 || v == 0) { return(false); } else { Circle c1 = new Circle(pl, r1); Circle c2 = new Circle(pl, r2); c2.Translate(pl.Normal * h); double t1 = (2 * Math.PI) / u; double t2 = 1.0 / v; //Construct Vertices for (int i = 0; i < u; i++) { Line ln = new Line(c1.PointAt(t1 * i), c2.PointAt(t1 * i)); for (int j = 0; j <= v; j++) { ITopologicVertex p = new ITopologicVertex(ln.PointAt(t2 * j)); p.Key = keyVertex; vertices.Add(p); keyVertex++; } } //Construct Faces for (int i = 0; i < u; i++) { int idxA = i; int idxB = i + 1; if (idxA == (u - 1)) { idxB = 0; } for (int j = 0; j < v; j++) { ISurfaceElement f = new ISurfaceElement((idxA * (v + 1) + j) + 1, (idxA * (v + 1) + j + 1) + 1, (idxB * (v + 1) + j + 1) + 1, (idxB * (v + 1) + j) + 1); f.Key = keyElement; faces.Add(f); keyElement++; } } return(true); } }
public static IMesh Triangulate2DElements(IMesh mesh) { IMesh triangulated = new IMesh(); foreach (ITopologicVertex v in mesh.Vertices) { triangulated.AddVertex(v.Key, new ITopologicVertex(v)); } ISurfaceElement face; int key = mesh.FindNextVertexKey(); foreach (IElement e in mesh.Elements) { if (e.TopologicDimension == 2) { if (e.VerticesCount == 3) { face = new ISurfaceElement(e.Vertices[0], e.Vertices[1], e.Vertices[2]); triangulated.AddElement(face); } else if (e.VerticesCount == 4) { face = new ISurfaceElement(e.Vertices[0], e.Vertices[1], e.Vertices[3]); triangulated.AddElement(face); face = new ISurfaceElement(e.Vertices[3], e.Vertices[1], e.Vertices[2]); triangulated.AddElement(face); } else { IPoint3D pos = ISubdividor.ComputeAveragePosition(e.Vertices, mesh); ITopologicVertex v = new ITopologicVertex(pos.X, pos.Y, pos.Z, key); triangulated.AddVertex(key, v); for (int i = 1; i <= e.HalfFacetsCount; i++) { int[] hf; e.GetHalfFacet(i, out hf); face = new ISurfaceElement(hf[0], hf[1], key); triangulated.AddElement(face); } key++; } } } triangulated.BuildTopology(); return(triangulated); }
public Boolean BuildDataBase() { if (sizeU == 0 || sizeV == 0) { return(false); } else { double stepU = sizeU / U; double stepV = sizeV / V; double mapU = 1.0 / U; double mapV = 1.0 / V; int keyNode = 1; //Creation of vertices for (int i = 0; i <= U; i++) { for (int j = 0; j <= V; j++) { Point3d pt = pl.PointAt(i * stepU - sizeU / 2, j * stepV - sizeV / 2, 0); Tuple <double, double> uvPt = Tuple.Create(i * mapU, j * mapV); vertices.Add(new ITopologicVertex(pt.X, pt.Y, pt.Z, i * mapU, j * mapV, 0, keyNode)); keyNode++; } } //Toplogy of quadragular faces for (int i = 0; i < U; i++) { for (int j = 0; j < V; j++) { int[] f = new int[4]; f[0] = ((i * (V + 1)) + j) + 1; f[1] = ((i * (V + 1)) + (j + 1)) + 1; f[2] = (((i + 1) * (V + 1)) + (j + 1)) + 1; f[3] = (((i + 1) * (V + 1)) + j) + 1; ISurfaceElement iF = new ISurfaceElement(f); iF.Key = keyElement; faces.Add(iF); keyElement++; } } return(true); } }
public bool BuildDataBase() { if (vertices != null) { Boolean flag = false; if (rhinoMesh.TextureCoordinates.Count == rhinoMesh.Vertices.Count) { flag = true; } Point2f uvw = new Point2f(0, 0); for (int i = 0; i < rhinoMesh.Vertices.Count; i++) { if (flag) { uvw = rhinoMesh.TextureCoordinates[i]; } ITopologicVertex v = new ITopologicVertex(rhinoMesh.Vertices[i]); v.Key = i + 1; v.TextureCoordinates = new double[] { uvw.X, uvw.Y, 0 }; vertices.Add(v); } foreach (MeshFace f in rhinoMesh.Faces) { ISurfaceElement iF = new ISurfaceElement(vertices[f.A].Key, vertices[f.B].Key, vertices[f.C].Key); if (f.IsQuad) { iF = new ISurfaceElement(vertices[f.A].Key, vertices[f.B].Key, vertices[f.C].Key, vertices[f.D].Key); } iF.Key = keyElement; faces.Add(iF); keyElement++; } return(true); } else { return(false); } }
public bool BuildDataBase() { if (U == 0 || V == 0) { return(false); } else { double x, y, z, u, v, sqU, sqV; Point3d pt; List <Point3d> tempV = new List <Point3d>(); Boolean flag; int keyMap = 1; Dictionary <int, int> maps = new Dictionary <int, int>(); if (D2.T0 < 0) { D2.T0 = 0; } if (D2.T1 > 2 * Math.PI) { D2.T1 = 2 * Math.PI; } uStep = D1.Length / (U - 1); vStep = D2.Length / (V - 1); // Vertices for (int i = 0; i < U; i++) { for (int j = 0; j < V; j++) { u = uStep * i + D1.T0; v = vStep * j + D2.T0; sqU = Math.Pow(u, 2); sqV = Math.Pow(v, 2); x = a * Math.Cosh(u) * Math.Cos(v); y = b * Math.Cosh(u) * Math.Sin(v); z = c * Math.Sinh(u); pt = pl.PointAt(x, y, z); //Temporary list of vertices tempV.Add(pt); //list of unique vertices flag = true; vertices.ForEach(eval => { if (eval.DistanceTo(pt) < Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) { flag = false; } }); if (flag) { vertices.Add(new ITopologicVertex(pt.X, pt.Y, pt.Z, u, v, 0, keyMap)); keyMap++; } } } //Creates mapping for (int i = 0; i < tempV.Count; i++) { pt = tempV[i]; keyMap = -1; vertices.ForEach(eval => { if (eval.DistanceTo(pt) < 0.01) { keyMap = eval.Key; } }); maps.Add(i, keyMap); } //Quad-faces for (int i = 0; i < U - 1; i++) { for (int j = 0; j < V - 1; j++) { int[] f = new int[4]; f[0] = maps[i * (V) + j]; f[1] = maps[i * (V) + (j + 1)]; f[2] = maps[(i + 1) * (V) + (j + 1)]; f[3] = maps[(i + 1) * (V) + j]; ISurfaceElement iF = new ISurfaceElement(f); iF.Key = keyElement; faces.Add(iF); keyElement++; } } return(true); } }
public static IMesh CatmullClark(IMesh mesh) { IMesh sMesh = new IMesh(); //Old vertices foreach (int vK in mesh.VerticesKeys) { sMesh.AddVertex(vK, new ITopologicVertex(ComputesCatmullClarkVertexPosition(mesh, vK))); } // Subidvision int key = mesh.FindNextVertexKey(); int[] hf; IElement element_sibling; int elementID_sibling, halfFacetID_sibling; Boolean visited; Dictionary <int, int[]> eVertex = new Dictionary <int, int[]>(); Dictionary <int, int> fVertex = new Dictionary <int, int>(); IPoint3D pos; int count = mesh.ElementsKeys.Count; // Vertices foreach (int elementID in mesh.ElementsKeys) { IElement e = mesh.GetElementWithKey(elementID); //Add face vertex pos = ComputeAveragePosition(e.Vertices, mesh); sMesh.AddVertex(key, new ITopologicVertex(pos.X, pos.Y, pos.Z, key)); fVertex.Add(elementID, key); key++; if (!e.Visited) { if (e.TopologicDimension == 2) { if (!eVertex.ContainsKey(elementID)) { eVertex.Add(elementID, new int[e.HalfFacetsCount]); } for (int halfFacetID = 1; halfFacetID <= e.HalfFacetsCount; halfFacetID++) { e.GetHalfFacet(halfFacetID, out hf); visited = e.IsHalfFacetVisited(halfFacetID); if (!visited) { e.RegisterHalfFacetVisit(halfFacetID); e.GetHalfFacet(halfFacetID, out hf); pos = ComputeAveragePosition(hf, mesh); sMesh.AddVertex(key, new ITopologicVertex(pos.X, pos.Y, pos.Z, key)); eVertex[elementID][halfFacetID - 1] = key; if (!e.IsNakedSiblingHalfFacet(halfFacetID)) { while (!visited) { e.RegisterHalfFacetVisit(halfFacetID); //Collect information of siblings elementID_sibling = e.GetSiblingElementID(halfFacetID); halfFacetID_sibling = e.GetSiblingHalfFacetID(halfFacetID); element_sibling = mesh.GetElementWithKey(elementID_sibling); visited = element_sibling.IsHalfFacetVisited(halfFacetID_sibling); halfFacetID = halfFacetID_sibling; e = element_sibling; if (!eVertex.ContainsKey(elementID_sibling)) { eVertex.Add(elementID_sibling, new int[e.HalfFacetsCount]); } eVertex[elementID_sibling][halfFacetID - 1] = key; } } key++; } } } } } mesh.CleanElementsVisits(); //Faces int prev; int[] data; foreach (int elementID in mesh.ElementsKeys) { IElement e = mesh.GetElementWithKey(elementID); if (e.TopologicDimension == 2) { int[] eV = eVertex[elementID]; for (int i = 0; i < e.Vertices.Length; i++) { prev = i - 1; if (prev < 0) { prev = e.Vertices.Length - 1; } data = new int[] { e.Vertices[i], eV[prev], fVertex[elementID], eV[i] }; ISurfaceElement face = new ISurfaceElement(data); sMesh.AddElement(face); } } } // Edge Vertex foreach (int eK in eVertex.Keys) { IElement e = mesh.GetElementWithKey(eK); for (int i = 1; i <= e.HalfFacetsCount; i++) { int[] hf1; e.GetHalfFacet(i, out hf1); ITopologicVertex v1 = sMesh.GetVertexWithKey(eVertex[eK][i - 1]); v1.Position = ComputeCatmullClarkEdgeVertexPosition(hf1, mesh); sMesh.SetVertex(v1.Key, v1); } } //Build Mesh sMesh.BuildTopology(); return(sMesh); }
public static HashSet <int> TryParseToIguanaElement(int elementType, long[] nodes, int nodes_per_element, int number_of_elements, ref HashSet <int> parsedNodes, ref IMesh mesh) { if (IsElementImplemented(elementType)) { for (int j = 0; j < number_of_elements; j++) { int[] eD = new int[nodes_per_element]; IElement e = null; for (int k = 0; k < nodes_per_element; k++) { eD[k] = (int)nodes[j * nodes_per_element + k]; parsedNodes.Add(eD[k]); } switch (elementType) { //1st-order Triangle Face case 2: e = new ISurfaceElement(eD); break; //1st-order Quadrangle Face case 3: e = new ISurfaceElement(eD); break; //2nd-order 6-node triangle case 9: e = new ISurfaceElement.HighOrder.ITriangle6(eD); break; //2nd-order 9-node quadrangle case 10: e = new ISurfaceElement.HighOrder.IQuadrangle9(eD); break; //2nd-order 8-node quadrangle case 16: e = new ISurfaceElement.HighOrder.IQuadrangle8(eD); break; //3rd-order 9-node incomplete triangle case 20: e = new ISurfaceElement.HighOrder.ITriangle9(eD); break; //4th-order 12-node incomplete triangle case 22: e = new ISurfaceElement.HighOrder.ITriangle12(eD); break; //5th-order 15-node incomplete triangle case 24: e = new ISurfaceElement.HighOrder.ITriangle15(eD); break; //2nd-order 10-node tetrahedron case 11: e = new ITetrahedronElement.HighOrder.ITetrahedron10(eD); break; //1s-order 4-node tetrahedron element case 4: e = new ITetrahedronElement(eD); break; //2n-order 13-node pyramid case 19: e = new IPyramidElement.HighOrder.IPyramid13(eD); break; //1st-order 5-node pyramid element case 7: e = new IPyramidElement(eD); break; //1st-order 6-node prism element case 6: e = new IPrismElement(eD); break; //2nd-order 15-node prism case 18: e = new IPrismElement.HighOrder.IPrism15(eD); break; //1st-order 8-node hexahedron element case 5: e = new IHexahedronElement(eD); break; //2nd-order 20-node hexahedron case 17: e = new IHexahedronElement.HighOrder.IHexahedron20(eD); break; } if (e != null) { mesh.AddElement(e); } } } return(parsedNodes); }
public bool BuildDataBase() { if (U == 0 || V == 0) { return(false); } else { double x, y, z, u, v; Point3d pt; List <Point3d> tempV = new List <Point3d>(); Boolean flag; int keyMap = 1; Dictionary <int, int> maps = new Dictionary <int, int>(); if (D1.T0 < 0) { D1.T0 = 0; } if (D1.T1 > Math.PI) { D1.T1 = Math.PI; } if (D2.T0 < 0) { D2.T0 = 0; } if (D2.T1 > 2 * Math.PI) { D2.T1 = 2 * Math.PI; } uStep = D1.Length / (U - 1); vStep = D2.Length / (V - 1); // Vertices for (int i = 0; i < U; i++) { for (int j = 0; j < V; j++) { u = uStep * i + D1.T0; v = vStep * j + D2.T0; x = a * Math.Sin(u) * Math.Cos(v); y = b * Math.Sin(u) * Math.Sin(v); z = c * Math.Cos(u); pt = pl.PointAt(x, y, z); //Temporary list of vertices tempV.Add(pt); //list of unique vertices flag = true; vertices.ForEach(eval => { if (eval.DistanceTo(pt) < Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance) { flag = false; } }); if (flag) { vertices.Add(new ITopologicVertex(pt.X, pt.Y, pt.Z, u, v, 0, keyMap)); keyMap++; } } } //Creates mapping for (int i = 0; i < tempV.Count; i++) { pt = tempV[i]; keyMap = -1; vertices.ForEach(eval => { if (eval.DistanceTo(pt) < 0.01) { keyMap = eval.Key; } }); maps.Add(i, keyMap); } List <int> f; //Quad-faces for (int i = 0; i < U - 1; i++) { for (int j = 0; j < V - 1; j++) { int A = maps[i * (V) + j]; int B = maps[i * (V) + (j + 1)]; int C = maps[(i + 1) * (V) + (j + 1)]; int D = maps[(i + 1) * (V) + j]; f = new List <int>(); if (!f.Contains(A)) { f.Add(A); } if (!f.Contains(B)) { f.Add(B); } if (!f.Contains(C)) { f.Add(C); } if (!f.Contains(D)) { f.Add(D); } ISurfaceElement face = new ISurfaceElement(f.ToArray()); faces.Add(face); } } return(true); } }