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)
        {
            ///define i/o parameters
            PointCloud Rhino_Cloud = new PointCloud();

            /// read inputs
            if (!DA.GetData("Point_Cloud", ref Rhino_Cloud))
            {
                return;
            }
            if (!DA.GetData("k", ref k))
            {
                return;
            }

            /// interal parameters
            var           Rhino_xyz = Rhino_Cloud.GetPoints();
            List <double> xyz       = new List <double>();

            if (!Rhino_Cloud.ContainsNormals)
            {
                for (int i = 0; i < Rhino_Cloud.Count; i++)
                {
                    xyz.Add(Rhino_xyz[i].X);
                    xyz.Add(Rhino_xyz[i].Y);
                    xyz.Add(Rhino_xyz[i].Z);
                }
            }

            ///2.
            var Matlab_xyz = new MWNumericArray(Rhino_Cloud.Count, 3, xyz.ToArray());



            /// 3.
            Segmentation.segment segment_mesh = new Segmentation.segment();

            MWArray array = new MWNumericArray();

            array = pointcloudutilities.G_compute_normals(Matlab_xyz, k);

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

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

            /// 5.%£%/:
            Resolution = dc[0];

            /// 6.
            DA.SetData(0, Resolution);
        }
Beispiel #2
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)
        {
            ///define i/o parameters
            PointCloud Rhino_Cloud = new PointCloud();
            double     Samples     = new double();
            double     Resolution  = new double();

            /// read inputs
            if (!DA.GetData("Point_Cloud", ref Rhino_Cloud))
            {
                return;
            }
            if (!DA.GetData("Samples", ref Samples))
            {
                return;
            }

            /// interal parameters
            var           Rhino_xyz = Rhino_Cloud.GetPoints();
            List <double> xyz       = new List <double>();

            for (int i = 0; i < Rhino_Cloud.Count; i++)
            {
                xyz.Add(Rhino_xyz[i].X);
                xyz.Add(Rhino_xyz[i].Y);
                xyz.Add(Rhino_xyz[i].Z);
            }

            ///2.
            var Matlab_samples = new MWNumericArray(Samples);
            var Matlab_xyz     = new MWNumericArray(Rhino_Cloud.Count, 3, xyz.ToArray());


            /// 3.
            Segmentation.segment segment_mesh = new Segmentation.segment();

            MWArray cluster = new MWNumericArray();

            cluster = segment_mesh.G_Resolution_PCD(Matlab_xyz, Matlab_samples);

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

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

            /// 5.%£%/:
            Resolution = dc[0];

            /// 6.
            DA.SetData(0, Resolution);
        }
Beispiel #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)
        {
            ///define i/o parameters
            PointCloud    Rhino_Cloud   = new PointCloud();
            List <double> Rhino_indices = new List <double>();

            /// initialise internal parameters
            double T_N = 0.0, T_C = 0.0, D = 0.0, M = 0.0, O = 0.0, T_s = 0.0;


            if (!DA.GetData("Point_Cloud", ref Rhino_Cloud))
            {
                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;
            }
            if (!DA.GetData("Tilesize", ref T_s))
            {
                return;
            }

            /// 1. decompose PCD into vertices, normals (rhinocommon => .NET)
            /// 1a. retrieve/construct colors
            /// 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

            var Rhino_xyz = Rhino_Cloud.GetPoints();
            var Rhino_n   = Rhino_Cloud.GetNormals();
            var Rhino_c   = Rhino_Cloud.GetColors();

            List <double>  xyz      = new List <double>();
            List <double>  n        = new List <double>();
            List <double>  c        = new List <double>();
            MWNumericArray Matlab_n = new MWNumericArray();
            MWNumericArray Matlab_c = new MWNumericArray();

            for (int i = 0; i < Rhino_Cloud.Count; i++)
            {
                xyz.Add(Rhino_xyz[i].X);
                xyz.Add(Rhino_xyz[i].Y);
                xyz.Add(Rhino_xyz[i].Z);
            }


            if (Rhino_Cloud.ContainsNormals == true)
            {
                for (int i = 0; i < Rhino_Cloud.Count; i++)
                {
                    n.Add(Rhino_n[i].X);
                    n.Add(Rhino_n[i].Y);
                    n.Add(Rhino_n[i].Z);
                }
                Matlab_n = new MWNumericArray(Rhino_Cloud.Count, 3, n.ToArray());
            }


            if (Rhino_Cloud.ContainsColors == true)
            {
                for (int i = 0; i < Rhino_Cloud.Count; i++)
                {
                    c.Add(Rhino_c[i].R);
                    c.Add(Rhino_c[i].G);
                    c.Add(Rhino_c[i].B);
                }
                Matlab_c = new MWNumericArray(Rhino_Cloud.Count, 3, c.ToArray());
            }


            ///2.
            var Matlab_xyz = new MWNumericArray(Rhino_Cloud.Count, 3, xyz.ToArray());


            /// 3.
            Segmentation.segment segment_mesh = new Segmentation.segment();

            MWArray cluster = new MWNumericArray();

            cluster = segment_mesh.G_RegionGrowingNC2(Matlab_xyz, Matlab_n, Matlab_c, T_N, T_C, 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);
        }
        /// <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)
        {
            ///define i/o parameters
            PointCloud Rhino_Cloud = new PointCloud();
            Double     k           = 6;

            /// read inputs
            if (!DA.GetData(0, ref Rhino_Cloud))
            {
                return;
            }
            if (!DA.GetData("k", ref k))
            {
                return;
            }


            if (Rhino_Cloud.Count <= k)
            {
                throw new Size_Exception(string.Format("Use point clouds with more than k points"));
            }

            /// interal parameters
            List <Vector3d> normals = new List <Vector3d>();

            if (!Rhino_Cloud.ContainsNormals)
            {
                var X = Rhino_Cloud.Select(x => x.X).ToList();
                var Y = Rhino_Cloud.Select(x => x.Y).ToList();
                var Z = Rhino_Cloud.Select(x => x.Z).ToList();

                ///2.
                var Matlab_X = new MWNumericArray(Rhino_Cloud.Count, 1, X.ToArray());
                var Matlab_Y = new MWNumericArray(Rhino_Cloud.Count, 1, Y.ToArray());
                var Matlab_Z = new MWNumericArray(Rhino_Cloud.Count, 1, Z.ToArray());

                /// 3.
                Segmentation.segment segment_mesh = new Segmentation.segment();

                var mwca = (MWCellArray)segment_mesh.G_Normals(Matlab_X, Matlab_Y, Matlab_Z, k);

                /// 4.
                MWNumericArray na0 = (MWNumericArray)mwca[1];
                double[]       dc0 = (double[])na0.ToVector(0);

                MWNumericArray na1 = (MWNumericArray)mwca[2];
                double[]       dc1 = (double[])na1.ToVector(0);

                MWNumericArray na2 = (MWNumericArray)mwca[3];
                double[]       dc2 = (double[])na2.ToVector(0);


                /// 5.
                var      Rhino_param0 = new List <double>(dc0);
                var      Rhino_param1 = new List <double>(dc1);
                var      Rhino_param2 = new List <double>(dc2);
                Vector3d R            = new Vector3d();
                for (int i = 0; i < Rhino_param0.Count; i++)
                {
                    R = new Vector3d(Rhino_param0[i], Rhino_param1[i], Rhino_param2[i]);
                    normals.Add(R);
                }
            }

            else
            {
                normals = Rhino_Cloud.GetNormals().ToList();
            }

            PointCloud Rhino_Cloud_out = new PointCloud();

            Rhino_Cloud_out.AddRange(Rhino_Cloud.GetPoints(), normals);
            GH_Cloud Rhino_Cloud_out2 = new GH_Cloud(Rhino_Cloud_out);

            /// 6.
            DA.SetData(0, Rhino_Cloud_out2);
        }