Esempio n. 1
0
            public IEnumerator <byte[]> GetEnumerator()
            {
                var iter = PointIndices.GetEnumerator();

                while (iter.MoveNext())
                {
                    yield return(_points[iter.Current]);
                }
            }
        public unsafe void PlanarSegmentationTutorialTest()
        {
            using (var cloud = new PointCloudOfXYZ())
            {
                cloud.Width  = 15;
                cloud.Height = 1;
                cloud.Points.Resize(cloud.Width * cloud.Height);

                for (var i = 0; i < cloud.Points.Count; i++)
                {
                    (cloud.Data + i)->X = 1024 * rand();
                    (cloud.Data + i)->Y = 1024 * rand();
                    (cloud.Data + i)->Z = 1;
                }

                //set a few outliers
                (cloud.Data + 0)->Z = 2f;
                (cloud.Data + 3)->Z = -2f;
                (cloud.Data + 6)->Z = 4f;

                using (var seg = new SACSegmentationOfXYZ())
                    using (var inliers = new PointIndices())
                        using (var coefficients = new ModelCoefficients())
                        {
                            seg.OptimizeCoefficients = true;
                            seg.ModelType            = SACModel.Plane;
                            seg.MethodType           = SACMethod.RANSAC;
                            seg.DistanceThreshold    = 0.01;

                            seg.SetInputCloud(cloud);
                            seg.Segment(inliers, coefficients);

                            if (inliers.Indices.Count == 0)
                            {
                                Assert.Fail("Could not estimate a planar model for the given dataset");
                            }

                            Assert.AreEqual(4, coefficients.Values.Count);
                            Assert.AreEqual(0, coefficients.Values[0]);
                            Assert.AreEqual(0, coefficients.Values[1]);
                            Assert.AreEqual(1, coefficients.Values[2]);
                            Assert.AreEqual(-1, coefficients.Values[3]);

                            Console.WriteLine($"Model inliers: {inliers.Indices.Count}");
                        }
            }
        }
 public override void Segment(PointIndices inliers, ModelCoefficients coefficients)
 {
     Invoke.segmentation_sacsegmentation_xyz_segment(_ptr, inliers, coefficients);
 }
Esempio n. 4
0
 public void AddPoint(uint pointInd)
 {
     PointIndices.Add(pointInd);
 }
Esempio n. 5
0
 public void ClearPoints()
 {
     PointIndices.Clear();
 }
Esempio n. 6
0
 public abstract void GetHullPointIndices(PointIndices indices);
Esempio n. 7
0
 public abstract void Segment(PointIndices inliers, ModelCoefficients coefficients);
Esempio n. 8
0
        public void ClusterExtractionTutorialTest()
        {
            using (var cloud = new PointCloudOfXYZ())
                using (var clusterIndices = new VectorOfPointIndices())
                {
                    using (var reader = new PCDReader())
                        reader.Read(DataPath("tutorials/table_scene_lms400.pcd"), cloud);

                    using (var vg = new VoxelGridOfXYZ())
                    {
                        vg.SetInputCloud(cloud);
                        vg.LeafSize = new Vector3(0.01f);

                        var cloudFiltered = new PointCloudOfXYZ();
                        vg.filter(cloudFiltered);


                        using (var seg = new SACSegmentationOfXYZ()
                        {
                            OptimizeCoefficients = true,
                            ModelType = SACModel.Plane,
                            MethodType = SACMethod.RANSAC,
                            MaxIterations = 100,
                            DistanceThreshold = 0.02f
                        })
                            using (var cloudPlane = new PointCloudOfXYZ())
                                using (var coefficients = new Common.ModelCoefficients())
                                    using (var inliers = new PointIndices())
                                    {
                                        int i        = 0;
                                        int nrPoints = cloudFiltered.Points.Count;

                                        while (cloudFiltered.Points.Count > 0.3 * nrPoints)
                                        {
                                            seg.SetInputCloud(cloudFiltered);
                                            seg.Segment(inliers, coefficients);
                                            if (inliers.Indices.Count == 0)
                                            {
                                                Assert.Fail("could not estimate a planar model for the given dataset");
                                            }

                                            using (var extract = new ExtractIndicesOfXYZ()
                                            {
                                                Negative = false
                                            })
                                            {
                                                extract.SetInputCloud(cloudFiltered);
                                                extract.SetIndices(inliers.Indices);

                                                extract.filter(cloudPlane);

                                                extract.Negative = true;
                                                var cloudF = new PointCloudOfXYZ();
                                                extract.filter(cloudF);

                                                cloudFiltered.Dispose();
                                                cloudFiltered = cloudF;
                                            }

                                            i++;
                                        }

                                        Assert.IsTrue(i > 1, "Didn't find more than 1 plane");
                                        var tree = new Search.KdTreeOfXYZ();
                                        tree.SetInputCloud(cloudFiltered);

                                        using (var ec = new EuclideanClusterExtractionOfXYZ
                                        {
                                            ClusterTolerance = 0.02,
                                            MinClusterSize = 100,
                                            MaxClusterSize = 25000
                                        })
                                        {
                                            ec.SetSearchMethod(tree);
                                            ec.SetInputCloud(cloudFiltered);
                                            ec.Extract(clusterIndices);
                                        }

                                        foreach (var pis in clusterIndices)
                                        {
                                            using (var cloudCluster = new PointCloudOfXYZ())
                                            {
                                                foreach (var pit in pis.Indices)
                                                {
                                                    cloudCluster.Add(cloudFiltered.Points[pit]);
                                                }

                                                cloudCluster.Width  = cloudCluster.Points.Count;
                                                cloudCluster.Height = 1;
                                            }
                                        }
                                    }
                    }
                }
        }
 public override void GetHullPointIndices(PointIndices indices)
 => Invoke.surface_convexhull_xyz_getHullPointIndices(_ptr, indices);
Esempio n. 10
0
 public static extern void std_vector_pointindices_insert(IntPtr ptr, IntPtr idx, PointIndices value);
Esempio n. 11
0
 public static extern void std_vector_pointindices_add(IntPtr ptr, PointIndices value);