Ejemplo n.º 1
0
        /// <summary>
        /// Gets the video mode from the hardware.
        /// </summary>
        /// <param name="videoMode"> Reference to be filled out by the Tango API.</param>
        /// <returns> O if successful, otherwise it returns -1.</returns>
        static public int LookupVideoMode(ref VideoModeAttributes videoMode)
        {
            int    videoModeID  = -1;
            IntPtr videoModePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(VideoModeAttributes)));
            int    numModes     = Tango.HardwareParameters.HardwareParametersAPI.HardwareCameraNumberVideoModes();

            if (numModes > 0)
            {
                // choose the very first video mode
                Common.RetCodes res = (Common.RetCodes)Tango.HardwareParameters.HardwareParametersAPI.HardwareCameraGetVideoMode(0, videoModePtr);
                if (res == Common.RetCodes.kCAPISuccess)
                {
                    VideoModeAttributes supportedVideoMode = (VideoModeAttributes)Marshal.PtrToStructure(videoModePtr, typeof(VideoModeAttributes));
                    videoMode.frameRate = supportedVideoMode.frameRate;
                    videoMode.width     = supportedVideoMode.width;
                    videoMode.height    = supportedVideoMode.height;
                    videoModeID         = 0;
                }
                else
                {
                    DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_ERROR, "Failed to get video mode with error:" + res);
                }
            }
            else
            {
                DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_ERROR, "Number of video modes:" + numModes);
            }
            Marshal.FreeHGlobal(videoModePtr);
            return(videoModeID);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the latest depth frame.
        /// </summary>
        /// <param name="buffer"> Buffer to be filled out for depth.</param>
        /// <param name="timestamp"> Gets filled with the current depth timestamp.</param>
        /// <returns> True if the API returns success.</returns>
        public static bool GetLatestFrame(ref int[] buffer, ref double timestamp)
        {
            if (!m_isInit)
            {
                DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_WARN,
                                                   "DepthProvider.GetLatestFrame : Not Initialized!");
                return(false);
            }

            if (buffer.Length < Common.DepthBufferSize)
            {
                DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_WARN, "Wrong depth buffer size");
                return(false);
            }
            GCHandle bufferHandler = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            Common.RetCodes retCode = (Common.RetCodes)TangoDepthAPI.DepthGetLatestFrame(TangoApplication.Instance.Handle,
                                                                                         bufferHandler.AddrOfPinnedObject(),
                                                                                         Common.DepthBufferSize,
                                                                                         ref timestamp);
            if (retCode != Common.RetCodes.kCAPISuccess)
            {
                DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_WARN,
                                                   "Failed to get depth buffer with error:" + retCode);
            }
            bufferHandler.Free();
            return(retCode == Common.RetCodes.kCAPISuccess);
        }
Ejemplo n.º 3
0
        void LateUpdate()
        {
            //load next frame
            if (mApplicationHandler != System.IntPtr.Zero)
            {
                Common.RetCodes retCode = (Common.RetCodes)TangoApplicationAPI.ApplicationDoStep(mApplicationHandler);
                mValid = (retCode == Common.RetCodes.kCAPISuccess);
//				if(retCode != Common.RetCodes.kCAPISuccess)
//					ErrorHandler.instance.presentErrorMessage("Application step failed with error code:" + retCode);
//				else
//					Debug.Log("Do step succeed");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Init VIO service.
        /// </summary>
        /// <param name="operationMode">Operation Mode.</param>
        /// <param name="sparseMapPath">Sparse map path.
        /// If it's null, the application will run in loop closure mode.</param>
        public static void Init(Mode operationMode, string sparseMapPath)
        {
            int withSparseMapping =
                (operationMode == Mode.VisualIntertialNavigationAndMapping) ? 1 : 0;

            Common.RetCodes retCode = (Common.RetCodes)TangoVIOAPI.VIOInitialize(TangoApplication.Instance.Handle,
                                                                                 withSparseMapping,
                                                                                 sparseMapPath);
            if (retCode != Common.RetCodes.kCAPISuccess)
            {
                Debug.Log("VIO initialization failed: " + retCode);
            }
            else
            {
                m_isInit = true;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Perform updates for the next frame after the
        /// normal update has run. This loads next frame.
        /// </summary>
        private void LateUpdate()
        {
            if (m_applicationHandle != System.IntPtr.Zero)
            {
                Common.RetCodes retCode = (Common.RetCodes)TangoApplicationAPI.ApplicationDoStep(m_applicationHandle);
                if (retCode != Common.RetCodes.kCAPISuccess)
                {
                    DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_ERROR,
                                                       "Application do step error: " + retCode);
                }
                m_valid = retCode == Common.RetCodes.kCAPISuccess;
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Save current recorded sparse map to file.
        /// </summary>
        /// <param name="sparseMapPath">Absolute location on phone.</param>
        /// <returns>If the function call succeed.</returns>
        public static bool SaveSparseMap(string sparseMapPath)
        {
            if (!m_isInit)
            {
                DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_WARN,
                                                   "VIOProvider.SaveSparseMap : Not Initialized!");
                return(false);
            }

            Common.RetCodes ret_code =
                (Common.RetCodes)TangoVIOAPI.VIOSaveSparseMap(
                    TangoApplication.Instance.Handle, sparseMapPath);
            if (ret_code != Common.RetCodes.kCAPISuccess)
            {
                ErrorHandler.instance.presentErrorMessage(
                    "Application initialization failed" + ret_code);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 7
0
        public bool getDepthBuffer(ref int [] buffer, ref double timestamp)
        {
            if (buffer.Length < getDepthBufferSize())
            {
                DebugLogger.WriteToLog(DebugLogger.EDebugLevel.DEBUG_WARN, "Wrong depth buffer size");
                return(false);
            }

            GCHandle bufferHandler = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            Common.RetCodes retCode = (Common.RetCodes)TangoUtilAPI.UtilGetDepthFrame(mApplicationHandler, bufferHandler.AddrOfPinnedObject(),
                                                                                      mDepthBufferResolution.width * mDepthBufferResolution.height,
                                                                                      ref timestamp);
            if (retCode != Common.RetCodes.kCAPISuccess)
            {
                DebugLogger.WriteToLog(DebugLogger.EDebugLevel.DEBUG_WARN, "Failed to get depth buffer with error:" + retCode);
            }
            bufferHandler.Free();
            return(retCode == Common.RetCodes.kCAPISuccess);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get latest vioStatus.
        /// </summary>
        /// <param name="vioStatus">Reference to vioStatus,
        /// need caller to allocate.</param>
        /// <returns>If the function call succeed.</returns>
        public static bool GetLatestPose(ref VIOStatus vioStatus)
        {
            if (!m_isInit)
            {
                DebugLogger.GetInstance.WriteToLog(DebugLogger.EDebugLevel.DEBUG_WARN, "VIOProvider.GetLatestPose : Not Initialized!");
                return(false);
            }

            Common.RetCodes ret_code =
                (Common.RetCodes)TangoVIOAPI.VIOGetLatestPose(
                    TangoApplication.Instance.Handle, ref vioStatus);
            if (ret_code != Common.RetCodes.kCAPISuccess)
            {
                Debug.Log("get latest vio pose failed:" + ret_code);
                return(false);
            }

            // Convert the estimator format to unity format
            Utilities.TangoUtilAPI.UtilConvertPoseToUnityFormat(
                ref vioStatus.rotation, ref vioStatus.translation,
                ref vioStatus.rotation, ref vioStatus.translation);
            return(true);
        }