protected override void SolveInstance(IGH_DataAccess DA) { string name = null; GH_RobotSystem robotSystem = null; var initCommandsGH = new List<GH_Command>(); var targetsA = new List<GH_Target>(); var targetsB = new List<GH_Target>(); var multiFileIndices = new List<int>(); double stepSize = 1; if (!DA.GetData(0, ref name)) { return; } if (!DA.GetData(1, ref robotSystem)) { return; } if (!DA.GetDataList(2, targetsA)) { return; } DA.GetDataList(3, targetsB); DA.GetDataList(4, initCommandsGH); DA.GetDataList(5, multiFileIndices); if (!DA.GetData(6, ref stepSize)) { return; } var initCommands = initCommandsGH.Count > 0 ? new Robots.Commands.Group(initCommandsGH.Select(x => x.Value)) : null; var targets = new List<IEnumerable<Target>>(); targets.Add(targetsA.Select(x => x.Value)); if (targetsB.Count > 0) targets.Add(targetsB.Select(x => x.Value)); var program = new Program(name, robotSystem.Value, targets, initCommands, multiFileIndices, stepSize); DA.SetData(0, new GH_Program(program)); if (program.Code != null) { var path = DA.ParameterTargetPath(2); var structure = new GH_Structure<GH_String>(); for (int i = 0; i < program.Code.Count; i++) { var tempPath = path.AppendElement(i); for (int j = 0; j < program.Code[i].Count; j++) { structure.AppendRange(program.Code[i][j].Select(x => new GH_String(x)), tempPath.AppendElement(j)); } } DA.SetDataTree(1, structure); } DA.SetData(2, program.Duration); if (program.Warnings.Count > 0) { DA.SetDataList(3, program.Warnings); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Warnings in program"); } if (program.Errors.Count > 0) { DA.SetDataList(4, program.Errors); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Errors in program"); } }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Program program = null; DA.GetData(0, ref program); var path = DA.ParameterTargetPath(0); var cellTargets = program.Value.Targets; var groupCount = cellTargets[0].ProgramTargets.Count; var planes = new GH_Structure<GH_Plane>(); var joints = new GH_Structure<GH_Number>(); var configuration = new GH_Structure<GH_String>(); var deltaTime = new GH_Structure<GH_Number>(); for (int i = 0; i < groupCount; i++) { var tempPath = path.AppendElement(i); for (int j = 0; j < cellTargets.Count; j++) { planes.AppendRange(cellTargets[j].ProgramTargets[i].Kinematics.Planes.Select(x => new GH_Plane(x)), tempPath.AppendElement(j)); joints.AppendRange(cellTargets[j].ProgramTargets[i].Kinematics.Joints.Select(x => new GH_Number(x)), tempPath.AppendElement(j)); configuration.Append(new GH_String(cellTargets[j].ProgramTargets[i].Kinematics.Configuration.ToString()), tempPath); deltaTime.Append(new GH_Number(cellTargets[j].DeltaTime), tempPath); } } DA.SetDataTree(0, planes); DA.SetDataTree(1, joints); DA.SetDataTree(2, configuration); DA.SetDataTree(3, deltaTime); }
/// <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 <GH_Number> joint = new GH_Structure <GH_Number>(); DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r); DA.GetDataTree("element_node_relationship(shell)", out GH_Structure <GH_Number> _ijkl); if (_r.Branches[0][0].Value != -9999 && _ijkl.Branches[0][0].Value != -9999) { var r = _r.Branches; var ijkl = _ijkl.Branches; var x = new List <double>(); DA.GetDataList("x coordinates of element center point", x); var y = new List <double>(); DA.GetDataList("y coordinates of element center point", y); var z = new List <double>(); DA.GetDataList("z coordinates of element center point", z); var ki = new List <double>(); DA.GetDataList("axial spring for node_i", ki); var kj = new List <double>(); DA.GetDataList("axial spring for node_j", kj); var ri = new List <double>(); DA.GetDataList("rotational spring for node_i", ri); var rj = new List <double>(); DA.GetDataList("rotational spring for node_j", rj); var kxi = ki[0]; var kyi = ki[1]; var kzi = ki[2]; var rxi = ri[0]; var ryi = ri[1]; var rzi = ri[2]; var kxj = kj[0]; var kyj = kj[1]; var kzj = kj[2]; var rxj = rj[0]; var ryj = rj[1]; var rzj = ri[2]; int k = 0; for (int j = 0; j < Math.Max(Math.Max(x.Count, y.Count), z.Count); j++) { for (int e = 0; e < ijkl.Count; e++) { var ni = (int)ijkl[e][0].Value; var nj = (int)ijkl[e][1].Value; var nk = (int)ijkl[e][2].Value; var nl = (int)ijkl[e][3].Value; var xi = r[ni][0].Value; var yi = r[ni][1].Value; var zi = r[ni][2].Value; var xj = r[nj][0].Value; var yj = r[nj][1].Value; var zj = r[nj][2].Value; var xk = r[nk][0].Value; var yk = r[nk][1].Value; var zk = r[nk][2].Value; var xc = 0.0; var yc = 0.0; var zc = 0.0; if (nl < 0) { xc = (xi + xj + xk) / 3.0; yc = (yi + yj + yk) / 3.0; zc = (zi + zj + zk) / 3.0; } else { var xl = r[nl][0].Value; var yl = r[nl][1].Value; var zl = r[nl][2].Value; xc = (xi + xj + xk + xl) / 4.0; yc = (yi + yj + yk + yl) / 4.0; zc = (zi + zj + zk + zl) / 4.0; } if (Math.Abs(xc - x[Math.Min(j, x.Count - 1)]) < 1e-8 || x[0] == -9999) { if (Math.Abs(yc - y[Math.Min(j, y.Count - 1)]) < 1e-8 || y[0] == -9999) { if (Math.Abs(zc - z[Math.Min(j, z.Count - 1)]) < 1e-8 || z[0] == -9999) { List <GH_Number> jlist = new List <GH_Number>(); jlist.Add(new GH_Number(e)); jlist.Add(new GH_Number(1000 * I + 100 * J + 10 * K + L)); jlist.Add(new GH_Number(kxi)); jlist.Add(new GH_Number(kyi)); jlist.Add(new GH_Number(kzi)); jlist.Add(new GH_Number(rxi)); jlist.Add(new GH_Number(ryi)); jlist.Add(new GH_Number(rzi)); jlist.Add(new GH_Number(kxj)); jlist.Add(new GH_Number(kyj)); jlist.Add(new GH_Number(kzj)); jlist.Add(new GH_Number(rxj)); jlist.Add(new GH_Number(ryj)); jlist.Add(new GH_Number(rzj)); joint.AppendRange(jlist, new GH_Path(k)); k += 1; } } } } } DA.SetDataTree(0, joint); } }///ここからGUIの作成*****************************************************************************************
protected override void SolveInstance(IGH_DataAccess DA) { int iterations = 0; var algorithm = new Boa_Algorithm(); var inputs = new double[0]; if (!GetInputs(DA, ref inputs)) { return; } if (!DA.GetData(2, ref iterations)) { return; } GetAlgorithm(DA, ref algorithm); if (iterations < 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of iterations must be greater than or equal to one."); return; } GH_Structure <GH_Number> outputDataTree = new GH_Structure <GH_Number>(); GH_Path targetPath = DA.ParameterTargetPath(0); //Feedback loop for (int i = 0; i < iterations; i++) { // on the first iteration if (i == 0) { if (!SolveAlgorithm(ref inputs, algorithm)) { return; } } else { if (!SolveAlgorithm(ref inputs, algorithm, "Number of outputs is less than number of inputs. Algorithm cannot support a feedback loop.")) { return; } } GH_Number[] outputList = new GH_Number[inputs.Length]; for (int j = 0; j < inputs.Length; j++) { outputList[j] = new GH_Number(inputs[j]); } outputDataTree.AppendRange(outputList, targetPath.AppendElement(i)); } DA.SetDataTree(0, outputDataTree); }
/// <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) { double Width = 0, Height = 0; int Column = 0, Row = 0; Point3d Position = default(Point3d); GH_Structure <GH_Rectangle> OutputRect = new GH_Structure <GH_Rectangle>(); if (!DA.GetData(0, ref Position)) { return; } if (!DA.GetData(1, ref Width)) { return; } if (!DA.GetData(2, ref Height)) { return; } if (!DA.GetData(3, ref Column)) { return; } if (!DA.GetData(4, ref Row)) { return; } double _X = Position.X, _Y = Position.Y; for (int i = 0; i < Row; i++) { List <GH_Rectangle> TempList = new List <GH_Rectangle>(); var Y = _Y - Height * i; GH_Path Path = new GH_Path(i); for (int j = 0; j < Column; j++) { Point3d Origin; if (Direction == 1) { var X = _X + Width * j * this.Direction; Origin = new Point3d(X, Y - Height, 0); } else { var X = _X + Width * j * this.Direction - Width; Origin = new Point3d(X, Y - Height, 0); } Plane _Plane = new Plane(Origin, Vector3d.ZAxis); Rectangle3d Rect = new Rectangle3d(_Plane, Math.Abs(Width), Math.Abs(Height)); TempList.Add(new GH_Rectangle(Rect)); } OutputRect.AppendRange(TempList, Path); } DA.SetDataTree(0, OutputRect); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <string> layer = new List <string>(); DA.GetDataList("layer", layer); var name_K = "K"; DA.GetData("name K", ref name_K); var name_Cd = "Cd"; DA.GetData("name Cd", ref name_Cd); var name_alpha = "Cd"; DA.GetData("name alpha", ref name_alpha); var doc = RhinoDoc.ActiveDoc; List <Curve> lines = new List <Curve>(); GH_Structure <GH_Number> KCa = new GH_Structure <GH_Number>(); for (int i = 0; i < layer.Count; i++) { var line = doc.Objects.FindByLayer(layer[i]); for (int j = 0; j < line.Length; j++) { var obj = line[j]; Curve[] l = new Curve[] { (new ObjRef(obj)).Curve() }; int nl = (new ObjRef(obj)).Curve().SpanCount;//ポリラインのセグメント数 if (nl > 1) { l = (new ObjRef(obj)).Curve().DuplicateSegments(); } for (int jj = 0; jj < nl; jj++) { lines.Add(l[jj]); List <GH_Number> kcalist = new List <GH_Number>(); var text = obj.Attributes.GetUserString(name_K); if (text == null) { kcalist.Add(new GH_Number(25000)); } else { kcalist.Add(new GH_Number(float.Parse(text))); } text = obj.Attributes.GetUserString(name_Cd); if (text == null) { kcalist.Add(new GH_Number(450)); } else { kcalist.Add(new GH_Number(float.Parse(text))); } text = obj.Attributes.GetUserString(name_alpha); if (text == null) { kcalist.Add(new GH_Number(0.3)); } else { kcalist.Add(new GH_Number(float.Parse(text))); } KCa.AppendRange(kcalist, new GH_Path(jj)); } } } DA.SetDataList("dlines", lines); DA.SetDataTree(1, KCa); }
/// <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) { var filenames = new List <string>(); if (!DA.GetDataList("filename", filenames)) { return; } if (filenames[0] == "") { return; } var X = 0.0; DA.GetData("x", ref X); var Y = 0.0; DA.GetData("y", ref Y); var cp = new List <double>(); DA.GetDataList("origin", cp); var time = new GH_Structure <GH_Number>(); var acc = new GH_Structure <GH_Number>(); var vel = new GH_Structure <GH_Number>(); var disp = new GH_Structure <GH_Number>(); var tmax = 0.0; var amax = 0.0; var vmax = 0.0; var dmax = 0.0; var colors = new List <Color> { Color.Red, Color.Blue, Color.DarkOrange, Color.Gold, Color.LightPink }; for (int e = 0; e < filenames.Count; e++) { StreamReader sr = new StreamReader(@filenames[0]);// 読み込みたいCSVファイルのパスを指定して開く int k = 0; var tlist = new List <GH_Number>(); var alist = new List <GH_Number>(); var vlist = new List <GH_Number>(); var dlist = new List <GH_Number>(); while (!sr.EndOfStream) // 末尾まで繰り返す { string line = sr.ReadLine(); // CSVファイルの一行を読み込む string[] values = line.Split(','); // 読み込んだ一行をカンマ毎に分けて配列に格納する if (double.Parse(values[0]) != 0 && k == 0) { tlist.Add(new GH_Number(0)); alist.Add(new GH_Number(0)); } else { tlist.Add(new GH_Number(double.Parse(values[0]))); alist.Add(new GH_Number(double.Parse(values[1]))); tmax = Math.Max(Math.Abs(double.Parse(values[0])), tmax); amax = Math.Max(Math.Abs(double.Parse(values[1])), amax); } k += 1; } time.AppendRange(tlist, new GH_Path(e)); acc.AppendRange(alist, new GH_Path(e)); vel.AppendRange(vlist, new GH_Path(e)); disp.AppendRange(dlist, new GH_Path(e)); //外枠の描画 _frame.Add(new Line(cp[0], cp[1], cp[2], cp[0] + X, cp[1], cp[2])); _frame.Add(new Line(cp[0], cp[1] + Y, cp[2], cp[0] + X, cp[1] + Y, cp[2])); _frame.Add(new Line(cp[0], cp[1], cp[2], cp[0], cp[1] + Y, cp[2])); _frame.Add(new Line(cp[0] + X, cp[1], cp[2], cp[0] + X, cp[1] + Y, cp[2])); var dx = X / tmax; var dy = Y / (amax * 2); var x = time.Branches; var y = acc.Branches; for (int i = 0; i < x.Count; i++) { for (int j = 0; j < x[i].Count - 1; j++) { _wave.Add(new Line(cp[0] + x[i][j].Value * dx, cp[1] + (y[i][j].Value + amax) * dy, cp[2], cp[0] + x[i][j + 1].Value * dx, cp[1] + (y[i][j + 1].Value + amax) * dy, cp[2])); _c.Add(colors[e]); } } } DA.SetDataTree(0, time); DA.SetDataTree(1, acc); }
/*************************************/ public static GH_Structure <IGH_Goo> IToGoo <T>(this List <List <T> > tree) { GH_Structure <IGH_Goo> structure = new GH_Structure <IGH_Goo>(); for (int i = 0; i < tree.Count; i++) { structure.AppendRange(tree[i].IToGoo(), new GH_Path(i)); } return(structure); }
/// <summary> /// Like GH_Structure.DuplicateCast(), but it works. /// </summary> public static GH_Structure <Q> DupCast <T, Q>(GH_Structure <T> structure, Func <T, Q> cast) where T : IGH_Goo where Q : IGH_Goo { var res = new GH_Structure <Q>(); for (int i = 0; i < structure.PathCount; i++) { res.AppendRange(structure.Branches[i].Select(item => cast(item)), structure.Paths[i]); } return(res); }
/// <summary> /// Converts nested list of polylines into GH_Structure (for gha dev) /// </summary> /// <param name="conversionData">the nested list to convert</param> /// <returns>The data structure</returns> public static GH_Structure <IGH_Goo> ConvertToGHDataStructure(List <List <Polyline> > conversionData) { GH_Structure <IGH_Goo> ghStructure = new GH_Structure <IGH_Goo>(); for (int i = 0; i < conversionData.Count; i++) { List <GH_Curve> ghCurveList = ConvertTOGHCurveList(conversionData[i]); ghStructure.AppendRange(ghCurveList, new GH_Path(i)); } return(ghStructure); }
protected override void SolveInstance(IGH_DataAccess DA) { /// <summary> /// This is the method that actually does the work. /// </summary> /// /// First, we need to retrieve all data from the input parameters. /// We'll start by declaring variables and assigning them starting values. /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> // datatree should be accessed through GH_structure (grasshopper.kernal.data namespace) GH_Structure <GH_Point> winnerTree = new GH_Structure <GH_Point>(); GH_Structure <GH_Point> dataTree = new GH_Structure <GH_Point>();; // Then we need to access the input parameters individually. // When data cannot be extracted from a parameter, we should abort this method. if (!DA.GetDataTree(0, out dataTree)) { return; } // body of code while (dataTree.PathCount != 0) { var pointlist = dataTree.Branches[0].GetRange(0, dataTree.Branches[0].Count); // copy data from first branch to winner winnerTree.EnsurePath(dataTree.Paths[0]); winnerTree.AppendRange(pointlist); dataTree.RemovePath(dataTree.Paths[0]); // test other branches for inliers with winner(0), if so delete them for (int i = 0; i < pointlist.Count; i++) { var pointtest = pointlist[i]; for (int branchj = 0; branchj < dataTree.PathCount; branchj++) { for (int listj = 0; listj < dataTree.Branches[branchj].Count; listj++) { if (((pointtest.Value.X - dataTree.get_DataItem(dataTree.Paths[branchj], listj).Value.X) < 0.001) && ((pointtest.Value.Y - dataTree.get_DataItem(dataTree.Paths[branchj], listj).Value.Y) < 0.001) && ((pointtest.Value.Z - dataTree.get_DataItem(dataTree.Paths[branchj], listj).Value.Z) < 0.001)) { dataTree.RemovePath(dataTree.Paths[branchj]); } } } } } /// run some function on the data //// Finally assign the output to the output parameter. DA.SetDataTree(0, winnerTree); //DA.SetDataList(1, output); }
private static GH_Structure <IGH_Goo> GetSubTree(GH_Structure <IGH_Goo> valueTree, GH_Path searchPath) { var subTree = new GH_Structure <IGH_Goo>(); var gen = 0; foreach (var path in valueTree.Paths) { var branch = valueTree.get_Branch(path) as IEnumerable <IGH_Goo>; if (path.IsAncestor(searchPath, ref gen)) { subTree.AppendRange(branch, path); } else if (path.IsCoincident(searchPath)) { subTree.AppendRange(branch, path); break; } } subTree.Simplify(GH_SimplificationMode.CollapseLeadingOverlaps); return(subTree); }
/// <summary> /// Extract nodes from a tree structure with a flat hierarchy and returns grouped as nodes. NOTE: will have duplicate lines, as untrimmed. /// </summary> /// <param name="skeleton"></param> /// <param name="trimLengthBase"></param> /// <param name="trimLengthTop"></param> /// <returns></returns> private GH_Structure <GH_Curve> ExtractNodes(GH_Structure <GH_Curve> skeleton, double trimLengthBase, double trimLengthTop) { GH_Structure <GH_Curve> nodes = new GH_Structure <GH_Curve>(); //3dimensional list to preserve data structure internally int nodeCount = 0; for (int i = 0; i < skeleton.PathCount; i++) { List <GH_Curve> tempMembers = new List <GH_Curve>(); //add first member to tree GH_Curve member0 = skeleton.get_DataItem(new GH_Path(i), 0); tempMembers.Add(member0); for (int j = 0; j < skeleton.PathCount; j++) { if (j != i) //if its not the same branch { //check whether last plane of branch i is the same as first plane of branch j GH_Curve otherMember = skeleton.get_DataItem(new GH_Path(j), 0); Vector3d distVector = member0.Value.PointAtEnd - otherMember.Value.PointAtStart; double dist = distVector.Length; if (dist < 0.01) { //if same plane, add branch tempMembers.Add(otherMember); } } } if (tempMembers.Count > 1) //if node is actually a node that is more than just a base { //check if members have enough planes. //e.g. if a member has only 1 plane, it is not enough to build a node. bool isSufficient = true; foreach (GH_Curve crv in tempMembers) { if (crv.Value.GetLength() < trimLengthTop) { isSufficient = false; break; } } if (isSufficient) { nodes.AppendRange(tempMembers, new GH_Path(nodeCount)); nodeCount++; } } } return(nodes); }
/// <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 <GH_Point> TempPtsTree = new GH_Structure <GH_Point>(); Point3d StartPt = Point3d.Origin; double ExtendX = default(double), ExtendY = default(double); int TotalNum = default(int), ColumnNum = default(int); if (!DA.GetData(0, ref StartPt)) { return; } if (!DA.GetData(1, ref ExtendX)) { return; } if (!DA.GetData(2, ref ExtendY)) { return; } if (!DA.GetData(3, ref TotalNum)) { return; } if (!DA.GetData(4, ref ColumnNum)) { return; } double StartX = StartPt.X, StartY = StartPt.Y, StartZ = StartPt.Z, CurrentY = 0; double RowNum = TotalNum / ColumnNum; int TotalColumn = Convert.ToInt32((TotalNum % ColumnNum == 0) ? RowNum : (RowNum + 1)); for (int Column = 0; Column < TotalColumn; Column++) { List <GH_Point> TempList = new List <GH_Point>(); int leftNum = TotalNum - Column * ColumnNum; ColumnNum = leftNum < ColumnNum ? leftNum: ColumnNum; CurrentY = StartY; for (int j = 0; j < ColumnNum; j++) { Point3d Temp_Pt = new Point3d(StartX, CurrentY, StartZ); TempList.Add(new GH_Point(Temp_Pt)); CurrentY += ExtendY; } TempPtsTree.AppendRange(TempList, new GH_Path(Column)); StartX += ExtendX; } TempPtsTree.Flatten(); DA.SetDataList(0, TempPtsTree); }
/// <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) { var vec = new Vector3d(1, 0, 0); DA.GetData("A vector that is the basis for rotation", ref vec); var angle = 90.0; DA.GetData("rotate angle", ref angle); var center = new Point3d(0, 0, 0); DA.GetData("center point of rotation", ref center); var offset = new Vector3d(0, 0, 0); DA.GetData("offset after rotation", ref offset); GH_Structure <GH_Number> r2 = new GH_Structure <GH_Number>(); GH_Structure <GH_Point> p2 = new GH_Structure <GH_Point>(); Vector3d rotation(Vector3d a, Vector3d b, double theta) { double rad = theta * Math.PI / 180; double s = Math.Sin(rad); double c = Math.Cos(rad); b /= Math.Sqrt(Vector3d.Multiply(b, b)); double b1 = b[0]; double b2 = b[1]; double b3 = b[2]; Vector3d m1 = new Vector3d(c + Math.Pow(b1, 2) * (1 - c), b1 * b2 * (1 - c) - b3 * s, b1 * b3 * (1 - c) + b2 * s); Vector3d m2 = new Vector3d(b2 * b1 * (1 - c) + b3 * s, c + Math.Pow(b2, 2) * (1 - c), b2 * b3 * (1 - c) - b1 * s); Vector3d m3 = new Vector3d(b3 * b1 * (1 - c) - b2 * s, b3 * b2 * (1 - c) + b1 * s, c + Math.Pow(b3, 2) * (1 - c)); return(new Vector3d(Vector3d.Multiply(m1, a), Vector3d.Multiply(m2, a), Vector3d.Multiply(m3, a))); } DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r); if (_r.Branches[0][0].Value != -9999) { var r = _r.Branches; var n = r.Count; for (int i = 0; i < n; i++) { var rvec = new Vector3d(r[i][0].Value - center[0], r[i][1].Value - center[1], r[i][2].Value - center[2]); var r2vec = rotation(rvec, vec, angle); var rlist = new List <GH_Number>(); rlist.Add(new GH_Number(r2vec[0] + offset[0])); rlist.Add(new GH_Number(r2vec[1] + offset[1])); rlist.Add(new GH_Number(r2vec[2] + offset[2])); r2.AppendRange(rlist, new GH_Path(i)); } DA.SetDataTree(0, r2); } else { DA.GetDataTree("grid points", out GH_Structure <GH_Point> _p); var p = _p.Branches; for (int i = 0; i < p.Count; i++) { var plist = new List <GH_Point>(); for (int j = 0; j < p[i].Count; j++) { var r = p[i][j].Value; var rvec = new Vector3d(r[0] - center[0], r[1] - center[1], r[2] - center[2]); var r2vec = rotation(rvec, vec, angle); var pj = new Point3d(r2vec[0] + offset[0], r2vec[1] + offset[1], r2vec[2] + offset[2]); plist.Add(new GH_Point(pj)); } p2.AppendRange(plist, new GH_Path(i)); } DA.SetDataTree(1, p2); } }
private void PopulateVaribleTree(List <double> _dAValues, List <double> _dBValues, List <double> _fValues, List <double> _kValues, int _valuesCount) { for (int i = 0; i < _valuesCount; i++) { List <GH_Number> allVaribles = new List <GH_Number>(); allVaribles.Add(new GH_Number(_dAValues[i])); allVaribles.Add(new GH_Number(_dBValues[i])); allVaribles.Add(new GH_Number(_fValues[i])); allVaribles.Add(new GH_Number(_kValues[i])); varibles.AppendRange(allVaribles, new GH_Path(i)); } }
/// <summary> /// /// </summary> /// <param name="list"></param> /// <returns></returns> private GH_Structure <GH_Plane> ConvertListToTree(List <List <List <GH_Plane> > > list) { GH_Structure <GH_Plane> tree = new GH_Structure <GH_Plane>(); for (int i = 0; i < list.Count; i++) { for (int j = 0; j < list[i].Count; j++) { GH_Path pth = new GH_Path(i, j); tree.AppendRange(list[i][j], pth); } } 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) { GH_Structure <GH_Number> e_load = new GH_Structure <GH_Number>(); DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r); DA.GetDataTree("element_node_relationship", out GH_Structure <GH_Number> _ij); if (_r.Branches[0][0].Value != -9999 && _ij.Branches[0][0].Value != -9999) { var r = _r.Branches; var ij = _ij.Branches; var x = new List <double>(); DA.GetDataList("x coordinates of element center point", x); var y = new List <double>(); DA.GetDataList("y coordinates of element center point", y); var z = new List <double>(); DA.GetDataList("z coordinates of element center point", z); var wx = 0.0; DA.GetData("distributed load of x axis direction", ref wx); var wy = 0.0; DA.GetData("distributed load of y axis direction", ref wy); var wz = 0.0; DA.GetData("distributed load of z axis direction", ref wz); int kk = 0; for (int e = 0; e < ij.Count; e++) { var ni = (int)ij[e][0].Value; var nj = (int)ij[e][1].Value; var xi = r[ni][0].Value; var yi = r[ni][1].Value; var zi = r[ni][2].Value; var xj = r[nj][0].Value; var yj = r[nj][1].Value; var zj = r[nj][2].Value; var xc = (xi + xj) / 2.0; var yc = (yi + yj) / 2.0; var zc = (zi + zj) / 2.0; int k = 0; for (int j = 0; j < x.Count; j++) { if (Math.Abs(x[j] - xc) < 5e-3 || x[j] == -9999) { k += 1; break; } } for (int j = 0; j < y.Count; j++) { if (Math.Abs(y[j] - yc) < 5e-3 || y[j] == -9999) { k += 1; break; } } for (int j = 0; j < z.Count; j++) { if (Math.Abs(z[j] - zc) < 5e-3 || z[j] == -9999) { k += 1; break; } } if (k == 3) { List <GH_Number> elist = new List <GH_Number>(); elist.Add(new GH_Number(e)); elist.Add(new GH_Number(wx)); elist.Add(new GH_Number(wy)); elist.Add(new GH_Number(wz)); e_load.AppendRange(elist, new GH_Path(kk)); kk += 1; } } } DA.SetDataTree(0, e_load); }
/// <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 variables GH_Controller controllerGoo = null; // Catch input data if (!DA.GetData(0, ref controllerGoo)) { return; } // Clear output variables _robotJointPositions.Clear(); _externalAxisValues.Clear(); // Data needed for making the datatree with axis values MechanicalUnitCollection mechanicalUnits = controllerGoo.Value.MotionSystem.MechanicalUnits; int externalAxisValuesPath = 0; List <double> values; GH_Path path; // Make the output datatree with names with a branch for each mechanical unit for (int i = 0; i < mechanicalUnits.Count; i++) { // Get the ABB joint target of the mechanical unit MechanicalUnit mechanicalUnit = mechanicalUnits[i]; ABB.Robotics.Controllers.RapidDomain.JointTarget jointTarget = mechanicalUnit.GetPosition(); // For internal axis values if (mechanicalUnit.Type == MechanicalUnitType.TcpRobot) { values = GetInternalAxisValuesAsList(jointTarget); _robotJointPositions.Add(new RobotJointPosition(values)); } // For external axis values else { values = GetExternalAxisValuesAsList(jointTarget); path = new GH_Path(externalAxisValuesPath); _externalAxisValues.AppendRange(values.GetRange(0, mechanicalUnit.NumberOfAxes).ConvertAll(val => new GH_Number(val)), path); externalAxisValuesPath += 1; } } // Output DA.SetDataList(0, _robotJointPositions); DA.SetDataTree(1, _externalAxisValues); }
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 useCount = Math.Max(count, 5); var postProcess = count < useCount; var result = RTree.Point3dKNeighbors(inputCloud, inputPts, useCount); 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); var pts = foundIdx.Select(idx => new GH_Point(inputCloud[idx])); if (postProcess) { var localBranchIdx = branchIdx; pts = foundIdx.Select(idx => new { Point = inputCloud[idx], DistanceSquared = inputPts[idx].DistanceToSquared(inputCloud[localBranchIdx]) }) .OrderBy(pt => pt.DistanceSquared) .Select(pt => new GH_Point(pt.Point)) .Take(count); } outPts.AppendRange(pts, path); branchIdx++; } da.SetDataTree(0, outPts); da.SetDataTree(1, outIdx); }
private static GH_Structure <GH_String> GetTagStrings(IEnumerable <StbWall> walls, StbSections sections) { var ghSecStrings = new GH_Structure <GH_String>(); foreach (var item in walls.Select((wall, index) => new { wall, index })) { string secId = item.wall.id_section; var ghPath = new GH_Path(0, item.index); StbSecWall_RC secRc = sections.StbSecWall_RC.First(i => i.id == secId); StbSecWall_RC_Straight figure = secRc.StbSecFigureWall_RC.StbSecWall_RC_Straight; ghSecStrings.AppendRange(TagUtils.GetWallRcSection(figure, secRc.strength_concrete), ghPath); } return(ghSecStrings); }
public GH_Structure <IGH_Goo> SortTreeByIndex(GH_Structure <IGH_Goo> gooTree, GH_Structure <GH_Integer> indTree) { GH_Structure <IGH_Goo> sorted = new GH_Structure <IGH_Goo>(); foreach (GH_Path p in gooTree.Paths) { //feed a copy of the goo tree, because the tree oreder will not correspond to index when sorting starts List <IGH_Goo> goo = (List <IGH_Goo>)(gooTree.get_Branch(p)); List <IGH_Goo> gooCopy = new List <IGH_Goo>(goo); List <GH_Integer> index = (List <GH_Integer>)(indTree.get_Branch(p)); SelectCompareGoo cg = new SelectCompareGoo(gooCopy, index); goo.Sort(cg); sorted.AppendRange(goo, p); } return(sorted); }
/// <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) { // // // Grasshopper.Kernel.GH_Convert.ToGeometricGoo,这个方法非常的重要 // 可以实现IGH_GeometricGoo 到GeometryBase之间的转换 // // List <IGH_GeometricGoo> GeomList = new List <IGH_GeometricGoo>(); GH_Structure <IGH_GeometricGoo> OutPutTree = new GH_Structure <IGH_GeometricGoo>(); string ClassfilyText = null; if (!DA.GetDataList <IGH_GeometricGoo>(0, GeomList)) { return; } if (!DA.GetData(1, ref ClassfilyText)) { return; } try { var Geom_Temp = GeomList.Select(item => { GeometryBase Geom = Grasshopper.Kernel.GH_Convert.ToGeometryBase(item); return(Geom); }); var Temp = Geom_Temp.GroupBy(item => item.UserDictionary[ClassfilyText]).ToList(); for (int Index = 0; Index < Temp.Count; Index++) { int[] PathArr = new int[] { Index }; GH_Path Path = new GH_Path(PathArr); List <GeometryBase> Temp_Geom = Temp[Index].ToList(); List <IGH_GeometricGoo> Temp_IGeom = Temp_Geom.Select(item => { var Geom = Grasshopper.Kernel.GH_Convert.ToGeometricGoo(item); return(Geom); }).ToList(); OutPutTree.AppendRange(Temp_IGeom, Path); } DA.SetDataTree(0, OutPutTree); } catch (Exception Ex) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, Ex.Message); } }
/// <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 <GH_Number> p_load = new GH_Structure <GH_Number>(); if (!DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r)) { } else if (_r.Branches[0][0].Value != -9999) { var r = _r.Branches; var n = r.Count; var x = new List <double>(); DA.GetDataList(1, x); var y = new List <double>(); DA.GetDataList(2, y); var z = new List <double>(); DA.GetDataList(3, z); var px = 0.0; DA.GetData("axial load of x axis direction", ref px); var py = 0.0; DA.GetData("axial load of y axis direction", ref py); var pz = 0.0; DA.GetData("axial load of z axis direction", ref pz); var mx = 0.0; DA.GetData("moment load around x axis direction", ref mx); var my = 0.0; DA.GetData("moment load around y axis direction", ref my); var mz = 0.0; DA.GetData("moment load around z axis direction", ref mz); int e = 0; for (int i = 0; i < n; i++) { var xi = r[i][0].Value; var yi = r[i][1].Value; var zi = r[i][2].Value; int k = 0; for (int j = 0; j < x.Count; j++) { if (Math.Abs(x[j] - xi) < 5e-3 || x[j] == -9999) { k += 1; break; } } for (int j = 0; j < y.Count; j++) { if (Math.Abs(y[j] - yi) < 5e-3 || y[j] == -9999) { k += 1; break; } } for (int j = 0; j < z.Count; j++) { if (Math.Abs(z[j] - zi) < 5e-3 || z[j] == -9999) { k += 1; break; } } if (k == 3) { List <GH_Number> plist = new List <GH_Number>(); plist.Add(new GH_Number(i)); plist.Add(new GH_Number(px)); plist.Add(new GH_Number(py)); plist.Add(new GH_Number(pz)); plist.Add(new GH_Number(mx)); plist.Add(new GH_Number(my)); plist.Add(new GH_Number(mz)); p_load.AppendRange(plist, new GH_Path(e)); e += 1; } } } DA.SetDataTree(0, p_load); }
/// <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 <GH_Number> fix = new GH_Structure <GH_Number>(); if (!DA.GetDataTree("nodal_coordinates", out GH_Structure <GH_Number> _r)) { } else if (_r.Branches[0][0].Value != -9999) { var r = _r.Branches; var n = r.Count; var x = new List <double>(); DA.GetDataList(1, x); var y = new List <double>(); DA.GetDataList(2, y); var z = new List <double>(); DA.GetDataList(3, z); int e = 0; for (int i = 0; i < n; i++) { var xi = r[i][0].Value; var yi = r[i][1].Value; var zi = r[i][2].Value; int k = 0; for (int j = 0; j < x.Count; j++) { if (Math.Abs(x[j] - xi) < 5e-3 || x[j] == -9999) { k += 1; break; } } for (int j = 0; j < y.Count; j++) { if (Math.Abs(y[j] - yi) < 5e-3 || y[j] == -9999) { k += 1; break; } } for (int j = 0; j < z.Count; j++) { if (Math.Abs(z[j] - zi) < 5e-3 || z[j] == -9999) { k += 1; break; } } if (k == 3) { List <GH_Number> fixlist = new List <GH_Number>(); fixlist.Add(new GH_Number(i)); fixlist.Add(new GH_Number(fx)); fixlist.Add(new GH_Number(fy)); fixlist.Add(new GH_Number(fz)); fixlist.Add(new GH_Number(rx)); fixlist.Add(new GH_Number(ry)); fixlist.Add(new GH_Number(rz)); fix.AppendRange(fixlist, new GH_Path(e)); e += 1; } } } DA.SetDataTree(0, fix); }
protected override void SolveInstance(IGH_DataAccess DA) { GH_Structure <IGH_Goo> tree; var pList = new List <int?>(); int?t = 0; if (!DA.GetDataTree(0, out tree)) { return; } for (var i = 1; i < Params.Input.Count; i++) { pList.Add(DA.GetData(i, ref t) ? t : null); } var subtree = new GH_Structure <IGH_Goo>(); var descendant = new List <GH_Path>(); foreach (var p in tree.Paths) { if (pList.Count > p.Length) { continue; } var flag = true; for (var i = 0; i < pList.Count; i++) { flag = flag && (pList[i] == null || pList[i] == p[i]); } if (flag) { descendant.Add(p); } } int i1 = 0, i2 = 0; foreach (var p in descendant) { tree.PathIndex(p, ref i1, ref i2); subtree.AppendRange(tree.Branches[i1], p); } DA.SetData(0, "{" + string.Join(";", pList.Select(i => i != null ? i.ToString() : "?")) + "}"); DA.SetDataTree(1, subtree); }
public static bool PtListArrayToGhTreePoint(List <Point3d[]> rhGrid, ref GH_Structure <GH_Point> grid, GH_Path path) { int num = 0; foreach (Point3d[] pointdArray in rhGrid) { if (pointdArray.Length > 0) { List <GH_Point> data = new List <GH_Point>(); foreach (Point3d pointd in pointdArray) { data.Add(new GH_Point(pointd)); } grid.AppendRange(data, path.AppendElement(num++)); } } return(true); }
protected override void SolveInstance(IGH_DataAccess DA) { GeometryBase region = null; var curves = new List <Curve>(); double radius = 0; int iterations = 0, convergence = 0; DA.GetData(0, ref region); DA.GetDataList(1, curves); DA.GetData(2, ref radius); DA.GetData(3, ref iterations); DA.GetData(4, ref convergence); Polyline polyline = null; Mesh mesh = null; if (region is Curve) { polyline = (region as Curve).ToPolyline(); } else if (region is Mesh) { mesh = (region as Mesh); } else { throw new Exception(" Region should be polyline or mesh."); } var inPolylines = curves.Select(c => c.ToPolyline()).ToList(); var simulation = new Model.Simulations.DifferentialGrowth.DifferentialGrowth(inPolylines, radius, convergence, iterations, polyline, mesh); var polylines = simulation.AllPolylines; var outCurves = new GH_Structure <GH_Curve>(); var path = DA.ParameterTargetPath(0); for (int j = 0; j < polylines.Count; j++) { outCurves.AppendRange(polylines[j].Select(p => new GH_Curve(p.ToNurbsCurve())), path.AppendElement(j)); } DA.SetDataTree(0, outCurves); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <IGH_GeometricGoo> InputList = new List <IGH_GeometricGoo>(); GH_Structure <IGH_GeometricGoo> OutputTree = new GH_Structure <IGH_GeometricGoo>(); if (!DA.GetDataList <IGH_GeometricGoo>(0, InputList)) { return; } var Temp = InputList.GroupBy(item => item.GetType()).ToList(); for (int Index = 0; Index < Temp.Count; Index++) { OutputTree.AppendRange(Temp[Index], new GH_Path(Index)); } DA.SetDataTree(0, OutputTree); }
/// <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 <GH_String> ClassifyTree = new GH_Structure <GH_String> (); List <double> InputList = new List <double>(); GH_Structure <GH_Number> OutputTree = new GH_Structure <GH_Number>(); if (!DA.GetDataList <double>(0, InputList)) { return; } if (!DA.GetDataTree <GH_String>(1, out ClassifyTree)) { return; } List <List <double> > IntervalDataList = new List <List <double> >(); try { IntervalDataList = Convert2ListInterval(ClassifyTree); }catch (Exception e) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message); } int IntervalCount = IntervalDataList.Count; for (int Index = 0; Index < IntervalCount; Index++) { List <double> IntervalBranch = IntervalDataList[Index]; double min = IntervalBranch.Min(); double max = IntervalBranch.Max(); List <double> TempList = (from item in InputList where item >= min && item < max select item).ToList(); TempList.OrderByDescending(item => item).ToList(); TempList.Reverse(); OutputTree.AppendRange(TempList.Select(item => new GH_Number(item)).ToList(), new GH_Path(Index)); } DA.SetDataTree(0, OutputTree); }
/// <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> TreeA = new GH_Structure <IGH_Goo>(); GH_Structure <IGH_Goo> TreeB = new GH_Structure <IGH_Goo>(); GH_Structure <IGH_Goo> InputTree = new GH_Structure <IGH_Goo>(); List <GH_Boolean> InputPattern = new List <GH_Boolean>(); List <int> IA_List = new List <int>(); List <int> IB_List = new List <int>(); if (!DA.GetDataTree <IGH_Goo>(0, out InputTree)) { return; } if (!DA.GetDataList <GH_Boolean>(1, InputPattern)) { return; } List <GH_Boolean> PatternList = this.PatternConstruct(InputPattern, InputTree.Branches.Count); int Branch_A = 0, Branch_B = 0, Index = 0; for (; Index < PatternList.Count; Index++) { if (PatternList[Index].Value) { TreeA.AppendRange(InputTree.Branches[Index], InputTree.Paths[Index]); IA_List.Add(Index); Branch_A++; } else { TreeB.AppendRange(InputTree.Branches[Index], InputTree.Paths[Index]); IB_List.Add(Index); Branch_B++; } } DA.SetDataTree(0, TreeA); DA.SetDataTree(1, TreeB); DA.SetDataList(2, IA_List); DA.SetDataList(3, IB_List); }
public GH_Structure <GH_Number> DataTree() { GH_Structure <GH_Number> dataTree = new GH_Structure <GH_Number>(); GH_Structure <GH_Integer> indices = new GH_Structure <GH_Integer>(); for (int i = 0; i < trainedVectors.GetLength(0); i++) { GH_Path p = new GH_Path(Utils.ReverseArray(this.adressBook[i])); indices.Append(new GH_Integer(i), p); } indices.Flatten(); dataTree = new GH_Structure <GH_Number>(); GH_Structure <GH_Number> valueTree = Utils.MultidimensionalArrayToGHTree(trainedVectors); for (int i = 0; i < indices.DataCount; i++) { dataTree.AppendRange(valueTree.Branches[indices.Branches[0][i].Value], new GH_Path(this.adressBook[i])); } return(dataTree); }