Exemplo n.º 1
0
        /// <summary>
        /// Converts a point into a GH_Point
        /// </summary>
        /// <param name="pt">The point to convert</param>
        /// <returns>The GH_Point</returns>
        public static GH_Point ConvertToGHPoint(Point3d pt)
        {
            GH_Point ghp = new GH_Point();
            bool     c   = GH_Convert.ToGHPoint(pt, GH_Conversion.Both, ref ghp);

            return(ghp);
        }
Exemplo n.º 2
0
        ///Projection engines
        public static GH_Point ProjectPointToTopo(Mesh topoMesh, Point3d pt)
        {
            GH_Point ghPoint = new GH_Point();
            Ray3d    ray     = new Ray3d(pt, moveDir);
            double   t       = Rhino.Geometry.Intersect.Intersection.MeshRay(topoMesh, ray);

            if (t >= 0.0)
            {
                GH_Convert.ToGHPoint(ray.PointAt(t), GH_Conversion.Primary, ref ghPoint);
            }
            else
            {
                Ray3d  rayOpp = new Ray3d(pt, -moveDir);
                double tOpp   = Rhino.Geometry.Intersect.Intersection.MeshRay(topoMesh, rayOpp);
                if (tOpp >= 0.0)
                {
                    GH_Convert.ToGHPoint(rayOpp.PointAt(tOpp), GH_Conversion.Primary, ref ghPoint);
                }
                else
                {
                    return(null);
                }
            }
            return(ghPoint);
        }
Exemplo n.º 3
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)
        {
            string path     = "";
            int    lineSkip = 1;

            if (!DA.GetData(0, ref path))
            {
                return;
            }
            DA.GetData(1, ref recursive);
            DA.GetData(2, ref asMesh);
            DA.GetData(3, ref lineSkip);

            if (lineSkip < 1)
            {
                lineSkip = 1;
            }

            try
            {
                if (oldPath != path)
                {
                    oldPath  = path;
                    geometry = GetGeometricData(path);
                }

                DataTree <IGH_GeometricGoo> geo = new DataTree <IGH_GeometricGoo>();

                foreach (Tuple <int, ConcurrentQueue <IGH_GeometricGoo>, FileTypes> tuple in geometry)
                {
                    switch (tuple.Item3)
                    {
                    case FileTypes.XYZ:

                        if (asMesh)
                        {
                            ConcurrentQueue <Point3d> pp = new ConcurrentQueue <Point3d>();
                            Parallel.ForEach(tuple.Item2, (item, _, iNum) =>
                            {
                                if (iNum % lineSkip == 0)
                                {
                                    GH_Point p = new GH_Point();
                                    if (GH_Convert.ToGHPoint(item, GH_Conversion.Both, ref p))
                                    {
                                        pp.Enqueue(p.Value);
                                    }
                                }
                            });
                            Mesh mesh = new Mesh();
                            mesh.Vertices.AddVertices(pp);
                            try
                            {
                                Node2List              nodes     = new Node2List(pp);
                                List <Face>            faces     = Solver.Solve_Faces(nodes, 1);
                                IEnumerable <MeshFace> meshFaces = faces.Select(x => new MeshFace(x.A, x.B, x.C));
                                mesh.Faces.AddFaces(meshFaces);

                                ConcurrentQueue <IGH_GeometricGoo> goo = new ConcurrentQueue <IGH_GeometricGoo>();
                                goo.Enqueue(GH_Convert.ToGeometricGoo(mesh));
                                geo.AddRange(goo, new GH_Path(tuple.Item1));
                            }
                            catch (Exception e)
                            {
                                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                            }
                        }
                        else
                        {
                            ConcurrentQueue <IGH_GeometricGoo> goo = new ConcurrentQueue <IGH_GeometricGoo>();
                            Parallel.ForEach(tuple.Item2, (item, _, iNum) =>
                            {
                                if (iNum % lineSkip == 0)
                                {
                                    goo.Enqueue(item);
                                }
                            });
                            geo.AddRange(goo, new GH_Path(tuple.Item1));
                        }
                        break;
                    }
                }
                DA.SetDataTree(0, geo);
            }
            catch (Exception e)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
            }
        }
Exemplo n.º 4
0
        public override bool CastTo <Q>(ref Q target)
        {
            // This function is called when Grasshopper needs to convert this
            // instance of GsaLoad into some other type Q.


            if (typeof(Q).IsAssignableFrom(typeof(GsaLoad)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    target = (Q)(object)Value.Duplicate();
                }
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GsaGridPlaneSurfaceGoo)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    if (Value.AreaLoad != null)
                    {
                        GsaGridPlaneSurface    gridplane = Value.AreaLoad.GridPlaneSurface;
                        GsaGridPlaneSurfaceGoo gpgoo     = new GsaGridPlaneSurfaceGoo(gridplane);
                        target = (Q)(object)gpgoo;
                        return(true);
                    }
                    if (Value.LineLoad != null)
                    {
                        GsaGridPlaneSurface    gridplane = Value.LineLoad.GridPlaneSurface;
                        GsaGridPlaneSurfaceGoo gpgoo     = new GsaGridPlaneSurfaceGoo(gridplane);
                        target = (Q)(object)gpgoo;
                        return(true);
                    }
                    if (Value.PointLoad != null)
                    {
                        GsaGridPlaneSurface    gridplane = Value.PointLoad.GridPlaneSurface;
                        GsaGridPlaneSurfaceGoo gpgoo     = new GsaGridPlaneSurfaceGoo(gridplane);
                        target = (Q)(object)gpgoo;
                        return(true);
                    }
                }
                return(true);
            }

            if (typeof(Q).IsAssignableFrom(typeof(GH_Plane)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    if (Value.LoadType == GsaLoad.LoadTypes.GridArea)
                    {
                        GH_Plane ghpln = new GH_Plane();
                        GH_Convert.ToGHPlane(Value.AreaLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln);
                        target = (Q)(object)ghpln;
                        return(true);
                    }
                    if (Value.LoadType == GsaLoad.LoadTypes.GridLine)
                    {
                        GH_Plane ghpln = new GH_Plane();
                        GH_Convert.ToGHPlane(Value.LineLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln);
                        target = (Q)(object)ghpln;
                        return(true);
                    }
                    if (Value.LoadType == GsaLoad.LoadTypes.GridPoint)
                    {
                        GH_Plane ghpln = new GH_Plane();
                        GH_Convert.ToGHPlane(Value.PointLoad.GridPlaneSurface.Plane, GH_Conversion.Both, ref ghpln);
                        target = (Q)(object)ghpln;
                        return(true);
                    }
                }
                return(false);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GH_Point)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    if (Value.LoadType == GsaLoad.LoadTypes.GridPoint)
                    {
                        Point3d point = new Point3d
                        {
                            X = Value.PointLoad.GridPointLoad.X,
                            Y = Value.PointLoad.GridPointLoad.Y,
                            Z = Value.PointLoad.GridPlaneSurface.Plane.OriginZ
                        };
                        GH_Point ghpt = new GH_Point();
                        GH_Convert.ToGHPoint(point, GH_Conversion.Both, ref ghpt);
                        target = (Q)(object)ghpt;
                        return(true);
                    }
                }
                return(false);
            }
            if (typeof(Q).IsAssignableFrom(typeof(GH_Curve)))
            {
                if (Value == null)
                {
                    target = default;
                }
                else
                {
                    if (Value.LoadType == GsaLoad.LoadTypes.GridLine)
                    {
                        List <Point3d> pts = new List <Point3d>();
                        string         def = Value.LineLoad.GridLineLoad.PolyLineDefinition; //implement converter
                        // to be done
                        //target = (Q)(object)ghpt;
                        //return true;
                    }
                }
                return(false);
            }

            target = default;
            return(false);
        }
Exemplo n.º 5
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)
        {
            bool IsPointData = false;

            GH_Structure <IGH_Goo> data = new GH_Structure <IGH_Goo>();
            List <double>          eps  = new List <double>();
            List <int>             minP = new List <int>();

            if (!DA.GetDataTree(0, out data))
            {
                return;
            }
            if (!DA.GetDataList(1, eps))
            {
                return;
            }
            if (!DA.GetDataList(2, minP))
            {
                return;
            }

            data.Simplify(GH_SimplificationMode.CollapseAllOverlaps);

            List <DataSetItemPoint[]> points = new List <DataSetItemPoint[]>();

            for (int i = 0; i < data.Branches.Count; i++)
            {
                DataSetItemPoint[] pp = new DataSetItemPoint[data.Branches[i].Count];

                for (int j = 0; j < data.Branches[i].Count; j++)
                {
                    if (data.Branches[i][j] is GH_Point)
                    {
                        IsPointData = true;
                        GH_Point target = new GH_Point();
                        if (GH_Convert.ToGHPoint(data.Branches[i][j], GH_Conversion.Both, ref target))
                        {
                            pp[j] = new DataSetItemPoint(target.Value.X, target.Value.Y, target.Value.Z, 0.0);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (IsPointData)
                {
                    points.Add(pp);
                }
                else
                {
                    break;
                }
            }

            // double data
            if (!IsPointData)
            {
                DataSetItemPoint[] pp = new DataSetItemPoint[data.Branches.Count];

                for (int i = 0; i < data.Branches.Count; i++)
                {
                    DataSetItemPoint p = new DataSetItemPoint();
                    for (int j = 0; j < data.Branches[i].Count; j++)
                    {
                        if (data.Branches[i][j] is GH_Number)
                        {
                            if (GH_Convert.ToDouble(data.Branches[i][j], out double value, GH_Conversion.Both))
                            {
                                switch (j)
                                {
                                case 0:
                                    p.X = value;
                                    break;

                                case 1:
                                    p.Y = value;
                                    break;

                                case 2:
                                    p.Z = value;
                                    break;

                                case 3:
                                    p.W = value;
                                    break;
                                }
                            }
                        }
                    }
                    pp[i] = p;
                }
                points.Add(pp);
            }

            if (IsPointData)
            {
                DataTree <IGH_Goo> output = new DataTree <IGH_Goo>();

                for (int i = 0; i < points.Count; i++)
                {
                    DbscanAlgorithm <DataSetItemPoint> dbs = new DbscanAlgorithm <DataSetItemPoint>((x, y) => Math.Sqrt(((x.X - y.X) * (x.X - y.X)) + ((x.Y - y.Y) * (x.Y - y.Y)) + ((x.Z - y.Z) * (x.Z - y.Z)) + ((x.W - y.W) * (x.W - y.W))));
                    dbs.ComputeClusterDbscan(points[i].ToArray(), eps[i], minP[i], out HashSet <DataSetItemPoint[]> clusters3d);

                    for (int j = 0; j < clusters3d.Count; j++)
                    {
                        ConcurrentQueue <GH_Point> _points = new ConcurrentQueue <GH_Point>();
                        Parallel.ForEach(clusters3d.ElementAt(j), p =>
                        {
                            _points.Enqueue(new GH_Point(new Point3d(p.X, p.Y, p.Z)));
                        });

                        output.AddRange(_points.ToList(), new GH_Path(i, j));
                    }
                }

                DA.SetDataTree(0, output);
            }
            else
            {
                DataTree <GH_Number> output = new DataTree <GH_Number>();

                for (int i = 0; i < points.Count; i++)
                {
                    DbscanAlgorithm <DataSetItemPoint> dbs = new DbscanAlgorithm <DataSetItemPoint>((x, y) => Math.Sqrt(((x.X - y.X) * (x.X - y.X)) + ((x.Y - y.Y) * (x.Y - y.Y)) + ((x.Z - y.Z) * (x.Z - y.Z)) + ((x.W - y.W) * (x.W - y.W))));
                    dbs.ComputeClusterDbscan(points[i].ToArray(), eps[i], minP[i], out HashSet <DataSetItemPoint[]> clusters3d);

                    for (int j = 0; j < clusters3d.Count; j++)
                    {
                        ConcurrentQueue <List <double> > _points = new ConcurrentQueue <List <double> >();

                        for (int k = 0; k < clusters3d.ElementAt(j).Length; k++)
                        {
                            List <GH_Number> ii      = new List <GH_Number>();
                            GH_Number        target1 = new GH_Number();
                            GH_Number        target2 = new GH_Number();
                            GH_Number        target3 = new GH_Number();
                            GH_Number        target4 = new GH_Number();
                            if (GH_Convert.ToGHNumber(clusters3d.ElementAt(j).ElementAt(k).X, GH_Conversion.Both, ref target1))
                            {
                                ii.Add(target1);
                            }
                            if (GH_Convert.ToGHNumber(clusters3d.ElementAt(j).ElementAt(k).Y, GH_Conversion.Both, ref target2))
                            {
                                ii.Add(target2);
                            }
                            if (GH_Convert.ToGHNumber(clusters3d.ElementAt(j).ElementAt(k).Z, GH_Conversion.Both, ref target3))
                            {
                                ii.Add(target3);
                            }
                            if (GH_Convert.ToGHNumber(clusters3d.ElementAt(j).ElementAt(k).W, GH_Conversion.Both, ref target4))
                            {
                                ii.Add(target4);
                            }

                            output.AddRange(ii, new GH_Path(i, j, k));
                        }
                    }
                }
                DA.SetDataTree(0, output);
            }
        }
Exemplo n.º 6
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)
        {
            if (!this.Hidden)
            {
                try
                {
                    m_display.Clear();
                }
                catch
                {
                    m_display = new CustomDisplay(true);
                }
                GH_Structure <IGH_GeometricGoo> geo = new GH_Structure <IGH_GeometricGoo>();
                List <Color> colors = new List <Color>();
                int          style  = 4;
                int          size   = 1;

                if (!DA.GetDataTree(0, out geo))
                {
                    return;
                }
                if (!DA.GetDataList(1, colors))
                {
                    return;
                }
                DA.GetData(2, ref style);
                DA.GetData(3, ref size);
                try
                {
                    geo.Simplify(GH_SimplificationMode.CollapseAllOverlaps);

                    if (geo.Branches.Count == colors.Count)
                    {
                        for (int i = 0; i < geo.Branches.Count; i++)
                        {
                            ConcurrentQueue <Point3d> points = new ConcurrentQueue <Point3d>();

                            // Testing first object
                            if (geo.Branches[i][0] is GH_Point)
                            {
                                Parallel.ForEach(geo.Branches[i], obj =>
                                {
                                    if (obj is GH_Point)
                                    {
                                        GH_Point p = new GH_Point();
                                        if (GH_Convert.ToGHPoint(obj, GH_Conversion.Both, ref p))
                                        {
                                            points.Enqueue(new Point3d(p.Value.X, p.Value.Y, p.Value.Z));
                                        }
                                    }
                                });
                            }
                            // Testing for mesh
                            else if (geo.Branches[i][0].TypeName == "Mesh")
                            {
                                Parallel.ForEach(geo.Branches[i], obj =>
                                {
                                    if (obj.TypeName == "Mesh")
                                    {
                                        Mesh m = new Mesh();
                                        if (GH_Convert.ToMesh(obj, ref m, GH_Conversion.Both))
                                        {
                                            points = new ConcurrentQueue <Point3d>(m.Vertices.ToPoint3dArray());
                                        }
                                    }
                                });
                            }

                            PointStyle pointStyle = (PointStyle)style;
                            m_display.AddPoints(points, colors[i], pointStyle, size);
                        }
                    }
                    else
                    {
                        this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Data input incorrect!");
                    }
                }
                catch (Exception e)
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                }
            }
        }
Exemplo n.º 7
0
        /*******************************************/

        public static bool CastToGoo(object value, ref GH_Point target)
        {
            return(GH_Convert.ToGHPoint(value, GH_Conversion.Both, ref target));
        }
Exemplo n.º 8
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 <IGH_GeometricGoo> geo = new List <IGH_GeometricGoo>();

            if (!DA.GetDataList(0, geo))
            {
                return;
            }
            if (!DA.GetData(1, ref constraint_X))
            {
                return;
            }
            if (!DA.GetData(2, ref constraint_Y))
            {
                return;
            }
            if (!DA.GetData(3, ref constraint_Z))
            {
                return;
            }
            if (!DA.GetData(4, ref constraint_RX))
            {
                return;
            }
            if (!DA.GetData(5, ref constraint_RY))
            {
                return;
            }
            if (!DA.GetData(6, ref constraint_RZ))
            {
                return;
            }
            DA.GetData(7, ref scale);


            DataTree <IGH_GeometricGoo> symbols = new DataTree <IGH_GeometricGoo>();

            for (int i = 0; i < geo.Count; i++)
            {
                Point3d p = new Point3d();

                if (geo[i] is Point3d)
                {
                    if (!GH_Convert.ToPoint3d(geo[i], ref p, GH_Conversion.Both))
                    {
                        return;
                    }
                }
                else if (geo[i] is GH_Point)
                {
                    GH_Point ghP = new GH_Point();

                    if (GH_Convert.ToGHPoint(geo[i], GH_Conversion.Both, ref ghP))
                    {
                        p = ghP.Value;
                    }
                    else
                    {
                        return;
                    }
                }

                double radius = scale / 8.0;

                Sphere s1 = new Sphere(p, radius);

                double pX = radius * Math.Sin(Math.PI / 4) * Math.Cos(Math.PI / 4);
                double pY = radius * Math.Sin(Math.PI / 4) * Math.Sin(Math.PI / 4);
                double pZ = radius * Math.Cos(Math.PI / 4);

                double pX0 = radius * Math.Sin(Math.PI / 4) * Math.Cos(0);
                double pY0 = radius * Math.Sin(0) * Math.Sin(Math.PI / 4);

                Point3d p01 = new Point3d(p.X - pX0, p.Y - pY0, p.Z - pZ);
                Point3d p02 = new Point3d(p.X + pX0, p.Y - pY0, p.Z - pZ);
                Point3d p03 = new Point3d(p.X + pX0, p.Y + pY0, p.Z - pZ);
                Point3d p04 = new Point3d(p.X - pX0, p.Y + pY0, p.Z - pZ);

                Point3d p11 = new Point3d(p.X - pX, p.Y - pY, p.Z - pZ);
                Point3d p12 = new Point3d(p.X + pX, p.Y - pY, p.Z - pZ);
                Point3d p13 = new Point3d(p.X + pX, p.Y + pY, p.Z - pZ);
                Point3d p14 = new Point3d(p.X - pX, p.Y + pY, p.Z - pZ);

                Point3d p21 = new Point3d(p.X - scale / 2.0, p.Y - scale / 2.0, p.Z - scale / 2.0);
                Point3d p22 = new Point3d(p.X + scale / 2.0, p.Y - scale / 2.0, p.Z - scale / 2.0);
                Point3d p23 = new Point3d(p.X + scale / 2.0, p.Y + scale / 2.0, p.Z - scale / 2.0);
                Point3d p24 = new Point3d(p.X - scale / 2.0, p.Y + scale / 2.0, p.Z - scale / 2.0);

                Line l1 = new Line(p11, p21);
                Line l2 = new Line(p12, p22);
                Line l3 = new Line(p13, p23);
                Line l4 = new Line(p14, p24);

                Line l5 = new Line(p21, p22);
                Line l6 = new Line(p22, p23);
                Line l7 = new Line(p23, p24);
                Line l8 = new Line(p24, p21);

                Arc a1 = new Arc(p11, p01, p12);
                Arc a2 = new Arc(p12, p02, p13);
                Arc a3 = new Arc(p13, p03, p14);
                Arc a4 = new Arc(p14, p04, p11);

                List <Curve> c1 = new List <Curve>()
                {
                    l1.ToNurbsCurve(), l2.ToNurbsCurve(), l5.ToNurbsCurve(), a3.ToNurbsCurve()
                };
                List <Curve> c2 = new List <Curve>()
                {
                    l2.ToNurbsCurve(), l3.ToNurbsCurve(), l6.ToNurbsCurve(), a2.ToNurbsCurve()
                };
                List <Curve> c3 = new List <Curve>()
                {
                    l3.ToNurbsCurve(), l4.ToNurbsCurve(), l7.ToNurbsCurve(), a1.ToNurbsCurve()
                };
                List <Curve> c4 = new List <Curve>()
                {
                    l4.ToNurbsCurve(), l1.ToNurbsCurve(), l8.ToNurbsCurve(), a4.ToNurbsCurve()
                };

                Brep b1 = Brep.CreateEdgeSurface(c1);
                Brep b2 = Brep.CreateEdgeSurface(c2);
                Brep b3 = Brep.CreateEdgeSurface(c3);
                Brep b4 = Brep.CreateEdgeSurface(c4);

                symbols.Add(GH_Convert.ToGeometricGoo(s1), new GH_Path(i));

                symbols.Add(GH_Convert.ToGeometricGoo(l1), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(l2), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(l3), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(l4), new GH_Path(i));

                symbols.Add(GH_Convert.ToGeometricGoo(l5), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(l6), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(l7), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(l8), new GH_Path(i));

                symbols.Add(GH_Convert.ToGeometricGoo(b1), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(b2), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(b3), new GH_Path(i));
                symbols.Add(GH_Convert.ToGeometricGoo(b4), new GH_Path(i));
            }
            DA.SetDataTree(0, symbols);
        }
Exemplo n.º 9
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)
        {
            int  i, j, k;
            bool IsPointData = false;

            GH_Structure <IGH_Goo>          data = new GH_Structure <IGH_Goo>();
            GH_Structure <IGH_GeometricGoo> geo  = new GH_Structure <IGH_GeometricGoo>();
            List <int> numCluster = new List <int>();

            if (!DA.GetDataTree(0, out data))
            {
                return;
            }
            if (!DA.GetDataTree(1, out geo))
            {
                return;
            }
            if (!DA.GetDataList(2, numCluster))
            {
                return;
            }

            data.Simplify(GH_SimplificationMode.CollapseAllOverlaps);
            DataTree <IGH_Goo>          outputData      = new DataTree <IGH_Goo>();
            DataTree <IGH_GeometricGoo> outputGeo       = new DataTree <IGH_GeometricGoo>();
            DataTree <Point3d>          outputCentroids = new DataTree <Point3d>();

            for (i = 0; i < data.Branches.Count; i++)
            {
                double[] x = new double[data.Branches[i].Count];
                double[] y = new double[data.Branches[i].Count];
                double[] z = new double[data.Branches[i].Count];

                for (j = 0; j < data.Branches[i].Count; j++)
                {
                    if (data.Branches[i][j] is GH_Point)
                    {
                        IsPointData = true;
                        GH_Point target = new GH_Point();

                        if (GH_Convert.ToGHPoint(data.Branches[i][j], GH_Conversion.Both, ref target))
                        {
                            x[j] = target.Value.X;
                            y[j] = target.Value.Y;
                            z[j] = target.Value.Z;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (IsPointData)
                {
                    List <double[]> datalist = new List <double[]>
                    {
                        x,
                        y,
                        z
                    };
                    double[][] _data = ArrayConvert.To2DArray(datalist);

                    KMeans m = new KMeans(numCluster[i]);
                    KMeansClusterCollection cluster = m.Learn(_data);

                    int[]      labels    = cluster.Decide(_data);
                    double[][] centroids = m.Centroids;

                    for (j = 0; j < data.Branches[i].Count; j++)
                    {
                        GH_Path path = new GH_Path(i, labels[j]);
                        outputData.Add(data.Branches[i][j], path);
                        outputGeo.Add(geo.Branches[i][j], path);
                    }

                    for (k = 0; k < centroids.Length; k++)
                    {
                        outputCentroids.Add(new Point3d(centroids.ElementAt(k).ElementAt(0), centroids.ElementAt(k).ElementAt(1), centroids.ElementAt(k).ElementAt(2)), new GH_Path(k));
                    }
                }
                else
                {
                    break;
                }
            }

            if (!IsPointData)
            {
                GH_Path oldPath        = new GH_Path();
                GH_Path newPath        = new GH_Path();
                int     DataGroupCount = 0;

                for (i = 0; i < data.PathCount; i++)
                {
                    if (data.Paths[i].Indices.Length == 1)
                    {
                        DataGroupCount = 1;
                        break;
                    }
                    else
                    {
                        int[] pp = new int[data.Paths[i].Indices.Length - 1];

                        for (j = 0; j < data.Paths[i].Indices.Length - 1; j++)
                        {
                            pp[j] = data.Paths[i].Indices[j];
                        }
                        newPath.Indices = pp;

                        if (newPath != oldPath)
                        {
                            DataGroupCount++;
                            oldPath = newPath;
                        }
                        newPath = new GH_Path();
                    }
                }

                for (i = 0; i < DataGroupCount; i++)
                {
                    List <double[]> datalist = new List <double[]>();

                    for (j = 0; j < data.Branches.Count / DataGroupCount; j++)
                    {
                        double[] values = new double[data.Branches[DataGroupCount * i + j].Count];

                        for (k = 0; k < data.Branches[DataGroupCount * i + j].Count; k++)
                        {
                            if (data.Branches[DataGroupCount * i + j][k] is GH_Number)
                            {
                                if (GH_Convert.ToDouble(data.Branches[DataGroupCount * i + j][k], out double value, GH_Conversion.Both))
                                {
                                    values[k] = value;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        datalist.Add(values);
                    }
                    double[][] _data = ArrayConvert.ToDoubleArray(datalist);

                    KMeans m = new KMeans(numCluster[0]);
                    KMeansClusterCollection cluster = m.Learn(_data);

                    int[] labels = cluster.Decide(_data);

                    for (j = 0; j < labels.Length; j++)
                    {
                        List <IGH_Goo>          numbers = new List <IGH_Goo>();
                        List <IGH_GeometricGoo> geos    = new List <IGH_GeometricGoo>();

                        for (k = 0; k < data.Branches[DataGroupCount * i + j].Count; k++)
                        {
                            numbers.Add(data.Branches[DataGroupCount * i + j][k]);
                            geos.Add(geo.Branches[DataGroupCount * i + j][k]);
                        }

                        GH_Path path = new GH_Path(i, j, labels[j]);
                        outputData.AddRange(numbers, path);
                        outputGeo.AddRange(geos, path);
                    }
                }
            }
            DA.SetDataTree(0, outputData);
            DA.SetDataTree(1, outputGeo);
            DA.SetDataTree(2, outputCentroids);
        }