예제 #1
0
파일: MainActivity.cs 프로젝트: bertt/tango
        private TangoConfig SetupTangoConfig(Tango tango)
        {
            try
            {
                // Create a new Tango Configuration and enable the MotionTrackingActivity API.
                TangoConfig config = tango.GetConfig(TangoConfig.ConfigTypeDefault);
                config.PutBoolean(TangoConfig.KeyBooleanMotiontracking, true);
                // Tango service should automatically attempt to recover when it enters an invalid state.
                config.PutBoolean(TangoConfig.KeyBooleanAutorecovery, true);

                config.PutBoolean(TangoConfig.KeyBooleanColorcamera, true);
                config.PutBoolean(TangoConfig.KeyBooleanDepth, true);
                // NOTE: Low latency integration is necessary to achieve a precise alignment of
                // virtual objects with the RBG image and produce a good AR effect.
                config.PutBoolean(TangoConfig.KeyBooleanLowlatencyimuintegration, true);
                // Drift correction allows motion tracking to recover after it loses tracking.
                // The drift corrected pose is is available through the frame pair with
                // base frame AREA_DESCRIPTION and target frame DEVICE.
                config.PutBoolean(TangoConfig.KeyBooleanDriftCorrection, true);
                var c = config.GetString(TangoConfig.KeyStringDatasetsPath);
                config.PutInt(TangoConfig.KeyIntDepthMode, TangoConfig.TangoDepthModePointCloud);

                return(config);
            }
            catch (TangoErrorException e)
            {
                Log.Debug("gaat iets mis", "TangoErrorException", e);
                throw;
            }
        }
예제 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_jpoint_cloud);
            Title = GetString(Resource.String.app_name);

            mPoseTextView                = (TextView)FindViewById(Resource.Id.pose);
            mQuatTextView                = (TextView)FindViewById(Resource.Id.quat);
            mPoseCountTextView           = (TextView)FindViewById(Resource.Id.posecount);
            mDeltaTextView               = (TextView)FindViewById(Resource.Id.deltatime);
            mTangoEventTextView          = (TextView)FindViewById(Resource.Id.tangoevent);
            mPoseStatusTextView          = (TextView)FindViewById(Resource.Id.status);
            mPointCountTextView          = (TextView)FindViewById(Resource.Id.pointCount);
            mTangoServiceVersionTextView = (TextView)FindViewById(Resource.Id.version);
            mApplicationVersionTextView  = (TextView)FindViewById(Resource.Id.appversion);
            mAverageZTextView            = (TextView)FindViewById(Resource.Id.averageZ);
            mFrequencyTextView           = (TextView)FindViewById(Resource.Id.frameDelta);

            mFirstPersonButton = (Button)FindViewById(Resource.Id.first_person_button);
            mFirstPersonButton.SetOnClickListener(this);
            mThirdPersonButton = (Button)FindViewById(Resource.Id.third_person_button);
            mThirdPersonButton.SetOnClickListener(this);
            mTopDownButton = (Button)FindViewById(Resource.Id.top_down_button);
            mTopDownButton.SetOnClickListener(this);

            mTango  = new Tango(this);
            mConfig = new TangoConfig();
            mConfig = mTango.GetConfig(TangoConfig.ConfigTypeCurrent);
            mConfig.PutBoolean(TangoConfig.KeyBooleanDepth, true);

            int maxDepthPoints = mConfig.GetInt("max_point_cloud_elements");

            mRenderer = new PCRenderer(maxDepthPoints);
            mGLView   = (GLSurfaceView)FindViewById(Resource.Id.gl_surface_view);
            mGLView.SetEGLContextClientVersion(2);
            mGLView.SetRenderer(mRenderer);
            mGLView.RenderMode = Rendermode.WhenDirty;

            PackageInfo packageInfo;

            try
            {
                packageInfo = this.PackageManager.GetPackageInfo(this.PackageName, 0);
                mApplicationVersionTextView.Text = packageInfo.VersionName;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
                System.Diagnostics.Debug.WriteLine(e.StackTrace);
            }

            // Display the version of Tango Service
            mServiceVersion = mConfig.GetString("tango_service_library_version");
            mTangoServiceVersionTextView.Text = mServiceVersion;
            mIsTangoServiceConnected          = false;
        }
예제 #3
0
        private TangoConfig SetupTangoConfig(Tango tango)
        {
            // Create a new Tango Configuration and enable the MotionTrackingActivity API.
            TangoConfig config = tango.GetConfig(TangoConfig.ConfigTypeDefault);

            config.PutBoolean(TangoConfig.KeyBooleanMotiontracking, true);
            // Tango service should automatically attempt to recover when it enters an invalid state.
            config.PutBoolean(TangoConfig.KeyBooleanAutorecovery, true);
            return(config);
        }
예제 #4
0
        public void SurfaceCreated(ISurfaceHolder holder)
        {
            Surface surface = holder.Surface;

            if (surface.IsValid)
            {
                TangoConfig config = new TangoConfig();
                config = mTango.GetConfig(TangoConfig.ConfigTypeCurrent);
                // TODO : Verify Connect doesn't require new set up without ConnectSurface
                //mTango.ConnectSurface(0, surface);
                mTango.Connect(config);
            }
        }
예제 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            mTranslationTextView = (TextView)FindViewById(Resource.Id.translation_text_view);
            mRotationTextView    = (TextView)FindViewById(Resource.Id.rotation_text_view);

            // Instantiate Tango client
            mTango = new Tango(this);

            // Set up Tango configuration for motion tracking
            // If you want to use other APIs, add more appropriate to the config
            // like: mConfig.PutBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true)
            mConfig = new TangoConfig();
            mConfig = mTango.GetConfig(TangoConfig.ConfigTypeCurrent);
            mConfig.PutBoolean(TangoConfig.KeyBooleanMotiontracking, true);
        }
예제 #6
0
        protected override void OnResume()
        {
            Log.Debug(Tag, "OnResume");
            base.OnResume();

            _tango = new Tango(this, new Runnable(() =>
            {
                Log.Debug(Tag, "TangoRunnable");
                //try
                //{
                TangoSupport.Initialize();
                _tangoConfig = SetupTangoConfig(_tango);
                _tango.Connect(_tangoConfig);
                startupTango();
                //}
                //catch (TangoOutOfDateException e)
                //{
                //    Log.Error(Tag, GetString(R.
                //    string.exception_out_of_date),
                //    e)
                //    ;
                //}
                //catch (TangoErrorException e)
                //{
                //    Log.Error(Tag, GetString(R.
                //    string.exception_tango_error),
                //    e)
                //    ;
                //}
                //catch (TangoInvalidException e)
                //{
                //    Log.Error(Tag, GetString(R.
                //    string.exception_tango_invalid),
                //    e)
                //    ;
                //}
            }));
        }
예제 #7
0
        private void SetTangoConfig()
        {
            mConfig = new TangoConfig();
            mConfig = mTango.GetConfig(TangoConfig.ConfigTypeCurrent);
            // Check if learning mode
            if (mIsLearningMode)
            {
                // Set learning mode to config.
                mConfig.PutBoolean(TangoConfig.KeyBooleanLearningmode, true);
                // Set the ADF save button visible.
                mSaveAdf.Visibility = Android.Views.ViewStates.Visible; // TODO: Check to see if ViewStates is correct
                mSaveAdf.SetOnClickListener(this);
            }
            // Check for Load ADF/Constant Space relocalization mode
            if (mIsConstantSpaceRelocalize)
            {
                IList <string> fullUUIDList = new List <string>();
                // Returns a list of ADFs with their UUIDs
                fullUUIDList = mTango.ListAreaDescriptions();
                if (fullUUIDList.Count == 0)
                {
                    mUUIDTextView.Text = GetString(Resource.String.no_uuid);
                }

                // Load the latest ADF if ADFs are found.
                if (fullUUIDList.Count > 0)
                {
                    mConfig.PutString(TangoConfig.KeyStringAreadescription, fullUUIDList[fullUUIDList.Count - 1]);
                    mUUIDTextView.Text = GetString(Resource.String.number_of_adfs) + fullUUIDList.Count + GetString(Resource.String.latest_adf_is) + fullUUIDList[fullUUIDList.Count - 1];
                }
            }

            // Set the number of loop closures to zero at start.
            mStart2DevicePoseCount            = 0;
            mAdf2DevicePoseCount              = 0;
            mAdf2StartPoseCount               = 0;
            mTangoServiceVersionTextView.Text = mConfig.GetString("tango_service_library_version");
        }
예제 #8
0
파일: MainActivity.cs 프로젝트: bertt/tango
        protected override void OnResume()
        {
            base.OnResume();

            _tango = new Tango(this, new Runnable(() =>
            {
                Log.Debug(Tag, "TangoRunnable");
                try
                {
                    TangoSupport.Initialize();
                    _tangoConfig = SetupTangoConfig(_tango);
                    _tango.Connect(_tangoConfig);
                    _isConnected = true;
                    var adfs     = _tango.ListAreaDescriptions();

                    // get the number of adfs
                    var nr       = adfs.Count;
                    var textView = FindViewById <TextView>(Resource.Id.textView2);

                    RunOnUiThread(() => textView.Text = nr.ToString());
                }
                catch (TangoOutOfDateException e)
                {
                    Log.Error(Tag, "TangoOutOfDateException", e);
                }
                catch (TangoErrorException e)
                {
                    // this exception gets thrown
                    Log.Error(Tag, "TangoErrorException", e);
                }
                catch (TangoInvalidException e)
                {
                    Log.Error(Tag, "TangoInvalidException", e);
                }
            }));
        }
예제 #9
0
        /// <summary>
        /// Unity callback when this object is destroyed.
        /// </summary>
        private void OnDestroy()
        {
            Shutdown();

            // Clean up configs.
            if (m_tangoConfig != null)
            {
                m_tangoConfig.Dispose();
                m_tangoConfig = null;
            }

            if (m_tangoRuntimeConfig != null)
            {
                m_tangoRuntimeConfig.Dispose();
                m_tangoRuntimeConfig = null;
            }
        }
예제 #10
0
        /// <summary>
        /// Awake this instance.
        /// </summary>
        private void Awake()
        {
            AndroidHelper.RegisterPauseEvent(_androidOnPause);
            AndroidHelper.RegisterResumeEvent(_androidOnResume);
            AndroidHelper.RegisterOnActivityResultEvent(_androidOnActivityResult);

            // Setup listeners.
            m_tangoEventListener = new TangoEventListener();
            m_areaDescriptionEventListener = new AreaDescriptionEventListener();

            if (m_enableCloudADF)
            {
                m_tangoCloudEventListener = new TangoCloudEventListener();
            }

            if (m_enableMotionTracking)
            {
                m_poseListener = new PoseListener();
            }

            if (m_enableDepth)
            {
                m_depthListener = new DepthListener();
            }

            if (m_enableVideoOverlay)
            {
                int yTextureWidth = 0;
                int yTextureHeight = 0;
                int uvTextureWidth = 0;
                int uvTextureHeight = 0;

                m_yuvTexture = new YUVTexture(yTextureWidth, yTextureHeight, uvTextureWidth, uvTextureHeight, TextureFormat.RGBA32, false);
                m_videoOverlayListener = new VideoOverlayListener();
            }

            // Setup configs.
            m_tangoConfig = new TangoConfig(TangoEnums.TangoConfigType.TANGO_CONFIG_DEFAULT);
            m_tangoRuntimeConfig = new TangoConfig(TangoEnums.TangoConfigType.TANGO_CONFIG_RUNTIME);
        }
예제 #11
0
 /// <summary>
 /// Disconnect from the Tango service.
 /// 
 /// This is called automatically when the TangoApplication goes away.  You only need 
 /// to call this to disconnect from the Tango service before the TangoApplication goes
 /// away.
 /// </summary>
 public void Shutdown()
 {
     Debug.Log("Tango Shutdown");
     if (m_tangoConfig != null)
     {
         m_tangoConfig.Dispose();
         m_tangoConfig = null;
     }
     if (m_tangoRuntimeConfig != null)
     {
         m_tangoRuntimeConfig.Dispose();
         m_tangoRuntimeConfig = null;
     }
     _TangoDisconnect();
 }
예제 #12
0
        /// <summary>
        /// Init step 2.  Call this to initialize internal state on TangoApplication.
        /// 
        /// Call this in the permissions callback if all permissions have been granted.
        /// 
        /// Also see TangoApplication.RequestNecessaryPermissionsandConnect, TangoApplication.InitProviders, and
        /// TangoApplication.ConnectToService.
        /// </summary>
        public void InitApplication()
        {
            Debug.Log("-----------------------------------Initializing Tango");
            _CheckTangoVersion();
            if (m_tangoConfig == null)
            {
                m_tangoConfig = new TangoConfig(TangoEnums.TangoConfigType.TANGO_CONFIG_DEFAULT);
            }
            if (m_tangoRuntimeConfig == null)
            {
                m_tangoRuntimeConfig = new TangoConfig(TangoEnums.TangoConfigType.TANGO_CONFIG_RUNTIME);
            }

            if (m_enableVideoOverlay && m_useExperimentalVideoOverlay)
            {
                int yTextureWidth = 0;
                int yTextureHeight = 0;
                int uvTextureWidth = 0;
                int uvTextureHeight = 0;

                m_tangoConfig.GetInt32(TangoConfig.Keys.EXPERIMENTAL_Y_TEXTURE_WIDTH, ref yTextureWidth);
                m_tangoConfig.GetInt32(TangoConfig.Keys.EXPERIMENTAL_Y_TEXTURE_HEIGHT, ref yTextureHeight);
                m_tangoConfig.GetInt32(TangoConfig.Keys.EXPERIMENTAL_UV_TEXTURE_WIDTH, ref uvTextureWidth);
                m_tangoConfig.GetInt32(TangoConfig.Keys.EXPERIMENTAL_UV_TEXTURE_HEIGHT, ref uvTextureHeight);

                if (yTextureWidth == 0 || yTextureHeight == 0 || uvTextureWidth == 0 || uvTextureHeight == 0)
                {
                    Debug.Log("Video overlay texture sizes were not set properly");
                }

                m_yuvTexture.ResizeAll(yTextureWidth, yTextureHeight, uvTextureWidth, uvTextureHeight);
            }
        }
예제 #13
0
        /// <summary>
        /// Awake this instance.
        /// </summary>
        private void Awake()
        {
            AndroidHelper.RegisterPauseEvent(_androidOnPause);
            AndroidHelper.RegisterResumeEvent(_androidOnResume);
            AndroidHelper.RegisterOnActivityResultEvent(_androidOnActivityResult);
            AndroidHelper.RegisterOnScreenOrientationChangedEvent(_androidOnScreenOrientationChanged);

            // Setup listeners.
            m_tangoEventListener = new TangoEventListener();
            m_areaDescriptionEventListener = new AreaDescriptionEventListener();

            if (m_enableCloudADF)
            {
                m_tangoCloudEventListener = new TangoCloudEventListener();
            }

            if (m_enableMotionTracking)
            {
                m_poseListener = new PoseListener();
            }

            if (m_enableDepth)
            {
                m_depthListener = new DepthListener();
            }

            if (m_enableVideoOverlay)
            {
                int yTextureWidth = 0;
                int yTextureHeight = 0;
                int uvTextureWidth = 0;
                int uvTextureHeight = 0;

                m_yuvTexture = new YUVTexture(yTextureWidth, yTextureHeight, uvTextureWidth, uvTextureHeight, TextureFormat.RGBA32, false);
                m_videoOverlayListener = new VideoOverlayListener();
            }

            if (m_enable3DReconstruction)
            {
                m_tango3DReconstruction = new Tango3DReconstruction(m_3drResolutionMeters, m_3drGenerateColor, m_3drSpaceClearing);
                m_tango3DReconstruction.m_useAreaDescriptionPose = m_3drUseAreaDescriptionPose;
                m_tango3DReconstruction.m_sendColorToUpdate = m_3drGenerateColor;
            }

            // Setup configs.
            m_tangoConfig = new TangoConfig(TangoEnums.TangoConfigType.TANGO_CONFIG_DEFAULT);
            m_tangoRuntimeConfig = new TangoConfig(TangoEnums.TangoConfigType.TANGO_CONFIG_RUNTIME);

            TangoSupport.UpdateCurrentRotationIndex();
        }
예제 #14
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            var layOut = Resource.Layout.activity_motion_tracking;

            _TAG = this.GetType().Name;
            SetContentView(layOut);
            Intent intent = Intent;

            mIsAutoRecovery = intent.GetBooleanExtra(KEY_MOTIONTRACKING_AUTORECOVER, false);
            // Text views for displaying translation and rotation data
            mPoseTextView       = (TextView)FindViewById(Resource.Id.pose);
            mQuatTextView       = (TextView)FindViewById(Resource.Id.quat);
            mPoseCountTextView  = (TextView)FindViewById(Resource.Id.posecount);
            mDeltaTextView      = (TextView)FindViewById(Resource.Id.deltatime);
            mTangoEventTextView = (TextView)FindViewById(Resource.Id.tangoevent);
            // Buttons for selecting camera view and Set up button click listeners
            FindViewById(Resource.Id.first_person_button).SetOnClickListener(this);
            FindViewById(Resource.Id.third_person_button).SetOnClickListener(this);
            FindViewById(Resource.Id.top_down_button).SetOnClickListener(this);

            // Button to reset motion tracking
            mMotionResetButton = (Button)FindViewById(Resource.Id.resetmotion);

            // Text views for the status of the pose data and Tango library versions
            mPoseStatusTextView          = (TextView)FindViewById(Resource.Id.status);
            mTangoServiceVersionTextView = (TextView)FindViewById(Resource.Id.version);
            mApplicationVersionTextView  = (TextView)FindViewById(Resource.Id.appversion);

            // OpenGL view where all of the graphics are drawn
            mGLView = (GLSurfaceView)FindViewById(Resource.Id.gl_surface_view);

            // Set up button click listeners
            mMotionResetButton.Click += mMotionResetButton_Click;

            // Configure OpenGL renderer
            mRenderer = new MTGLRenderer();
            mGLView.SetEGLContextClientVersion(2);
            mGLView.SetRenderer(mRenderer);
            mGLView.RenderMode = Rendermode.WhenDirty;

            // Instantiate the Tango service
            mTango = new Tango(this);
            // Create a new Tango Configuration and enable the MotionTracking API
            mConfig = new TangoConfig();
            mConfig = mTango.GetConfig(TangoConfig.ConfigTypeCurrent);
            mConfig.PutBoolean(TangoConfig.KeyBooleanMotiontracking, true);

            // The Auto-Recovery ToggleButton Sets a boolean variable to determine
            // if the
            // Tango service should automatically attempt to recover when
            // / MotionTracking enters an invalid state.
            if (mIsAutoRecovery)
            {
                mConfig.PutBoolean(TangoConfig.KeyBooleanAutorecovery, true);
                Log.Info(TAG, "Auto Recovery On");
            }
            else
            {
                mConfig.PutBoolean(TangoConfig.KeyBooleanAutorecovery, false);
                Log.Info(TAG, "Auto Recovery Off");
            }

            PackageInfo packageInfo;

            try
            {
                packageInfo = this.PackageManager.GetPackageInfo(this.PackageName, 0);
                mApplicationVersionTextView.Text = packageInfo.VersionName;
            }
            catch (NameNotFoundException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }

            // Display the library version for debug purposes
            mTangoServiceVersionTextView.Text = mConfig.GetString("tango_service_library_version");
        }
예제 #15
0
        /// <summary>
        /// Manual initialization step 2: Call this to connect to the Tango service.
        /// 
        /// After connecting to the Tango service, you will get updates for Motion Tracking, Depth Sensing, and Area
        /// Learning.  If you have a specific Area Description you want to localize too, pass that Area Description in
        /// here.
        /// </summary>
        /// <param name="areaDescription">If not null, the Area Description to localize to.</param>
        public void Startup(AreaDescription areaDescription)
        {
            // Make sure all required permissions have been granted.
            if (m_requiredPermissions != PermissionsTypes.NONE)
            {
                Debug.Log("TangoApplication.Startup() -- ERROR: Not all required permissions were accepted yet.");
                return;
            }

            if (!_CheckTangoVersion())
            {
                // Error logged in _CheckTangoVersion function.
                return;
            }

            // Setup configs.
            m_tangoConfig = new TangoConfig(TangoEnums.TangoConfigType.TANGO_CONFIG_DEFAULT);
            m_tangoRuntimeConfig = new TangoConfig(TangoEnums.TangoConfigType.TANGO_CONFIG_RUNTIME);

            if (m_enableVideoOverlay && m_videoOverlayUseYUVTextureIdMethod)
            {
                int yTextureWidth = 0;
                int yTextureHeight = 0;
                int uvTextureWidth = 0;
                int uvTextureHeight = 0;
                
                m_tangoConfig.GetInt32(TangoConfig.Keys.EXPERIMENTAL_Y_TEXTURE_WIDTH, ref yTextureWidth);
                m_tangoConfig.GetInt32(TangoConfig.Keys.EXPERIMENTAL_Y_TEXTURE_HEIGHT, ref yTextureHeight);
                m_tangoConfig.GetInt32(TangoConfig.Keys.EXPERIMENTAL_UV_TEXTURE_WIDTH, ref uvTextureWidth);
                m_tangoConfig.GetInt32(TangoConfig.Keys.EXPERIMENTAL_UV_TEXTURE_HEIGHT, ref uvTextureHeight);
                
                if (yTextureWidth == 0 || yTextureHeight == 0 || uvTextureWidth == 0 || uvTextureHeight == 0)
                {
                    Debug.Log("Video overlay texture sizes were not set properly");
                }
                
                m_yuvTexture.ResizeAll(yTextureWidth, yTextureHeight, uvTextureWidth, uvTextureHeight);
            }

            if (areaDescription != null)
            {
                _InitializeMotionTracking(areaDescription.m_uuid);
            }
            else
            {
                _InitializeMotionTracking(null);
            }

            if (m_tangoConfig.SetBool(TangoConfig.Keys.ENABLE_DEPTH_PERCEPTION_BOOL, m_enableDepth) 
                && m_tangoConfig.SetInt32(TangoConfig.Keys.DEPTH_MODE, (int)TangoConfig.DepthMode.XYZC)
                && m_enableDepth)
            {
                DepthListener.SetCallback();
            }

            if (m_tangoConfig.SetBool(TangoConfig.Keys.ENABLE_COLOR_CAMERA_BOOL, m_enableVideoOverlay) && 
                m_enableVideoOverlay)
            {
                _SetVideoOverlayCallbacks();
            }

            TangoEventListener.SetCallback();

            if (m_enable3DReconstruction)
            {
                Register(m_tango3DReconstruction);
            }

            _TangoConnect();
        }
예제 #16
0
        /// <summary>
        /// Unity callback when this object is destroyed.
        /// </summary>
        private void OnDestroy()
        {
            Debug.Log("TangoApplication.OnDestroy()");
            PoseListener.Reset();
            DepthListener.Reset();
            VideoOverlayListener.Reset();
            TangoEventListener.Reset();
            AreaDescriptionEventListener.Reset();

            Shutdown();

            // Clean up configs.
            if (m_tangoConfig != null)
            {
                m_tangoConfig.Dispose();
                m_tangoConfig = null;
            }

            if (m_tangoRuntimeConfig != null)
            {
                m_tangoRuntimeConfig.Dispose();
                m_tangoRuntimeConfig = null;
            }
        }