//////////here are my functions: String mySurfaceCheckFunction(Surface s, int sam, double tol) { String Result = null; List <double> myKappa0List = new List <double>(); List <double> myKappa1List = new List <double>(); double MIN0 = s.Domain(0).Min; double MAX0 = s.Domain(0).Max; double MIN1 = s.Domain(1).Min; double MAX1 = s.Domain(1).Max; double uStep = (MAX0 - MIN0) / (sam - 1); double vStep = (MAX1 - MIN1) / (sam - 1); for (int i = 0; i < sam; ++i) { for (int j = 0; j < sam; ++j) { double utemp = s.Domain(0).Min + i * uStep; double vtemp = s.Domain(1).Min + j * vStep; SurfaceCurvature mySurfaceCurvature = s.CurvatureAt(utemp, vtemp); double temp0 = mySurfaceCurvature.Kappa(0); myKappa0List.Add(temp0); double temp1 = mySurfaceCurvature.Kappa(1); myKappa1List.Add(temp1); } } for (int i = 0; i < myKappa0List.Count; i++) { if (Math.Abs(myKappa0List[i]) < tol && Math.Abs(myKappa1List[i]) < tol) { Result = "zero"; } else if (Math.Abs(myKappa0List[i]) < tol || Math.Abs(myKappa1List[i]) < tol) { Result = "one"; } else { Result = "two"; } } return(Result); }
protected override void SolveInstance(IGH_DataAccess DA) { Surface mySurface = null; if (!DA.GetData(0, ref mySurface)) { return; } int myMinRad = 0; if (!DA.GetData(1, ref myMinRad)) { return; } int mySampleDensity = 0; if (!DA.GetData(2, ref mySampleDensity)) { return; } double myFactor = 0.0; if (!DA.GetData(3, ref myFactor)) { return; } List <Curve> myCurveList = new List <Curve>(); List <double> myOffsetList = new List <double>(); List <Point3d> myOriginalList = new List <Point3d>(); List <List <Point3d> > myNewListList = new List <List <Point3d> >(); List <Vector3d> myNormalList = new List <Vector3d>(); //Get Curve from Surface double MIN1 = mySurface.Domain(1).Min; double MAX1 = mySurface.Domain(1).Max; double myStep = (MAX1 - MIN1) / mySampleDensity; for (int i = 0; i < (mySampleDensity - 1); i++) { Curve myCurve = mySurface.IsoCurve(0, i * myStep); //Problem here? 1 and 0? myCurveList.Add(myCurve); } //Loop through Curve; foreach (Curve myCurve in myCurveList) { /*Curve c = myCurve.DuplicateCurve(); * * * for(int iter=0; iter<10; ++iter) { * double[] t = c.DivideByCount(100, true); * List<Point3d> cp = new List<Point3d>(); * for (int k = 0; k <t.Length; ++k) * { * Point3d p = c.PointAt(t[k]); * Vector3d k1=c.CurvatureAt(t[k]); * p += k1 * 0.01; * cp.Add(p); * } * c = NurbsCurve.CreateInterpolatedCurve(cp, 3); * }*/ List <Point3d> myNewList = new List <Point3d>(); double Max = myCurve.Domain.Max; double Min = myCurve.Domain.Min; double step = (Max - Min) / mySampleDensity; for (int i = 0; i < mySampleDensity - 1; i++) { Point3d P = new Point3d(myCurve.PointAt(step * i)); myOriginalList.Add(P); //Make List of Points myNewList.Add(P); Vector3d myCurvature = myCurve.CurvatureAt(step * i); double myRadius = 1 / myCurvature.Length; double myOffset = myMinRad - myRadius; myOffsetList.Add(myOffset); //Make List of offset double u; double v; mySurface.ClosestPoint(P, out u, out v); Vector3d myNormal = mySurface.NormalAt(u, v); myNormal.Unitize(); myNormalList.Add(myNormal); SurfaceCurvature mySurfaceCurvature = mySurface.CurvatureAt(u, v); //double myGaussian = mySurfaceCurvature.Gaussian;//Gaussian from Surface double Kappa0 = mySurfaceCurvature.Kappa(0);//Problem here? if (myOffset > 0) { if (Math.Abs(Kappa0) > 0) { Point3d PNew = new Point3d(); PNew = P + myNormal * myOffset * myFactor; myNewList.RemoveAt(i); myNewList.Insert(i, PNew); } else { Point3d PNew = new Point3d(); PNew = P - myNormal * myOffset * myFactor; myNewList.RemoveAt(i); myNewList.Insert(i, PNew); } } } myNewListList.Add(myNewList); } List <Curve> myNewCurveList = new List <Curve>(); Brep FINAL = new Brep(); for (int i = 0; i < myNewListList.Count; i++) { Curve myNewCurve = NurbsCurve.CreateControlPointCurve(myNewListList[i], 3); myNewCurveList.Add(myNewCurve); } FINAL = Brep.CreateFromLoft(myNewCurveList, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0]; DA.SetData(0, FINAL); }
protected override void SolveInstance(IGH_DataAccess DA) { //myFailedPointList.Clear(); //myThicknessList.Clear(); int myMaterial = 0; if (!DA.GetData(0, ref myMaterial)) { return; } //myThicknessList.Clear(); Surface mySurface = null; if (!DA.GetData(1, ref mySurface)) { return; } int myGrain = 0; if (!DA.GetData(2, ref myGrain)) { return; } int myThickness = 0; if (!DA.GetData(3, ref myThickness)) { return; } ///////////GetData cont. :- int mySampleDensity = 0; if (!DA.GetData(4, ref mySampleDensity)) { return; } //////////Pre-Processing:- List <double> myRadii = new List <double>(); List <Point3d> myPointList = new List <Point3d>(); double MIN0 = mySurface.Domain(0).Min; double MAX0 = mySurface.Domain(0).Max; double MIN1 = mySurface.Domain(1).Min; double MAX1 = mySurface.Domain(1).Max; double uStep = (MAX0 - MIN0) / mySampleDensity; double vStep = (MAX1 - MIN1) / mySampleDensity; for (int i = 0; i < mySampleDensity; i++) { for (int j = 0; j < mySampleDensity; j++) { double u = i * uStep; double v = j * vStep; Point3d P = mySurface.PointAt(u, v); myPointList.Add(P); SurfaceCurvature mySurfaceCurvature = mySurface.CurvatureAt(u, v); double myKappa0 = Math.Abs(mySurfaceCurvature.Kappa(0)); double myKappa1 = Math.Abs(mySurfaceCurvature.Kappa(1)); if (myKappa0 > myKappa1) { double myRadius = 1 / myKappa0; myRadii.Add(myRadius); } else { double myRadius = 1 / myKappa1; myRadii.Add(myRadius); } } } ////////// Code to loop through XML nodes and get MinRad value:- double MinRad = 0.0; string temp = IBIS_XML.SelectSingleNode("IBIS/DryBending/Material[@id= '" + myMaterial + "']/BendDirection[@id= '" + myGrain + "']/Thickness[@id= '" + myThickness + "']").InnerText; MinRad = Convert.ToDouble(temp); //////////PostProcessing:- //List<Surface> myFailedSurfaceList = new List<Surface>(); List <Point3d> myFailedPointList = new List <Point3d>(); for (int i = 0; i < myRadii.Count; i++) { if (myRadii[i] < MinRad) { myFailedPointList.Add(myPointList[i]); // myFailedSurfaceList.Add(mySurface); } } ////////// //List<NurbsSurface> myNurbsList = new List<NurbsSurface>(); //List<int> myNotOkIndex = new List<int>(); //List<int> myOkIndex = new List<int>(); //foreach (NurbsSurface myNurbsTemp in myNurbsList) //{ // double subMIN0 = myNurbsTemp.Domain(0).Min; // double subMAX0 = myNurbsTemp.Domain(0).Max; // double subMIN1 = myNurbsTemp.Domain(1).Min; // double subMAX1 = myNurbsTemp.Domain(1).Max; // double v = (MAX0 - MIN0) / 2; // double u = (MAX1 - MIN1) / 2; // SurfaceCurvature mySurfaceCurvature = myNurbsTemp.CurvatureAt(u, v); //} //for (int j = 0; j < myRadii.Count; j++) //{ // if (myRadii[j] < MinRad) // { // myNotOkIndex.Add(j); // } // else // { // myOkIndex.Add(j); // } //} //for (int i = 0; i < myOkIndex.Count; i++) //{ // myOkNurbsList.Add(myNurbsList[myOkIndex[i]]); //} //for (int i = 0; i < myNotOkIndex.Count; i++) //{ // myNotOkNurbsList.Add(myNurbsList[myNotOkIndex[i]]); //} ////////// Outputs:- //DA.SetDataList(0, myOkNurbsList); // DA.SetDataList(1, myNotOkNurbsList); // DA.SetDataList(0, myFailedSurfaceList); DA.SetDataList(0, myFailedPointList); DA.SetData(1, MinRad); }