예제 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            ///input parameters
            List <Point3d> Rhino_points = new List <Point3d>();


            /// initialise parameters
            double        T_N = 0.0, D = 0.0, M = 0.0, O = 0.0, T_s = 0.0;
            List <double> Rhino_indices = new List <double>();
            List <double> Rhino_xyz     = new List <double>();

            ///import data
            if (!DA.GetDataList("Points", Rhino_points))
            {
                return;
            }
            if (!DA.GetData("ThresValN", ref T_N))
            {
                return;
            }
            if (!DA.GetData("MaxDist", ref D))
            {
                return;
            }
            if (!DA.GetData("Minsize", ref M))
            {
                return;
            }
            if (!DA.GetData("Offset", ref O))
            {
                return;
            }
            if (!DA.GetData("Tilesize", ref T_s))
            {
                return;
            }

            /// 1. decompose points into doubles (rhinocommon => .NET)
            /// 2. create appropriete matlab arrays (.NET => Matlab)
            /// 3. run matlab function (Matlab)
            /// 4. convert function output (list with indices) to .Net array (Matlab => .Net)
            /// 5. convert array to rhinocommon list. (.Net => Rhinocommon)
            /// 6. output data

            /// 1.
            for (int i = 0; i < Rhino_points.Count; i++)
            {
                Rhino_xyz[i * 3]     = Rhino_points[i].X;
                Rhino_xyz[i * 3 + 1] = Rhino_points[i].Y;
                Rhino_xyz[i * 3 + 2] = Rhino_points[i].Z;
            }

            /// 2.
            var Matlab_xyz = new MWNumericArray(Rhino_points.Count, 3, Rhino_xyz.ToArray());
            var Matlab_n   = new MWNumericArray();
            var Matlab_c   = new MWNumericArray();

            /// 3.
            Scan2BIM_Matlab.Segmentation segmentation = new Scan2BIM_Matlab.Segmentation();

            MWArray cluster = new MWNumericArray();

            cluster = segmentation.S2B_RegionGrowing_2(Matlab_xyz, Matlab_n, Matlab_c, T_N, D, M, O, T_s);

            /// 4.
            MWNumericArray na = (MWNumericArray)cluster;

            double[] dc = (double[])na.ToVector(0);

            /// 5.
            Rhino_indices = new List <double>(dc);

            /// 6.
            DA.SetDataList(0, Rhino_indices);
        }
예제 #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            ///input parameters
            Mesh Rhino_mesh = new Mesh();

            /// initialise parameters
            double        T_N = 0.0, T_C = 0.0, D = 0.0, M = 0.0, O = 0.0;
            List <double> Rhino_indices = new List <double>();

            ///import data
            if (!DA.GetData("Mesh", ref Rhino_mesh))
            {
                return;
            }
            if (!DA.GetData("ThresValN", ref T_N))
            {
                return;
            }
            if (!DA.GetData("ThresValC", ref T_C))
            {
                return;
            }
            if (!DA.GetData("MaxDist", ref D))
            {
                return;
            }
            if (!DA.GetData("Minsize", ref M))
            {
                return;
            }
            if (!DA.GetData("Offset", ref O))
            {
                return;
            }

            ///get mesh data to Matlab
            /// 1. decompose mesh into face centroids/normals (rhinocommon => .NET)
            /// 1a. compute normals if not present
            /// 2. create appropriete matlab arrays (.NET => Matlab)
            /// 3. run matlab function (Matlab)
            /// 4. convert function output (list with indices) to .Net array (Matlab => .Net)
            /// 5. convert array to rhinocommon list. (.Net => Rhinocommon)
            /// 6. output data

            /// 1.
            var Rhino_c = new Point3f();
            var Rhino_n = new Vector3f();
            var C_xyz   = new float[Rhino_mesh.Faces.Count * 3];
            var C_n     = new float[Rhino_mesh.Faces.Count * 3];

            ///1a. check if normals are present
            if (Rhino_mesh.FaceNormals.Count == 0)
            {
                Rhino_mesh.FaceNormals.ComputeFaceNormals();
            }

            /// 2.
            for (int i = 0; i < Rhino_mesh.Faces.Count; i++)
            {
                Rhino_c          = (Point3f)Rhino_mesh.Faces.GetFaceCenter(i);
                C_xyz[i * 3]     = Rhino_c.X;
                C_xyz[i * 3 + 1] = Rhino_c.Y;
                C_xyz[i * 3 + 2] = Rhino_c.Z;

                Rhino_n        = Rhino_mesh.FaceNormals[i];
                C_n[i * 3]     = Rhino_n.X;
                C_n[i * 3 + 1] = Rhino_n.Y;
                C_n[i * 3 + 2] = Rhino_n.Z;
            }

            var Matlab_xyz = new MWNumericArray(Rhino_mesh.Faces.Count, 3, C_xyz);
            var Matlab_n   = new MWNumericArray(Rhino_mesh.Faces.Count, 3, C_n);

            /// 3.
            Scan2BIM_Matlab.Segmentation segmentation = new Scan2BIM_Matlab.Segmentation();

            MWArray cluster = new MWNumericArray();

            cluster = segmentation.S2B_RegionGrowing_2(Matlab_xyz, Matlab_n, T_N, T_C, D, M, O);

            /// 4.
            MWNumericArray na = (MWNumericArray)cluster;

            double[] dc = (double[])na.ToVector(0);

            /// 5.
            Rhino_indices = new List <double>(dc);

            /// 6.
            DA.SetDataList(0, Rhino_indices);
        }