Ejemplo n.º 1
0
        // Render loop
        private void NativeWindow_Render(object sender, NativeWindowEventArgs e)
        {
            OpenGL.CoreUI.NativeWindow nativeWindow = (OpenGL.CoreUI.NativeWindow)sender;
            Gl.Viewport(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            ERROR_CODE err = ERROR_CODE.FAILURE;

            if (viewer.isAvailable() && zedCamera.Grab(ref runtimeParameters) == ERROR_CODE.SUCCESS)
            {
                if (zedMat.IsInit())
                {
                    // Retrieve left image
                    err = zedCamera.RetrieveImage(zedMat, sl.VIEW.LEFT, sl.MEM.CPU);
                    if (err == ERROR_CODE.SUCCESS)
                    {
                        // Retrieve Objects
                        zedCamera.RetrieveObjects(ref object_frame, ref obj_runtime_parameters);

                        //Update GL View
                        viewer.update(zedMat, object_frame);
                        viewer.render();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // Render loop
        private void NativeWindow_Render(object sender, NativeWindowEventArgs e)
        {
            OpenGL.CoreUI.NativeWindow nativeWindow = (OpenGL.CoreUI.NativeWindow)sender;
            Gl.Viewport(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            ERROR_CODE err = ERROR_CODE.FAILURE;

            if (viewer.isAvailable() && zedCamera.Grab(ref runtimeParameters) == ERROR_CODE.SUCCESS)
            {
                if (point_cloud.IsInit())
                {
                    // Retrieve Objects
                    err = zedCamera.RetrieveObjects(ref object_frame, ref obj_runtime_parameters);

                    if (err == ERROR_CODE.SUCCESS && object_frame.isNew != 0)
                    {
                        // Retrieve left image
                        zedCamera.RetrieveMeasure(point_cloud, sl.MEASURE.XYZRGBA, sl.MEM.CPU, res);
                        zedCamera.GetPosition(ref cam_pose, REFERENCE_FRAME.WORLD);
                        //Update GL View
                        viewer.update(point_cloud, object_frame, cam_pose);
                        viewer.render();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        // Render loop
        private void NativeWindow_Render(object sender, NativeWindowEventArgs e)
        {
            OpenGL.CoreUI.NativeWindow nativeWindow = (OpenGL.CoreUI.NativeWindow)sender;
            Gl.Viewport(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            ERROR_CODE err = ERROR_CODE.FAILURE;

            if (viewer.isAvailable() && zedCamera.Grab(ref runtimeParameters) == ERROR_CODE.SUCCESS)
            {
                if (zedMat.IsInit())
                {
                    // Retrieve left image
                    err = zedCamera.RetrieveImage(zedMat, sl.VIEW.LEFT, sl.MEM.CPU);
                    // Update pose data (used for projection of the mesh over the current image)
                    tracking_state = zedCamera.GetPosition(ref cam_pose);

                    if (tracking_state == POSITIONAL_TRACKING_STATE.OK)
                    {
                        timer++;
                        if (userAction.hit)
                        {
                            Vector2 imageClick = new Vector2((float)userAction.hitCoord.X * (float)zedCamera.ImageWidth, (float)userAction.hitCoord.Y * (float)zedCamera.ImageHeight);
                            findPlaneStatus = zedCamera.findPlaneAtHit(ref plane, imageClick);
                            if (findPlaneStatus == ERROR_CODE.SUCCESS)
                            {
                                zedCamera.convertHitPlaneToMesh(planeMeshVertices, planeMeshTriangles, out nbVertices, out nbTriangles);
                            }
                            userAction.clear();
                        }
                        //if 500ms have spend since last request (for 60fps)
                        if (timer % 30 == 0 && userAction.pressSpace)
                        {
                            // Update pose data (used for projection of the mesh over the current image)
                            Quaternion priorQuat  = Quaternion.Identity;
                            Vector3    priorTrans = Vector3.Zero;
                            findPlaneStatus = zedCamera.findFloorPlane(ref plane, out float playerHeight, priorQuat, priorTrans);

                            if (findPlaneStatus == ERROR_CODE.SUCCESS)
                            {
                                zedCamera.convertFloorPlaneToMesh(planeMeshVertices, planeMeshTriangles, out nbVertices, out nbTriangles);
                            }
                            userAction.clear();
                        }
                    }
                    if (findPlaneStatus == ERROR_CODE.SUCCESS)
                    {
                        viewer.updateMesh(planeMeshVertices, planeMeshTriangles, nbVertices, nbTriangles, plane.Type, plane.Bounds, userAction);
                    }
                    viewer.updateImageAndState(zedMat, cam_pose, tracking_state);
                    viewer.render();
                }
            }
        }
Ejemplo n.º 4
0
        // Render loop
        private void NativeWindow_Render(object sender, NativeWindowEventArgs e)
        {
            OpenGL.CoreUI.NativeWindow nativeWindow = (OpenGL.CoreUI.NativeWindow)sender;
            Gl.Viewport(0, 0, (int)nativeWindow.Width, (int)nativeWindow.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            ERROR_CODE err = ERROR_CODE.FAILURE;

            if (viewer.isAvailable() && zedCamera.Grab(ref runtimeParameters) == ERROR_CODE.SUCCESS)
            {
                if (zedMat.IsInit())
                {
                    // Retrieve left image
                    err = zedCamera.RetrieveImage(zedMat, sl.VIEW.LEFT, sl.MEM.CPU);
                    // Update pose data (used for projection of the mesh over the current image)
                    tracking_state = zedCamera.GetPosition(ref cam_pose);

                    if (mapping_activated)
                    {
                        mapping_state = zedCamera.GetSpatialMappingState();
                        if (timer % 60 == 0 && viewer.chunksUpdated() == true)
                        {
                            zedCamera.RequestSpatialMap();
                        }
                        if (zedCamera.GetMeshRequestStatus() == ERROR_CODE.SUCCESS && timer > 0)
                        {
                            /// MAP_TYPE == MESH
                            if (CREATE_MESH)
                            {
                                //Retrieves data for mesh visualization only (vertices + triangles);
                                zedCamera.RetrieveChunks(ref mesh);

                                var chunks = new List <Chunk>(mesh.chunks.Values);
                                viewer.updateData(chunks);
                            }

                            /// MAP_TYPE == FUSED_POINT_CLOUD
                            else
                            {
                                zedCamera.RetrieveSpatialMap(ref fusedPointCloud);
                                viewer.updateData(fusedPointCloud.vertices);
                            }
                        }
                    }

                    bool change_state = viewer.updateImageAndState(zedMat, cam_pose, tracking_state, mapping_state);

                    if (change_state)
                    {
                        if (!mapping_activated)
                        {
                            Quaternion quat = Quaternion.Identity; Vector3 vec = Vector3.Zero;
                            zedCamera.ResetPositionalTracking(quat, vec);

                            zedCamera.EnableSpatialMapping(ref spatialMappingParameters);

                            Console.WriteLine("Hit SPACE BAR to stop spatial mapping...");
                            // Clear previous Mesh data
                            viewer.clearCurrentMesh();

                            mapping_activated = true;
                        }
                        else
                        {
                            // Filter the mesh (remove unnecessary vertices and faces)
                            if (CREATE_MESH)
                            {
                                zedCamera.ExtractWholeSpatialMap();
                                zedCamera.FilterMesh(MESH_FILTER.MEDIUM, ref mesh);
                            }

                            if (CREATE_MESH && spatialMappingParameters.saveTexture)
                            {
                                zedCamera.ApplyTexture(ref mesh);
                            }

                            bool   error_save = false;
                            string saveName   = "";
                            //Save mesh as obj file
                            if (CREATE_MESH)
                            {
                                saveName   = "mesh_gen.obj";
                                error_save = zedCamera.SaveMesh(saveName, MESH_FILE_FORMAT.OBJ);
                            }
                            else
                            {
                                saveName   = "point_cloud.ply";
                                error_save = zedCamera.SavePointCloud(saveName, MESH_FILE_FORMAT.PLY);
                            }


                            if (error_save)
                            {
                                Console.WriteLine("Mesh saved under: " + saveName);
                            }
                            else
                            {
                                Console.WriteLine("Failed to save the mesh under: " + saveName);
                            }

                            mapping_state     = SPATIAL_MAPPING_STATE.NOT_ENABLED;
                            mapping_activated = false;
                            zedCamera.DisableSpatialMapping();

                            Console.WriteLine("Hit SPACE BAR to start spatial mapping...");
                        }
                    }
                    timer++;
                    viewer.render();
                }
            }
        }