/// <summary> /// You will need to override this method to solve the component. /// </summary> /// <param name="DA">Grasshopper's DataAccess interface</param> protected override void SolveInstance(GH.Kernel.IGH_DataAccess DA) { // Retrieve the data and pass it to the designer component Point3d point = new Point3d(0, 0, 0); double span = 10.0; double height = 1.0; int n = 1; double spacing = 1.0; if (DA.GetData<Point3d>(1, ref point)) { ((DesignerWithVisualOutputExample)this.Designer).basePoint = new SOPoint3d( point.X, point.Y, point.Z); } if (DA.GetData<double>(2, ref span)) { ((DesignerWithVisualOutputExample)this.Designer).Span = span; } if (DA.GetData<double>(3, ref height)) { ((DesignerWithVisualOutputExample)this.Designer).Height = height; } if (DA.GetData<int>(4, ref n)) { ((DesignerWithVisualOutputExample)this.Designer).NumberOfFrames = n; } if (DA.GetData<double>(5, ref spacing)) { ((DesignerWithVisualOutputExample)this.Designer).Spacing = spacing; } /// Note that you will need to call the SolveInstance method of the base class to process the default parameters and connect them to the framework. base.SolveInstance(DA); DesignerWithVisualOutputExample dsn = (DesignerWithVisualOutputExample)this.Designer; List<Line> lines = new List<Line>(); for (int i = 0; i < dsn.NumberOfFrames; i++) { lines.Add(new Line(dsn.Points2[i].X, dsn.Points2[i].Y, dsn.Points2[i].Z, dsn.Points4[i].X, dsn.Points4[i].Y, dsn.Points4[i].Z)); lines.Add(new Line(dsn.Points1[i].X, dsn.Points1[i].Y, dsn.Points1[i].Z, dsn.Points2[i].X, dsn.Points2[i].Y, dsn.Points2[i].Z)); lines.Add(new Line(dsn.Points3[i].X, dsn.Points3[i].Y, dsn.Points3[i].Z, dsn.Points4[i].X, dsn.Points4[i].Y, dsn.Points4[i].Z)); } DA.SetDataList(1, lines); }
/// <summary> /// You will need to override this method to solve the component. /// </summary> /// <param name="DA">Grasshopper's DataAccess interface</param> protected override void SolveInstance(GH.Kernel.IGH_DataAccess DA) { // first set the properties in the SODesigner int n = 0; if (DA.GetData<int>(1, ref n)) { ((DesignerWithInputExample)this.Designer).NumberOfBeams = n; } /// Note that you will need to call the SolveInstance method of the base class to process the default parameters and connect them to the framework. base.SolveInstance(DA); }
protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA) { double v = -1.0; DA.GetData(1, ref v); if (!FriedChiken.isInitialized) { Rhino.Geometry.Curve c = null; if (!DA.GetData(0, ref c)) return; if (c.IsPolyline()) { Rhino.Geometry.Polyline pl = null; if (c.TryGetPolyline(out pl)) { nNewNodes = pl.Count(); nElements = nNewNodes - 1; newNodes.Clear(); newNodes.AddRange(pl); lGeometry.Clear(); for (int i = 0; i < nElements; i++) { lGeometry.Add(new Rhino.Geometry.Line(newNodes[i], newNodes[i + 1])); } mikity.NumericalMethodHelper.particle[] particles = new mikity.NumericalMethodHelper.particle[nNewNodes]; for (int i = 0; i < nNewNodes; i++) { particles[i] = new mikity.NumericalMethodHelper.particle(newNodes[i][0], newNodes[i][1], newNodes[i][2]); } List<mikity.NumericalMethodHelper.elements.isoparametricElement> e = new List<mikity.NumericalMethodHelper.elements.isoparametricElement>(); for (int i = 0; i < nElements; i++) { e.Add(new mikity.NumericalMethodHelper.elements.isoparametricElement(i, i + 1)); } lCV.Clear(); pS = new GH_particleSystem(particles); for (int i = 0; i < e.Count; i++) { lCV.Add(new constrainVolumeObject(v / nElements)); lCV[i].addElement(e[i]); pS.Value.addObject(lCV[i]); } lGeometry.Clear(); for (int i = 0; i < nElements; i++) { lGeometry.Add(new Rhino.Geometry.Line(pS.Value.particles[i, 0], pS.Value.particles[i, 1], pS.Value.particles[i, 2], pS.Value.particles[i + 1, 0], pS.Value.particles[i + 1, 1], pS.Value.particles[i + 1, 2])); } } } else { AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "Only polyline is accepted"); return; } } else { if (lCV != null && v > 0) { for (int i = 0; i < lCV.Count; i++) { lCV[i].refVolume = v / nElements; } } } DA.SetData(0, pS); DA.SetDataList(1, newNodes); }
protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA) { init(); _listSrf = new List<Surface>(); _listCrv = new List<Curve>(); listPnt = new List<Point3d>(); List<string> crvTypes = new List<string>(); List<string> pntHeights = new List<string>(); if (!DA.GetDataList(0, _listSrf)) { return; } if (!DA.GetDataList(1, _listCrv)) { return; } if (!DA.GetDataList(2, crvTypes)) { return; } if (!DA.GetDataList(3, listPnt)) { listPnt.Clear(); } if (!DA.GetData(4, ref globalC)) { return; } if (_listCrv.Count != crvTypes.Count) { AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "need types for curves"); return; } listSlice = new Dictionary<string, slice>(); listSlice2 = new Dictionary<string, slice2>(); listRange = new Dictionary<string, range>(); listRangeOpen = new Dictionary<string, range>(); listRangeLeaf = new Dictionary<string, range>(); listLeaf = new List<leaf>(); listBranch = new List<branch>(); listNode=new List<node>(); myControlBox.clearSliders(); for (int i = 0; i < _listCrv.Count; i++) { var branch = new branch(); branch.crv = _listCrv[i] as NurbsCurve; branch.N = branch.crv.Points.Count; branch.dom = branch.crv.Domain; branch.Dim= branch.crv.Order; branch.dDim = branch.crv.Order - 1; branch.nElem = branch.N - branch.dDim; branch.scaleT = (branch.dom.T1 - branch.dom.T0) / branch.nElem; branch.originT = branch.dom.T0; if(crvTypes[i].StartsWith("reinforce")) { branch.branchType = branch.type.reinforce; var key=crvTypes[i].Replace("reinforce",""); branch.sliceKey=key; try{ branch.slice=listSlice[key]; branch.slice.sliceType = slice.type.fr; branch.slice.lB.Add(branch); } catch (KeyNotFoundException e){ listSlice[key]=new slice(); branch.slice=listSlice[key]; branch.slice.sliceType=slice.type.fr; branch.slice.lB.Add(branch); } } else if(crvTypes[i].StartsWith("kink")) { branch.branchType = branch.type.kink; var key = crvTypes[i].Replace("kink", ""); if (key == "") key = "kink"; else key = "kink:" + key; branch.sliceKey = key; try { branch.range = listRange[key]; branch.range.rangeType = range.type.lo; branch.range.lb = 0; branch.range.ub = 0; branch.range.lB.Add(branch); } catch (KeyNotFoundException) { listRange[key] = new range(); branch.range = listRange[key]; branch.range.rangeType = range.type.lo; branch.range.lb = 0; branch.range.ub = 0; branch.range.lB.Add(branch); var adjuster = myControlBox.addRangeSetter(key, (th,sw, lb, ub) => { if (listRange[key].firstPathDone) { th.setMeasured(listRange[key].lastMin,listRange[key].lastMax); } foreach (var _branch in listRange[key].lB) { if (sw == 0) { _branch.range.rangeType = range.type.lo; _branch.range.lb = lb; _branch.range.ub = 0d; } if (sw == 2) { _branch.range.rangeType = range.type.ra; _branch.range.lb = lb; _branch.range.ub = ub; } } } ); } }else if(crvTypes[i].StartsWith("open")) { branch.branchType = branch.type.open; var key = crvTypes[i].Replace("open", ""); if (key == "") key = "open"; else key = "open:" + key; branch.sliceKey = key; try { branch.slice = listSlice[key]; branch.slice.sliceType = slice.type.fr; branch.slice.lB.Add(branch); } catch (KeyNotFoundException e) { listSlice[key] = new slice(); branch.slice = listSlice[key]; branch.slice.sliceType = slice.type.fr; branch.slice.lB.Add(branch); } try { branch.range = listRangeOpen[key]; branch.range.rangeType = range.type.lo; branch.range.lb = 0; branch.range.ub = 0; branch.range.lB.Add(branch); } catch (KeyNotFoundException) { listRangeOpen[key] = new range(); branch.range = listRangeOpen[key]; branch.range.rangeType = range.type.lo; branch.range.lb = 0; branch.range.ub = 0; branch.range.lB.Add(branch); var adjuster = myControlBox.addRangeSetter(key, (th,sw, lb, ub) => { if (listRangeOpen[key].firstPathDone) { th.setMeasured(listRangeOpen[key].lastMin,listRangeOpen[key].lastMax); } foreach (var _branch in listRangeOpen[key].lB) { if (sw == 0) { _branch.range.rangeType = range.type.lo; _branch.range.lb = lb; _branch.range.ub = 0d; } if (sw == 2) { _branch.range.rangeType = range.type.ra; _branch.range.lb = lb; _branch.range.ub = ub; } } } ); } } else if (crvTypes[i].StartsWith("fix")) { branch.branchType = branch.type.fix; var key = crvTypes[i].Replace("fix", ""); branch.sliceKey = key; try { branch.slice2 = listSlice2[key]; } catch (KeyNotFoundException e) { listSlice2[key] = new slice2(); branch.slice2 = listSlice2[key]; var slider = myControlBox.addSliderVert(0, 1, 200, 100); slider.Converter = (val) => { double height = val / 10d - 10d; branch.slice2.height = height; this.ExpirePreview(true); return height; }; } }else{ AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "type should be either of reinforce, kink, fix, or open"); } listBranch.Add(branch); } for(int i=0;i<_listSrf.Count;i++) { var srf = _listSrf[i]; var leaf=new leaf(); listLeaf.Add(leaf); leaf.srf = srf as NurbsSurface; leaf.nU = leaf.srf.Points.CountU; leaf.nV = leaf.srf.Points.CountV; leaf.domU = leaf.srf.Domain(0); leaf.domV = leaf.srf.Domain(1); leaf.uDim = leaf.srf.OrderU; leaf.vDim = leaf.srf.OrderV; leaf.uDdim = leaf.srf.OrderU - 1; leaf.vDdim = leaf.srf.OrderV - 1; leaf.nUelem = leaf.nU - leaf.uDdim; leaf.nVelem = leaf.nV - leaf.vDdim; leaf.scaleU = (leaf.domU.T1 - leaf.domU.T0) / leaf.nUelem; leaf.scaleV = (leaf.domV.T1 - leaf.domV.T0) / leaf.nVelem; leaf.originU = leaf.domU.T0; leaf.originV = leaf.domV.T0; var domainU = leaf.srf.Domain(0); var domainV = leaf.srf.Domain(1); //Find corresponding curve //(0,0)->(1,0) var curve = leaf.srf.IsoCurve(0, domainV.T0) as NurbsCurve; leaf.flip[0] = findCurve(leaf,ref leaf.branch[0], listBranch, curve);//bottom //(1,0)->(1,1) curve = leaf.srf.IsoCurve(1, domainU.T1) as NurbsCurve; leaf.flip[1] = findCurve(leaf, ref leaf.branch[1], listBranch, curve);//right //(1,1)->(0,1) curve = leaf.srf.IsoCurve(0, domainV.T1) as NurbsCurve; leaf.flip[2] = findCurve(leaf, ref leaf.branch[2], listBranch, curve);//top //(0,1)->(0,0) curve = leaf.srf.IsoCurve(1, domainU.T0) as NurbsCurve; leaf.flip[3] = findCurve(leaf, ref leaf.branch[3], listBranch, curve);//left var key = "leaf"; try { leaf.range = listRangeLeaf[key]; leaf.range.rangeType = range.type.lo; leaf.range.lb = 0; leaf.range.ub = 0; leaf.range.lL.Add(leaf); } catch (KeyNotFoundException) { listRangeLeaf[key] = new range(); leaf.range = listRangeLeaf[key]; leaf.range.rangeType = range.type.lo; leaf.range.lb = 0; leaf.range.ub = 0; leaf.range.lL.Add(leaf); var adjuster = myControlBox.addRangeSetter(key, (th, sw, lb, ub) => { if (listRangeLeaf[key].firstPathDone) { th.setMeasured(listRangeLeaf[key].lastMin, listRangeLeaf[key].lastMax); } foreach (var _leaf in listRangeLeaf[key].lL) { if (sw == 0) { _leaf.range.rangeType = range.type.lo; _leaf.range.lb = lb; _leaf.range.ub = 0d; } if (sw == 2) { _leaf.range.rangeType = range.type.ra; _leaf.range.lb = lb; _leaf.range.ub = ub; } } } ); } } // Connect nodes foreach (var leaf in listLeaf) { leaf.globalIndex = new int[leaf.srf.Points.CountU * leaf.srf.Points.CountV]; for (int j = 0; j < leaf.srf.Points.CountV; j++) { for (int i = 0; i < leaf.srf.Points.CountU; i++) { var P = leaf.srf.Points.GetControlPoint(i, j).Location; bool flag = false; foreach (var node in listNode) { if (node.compare(P)) { flag = true; node.N++; node.shareL.Add(leaf); node.numberL.Add(i + j * leaf.nU); leaf.globalIndex[i + j * leaf.nU] = listNode.IndexOf(node); break; } } if (!flag) { var newNode = new node(); listNode.Add(newNode); newNode.N = 1; newNode.x = P.X; newNode.y = P.Y; newNode.z = P.Z; newNode.shareL.Add(leaf); newNode.numberL.Add(i + j * leaf.nU); leaf.globalIndex[i + j * leaf.nU] = listNode.IndexOf(newNode); } } } } foreach (var branch in listBranch) { branch.globalIndex = new int[branch.crv.Points.Count]; for (int i = 0; i < branch.crv.Points.Count; i++) { var P = branch.crv.Points[i].Location; bool flag = false; foreach (var node in listNode) { if (node.compare(P)) { flag = true; node.N++; node.shareB.Add(branch); node.numberB.Add(i); if (branch.branchType == branch.type.fix) { node.nodeType = node.type.fx; } branch.globalIndex[i] = listNode.IndexOf(node); break; } } if (!flag) { var newNode = new node(); listNode.Add(newNode); newNode.N = 1; newNode.shareB.Add(branch); newNode.numberB.Add(i); newNode.x = P.X; newNode.y = P.Y; newNode.z = P.Z; if (branch.branchType == branch.type.fix) { newNode.nodeType = node.type.fx; } branch.globalIndex[i] = listNode.IndexOf(newNode); } } } //multiqudric surface var A=new Rhino.Geometry.Matrix(listPnt.Count,listPnt.Count); var z=new Rhino.Geometry.Matrix(listPnt.Count,1); for(int i=0;i<listPnt.Count;i++) { for(int j=0;j<listPnt.Count;j++) { var pi=listPnt[i]; var pj=listPnt[j]; A[i,j]=quadFunc(pi.X,pj.X,pi.Y,pj.Y); z[i,0]=pi.Z; } } A.Invert(0.0); //this parameter should be 0.0 var c=A*z; globalCoeff=new double[listPnt.Count]; for(int i=0;i<listPnt.Count;i++) { globalCoeff[i]=c[i,0]; } targetSrf=new List<Point3d>(); globalFunc=(xi,yi)=>{ double Z=0; for(int j=0;j<listPnt.Count;j++) { Z=Z+globalCoeff[j]*quadFunc(xi,listPnt[j].X,yi,listPnt[j].Y); } return Z; }; foreach (var leaf in listLeaf) { var domU = leaf.domU; var domV = leaf.domV; for (double i = 0; i <= 1.0; i += 0.05) { for (double j = 0; j < 1.0; j += 0.05) { double u = domU[0] + i * (domU[1] - domU[0]); double v = domV[0] + j * (domV[1] - domV[0]); Rhino.Geometry.Point3d P; Rhino.Geometry.Vector3d[] V; leaf.srf.Evaluate(u, v, 0, out P, out V); var newP = new Rhino.Geometry.Point3d(P.X, P.Y, globalFunc(P.X, P.Y)); targetSrf.Add(newP); } } } }