コード例 #1
0
        /// <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)
        {
            Surface surface  = null;
            double  uPercent = 0;
            double  vPercent = 0;

            if (!DA.GetData(0, ref surface))
            {
                return;
            }
            if (!DA.GetData(1, ref uPercent))
            {
                return;
            }
            if (!DA.GetData(2, ref vPercent))
            {
                return;
            }
            ////////////////////////////////////////////
            Interval         uu   = surface.Domain(0);
            Interval         vv   = surface.Domain(1);
            double           num1 = (uu.T1 - uu.T0) * uPercent + uu.T0;
            double           num2 = (vv.T1 - vv.T0) * vPercent + vv.T0;
            Point3d          pt   = surface.PointAt(num1, num2);
            SurfaceCurvature sc   = surface.CurvatureAt(num1, num2);
            Point2d          pt2  = sc.UVPoint;

            DA.SetData(0, pt);
            DA.SetData(1, pt2);
            DA.SetData(2, sc.Gaussian);
            DA.SetData(3, sc.Mean);
            DA.SetData(4, sc.Normal);
        }
コード例 #2
0
        //////////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);
        }
コード例 #3
0
ファイル: SurfaceAdjust.cs プロジェクト: ahmedhosny/Ibis
        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);
        }
コード例 #4
0
        public override void Run(RenderControl render)
        {
            //1. Create Shape
            TopoShapeList tg     = new TopoShapeList();
            GPntList      points = new GPntList();

            using (var sr = new StreamReader(GetResourcePath("data/Stage4_Rotor4_Profile.curve")))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.StartsWith("# Profile"))
                    {
                        if (points.Count > 0)
                        {
                            var temp2 = SketchBuilder.MakeBSpline(points);
                            if (temp2 != null)
                            {
                                tg.Add(temp2);
                            }
                        }

                        points = new GPntList();
                    }
                    else
                    {
                        var temp = line.Split('\t');
                        points.Add(new GPnt(double.Parse(temp[0]), double.Parse(temp[1]), double.Parse(temp[2])));
                    }
                }
            }


            var shape = FeatureTool.Loft(tg, true, true);

            //2. Compute Curvature
            var material = BasicMaterial.Create("vertex-color");

            material.SetVertexColors(true);
            material.SetFaceSide(EnumFaceSide.DoubleSide);

            var bs = new BufferShape(shape, material, null, 0.01f);

            bs.Build();

            ColorLookupTable clt = new ColorLookupTable();

            clt.SetColorMap(ColorMapKeyword.Create(EnumSystemColorMap.Rainbow));

            float scale = 100;

            clt.SetMinValue(-0.2f * scale);
            clt.SetMaxValue(scale);

            for (uint ii = 0; ii < bs.GetFaceCount(); ++ii)
            {
                var sc = new SurfaceCurvature(bs);
                if (sc.Compute(ii, EnumCurvatureType.MeanCurvature))
                {
                    Console.WriteLine("{0}, {1}", sc.GetMinValue(), sc.GetMaxValue());
                    var colorBuffer = sc.ComputeColors(clt, scale);
                    bs.SetVertexColors(ii, colorBuffer);
                }
            }

            // 3. Show it!
            var node = new BrepSceneNode(bs);

            render.ShowSceneNode(node);
        }
コード例 #5
0
        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);
        }