Example #1
0
        private void savingWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int nFrames = 0;

            string        outDir = "out" + "\\" + txtSeqName.Text + "\\";
            DirectoryInfo di     = Directory.CreateDirectory(outDir);

            BackgroundWorker worker = (BackgroundWorker)sender;

            //This loop is running till it is either cancelled (using the btRecord button), or till there are no more stored frames.
            while (!worker.CancellationPending)
            {
                VertexC4ubV3f[] lVerticesWithColors = new VertexC4ubV3f[0];
                int[]           lTriangles;

                bool success = oServer.GetStoredFrame(out lVerticesWithColors, out lTriangles);

                //This indicates that there are no more stored frames.
                if (!success)
                {
                    break;
                }

                nFrames++;

                SetStatusBarOnTimer("Saving frame " + (nFrames).ToString() + ".", 5000);

                //This is ran if the frames from all clients are to be placed in a single file.
                if (oSettings.bMergeScansForSave)
                {
                    string outputFilename = outDir + "\\" + nFrames.ToString().PadLeft(5, '0') + ".ply";
                    Utils.saveToPly(outputFilename, lVerticesWithColors.ToList(), lTriangles.ToList(), oSettings.bSaveAsBinaryPLY);
                }
            }
        }
Example #2
0
        private VertexC4ubV3f[] CopyMeshToVerticesWithColoursArray(Mesh mesh)
        {
            int nElements = mesh.nVertices;

            if (nElements == 0)
            {
                return(new VertexC4ubV3f[0]);
            }

            byte[] byteVertices = new byte[nElements * 4 * sizeof(int)];
            Marshal.Copy(mesh.verticesWithColors, byteVertices, 0, nElements * 4 * sizeof(int));
            VertexC4ubV3f[] vertices = new VertexC4ubV3f[1];

            vertices = FromByteArray <VertexC4ubV3f>(byteVertices);

            return(vertices);
        }
Example #3
0
        public void GenerateMesh(out VertexC4ubV3f[] lVerticesWithColours, out int[] lFrameTriangles)
        {
            Mesh mesh = new Mesh();

            mesh.nVertices       = 0;
            lVerticesWithColours = new VertexC4ubV3f[0];
            lFrameTriangles      = new int[0];

            int nClients = nFramesCopied;

            if (nClients != 0)
            {
                generateMeshFromDepthMaps(nClients, depthMaps, depthColors, widths, heights, intrinsicsParams, transformParams, ref mesh, oSettings.bColorTransfer,
                                          oSettings.aMinBounds[0], oSettings.aMinBounds[1], oSettings.aMinBounds[2],
                                          oSettings.aMaxBounds[0], oSettings.aMaxBounds[1], oSettings.aMaxBounds[2],
                                          oSettings.bGenerateTriangles);

                lVerticesWithColours = CopyMeshToVerticesWithColoursArray(mesh);
                lFrameTriangles      = CopyMeshToTrianglesArray(mesh);
                deleteMesh(ref mesh);
            }
        }
Example #4
0
        //Continually requests frames that will be displayed in the live view window.
        private void updateWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            List <List <Body> > lFramesBody = new List <List <Body> >();

            VertexC4ubV3f[]  lFramesVerts     = new VertexC4ubV3f[0];
            int[]            lFramesTriangles = new int[0];
            BackgroundWorker worker           = (BackgroundWorker)sender;

            while (!worker.CancellationPending)
            {
                Thread.Sleep(1);

                //oServer.RequestLastFrames();
                oServer.CopyLatestFrames();
                oServer.RequestLastFrames();
                oServer.CorrectRadialDistortionsForDepthMaps();
                oServer.GenerateAndGetMesh(out lFramesVerts, lFramesBody, out lFramesTriangles);

                //Update the vertex and color lists that are common between this class and the OpenGLWindow.

                lock (lAllVerticesLock)
                {
                    //lAllVertices.Clear();
                    //lAllBodies.Clear();
                    //lAllTriangles.Clear();

                    int TotalVerticesCount             = 0;
                    int TotalTrianglesElementsCount    = 0;
                    int ActTotalTrianglesElementsCount = 0;
                    lAllVertices  = lFramesVerts;
                    lAllTriangles = lFramesTriangles;
                    //lAllVertices.AddRange(lFramesVerts);
                    //lAllTriangles.AddRange(lFramesTriangles);
                    for (int i = 0; i < lAllBodies.Count; i++)
                    {
                        lAllBodies.AddRange(lFramesBody[i]);

                        ActTotalTrianglesElementsCount = lAllTriangles.Count();
                        for (int v = TotalTrianglesElementsCount; v < ActTotalTrianglesElementsCount; v++)
                        {
                            lAllTriangles[v] += TotalVerticesCount / 3;
                        }

                        TotalTrianglesElementsCount = lAllTriangles.Count();
                        TotalVerticesCount          = lAllVertices.Count();
                    }
                }

                // adding camera poses is in separate range, because oServer.lCameraPoses "get" locks oClientSocketLock
                // that may cause deadlock when locking with lAllVertices
                List <AffineTransform> cameraPoses = oServer.lCameraPoses;

                lock (lAllVerticesLock)
                {
                    lAllCameraPoses.Clear();
                    lAllCameraPoses.AddRange(cameraPoses);
                }
                //Notes the fact that a new frame was downloaded, this is used to estimate the FPS.
                if (oOpenGLWindow != null)
                {
                    oOpenGLWindow.SetNewVerticesAndTriangles(lAllVertices, lAllTriangles);
                    oOpenGLWindow.CloudUpdateTick();
                }

                oTransferServer.updateMesh(lAllVertices, lAllTriangles);
            }
        }
Example #5
0
        private MeshChunks formMeshChunks(List <VertexC4ubV3f> lVertices, List <int> lTriangles)
        {
            int chunkSizeLimit = 65000 - 3;

            MeshChunks ret               = new MeshChunks();
            int        nVertices         = lVertices.Count();
            int        nTriangles        = lTriangles.Count() / 3;
            List <int> trianglesInChunks = new List <int>();
            List <int> verticesInChunks  = new List <int>();

            int[]           chunkIndex          = new int[nVertices];
            int[]           verticesMap         = new int[nVertices];
            VertexC4ubV3f[] newVertices         = new VertexC4ubV3f[nTriangles * 3];
            int[]           newTriangles        = new int[nTriangles * 3];
            int             trianglesChunkStart = 0;
            int             currentChunkIndex   = 0;
            int             currentVertex       = 0;

            for (int v = 0; v < nVertices; v++)
            {
                chunkIndex[v] = -1;
            }

            int verticesInCurrentChunk = 0;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            for (int t = 0; t < nTriangles * 3; t++)
            {
                int val = lTriangles[t];
                if (chunkIndex[val] != currentChunkIndex)
                {
                    newVertices[currentVertex] = lVertices[val];
                    verticesMap[val]           = verticesInCurrentChunk;
                    chunkIndex[val]            = currentChunkIndex;
                    currentVertex++;
                    newTriangles[t] = verticesInCurrentChunk;
                    verticesInCurrentChunk++;
                }
                else
                {
                    newTriangles[t] = verticesMap[val];
                }

                if (verticesInCurrentChunk >= chunkSizeLimit && (((t + 1) % 3) == 0))
                {
                    currentChunkIndex++;
                    verticesInChunks.Add(verticesInCurrentChunk);
                    trianglesInChunks.Add((t - trianglesChunkStart) / 3);
                    verticesInCurrentChunk = 0;
                    trianglesChunkStart    = t;
                }
            }

            if (verticesInCurrentChunk != 0)
            {
                verticesInChunks.Add(verticesInCurrentChunk);
                trianglesInChunks.Add((nTriangles * 3 - trianglesChunkStart) / 3);
            }

            ret.lTriangles          = new List <int>(newTriangles);
            ret.lVertices           = new List <VertexC4ubV3f>(SubArray(newVertices, 0, currentVertex));
            ret.trianglesChunkSizes = trianglesInChunks;
            ret.verticesChunkSizes  = verticesInChunks;

            sw.Stop();

            Console.WriteLine("Forming elapsed={0}", sw.ElapsedMilliseconds);

            return(ret);
        }
Example #6
0
 private VertexC4ubV3f[] SubArray(VertexC4ubV3f[] data, int index, int length)
 {
     VertexC4ubV3f[] result = new VertexC4ubV3f[length];
     Array.Copy(data, index, result, 0, length);
     return(result);
 }