/// <summary> /// Raises the tango depth available event. /// </summary> /// <param name="tangoDepth">Tango depth.</param> public void OnTangoDepthAvailable(Tango.TangoUnityDepth tangoDepth) { if (m_enableUXLibrary) { AndroidHelper.ParseTangoDepthPointCount(tangoDepth.m_pointCount); } }
/// <summary> /// Pose callback from Project Tango. /// </summary> /// <param name="pose">Tango pose data.</param> public void OnTangoPoseAvailable(Tango.TangoPoseData pose) { if (pose == null) { Debug.Log("TangoPostData is null."); return; } if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE && pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE) { if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID) { m_tangoPosition = new Vector3((float)pose.translation[0], (float)pose.translation[1], (float)pose.translation[2]); m_tangoRotation = new Quaternion((float)pose.orientation[0], (float)pose.orientation[1], (float)pose.orientation[2], (float)pose.orientation[3]); } else { m_tangoPosition = Vector3.zero; m_tangoRotation = Quaternion.identity; } } }
/// <summary> /// Register to get Tango image events. /// /// NOTE: Tango image events happen on a different thread than the main /// Unity thread. /// </summary> /// <param name="cameraId">Camera identifier to get events for.</param> /// <param name="useExperimentalOverlay">If true, use the experimental video overlay.</param> /// <param name="videoOverlayTexture">The video overlay texture to use. Only used in experimental mode.</param> internal virtual void SetCallback(Tango.TangoEnums.TangoCameraId cameraId, bool useExperimentalOverlay, YUVTexture videoOverlayTexture) { m_usingExperimentalOverlay = useExperimentalOverlay; if (!useExperimentalOverlay) { m_previousImageBuffer = new TangoUnityImageData(); m_onImageAvailable = new Tango.VideoOverlayProvider.TangoService_onImageAvailable(_OnImageAvailable); Tango.VideoOverlayProvider.SetCallback(cameraId, m_onImageAvailable); } else { if (videoOverlayTexture != null) { m_onUnityFrameAvailable = new Tango.VideoOverlayProvider.TangoService_onUnityFrameAvailable(_OnExperimentalUnityFrameAvailable); VideoOverlayProvider.ExperimentalConnectTexture(cameraId, videoOverlayTexture, m_onUnityFrameAvailable); Debug.Log("VideoOverlayListener.SetCallback() : Experimental Overlay listener hooked up"); } else { Debug.Log("VideoOverlayListener.SetCallback() : No Texture2D found!"); } } }
/// <summary> /// Handle the callback sent by the Tango Service /// when a new pose is sampled. /// </summary> /// <param name="pose">Pose.</param> public void OnTangoPoseAvailable(Tango.TangoPoseData pose) { // The callback pose is for device with respect to start of service pose. if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE && pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE) { if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID) { popManager.tangoInitialized = true; popManager.TriggerAPICallbackFPS(); UpdateInterpolationData(pose); if (enableInterpolation) { if (unityTimestampOffset > float.Epsilon) { UpdateUsingInterpolatedPose(Time.realtimeSinceStartup + unityTimestampOffset); } } else { UpdateUsingInterpolatedPose(currPose.timestamp); } } } }
/// <summary> /// Handle the callback sent by the Tango Service /// when a new pose is sampled. /// </summary> /// <param name="pose">Pose.</param> public void OnTangoPoseAvailable(Tango.TangoPoseData pose) { // Get out of here if the pose is null if (pose == null) { Debug.Log("TangoPoseDate is null."); return; } // The callback pose is for device with respect to start of service pose. if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE && pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE) { // Update the stats for the pose for the debug text if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID) { // Create new Quaternion and Vec3 from the pose data received in the event. m_tangoPosition = new Vector3((float)pose.translation[0], (float)pose.translation[1], (float)pose.translation[2]); m_tangoRotation = new Quaternion((float)pose.orientation[0], (float)pose.orientation[1], (float)pose.orientation[2], (float)pose.orientation[3]); // Reset the current status frame count if the status code changed. if (pose.status_code != m_status) { m_frameCount = 0; } m_frameCount++; // Compute delta frame timestamp. m_frameDeltaTime = (float)pose.timestamp - m_prevFrameTimestamp; m_prevFrameTimestamp = (float)pose.timestamp; // Construct the start of service with respect to device matrix from the pose. Matrix4x4 matrixssTd = Matrix4x4.TRS(m_tangoPosition, m_tangoRotation, Vector3.one); // Converting from Tango coordinate frame to Unity coodinate frame. Matrix4x4 matrixuwTuc = m_matrixuwTss * matrixssTd * m_matrixdTuc; // Extract new local position transform.position = matrixuwTuc.GetColumn(3); // Extract new local rotation transform.rotation = Quaternion.LookRotation(matrixuwTuc.GetColumn(2), matrixuwTuc.GetColumn(1)); } else { // if the current pose is not valid we set the pose to identity m_tangoPosition = Vector3.zero; m_tangoRotation = Quaternion.identity; } // Finally, apply the new pose status m_status = pose.status_code; } }
/// <summary> /// Raises the tango pose available event. /// </summary> /// <param name="poseData">Pose data.</param> public void OnTangoPoseAvailable(Tango.TangoPoseData poseData) { if(m_enableUXLibrary) { AndroidHelper.ParseTangoPoseStatus((int)poseData.status_code); } }
public bool GuessTango(Tango tango) { if (GameState != GameState.Playing) { throw new ServiceException("Invalid state"); } _tryNumber++; if (tango.Honyaku == _currentCard.Tango.Honyaku) { if (_currentWrong) { return(true); } _tangoService.Mark(_currentCard.Tango, Mark.Answer); _currentGuessed = true; _correctNumber++; return(true); } _currentWrong = true; _wrongNumber++; _tangoService.Mark(_currentCard.Tango, Mark.Wrong); return(false); }
/// <summary> /// Raises the tango depth available event. /// </summary> /// <param name="tangoDepth">Tango depth.</param> public void OnTangoDepthMultithreadedAvailable(Tango.TangoXYZij tangoDepth) { if (m_enableUXLibrary) { AndroidHelper.ParseTangoDepthPointCount(tangoDepth.xyz_count); } }
// Pose callbacks from Project Tango public void OnTangoPoseAvailable(Tango.TangoPoseData pose) { // Do nothing if we don't get a pose if (pose == null) { Debug.Log("TangoPoseData is null."); return; } // The callback pose is for device with respect to start of service pose. if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE && pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE) { if (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID) { // Cache the position and rotation to be set in the update function. m_tangoPosition = new Vector3((float)pose.translation [0], (float)pose.translation [1], (float)pose.translation [2]); m_tangoRotation = new Quaternion((float)pose.orientation [0], (float)pose.orientation [1], (float)pose.orientation [2], (float)pose.orientation [3]); } else // if the current pose is not valid we set the pose to identity { m_tangoPosition = Vector3.zero; m_tangoRotation = Quaternion.identity; } } }
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; } }
private void StartTango() { tango = new Tango(this, new Runnable(() => { Log.Debug(Tag, "TangoRunnable"); try { TangoSupport.Initialize(); var tangoConfig = GetTangoConfig(tango); tango.Connect(tangoConfig); TangoAddListeners(); tango.ConnectTextureId(TangoCameraIntrinsics.TangoCameraColor, -1); } catch (TangoOutOfDateException e) { Log.Error(Tag, "TangoOutOfDateException", e); } catch (TangoErrorException e) { Log.Error(Tag, "TangoErrorException", e); } catch (TangoInvalidException e) { Log.Error(Tag, "TangoInvalidException", e); } })); }
public TangoEditor(Window parent, int id) : this(parent) { _tango = _tangoService.Get(id); _idEntry.Text = _tango.Id.ToString(); _tangoEntry.Text = _tango.Namae; _furiganaEntry.Text = _tango.Furigana; _romajiEntry.Text = _tango.Romaji; _honyakuEntry.Text = _tango.Honyaku; }
public Tango Insert(string namae, string furigana, string romaji, string honyaku) { var tango = new Tango { Namae = namae, Furigana = furigana, Romaji = romaji, Honyaku = honyaku }; _context.Conn.Insert(tango); return(tango); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); surfaceView = (SurfaceView)FindViewById(Resource.Id.cameraView); surfaceHolder = surfaceView.Holder; surfaceHolder.AddCallback(this); mTango = new Tango(this); }
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; }
/// <summary> /// Raises the tango event available event handler event. /// </summary> /// <param name="tangoEvent">Tango event.</param> public void OnTangoEventMultithreadedAvailableEventHandler(Tango.TangoEvent tangoEvent) { if (m_enableUXLibrary) { AndroidHelper.ParseTangoEvent(tangoEvent.timestamp, (int)tangoEvent.type, tangoEvent.event_key, tangoEvent.event_value); } }
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); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); //_pointCloudManager = new TangoPointCloudManager(); //_windowManager = ApplicationContext.GetSystemService(Context.WindowService).JavaCast<IWindowManager>(); var intent = Tango.GetRequestPermissionIntent(Tango.PermissiontypeAdfLoadSave); StartActivityForResult(intent, 1); }
public static TangoConfig SetupTangoConfigForNavigating(Tango tango, string uuid) { var config = tango.GetConfig(TangoConfig.ConfigTypeDefault); config.PutBoolean(TangoConfig.KeyBooleanMotiontracking, true); config.PutString(TangoConfig.KeyStringAreadescription, uuid); // is this next one are learning mode? config.PutBoolean(TangoConfig.KeyBooleanLearningmode, false); config.PutBoolean(TangoConfig.KeyBooleanLowlatencyimuintegration, true); config.PutBoolean(TangoConfig.KeyBooleanAutorecovery, true); return(config); }
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); }
/// <summary> /// Register to get Tango image events for the texture ID is updated. /// /// NOTE: Tango image events happen on a different thread than the main /// Unity thread. /// </summary> /// <param name="cameraId">Camera identifier to get events for.</param> /// <param name="videoOverlayTexture">The video overlay texture to use.</param> internal virtual void SetCallbackTextureIdMethod(Tango.TangoEnums.TangoCameraId cameraId, YUVTexture videoOverlayTexture) { if (videoOverlayTexture != null) { m_onUnityFrameAvailable = new Tango.VideoOverlayProvider.TangoService_onUnityFrameAvailable(_OnExperimentalUnityFrameAvailable); VideoOverlayProvider.ExperimentalConnectTexture(cameraId, videoOverlayTexture, m_onUnityFrameAvailable); Debug.Log("VideoOverlayListener.SetCallback() : Experimental Overlay listener hooked up"); } else { Debug.Log("VideoOverlayListener.SetCallback() : No Texture2D found!"); } }
public void Mark(Tango tango, Mark mark) { switch (mark) { case Services.Mark.Answer: tango.Answer++; break; case Services.Mark.Wrong: tango.Wrong++; break; case Services.Mark.Seen: tango.Seen++; break; } _context.Conn.Update(tango); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_navigate_route); var button = (Button)FindViewById(Resource.Id.back); button.Click += delegate { DisconnectTango(); var intent = new Intent(this, typeof(MainActivity)); StartActivity(intent); }; tango = new Tango(this, new Runnable(() => { // now load the latest adf... StartTango(); })); }
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) // ; //} })); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); StartActivityForResult(Tango.GetRequestPermissionIntent(Tango.PermissiontypeAdfLoadSave), 0); SetContentView(Resource.Layout.activity_main); var button = (Button)FindViewById(Resource.Id.listadfs); button.Click += delegate { var intent = new Intent(this, typeof(ListAdfsActivity)); StartActivity(intent); }; var buttonRec = (Button)FindViewById(Resource.Id.recording); buttonRec.Click += delegate { var intent = new Intent(this, typeof(CreateRouteActivity)); StartActivity(intent); }; var buttonNav = (Button)FindViewById(Resource.Id.navigating); buttonNav.Click += delegate { var intent = new Intent(this, typeof(NavigateRouteActivity)); StartActivity(intent); }; var buttonUrho = (Button)FindViewById(Resource.Id.urho); buttonUrho.Click += delegate { var intent = new Intent(this, typeof(UrhoActivity)); StartActivity(intent); }; }
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); } })); }
private void ShowAdfs() { var adfs = new List <string>(); tango = new Tango(this, new Runnable(() => { var listAdfs = tango.ListAreaDescriptions(); foreach (var uuid in listAdfs) { var metadata = tango.LoadAreaDescriptionMetaData(uuid); var name = new String(metadata.Get(TangoAreaDescriptionMetaData.KeyName)).ToString(); var uuid_in = new String(metadata.Get(TangoAreaDescriptionMetaData.KeyUuid)).ToString(); adfs.Add(name); } RunOnUiThread(() => { var lv = (ListView)FindViewById(Resource.Id.listView1); var adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, adfs); lv.Adapter = adapter; }); })); }
public FlashCard(Tango tango) { Tango = tango; }
/// <summary> /// OnTangoPoseAvailable event from Tango. /// /// In this function, we only listen to the Start-Of-Service with respect to Area-Description frame pair. This pair /// indicates a relocalization or loop closure event happened, base on that, we either start the initialize the /// interaction or begin meshing if applicable. /// </summary> /// <param name="poseData">Returned pose data from TangoService.</param> public void OnTangoPoseAvailable(Tango.TangoPoseData poseData) { // This frame pair's callback indicates that a loop closure or relocalization has happened. // // When learning mode is off, and an Area Description is loaded, this callback indicates a relocalization event. // In our case, when the device is relocalized, user interaction is allowed and meshing starts if applicable. if (poseData.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION && poseData.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE && poseData.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID) { // When we get the first loop closure/ relocalization event, we initialized all the in-game interactions. if (!m_initialized) { Debug.Log("First loop closure/relocalization"); m_initialized = true; m_relocalizeImage.gameObject.SetActive(false); if (m_3dReconstruction) { m_tangoApplication.Set3DReconstructionEnabled(true); } else { m_tangoApplication.Set3DReconstructionEnabled(false); } } } }
/// <summary> /// Compute a rotation from rotation a to rotation b, in form of the OrientationManager.Rotation enum. /// </summary> /// <param name="b">Target rotation frame.</param> /// <param name="a">Start rotation frame.</param> /// <returns>The orientation index that follows Android screen rotation standard.</returns> public static Tango.OrientationManager.Rotation RotateFromAToB(Tango.OrientationManager.Rotation b, Tango.OrientationManager.Rotation a) { int ret = (int)b - (int)a; if (ret < 0) { ret += 4; } return (Tango.OrientationManager.Rotation)(ret % 4); }
public SaveAdfTask(Context context, Tango tango, string adfName) { this.context = context; this.adfName = adfName; this.tango = tango; }
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"); }
/// <summary> /// OnTangoPoseAvailable event from Tango. /// /// In this function, we only listen to the Start-Of-Service with respect to Area-Description frame pair. This pair /// indicates a relocalization or loop closure event happened, base on that, we either start the initialize the /// interaction or do a bundle adjustment for all marker position. /// </summary> /// <param name="poseData">Returned pose data from TangoService.</param> public void OnTangoPoseAvailable(Tango.TangoPoseData poseData) { // This frame pair's callback indicates that a loop closure or relocalization has happened. // // When learning mode is on, this callback indicates the loop closure event. Loop closure will happen when the // system recognizes a pre-visited area, the loop closure operation will correct the previously saved pose // to achieve more accurate result. (pose can be queried through GetPoseAtTime based on previously saved // timestamp). // Loop closure definition: https://en.wikipedia.org/wiki/Simultaneous_localization_and_mapping#Loop_closure // // When learning mode is off, and an Area Description is loaded, this callback indicates a // relocalization event. Relocalization is when the device finds out where it is with respect to the loaded // Area Description. In our case, when the device is relocalized, the markers will be loaded because we // know the relatvie device location to the markers. if (poseData.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION && poseData.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE && poseData.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID) { // When we get the first loop closure/ relocalization event, we initialized all the in-game interactions. if (!m_initialized) { m_initialized = true; if (m_curAreaDescription == null) { Debug.Log("AndroidInGameController.OnTangoPoseAvailable(): m_curAreaDescription is null"); return; } _LoadMarkerFromDisk(); } } }
/// <summary> /// OnTangoPoseAvailable event from Tango. /// /// In this function, we only listen to the Start-Of-Service with respect to Area-Description frame pair. This pair /// indicates a relocalization or loop closure event happened, base on that, we either start the initialize the /// interaction or do a bundle adjustment for all marker position. /// </summary> /// <param name="poseData">Returned pose data from TangoService.</param> public void OnTangoPoseAvailable(Tango.TangoPoseData poseData) { // This frame pair's callback indicates that a loop closure or relocalization has happened. // // When learning mode is on, this callback indicates the loop closure event. Loop closure will happen when the // system recognizes a pre-visited area, the loop closure operation will correct the previously saved pose // to achieve more accurate result. (pose can be queried through GetPoseAtTime based on previously saved // timestamp). // Loop closure definition: https://en.wikipedia.org/wiki/Simultaneous_localization_and_mapping#Loop_closure // // When learning mode is off, and an Area Description is loaded, this callback indicates a // relocalization event. Relocalization is when the device finds out where it is with respect to the loaded // Area Description. In our case, when the device is relocalized, the markers will be loaded because we // know the relatvie device location to the markers. if (poseData.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION && poseData.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE && poseData.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID) { // When we get the first loop closure/ relocalization event, we initialized all the in-game interactions. if (!m_initialized) { m_initialized = true; if (m_curAreaDescription == null) { Debug.Log("AndroidInGameController.OnTangoPoseAvailable(): m_curAreaDescription is null"); return; } // Attempt to load the exsiting markers from storage. List<MarkerData> xmlDataList = _ReadFromXml(m_curAreaDescription.m_uuid + ".xml"); if (xmlDataList == null) { Debug.Log("AndroidInGameController.OnTangoPoseAvailable(): xmlDataList is null"); return; } m_markerList.Clear(); foreach (MarkerData mark in xmlDataList) { // Instantiate all markers' gameobject. GameObject temp = Instantiate(m_markPrefabs[mark.m_type], mark.m_position, mark.m_orientation) as GameObject; m_markerList.Add(temp); } } else { Debug.Log("AndroidInGameController.OnTangoPoseAvailable(): relocalized"); if (m_tangoApplication.m_enableAreaLearning) { _UpdateMarkersForLoopClosures(); } } } }
/// <summary> /// Returns the RGB value at a given theta and phi given a TangoImageBuffer. /// </summary> /// <param name="buffer">The TangoImageBuffer to sample.</param> /// <param name="i">Range from [0..height].</param> /// <param name="j">Range from [0..width].</param> /// <returns>The RGB value on the buffer at the given theta and phi.</returns> private Vector3 _GetRgbFromImageBuffer(Tango.TangoUnityImageData buffer, int i, int j) { int width = (int)buffer.width; int height = (int)buffer.height; int uv_buffer_offset = width * height; int x_index = j; if (j % 2 != 0) { x_index = j - 1; } // Get the YUV color for this pixel. int yValue = buffer.data[(i * width) + j]; int uValue = buffer.data[uv_buffer_offset + ((i / 2) * width) + x_index + 1]; int vValue = buffer.data[uv_buffer_offset + ((i / 2) * width) + x_index]; // Convert the YUV value to RGB. float r = yValue + (1.370705f * (vValue - 128)); float g = yValue - (0.689001f * (vValue - 128)) - (0.337633f * (uValue - 128)); float b = yValue + (1.732446f * (uValue - 128)); Vector3 result = new Vector3(r / 255.0f, g / 255.0f, b / 255.0f); // Gamma correct color to linear scale. result.x = Mathf.Pow(Mathf.Max(0.0f, result.x), 2.2f); result.y = Mathf.Pow(Mathf.Max(0.0f, result.y), 2.2f); result.z = Mathf.Pow(Mathf.Max(0.0f, result.z), 2.2f); return result; }
public void Update(Tango tango) { _context.Conn.Update(tango); }
private TangoConfig GetTangoConfig(Tango tango) { var config = ConfigInitialize.SetupTangoConfigForRecording(tango); return(config); }
/// <summary> /// Register to get Tango image events for getting the texture byte buffer callback. /// /// NOTE: Tango image events happen on a different thread than the main /// Unity thread. /// </summary> /// <param name="cameraId">Camera identifier to get events for.</param> internal virtual void SetCallbackByteBufferMethod(Tango.TangoEnums.TangoCameraId cameraId) { m_previousImageBuffer = new TangoUnityImageData(); m_onImageAvailable = new Tango.VideoOverlayProvider.TangoService_onImageAvailable(_OnImageAvailable); Tango.VideoOverlayProvider.SetCallback(cameraId, m_onImageAvailable); }
/// <summary> /// Handle the callback sent by the Tango Service /// when a new pose is sampled. /// DO NOT USE THE UNITY API FROM INSIDE THIS FUNCTION! /// </summary> /// <param name="callbackContext">Callback context.</param> /// <param name="pose">Pose.</param> public void OnTangoPoseAvailable(Tango.TangoPoseData pose) { // Get out of here if the pose is null if (pose == null) { Debug.Log("TangoPoseDate is null."); return; } // The callback pose is for device with respect to start of service pose. if (pose.framePair.baseFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_START_OF_SERVICE && pose.framePair.targetFrame == TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE) { if(pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID) { // Cache the position and rotation to be set in the update function. // This needs to be done because this callback does not // happen in the main game thread. m_tangoPosition = new Vector3((float)pose.translation [0], (float)pose.translation [1], (float)pose.translation [2]); m_tangoRotation = new Quaternion((float)pose.orientation [0], (float)pose.orientation [1], (float)pose.orientation [2], (float)pose.orientation [3]); } else // if the current pose is not valid we set the pose to identity { m_tangoPosition = Vector3.zero; m_tangoRotation = Quaternion.identity; } } // Reset the current status frame count if the status code changed. if (pose.status_code != m_status) { m_frameCount = 0; } // Update the stats for the pose for the debug text m_status = pose.status_code; m_frameCount++; // Compute delta frame timestamp. m_frameDeltaTime = (float)pose.timestamp - m_prevFrameTimestamp; m_prevFrameTimestamp = (float)pose.timestamp; // Switch m_isDirty to true, so that the new pose get rendered in update. m_isDirty = (pose.status_code == TangoEnums.TangoPoseStatusType.TANGO_POSE_VALID); }
/// <summary> /// This is called each time a Tango event happens. /// </summary> /// <param name="tangoEvent">Tango event.</param> public void OnTangoEventAvailableEventHandler(Tango.TangoEvent tangoEvent) { // We will not have the saving progress when the learning mode is off. if (!m_tangoApplication.m_areaDescriptionLearningMode) { return; } if (tangoEvent.type == TangoEnums.TangoEventType.TANGO_EVENT_AREA_LEARNING && tangoEvent.event_key == "AreaDescriptionSaveProgress") { m_savingText.text = "Saving... " + Mathf.RoundToInt(float.Parse(tangoEvent.event_value) * 100) + "%"; } }
public void _OnExperimentalUnityFrameAvailable(IntPtr callbackContext, Tango.TangoEnums.TangoCameraId cameraId) { m_previousCameraId = cameraId; m_shouldSendEvent = true; }
/// <summary> /// Sets the callback for image updates. /// </summary> /// <param name="cameraId">Camera identifier.</param> public virtual void SetCallback(Tango.TangoEnums.TangoCameraId cameraId) { m_onImageAvailable = new Tango.VideoOverlayProvider.TangoService_onImageAvailable(_OnImageAvailable); Tango.VideoOverlayProvider.SetCallback(cameraId, m_onImageAvailable); }
/// <summary> /// Handle the callback sent by the Tango Service /// when a new image is sampled. /// </summary> /// <param name="cameraId">Camera identifier.</param> /// <param name="callbackContext">Callback context.</param> /// <param name="imageBuffer">Image buffer.</param> protected abstract void _OnImageAvailable(IntPtr callbackContext, Tango.TangoEnums.TangoCameraId cameraId, Tango.TangoImageBuffer imageBuffer);
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_area_learning); mTangoEventTextView = (TextView)FindViewById(Resource.Id.tangoevent); mAdf2DeviceTranslationTextView = (TextView)FindViewById(Resource.Id.adf2devicePose); mStart2DeviceTranslationTextView = (TextView)FindViewById(Resource.Id.start2devicePose); mAdf2StartTranslationTextView = (TextView)FindViewById(Resource.Id.adf2startPose); mAdf2DeviceQuatTextView = (TextView)FindViewById(Resource.Id.adf2deviceQuat); mStart2DeviceQuatTextView = (TextView)FindViewById(Resource.Id.start2deviceQuat); mAdf2StartQuatTextView = (TextView)FindViewById(Resource.Id.adf2startQuat); mAdf2DevicePoseStatusTextView = (TextView)FindViewById(Resource.Id.adf2deviceStatus); mStart2DevicePoseStatusTextView = (TextView)FindViewById(Resource.Id.start2deviceStatus); mAdf2StartPoseStatusTextView = (TextView)FindViewById(Resource.Id.adf2startStatus); mAdf2DevicePoseCountTextView = (TextView)FindViewById(Resource.Id.adf2devicePosecount); mStart2DevicePoseCountTextView = (TextView)FindViewById(Resource.Id.start2devicePosecount); mAdf2StartPoseCountTextView = (TextView)FindViewById(Resource.Id.adf2startPosecount); mAdf2DevicePoseDeltaTextView = (TextView)FindViewById(Resource.Id.adf2deviceDeltatime); mStart2DevicePoseDeltaTextView = (TextView)FindViewById(Resource.Id.start2deviceDeltatime); mAdf2StartPoseDeltaTextView = (TextView)FindViewById(Resource.Id.adf2startDeltatime); mFirstPersonButton = (Button)FindViewById(Resource.Id.first_person_button); mThirdPersonButton = (Button)FindViewById(Resource.Id.third_person_button); mTopDownButton = (Button)FindViewById(Resource.Id.top_down_button); mTangoServiceVersionTextView = (TextView)FindViewById(Resource.Id.version); mApplicationVersionTextView = (TextView)FindViewById(Resource.Id.appversion); mGLView = (GLSurfaceView)FindViewById(Resource.Id.gl_surface_view); mSaveAdf = (Button)FindViewById(Resource.Id.saveAdf); mUUIDTextView = (TextView)FindViewById(Resource.Id.uuid); mSaveAdf.Visibility = Android.Views.ViewStates.Gone; // Set up button click listeners mFirstPersonButton.SetOnClickListener(this); mThirdPersonButton.SetOnClickListener(this); mTopDownButton.SetOnClickListener(this); PackageInfo packageInfo; try { packageInfo = this.PackageManager.GetPackageInfo(this.PackageName, 0); mApplicationVersionTextView.Text = packageInfo.VersionName; } catch (Android.Content.PM.PackageManager.NameNotFoundException e) { System.Diagnostics.Debug.WriteLine(e.ToString()); System.Diagnostics.Debug.WriteLine(e.StackTrace); } // Configure OpenGL renderer mRenderer = new ADRenderer(); mGLView.SetEGLContextClientVersion(2); mGLView.SetRenderer(mRenderer as Android.Opengl.GLSurfaceView.IRenderer); mGLView.RenderMode = Android.Opengl.Rendermode.WhenDirty; // Instantiate the Tango service mTango = new Tango(this); mIsRelocalized = false; Intent intent = Intent; mIsLearningMode = intent.GetBooleanExtra(ADStartActivity.USE_AREA_LEARNING, false); mIsConstantSpaceRelocalize = intent.GetBooleanExtra(ADStartActivity.LOAD_ADF, false); SetTangoConfig(); }