// =============================================================================================== // Get Vertices from breps // =============================================================================================== public static DataTree <Point3d> BrepVertices(List <Brep> breps) { DataTree <Point3d> faceVertices = new DataTree <Point3d>(); int i = 0; foreach (Brep brep in breps) { int j = 0; foreach (var face in brep.Faces) { Brep faceBrep = face.DuplicateFace(true); var pts = faceBrep.DuplicateVertices(); for (int k = 0; k < pts.Length; k++) { GH_Path path = new GH_Path(i, j); faceVertices.Add(pts[k], path); } j++; } i++; } return(faceVertices); }
private DataTree <Vector3d> GetMeshDisplacements(ref List <int> sfcNo, ref List <string> msg) { var oDisplacements = new DataTree <Vector3d>(); sfcNo = new List <int>(); // Save defoirmation vectors into a tree var surfaceResults = _lcresults.GetSurfacesDeformations(false).OrderBy(o => o.LocationNo); // Sort according to nodes so there are no errors when applying displacements foreach (var resulttype in surfaceResults.Select(x => x.Type).Distinct()) { _resultTypes.Add(resulttype); } foreach (var result in surfaceResults) // GET RESULT TYPES!!! { var gh_path = new GH_Path(result.SurfaceNo, (int)result.Type); var displacement = new Vector3d(result.Displacements.ToPoint3d()); oDisplacements.Add(displacement, gh_path); // Add surface numbers to output list if (sfcNo.Count == 0 || result.SurfaceNo != sfcNo[sfcNo.Count - 1]) { sfcNo.Add(result.SurfaceNo); } } return(oDisplacements); }
protected override void SolveInstance(IGH_DataAccess da) { var inputPts = new List <Point3d>(); var inputCloud = new List <Point3d>(); var count = 1; if (!da.GetDataList("Points", inputPts) || !da.GetDataList("Cloud", inputCloud) || !da.GetData("Number", ref count)) { return; } var result = RTree.Point3dKNeighbors(inputCloud, inputPts, count); var outPts = new GH_Structure <GH_Point>(); var outIdx = new GH_Structure <GH_Integer>(); int branchIdx = 0; foreach (var foundIdx in result) { var path = new GH_Path(branchIdx); outPts.AppendRange(foundIdx.Select(idx => new GH_Point(inputCloud[idx])), path); //outIdx.AppendRange(foundIdx.Select(idx => new GH_Integer(idx)), path); branchIdx++; } da.SetDataTree(0, outPts); da.SetDataTree(1, outIdx); }
public static GH_Path AddZerosToPath(GH_Path path, int[] topD, int desiredLength, double relativeIndex, int[] size) { GH_Path newPath = path; List <int> currP = new List <int>(); foreach (int ind in path.Indices) { currP.Add(ind); } for (int i = 0; i < desiredLength; i++) { bool addZero = true; for (int j = 0; j < topD.Length; j++) { if (i == topD[j]) { addZero = false; } } if (addZero) { currP.Insert(i, (int)(relativeIndex * (size[i] - 1))); } } return(new GH_Path(currP.ToArray())); }
private object GetTreeFromParameter(IGH_DataAccess DA, int index, bool addIntoGhDoc) { GH_Structure <IGH_Goo> structure; DA.GetDataTree(index, out structure); IGH_TypeHint typeHint = ((Param_ScriptVariable)_component.Params.Input[index]).TypeHint; var tree = new DataTree <object>(); for (int i = 0; i < structure.PathCount; i++) { GH_Path path = structure.get_Path(i); List <IGH_Goo> list = structure.Branches[i]; List <object> data = new List <object>(); for (int j = 0; j < list.Count; j++) { object cast = this.TypeCast(list[j], typeHint); DocumentSingle(ref cast, addIntoGhDoc); data.Add(cast); } tree.AddRange(data, path); } return(tree); }
protected override void SolveInstance(IGH_DataAccess DA) { //Get inputs List <Geo> geoList = new List <Geo>(); DA.GetDataList <Geo>(0, geoList); int i = 0; Grasshopper.DataTree <Point3d> GeoLayers = new DataTree <Point3d>(); Grasshopper.DataTree <string> LayerNames = new DataTree <string>(); foreach (Geo g in geoList) { GH_Path pth = new GH_Path(i); foreach (Point3d p in g.Points) { GeoLayers.Add(p, pth); } string name = g.Tag.Keys.FirstOrDefault(); LayerNames.Add(name, pth); i++; } //Outputs DA.SetDataTree(0, GeoLayers); DA.SetDataTree(1, LayerNames); }
/// <summary> /// /// </summary> /// <param name="planes"></param> /// <param name="trimLengthBase"></param> /// <param name="trimLengthTop"></param> /// <returns></returns> private GH_Structure <GH_Plane> ExtractStems(GH_Structure <GH_Plane> planes, int trimLengthBase, int trimLengthTop) { GH_Structure <GH_Plane> stems = new GH_Structure <GH_Plane>(); for (int i = 0; i < planes.PathCount; i++) { GH_Plane plane = planes.get_DataItem(planes.get_Path(i), 0); List <GH_Plane> stemPlanes = new List <GH_Plane>(); if (plane.Value.OriginZ == 0) { for (int j = 0; j < planes.get_Branch(i).Count - trimLengthBase + 1; j++) { stemPlanes.Add(planes.get_DataItem(planes.get_Path(i), j)); } } else { for (int j = trimLengthTop - 1; j < planes.get_Branch(i).Count - trimLengthBase + 1; j++) { stemPlanes.Add(planes.get_DataItem(planes.get_Path(i), j)); } } GH_Path path = new GH_Path(i); stems.AppendRange(stemPlanes, path); } return(stems); }
/// <summary> /// This procedure contains the user code. Input parameters are provided as regular arguments, /// Output parameters as ref arguments. You don't have to assign output parameters, /// they will have a default value. /// </summary> private void RunScript(DataTree <Point3d> P, ref object A, ref object B, ref object C, ref object D, ref object E) { // simplify P.SimplifyPaths(); // making a copy since DataTree is reference type A = new DataTree <Point3d>(P); // graft P.Graft(false); B = new DataTree <Point3d>(P); // flatten (extract alla data to a list) List <Point3d> pts = P.AllData(); // data tree to List C = pts; // extract paths list (like Param Viewer) IList <GH_Path> paths = P.Paths; D = paths; // rebuild a tree from the list DataTree <Point3d> pTree = new DataTree <Point3d>(); GH_Path p; for (int i = 0; i < paths.Count; i++) { p = new GH_Path(paths[i][0]); pTree.Add(pts[i], p); } E = pTree; }
public InterNode(GH_Path path) { var t = path.Indices; Level = t[t.Length - 2]; Index = t.Last(); }
//private DataTree<Point3d> CreateControlPoints(ref List<string> msg) //{ // var oControlPoints = new DataTree<Point3d>(); // foreach (var member in _saveddata.GetMembers()) // { // var gh_path = new GH_Path(member.No); // var fe1delements = _rfemMesh.GetMemberNodes(member.No, ItemAt.AtNo); // We can't sort this list // foreach (var node in fe1delements) // { // oControlPoints.Add(new Point3d(node.X, node.Y, node.Z), gh_path); // } // } // return oControlPoints; //} private DataTree <Vector3d> GetMemberDisplacements(ref List <string> msg) { // Get control points _controlPoints.Clear(); var rfmembers = Component_GetData.GetRFMembers(_saveddata.GetMembers().ToList(), _saveddata); // Save defoirmation vectors into a tree; var oDisplacements = new DataTree <Vector3d>(); foreach (var member in rfmembers) { // Add also control points. We are just going to get one set of control points for each curve regardless thne result type var pts_path = new GH_Path(member.No); _controlPoints.RemovePath(pts_path); var baseline = member.BaseLine.ToCurve(); // Get deformations var memberResults = _lcresults.GetMemberDeformations(member.No, ItemAt.AtNo, MemberAxesType.GlobalAxes); // We can't sort this list var valueType = memberResults[0].Type; // Get deformation types to avoid duplicate control points foreach (var result in memberResults) { var gh_path = new GH_Path(member.No, (int)result.Type); var displacement = new Vector3d(result.Displacements.ToPoint3d()); oDisplacements.Add(displacement, gh_path); // Get control points if (result.Type == valueType) { _controlPoints.Add(baseline.PointAtNormalizedLength(Math.Min(result.Location / baseline.GetLength(), 1.0)), pts_path); } } } return(oDisplacements); }
void ToDataTree(IEnumerable list, ref DataTree <object> Tree, List <int> path) { int k = 0; int b = 0; bool addedRecurse = false; foreach (var item in list) { if ((item is IEnumerable) && !(item is string)) { if (!addedRecurse) { path.Add(b); addedRecurse = true; } else { path[path.Count - 1]++; } ToDataTree(item as IEnumerable, ref Tree, path); } else { GH_Path Path = new GH_Path(path.ToArray()); Tree.Insert(item, Path, k++); } } }
void createNetFromPoints(DataTree <Point3d> PointGrid) { // Receives a tree of points and gives back it's corresponding net of lines properly divided into WARP AND WEFT directions DataTree <Line> warpLines = new DataTree <Line>(); DataTree <Line> weftLines = new DataTree <Line>(); //WARP for (int bNum = 0; bNum < PointGrid.BranchCount; bNum++) { // Iterate all branches List <Point3d> branch = PointGrid.Branches[bNum]; GH_Path pth = PointGrid.Paths[bNum]; for (int ptNum = 0; ptNum < branch.Count - 1; ptNum++) { // Iterate all points in each branch Line warpLn = new Line(branch[ptNum], branch[ptNum + 1]); warpLines.Add(warpLn, new GH_Path(pth)); if (bNum < PointGrid.BranchCount - 1) { List <Point3d> nextBranch = PointGrid.Branches[bNum + 1]; if (ptNum < nextBranch.Count) { Line weftLn = new Line(branch[ptNum], nextBranch[ptNum]); weftLines.Add(weftLn, pth); } } } } _warpNet.MergeTree(warpLines); _weftNet.MergeTree(weftLines); }
protected override void SolveInstance(IGH_DataAccess DA) { List <IFrameSet> beams = new List <IFrameSet>(); if (!DA.GetDataList(0, beams)) { return; } DataTree <IFrameSet> beamTree = new DataTree <IFrameSet>(); var grouped = beams.GroupBy(b => b.crossSection.shapeName); int groupID = 0; foreach (var bgroup in grouped) { GH_Path bpth = new GH_Path(groupID); foreach (IFrameSet sb in bgroup) { beamTree.Add(sb, bpth); } groupID++; } DA.SetDataTree(0, beamTree); }
public static GH_Structure <GH_String> DataTreeNaming(string name, GH_Structure <IGH_Goo> data) { // Output GH_Structure <GH_String> names = new GH_Structure <GH_String>(); // Paths var paths = data.Paths; // Make the output datatree with names for (int i = 0; i < data.Branches.Count; i++) { var branches = data.Branches[i]; GH_Path iPath = paths[i]; string pathString = iPath.ToString(); string newPath = pathString.Replace("{", "").Replace(";", "_").Replace("}", ""); for (int j = 0; j < branches.Count; j++) { string myName = name + "_" + newPath + "_" + j; GH_String converted = new GH_String(myName); names.Append(converted, iPath); } } return(names); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Structure <GH_Brep> breps = null; GH_Structure <GH_Brep> cutters = null; //Brep brep = null; //List<Brep> cutters = new List<Brep>(); if (!DA.GetDataTree("Brep", out breps)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Invalid Brep input."); return; } if (!DA.GetDataTree("Cutters", out cutters)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Invalid cutter input."); return; } GH_Structure <GH_Brep> resTree = new GH_Structure <GH_Brep>(); foreach (var path in breps.Paths) { resTree.EnsurePath(path); } List <string> errors = new List <string>(); Parallel.For(0, breps.Paths.Count, index => { GH_Path path = breps.Paths[index]; if (cutters.PathExists(path) && breps[path].Count > 0) { resTree[path].Add(new GH_Brep(breps[path][0].Value.Cut( cutters[path].Select(x => x.Value)))); } else if (cutters.PathCount == 1 && breps[path].Count > 0) // Handle a single list of cutters { try { if (cutters[0].Count > 0 && breps[path][0] != null) { resTree[path].Add(new GH_Brep(breps[path][0].Value.Cut( cutters[cutters.Paths[0]].Select(x => x.Value)))); } } catch (Exception ex) { errors.Add(ex.Message); } } else { resTree[path].AddRange(breps[path]); } }); DA.SetDataTree(0, resTree); DA.SetDataList("Errors", errors); }
/// <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) { counter++; DA.GetData(1, ref n); n = Math.Max(1, n); if (counter % n == 0) { Flex flex = null; DA.GetData(0, ref flex); if (flex != null) { List <FlexParticle> part = flex.Scene.GetFluidParticles(); pts = new GH_Structure <GH_Point>(); vel = new GH_Structure <GH_Vector>(); foreach (FlexParticle fp in part) { GH_Path p = new GH_Path(fp.GroupIndex); pts.Append(new GH_Point(new Point3d(fp.PositionX, fp.PositionY, fp.PositionZ)), p); vel.Append(new GH_Vector(new Vector3d(fp.VelocityX, fp.VelocityY, fp.VelocityZ)), p); } } } DA.SetDataTree(0, pts); DA.SetDataTree(1, vel); }
protected override void SetOutputs(IGH_DataAccess da) { outTree = new DataTree <Point3d>(); GH_Path trunk = new GH_Path(0); // {0} GH_Path branch = new GH_Path(); // {}\ GH_Path limb = new GH_Path(); for (int i = 0; i < particles.Count; i++) { IQuelea particle = particles[i]; branch = trunk.AppendElement(i); DataTree <Point3d> particlePositionHistoryTree = particle.Position3DHistory.ToTree(); for (int j = 0; j < particlePositionHistoryTree.BranchCount; j++) { limb = branch.AppendElement(j); //for (int k = particlePositionHistoryTree.Branch(j).Count - 1; k >= 0; k--) //{ // outTree.Add(particlePositionHistoryTree.Branch(j)[k], limb); //} outTree.AddRange(particlePositionHistoryTree.Branch(j), limb); } } da.SetDataTree(nextOutputIndex++, outTree); }
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_GeometricGoo> oDualMeshTree = new GH_Structure <IGH_GeometricGoo>(); GH_Structure <IGH_GeometricGoo> oDualMeshCurveTree = new GH_Structure <IGH_GeometricGoo>(); 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 { oDualMeshTree.Append( GH_Convert.ToGeometricGoo(mesh.ToPlanktonMesh().Dual(0).ToRhinoMesh()), path); } } } DA.SetDataTree(0, oDualMeshTree); }
/// <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) { GH_Structure <IGH_Goo> T = new GH_Structure <IGH_Goo>(); if (!DA.GetDataTree(0, out T)) { return; } int i = 0; DA.GetData(1, ref i); GH_Path P = new GH_Path(); List <IGH_Goo> data = new List <IGH_Goo>(); if (T.Branches.Count > 0) { int ind = i % T.Branches.Count; P = T.Paths[ind]; data = T.Branches[ind]; } DA.SetData(0, P); DA.SetDataList(1, data); }
/// <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) { // First, we need to retrieve all data from the input parameters. // We'll start by declaring variables and assigning them starting values. object obj = new object(); GH_Path path = new GH_Path(); // Then we need to access the input parameters individually. // When data cannot be extracted from a parameter, we should abort this method. if (!DA.GetData(0, ref obj)) { return; } if (!DA.GetData(1, ref path)) { return; } DataTree <object> dt = new DataTree <object>(); dt.Add(obj, path); // Finally assign to the output parameter. DA.SetData(0, dt); }
/// <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) { IssueCollection issues = new IssueCollection(); List <DateTime> timestamps = new List <DateTime>(); DA.GetDataList <Issue>(0, issues); DateTime timestamp = DateTime.Now; DataTree <Issue> results = new DataTree <Issue>(); List <int> counts = new List <int>(); DA.GetDataList(1, timestamps); for (int i = 0; i < timestamps.Count; i++) { timestamp = timestamps[i]; IssueCollection issues_as_of = issues.AsOf(timestamp); GH_Path path = new GH_Path(i); results.AddRange(issues_as_of, path); counts.Add(issues_as_of.Count); } DA.SetDataList(0, counts); DA.SetDataTree(1, results); }
void clusterize(int cb, int sb, ref DataTree <int> Td, ref DataTree <int> cl, ref List <int> tP) { // current branch path GH_Path cp = new GH_Path(cb); if (cb == sb) // when cb==sb create a new branch in cl { // // create new cluster // GH_Path clp = new GH_Path(cl.BranchCount); //new cluster path cl.Add(cb, clp); // add Td branch index as first element // add all branch indexes cl.AddRange(Td.Branches[cb]); // call clusterize for each of them for (int i = 0; i < Td.Branches[cb].Count; i++) { clusterize(Td[cp, i], cb, ref Td, ref cl, ref tP); } tP.RemoveAt(tP.IndexOf(cb)); // // call new cluster if there are still available indexes // if (tP.Count > 0) { clusterize(tP[0], tP[0], ref Td, ref cl, ref tP); } } else { // // add elements to existing cluster // // scan elements of current branch for (int i = 0; i < Td.Branches[cb].Count; i++) { // if elements in current branch (cb) of Td are different // from sending branch index (sb): if (Td[cp, i] != sb) { // if elements are not yet in cluster, add them // and call clusterize on them if (!cl.Branches[cl.BranchCount - 1].Contains(Td[cp, i])) { cl.Add(Td[cp, i], new GH_Path(cl.BranchCount - 1)); clusterize(Td[cp, i], cb, ref Td, ref cl, ref tP); } } else if (tP.Contains(cb)) { tP.RemoveAt(tP.IndexOf(cb)); //remove branch index from list } } } }
/// <summary> /// 返回一个路径中第n个数,从1开始 /// </summary> /// <param name="path"></param> /// <param name="index"></param> /// <returns></returns> public static int GetPathNumber(GH_Path path, int index) { string str = path.ToString(); char[] chr = str.ToArray(); int count = CountItem(chr, ';') + 1; int idx = index % count; if (idx == 0) { idx = count; } List <char> seperator_l = new List <char> { '{' }; for (int i = 0; i < count - 1; i++) { seperator_l.Add(';'); } seperator_l.Add('}'); char[] seperator = seperator_l.ToArray(); int number = int.Parse(str.Split(seperator)[idx]); return(number); }
protected override void SolveInstance(IGH_DataAccess DA) { try { List <Point3d> pts = new List <Point3d>(); DA.GetDataList(0, pts); DataTree <Line> links = new DataTree <Line>(); DataTree <int> indices = new DataTree <int>(); for (int i = 0; i < pts.Count; i++) { Point3d p0 = pts[i]; for (int j = i + 1; j < pts.Count; j++) { Point3d p1 = pts[j]; double d = p0.DistanceTo(p1); bool linkus = true; for (int k = 0; k < pts.Count; k++) { if (k != i && k != j) { Point3d p2 = pts[k]; if (p2.DistanceTo(p0) < d && p2.DistanceTo(p1) < d) { linkus = false; break; } } } if (linkus) { links.Add(new Line(p0, p1), new GH_Path(i)); links.Add(new Line(p1, p0), new GH_Path(j)); indices.Add(j, new GH_Path(i)); indices.Add(i, new GH_Path(j)); } } } //for(int i = 0;i < pts.Count;i++){ System.Threading.Tasks.Parallel.For(0, pts.Count, i => { GH_Path path = new GH_Path(i); if (!links.PathExists(path)) {//Add nulls links.AddRange(new List <Line>() { }, path); indices.AddRange(new List <int>() { }, path); } }); DA.SetDataTree(0, links); DA.SetDataTree(1, indices); } catch (Exception e) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.ToString()); } }
protected override void SolveInstance(IGH_DataAccess DA) { List <sPointLoad> sups = new List <sPointLoad>(); if (!DA.GetDataList(0, sups)) { return; } DataTree <sPointLoad> supTree = new DataTree <sPointLoad>(); var ngrouped = sups.GroupBy(n => n.loadPatternName); int ngroupID = 0; foreach (var nngroup in ngrouped) { GH_Path npth = new GH_Path(ngroupID); foreach (sPointLoad sn in nngroup) { supTree.Add(sn, npth); } ngroupID++; } DA.SetDataTree(0, supTree); }
protected override void SetOutputs(IGH_DataAccess da) { outTree = new DataTree<Point3d>(); GH_Path trunk = new GH_Path(0); // {0} GH_Path branch = new GH_Path(); // {}\ GH_Path limb = new GH_Path(); for (int i = 0; i < particles.Count; i++) { IQuelea particle = particles[i]; branch = trunk.AppendElement(i); DataTree<Point3d> particlePositionHistoryTree = particle.Position3DHistory.ToTree(); for (int j = 0; j < particlePositionHistoryTree.BranchCount; j++) { limb = branch.AppendElement(j); //for (int k = particlePositionHistoryTree.Branch(j).Count - 1; k >= 0; k--) //{ // outTree.Add(particlePositionHistoryTree.Branch(j)[k], limb); //} outTree.AddRange(particlePositionHistoryTree.Branch(j), limb); } } da.SetDataTree(nextOutputIndex++, outTree); }
public override void PostProcessData() { base.PostProcessData(); if (SourceCount == 0) { RefreshList(NickName); } else { RefreshList(VolatileData.AllData(true)); } // Show elements sorted ListItems.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name)); //base.CollectVolatileData_Custom(); m_data.Clear(); var path = new GH_Path(0); if (SelectedItems.Count == 0) { m_data.AppendRange(new IGH_Goo[0], path); } else { foreach (var item in SelectedItems) { m_data.Append(item.Value, path); } } }
private static void SetSectionInfo(StbSections sections, GH_Structure <GH_String> ghSecStrings, StbSlab slab, int index) { string secId = slab.id_section; var ghPath = new GH_Path(0, index); StbSlabKind_structure kindStruct = slab.kind_structure; switch (kindStruct) { case StbSlabKind_structure.RC: StbSecSlab_RC secRc = sections.StbSecSlab_RC.First(i => i.id == secId); foreach (object figure in secRc.StbSecFigureSlab_RC.Items) { ghSecStrings.AppendRange(TagUtils.GetSlabRcSection(figure, secRc.strength_concrete), ghPath); } break; case StbSlabKind_structure.DECK: StbSecSlabDeck secDeck = sections.StbSecSlabDeck.First(i => i.id == secId); ghSecStrings.AppendRange(TagUtils.GetSlabDeckSection(secDeck.StbSecFigureSlabDeck.StbSecSlabDeckStraight, secDeck.strength_concrete), ghPath); break; case StbSlabKind_structure.PRECAST: StbSecSlabPrecast secPrecast = sections.StbSecSlabPrecast.First(i => i.id == secId); ghSecStrings.AppendRange(TagUtils.GetSlabPrecastSection(secPrecast.precast_type, secPrecast.StbSecProductSlabPrecast, secPrecast.strength_concrete), ghPath); break; default: throw new ArgumentOutOfRangeException(nameof(kindStruct), kindStruct, null); } }
private void RunScript(List <System.Object> iWindingObjects, double iVecAmp, Curve iAxis, List <Curve> iSyntaxCurves, bool iBackSyntax, ref object oWindingObjects, ref object iTravelPlanes, ref object iAllPlanes) { // <Custom code> DataTree <Plane> allPlanes = new DataTree <Plane>(); DataTree <Plane> travelPlanes = new DataTree <Plane>(); GH_Path pth = new GH_Path(0); List <WindingClass> windingObjects = new List <WindingClass>(); for (var index = 0; index < iWindingObjects.Count - 1; index++) { pth = new GH_Path(index); WindingClass wC = (WindingClass)iWindingObjects[index]; wC.travelPath = CreateTravelPath(wC, (WindingClass)iWindingObjects[index + 1], iSyntaxCurves[index], iAxis, iVecAmp, iBackSyntax); travelPlanes.AddRange(wC.travelPath, pth); allPlanes.AddRange(wC.windingPath, pth); allPlanes.AddRange(wC.travelPath, pth); //allPlanes.AddRange(wC.transitionPath); windingObjects.Add(wC); } // Deal with last winding plane since it dosn't have two neighbors WindingClass lastItem = (WindingClass)iWindingObjects[iWindingObjects.Count - 1]; allPlanes.AddRange(lastItem.windingPath, pth); windingObjects.Add((WindingClass)windingObjects.Last()); oWindingObjects = windingObjects; iTravelPlanes = travelPlanes; iAllPlanes = allPlanes; // </Custom code> }
public static Dictionary <string, DataTree <object> > CreateAnalysisMesh( List <Brep> baseSurfaces, double gridSize, List <Brep> excludeGeometry, double offset, string offsetDirection) { var analysisMesh = new DataTree <object>(); var faceCenters = new DataTree <object>(); var faceNormals = new DataTree <object>(); var index = 0; var doneEvents = new ManualResetEvent[baseSurfaces.Count]; var callBacks = new List <ThreadedCreateAnalysisMesh>(); foreach (var surface in baseSurfaces) { doneEvents[index] = new ManualResetEvent(false); var callBack = new ThreadedCreateAnalysisMesh { surface = surface, gridSize = gridSize, excludeGeometry = excludeGeometry, offset = offset, offsetDirection = offsetDirection, doneEvent = doneEvents[index] }; ThreadPool.QueueUserWorkItem(callBack.ThreadPoolCallback); callBacks.Add(callBack); index++; } WaitHandle.WaitAll(doneEvents); index = 0; foreach (var callBack in callBacks) { var mesh = callBack.analysisMesh; var path = new GH_Path(index); analysisMesh.Add(mesh, path); foreach (var normal in mesh.FaceNormals) { faceNormals.Add(normal, path); } for (var i = 0; i < mesh.Faces.Count(); i++) { faceCenters.Add(mesh.Faces.GetFaceCenter(i), path); } index++; } return(new Dictionary <string, DataTree <object> > { { "analysisMesh", analysisMesh }, { "faceCenters", faceCenters }, { "faceNormals", faceNormals }, }); }
public void SetObjects(IGH_DataAccess DA) { if (Layers == null) { return; } if (ConvertedObjects.Count == 0) { return; } int k = 0; foreach (Layer layer in Layers) { //TODO: Check if we're out or under range, and add default layers as such. var subset = ConvertedObjects.GetRange(( int )layer.StartIndex, ( int )layer.ObjectCount); if (subset.Count == 0) { continue; } if (layer.Topology == "") { DA.SetDataList(( int )layer.OrderIndex, subset); } else { //HIC SVNT DRACONES var tree = new DataTree <object>(); var treeTopo = layer.Topology.Split(' '); int subsetCount = 0; foreach (var branch in treeTopo) { if (branch != "") { var branchTopo = branch.Split('-')[0].Split(';'); var branchIndexes = new List <int>(); foreach (var t in branchTopo) { branchIndexes.Add(Convert.ToInt32(t)); } var elCount = Convert.ToInt32(branch.Split('-')[1]); GH_Path myPath = new GH_Path(branchIndexes.ToArray()); for (int i = 0; i < elCount; i++) { tree.EnsurePath(myPath).Add(new Grasshopper.Kernel.Types.GH_ObjectWrapper(subset[subsetCount + i])); } subsetCount += elCount; } } DA.SetDataTree(layer.OrderIndex != null ? ( int )layer.OrderIndex : k, tree); k++; } } }
private static DataTree<Brep> BrepArray2DToDatatree(Brep[][] array) { DataTree<Brep> tree = new DataTree<Brep>(); GH_Path trunk = new GH_Path(); for (int i = 0; i < array.Length; i++) { GH_Path branch = trunk.AppendElement(i); for (int j = 0; j < array[i].Length; j++) { tree.Add(array[i][j], branch); } } return tree; }
/// <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) { // 1. Retrieve and validate data var cell = new UnitCell(); GeometryBase designSpace = null; Plane orientationPlane = Plane.Unset; double xCellSize = 0; double yCellSize = 0; double zCellSize = 0; double minLength = 0; // the trim tolerance (i.e. minimum strut length) double maxLength = 0; bool strictlyIn = false; if (!DA.GetData(0, ref cell)) { return; } if (!DA.GetData(1, ref designSpace)) { return; } if (!DA.GetData(2, ref orientationPlane)) { return; } if (!DA.GetData(3, ref xCellSize)) { return; } if (!DA.GetData(4, ref yCellSize)) { return; } if (!DA.GetData(5, ref zCellSize)) { return; } if (!DA.GetData(6, ref minLength)) { return; } if (!DA.GetData(7, ref maxLength)) { return; } if (!DA.GetData(8, ref strictlyIn)) { return; } if (!cell.isValid) { return; } if (!designSpace.IsValid) { return; } if (!orientationPlane.IsValid) { return; } if (xCellSize == 0) { return; } if (yCellSize == 0) { return; } if (zCellSize == 0) { return; } if (minLength>=xCellSize || minLength>=yCellSize || minLength>=zCellSize) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Tolerance parameter cannot be larger than the unit cell dimensions."); return; } // 2. Validate the design space int spaceType = FrameTools.ValidateSpace(ref designSpace); if (spaceType == 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Design space must be a closed Brep, Mesh or Surface"); return; } double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; // 3. Compute oriented bounding box and its corner points Box bBox = new Box(); designSpace.GetBoundingBox(orientationPlane, out bBox); Point3d[] bBoxCorners = bBox.GetCorners(); // Set basePlane based on the bounding box Plane basePlane = new Plane(bBoxCorners[0], bBoxCorners[1], bBoxCorners[3]); // 4. Determine number of iterations required to fill the box, and package into array double xLength = bBoxCorners[0].DistanceTo(bBoxCorners[1]); double yLength = bBoxCorners[0].DistanceTo(bBoxCorners[3]); double zLength = bBoxCorners[0].DistanceTo(bBoxCorners[4]); int nX = (int)Math.Ceiling(xLength / xCellSize); // Roundup to next integer if non-integer int nY = (int)Math.Ceiling(yLength / yCellSize); int nZ = (int)Math.Ceiling(zLength / zCellSize); float[] N = new float[3] { nX, nY, nZ }; // 5. Initialize nodeTree var lattice = new Lattice(); // 6. Prepare cell (this is a UnitCell object) cell = cell.Duplicate(); cell.FormatTopology(); // 7. Define iteration vectors in each direction (accounting for Cell Size) Vector3d vectorU = xCellSize * basePlane.XAxis; Vector3d vectorV = yCellSize * basePlane.YAxis; Vector3d vectorW = zCellSize * basePlane.ZAxis; // 8. Map nodes to design space // Loop through the uvw cell grid for (int u = 0; u <= N[0]; u++) { for (int v = 0; v <= N[1]; v++) { for (int w = 0; w <= N[2]; w++) { // Construct cell path in tree GH_Path treePath = new GH_Path(u, v, w); // Fetch the list of nodes to append to, or initialise it var nodeList = lattice.Nodes.EnsurePath(treePath); // This loop maps each node in the cell for (int i = 0; i < cell.Nodes.Count; i++) { double usub = cell.Nodes[i].X; // u-position within unit cell (local) double vsub = cell.Nodes[i].Y; // v-position within unit cell (local) double wsub = cell.Nodes[i].Z; // w-position within unit cell (local) double[] uvw = { u + usub, v + vsub, w + wsub }; // uvw-position (global) // Check if the node belongs to another cell (i.e. it's relative path points outside the current cell) bool isOutsideCell = (cell.NodePaths[i][0] > 0 || cell.NodePaths[i][1] > 0 || cell.NodePaths[i][2] > 0); // Check if current uvw-position is beyond the upper boundary bool isOutsideSpace = (uvw[0] > N[0] || uvw[1] > N[1] || uvw[2] > N[2]); if (isOutsideCell || isOutsideSpace) { nodeList.Add(null); } else { // Compute position vector Vector3d V = uvw[0] * vectorU + uvw[1] * vectorV + uvw[2] * vectorW; var newNode = new LatticeNode(basePlane.Origin + V); // Check if point is inside - use unstrict tolerance, meaning it can be outside the surface by the specified tolerance bool isInside = FrameTools.IsPointInside(designSpace, newNode.Point3d, spaceType, tol, strictlyIn); // Set the node state (it's location wrt the design space) if (isInside) { newNode.State = LatticeNodeState.Inside; } else { newNode.State = LatticeNodeState.Outside; } // Add node to tree nodeList.Add(newNode); } } } } } // 9. Map struts to the node tree lattice.UniformMapping(cell, designSpace, spaceType, N, minLength, maxLength); // 10. Set output DA.SetDataList(0, lattice.Struts); }
private void createStripe(int firstVertexIndex, int secondVertexIndex, int thirdVertexIndex, GH_Path path, int item) { // first vertex in the stripe direction Point3d a = bottomCps[firstVertexIndex]; Point3d A = topCps[firstVertexIndex]; Point3d b = bottomCps[secondVertexIndex]; Point3d B = topCps[secondVertexIndex]; Point3d c = bottomCps[thirdVertexIndex]; Point3d C = topCps[thirdVertexIndex]; // Centre of Edge AB Point3d ab = 0.5 * (a + b); Point3d AB = 0.5 * (A + B); // Centre of Edge AC Point3d ac = 0.5 * (a + c); Point3d AC = 0.5 * (A + C); // Centre of Mesh Face Point3d m = (ab + ac + 0.5 * (b + c)) / 3; Point3d M = (AB + AC + 0.5 * (B + C)) / 3; // perform planar Offset double planarOffset = planarVerticesValues[firstVertexIndex]; double curveScaler = curveVerticesValues[firstVertexIndex]; double openingScaler = openingWidthVerticesValues[firstVertexIndex]; double curvePointiness = pointinessValues[firstVertexIndex]; if (ManualAdjustedVertexIndexies.Contains(firstVertexIndex)) { GH_Path pth = new GH_Path(firstVertexIndex); planarOffset = ManualValueTree[new GH_Path(firstVertexIndex)][2].Value; curveScaler = ManualValueTree[new GH_Path(firstVertexIndex)][0].Value; openingScaler = ManualValueTree[new GH_Path(firstVertexIndex)][3].Value; curvePointiness = ManualValueTree[new GH_Path(firstVertexIndex)][1].Value; } // Offset : Centre of Edge AB Vector3d v_ab = a - b; Vector3d v_AB = A - B; v_ab.Unitize(); v_AB.Unitize(); // Offset : Centre of Edge AC Vector3d v_ac = a - c; Vector3d v_AC = A - C; v_ac.Unitize(); v_AC.Unitize(); // not used #region Correct Offset /* // Angles Vector3d ac_ab = ac - ab; ac_ab.Unitize(); Vector3d AC_AB = AC - AB; AC_AB.Unitize(); double dotProduct_b = ac_ab * v_ab; double dotProduct_B = AC_AB * v_AB; double dotProduct_c = -ac_ab * v_ac; double dotProduct_C = -AC_AB * v_AC; Utils.ToDegree(dotProduct_b); Utils.ToDegree(dotProduct_B); Utils.ToDegree(dotProduct_c); Utils.ToDegree(dotProduct_C); v_ab *= planarOffset / Math.Tan(Math.Acos(dotProduct_b)); v_AB *= planarOffset / Math.Tan(Math.Acos(dotProduct_B)); v_ac *= planarOffset / Math.Tan(Math.Acos(dotProduct_c)); v_AC *= planarOffset / Math.Tan(Math.Acos(dotProduct_C)); */ #endregion correct offset // create offset point Point3d oab = ab + (v_ab * planarOffset); Point3d oAB = AB + (v_AB * planarOffset); // create offset point Point3d oac = ac + (v_ac * planarOffset); Point3d oAC = AC + (v_AC * planarOffset); //---- Super normalization of Offset Points ---------------------------------------------------------------------------- // shortest connected Edge (changes offset point; normalize offset point) if (iSuperNormalization == true) { List<int> neighbourVertices = iSpringMesh.Vertices[firstVertexIndex].NeighborVertexIndices; double minimalLengthTop = 999999999999; double minimalLengthBottom = 9999999999999; foreach (int i in neighbourVertices) { Vector3d vectorBottom = bottomCps[firstVertexIndex] - bottomCps[i]; Vector3d vectorTop = topCps[firstVertexIndex] - topCps[i]; if (vectorBottom.Length * 0.5 < minimalLengthBottom) minimalLengthBottom = vectorBottom.Length * 0.5; if (vectorTop.Length * 0.5 < minimalLengthTop) minimalLengthTop = vectorTop.Length * 0.5; } //Test: minimalLengthBottom = (minimalLengthTop + minimalLengthBottom) * 0.5; minimalLengthTop = minimalLengthBottom; //End Test oab = a - (v_ab * (minimalLengthBottom - planarOffset)); oAB = A - (v_AB * (minimalLengthTop - planarOffset)); oac = a - (v_ac * (minimalLengthBottom - planarOffset)); oAC = A - (v_AC * (minimalLengthTop - planarOffset)); } //---- End Super normalization of Offset Points ---------------------------------------------------------------------------- Point3d AAB = curveScaler * A + (1.0 - curveScaler) * oAB; Point3d aab = curveScaler * a + (1.0 - curveScaler) * oab; Point3d AAC = curveScaler * A + (1.0 - curveScaler) * oAC; Point3d aac = curveScaler * a + (1.0 - curveScaler) * oac; Point3d openingAAB = (-1 * v_AB * openingScaler) + A; Point3d openingaab = (-1 * v_ab * openingScaler) + a; Point3d openingAAC = (-1 * v_AC * openingScaler) + A; Point3d openingaac = (-1 * v_ac * openingScaler) + a; // Condition, choose between Opening Width and tangentscale if (new Vector3d(AAB - A).Length > openingScaler) AAB = openingAAB; if (new Vector3d(aab - a).Length > openingScaler) aab = openingaab; if (new Vector3d(AAC - A).Length > openingScaler) AAC = openingAAC; if (new Vector3d(aac - a).Length > openingScaler) aac = openingaac; // Pointiness of the Surface Point3d max_aA = 0.5 * (a + A); Point3d min_aA1 = 0.5 * (aab + AAB); Point3d min_aA2 = 0.5 * (aac + AAC); Point3d aA1 = (curvePointiness * max_aA) + ((1 - curvePointiness) * min_aA1); Point3d aA2 = (curvePointiness * max_aA) + ((1 - curvePointiness) * min_aA2); // Create Curves Curve profileCurve1 = Curve.CreateControlPointCurve(new List<Point3d>() { oab, aab, aA1, AAB, oAB }, curveDegree); Curve profileCurve2 = Curve.CreateControlPointCurve(new List<Point3d>() { oac, aac, aA2, AAC, oAC }, curveDegree); Curve profileCrv11 = Curve.CreateControlPointCurve(new List<Point3d>() { ab, oab }, 1); Curve profileCrv12 = Curve.CreateControlPointCurve(new List<Point3d>() { oAB, AB }, 1); Curve profileCrv21 = Curve.CreateControlPointCurve(new List<Point3d>() { ac, oac }, 1); Curve profileCrv22 = Curve.CreateControlPointCurve(new List<Point3d>() { oAC, AC }, 1); Curve profileCurveNew1 = Curve.JoinCurves(new List<Curve>() { profileCrv11, profileCurve1, profileCrv12 }, documentTolerance, true)[0]; Curve profileCurveNew2 = Curve.JoinCurves(new List<Curve>() { profileCrv21, profileCurve2, profileCrv22 }, documentTolerance, true)[0]; oTriLoopCurves.Add(profileCurveNew1, path.AppendElement(item)); oTriLoopCurves.Add(profileCurveNew2, path.AppendElement(item)); if (iPolySrf) { //not used method : if triloop need to be polySurface. #region Genes Method /* PolyCurve polyCurve1 = new PolyCurve(); polyCurve1.Append(new LineCurve(m, ab)); polyCurve1.Append(new LineCurve(ab, oab)); polyCurve1.Append(profileCurve1); polyCurve1.Append(new LineCurve(oAB, AB)); polyCurve1.Append(new LineCurve(AB, M)); PolyCurve polyCurve2 = new PolyCurve(); polyCurve2.Append(new LineCurve(m, ac)); polyCurve2.Append(new LineCurve(ac, oac)); polyCurve2.Append(profileCurve2); polyCurve2.Append(new LineCurve(oAC, AC)); polyCurve2.Append(new LineCurve(AC, M)); oTriLoop.Add( Brep.CreateFromLoft( new List<Curve>() { polyCurve1, polyCurve2 }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false )[0], path.AppendElement(item) ); */ #endregion Genes Method //used method #region Seperate Planar from Curved Method PolyCurve polyCurve1 = new PolyCurve(); polyCurve1.Append(profileCurve1); PolyCurve polyCurve2 = new PolyCurve(); polyCurve2.Append(profileCurve2); // Planar Part Curves Curve planarCurveBottom = Curve.CreateControlPointCurve(new List<Point3d>() { m, ac, oac, oab, ab, m }, 1); Curve planarCurveTop = Curve.CreateControlPointCurve(new List<Point3d>() { M, AB, oAB, oAC, AC, M }, 1); // Add Planar Crv oTriLoopPlanCrv.Add(planarCurveBottom, path.AppendElement(item)); oTriLoopPlanCrv.Add(planarCurveTop, path.AppendElement(item)); // Add Bended Brep oTriLoop.Add( Brep.CreateFromLoft( new List<Curve>() { polyCurve1, polyCurve2 }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false )[0], path.AppendElement(item) ); #endregion Seperate Planar from Curved Method } else #region single surface { profileCurve1 = Curve.JoinCurves( new List<Curve>() { new LineCurve(b, oab), profileCurve1, new LineCurve(oAB, B) }, documentTolerance, true)[0]; profileCurve2 = Curve.JoinCurves( new List<Curve>() { new LineCurve(c, oac), profileCurve2, new LineCurve(oAC, C) }, documentTolerance, true)[0]; // Planar Part Curves Curve planarCurveBottom = Curve.CreateControlPointCurve(new List<Point3d>() { m, ac, oac, oab, ab, m }, 1); Curve planarCurveTop = Curve.CreateControlPointCurve(new List<Point3d>() { M, AB, oAB, oAC, AC, M }, 1); // Add Planar Crvs oTriLoopPlanCrv.Add(planarCurveBottom, path.AppendElement(item)); oTriLoopPlanCrv.Add(planarCurveTop, path.AppendElement(item)); Brep brep = Brep.CreateFromLoft( new List<Curve>() { profileCurve1, profileCurve2 }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false )[0]; // ============================================= // Trim the brep using planes // ============================================= double offsetAmount = 0.2; Vector3d normal; Brep[] breps; normal = Vector3d.CrossProduct(B - A, C - A); Point3d A_ = A + offsetAmount * normal; breps = brep.Trim(new Plane(A_, AB, M), documentTolerance); if (breps.Length > 0) brep = breps[0]; else { oTriLoop.Add(brep, path.AppendElement(item)); return; } breps = brep.Trim(new Plane(A_, M, AC), documentTolerance); if (breps.Length > 0) brep = breps[0]; else { oTriLoop.Add(brep, path.AppendElement(item)); return; } normal = Vector3d.CrossProduct(b - a, c - a); Point3d a_ = a - offsetAmount * normal; breps = brep.Trim(new Plane(a_, m, ab), documentTolerance); if (breps.Length > 0) brep = breps[0]; else { oTriLoop.Add(brep, path.AppendElement(item)); return; } breps = brep.Trim(new Plane(a_, ac, m), documentTolerance); if (breps.Length > 0) brep = breps[0]; else { oTriLoop.Add(brep, path.AppendElement(item)); return; } oTriLoop.Add(brep, path.AppendElement(item)); } #endregion single surface #region close panel // close panel //Point3d closeVertice = Point3dList.ClosestPointInList(iClosedPanelPts, iSpringMesh.Vertices[firstVertexIndex].Position); //if (ICD.Utils.Distance(closeVertice, iSpringMesh.Vertices[firstVertexIndex].Position) < iClosePanelDist) if (iVertexPanel2[firstVertexIndex]) { oClosedPanel.Add( Brep.CreateFromLoft( new List<Curve>() { new LineCurve(A, oAB), new LineCurve(A, oAC) }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false )[0], path.AppendElement(item) ); oClosedPanel.Add( Brep.CreateFromLoft( new List<Curve>() { new LineCurve(oab, a), new LineCurve(oac, a) }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false )[0], path.AppendElement(item) ); } #endregion close panel // do EffectorHoles List<Point3d> EffectorHoleTop = EffectorHoles(A, B, C, M, oAB, oAC, item); List<Point3d> EffectorHoleBottom = EffectorHoles(a, b, c, m, oab, oac, item); foreach (Point3d pt in EffectorHoleTop) oTriLoopEffectorHoles.Add(pt, path.AppendElement(item).AppendElement(1)); foreach (Point3d pt in EffectorHoleBottom) oTriLoopEffectorHoles.Add(pt, path.AppendElement(item).AppendElement(0)); }
private void RunScript(List<Mesh> x, List<int> y, List<double> z, ref object A, ref object B, ref object C,ref object D) { try { DataTree<double> output222; if (temp.Count == 0) { temp = y; for (int i = 0; i < x.Count; i++) { GH_Path path = new GH_Path(i); List<Line> output11; List<double> output22; Point3d output33; List<Point3d> output44; Print(Step(x[i], y[i], 0.5, true, out output11, out output22, out output33, out output44)); output1.AddRange(output11, path); output2.AddRange(output22, path); output3.Add(output33, path); output4.AddRange(output44, path); } } else { for (int i = 0; i < y.Count; i++) { GH_Path path = new GH_Path(i); if (y[i] != temp[i]) { List<Line> output11; List<double> output22; Point3d output33; List<Point3d> output44; Print(Step(x[i], y[i], 0.5, true, out output11, out output22, out output33, out output44)); output1.Branch(path).Clear(); output1.Branch(path).AddRange(output11); output2.Branch(path).Clear(); output2.Branch(path).AddRange(output22); output3.Branch(path)[0] = output33; output4.Branch(path).Clear(); output4.Branch(path).AddRange(output44); temp[i] = y[i]; } } } output222 = new DataTree<double>(output2); for (int i = 0; i < output222.Paths.Count; i++) { GH_Path path = new GH_Path(i); for(int j=0;j<output222.Branch(path).Count;j++){ output222[path, j] *= z[i]; }} A = output1; B = output222; C = output3; D = output4; } catch (Exception ex) { Print(ex.ToString()); } }
// dual loop directly connected to plates private void half_dualLoop_type_1(int edgeIndex) { Edge edge = iSpringMesh.Edges[edgeIndex]; int rightTriIndex = edge.FirstTriangleIndex; int leftTriIndex = edge.SecondTriangleIndex; // vertex point int vertex1 = edge.FirstVertexIndex; int vertex2 = edge.SecondVertexIndex; int vertex = vertex1; int occupyiedVertex = vertex2; if (iVertexStatus[vertex1] == false && iVertexStatus[vertex2] == true) { vertex = vertex1; occupyiedVertex = vertex2; } else if (iVertexStatus[vertex2] == false && iVertexStatus[vertex1] == true) { vertex = vertex2; occupyiedVertex = vertex1; } else { oInfo += "bug found..."; } // layer up Point3d rightUp01 = topCenterPts[rightTriIndex]; Point3d leftUp01 = topCenterPts[leftTriIndex]; Point3d up03 = topCps[vertex]; //reference point not for construct surfaces double planarOffset = planarVerticesValues[vertex]; double scaler = curveVerticesValues[vertex]; double openingScalar = openingWidthVerticesValues[vertex]; double curvePointiness = pointinessValues[vertex]; //Calculate offset planar points Vector3d v_oRightUp01 = up03 - rightUp01; Vector3d v_oLeftUp01 = up03 - leftUp01; v_oRightUp01.Unitize(); v_oLeftUp01.Unitize(); Point3d oRightUp01 = rightUp01 + (v_oRightUp01 * planarOffset); Point3d oLeftUp01 = leftUp01 + (v_oLeftUp01 * planarOffset); Point3d rightUp02 = (1 - scaler) * oRightUp01 + (scaler) * up03; Point3d leftUp02 = (1 - scaler) * oLeftUp01 + (scaler) * up03; // normalise hohles Point3d openingRightUp02 = up03 + (openingScalar * v_oRightUp01 * -1); Point3d openingLeftUp02 = up03 + (openingScalar * v_oLeftUp01 * -1); if (new Vector3d(rightUp02 - up03).Length > openingScalar) rightUp02 = openingRightUp02; if (new Vector3d(leftUp02 - up03).Length > openingScalar) leftUp02 = openingLeftUp02; // end normalise hohles // layer down Point3d rightDown01 = bottomCenterPts[rightTriIndex]; Point3d leftDown01 = bottomCenterPts[leftTriIndex]; Point3d down03 = bottomCps[vertex]; //reference point not for construct surfaces //Calculate offset planar points Vector3d v_oRightDownp01 = down03 - rightDown01; Vector3d v_oLeftDown01 = down03 - leftDown01; v_oRightDownp01.Unitize(); v_oLeftDown01.Unitize(); Point3d oRightDown01 = rightDown01 + (v_oRightDownp01 * planarOffset); Point3d oLeftDown01 = leftDown01 + (v_oLeftDown01 * planarOffset); Point3d rightDown02 = (1 - scaler) * oRightDown01 + (scaler) * down03; Point3d leftDown02 = (1 - scaler) * oLeftDown01 + (scaler) * down03; // normalise hohles Point3d openingRightDown02 = down03 + (openingScalar * v_oRightDownp01 * -1); Point3d openingLeftDown02 = down03 + (openingScalar * v_oLeftDown01 * -1); if (new Vector3d(rightDown02 - down03).Length > openingScalar) rightDown02 = openingRightDown02; if (new Vector3d(leftDown02 - down03).Length > openingScalar) leftDown02 = openingLeftDown02; // end normalise hohles //Pointiness Point3d maxVertexPt = iSpringMesh.Vertices[vertex].Position; Point3d min_rightVertexPt = 0.5 * (rightUp02 + rightDown02); Point3d min_leftVertexPt = 0.5 * (leftUp02 + leftDown02); Point3d rightVertexPt = (curvePointiness * maxVertexPt) + ((1 - curvePointiness) * min_rightVertexPt); Point3d leftVertexPt = (curvePointiness * maxVertexPt) + ((1 - curvePointiness) * min_leftVertexPt); // Right Curves (Curved Curve, Planar Part Curve at Top, Planar Part Curve at Bottom, Joined Curve) Curve rightLoop = Curve.CreateControlPointCurve( new List<Point3d>() { oRightDown01, rightDown02, rightVertexPt, rightUp02, oRightUp01 }, curveDegree); Curve rightPlanarUp = Curve.CreateControlPointCurve( new List<Point3d>() { oRightUp01, rightUp01 }, 1); Curve rightPlanarDown = Curve.CreateControlPointCurve( new List<Point3d>() { rightDown01, oRightDown01 }, 1); /* PolyCurve right = new PolyCurve(); right.Append(rightPlanarUp); right.Append(rightLoop); right.Append(rightPlanarDown);*/ Curve right = Curve.JoinCurves(new List<Curve>() { rightPlanarDown, rightLoop, rightPlanarUp }, documentTolerance, true)[0]; if (iPolySrf) { right = rightLoop; } // Left Curves (Curved Curve, Planar Part Curve at Top, Planar Part Curve at Bottom, Joined Curve) Curve leftLoop = Curve.CreateControlPointCurve( new List<Point3d>() { oLeftDown01, leftDown02, leftVertexPt, leftUp02, oLeftUp01 }, curveDegree); Curve leftPlanarUp = Curve.CreateControlPointCurve( new List<Point3d>() { oLeftUp01, leftUp01 }, 1); Curve leftPlanarDown = Curve.CreateControlPointCurve( new List<Point3d>() { leftDown01, oLeftDown01 }, 1); /* PolyCurve left = new PolyCurve(); left.Append(leftPlanarUp); left.Append(leftLoop); left.Append(leftPlanarDown);*/ Curve left = Curve.JoinCurves(new List<Curve>() { leftPlanarDown, leftLoop, leftPlanarUp }, documentTolerance, true)[0]; if (iPolySrf) { left = leftLoop; } // compare their polygon index to sort the lofting sequence #region compair polygon index // dataTree int plateID = iPolyLineID[occupyiedVertex]; plateID = -10 - plateID; // prevent -1 situation GH_Path path = new GH_Path(plateID); int[] rightIndex = indexSortPolygon[rightTriIndex]; int[] leftIndex = indexSortPolygon[leftTriIndex]; for (int r = 0; r < 3; r++) for (int l = 0; l < 3; l++) if (rightIndex[r] == leftIndex[l] && rightIndex[r] != -1 && leftIndex[l] != -1) if ((rightIndex[r + 3] == 0 && leftIndex[l + 3] != 1) || (leftIndex[l + 3] == 0 && rightIndex[r + 3] != 1) && (rightIndex[r + 3] < leftIndex[l + 3])) { Brep[] brep = Brep.CreateFromLoft( new List<Curve>() { left, right }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); #region allow poly surface if (iPolySrf) { Brep[] brepPlanarUp = Brep.CreateFromLoft( new List<Curve>() { leftPlanarUp, rightPlanarUp }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); Brep[] brepPlanarDown = Brep.CreateFromLoft( new List<Curve>() { leftPlanarDown, rightPlanarDown }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); brep = Brep.JoinBreps(new List<Brep>() { brepPlanarDown[0], brep[0], brepPlanarUp[0] }, documentTolerance); } #endregion allow poly surface if (brep.Length > 0) { oDualLoop1.Add(brep[0], path.AppendElement(leftIndex[l + 3])); oDualLoop1ID.Add("H;" + rightTriIndex.ToString() + "-" + leftTriIndex.ToString() + ";" + plateID.ToString(), path.AppendElement(leftIndex[l + 3])); oDualLoop1Curves.Add(left, path.AppendElement(leftIndex[l + 3])); oDualLoop1Curves.Add(right, path.AppendElement(leftIndex[l + 3])); } } else if ((rightIndex[r + 3] == 0 && leftIndex[l + 3] != 1) || (leftIndex[l + 3] == 0 && rightIndex[r + 3] != 1) && (rightIndex[r + 3] >= leftIndex[l + 3])) { Brep[] brep = Brep.CreateFromLoft( new List<Curve>() { right, left }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); #region allow poly surface if (iPolySrf) { Brep[] brepPlanarUp = Brep.CreateFromLoft( new List<Curve>() { rightPlanarUp, leftPlanarUp }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); Brep[] brepPlanarDown = Brep.CreateFromLoft( new List<Curve>() { rightPlanarDown, leftPlanarDown }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); brep = Brep.JoinBreps(new List<Brep>() { brepPlanarDown[0], brep[0], brepPlanarUp[0] }, documentTolerance); } #endregion allow poly surface if (brep.Length > 0) { oDualLoop1.Add(brep[0], path.AppendElement(rightIndex[r + 3])); oDualLoop1ID.Add("H;" + rightTriIndex.ToString() + "-" + leftTriIndex.ToString() + ";" + plateID.ToString(), path.AppendElement(rightIndex[r + 3])); oDualLoop1Curves.Add(right, path.AppendElement(rightIndex[r + 3])); oDualLoop1Curves.Add(left, path.AppendElement(rightIndex[r + 3])); } } else if (rightIndex[r + 3] >= leftIndex[l + 3]) { Brep[] brep = Brep.CreateFromLoft( new List<Curve>() { left, right }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); #region allow poly surface if (iPolySrf) { Brep[] brepPlanarUp = Brep.CreateFromLoft( new List<Curve>() { leftPlanarUp, rightPlanarUp }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); Brep[] brepPlanarDown = Brep.CreateFromLoft( new List<Curve>() { leftPlanarDown, rightPlanarDown }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); brep = Brep.JoinBreps(new List<Brep>() { brepPlanarDown[0], brep[0], brepPlanarUp[0] }, documentTolerance); } #endregion allow poly surface if (brep.Length > 0) { oDualLoop1.Add(brep[0], path.AppendElement(leftIndex[l + 3])); oDualLoop1ID.Add("H;" + rightTriIndex.ToString() + "-" + leftTriIndex.ToString() + ";" + plateID.ToString(), path.AppendElement(leftIndex[l + 3])); oDualLoop1Curves.Add(left, path.AppendElement(leftIndex[l + 3])); oDualLoop1Curves.Add(right, path.AppendElement(leftIndex[l + 3])); } } else if (rightIndex[r + 3] < leftIndex[l + 3]) { Brep[] brep = Brep.CreateFromLoft( new List<Curve>() { right, left }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); #region allow poly surface if (iPolySrf) { Brep[] brepPlanarUp = Brep.CreateFromLoft( new List<Curve>() { rightPlanarUp, leftPlanarUp }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); Brep[] brepPlanarDown = Brep.CreateFromLoft( new List<Curve>() { rightPlanarDown, leftPlanarDown }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); brep = Brep.JoinBreps(new List<Brep>() { brepPlanarDown[0], brep[0], brepPlanarUp[0] }, documentTolerance); } #endregion allow poly surface if (brep.Length > 0) { oDualLoop1.Add(brep[0], path.AppendElement(rightIndex[r + 3])); oDualLoop1ID.Add("H;" + rightTriIndex.ToString() + "-" + leftTriIndex.ToString() + ";" + plateID.ToString(), path.AppendElement(rightIndex[r + 3])); oDualLoop1Curves.Add(right, path.AppendElement(rightIndex[r + 3])); oDualLoop1Curves.Add(left, path.AppendElement(rightIndex[r + 3])); } } #endregion compair polygon index }
/// <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) { // 1. Retrieve and validate data var cell = new UnitCell(); double radius = 0; double height = 0; int nU = 0; int nV = 0; int nW = 0; bool morphed = false; if (!DA.GetData(0, ref cell)) { return; } if (!DA.GetData(1, ref radius)) { return; } if (!DA.GetData(2, ref height)) { return; } if (!DA.GetData(3, ref nU)) { return; } if (!DA.GetData(4, ref nV)) { return; } if (!DA.GetData(5, ref nW)) { return; } if (!DA.GetData(6, ref morphed)) { return; } if (!cell.isValid) { return; } if (radius == 0) { return; } if (height == 0) { return; } if (nU == 0) { return; } if (nV == 0) { return; } if (nW == 0) { return; } // 2. Initialize the lattice var lattice = new Lattice(); // Will contain the morphed uv spaces (as surface-surface, surface-axis or surface-point) var spaceTree = new DataTree<GeometryBase>(); // 3. Define cylinder Plane basePlane = Plane.WorldXY; Surface cylinder = ( new Cylinder(new Circle(basePlane, radius), height) ).ToNurbsSurface(); cylinder = cylinder.Transpose(); LineCurve axis = new LineCurve(basePlane.Origin, basePlane.Origin + height*basePlane.ZAxis); // 4. Package the number of cells in each direction into an array float[] N = new float[3] { nU, nV, nW }; // 5. Normalize the UV-domain Interval unitDomain = new Interval(0, 1); cylinder.SetDomain(0, unitDomain); // surface u-direction cylinder.SetDomain(1, unitDomain); // surface v-direction axis.Domain = unitDomain; // 6. Prepare cell (this is a UnitCell object) cell = cell.Duplicate(); cell.FormatTopology(); // 7. Map nodes to design space // Loop through the uvw cell grid for (int u = 0; u <= N[0]; u++) { for (int v = 0; v <= N[1]; v++) { for (int w = 0; w <= N[2]; w++) { // Construct cell path in tree GH_Path treePath = new GH_Path(u, v, w); // Fetch the list of nodes to append to, or initialise it var nodeList = lattice.Nodes.EnsurePath(treePath); // This loop maps each node index in the cell onto the UV-surface maps for (int i = 0; i < cell.Nodes.Count; i++) { double usub = cell.Nodes[i].X; // u-position within unit cell (local) double vsub = cell.Nodes[i].Y; // v-position within unit cell (local) double wsub = cell.Nodes[i].Z; // w-position within unit cell (local) double[] uvw = { u + usub, v + vsub, w + wsub }; // uvw-position (global) // Check if the node belongs to another cell (i.e. it's relative path points outside the current cell) bool isOutsideCell = (cell.NodePaths[i][0] > 0 || cell.NodePaths[i][1] > 0 || cell.NodePaths[i][2] > 0); // Check if current uvw-position is beyond the upper boundary bool isOutsideSpace = (uvw[0] > N[0] || uvw[1] > N[1] || uvw[2] > N[2]); if (isOutsideCell || isOutsideSpace) { nodeList.Add(null); } else { Point3d pt1, pt2; Vector3d[] derivatives; // Construct z-position vector Vector3d vectorZ = height * basePlane.ZAxis * uvw[0] / N[0]; // Compute pt1 (on axis) pt1 = basePlane.Origin + vectorZ; // Compute pt2 (on surface) cylinder.Evaluate(uvw[0] / N[0], uvw[1] / N[1], 2, out pt2, out derivatives); // Create vector joining these two points Vector3d wVect = pt2 - pt1; // Instantiate new node var newNode = new LatticeNode(pt1 + wVect * uvw[2] / N[2]); // Add new node to tree nodeList.Add(newNode); } } } // Define the uv space map tree (used for morphing) if (morphed && u < N[0] && v < N[1]) { GH_Path spacePath = new GH_Path(u, v); // Set trimming interval var uInterval = new Interval((u) / N[0], (u + 1) / N[0]); var vInterval = new Interval((v) / N[1], (v + 1) / N[1]); // Create sub-surface and sub axis Surface ss1 = cylinder.Trim(uInterval, vInterval); Curve ss2 = axis.Trim(uInterval); // Unitize domains ss1.SetDomain(0, unitDomain); ss1.SetDomain(1, unitDomain); ss2.Domain = unitDomain; // Save to the space tree spaceTree.Add(ss1, spacePath); spaceTree.Add(ss2, spacePath); } } } // 8. Map struts to the node tree if (morphed) { lattice.MorphMapping(cell, spaceTree, N); } else { lattice.ConformMapping(cell, N); } // 9. Set output DA.SetDataList(0, lattice.Struts); }
/// <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) { //-----------------------------------------------------------------INPUT----------------------------------------------------------------------------// List<IGoal> permanentGoals = new List<IGoal>(); DA.GetDataList(0, permanentGoals); List<IGoal> loadGoals = new List<IGoal>(); DA.GetDataList(1, loadGoals); double fStart = 1.0; DA.GetData(2, ref fStart); double fStep = 0.1; DA.GetData(3, ref fStep); double angle = 15.0; DA.GetData(4, ref angle); angle *= Math.PI / 180.0; double displ = 2.0; DA.GetData(5, ref displ); double threshold = 1e-15; DA.GetData(6, ref threshold); int equilibriumIter = 100; DA.GetData(7, ref equilibriumIter); bool opt = false; DA.GetData(8, ref opt); int maxIterations = 1000; //--------------------------------------------------------------CALCULATE----------------------------------------------------------------------------// //-------------------VALUES TO STORE----------------------------// //Position lists List<Point3d> initialPositions = new List<Point3d>(); List<Point3d> previousPositions = new List<Point3d>(); List<Point3d> currentPositions = new List<Point3d>(); DataTree<Point3d> vertexPositions = new DataTree<Point3d>(); //Goal output lists List<object> previousGOutput = new List<object>(); List<object> currentGOutput = new List<object>(); DataTree<object> outputGoals = new DataTree<object>(); //Load factors and displacements List<double> loadfactors = new List<double>(); List<double> displacementsRMS = new List<double>(); //-------------------K2 PHYSICAL SYSTEM----------------------------// //Initialise Kangaroo solver var PS = new KangarooSolver.PhysicalSystem(); var GoalList = new List<IGoal>(); //Assign indexes to the particles in each Goal foreach (IGoal pG in permanentGoals) { PS.AssignPIndex(pG, 0.01); GoalList.Add(pG); } foreach (IGoal lG in loadGoals) { PS.AssignPIndex(lG, 0.01); GoalList.Add(lG); } //Store initial loads List<Vector3d> initialLoads = new List<Vector3d>(); for (int i = 0; i < loadGoals.Count; i++) { initialLoads.Add(loadGoals[i].Move[0]); } //-------------------INITIALISE VALUE LISTS----------------------------// //Initial vertex positions Point3d[] initPos = PS.GetPositionArray(); foreach (Point3d pt in initPos) { initialPositions.Add(pt); previousPositions.Add(pt); currentPositions.Add(pt); } //Initial goal output List<object> initGOutput = PS.GetOutput(GoalList); for (int i = 0; i < permanentGoals.Count; i++) { previousGOutput.Add(initGOutput[i]); currentGOutput.Add(initGOutput[i]); } //-------------------LOAD INCREMENT LOOP----------------------------// bool run = true; int iter = 0; double LF; double BLF = 0.0; double preRMS = 0.0; while (run && iter < maxIterations) { LF = fStart + (fStep * iter); loadfactors.Add(LF); //Scale load goals in each iteration for (int i = 0; i < loadGoals.Count; i++) { int index = GoalList.Count - loadGoals.Count + i; Vector3d scaledLoad = initialLoads[i] * LF; GoalList[index] = new KangarooSolver.Goals.Unary(GoalList[index].PIndex[0], scaledLoad); } //Solve equilibrium for given load increment int counter = 0; do { PS.Step(GoalList, true, threshold); counter++; } while (PS.GetvSum() > threshold && counter < equilibriumIter); //Update value lists GH_Path path = new GH_Path(iter); //Get new equilibrium positions and update position lists Point3d[] newPositions = PS.GetPositionArray(); for (int k = 0; k < initialPositions.Count; k++) { previousPositions[k] = currentPositions[k]; currentPositions[k] = newPositions[k]; if (opt) { vertexPositions.Add(newPositions[k], path); } } //Get new goal output and update goal output lists List<object> newGOutput = PS.GetOutput(GoalList); for (int m = 0; m < permanentGoals.Count; m++) { previousGOutput[m] = currentGOutput[m]; currentGOutput[m] = newGOutput[m]; if (opt) { outputGoals.Add(newGOutput[m], path); } } //Does buckling occur? List<Vector3d> nodalDisplacements = calcDisplacement(currentPositions, initialPositions); double curRMS = calcDisplacementsRMS(nodalDisplacements); displacementsRMS.Add(curRMS); bool buckled = isBuckled(curRMS, preRMS, iter, fStart, fStep, angle); bool deflected = isDeflectionTooBig(nodalDisplacements, displ); if (buckled || deflected) { run = false; BLF = LF - fStep; } //Update preRMS = curRMS; iter++; } //-----------------------FLAG BUCKLED STATE----------------------------// if (BLF >= 1.0) { this.Message = "Works!"; } else { this.Message = "Buckles!"; } //-----------------------WARNING----------------------------// //If the maximum number of iterations has been reached if (iter == maxIterations) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Buckling did not occur within " + maxIterations + " load increments. Adjust load-step"); } //-----------------------UPDATE VALUE LISTS----------------------------// //If opt is false then add results from last two iterations if (!opt) { for (int i = 0; i < currentPositions.Count; i++) { vertexPositions.Add(previousPositions[i], new GH_Path(0)); vertexPositions.Add(currentPositions[i], new GH_Path(1)); } for (int j = 0; j < currentGOutput.Count; j++) { outputGoals.Add(previousGOutput[j], new GH_Path(0)); outputGoals.Add(currentGOutput[j], new GH_Path(1)); } } //---------------------------------------------------------------OUTPUT-------------------------------------------------------------------------------// DA.SetData(0, BLF); DA.SetDataList(1, loadfactors); DA.SetDataList(2, displacementsRMS); DA.SetDataTree(3, vertexPositions); DA.SetDataTree(4, outputGoals); }
protected override void SolveInstance(IGH_DataAccess DA) { bool runCommand = false; GH_Structure<GH_Point> origPoints = new GH_Structure<GH_Point>(); GH_Structure<GH_Point> adaptPoints = new GH_Structure<GH_Point>(); GH_Structure<GH_Curve> curves = new GH_Structure<GH_Curve>(); GH_Structure<GH_Vector> orientations = new GH_Structure<GH_Vector>(); GH_Structure<GH_Vector> faceOrientations = new GH_Structure<GH_Vector>(); DA.GetData(0, ref runCommand); DA.GetDataTree(1, out origPoints); DA.GetDataTree(2, out adaptPoints); DA.GetDataTree(3, out curves); DA.GetDataTree(4, out orientations); DA.GetDataTree(5, out faceOrientations); // Make sure the family and type is set before running the command. if (runCommand && (familyName == null || familyName == "Not Selected")) { message = "Please select a family/type by double-clicking on the component before running the command."; } else if (runCommand) { // Get the scale GHInfo ghi = new GHInfo(); GHScale scale = ghi.GetScale(Rhino.RhinoDoc.ActiveDoc); // Send to Revit LyrebirdChannel channel = new LyrebirdChannel(appVersion); channel.Create(); if (channel != null) { string documentName = channel.DocumentName(); if (documentName != null) { // Create RevitObjects List<RevitObject> obj = new List<RevitObject>(); #region OriginPoint Based if (origPoints != null && origPoints.Branches.Count > 0) { List<RevitObject> tempObjs = new List<RevitObject>(); // make sure the branches match the datacount if (origPoints.Branches.Count == origPoints.DataCount) { for (int i = 0; i < origPoints.Branches.Count; i++) { GH_Point ghpt = origPoints[i][0]; LyrebirdPoint point = new LyrebirdPoint { X = ghpt.Value.X, Y = ghpt.Value.Y, Z = ghpt.Value.Z }; RevitObject ro = new RevitObject { Origin = point, FamilyName = familyName, TypeName = typeName, Category = category, CategoryId = categoryId, GHPath = origPoints.Paths[i].ToString(), GHScaleFactor = scale.ScaleFactor, GHScaleName = scale.ScaleName }; tempObjs.Add(ro); } obj = tempObjs; } else { // Inform the user they need to graft their inputs. Only one point per branch System.Windows.Forms.MessageBox.Show("Warning:\n\nEach Branch represents an object, " + "so origin point based elements should be grafted so that each point is on it's own branch."); } } #endregion #region AdaptiveComponents else if (adaptPoints != null && adaptPoints.Branches.Count > 0) { // generate adaptive components List<RevitObject> tempObjs = new List<RevitObject>(); for (int i = 0; i < adaptPoints.Branches.Count; i++) { RevitObject ro = new RevitObject(); List<LyrebirdPoint> points = new List<LyrebirdPoint>(); for (int j = 0; j < adaptPoints.Branches[i].Count; j++) { LyrebirdPoint point = new LyrebirdPoint(adaptPoints.Branches[i][j].Value.X, adaptPoints.Branches[i][j].Value.Y, adaptPoints.Branches[i][j].Value.Z); points.Add(point); } ro.AdaptivePoints = points; ro.FamilyName = familyName; ro.TypeName = typeName; ro.Origin = null; ro.Category = category; ro.CategoryId = categoryId; ro.GHPath = adaptPoints.Paths[i].ToString(); ro.GHScaleFactor = scale.ScaleFactor; ro.GHScaleName = scale.ScaleName; tempObjs.Add(ro); } obj = tempObjs; } #endregion #region Curve Based else if (curves != null && curves.Branches.Count > 0) { // Get curves for curve based components // Determine if we're profile or line based if (curves.Branches.Count == curves.DataCount) { // Determine if the curve is a closed planar curve Curve tempCrv = curves.Branches[0][0].Value; if (tempCrv.IsPlanar(0.00000001) && tempCrv.IsClosed) { // Closed planar curve List<RevitObject> tempObjs = new List<RevitObject>(); for (int i = 0; i < curves.Branches.Count; i++) { Curve crv = curves[i][0].Value; List<Curve> rCurves = new List<Curve>(); bool getCrvs = CurveSegments(rCurves, crv, true); if (rCurves.Count > 0) { RevitObject ro = new RevitObject(); List<LyrebirdCurve> lbCurves = new List<LyrebirdCurve>(); for (int j = 0; j < rCurves.Count; j++) { LyrebirdCurve lbc; lbc = GetLBCurve(rCurves[j]); lbCurves.Add(lbc); } ro.Curves = lbCurves; ro.FamilyName = familyName; ro.Category = category; ro.CategoryId = categoryId; ro.TypeName = typeName; ro.Origin = null; ro.GHPath = curves.Paths[i].ToString(); ro.GHScaleFactor = scale.ScaleFactor; ro.GHScaleName = scale.ScaleName; tempObjs.Add(ro); } } obj = tempObjs; } else if (!tempCrv.IsClosed) { // Line based. Can only be arc or linear curves List<RevitObject> tempObjs = new List<RevitObject>(); for (int i = 0; i < curves.Branches.Count; i++) { Curve ghc = curves.Branches[i][0].Value; // Test that there is only one curve segment PolyCurve polycurve = ghc as PolyCurve; if (polycurve != null) { Curve[] segments = polycurve.Explode(); if (segments.Count() != 1) { break; } } if (ghc != null) { //List<LyrebirdPoint> points = new List<LyrebirdPoint>(); LyrebirdCurve lbc = GetLBCurve(ghc); List<LyrebirdCurve> lbcurves = new List<LyrebirdCurve> { lbc }; RevitObject ro = new RevitObject { Curves = lbcurves, FamilyName = familyName, Category = category, CategoryId = categoryId, TypeName = typeName, Origin = null, GHPath = curves.Paths[i].ToString(), GHScaleFactor = scale.ScaleFactor, GHScaleName = scale.ScaleName }; tempObjs.Add(ro); } } obj = tempObjs; } } else { // Make sure all of the curves in each branch are closed bool allClosed = true; DataTree<CurveCheck> crvTree = new DataTree<CurveCheck>(); for (int i = 0; i < curves.Branches.Count; i++) { List<GH_Curve> ghCrvs = curves.Branches[i]; List<CurveCheck> checkedcurves = new List<CurveCheck>(); GH_Path path = new GH_Path(i); for (int j = 0; j < ghCrvs.Count; j++) { Curve c = ghCrvs[j].Value; if (c.IsClosed) { AreaMassProperties amp = AreaMassProperties.Compute(c); if (amp != null) { double area = amp.Area; CurveCheck cc = new CurveCheck(c, area); checkedcurves.Add(cc); } } else { allClosed = false; } } if (allClosed) { // Sort the curves by area checkedcurves.Sort((x, y) => x.Area.CompareTo(y.Area)); checkedcurves.Reverse(); foreach (CurveCheck cc in checkedcurves) { crvTree.Add(cc, path); } } } if (allClosed) { // Determine if the smaller profiles are within the larger bool allInterior = true; List<RevitObject> tempObjs = new List<RevitObject>(); for (int i = 0; i < crvTree.Branches.Count; i++) { try { List<int> crvSegmentIds = new List<int>(); List<LyrebirdCurve> lbCurves = new List<LyrebirdCurve>(); List<CurveCheck> checkedCrvs = crvTree.Branches[i]; Curve outerProfile = checkedCrvs[0].Curve; double outerArea = checkedCrvs[0].Area; List<Curve> planarCurves = new List<Curve>(); planarCurves.Add(outerProfile); double innerArea = 0.0; for (int j = 1; j < checkedCrvs.Count; j++) { planarCurves.Add(checkedCrvs[j].Curve); innerArea += checkedCrvs[j].Area; } // Try to create a planar surface IEnumerable<Curve> surfCurves = planarCurves; Brep[] b = Brep.CreatePlanarBreps(surfCurves); if (b.Count() == 1) { // Test the areas double brepArea = b[0].GetArea(); double calcArea = outerArea - innerArea; double diff = (brepArea - calcArea) / calcArea; if (diff < 0.1) { // The profiles probably are all interior foreach (CurveCheck cc in checkedCrvs) { Curve c = cc.Curve; List<Curve> rCurves = new List<Curve>(); bool getCrvs = CurveSegments(rCurves, c, true); if (rCurves.Count > 0) { int crvSeg = rCurves.Count; crvSegmentIds.Add(crvSeg); foreach (Curve rc in rCurves) { LyrebirdCurve lbc; lbc = GetLBCurve(rc); lbCurves.Add(lbc); } } } RevitObject ro = new RevitObject(); ro.Curves = lbCurves; ro.FamilyName = familyName; ro.Category = category; ro.CategoryId = categoryId; ro.TypeName = typeName; ro.Origin = null; ro.GHPath = crvTree.Paths[i].ToString(); ro.GHScaleFactor = scale.ScaleFactor; ro.GHScaleName = scale.ScaleName; ro.CurveIds = crvSegmentIds; tempObjs.Add(ro); } } else { allInterior = false; message = "Warning:\n\nEach Branch represents an object, " + "so curve based elements should be grafted so that each curve is on it's own branch, or all curves on a branch should " + "be interior to the largest, outer boundary."; } } catch { allInterior = false; // Inform the user they need to graft their inputs. Only one curve per branch message = "Warning:\n\nEach Branch represents an object, " + "so curve based elements should be grafted so that each curve is on it's own branch, or all curves on a branch should " + "be interior to the largest, outer boundary."; } } if (tempObjs.Count > 0) { obj = tempObjs; } } } } #endregion // Orientation if (orientations != null && orientations.Branches.Count > 0) { List<RevitObject> tempList = AssignOrientation(obj, orientations); obj = tempList; } // face orientation if (faceOrientations != null && faceOrientations.Branches.Count > 0) { List<RevitObject> tempList = AssignFaceOrientation(obj, faceOrientations); obj = tempList; } // Parameters... if (Params.Input.Count > 6) { List<RevitObject> currentObjs = obj; List<RevitObject> tempObjs = new List<RevitObject>(); for (int r = 0; r < currentObjs.Count; r++) { RevitObject ro = currentObjs[r]; List<RevitParameter> revitParams = new List<RevitParameter>(); for (int i = 6; i < Params.Input.Count; i++) { RevitParameter rp = new RevitParameter(); IGH_Param param = Params.Input[i]; string paramInfo = param.Description; string[] pi = paramInfo.Split(new[] { "\n", ":" }, StringSplitOptions.None); string paramName = null; try { paramName = pi[1].Substring(1); string paramStorageType = pi[5].Substring(1); rp.ParameterName = paramName; rp.StorageType = paramStorageType; } catch (Exception ex) { Debug.WriteLine(ex.Message); } if (paramName != null) { GH_Structure<IGH_Goo> data = null; try { DA.GetDataTree(i, out data); } catch (Exception ex) { Debug.WriteLine(ex.Message); } if (data != null) { string value = data[r][0].ToString(); rp.Value = value; revitParams.Add(rp); } } } ro.Parameters = revitParams; tempObjs.Add(ro); } obj = tempObjs; } // Send the data to Revit to create and/or modify family instances. if (obj != null && obj.Count > 0) { try { string docName = channel.DocumentName(); if (docName == null || docName == string.Empty) { message = "Could not contact the lyrebird server. Make sure it's running and try again."; } else { string nn = NickName; if (nn == null || nn.Length == 0) { nn = "LBOut"; } channel.CreateOrModify(obj, InstanceGuid, NickName); message = obj.Count.ToString() + " objects sent to the lyrebird server."; } } catch { message = "Could not contact the lyrebird server. Make sure it's running and try again."; } } channel.Dispose(); try { } catch (Exception ex) { Debug.WriteLine(ex.Message); } } else { message = "Error\n" + "The Lyrebird Service could not be found. Ensure Revit is running, the Lyrebird server plugin is installed, and the server is active."; } } } else { message = null; } // Check if the revit information is set if (familyName != null || (familyName != "Not Selected" && typeName != "Not Selected")) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Family: " + familyName); sb.AppendLine("Type: " + typeName); sb.AppendLine("Category: " + category); for (int i = 0; i < inputParameters.Count; i++) { RevitParameter rp = inputParameters[i]; string type = "Instance"; if (rp.IsType) { type = "Type"; } sb.AppendLine(string.Format("Parameter{0}: {1} / {2} / {3}", (i + 1).ToString(CultureInfo.InvariantCulture), rp.ParameterName, rp.StorageType, type)); } objMessage = sb.ToString(); } else { objMessage = "No data type set. Double-click to set data type"; } DA.SetData(0, objMessage); DA.SetData(1, message); }
// dual loop not directly connected to plates private void half_dualLoop_type_2(int edgeIndex, int triangleIndex, int neighbourTriIndex) { GH_Path path = new GH_Path(triangleIndex); Edge edge = iSpringMesh.Edges[edgeIndex]; // added for recognizing where is the plate - plate id int occupyiedVertex = edge.FirstAdjacentVertexIndex; if (iVertexStatus[edge.FirstAdjacentVertexIndex]) { occupyiedVertex = edge.FirstAdjacentVertexIndex; } if (edge.SecondAdjacentVertexIndex > 0 && iVertexStatus[edge.SecondAdjacentVertexIndex]) { occupyiedVertex = edge.SecondAdjacentVertexIndex; } int plateID = iPolyLineID[occupyiedVertex]; plateID = -10 - plateID; // vertex point int vertex1 = edge.FirstVertexIndex; int vertex2 = edge.SecondVertexIndex; Point3d vertexPt1 = iSpringMesh.Vertices[vertex1].Position; Point3d vertexPt2 = iSpringMesh.Vertices[vertex2].Position; double scaler1 = curveVerticesValues[vertex1]; double scaler2 = curveVerticesValues[vertex2]; double planarOffset1 = planarVerticesValues[vertex1]; double planarOffset2 = planarVerticesValues[vertex2]; double openingScalar1 = openingWidthVerticesValues[vertex1]; double openingScalar2 = openingWidthVerticesValues[vertex2]; double curvePointiness1 = pointinessValues[vertex1]; double curvePointiness2 = pointinessValues[vertex2]; //---- TriLoop Side UP ----------------------------------------------- #region TriLoop Side UP Point3d vertexPtUp1 = topCps[vertex1]; Point3d vertexPtUp2 = topCps[vertex2]; Point3d vertexPtUpM = 0.5 * (vertexPtUp1 + vertexPtUp2); Vector3d v_vertexPtUp1 = vertexPtUp1 - vertexPtUpM; Vector3d v_vertexPtUp2 = vertexPtUp2 - vertexPtUpM; v_vertexPtUp1.Unitize(); v_vertexPtUp2.Unitize(); Point3d oVertexPtUpM1 = vertexPtUpM + (v_vertexPtUp1 * planarOffset1); Point3d oVertexPtUpM2 = vertexPtUpM + (v_vertexPtUp2 * planarOffset2); Point3d ctPtUp1 = (scaler1) * vertexPtUp1 + (1 - scaler1) * oVertexPtUpM1; Point3d ctPtUp2 = (scaler2) * vertexPtUp2 + (1 - scaler2) * oVertexPtUpM2; // normalise hohles Point3d openingCtPtUp1 = vertexPtUp1 + (openingScalar1 * v_vertexPtUp1 * -1); Point3d openingCtPtUp2 = vertexPtUp2 + (openingScalar2 * v_vertexPtUp2 * -1); if (new Vector3d(ctPtUp1 - vertexPtUp1).Length > openingScalar1) ctPtUp1 = openingCtPtUp1; if (new Vector3d(ctPtUp2 - vertexPtUp2).Length > openingScalar2) ctPtUp2 = openingCtPtUp2; // end normalise hohles #endregion TriLoop Side UP //---- TriLoop Side Down ----------------------------------------------- #region TriLoop Side Down Point3d vertexPtDown1 = bottomCps[vertex1]; Point3d vertexPtDown2 = bottomCps[vertex2]; Point3d vertexPtDownM = 0.5 * (vertexPtDown1 + vertexPtDown2); Vector3d v_vertexPtDown1 = vertexPtDown1 - vertexPtDownM; Vector3d v_vertexPtDown2 = vertexPtDown2 - vertexPtDownM; v_vertexPtDown1.Unitize(); v_vertexPtDown2.Unitize(); Point3d oVertexPtDownM1 = vertexPtDownM + (v_vertexPtDown1 * planarOffset1); Point3d oVertexPtDownM2 = vertexPtDownM + (v_vertexPtDown2 * planarOffset2); Point3d ctPtDown1 = (scaler1) * vertexPtDown1 + (1 - scaler1) * oVertexPtDownM1; Point3d ctPtDown2 = (scaler2) * vertexPtDown2 + (1 - scaler2) * oVertexPtDownM2; // normalise hohles Point3d openingCtPtDown1 = vertexPtDown1 + (openingScalar1 * v_vertexPtDown1 * -1); Point3d openingCtPtDown2 = vertexPtDown2 + (openingScalar2 * v_vertexPtDown2 * -1); if (new Vector3d(ctPtDown1 - vertexPtDown1).Length > openingScalar1) ctPtDown1 = openingCtPtDown1; if (new Vector3d(ctPtDown2 - vertexPtDown2).Length > openingScalar2) ctPtDown2 = openingCtPtDown2; // end normalise hohles #endregion TriLoop Side Down //---- Plate Side UP ------------------------------------------------- #region Plate Side UP Point3d upTPI = topCenterPts[triangleIndex]; Vector3d v_vertexPtUp1_upTPI = vertexPtUp1 - upTPI; Vector3d v_vertexPtUp2_upTPI = vertexPtUp2 - upTPI; v_vertexPtUp1_upTPI.Unitize(); v_vertexPtUp2_upTPI.Unitize(); Point3d oUpTPI01 = upTPI + (v_vertexPtUp1_upTPI * planarOffset1); Point3d oUpTPI02 = upTPI + (v_vertexPtUp2_upTPI * planarOffset2); Point3d ctUpTPI1 = (scaler1) * vertexPtUp1 + (1 - scaler1) * oUpTPI01; Point3d ctUpTPI2 = (scaler2) * vertexPtUp2 + (1 - scaler2) * oUpTPI02; // normalise hohles Point3d openingCtUpTPI1 = vertexPtUp1 + (openingScalar1 * v_vertexPtUp1_upTPI * -1); Point3d openingCtUpTPI2 = vertexPtUp2 + (openingScalar2 * v_vertexPtUp2_upTPI * -1); if (new Vector3d(ctUpTPI1 - vertexPtUp1).Length > openingScalar1) ctUpTPI1 = openingCtUpTPI1; if (new Vector3d(ctUpTPI2 - vertexPtUp2).Length > openingScalar2) ctUpTPI2 = openingCtUpTPI2; // end normalise hohles #endregion Plate Side UP //---- Plate Side DOWN ----------------------------------------------- #region Plate Side DOWN Point3d downTPI = bottomCenterPts[triangleIndex]; Vector3d v_vertexPtUp1_downTPI = vertexPtDown1 - downTPI; Vector3d v_vertexPtUp2_downTPI = vertexPtDown2 - downTPI; v_vertexPtUp1_downTPI.Unitize(); v_vertexPtUp2_downTPI.Unitize(); Point3d oDownTPI01 = downTPI + (v_vertexPtUp1_downTPI * planarOffset1); Point3d oDownTPI02 = downTPI + (v_vertexPtUp2_downTPI * planarOffset2); Point3d ctDownTPI1 = (scaler1) * vertexPtDown1 + (1 - scaler1) * oDownTPI01; Point3d ctDownTPI2 = (scaler2) * vertexPtDown2 + (1 - scaler2) * oDownTPI02; // normalise hohles Point3d openingCtDownTPI1 = vertexPtDown1 + (openingScalar1 * v_vertexPtUp1_downTPI * -1); Point3d openingCtDownTPI2 = vertexPtDown2 + (openingScalar2 * v_vertexPtUp2_downTPI * -1); if (new Vector3d(ctDownTPI1 - vertexPtDown1).Length > openingScalar1) ctDownTPI1 = openingCtDownTPI1; if (new Vector3d(ctDownTPI2 - vertexPtDown2).Length > openingScalar2) ctDownTPI2 = openingCtDownTPI2; // end normalise hohles #endregion Plate Side DOWN //---- Curves Right 1 ----------------------------------------------------------- #region Curves Right 1 // Pointiness of the Surface Point3d min_vertexPtRight1 = 0.5 * (ctUpTPI1 + ctDownTPI1); Point3d vertexPtRight1 = (curvePointiness1 * vertexPt1) + ((1 - curvePointiness1) * min_vertexPtRight1); Curve right1Loop = Curve.CreateControlPointCurve( new List<Point3d>() { oDownTPI01, ctDownTPI1, vertexPtRight1, ctUpTPI1, oUpTPI01 }, curveDegree); Curve right1PlanarUp = Curve.CreateControlPointCurve( new List<Point3d>() { oUpTPI01, upTPI }, 1); Curve right1PlanarDown = Curve.CreateControlPointCurve( new List<Point3d>() { downTPI, oDownTPI01 }, 1); /* PolyCurve right1 = new PolyCurve(); right1.Append(right1PlanarUp); right1.Append(right1Loop); right1.Append(right1PlanarDown);*/ Curve right1 = Curve.JoinCurves(new List<Curve>() { right1PlanarDown, right1Loop, right1PlanarUp }, documentTolerance, true)[0]; if (iPolySrf) { right1 = right1Loop; } #endregion Curves Right 1 //---- Curves Left 1 ----------------------------------------------------------- #region Curves Left 1 // Pointiness of the Surface Point3d min_vertexPtLeft1 = 0.5 * (ctPtUp1 + ctPtDown1); Point3d vertexPtLeft1 = (curvePointiness1 * vertexPt1) + ((1 - curvePointiness1) * min_vertexPtLeft1); Curve left1Loop = Curve.CreateControlPointCurve( new List<Point3d>() { oVertexPtDownM1, ctPtDown1, vertexPtLeft1, ctPtUp1, oVertexPtUpM1 }, curveDegree); Curve left1PlanarUp = Curve.CreateControlPointCurve( new List<Point3d>() { oVertexPtUpM1, vertexPtUpM }, 1); Curve left1PlanarDown = Curve.CreateControlPointCurve( new List<Point3d>() { vertexPtDownM, oVertexPtDownM1 }, 1); /* PolyCurve left1 = new PolyCurve(); left1.Append(left1PlanarUp); left1.Append(left1Loop); left1.Append(left1PlanarDown);*/ Curve left1 = Curve.JoinCurves(new List<Curve>() { left1PlanarDown, left1Loop, left1PlanarUp }, documentTolerance, true)[0]; if (iPolySrf) { left1 = left1Loop; } #endregion Curves Left 1 //---- Curves Right 2 ----------------------------------------------------------- #region Curves Right 2 // Pointiness of the Surface Point3d min_vertexPtRight2 = 0.5 * (ctUpTPI2 + ctDownTPI2); Point3d vertexPtRight2 = (curvePointiness2 * vertexPt2) + ((1 - curvePointiness2) * min_vertexPtRight2); Curve right2Loop = Curve.CreateControlPointCurve( new List<Point3d>() { oDownTPI02, ctDownTPI2, vertexPtRight2, ctUpTPI2, oUpTPI02 }, curveDegree); Curve right2PlanarUp = Curve.CreateControlPointCurve( new List<Point3d>() { oUpTPI02, upTPI }, 1); Curve right2PlanarDown = Curve.CreateControlPointCurve( new List<Point3d>() { downTPI, oDownTPI02 }, 1); /* PolyCurve right2 = new PolyCurve(); right2.Append(right2PlanarUp); right2.Append(right2Loop); right2.Append(right2PlanarDown);*/ Curve right2 = Curve.JoinCurves(new List<Curve>() { right2PlanarDown, right2Loop, right2PlanarUp }, documentTolerance, true)[0]; if (iPolySrf) { right2 = right2Loop; } #endregion Curves Right 2 //---- Curves Left 2 ----------------------------------------------------------- #region Curves Left 2 // Pointiness of the Surface Point3d min_vertexPtLeft2 = 0.5 * (ctPtUp2 + ctPtDown2); Point3d vertexPtLeft2 = (curvePointiness2 * vertexPt2) + ((1 - curvePointiness2) * min_vertexPtLeft2); Curve left2Loop = Curve.CreateControlPointCurve( new List<Point3d>() { oVertexPtDownM2, ctPtDown2, vertexPtLeft2, ctPtUp2, oVertexPtUpM2 }, curveDegree); Curve left2PlanarUp = Curve.CreateControlPointCurve( new List<Point3d>() { oVertexPtUpM2, vertexPtUpM }, 1); Curve left2PlanarDown = Curve.CreateControlPointCurve( new List<Point3d>() { vertexPtDownM, oVertexPtDownM2 }, 1); /* PolyCurve left2 = new PolyCurve(); left2.Append(left2PlanarUp); left2.Append(left2Loop); left2.Append(left2PlanarDown);*/ Curve left2 = Curve.JoinCurves(new List<Curve>() { left2PlanarDown, left2Loop, left2PlanarUp }, documentTolerance, true)[0]; if (iPolySrf) { left2 = left2Loop; } #endregion Curves Left 2 // sorting sequence Brep[] brep1 = Brep.CreateFromLoft( new List<Curve>() { left1, right1 }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); #region allow poly surface if (iPolySrf) { Brep[] brep1PlanarUp = Brep.CreateFromLoft( new List<Curve>() { left1PlanarUp, right1PlanarUp }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); Brep[] brep1PlanarDown = Brep.CreateFromLoft( new List<Curve>() { left1PlanarDown, right1PlanarDown }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); brep1 = Brep.JoinBreps(new List<Brep>(){brep1PlanarDown[0], brep1[0], brep1PlanarUp[0]}, documentTolerance); } #endregion allow poly surface if (brep1.Length > 0) { //oDualLoop.Add(brep1[0]); Brep brepTestNormal = brep1[0]; BrepFace brepF = brepTestNormal.Faces[0]; // id int neighbour2TriIndex = 0; if (vertex2 == iSpringMesh.Triangles[triangleIndex].FirstVertexIndex) neighbour2TriIndex = iSpringMesh.Triangles[triangleIndex].FirstAdjTriIndex; if (vertex2 == iSpringMesh.Triangles[triangleIndex].SecondVertexIndex) neighbour2TriIndex = iSpringMesh.Triangles[triangleIndex].SecondAdjTriIndex; if (vertex2 == iSpringMesh.Triangles[triangleIndex].ThirdVertexIndex) neighbour2TriIndex = iSpringMesh.Triangles[triangleIndex].ThirdAdjTriIndex; if (brepF.NormalAt(0, 0).Z < 0) // conditional flipping surface, according face normal. special case for our pavilion mesh { Brep[] brepN1 = Brep.CreateFromLoft( new List<Curve>() { right1, left1 }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); #region allow poly surface if (iPolySrf) { Brep[] brepN1PlanarUp = Brep.CreateFromLoft( new List<Curve>() { right1PlanarUp, left1PlanarUp }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); Brep[] brepN1PlanarDown = Brep.CreateFromLoft( new List<Curve>() { right1PlanarDown, left1PlanarDown }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); brepN1 = Brep.JoinBreps(new List<Brep>() { brepN1PlanarDown[0], brepN1[0], brepN1PlanarUp[0] }, documentTolerance); } #endregion allow poly surface if (brep1.Length > 0) { oDualLoop2.Add(brepN1[0], path.AppendElement(0)); oDualLoop2ID.Add("J;" + triangleIndex.ToString() + ";" + neighbourTriIndex.ToString() + ";" + neighbour2TriIndex.ToString() + ";" + plateID.ToString(), path.AppendElement(0)); oDualLoop2Curves.Add(right1, path.AppendElement(0)); oDualLoop2Curves.Add(left1, path.AppendElement(0)); } } else { oDualLoop2.Add(brep1[0], path.AppendElement(0)); oDualLoop2ID.Add("J;" + triangleIndex.ToString() + ";" + neighbourTriIndex.ToString() + ";" + neighbour2TriIndex.ToString() + ";" + plateID.ToString(), path.AppendElement(0)); oDualLoop2Curves.Add(left1, path.AppendElement(0)); oDualLoop2Curves.Add(right1, path.AppendElement(0)); } } Brep[] brep2 = Brep.CreateFromLoft( new List<Curve>() { left2, right2 }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); #region allow poly surface if (iPolySrf) { Brep[] brep2PlanarUp = Brep.CreateFromLoft( new List<Curve>() { left2PlanarUp, right2PlanarUp }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); Brep[] brep2PlanarDown = Brep.CreateFromLoft( new List<Curve>() { left2PlanarDown, right2PlanarDown }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); brep2 = Brep.JoinBreps(new List<Brep>() { brep2PlanarDown[0], brep2[0], brep2PlanarUp[0] }, documentTolerance); } #endregion allow poly surface if (brep2.Length > 0) { //oDualLoop.Add(brep2[0]); Brep brepTestNormal = brep2[0]; BrepFace brepF = brepTestNormal.Faces[0]; // id int neighbour2TriIndex = 0; if (vertex1 == iSpringMesh.Triangles[triangleIndex].FirstVertexIndex) neighbour2TriIndex = iSpringMesh.Triangles[triangleIndex].FirstAdjTriIndex; if (vertex1 == iSpringMesh.Triangles[triangleIndex].SecondVertexIndex) neighbour2TriIndex = iSpringMesh.Triangles[triangleIndex].SecondAdjTriIndex; if (vertex1 == iSpringMesh.Triangles[triangleIndex].ThirdVertexIndex) neighbour2TriIndex = iSpringMesh.Triangles[triangleIndex].ThirdAdjTriIndex; if (brepF.NormalAt(0, 0).Z < 0) { Brep[] brepN2 = Brep.CreateFromLoft( new List<Curve>() { right2, left2 }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); #region allow poly surface if (iPolySrf) { Brep[] brepN2PlanarUp = Brep.CreateFromLoft( new List<Curve>() { right2PlanarUp, left2PlanarUp }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); Brep[] brepN2PlanarDown = Brep.CreateFromLoft( new List<Curve>() { right2PlanarDown, left2PlanarDown }, Point3d.Unset, Point3d.Unset, LoftType.Normal, false ); brepN2 = Brep.JoinBreps(new List<Brep>() { brepN2PlanarDown[0], brepN2[0], brepN2PlanarUp[0] }, documentTolerance); } #endregion allow poly surface if (brep2.Length > 0) { oDualLoop2.Add(brepN2[0], path.AppendElement(1)); oDualLoop2ID.Add("J;" + triangleIndex.ToString() + ";" + neighbourTriIndex.ToString() + ";" + neighbour2TriIndex.ToString() + ";" + plateID.ToString(), path.AppendElement(1)); oDualLoop2Curves.Add(right2, path.AppendElement(1)); oDualLoop2Curves.Add(left2, path.AppendElement(1)); } } else { oDualLoop2.Add(brep2[0], path.AppendElement(1)); oDualLoop2ID.Add("J;" + triangleIndex.ToString() + ";" + neighbourTriIndex.ToString() + ";" + neighbour2TriIndex.ToString() + ";" + plateID.ToString(), path.AppendElement(1)); oDualLoop2Curves.Add(left2, path.AppendElement(1)); oDualLoop2Curves.Add(right2, path.AppendElement(1)); } } }
// Sofistik Information public void SofistikInformation() { GH_Path pthPlanarL01 = new GH_Path(0); GH_Path pthPlanarL02 = new GH_Path(1); GH_Path pthLoop00 = new GH_Path(2); GH_Path pthLoop01 = new GH_Path(3); GH_Path pthLoop02 = new GH_Path(4); #region Sofistik Points for (int i = 0; i < 3; i++) { //planar Part Points L01 AllSofistikPoints.Add(RightfromCenterL01[i], pthPlanarL01); SofistikIndexies.Add(i + 0 + (i * 2), pthPlanarL01); AllSofistikPoints.Add(CentersL01[i], pthPlanarL01); SofistikIndexies.Add(i + 1 + (i * 2), pthPlanarL01); AllSofistikPoints.Add(LeftfromCenterL01[i], pthPlanarL01); SofistikIndexies.Add(i + 2 + (i * 2), pthPlanarL01); //planar Part Points L02 AllSofistikPoints.Add(RightfromCenterL02[i], pthPlanarL02); SofistikIndexies.Add(i + 10 + (i * 2), pthPlanarL02); AllSofistikPoints.Add(CentersL02[i], pthPlanarL02); SofistikIndexies.Add(i + 11 + (i * 2), pthPlanarL02); AllSofistikPoints.Add(LeftfromCenterL02[i], pthPlanarL02); SofistikIndexies.Add(i + 12 + (i * 2), pthPlanarL02); #region Sofistik Plate //---- Sofistik Plate Curves --------------------------------------------------------------------------- //planar Part Points L01 SofistikPlatePoints.Add(RightfromCenterL01[i], pthPlanarL01); SofistikPlateIndexies.Add(i + 0 + (i * 2), pthPlanarL01); SofistikPlatePoints.Add(CentersL01[i], pthPlanarL01); SofistikPlateIndexies.Add(i + 1 + (i * 2), pthPlanarL01); SofistikPlatePoints.Add(LeftfromCenterL01[i], pthPlanarL01); SofistikPlateIndexies.Add(i + 2 + (i * 2), pthPlanarL01); //planar Part Points L02 SofistikPlatePoints.Add(RightfromCenterL02[i], pthPlanarL02); SofistikPlateIndexies.Add(i + 10 + (i * 2), pthPlanarL02); SofistikPlatePoints.Add(CentersL02[i], pthPlanarL02); SofistikPlateIndexies.Add(i + 11 + (i * 2), pthPlanarL02); SofistikPlatePoints.Add(LeftfromCenterL02[i], pthPlanarL02); SofistikPlateIndexies.Add(i + 12 + (i * 2), pthPlanarL02); #endregion Sofistik Plate } for (int i = 0; i < 3; i++) { int counter = 0; foreach (Curve c in Curves.Branch(i)) { AllSofistikPoints.Add(c.PointAtNormalizedLength(0.0), new GH_Path(i + 2)); // check for corresponding point index for (int k = 0; k < AllSofistikPoints.Branch(0).Count; k++) { if ((Math.Abs(c.PointAtNormalizedLength(0.0).X - AllSofistikPoints.Branch(0)[k].X) < 0.001) && (Math.Abs(c.PointAtNormalizedLength(0.0).Y - AllSofistikPoints.Branch(0)[k].Y) < 0.001)) { SofistikIndexies.Add(SofistikIndexies.Branch(0)[k], new GH_Path(i + 2)); } } //AllSofistikPoints.Add(c.PointAtNormalizedLength(0.5), new GH_Path(i + 2)); // check for corresponding point index //SofistikIndexies.Add(i * 2 + counter + 20, new GH_Path(i + 2)); AllSofistikPoints.Add(c.PointAtNormalizedLength(1.0), new GH_Path(i + 2)); // check for corresponding point index for (int k = 0; k < AllSofistikPoints.Branch(1).Count; k++) { if ((Math.Abs(c.PointAtNormalizedLength(1.0).X - AllSofistikPoints.Branch(1)[k].X) < 0.001) && (Math.Abs(c.PointAtNormalizedLength(1.0).Y - AllSofistikPoints.Branch(1)[k].Y) < 0.001)) { SofistikIndexies.Add(SofistikIndexies.Branch(1)[k], new GH_Path(i + 2)); } } counter++; } } #endregion Sofistik Points #region Sofistik Curves // planar Curves //L01 #region L01 for (int i = 0; i < AllSofistikPoints.Branch(0).Count; i++) { if (i < AllSofistikPoints.Branch(0).Count - 1) { int p = i + 0; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(0)[i], new GH_Path(p)); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(0)[i + 1], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(0)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(0)[i + 1], new GH_Path(p)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { AllSofistikPoints.Branch(0)[i], AllSofistikPoints.Branch(0)[i + 1] }), new GH_Path(p)); } else { int p = i + 0; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(0)[i], new GH_Path(p)); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(0)[0], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(0)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(0)[0], new GH_Path(p)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { AllSofistikPoints.Branch(0)[i], AllSofistikPoints.Branch(0)[0] }), new GH_Path(p)); } } #endregion L01 //L02 #region L02 for (int i = 0; i < AllSofistikPoints.Branch(1).Count; i++) { if (i < AllSofistikPoints.Branch(1).Count - 1) { int p = i + 10; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(1)[i], new GH_Path(p)); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(1)[i + 1], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(1)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(1)[i + 1], new GH_Path(p)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { AllSofistikPoints.Branch(1)[i], AllSofistikPoints.Branch(1)[i + 1] }), new GH_Path(p)); } else { int p = i + 10; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(1)[i], new GH_Path(p)); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(1)[0], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(1)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(1)[0], new GH_Path(p)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { AllSofistikPoints.Branch(1)[i], AllSofistikPoints.Branch(1)[0] }), new GH_Path(p)); } } #endregion L02 //Curves A #region Crv A SofistikCurves.Add(Curves.Branch(0)[0], new GH_Path(20)); SofistikCurves.Add(Curves.Branch(0)[1], new GH_Path(21)); for (int i = 0; i < AllSofistikPoints.Branch(2).Count; i++) { if (i < AllSofistikPoints.Branch(2).Count * 0.5) { // Left Curve int p = 20; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(2)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(2)[i], new GH_Path(p)); } else { // Right Curve int p = 21; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(2)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(2)[i], new GH_Path(p)); } } #endregion Crv A //Curves B #region Crv B SofistikCurves.Add(Curves.Branch(1)[0], new GH_Path(30)); SofistikCurves.Add(Curves.Branch(1)[1], new GH_Path(31)); for (int i = 0; i < AllSofistikPoints.Branch(3).Count; i++) { if (i < AllSofistikPoints.Branch(3).Count * 0.5) { // Left Curve int p = 30; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(3)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(3)[i], new GH_Path(p)); } else { // Right Curve int p = 31; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(3)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(3)[i], new GH_Path(p)); } } #endregion Crv B //Curves C #region Crv C SofistikCurves.Add(Curves.Branch(2)[0], new GH_Path(40)); SofistikCurves.Add(Curves.Branch(2)[1], new GH_Path(41)); for (int i = 0; i < AllSofistikPoints.Branch(4).Count; i++) { if (i < AllSofistikPoints.Branch(4).Count * 0.5) { // Left Curve int p = 40; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(4)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(4)[i], new GH_Path(p)); } else { // Right Curve int p = 41; SofistikCrvPtIdx.Add(SofistikIndexies.Branch(4)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(4)[i], new GH_Path(p)); } } #endregion Crv C //Curves AL-BR #region AL-BR //L01 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(20))[0], new GH_Path(22)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(21))[0], new GH_Path(22)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(20))[0], new GH_Path(22)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(21))[0], new GH_Path(22)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { SofistikCrvPtCoo.Branch(new GH_Path(20))[0], SofistikCrvPtCoo.Branch(new GH_Path(21))[0] }), new GH_Path(22)); //L02 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(20))[1], new GH_Path(23)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(21))[1], new GH_Path(23)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(20))[1], new GH_Path(23)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(21))[1], new GH_Path(23)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { SofistikCrvPtCoo.Branch(new GH_Path(20))[1], SofistikCrvPtCoo.Branch(new GH_Path(21))[1] }), new GH_Path(23)); #endregion AL-BR //Curves BL-CR #region BL-CR //L01 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(30))[0], new GH_Path(32)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(31))[0], new GH_Path(32)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(30))[0], new GH_Path(32)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(31))[0], new GH_Path(32)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { SofistikCrvPtCoo.Branch(new GH_Path(30))[0], SofistikCrvPtCoo.Branch(new GH_Path(31))[0] }), new GH_Path(32)); //L02 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(30))[1], new GH_Path(33)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(31))[1], new GH_Path(33)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(30))[1], new GH_Path(33)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(31))[1], new GH_Path(33)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { SofistikCrvPtCoo.Branch(new GH_Path(30))[1], SofistikCrvPtCoo.Branch(new GH_Path(31))[1] }), new GH_Path(33)); #endregion BL-CR //Curves CL-AR #region CL-AR //L01 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(40))[0], new GH_Path(42)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(41))[0], new GH_Path(42)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(40))[0], new GH_Path(42)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(41))[0], new GH_Path(42)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { SofistikCrvPtCoo.Branch(new GH_Path(40))[0], SofistikCrvPtCoo.Branch(new GH_Path(41))[0] }), new GH_Path(42)); //L02 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(40))[1], new GH_Path(43)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(new GH_Path(41))[1], new GH_Path(43)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(40))[1], new GH_Path(43)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(new GH_Path(41))[1], new GH_Path(43)); SofistikCurves.Add( Curve.CreateControlPointCurve(new List<Point3d>() { SofistikCrvPtCoo.Branch(new GH_Path(40))[1], SofistikCrvPtCoo.Branch(new GH_Path(41))[1] }), new GH_Path(43)); #endregion CL-AR #endregion Sofistik Curves }
//// ======================================================================================= public void Create_Stripe() { GH_Path pthA = new GH_Path(0); GH_Path pthB = new GH_Path(1); GH_Path pthC = new GH_Path(2); Tri_Loop_Stripe StripeA = new Tri_Loop_Stripe ( PlanarPentagonL01.Branch(pthA), PlanarPentagonL02.Branch(pthA), PlateCrvPts.Branch(pthA)[0], PlateCrvPts.Branch(pthA)[1], CurvesPts.Branch(pthA)[0], CurvesPts.Branch(pthA)[1], StripeID.Branch(pthA) ); Tri_Loop_Stripe StripeB = new Tri_Loop_Stripe ( PlanarPentagonL01.Branch(pthB), PlanarPentagonL02.Branch(pthB), PlateCrvPts.Branch(pthB)[0], PlateCrvPts.Branch(pthB)[1], CurvesPts.Branch(pthB)[0], CurvesPts.Branch(pthB)[1], StripeID.Branch(pthB) ); Tri_Loop_Stripe StripeC = new Tri_Loop_Stripe ( PlanarPentagonL01.Branch(pthC), PlanarPentagonL02.Branch(pthC), PlateCrvPts.Branch(pthC)[0], PlateCrvPts.Branch(pthC)[1], CurvesPts.Branch(pthC)[0], CurvesPts.Branch(pthC)[1], StripeID.Branch(pthC) ); Stripes.Add(StripeA); // [0] Stripes.Add(StripeB); // [1] Stripes.Add(StripeC); // [2] }
/// <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) { // 1. Declare placeholder variables and assign initial invalid data. // This way, if the input parameters fail to supply valid data, we know when to abort var cell = new UnitCell(); double xCellSize = 0; double yCellSize = 0; double zCellSize = 0; int nX = 0; int nY = 0; int nZ = 0; // 2. Retrieve input data. if (!DA.GetData(0, ref cell)) { return; } if (!DA.GetData(1, ref xCellSize)) { return; } if (!DA.GetData(2, ref yCellSize)) { return; } if (!DA.GetData(3, ref zCellSize)) { return; } if (!DA.GetData(4, ref nX)) { return; } if (!DA.GetData(5, ref nY)) { return; } if (!DA.GetData(6, ref nZ)) { return; } // 3. If data is invalid, we need to abort. if (!cell.isValid) { return; } if (xCellSize == 0) { return; } if (yCellSize == 0) { return; } if (zCellSize == 0) { return; } if (nX == 0) { return; } if (nY == 0) { return; } if (nZ == 0) { return; } // 4. Initialise the lattice object var lattice = new Lattice(); // 5. Prepare cell (this is a UnitCell object) cell = cell.Duplicate(); cell.FormatTopology(); // 6. Define BasePlane and directional iteration vectors Plane basePlane = Plane.WorldXY; Vector3d vectorX = xCellSize * basePlane.XAxis; Vector3d vectorY = yCellSize * basePlane.YAxis; Vector3d vectorZ = zCellSize * basePlane.ZAxis; float[] N = new float[3] { nX, nY, nZ }; // 7. Map nodes to design space // Loop through the uvw cell grid for (int u = 0; u <= N[0]; u++) { for (int v = 0; v <= N[1]; v++) { for (int w = 0; w <= N[2]; w++) { // Construct cell path in tree GH_Path treePath = new GH_Path(u, v, w); // Fetch the list of nodes to append to, or initialise it var nodeList = lattice.Nodes.EnsurePath(treePath); // This loop maps each node in the cell for (int i = 0; i < cell.Nodes.Count; i++) { double usub = cell.Nodes[i].X; // u-position within unit cell (local) double vsub = cell.Nodes[i].Y; // v-position within unit cell (local) double wsub = cell.Nodes[i].Z; // w-position within unit cell (local) double[] uvw = { u + usub, v + vsub, w + wsub }; // uvw-position (global) // Check if the node belongs to another cell (i.e. it's relative path points outside the current cell) bool isOutsideCell = (cell.NodePaths[i][0] > 0 || cell.NodePaths[i][1] > 0 || cell.NodePaths[i][2] > 0); // Check if current uvw-position is beyond the upper boundary bool isOutsideSpace = (uvw[0] > N[0] || uvw[1] > N[1] || uvw[2] > N[2]); if (isOutsideCell || isOutsideSpace) { nodeList.Add(null); } else { // Compute position vector Vector3d V = uvw[0] * vectorX + uvw[1] * vectorY + uvw[2] * vectorZ; // Instantiate new node var newNode = new LatticeNode(basePlane.Origin + V); // Add new node to tree nodeList.Add(newNode); } } } } } // 8. Map struts to the node tree lattice.ConformMapping(cell, N); // 9. Set output DA.SetDataList(0, lattice.Struts); }
/// <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) { //---- Declareing --------------------------------------------------------------------------- List<Tri_Loop_Component> All_Components = new List<Tri_Loop_Component>(); DA.GetDataList<Tri_Loop_Component>("Components", All_Components); DataTree<Curve> All_Curves = new DataTree<Curve>(); //// ======================================================================================= // Added by Gene DataTree<Curve> All_ExtendedCurves = new DataTree<Curve>(); DataTree<Brep> All_SingleStripeBreps = new DataTree<Brep>(); //// ======================================================================================= DataTree<Point3d> All_CentrePointsL01 = new DataTree<Point3d>(); DataTree<Point3d> All_CentrePointsL02 = new DataTree<Point3d>(); DataTree<Curve> All_PlateCrv = new DataTree<Curve>(); DataTree<Point3d> All_PentagonPts_L01 = new DataTree<Point3d>(); DataTree<Point3d> All_PentagonPts_L02 = new DataTree<Point3d>(); DataTree<int> All_StripeIds = new DataTree<int>(); DataTree<Brep> All_StripeBreps = new DataTree<Brep>(); DataTree<Curve> All_StripeIntersectCrvs = new DataTree<Curve>(); DataTree<Plane> All_StripeIntersectPlane = new DataTree<Plane>(); //---- End Declareing ----------------------------------------------------------------------- //---- Functions ---------------------------------------------------------------------------- int componentIdx = 0; foreach (Tri_Loop_Component component in All_Components) { GH_Path pth1 = new GH_Path(componentIdx); // run / generate Informations for Sofistik // create output information for (int p = 0; p < component.CentersL01.Count; p++) { All_CentrePointsL01.Add(component.CentersL01[p], pth1); All_CentrePointsL02.Add(component.CentersL02[p], pth1); } for (int c = 0; c < component.Curves.BranchCount; c++) { All_Curves.Add(component.Curves.Branch(c)[0], pth1.AppendElement(c)); All_Curves.Add(component.Curves.Branch(c)[1], pth1.AppendElement(c)); //// ======================================================================================= // Added by Gene All_ExtendedCurves.Add(component.ExtendedCurves.Branch(c)[0], pth1.AppendElement(c)); All_ExtendedCurves.Add(component.ExtendedCurves.Branch(c)[1], pth1.AppendElement(c)); //// ======================================================================================= } for (int sid = 0; sid < component.StripeID.BranchCount; sid++) { All_StripeIds.Add(component.StripeID.Branch(sid)[0], pth1.AppendElement(sid)); All_StripeIds.Add(component.StripeID.Branch(sid)[1], pth1.AppendElement(sid)); All_StripeIds.Add(component.StripeID.Branch(sid)[2], pth1.AppendElement(sid)); } for (int p = 0; p < component.PlateCrv.BranchCount; p++) { All_PlateCrv.Add(component.PlateCrv.Branch(p)[0], pth1.AppendElement(p)); All_PlateCrv.Add(component.PlateCrv.Branch(p)[1], pth1.AppendElement(p)); } for (int pent = 0; pent < component.PlanarPentagonL01.BranchCount; pent++) { All_PentagonPts_L01.Add(component.PlanarPentagonL01.Branch(pent)[0], pth1.AppendElement(pent)); All_PentagonPts_L01.Add(component.PlanarPentagonL01.Branch(pent)[1], pth1.AppendElement(pent)); All_PentagonPts_L01.Add(component.PlanarPentagonL01.Branch(pent)[2], pth1.AppendElement(pent)); All_PentagonPts_L01.Add(component.PlanarPentagonL01.Branch(pent)[3], pth1.AppendElement(pent)); All_PentagonPts_L01.Add(component.PlanarPentagonL01.Branch(pent)[4], pth1.AppendElement(pent)); } for (int pent = 0; pent < component.PlanarPentagonL02.BranchCount; pent++) { All_PentagonPts_L02.Add(component.PlanarPentagonL02.Branch(pent)[0], pth1.AppendElement(pent)); All_PentagonPts_L02.Add(component.PlanarPentagonL02.Branch(pent)[1], pth1.AppendElement(pent)); All_PentagonPts_L02.Add(component.PlanarPentagonL02.Branch(pent)[2], pth1.AppendElement(pent)); All_PentagonPts_L02.Add(component.PlanarPentagonL02.Branch(pent)[3], pth1.AppendElement(pent)); All_PentagonPts_L02.Add(component.PlanarPentagonL02.Branch(pent)[4], pth1.AppendElement(pent)); } // Information from Stripe Class for (int s = 0; s < component.Stripes.Count; s++) { for (int t = 0; t < component.Stripes[s].SurfaceAtLoop.Length; t++) { All_StripeBreps.Add(component.Stripes[s].SurfaceAtLoop[t], pth1.AppendElement(s)); } //for (int u = 0; u < component.Stripes[s].IntersectionCurve.Length; u++) //{ All_StripeIntersectCrvs.Add(component.Stripes[s].IntersectionCurve[u], pth1.AppendElement(s));} All_StripeIntersectPlane.Add(component.Stripes[s].IntersectionPlane, pth1.AppendElement(s)); } // ====================================================================================================== // Gene Added for (int s = 0; s < component.StripesSingle.Count; s++) { All_SingleStripeBreps.Add(component.StripesSingle[s].loop, pth1.AppendElement(s)); //for (int u = 0; u < component.Stripes[s].IntersectionCurve.Length; u++) //{ All_StripeIntersectCrvs.Add(component.Stripes[s].IntersectionCurve[u], pth1.AppendElement(s));} //All_StripeIntersectPlane.Add(component.StripesSingle[s].IntersectionPlane, pth1.AppendElement(s)); } // ====================================================================================================== componentIdx++; } //---- End Functions ------------------------------------------------------------------------ //---- Set Output --------------------------------------------------------------------------- DA.SetDataTree(0, All_CentrePointsL01); DA.SetDataTree(1, All_CentrePointsL02); DA.SetDataTree(2, All_Curves); DA.SetDataTree(3, All_PlateCrv); DA.SetDataTree(4, All_PentagonPts_L01); DA.SetDataTree(5, All_PentagonPts_L02); DA.SetDataTree(6, All_StripeIds); DA.SetDataTree(7, All_StripeBreps); DA.SetDataTree(8, All_StripeIntersectPlane); //// ======================================================================================= // Added by Gene DA.SetDataTree(9, All_ExtendedCurves); DA.SetDataTree(10, All_SingleStripeBreps); //// ======================================================================================= //---- End Set Output ----------------------------------------------------------------------- }
public void SofistikInformation_Version2() { GH_Path pthPlanarL01 = new GH_Path(0); GH_Path pthPlanarL02 = new GH_Path(1); GH_Path pthLoop00 = new GH_Path(2); GH_Path pthLoop01 = new GH_Path(3); GH_Path pthLoop02 = new GH_Path(4); #region Sofistik Points for (int i = 0; i < 3; i++) { //planar Part Points L01 AllSofistikPoints.Add(RightfromCenterL01[i], pthPlanarL01); SofistikIndexies.Add(i + 0 + (i * 2), pthPlanarL01); AllSofistikPoints.Add(CentersL01[i], pthPlanarL01); SofistikIndexies.Add(i + 1 + (i * 2), pthPlanarL01); AllSofistikPoints.Add(LeftfromCenterL01[i], pthPlanarL01); SofistikIndexies.Add(i + 2 + (i * 2), pthPlanarL01); //planar Part Points L02 AllSofistikPoints.Add(RightfromCenterL02[i], pthPlanarL02); SofistikIndexies.Add(i + 10 + (i * 2), pthPlanarL02); AllSofistikPoints.Add(CentersL02[i], pthPlanarL02); SofistikIndexies.Add(i + 11 + (i * 2), pthPlanarL02); AllSofistikPoints.Add(LeftfromCenterL02[i], pthPlanarL02); SofistikIndexies.Add(i + 12 + (i * 2), pthPlanarL02); #region Sofistik Plate //---- Sofistik Plate Curves --------------------------------------------------------------------------- //planar Part Points L01 SofistikPlatePoints.Add(RightfromCenterL01[i], pthPlanarL01); SofistikPlateIndexies.Add(i + 0 + (i * 2), pthPlanarL01); SofistikPlatePoints.Add(CentersL01[i], pthPlanarL01); SofistikPlateIndexies.Add(i + 1 + (i * 2), pthPlanarL01); SofistikPlatePoints.Add(LeftfromCenterL01[i], pthPlanarL01); SofistikPlateIndexies.Add(i + 2 + (i * 2), pthPlanarL01); //planar Part Points L02 SofistikPlatePoints.Add(RightfromCenterL02[i], pthPlanarL02); SofistikPlateIndexies.Add(i + 10 + (i * 2), pthPlanarL02); SofistikPlatePoints.Add(CentersL02[i], pthPlanarL02); SofistikPlateIndexies.Add(i + 11 + (i * 2), pthPlanarL02); SofistikPlatePoints.Add(LeftfromCenterL02[i], pthPlanarL02); SofistikPlateIndexies.Add(i + 12 + (i * 2), pthPlanarL02); #endregion Sofistik Plate } for (int i = 0; i < 3; i++) { int counter = 0; foreach (Curve c in Curves.Branch(i)) { AllSofistikPoints.Add(c.PointAtNormalizedLength(0.0), new GH_Path(i + 2)); // check for corresponding point index for (int k = 0; k < AllSofistikPoints.Branch(0).Count; k++) { if ((Math.Abs(c.PointAtNormalizedLength(0.0).X - AllSofistikPoints.Branch(0)[k].X) < 0.001) && (Math.Abs(c.PointAtNormalizedLength(0.0).Y - AllSofistikPoints.Branch(0)[k].Y) < 0.001)) { SofistikIndexies.Add(SofistikIndexies.Branch(0)[k], new GH_Path(i + 2)); } } //AllSofistikPoints.Add(c.PointAtNormalizedLength(0.5), new GH_Path(i + 2)); // check for corresponding point index //SofistikIndexies.Add(i * 2 + counter + 20, new GH_Path(i + 2)); AllSofistikPoints.Add(c.PointAtNormalizedLength(1.0), new GH_Path(i + 2)); // check for corresponding point index for (int k = 0; k < AllSofistikPoints.Branch(1).Count; k++) { if ((Math.Abs(c.PointAtNormalizedLength(1.0).X - AllSofistikPoints.Branch(1)[k].X) < 0.001) && (Math.Abs(c.PointAtNormalizedLength(1.0).Y - AllSofistikPoints.Branch(1)[k].Y) < 0.001)) { SofistikIndexies.Add(SofistikIndexies.Branch(1)[k], new GH_Path(i + 2)); } } counter++; } } #endregion Sofistik Points #region Sofistik Curves // planar Curves //L01 #region L01 for (int i = 0; i < AllSofistikPoints.Branch(0).Count; i++) { if (i < AllSofistikPoints.Branch(0).Count - 1) { GH_Path p = new GH_Path(0); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(0)[i], p); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(0)[i + 1], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(0)[i], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(0)[i + 1], p); } else { GH_Path p = new GH_Path(0); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(0)[i], p); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(0)[0], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(0)[i], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(0)[0], p); } } #endregion L01 //L02 #region L02 for (int i = 0; i < AllSofistikPoints.Branch(1).Count; i++) { if (i < AllSofistikPoints.Branch(1).Count - 1) { GH_Path p = new GH_Path(1); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(1)[i], p); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(1)[i + 1], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(1)[i], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(1)[i + 1], p); } else { GH_Path p = new GH_Path(1); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(1)[i], p); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(1)[0], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(1)[i], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(1)[0], p); } } #endregion L02 //Curves A #region Crv A for (int i = 0; i < AllSofistikPoints.Branch(2).Count; i++) { if (i < AllSofistikPoints.Branch(2).Count * 0.5) { // Left Curve GH_Path p = new GH_Path(2); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(2)[i], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(2)[i], p); } else { // Right Curve GH_Path p = new GH_Path(2); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(2)[i], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(2)[i], p); } } #endregion Crv A //Curves B #region Crv B for (int i = 0; i < AllSofistikPoints.Branch(3).Count; i++) { if (i < AllSofistikPoints.Branch(3).Count * 0.5) { // Left Curve GH_Path p = new GH_Path(3); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(3)[i], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(3)[i], p); } else { // Right Curve GH_Path p = new GH_Path(3); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(3)[i], p); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(3)[i], p); } } #endregion Crv B //Curves C #region Crv C for (int i = 0; i < AllSofistikPoints.Branch(4).Count; i++) { if (i < AllSofistikPoints.Branch(4).Count * 0.5) { // Left Curve GH_Path p = new GH_Path(4); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(4)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(4)[i], new GH_Path(p)); } else { // Right Curve GH_Path p = new GH_Path(4); p.AppendElement(i); SofistikCrvPtIdx.Add(SofistikIndexies.Branch(4)[i], new GH_Path(p)); SofistikCrvPtCoo.Add(AllSofistikPoints.Branch(4)[i], new GH_Path(p)); } } #endregion Crv C //Curves AL-BR #region AL-BR // adds te planar curves at the top and bottum of the bended curves in order to close the boundary curves of th surface GH_Path albr = new GH_Path(2); // i takes the start points and the endpoints of the bended curves and puts them in a branch //L01 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(albr.AppendElement(0))[0], albr.AppendElement(2)); // start point of first bended curve in path {2;0} element idx [0] SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(albr.AppendElement(1))[0], albr.AppendElement(2)); // start point of second bended curve in path {2;1} element idx [0] // stores it in path {2;2} SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(albr.AppendElement(0))[0], albr.AppendElement(2)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(albr.AppendElement(1))[0], albr.AppendElement(2)); //L02 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(albr.AppendElement(0))[1], albr.AppendElement(3)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(albr.AppendElement(1))[1], albr.AppendElement(3)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(albr.AppendElement(0))[1], albr.AppendElement(3)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(albr.AppendElement(1))[1], albr.AppendElement(3)); #endregion AL-BR //Curves BL-CR #region BL-CR GH_Path blcr = new GH_Path(3); //L01 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(blcr.AppendElement(0))[0], blcr.AppendElement(2)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(blcr.AppendElement(1))[0], blcr.AppendElement(2)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(blcr.AppendElement(0))[0], blcr.AppendElement(2)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(blcr.AppendElement(1))[0], blcr.AppendElement(2)); //L02 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(blcr.AppendElement(0))[1], blcr.AppendElement(3)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(blcr.AppendElement(1))[1], blcr.AppendElement(3)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(blcr.AppendElement(0))[1], blcr.AppendElement(3)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(blcr.AppendElement(1))[1], blcr.AppendElement(3)); #endregion BL-CR //Curves CL-AR #region CL-AR GH_Path clar = new GH_Path(4); //L01 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(clar.AppendElement(0))[0], clar.AppendElement(2)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(clar.AppendElement(1))[0], clar.AppendElement(2)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(clar.AppendElement(0))[0], clar.AppendElement(2)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(clar.AppendElement(1))[0], clar.AppendElement(2)); //L02 SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(clar.AppendElement(0))[1], clar.AppendElement(3)); SofistikCrvPtCoo.Add(SofistikCrvPtCoo.Branch(clar.AppendElement(1))[1], clar.AppendElement(3)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(clar.AppendElement(0))[1], clar.AppendElement(3)); SofistikCrvPtIdx.Add(SofistikCrvPtIdx.Branch(clar.AppendElement(1))[1], clar.AppendElement(3)); #endregion CL-AR #endregion Sofistik Curves }
private void triLoop() { for (int tri = 0; tri < iSpringMesh.Triangles.Count; tri++) { GH_Path path = new GH_Path(tri); //oInfo += "path = " + path.ToString() + "\n"; Triangle triangle = iSpringMesh.Triangles[tri]; if (!iVertexStatus[triangle.FirstVertexIndex] && !iVertexStatus[triangle.SecondVertexIndex] && !iVertexStatus[triangle.ThirdVertexIndex]) { // ids oTriLoopID.Add("T;" + tri.ToString() + ";" + triangle.SecondAdjTriIndex.ToString() + ";" + triangle.ThirdAdjTriIndex.ToString(), path.AppendElement(0)); oTriLoopID.Add("T;" + tri.ToString() + ";" + triangle.ThirdAdjTriIndex.ToString() + ";" + triangle.FirstAdjTriIndex.ToString(), path.AppendElement(1)); oTriLoopID.Add("T;" + tri.ToString() + ";" + triangle.FirstAdjTriIndex.ToString() + ";" + triangle.SecondAdjTriIndex.ToString(), path.AppendElement(2)); // stripes createStripe(triangle.FirstVertexIndex, triangle.SecondVertexIndex, triangle.ThirdVertexIndex, path, 0); createStripe(triangle.SecondVertexIndex, triangle.ThirdVertexIndex, triangle.FirstVertexIndex, path, 1); createStripe(triangle.ThirdVertexIndex, triangle.FirstVertexIndex, triangle.SecondVertexIndex, path, 2); } } }
//// ======================================================================================= // Added by Gene public void Create_Stipe_SinSrf() { GH_Path pthA = new GH_Path(0); GH_Path pthB = new GH_Path(1); GH_Path pthC = new GH_Path(2); Tri_Loop_Stripe StripeAS = new Tri_Loop_Stripe( ExtendedCurves.Branch(pthA)[0], ExtendedCurves.Branch(pthA)[1], cuttingPoints.Branch(pthA)[0], documentTolerance); Tri_Loop_Stripe StripeBS = new Tri_Loop_Stripe( ExtendedCurves.Branch(pthB)[0], ExtendedCurves.Branch(pthB)[1], cuttingPoints.Branch(pthB)[0], documentTolerance); Tri_Loop_Stripe StripeCS = new Tri_Loop_Stripe( ExtendedCurves.Branch(pthC)[0], ExtendedCurves.Branch(pthC)[1], cuttingPoints.Branch(pthC)[0], documentTolerance); StripesSingle.Add(StripeAS); StripesSingle.Add(StripeBS); StripesSingle.Add(StripeCS); }
/// <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) { //---- Declareing --------------------------------------------------------------------------- List<Tri_Loop_Component> All_Components = new List<Tri_Loop_Component>(); DA.GetDataList<Tri_Loop_Component>("Components", All_Components); DataTree<Point3d> SofistikPoints = new DataTree<Point3d>(); DataTree<int> SofistikIndexies = new DataTree<int>(); DataTree<int> SofistikCrvPtIdx = new DataTree<int>(); DataTree<Point3d> SofistikCrvPtCoo = new DataTree<Point3d>(); DataTree<Brep> SofistikBreps = new DataTree<Brep>(); DataTree<int> SofistikBrepsIdx = new DataTree<int>(); DataTree<Curve> SofistikCurves = new DataTree<Curve>(); //---- End Declareing ----------------------------------------------------------------------- //---- Functions ---------------------------------------------------------------------------- int componentIdx = 0; foreach (Tri_Loop_Component component in All_Components) { GH_Path pth1 = new GH_Path(componentIdx); // run / generate Informations for Sofistik component.SofistikInformation(); component.SofistikCreateSurfaces(); // Points for (int j = 0; j < component.SofistikPlatePoints.BranchCount; j++) { foreach (Point3d p in component.SofistikPlatePoints.Branch(j)) { SofistikPoints.Add(p, pth1.AppendElement(j)); } foreach (int idx in component.SofistikPlateIndexies.Branch(j)) { SofistikIndexies.Add(idx, pth1.AppendElement(j)); } } // CurvePoints for (int j = 0; j < component.SofistikCrvPtCoo.BranchCount; j++) { GH_Path pth0 = component.SofistikCrvPtCoo.Path(j); foreach (Point3d pt in component.SofistikCrvPtCoo.Branch(j)) { //pth1.AppendElement(pth0[0]); //pth1.AppendElement(pth0[1]); //SofistikCrvPtCoo.Add(pt, pth1.AppendElement(pth0[0])); // 2 level Tree SofistikCrvPtCoo.Add(pt, pth1.AppendElement(pth0[0])); } foreach (int idx in component.SofistikCrvPtIdx.Branch(j)) { //pth1.AppendElement(pth0[0]); //pth1.AppendElement(pth0[1]); //SofistikCrvPtIdx.Add(idx, pth1.AppendElement(pth0[0])); // 2 level Tree SofistikCrvPtIdx.Add(idx, pth1.AppendElement(pth0[0])); } } // Curves for (int i = 0; i < component.SofistikCurves.BranchCount; i++) { GH_Path pth0 = component.SofistikCurves.Path(i); foreach (Curve c in component.SofistikCurves.Branch(i)) { SofistikCurves.Add(c, pth1.AppendElement(pth0[0])); } } // Surfaces for (int j = 0; j < component.SofistikSurfaces.BranchCount; j++) { foreach (Brep[] p in component.SofistikSurfaces.Branch(j)) { SofistikBreps.Add(p[0], pth1.AppendElement(j)); } foreach (int idx in component.SofistikSurfacesIdx.Branch(j)) { SofistikBrepsIdx.Add(idx, pth1.AppendElement(j)); } } componentIdx++; } //---- End Functions ------------------------------------------------------------------------ //---- Set Output --------------------------------------------------------------------------- DA.SetDataTree(0, SofistikPoints); DA.SetDataTree(1, SofistikIndexies); DA.SetDataTree(2, SofistikCrvPtCoo); DA.SetDataTree(3, SofistikCrvPtIdx); DA.SetDataTree(4, SofistikBreps); DA.SetDataTree(5, SofistikBrepsIdx); DA.SetDataTree(6, SofistikCurves); //---- End Set Output ----------------------------------------------------------------------- }
public void Create_Plate(List<bool> openclosed) { GH_Path pthA = new GH_Path(0); GH_Path pthB = new GH_Path(1); GH_Path pthC = new GH_Path(2); //---- Stripe A ----------------------------------------------------------------------------------------------------- if (openclosed[TopoPts[0]]) { List<Point3d> PlateL01Pts = new List<Point3d>() { CentersL01[0], PointsL01[0], CentersL01[2], CentersL01[0] }; Curve PlateL01 = Curve.CreateControlPointCurve(PlateL01Pts, 1); List<Point3d> PlateL02Pts = new List<Point3d>() { CentersL02[0], PointsL02[0], CentersL02[2], CentersL02[0] }; Curve PlateL02 = Curve.CreateControlPointCurve(PlateL02Pts, 1); // Curves PlateCrv.Add(PlateL01, pthA); PlateCrv.Add(PlateL02, pthA); // Control Points PlateCrvPts.Add(PlateL01Pts, pthA); PlateCrvPts.Add(PlateL02Pts, pthA); } else { // Curves PlateCrv.Add(null, pthA); PlateCrv.Add(null, pthA); // Control Points PlateCrvPts.Add(null, pthA); PlateCrvPts.Add(null, pthA); } //---- Stripe B ----------------------------------------------------------------------------------------------------- if (openclosed[TopoPts[1]]) { List<Point3d> PlateL01Pts = new List<Point3d>() { CentersL01[1], PointsL01[1], CentersL01[0], CentersL01[1] }; Curve PlateL01 = Curve.CreateControlPointCurve(PlateL01Pts, 1); List<Point3d> PlateL02Pts = new List<Point3d>() { CentersL02[1], PointsL02[1], CentersL02[0], CentersL02[1] }; Curve PlateL02 = Curve.CreateControlPointCurve(PlateL02Pts, 1); // Curves PlateCrv.Add(PlateL01, pthB); PlateCrv.Add(PlateL02, pthB); // Control Points PlateCrvPts.Add(PlateL01Pts, pthB); PlateCrvPts.Add(PlateL02Pts, pthB); } else { // Curves PlateCrv.Add(null, pthB); PlateCrv.Add(null, pthB); // Control Points PlateCrvPts.Add(null, pthB); PlateCrvPts.Add(null, pthB); } //---- Stripe C ----------------------------------------------------------------------------------------------------- if (openclosed[TopoPts[2]]) { List<Point3d> PlateL01Pts = new List<Point3d>() { CentersL01[2], PointsL01[2], CentersL01[1], CentersL01[2] }; Curve PlateL01 = Curve.CreateControlPointCurve(PlateL01Pts, 1); List<Point3d> PlateL02Pts = new List<Point3d>() { CentersL02[2], PointsL02[2], CentersL02[1], CentersL02[2] }; Curve PlateL02 = Curve.CreateControlPointCurve(PlateL02Pts, 1); // Curves PlateCrv.Add(PlateL01, pthC); PlateCrv.Add(PlateL02, pthC); // Control Points PlateCrvPts.Add(PlateL01Pts, pthC); PlateCrvPts.Add(PlateL02Pts, pthC); } else { // Curves PlateCrv.Add(null, pthC); PlateCrv.Add(null, pthC); // Control Points PlateCrvPts.Add(null, pthC); PlateCrvPts.Add(null, pthC); } }
protected override void SolveInstance(IGH_DataAccess da) { if (!GetInputs(da)) return; if (reset == true) { trailTree = new DataTree<Point3d>(); iter = 0; maxid = 0; } else { foreach (Amoeba amo in p.population) { GH_Path thispath = new GH_Path(amo.ID); if (amo.ID > maxid) { trailTree.Add(amo.prev_loc, thispath); maxid = amo.ID; } trailTree.Add(amo.Location, thispath); if (trailTree.Branch(thispath).Count > history) { trailTree.Branch(thispath).RemoveAt(0); } } foreach (int id in p._todie_id) { GH_Path thispath = new GH_Path(id); trailTree.Branch(thispath).Clear(); } iter++; } SetOutputs(da); }
public void Create_Curves(List<double> offsetvalue, List<double> controlpointvalue) { // Data tree path GH_Path pthA = new GH_Path(0); GH_Path pthB = new GH_Path(1); GH_Path pthC = new GH_Path(2); #region planar offset points // calculate the planar offset points (points offsetet from the centre points) // Side A left Point3d pOAL0 = offsetvalue[TopoPts[0]] * PointsL01[0] + CentersL01[0] * (1.0 - offsetvalue[TopoPts[0]]); Point3d pOAL1 = offsetvalue[TopoPts[0]] * PointsL02[0] + CentersL02[0] * (1.0 - offsetvalue[TopoPts[0]]); LeftfromCenterL01.Add(pOAL0); LeftfromCenterL02.Add(pOAL1); // Side A right Point3d pOAR0 = offsetvalue[TopoPts[1]] * PointsL01[1] + CentersL01[0] * (1.0 - offsetvalue[TopoPts[1]]); Point3d pOAR1 = offsetvalue[TopoPts[1]] * PointsL02[1] + CentersL02[0] * (1.0 - offsetvalue[TopoPts[1]]); RightfromCenterL01.Add(pOAR0); RightfromCenterL02.Add(pOAR1); // Side B left Point3d pOBL0 = offsetvalue[TopoPts[1]] * PointsL01[1] + CentersL01[1] * (1.0 - offsetvalue[TopoPts[1]]); Point3d pOBL1 = offsetvalue[TopoPts[1]] * PointsL02[1] + CentersL02[1] * (1.0 - offsetvalue[TopoPts[1]]); LeftfromCenterL01.Add(pOBL0); LeftfromCenterL02.Add(pOBL1); // Side B right Point3d pOBR0 = offsetvalue[TopoPts[2]] * PointsL01[2] + CentersL01[1] * (1.0 - offsetvalue[TopoPts[2]]); Point3d pOBR1 = offsetvalue[TopoPts[2]] * PointsL02[2] + CentersL02[1] * (1.0 - offsetvalue[TopoPts[2]]); RightfromCenterL01.Add(pOBR0); RightfromCenterL02.Add(pOBR1); // Side C left Point3d pOCL0 = offsetvalue[TopoPts[2]] * PointsL01[2] + CentersL01[2] * (1.0 - offsetvalue[TopoPts[2]]); Point3d pOCL1 = offsetvalue[TopoPts[2]] * PointsL02[2] + CentersL02[2] * (1.0 - offsetvalue[TopoPts[2]]); LeftfromCenterL01.Add(pOCL0); LeftfromCenterL02.Add(pOCL1); // Side C right Point3d pOCR0 = offsetvalue[TopoPts[0]] * PointsL01[0] + CentersL01[2] * (1.0 - offsetvalue[TopoPts[0]]); Point3d pOCR1 = offsetvalue[TopoPts[0]] * PointsL02[0] + CentersL02[2] * (1.0 - offsetvalue[TopoPts[0]]); RightfromCenterL01.Add(pOCR0); RightfromCenterL02.Add(pOCR1); #endregion planar offset points #region curve control points // calculate control points for curves // Side A left Point3d ctrlAL0 = controlpointvalue[TopoPts[0]] * PointsL01[0] + pOAL0 * (1.0 - controlpointvalue[TopoPts[0]]); Point3d ctrlAL1 = controlpointvalue[TopoPts[0]] * PointsL02[0] + pOAL1 * (1.0 - controlpointvalue[TopoPts[0]]); // Side A right Point3d ctrlAR0 = controlpointvalue[TopoPts[1]] * PointsL01[1] + pOAR0 * (1.0 - controlpointvalue[TopoPts[1]]); Point3d ctrlAR1 = controlpointvalue[TopoPts[1]] * PointsL02[1] + pOAR1 * (1.0 - controlpointvalue[TopoPts[1]]); // Side B left Point3d ctrlBL0 = controlpointvalue[TopoPts[1]] * PointsL01[1] + pOBL0 * (1.0 - controlpointvalue[TopoPts[1]]); Point3d ctrlBL1 = controlpointvalue[TopoPts[1]] * PointsL02[1] + pOBL1 * (1.0 - controlpointvalue[TopoPts[1]]); // Side B right Point3d ctrlBR0 = controlpointvalue[TopoPts[2]] * PointsL01[2] + pOBR0 * (1.0 - controlpointvalue[TopoPts[2]]); Point3d ctrlBR1 = controlpointvalue[TopoPts[2]] * PointsL02[2] + pOBR1 * (1.0 - controlpointvalue[TopoPts[2]]); // Side C left Point3d ctrlCL0 = controlpointvalue[TopoPts[2]] * PointsL01[2] + pOCL0 * (1.0 - controlpointvalue[TopoPts[2]]); Point3d ctrlCL1 = controlpointvalue[TopoPts[2]] * PointsL02[2] + pOCL1 * (1.0 - controlpointvalue[TopoPts[2]]); // Side C right Point3d ctrlCR0 = controlpointvalue[TopoPts[0]] * PointsL01[0] + pOCR0 * (1.0 - controlpointvalue[TopoPts[0]]); Point3d ctrlCR1 = controlpointvalue[TopoPts[0]] * PointsL02[0] + pOCR1 * (1.0 - controlpointvalue[TopoPts[0]]); #endregion curve control points #region add points to data tree // A Level 01 foreach (Point3d p in new List<Point3d>() { pOAL0, pOBR0, CentersL01[1], AreaCentreL01, CentersL01[0] }) { PlanarPentagonL01.Add(p, pthA); } // A Level 02 foreach (Point3d p in new List<Point3d>() { pOAL1, pOBR1, CentersL02[1], AreaCentreL02, CentersL02[0] }) { PlanarPentagonL02.Add(p, pthA); } // B Level 01 foreach (Point3d p in new List<Point3d>() { pOBL0, pOCR0, CentersL01[2], AreaCentreL01, CentersL01[1] }) { PlanarPentagonL01.Add(p, pthB); } // B Level 02 foreach (Point3d p in new List<Point3d>() { pOBL1, pOCR1, CentersL02[2], AreaCentreL02, CentersL02[1] }) { PlanarPentagonL02.Add(p, pthB); } // C Level 01 foreach (Point3d p in new List<Point3d>() { pOCL0, pOAR0, CentersL01[0], AreaCentreL01, CentersL01[2] }) { PlanarPentagonL01.Add(p, pthC); } // C Level 02 foreach (Point3d p in new List<Point3d>() { pOCL1, pOAR1, CentersL02[0], AreaCentreL02, CentersL02[2] }) { PlanarPentagonL02.Add(p, pthC); } #endregion add points to data tree #region curves //---- Create Curves --------------------------------------------------------- // Side A left List<Point3d> cALPts = new List<Point3d>() { pOAL0, ctrlAL0, ctrlAL1, pOAL1 }; Curve cAL = Curve.CreateControlPointCurve(cALPts); // Side A right List<Point3d> cARPts = new List<Point3d>() { pOAR0, ctrlAR0, ctrlAR1, pOAR1 }; Curve cAR = Curve.CreateControlPointCurve(cARPts); // Side B left List<Point3d> cBLPts = new List<Point3d>() { pOBL0, ctrlBL0, ctrlBL1, pOBL1 }; Curve cBL = Curve.CreateControlPointCurve(cBLPts); // Side B right List<Point3d> cBRPts = new List<Point3d>() { pOBR0, ctrlBR0, ctrlBR1, pOBR1 }; Curve cBR = Curve.CreateControlPointCurve(cBRPts); // Side C left List<Point3d> cCLPts = new List<Point3d>() { pOCL0, ctrlCL0, ctrlCL1, pOCL1 }; Curve cCL = Curve.CreateControlPointCurve(cCLPts); // Side C right List<Point3d> cCRPts = new List<Point3d>() { pOCR0, ctrlCR0, ctrlCR1, pOCR1 }; Curve cCR = Curve.CreateControlPointCurve(cCRPts); // Add to data trees #region Add to Trees // A Curves.Add(cAL, pthA); Curves.Add(cBR, pthA); CurvesPts.Add(cALPts, pthA); CurvesPts.Add(cBRPts, pthA); // B Curves.Add(cBL, pthB); Curves.Add(cCR, pthB); CurvesPts.Add(cBLPts, pthB); CurvesPts.Add(cCRPts, pthB); // C Curves.Add(cCL, pthC); Curves.Add(cAR, pthC); CurvesPts.Add(cCLPts, pthC); CurvesPts.Add(cARPts, pthC); // Create and Add StripeID StripeID.Add(ID, pthA); StripeID.Add(NFIdx[1], pthA); StripeID.Add(NFIdx[2], pthA); StripeID.Add(ID, pthB); StripeID.Add(NFIdx[2], pthB); StripeID.Add(NFIdx[0], pthB); StripeID.Add(ID, pthC); StripeID.Add(NFIdx[0], pthC); StripeID.Add(NFIdx[1], pthC); #endregion Add to Trees #endregion curves //// ======================================================================================= // Added by Gene #region extended Curves //---- Create Extended Curves --- Join Curve with Line ------------------------------------- // Side A left Curve ecAL = Curve.JoinCurves(new List<Curve>() { new LineCurve(PointsL01[0], pOAL0), cAL, new LineCurve(pOAL1, PointsL02[0]) }, documentTolerance, true)[0]; // Side A right Curve ecAR = Curve.JoinCurves(new List<Curve>() { new LineCurve(PointsL01[1], pOAR0), cAR, new LineCurve(pOAR1, PointsL02[1]) }, documentTolerance, true)[0]; // Side B left Curve ecBL = Curve.JoinCurves(new List<Curve>() { new LineCurve(PointsL01[1], pOBL0), cBL, new LineCurve(pOBL1, PointsL02[1]) }, documentTolerance, true)[0]; // Side B right Curve ecBR = Curve.JoinCurves(new List<Curve>() { new LineCurve(PointsL01[2], pOBR0), cBR, new LineCurve(pOBR1, PointsL02[2]) }, documentTolerance, true)[0]; // Side C left Curve ecCL = Curve.JoinCurves(new List<Curve>() { new LineCurve(PointsL01[2], pOCL0), cCL, new LineCurve(pOCL1, PointsL02[2]) }, documentTolerance, true)[0]; // Side C right Curve ecCR = Curve.JoinCurves(new List<Curve>() { new LineCurve(PointsL01[0], pOCR0), cCR, new LineCurve(pOCR1, PointsL02[0]) }, documentTolerance, true)[0]; // A' cutting points List<Point3d> cuttingA = new List<Point3d>() { AreaCentreL01, AreaCentreL02, (pOAR0+pOAL0)*0.5, (pOAR1+pOAL1)*0.5, (pOBR0+pOBL0)*0.5, (pOBR1+pOBL1)*0.5, PointsL01[1], PointsL02[1] }; // B' cutting points List<Point3d> cuttingB = new List<Point3d>() { AreaCentreL01, AreaCentreL02, (pOBR0+pOBL0)*0.5, (pOBR1+pOBL1)*0.5, (pOCR0+pOCL0)*0.5, (pOCR1+pOCL1)*0.5, PointsL01[2], PointsL02[2] }; // C' cutting points List<Point3d> cuttingC = new List<Point3d>() { AreaCentreL01, AreaCentreL02, (pOCR0+pOCL0)*0.5, (pOCR1+pOCL1)*0.5, (pOAR0+pOAL0)*0.5, (pOAR1+pOAL1)*0.5, PointsL01[0], PointsL02[0] }; // Add to data trees #region Add to Trees // A' ExtendedCurves.Add(ecAL, pthA); ExtendedCurves.Add(ecBR, pthA); cuttingPoints.Add(cuttingA, pthA); // B' ExtendedCurves.Add(ecBL, pthB); ExtendedCurves.Add(ecCR, pthB); cuttingPoints.Add(cuttingB, pthB); // C' ExtendedCurves.Add(ecCL, pthC); ExtendedCurves.Add(ecAR, pthC); cuttingPoints.Add(cuttingC, pthC); #endregion Add to Trees #endregion extended Curves //// ======================================================================================= }
protected override void SolveInstance(IGH_DataAccess DA) { //declare input variables to load into AuthToken authToken = new AuthToken(); string sheetName = ""; string worksheet = ""; bool includeBlankCells = false; bool rangeSpecified = false; SpreadsheetRange range = new SpreadsheetRange(); bool rowsColumns = false; bool formulasValues = false; //declare output variables List<string> metaData = new List<string>(); GH_Structure<GH_String> values = new GH_Structure<GH_String>(); GH_Structure<GH_String> addresses = new GH_Structure<GH_String>(); //get data from inputs if (!DA.GetData<AuthToken>("Token", ref authToken)) { return; //exit if no token } if (!authToken.IsValid) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The provided authentication token appears to be invalid. Try re-running the Google Authenticator component."); return; //exit if invalid token } if (!DA.GetData<string>("Name", ref sheetName)) { return; //exit if no name provided } DA.GetData<string>("Worksheet", ref worksheet); DA.GetData<bool>("Include Blank Cells?", ref includeBlankCells); if (DA.GetData<SpreadsheetRange>("Spreadsheet Range", ref range)) { rangeSpecified = true; } DA.GetData<bool>("Organize by Rows or Columns", ref rowsColumns); DA.GetData<bool>("Read Formulas or Values", ref formulasValues); //set up oAuth parameters OAuth2Parameters parameters = GDriveUtil.GetParameters(authToken); //establish spreadsheetservice SpreadsheetsService service = GDriveUtil.GetSpreadsheetsService(parameters); //get spreadsheet by name SpreadsheetEntry spreadsheet = GDriveUtil.findSpreadsheetByName(sheetName, service); if (spreadsheet == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified Spreadsheet not found."); return; } //gather spreadsheet metadata metaData.Add("Spreadsheet Name: " + spreadsheet.Title.Text); metaData.Add("Last Updated: " + spreadsheet.Updated.ToString()); metaData.Add("Worksheets: " + worksheetList(spreadsheet.Worksheets)); //find the specified worksheet, or first one if none specified WorksheetEntry worksheetEntry = null; worksheetEntry = GDriveUtil.findWorksheetByName(worksheet, spreadsheet); if (worksheetEntry == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Specified worksheet not found."); return; } // Fetch the cell feed of the worksheet. CellQuery cellQuery = new CellQuery(worksheetEntry.CellFeedLink); if (rangeSpecified) { if (range.TestValid()) { cellQuery.MinimumColumn = range.startColumn(); cellQuery.MinimumRow = range.startRow(); cellQuery.MaximumColumn = range.endColumn(); cellQuery.MaximumRow = range.endRow(); } else { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid Range Specified"); return; } } //passes null values if user wants the blank cells represented, otherwise they are omitted from output. if (includeBlankCells) { cellQuery.ReturnEmpty = ReturnEmptyCells.yes; } //set up cell feed CellFeed cellFeed = service.Query(cellQuery); foreach (CellEntry cell in cellFeed.Entries) //for all the cells in the feed { GH_Path path = new GH_Path(DA.Iteration); //set up data path for data tree uint e = (rowsColumns) ? cell.Row : cell.Column; //decide whether to structure data path by row or column path = path.AppendElement((int)e); string v = (formulasValues) ? cell.InputValue : cell.Value; //decide whether to get the cell formula or the cell value as output values.Append(new GH_String(v), path); //save the value of the cell addresses.Append(new GH_String(cell.Title.Text), path); // save the address of the cell } //set output data DA.SetDataTree(0, values); DA.SetDataTree(1, addresses); DA.SetDataList("Sheet Info", metaData); }
public virtual void SetParamPointCapsure(string NickName, IEnumerable<Point3d> pts) { GH_Document ghdoc = Grasshopper.Instances.ActiveCanvas.Document; List<IGH_ActiveObject> aos = ghdoc.ActiveObjects(); for (int i = 0; i < aos.Count; i++) { IGH_ActiveObject ao = aos[i]; Print("Type==> " + ao.Name); if (ao.Name == "Point") { Param_Point comp = (Param_Point)ao; Print("Name==> " + comp.NickName); if (ao.NickName == NickName) { GH_Path path = new GH_Path(1); comp.AddVolatileDataList(path, pts); } } } }
/// <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) { //----Declareing-------------------------------------------------------------------------- // contains the 3 points of each face DataTree<Point3f> facePoints = new DataTree<Point3f>(); // contains the coresponding topology points of each face DataTree<int> faceTopologyPoints = new DataTree<int>(); // contains the face normals of each face List<Vector3f> faceNormals = new List<Vector3f>(); // contains the 3 topology edges of each face DataTree<int> faceTopoEdgesIdx = new DataTree<int>(); // contains the points of each topology edge DataTree<int> topologyEdgesTopPtsIdx = new DataTree<int>(); // Contains the coordinates of each topology point List<Point3d> topologyPoints = new List<Point3d>(); // Contains the index of neighbouring faces for each face DataTree<int> faceNeighbours = new DataTree<int>(); // Contains Normals of topology vertices List<Vector3d> topologyNormals = new List<Vector3d>(); // Contains the index of topology Edges for each Topology Point DataTree<int> TopPt_Connected_TopEdges = new DataTree<int>(); //get Mesh from input Mesh M = new Mesh(); DA.GetData<Mesh>("Mesh", ref M); //----End Declareing----------------------------------------------------------------------- //----Functions------------------------------------------------------------------------------ // get List with sublist of 3 points per face for (int face_id = 0; face_id < M.Faces.Count; face_id++) { // set up the branch index GH_Path pth = new GH_Path(face_id); # region FacePoints //---- Face Points (Point3f) Point3f A, B, C, D; M.Faces.GetFaceVertices(face_id, out A, out B, out C, out D); facePoints.Add(A, pth); facePoints.Add(B, pth); facePoints.Add(C, pth); #endregion FacePoints #region FaceNormals //---- Face Normals (Vector3f) M.FaceNormals.ComputeFaceNormals(); faceNormals.Add(M.FaceNormals[face_id]); #endregion FaceNormals #region faceTopologyPoints //---- Topology Points of the face (int) int TA = M.Faces.GetTopologicalVertices(face_id)[0]; int TB = M.Faces.GetTopologicalVertices(face_id)[1]; int TC = M.Faces.GetTopologicalVertices(face_id)[2]; faceTopologyPoints.Add(TA, pth); faceTopologyPoints.Add(TB, pth); faceTopologyPoints.Add(TC, pth); #endregion faceTopologyPoints #region faceNeighbours //---- Neighbours of face (int) foreach (int i in M.TopologyEdges.GetEdgesForFace(face_id)) { if (M.TopologyEdges.GetConnectedFaces(i).Length > 1) { foreach (int j in M.TopologyEdges.GetConnectedFaces(i)) { if (j != face_id) { faceNeighbours.Add(j, pth); } } } else { faceNeighbours.Add(-1, pth); } } #endregion faceNeighbours #region Face Topology Edges //---- Topology Edges (int) foreach (int i in M.TopologyEdges.GetEdgesForFace(face_id)) { faceTopoEdgesIdx.Add(i, pth); } #endregion Face Topology Edges } for (int i = 0; i < M.TopologyVertices.Count; i++) { #region topologyPoints //---- Topology Points (point3f) int[] vertIdx = M.TopologyVertices.MeshVertexIndices(i); topologyPoints.Add(M.Vertices[vertIdx[0]]); #endregion topologyPoints #region topologyNormals //---- Topology Normals M.FaceNormals.ComputeFaceNormals(); Vector3d normal = new Vector3d(0, 0, 0); int count = 0; foreach (int face in M.TopologyVertices.ConnectedFaces(i)) { Vector3f temp = new Vector3f(); temp = M.FaceNormals[face]; Vector3d temp2 = new Vector3d(temp.X, temp.Y, temp.Z); normal += temp2; count++; } normal /= count; topologyNormals.Add(normal); #endregion topologyNormals } #region Topology Edges for (int i = 0; i < M.TopologyEdges.Count; i++) { topologyEdgesTopPtsIdx.Add(M.TopologyEdges.GetTopologyVertices(i).I, new GH_Path(i)); topologyEdgesTopPtsIdx.Add(M.TopologyEdges.GetTopologyVertices(i).J, new GH_Path(i)); } #endregion Topology Edges #region Topology Vertex connected Topology Edge for (int i = 0; i < topologyPoints.Count; i++) { // i = index of Topology Point GH_Path pth = new GH_Path(i); for (int j = 0; j < topologyEdgesTopPtsIdx.BranchCount; j++) { // j = index of Topology Edge foreach (int k in topologyEdgesTopPtsIdx.Branch(j)) { if (k == i) // add multiple Topology Edges to the branch index, which is representing the topology point index { TopPt_Connected_TopEdges.Add(j, pth); } } } } #endregion Topology Vertex connected Topology Edge //----End Functions-------------------------------------------------------------------------- //----Set Output----------------------------------------------------------------------------- DA.SetDataTree(0, facePoints); DA.SetDataTree(1, faceTopologyPoints); DA.SetDataList(2, faceNormals); DA.SetDataTree(3, faceNeighbours); DA.SetDataList(4, topologyPoints); DA.SetDataList(5, topologyNormals); DA.SetDataTree(6, faceTopoEdgesIdx); DA.SetDataTree(7, topologyEdgesTopPtsIdx); DA.SetDataTree(8, TopPt_Connected_TopEdges); //----End Set Output------------------------------------------------------------------------- }
/// <summary> /// Morphs cell topology to UVWI node map (morphed struts). /// </summary> public void MorphMapping(UnitCell cell, DataTree<GeometryBase> spaceTree, float[] N) { for (int u = 0; u <= N[0]; u++) { for (int v = 0; v <= N[1]; v++) { for (int w = 0; w <= N[2]; w++) { // We're inside a unit cell // Loop through all pairs of nodes that make up struts foreach (IndexPair nodePair in cell.NodePairs) { // Prepare the path of the nodes (path in tree) // First, get relative paths of nodes (with respect to current unit cell) int[] IRel = cell.NodePaths[nodePair.I]; int[] JRel = cell.NodePaths[nodePair.J]; // Next, compute absolute paths GH_Path IPath = new GH_Path(u + IRel[0], v + IRel[1], w + IRel[2]); GH_Path JPath = new GH_Path(u + JRel[0], v + JRel[1], w + JRel[2]); // Make sure the cell exists // No cells exist beyond the boundary + 1 if (Nodes.PathExists(IPath) && Nodes.PathExists(JPath)) { LatticeNode node1 = Nodes[IPath, IRel[3]]; LatticeNode node2 = Nodes[JPath, JRel[3]]; // Make sure both nodes exist: // Null nodes either belong to other cells, or are beyond the upper uvw boundary. if (node1 != null && node2 != null) { GH_Path spacePath; // If strut is along boundary, we must use the previous morph space // Since one does not exist beyond the boundary) if (u == N[0] && v == N[1]) { spacePath = new GH_Path(u - 1, v - 1); } else if (u == N[0]) { spacePath = new GH_Path(u - 1, v); } else if (v == N[1]) { spacePath = new GH_Path(u, v - 1); } else { spacePath = new GH_Path(u, v); } // Retrieve uv cell space (will be casted in the tempPt loop) GeometryBase ss1 = spaceTree[spacePath, 0]; GeometryBase ss2 = spaceTree[spacePath, 1]; // Discretize the unit cell line for morph mapping int ptCount = 16; // Template points are unitized cell points (x,y of these points are u,v of sub-surface) var templatePts = new List<Point3d>(); Line templateLine = new Line(cell.Nodes[nodePair.I], cell.Nodes[nodePair.J]); for (int ptIndex = 0; ptIndex <= ptCount; ptIndex++) { templatePts.Add(templateLine.PointAt(ptIndex / (double)ptCount)); } // We will map the lines' points to its uvw cell-space // Control points are the interpolation points in space var controlPoints = new List<Point3d>(); foreach (Point3d tempPt in templatePts) { Point3d surfPt; Vector3d[] surfDerivs; // UV params on unitized sub-surface are simply the xy coordinate of the template point double uParam = tempPt.X; double vParam = tempPt.Y; // If at boundary, we're using a previous morph space, so reverse the parameter(s) if (u == N[0]) { uParam = 1 - uParam; } if (v == N[1]) { vParam = 1 - vParam; } // Now, we will map the template point to the uvw-space ((Surface)ss1).Evaluate(uParam, vParam, 0, out surfPt, out surfDerivs); Vector3d wVect = Vector3d.Unset; switch (ss2.ObjectType) { case ObjectType.Point: wVect = ((Point)ss2).Location - surfPt; ; break; case ObjectType.Curve: wVect = ((Curve)ss2).PointAt(uParam) - surfPt; break; case ObjectType.Surface: Point3d surfPt2; Vector3d[] surfDerivs2; ((Surface)ss2).Evaluate(uParam, vParam, 0, out surfPt2, out surfDerivs2); wVect = surfPt2 - surfPt; break; } // The mapped point Point3d uvwPt = surfPt + wVect * (w + tempPt.Z) / N[2]; controlPoints.Add(uvwPt); } // Now create interpolated curve based on control points Curve curve = Curve.CreateInterpolatedCurve(controlPoints, 3); if (curve != null && curve.IsValid) { Struts.Add(curve); } } } } } } } }
/// <summary> /// Maps cell topology to the node grid and trims to the design space. /// </summary> public void UniformMapping(UnitCell cell, GeometryBase designSpace, int spaceType, float[] N, double minStrutLength, double maxStrutLength) { double tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance; for (int u = 0; u <= N[0]; u++) { for (int v = 0; v <= N[1]; v++) { for (int w = 0; w <= N[2]; w++) { // We're inside a unit cell // Loop through all pairs of nodes that make up struts foreach (IndexPair nodePair in cell.NodePairs) { // Prepare the path of the nodes (path in tree) // First, get relative paths of nodes (with respect to current unit cell) int[] IRel = cell.NodePaths[nodePair.I]; int[] JRel = cell.NodePaths[nodePair.J]; // Next, compute absolute paths GH_Path IPath = new GH_Path(u + IRel[0], v + IRel[1], w + IRel[2]); GH_Path JPath = new GH_Path(u + JRel[0], v + JRel[1], w + JRel[2]); // Make sure the cell exists if (Nodes.PathExists(IPath) && Nodes.PathExists(JPath)) { LatticeNode node1 = Nodes[IPath, IRel[3]]; LatticeNode node2 = Nodes[JPath, JRel[3]]; // Make sure both nodes exist: // Null nodes either belong to other cells, or are beyond the upper uvw boundary if (node1 != null && node2 != null) { Curve fullCurve = new LineCurve(node1.Point3d, node2.Point3d); // If both nodes are inside, add full strut if (node1.IsInside && node2.IsInside) { Struts.Add(fullCurve); } // If neither node is inside, skip to next loop else if (!node1.IsInside && !node2.IsInside) { continue; } // Else, strut requires trimming else { // We are going to find the intersection point with the design space Point3d[] intersectionPts = null; Curve[] overlapCurves = null; LineCurve strutToTrim = null; switch (spaceType) { // Brep design space case 1: strutToTrim = new LineCurve(node1.Point3d, node2.Point3d); // Find intersection point Intersection.CurveBrep(strutToTrim, (Brep)designSpace, tol, out overlapCurves, out intersectionPts); break; // Mesh design space case 2: // Dummy faceIds variable for MeshLine call int[] faceIds; strutToTrim = new LineCurve(node1.Point3d, node2.Point3d); // Find intersection point intersectionPts = Intersection.MeshLine((Mesh)designSpace, strutToTrim.Line, out faceIds); break; // Solid surface design space case 3: // Dummy overlapCurves variable for CurveBrep call overlapCurves = null; strutToTrim = new LineCurve(node1.Point3d, node2.Point3d); // Find intersection point Intersection.CurveBrep(strutToTrim, ((Surface)designSpace).ToBrep(), tol, out overlapCurves, out intersectionPts); break; } LineCurve testLine = null; // Now, if an intersection point was found, trim the strut if (intersectionPts.Length > 0) { testLine = AddTrimmedStrut(node1, node2, intersectionPts[0], minStrutLength, maxStrutLength); // If the strut was succesfully trimmed, add it to the list if (testLine != null) { Struts.Add(testLine); } } else if (overlapCurves != null && overlapCurves.Length > 0) { Struts.Add(overlapCurves[0]); } } } } } } } } }
/// <summary> /// Maps cell topology to UVWi node map (linear struts). /// </summary> public void ConformMapping(UnitCell cell, float[] N) { for (int u = 0; u <= N[0]; u++) { for (int v = 0; v <= N[1]; v++) { for (int w = 0; w <= N[2]; w++) { // We're inside a unit cell // Loop through all pairs of nodes that make up struts foreach (IndexPair nodePair in cell.NodePairs) { // Prepare the path of the nodes (path in tree) // First, get relative paths of nodes (with respect to current unit cell) int[] IRel = cell.NodePaths[nodePair.I]; int[] JRel = cell.NodePaths[nodePair.J]; // Next, compute absolute paths GH_Path IPath = new GH_Path(u + IRel[0], v + IRel[1], w + IRel[2]); GH_Path JPath = new GH_Path(u + JRel[0], v + JRel[1], w + JRel[2]); // Make sure the cell exists // No cells exist beyond the boundary + 1 if (Nodes.PathExists(IPath) && Nodes.PathExists(JPath)) { LatticeNode node1 = Nodes[IPath, IRel[3]]; LatticeNode node2 = Nodes[JPath, JRel[3]]; // Make sure both nodes exist: // Null nodes either belong to other cells, or are beyond the upper uvw boundary if (node1 != null && node2 != null) { LineCurve curve = new LineCurve(node1.Point3d, node2.Point3d); if (curve != null && curve.IsValid) { Struts.Add(curve); } } } } } } } }
/// <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) { // 1. Retrieve and validate inputs var cell = new UnitCell(); Surface s1 = null; Surface s2 = null; int nU = 0; int nV = 0; int nW = 0; bool morphed = false; if (!DA.GetData(0, ref cell)) { return; } if (!DA.GetData(1, ref s1)) { return; } if (!DA.GetData(2, ref s2)) { return; } if (!DA.GetData(3, ref nU)) { return; } if (!DA.GetData(4, ref nV)) { return; } if (!DA.GetData(5, ref nW)) { return; } if (!DA.GetData(6, ref morphed)) { return; } if (!cell.isValid) { return; } if (!s1.IsValid) { return; } if (!s2.IsValid) { return; } if (nU == 0) { return; } if (nV == 0) { return; } if (nW == 0) { return; } // 2. Initialize the lattice var lattice = new Lattice(); // Will contain the morphed uv spaces (as surface-surface) var spaceTree = new DataTree<GeometryBase>(); // 3. Package the number of cells in each direction into an array float[] N = new float[3] { nU, nV, nW }; // 4. Normalize the UV-domain Interval unitDomain = new Interval(0,1); s1.SetDomain(0, unitDomain); // s1 u-direction s1.SetDomain(1, unitDomain); // s1 v-direction s2.SetDomain(0, unitDomain); // s2 u-direction s2.SetDomain(1, unitDomain); // s2 v-direction // 5. Prepare cell (this is a UnitCell object) cell = cell.Duplicate(); cell.FormatTopology(); // 6. Map nodes to design space // Loop through the uvw cell grid for (int u = 0; u <= N[0]; u++) { for (int v = 0; v <= N[1]; v++) { for (int w = 0; w <= N[2]; w++) { // Construct cell path in tree GH_Path treePath = new GH_Path(u, v, w); // Fetch the list of nodes to append to, or initialise it var nodeList = lattice.Nodes.EnsurePath(treePath); // This loop maps each node in the cell onto the UV-surface maps for (int i = 0; i < cell.Nodes.Count; i++) { double usub = cell.Nodes[i].X; // u-position within unit cell (local) double vsub = cell.Nodes[i].Y; // v-position within unit cell (local) double wsub = cell.Nodes[i].Z; // w-position within unit cell (local) double[] uvw = { u + usub, v + vsub, w + wsub }; // uvw-position (global) // Check if the node belongs to another cell (i.e. it's relative path points outside the current cell) bool isOutsideCell = (cell.NodePaths[i][0] > 0 || cell.NodePaths[i][1] > 0 || cell.NodePaths[i][2] > 0); // Check if current uvw-position is beyond the upper boundary bool isOutsideSpace = (uvw[0] > N[0] || uvw[1] > N[1] || uvw[2] > N[2]); if (isOutsideCell || isOutsideSpace) { nodeList.Add(null); } else { // Initialize for surface 1 Point3d pt1; Vector3d[] derivatives1; // Initialize for surface 2 Point3d pt2; Vector3d[] derivatives2; // Evaluate point on both surfaces s1.Evaluate(uvw[0] / N[0], uvw[1] / N[1], 2, out pt1, out derivatives1); s2.Evaluate(uvw[0] / N[0], uvw[1] / N[1], 2, out pt2, out derivatives2); // Create vector joining the two points (this is our w-range) Vector3d wVect = pt2 - pt1; // Create the node, accounting for the position along the w-direction var newNode = new LatticeNode(pt1 + wVect * uvw[2] / N[2]); // Add node to tree nodeList.Add(newNode); } } } // Define the uv space tree (used for morphing) if (morphed && u < N[0] && v < N[1]) { GH_Path spacePath = new GH_Path(u, v); // Set trimming interval var uInterval = new Interval((u) / N[0], (u + 1) / N[0]); var vInterval = new Interval((v) / N[1], (v + 1) / N[1]); // Create sub-surfaces Surface ss1 = s1.Trim(uInterval, vInterval); Surface ss2 = s2.Trim(uInterval, vInterval); // Unitize domain ss1.SetDomain(0, unitDomain); ss1.SetDomain(1, unitDomain); ss2.SetDomain(0, unitDomain); ss2.SetDomain(1, unitDomain); // Save to the space tree spaceTree.Add(ss1, spacePath); spaceTree.Add(ss2, spacePath); } } } // 7. Map struts to the node tree if (morphed) lattice.MorphMapping(cell, spaceTree, N); else lattice.ConformMapping(cell, N); // 8. Set output DA.SetDataList(0, lattice.Struts); }
/// <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) { //---- Declareing --------------------------------------------------------------------------- GH_Structure<GH_Brep> AllStripes; DA.GetDataTree("Triloop Stipes", out AllStripes); GH_Structure<GH_Point> AllPoints; DA.GetDataTree("Points", out AllPoints); bool Reorient = false; DA.GetData<bool>("Merge Stripes", ref Reorient); bool Switch = false; DA.GetData<bool>("Switch", ref Switch); int Seam = 0; DA.GetData<int>("Seam", ref Seam); DataTree<Brep> AllUnrolledBreps = new DataTree<Brep>(); DataTree<Brep> ForReorientBreps = new DataTree<Brep>(); DataTree<Plane> AllOrientPlanes = new DataTree<Plane>(); DataTree<Curve> AllSharedCurves = new DataTree<Curve>(); DataTree<Point3d> AllUnrolledPoints = new DataTree<Point3d>(); //---- End Declareing ----------------------------------------------------------------------- //---- Functions ---------------------------------------------------------------------------- #region Unroll for (int i = 0; i < AllStripes.Branches.Count; i++) { GH_Path pth = new GH_Path(i); GH_Path originalPath = AllStripes.Paths[i]; int stripecounter = 0; foreach (GH_Brep gbrep in AllStripes[i]) { Unroller unroll = new Unroller(gbrep.Value); // Add points to unroll with if (AllPoints.Branches.Count != 0) { foreach (GH_Point pt in AllPoints[i]) { unroll.AddFollowingGeometry(pt.Value); } } unroll.ExplodeOutput = false; Curve[] curves; Point3d[] unrolledPoints; TextDot[] dots; Brep[] unrolledBreps = unroll.PerformUnroll(out curves, out unrolledPoints, out dots); if (Reorient == false) { foreach (Brep b in unrolledBreps) { AllUnrolledBreps.Add(b, originalPath); } foreach (Point3d p in unrolledPoints) { AllUnrolledPoints.Add(p, originalPath); } } else { foreach (Brep b in unrolledBreps) { AllUnrolledBreps.Add(b, pth.AppendElement(stripecounter)); } } // For reorientation if (Reorient == true) { ForReorientBreps.Add(unrolledBreps[Seam], pth); } stripecounter++; } } #endregion unroll if (Reorient == true) { //ForReorientBreps.Branch(0)[0].Curves3D[0].PointAtEnd; for (int i = 0; i < ForReorientBreps.BranchCount; i++) { GH_Path pth = new GH_Path(i); foreach (Curve crv0 in ForReorientBreps.Branch(i)[0].Curves3D) { foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D) { double l0 = crv0.GetLength(); double l1 = crv1.GetLength(); if (Math.Abs(l0 - l1) < 0.00001) { // orient crv0 Plane origin0 = new Plane(new Point3d(0, 0, 0), new Vector3d(1, 0, 0), new Vector3d(0, 1, 0)); Plane target0 = new Plane(origin0); AllOrientPlanes.Add(origin0, pth.AppendElement(0)); AllOrientPlanes.Add(target0, pth.AppendElement(0)); // orient crv1 Vector3d vect0 = crv1.TangentAtStart; Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0)); Plane origin1 = new Plane(crv1.PointAtStart, vect0, vect1); Vector3d vect2 = new Vector3d(); Vector3d vect3 = new Vector3d(); Plane target1 = new Plane(); if (Switch == true) { vect2 = crv0.TangentAtStart; vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0)); target1 = new Plane(crv0.PointAtStart, vect2, vect3); } else { vect2 = crv0.TangentAtStart; vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0)); target1 = new Plane(crv0.PointAtEnd, -vect2, vect3); } AllOrientPlanes.Add(origin1, pth.AppendElement(1)); AllOrientPlanes.Add(target1, pth.AppendElement(1)); // shared curve of stripe0 and stripe 1 AllSharedCurves.Add(crv0, pth.AppendElement(0)); AllSharedCurves.Add(crv1, pth.AppendElement(0)); } } // orient crv2 foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D) { double l0 = crv0.GetLength(); double l1 = crv2.GetLength(); if (Math.Abs(l0 - l1) < 0.00001) { Vector3d vect0 = crv2.TangentAtStart; Vector3d vect1 = Vector3d.CrossProduct(vect0, new Vector3d(0.0, 0.0, 1.0)); Plane origin2 = new Plane(crv2.PointAtStart, vect0, vect1); Vector3d vect2 = new Vector3d(); Vector3d vect3 = new Vector3d(); Plane target2 = new Plane(); if (Switch == true) { vect2 = crv0.TangentAtStart; vect3 = Vector3d.CrossProduct(vect2, new Vector3d(0.0, 0.0, 1.0)); target2 = new Plane(crv0.PointAtStart, vect2, vect3); } else { vect2 = crv0.TangentAtStart; vect3 = Vector3d.CrossProduct(-vect2, new Vector3d(0.0, 0.0, 1.0)); target2 = new Plane(crv0.PointAtEnd, -vect2, vect3); } AllOrientPlanes.Add(origin2, pth.AppendElement(2)); AllOrientPlanes.Add(target2, pth.AppendElement(2)); // shared curve of stripe0 and stripe 2 AllSharedCurves.Add(crv2, pth.AppendElement(2)); AllSharedCurves.Add(crv0, pth.AppendElement(2)); } } } // find the shared curve oft stripe 1 and stripe 2 foreach (Curve crv1 in ForReorientBreps.Branch(i)[1].Curves3D) { foreach (Curve crv2 in ForReorientBreps.Branch(i)[2].Curves3D) { double l1 = crv1.GetLength(); double l2 = crv2.GetLength(); // shared curve of stripe1 and stripe 2 if (Math.Abs(l1 - l2) < 0.00001) { AllSharedCurves.Add(crv1, pth.AppendElement(1)); AllSharedCurves.Add(crv2, pth.AppendElement(1)); } } } } } //---- End Functions -------------------------------------------------------------------------- //----Set Output------------------------------------------------------------------------------- DA.SetDataTree(0, AllUnrolledBreps); DA.SetDataTree(1, AllOrientPlanes); DA.SetDataTree(2, AllSharedCurves); DA.SetDataTree(3, AllUnrolledPoints); //----End Set Output--------------------------------------------------------------------------- }