Exemple #1
0
        private static PointCloud PointCloudBW(CameraSpacePoint[] myRealWorldPoints, DepthMetaData myDepthMetaData, BodyMetaData myBodyMetaData)
        {
            int x = 0;
            int y = 0;
            // int indexVertex = 0;

            List <Vector3> list = new List <Vector3>();

            try
            {
                for (x = 0; x < DepthMetaData.XDepthMaxKinect; x++)
                {
                    for (y = 0; y < DepthMetaData.YDepthMaxKinect; y++)
                    {
                        int depthIndex = (y * DepthMetaData.XDepthMaxKinect) + x;
                        //int depthIndex = ((DepthMetaData.YResDefault - y - 1) * DepthMetaData.XResDefault) + x;

                        if (myDepthMetaData.FrameData[depthIndex] != 0)
                        {
                            int depthIndexColor = depthIndex * MetaDataBase.BYTES_PER_PIXEL;

                            Vector3 vect = new Vector3(myRealWorldPoints[depthIndex].X, myRealWorldPoints[depthIndex].Y, -myRealWorldPoints[depthIndex].Z);
                            list.Add(vect);
                        }
                    }
                }
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("..Debug : " + x.ToString() + " : " + y.ToString() + " : ");
            }
            return(PointCloud.FromListVector3(list));
        }
Exemple #2
0
        protected void CreateCube(int numberOfPoints)
        {
            List <Vector3> listVectors = ExamplePointClouds.Cuboid_Corners_CenteredAt0(1, 2, 1);

            this.pointCloudTarget = PointCloud.FromListVector3(listVectors);


            this.pointCloudSource = PointCloud.CloneAll(pointCloudTarget);
        }
        public void Cube_Corners()
        {
            List <Vector3> listVectors = ExamplePointClouds.Cuboid_Corners_CenteredAt0(1, 1, 1);
            PointCloud     pcl         = PointCloud.FromListVector3(listVectors);

            PointCloud.SetIndicesForCubeCorners(pcl);


            ShowPointCloudForOpenGL(pcl);
        }
Exemple #4
0
        public PointCloud ToPointCloud()
        {
            PointCloud pc = PointCloud.FromListVector3(this.Vectors);

            RearrangePointCloud(pc);


            pc.Name = "humanoid";
            pc.CalculateBoundingBox();
            //pc.Vectors = Vectors;
            return(pc);
        }
Exemple #5
0
        protected void CreateCuboid(float sizeX, float sizeY, float sizeZ)
        {
            List <Vector3> listVectors = ExamplePointClouds.Cuboid_Corners_CenteredAt0(sizeX, sizeY, sizeZ);

            this.pointCloudTarget = PointCloud.FromListVector3(listVectors);

            PointCloud.ResetToOriginAxis(pointCloudTarget);
            PointCloud.SetIndicesForCubeCorners(this.pointCloudTarget);

            this.pointCloudSource = pointCloudTarget.Clone();
            PointCloud.SetIndicesForCubeCorners(pointCloudSource);
        }
Exemple #6
0
        public void ShowModelWithoutFace()
        {
            string fileName = this.pathModels + "\\FaceMatching\\ModelWithoutFace.json";

            if (System.IO.File.Exists(fileName))
            {
                List <Vector3> listV = JsonUtils.DeserializeVectors(fileName);
                PointCloud     pc    = PointCloud.FromListVector3(listV);

                ShowPointCloud(pc);
            }
        }
Exemple #7
0
        public void Cube_ProjectedPoints()
        {
            this.pointCloudSource    = PointCloud.CreateCube_RegularGrid_Empty(cubeSizeX, 1);
            this.pointCloudAddition1 = PointCloud.CloneAll(pointCloudSource);

            pca.PCA_OfPointCloud(pointCloudSource);

            this.pointCloudSource = PointCloud.FromListVector3(pca.PointsResult0);
            this.pointCloudTarget = PointCloud.FromListVector3(pca.PointsResult1);
            this.pointCloudResult = PointCloud.FromListVector3(pca.PointsResult2);

            this.ShowResultsInWindow_Cube_ProjectedPoints(true);

            //Show4PointCloudsInWindow(true);
        }
Exemple #8
0
        public void Person()
        {
            this.pointCloudSource = new PointCloud(pathUnitTests + "\\1.obj");


            this.pointCloudAddition1 = pointCloudSource;

            pca.PCA_OfPointCloud(pointCloudSource);

            this.pointCloudSource = PointCloud.FromListVector3(pca.PointsResult0);
            this.pointCloudTarget = PointCloud.FromListVector3(pca.PointsResult1);
            this.pointCloudResult = PointCloud.FromListVector3(pca.PointsResult2);

            Show4PointCloudsInWindow(true);
        }
Exemple #9
0
        public void Person_Rotate_Projected()
        {
            this.pointCloudSource = new PointCloud(pathUnitTests + "\\1.obj");
            PointCloud.RotateDegrees(pointCloudSource, 25, 90, 25);


            this.pointCloudAddition1 = pointCloudSource;

            pca.PCA_OfPointCloud(pointCloudSource);

            this.pointCloudSource = PointCloud.FromListVector3(pca.PointsResult0);
            this.pointCloudTarget = PointCloud.FromListVector3(pca.PointsResult1);
            this.pointCloudResult = PointCloud.FromListVector3(pca.PointsResult2);

            Show4PointCloudsInWindow(true);
        }
Exemple #10
0
        public override PointCloudRenderable ToPointCloudRenderable(bool resizeTo1)
        {
            PointCloudRenderable pcr = new PointCloudRenderable();

            this.pointCloudBase = PointCloud.FromListVector3(this.DepthMetaData.Vectors);
            //SetDefaultColorForDepth();

            if (this.pointCloudBase != null && this.pointCloudBase.Vectors.Length > 0)
            {
                if (resizeTo1)
                {
                    pointCloudBase.ResizeTo1();
                }
                pcr.PointCloud = pointCloudBase;
                return(pcr);
            }
            return(null);
        }
Exemple #11
0
        public void Face_TranslateRotateScale()
        {
            this.pointCloudSource = new PointCloud(pathUnitTests + "\\KinectFace_1_15000.obj");
            PointCloud.RotateDegrees(pointCloudSource, 45, 45, 45);
            //Vertices.RotateVertices(pointCloudSource, 60, 60, 90);
            PointCloud.ScaleByFactor(pointCloudSource, 0.9f);
            PointCloud.Translate(pointCloudSource, 0.3f, 0.5f, -0.4f);

            this.pointCloudAddition1 = pointCloudSource;

            pca.PCA_OfPointCloud(pointCloudSource);


            this.pointCloudSource = PointCloud.FromListVector3(pca.PointsResult0);
            this.pointCloudTarget = PointCloud.FromListVector3(pca.PointsResult1);
            this.pointCloudResult = PointCloud.FromListVector3(pca.PointsResult2);

            Show4PointCloudsInWindow(true);
        }
Exemple #12
0
        public override bool SavePointCloud(string fileName)
        {
            if (this.DepthMetaData.Vectors != null)
            {
                //PointCloud pcTest = PointCloud.FromVector3List(this.depthVectors);

                PointCloud pc = PointCloud.FromListVector3(this.DepthMetaData.Vectors);
                if (pc != null)
                {
                    UtilsPointCloudIO.ToObjFile_ColorInVertex(pc, PathModels, fileName);
                }
                //UtilsPointCloudIO.ToObjFile(pc, PathModels, ImageExtensions.DateTimeString() + "PointCloud_" + this.scannerID.ToString() + ".obj");
                //UtilsPointCloudIO.Write_OBJ_Test(pc, pcTest, pathModels, "ObjTest" + this.RealSenseCameraNumber.ToString() + "_" + DateTime.Now.ToFileTimeUtc() + ".obj");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Nothing to save");
            }
            return(true);
        }
Exemple #13
0
        public void CuboidRotated_Projected()
        {
            float cubeSizeY      = 2;
            int   numberOfPoints = 3;


            this.pointCloudSource = ExamplePointClouds.Cuboid("Cuboid", cubeSizeX, cubeSizeY, numberOfPoints, System.Drawing.Color.White, null);
            PointCloud.RotateDegrees(pointCloudSource, 45, 45, 45);

            this.pointCloudAddition1 = PointCloud.CloneAll(pointCloudSource);

            pca.PCA_OfPointCloud(pointCloudSource);

            this.pointCloudSource = PointCloud.FromListVector3(pca.PointsResult0);
            this.pointCloudTarget = PointCloud.FromListVector3(pca.PointsResult1);
            this.pointCloudResult = PointCloud.FromListVector3(pca.PointsResult2);

            //Show4PointCloudsInWindow(true);
            this.ShowResultsInWindow_Cube_ProjectedPoints(true);
        }
Exemple #14
0
        public void Sample2D_Old()
        {
            UIMode = false;
            Create2DSamples();


            PCA pca = new PCA();


            pca.PCA_OfPointCloud(pointCloudSource);

            //List<Vector3> resultList = pca.ProjectPointsOnPCAAxes();

            // pointCloudTarget - is the result list of the first vector
            // pointCloudResult - is the result list of the second vector
            pointCloudTarget = PointCloud.FromListVector3(pca.PointsResult0);
            pointCloudResult = PointCloud.FromListVector3(pca.PointsResult1);


            if (UIMode)
            {
                //ShowResultsInWindow_Cube(true);
                Show4PointCloudsInWindow(true);
            }



            if (!GLSettings.PointCloudCentered)
            {
                Assert.IsTrue(1e-3f > PointCloud.MeanDistance(expectedResultCloud, pointCloudTarget));
            }
            else
            {
                expectedResultCloud = new PointCloud();
                expectedResultCloud.AddVector(new Vector3(-1.20497441625437f, -1.30683911366186f, 0));
                expectedResultCloud.AddVector(new Vector3(-0.282584287549998f, 0.260557580021532f, 0));
                expectedResultCloud.AddVector(new Vector3(0, 0, 0));
                Assert.IsTrue(this.threshold > PointCloud.MeanDistance(pointCloudSource.PCAAxes, expectedResultCloud));
            }
        }
        public void Delaunay_Scan()
        {
            string     path = AppDomain.CurrentDomain.BaseDirectory + "Models\\UnitTests";
            PointCloud pc   = PointCloud.FromObjFile(path + "\\KinectFace_1_15000.obj");


            List <TriangleVectors> listTrianglesDelaunay = Delaunay.DelaunayTriangulation(new List <Vector3>(pc.Vectors));



            List <Triangle> listTriangles = new List <Triangle>();
            List <Vector3>  newVectors    = new List <Vector3>();

            for (int i = 0; i < listTrianglesDelaunay.Count; i++)
            {
                Triangle t = new Triangle(newVectors.Count, newVectors.Count + 1, newVectors.Count + 2);
                listTriangles.Add(t);
                newVectors.Add(listTrianglesDelaunay[i].P1);
                newVectors.Add(listTrianglesDelaunay[i].P2);
                newVectors.Add(listTrianglesDelaunay[i].P3);
            }
            List <Vector3> newColors = new List <Vector3>();
            //for(int i = 0; i < newVectors.Count; i)
            //merge the two clouds
            List <Vector3> oldVectors = new List <Vector3>(pc.Vectors);
            List <Vector3> oldColors  = new List <Vector3>(pc.Colors);

            oldVectors.AddRange(newVectors);

            PointCloud pcNew = PointCloud.FromListVector3(oldVectors);

            pcNew.Triangles = listTriangles;
            pcNew.CreateIndicesFromTriangles();
            //ShowPointCloud(pcNew);
            ShowPointCloud(pc);

            //Assert.IsTrue(build_result);
        }
Exemple #16
0
        public void Delaunay_Simple()
        {
            List <Vector3> listVectors = new List <Vector3>()
            {
                new Vector3(158, 507, 0), new Vector3(142, 393, 0), new Vector3(100, 317, 0), new Vector3(92, 215, 0), new Vector3(98, 197, 0), new Vector3(151, 261, 0), new Vector3(143, 244, 0), new Vector3(170, 255, 0), new Vector3(209, 272, 0),
                new Vector3(198, 257, 0), new Vector3(214, 243, 0), new Vector3(223, 223, 0), new Vector3(214, 199, 0), new Vector3(234, 201, 0), new Vector3(264, 196, 0), new Vector3(159, 175, 0), new Vector3(158, 148, 0), new Vector3(143, 144, 0), new Vector3(141, 93, 0),
                new Vector3(166, 73, 0), new Vector3(136, 32, 0), new Vector3(179, 29, 0), new Vector3(207, 39, 0), new Vector3(233, 47, 0), new Vector3(257, 61, 0), new Vector3(267, 43, 0), new Vector3(271, 89, 0), new Vector3(292, 81, 0), new Vector3(234, 106, 0),
                new Vector3(214, 106, 0), new Vector3(221, 321, 0), new Vector3(235, 313, 0), new Vector3(247, 296, 0), new Vector3(265, 341, 0), new Vector3(283, 326, 0), new Vector3(307, 329, 0), new Vector3(320, 317, 0), new Vector3(340, 286, 0), new Vector3(327, 266, 0),
                new Vector3(322, 206, 0), new Vector3(337, 194, 0), new Vector3(348, 163, 0), new Vector3(320, 161, 0), new Vector3(370, 142, 0), new Vector3(350, 129, 0), new Vector3(389, 108, 0), new Vector3(355, 341, 0), new Vector3(384, 381, 0), new Vector3(421, 423, 0),
                new Vector3(441, 414, 0), new Vector3(391, 307, 0), new Vector3(416, 301, 0), new Vector3(391, 283, 0), new Vector3(490, 238, 0), new Vector3(460, 225, 0), new Vector3(474, 174, 0), new Vector3(453, 145, 0), new Vector3(467, 104, 0), new Vector3(543, 255, 0),
                new Vector3(618, 242, 0), new Vector3(611, 129, 0)
            };

            PointCloud pc = PointCloud.FromListVector3(listVectors);

            OpenTKExtension.Triangulation.Mesh m = OpenTKExtension.Triangulation.Mesh.Triangulate(pc, 5);

            pc.CreateIndicesFromTriangles(m.Triangles);

            ShowPointCloud(pc);

            //Assert.IsTrue(build_result);
        }
Exemple #17
0
        public void WikipediaBuildTests()
        {
            // Should generate the following tree:
            //             7,2
            //              |
            //       +------+-----+
            //      5,4          9,6
            //       |            |
            //   +---+---+     +--+
            //  2,3     4,7   8,1

            Vector3[] points = new Vector3[]
            {
                new Vector3(7, 2, 0), new Vector3(5, 4, 0), new Vector3(2, 3, 0),
                new Vector3(4, 7, 0), new Vector3(9, 6, 0), new Vector3(8, 1, 0)
            };

            List <Vector3> listV = new List <Vector3>(points);

            pointCloudTarget = PointCloud.FromListVector3(listV);
            pointCloudSource = pointCloudTarget.Clone();
            pointCloudSource.ShuffleVectors();
            //-------------------
            GlobalVariables.ResetTime();

            this.pointCloudResult = tree.BuildAndFindClosestPoints(pointCloudSource, pointCloudTarget, false);
            //    this.pointCloudResult = tree.BuildAndFindClosestPoints_NotParallel(pointCloudSource, pointCloudTarget, false);
            GlobalVariables.ShowLastTimeSpan("Search ");

            Assert.IsTrue(tree.MeanDistance == 0);

            for (int i = 0; i < pointCloudTarget.Vectors.Length; i++)
            {
                //Assert.That(pointCloudResult.Vectors[i], Is.EqualTo(pointCloudTarget.Vectors[i]));
                Assert.IsTrue(pointCloudSource.Vectors[i].Equals(pointCloudResult.Vectors[i]));
            }
        }
Exemple #18
0
 public void CutFace()
 {
     Humanoid.CutFace();
     FaceCut = PointCloud.FromListVector3(Humanoid.FaceVectors);
     //Humanoid.RearrangePointCloud(FaceCut);
 }
Exemple #19
0
        public void PCA_2D_InWork()
        {
            List <Vector3> pointsSource = new List <Vector3>();

            Vector3 v = new Vector3(1, 2, 0);

            pointsSource.Add(v);
            v = new Vector3(2, 3, 0);
            pointsSource.Add(v);
            v = new Vector3(3, 2, 0);
            pointsSource.Add(v);
            v = new Vector3(4, 4, 0);
            pointsSource.Add(v);
            v = new Vector3(5, 4, 0);
            pointsSource.Add(v);
            v = new Vector3(6, 7, 0);
            pointsSource.Add(v);
            v = new Vector3(7, 6, 0);
            pointsSource.Add(v);
            v = new Vector3(9, 7, 0);
            pointsSource.Add(v);


            PCA pca = new PCA();


            ////expected result
            //List<Vector3> listExpectedResult = new List<Vector3>();
            //Vector3 v1 = new Vector3(2.371258964, 2.51870600832217, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(0.605025583745627, 0.603160886338143, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(2.48258428755, 2.63944241997847, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(1.99587994658902, 2.11159364495307, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(2.94598120291464, 3.1420134339185, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(2.42886391124136, 2.58118069424077, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(1.74281634877673, 1.83713685698813, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(1.03412497746524, 1.06853497544495, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(1.51306017656077, 1.58795783010856, 0);
            //listExpectedResult.Add(v1);
            //v1 = new Vector3(0.980404601156606, 1.01027324970724, 0);
            //listExpectedResult.Add(v1);

            //for (int i = 0; i < listExpectedResult.Count; i++)
            //{
            //    Assert.IsTrue(PointCloud.CheckCloud(listExpectedResult[i].X, listResult[i].X, this.threshold));
            //    Assert.IsTrue(PointCloud.CheckCloud(listExpectedResult[i].Y, listResult[i].Y, this.threshold));


            //}


            // ShowVector3InWindow(listResult);
            this.pointCloudSource = PointCloud.FromListVector3(pointsSource);
            this.pointCloudTarget = pca.CalculatePCA(PointCloud.FromListVector3(pointsSource), 0);


            this.pointCloudResult = pca.CalculatePCA(PointCloud.FromListVector3(pointsSource), 1);

            if (UIMode)
            {
                Show4PointCloudsInWindow(true);
            }
        }