1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.cts.verifier.sensors.sixdof.Utils.PoseProvider; 17 18 public class PoseData { 19 /** Index of the X-value in the translation array. */ 20 public static final int INDEX_TRANSLATION_X = 0; 21 /** Index of the Y-value in the translation array. */ 22 public static final int INDEX_TRANSLATION_Y = 1; 23 /** Index of the Z-value in the translation array. */ 24 public static final int INDEX_TRANSLATION_Z = 2; 25 26 /** Index of the quaternion X-value in the rotation array. */ 27 public static final int INDEX_ROTATION_X = 0; 28 /** Index of the quaternion Y-value in the rotation array. */ 29 public static final int INDEX_ROTATION_Y = 1; 30 /** Index of the quaternion Z-value in the rotation array. */ 31 public static final int INDEX_ROTATION_Z = 2; 32 /** Index of the quaternion W-value in the rotation array. */ 33 public static final int INDEX_ROTATION_W = 3; 34 35 public double timestamp = 0; 36 37 /** 38 * Orientation, as a quaternion, of the pose of the target frame with reference to to the base 39 * frame. 40 * <p> 41 * Specified as (x,y,z,w) where RotationAngle is in radians: 42 * <pre> 43 * x = RotationAxis.x * sin(RotationAngle / 2) 44 * y = RotationAxis.y * sin(RotationAngle / 2) 45 * z = RotationAxis.z * sin(RotationAngle / 2) 46 * w = cos(RotationAngle / 2) 47 * </pre> 48 */ 49 public float mRotation[] = { 50 0.0f, 0.0f, 0.0f, 1.0f }; 51 52 /** 53 * Translation, ordered x, y, z, of the pose of the target frame relative to the reference 54 * frame. 55 */ 56 public float mTranslation[] = { 57 0.0f, 0.0f, 0.0f }; 58 PoseData(float[] sixDoFSensorValues, long timestamp)59 public PoseData(float[] sixDoFSensorValues, long timestamp){ 60 this.timestamp = timestamp; 61 mRotation[0] = sixDoFSensorValues[0]; 62 mRotation[1] = sixDoFSensorValues[1]; 63 mRotation[2] = sixDoFSensorValues[2]; 64 mRotation[3] = sixDoFSensorValues[3]; 65 mTranslation[0] = sixDoFSensorValues[4]; 66 mTranslation[1] = sixDoFSensorValues[5]; 67 mTranslation[2] = sixDoFSensorValues[6]; 68 } 69 PoseData(float[] translation, float[] rotation, long timestamp)70 public PoseData(float[] translation, float[] rotation, long timestamp){ 71 this.timestamp = timestamp; 72 mRotation[0] = rotation[0]; 73 mRotation[1] = rotation[1]; 74 mRotation[2] = rotation[2]; 75 mRotation[3] = rotation[3]; 76 mTranslation[0] = translation[0]; 77 mTranslation[1] = translation[1]; 78 mTranslation[2] = translation[2]; 79 } 80 81 /** 82 * Convenience function to get the rotation casted as an array of floats. 83 * 84 * @return The pose rotation. 85 */ getRotationAsFloats()86 public float[] getRotationAsFloats() { 87 float[] out = new float[4]; 88 for (int i = 0; i < 4; i++) { 89 out[i] = mRotation[i]; 90 } 91 return out; 92 } 93 94 /** 95 * Convenience function to get the translation casted as an array of floats. 96 * 97 * @return The pose translation. 98 */ getTranslationAsFloats()99 public float[] getTranslationAsFloats() { 100 float[] out = new float[3]; 101 for (int i = 0; i < 3; i++) { 102 out[i] = mTranslation[i]; 103 } 104 return out; 105 } 106 } 107