Beispiel #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)
        {
            List <LineObjClass> lineobjs = new List <LineObjClass>();
            List <Point3d>      points   = new List <Point3d>();
            double         err           = 0;
            int            pointsCount   = 0; //添加到points列表中点的个数
            int            pointsNo      = 0; //线段端点的索引
            DataTree <int> tree          = new DataTree <int>();

            DA.GetDataList(0, lineobjs);
            DA.GetData(1, ref err);
            int num = lineobjs.Count;

            for (int i = 0; i < num; i++)
            {
                List <Point3d> lineV = new List <Point3d>();
                List <int>     vInd  = new List <int>();
                GH_Path        path  = new GH_Path(tree.BranchCount);

                Point3d p0 = lineobjs[i].Line.PointAt(0);
                Point3d p1 = lineobjs[i].Line.PointAt(1);
                lineV.Add(p0);
                lineV.Add(p1);
                for (int j = 0; j < lineV.Count; j++)
                {
                    bool bo;
                    int  ind;
                    FunctionClass.BigThanErr(points, lineV[j], err, out bo, out ind);
                    if (bo)//如果点lineV[j]不跟其他点重合
                    {
                        points.Add(lineV[j]);
                        pointsCount += 1;
                        pointsNo     = pointsCount;
                    }
                    else
                    {
                        pointsNo = ind + 1;
                    }
                    vInd.Add(pointsNo);
                    lineobjs[i].Vertices = vInd;
                    tree.Add(vInd[j], path);
                }
            }
            DA.SetDataList(0, points);
            DA.SetDataList(1, lineobjs);
            DA.SetDataTree(2, tree);
        }