List of usage examples for java.nio FloatBuffer toString
public String toString()
From source file:Main.java
public static void main(String[] args) { FloatBuffer floatBuffer = FloatBuffer.allocate(10); floatBuffer.put(1, 1.23F);// w ww . j a va2s .c o m System.out.println(floatBuffer.toString()); }
From source file:com.projecttango.experiments.javapointcloud.PointCloudActivity.java
private void setTangoListeners() { // Configure the Tango coordinate frame pair final ArrayList<TangoCoordinateFramePair> framePairs = new ArrayList<TangoCoordinateFramePair>(); framePairs.add(new TangoCoordinateFramePair(TangoPoseData.COORDINATE_FRAME_START_OF_SERVICE, TangoPoseData.COORDINATE_FRAME_DEVICE)); // Listen for new Tango data mTango.connectListener(framePairs, new OnTangoUpdateListener() { @Override/*from ww w . j a v a2s.c o m*/ public void onPoseAvailable(final TangoPoseData pose) { mDeltaTime = (float) (pose.timestamp - mPosePreviousTimeStamp) * SECS_TO_MILLISECS; mPosePreviousTimeStamp = (float) pose.timestamp; if (mPreviousPoseStatus != pose.statusCode) { count = 0; } count++; mPreviousPoseStatus = pose.statusCode; mRenderer.getModelMatCalculator().updateModelMatrix(pose.getTranslationAsFloats(), pose.getRotationAsFloats()); mRenderer.updateViewMatrix(); mGLView.requestRender(); // Translation and Quaternion strings defined here. Can this be accessed later on xyzji availible? final DecimalFormat threeDec = new DecimalFormat("0.000"); final String translationString = "[" + threeDec.format(pose.translation[0]) + ", " + threeDec.format(pose.translation[1]) + ", " + threeDec.format(pose.translation[2]) + "] "; final String quaternionString = "[" + threeDec.format(pose.rotation[0]) + ", " + threeDec.format(pose.rotation[1]) + ", " + threeDec.format(pose.rotation[2]) + ", " + threeDec.format(pose.rotation[3]) + "] "; // Update the UI with TangoPose information runOnUiThread(new Runnable() { @Override public void run() { // Display pose data on screen in TextViews mPoseTextView.setText(translationString); mQuatTextView.setText(quaternionString); mPoseCountTextView.setText(Integer.toString(count)); mDeltaTextView.setText(threeDec.format(mDeltaTime)); if (pose.statusCode == TangoPoseData.POSE_VALID) { mPoseStatusTextView.setText(R.string.pose_valid); } else if (pose.statusCode == TangoPoseData.POSE_INVALID) { mPoseStatusTextView.setText(R.string.pose_invalid); } else if (pose.statusCode == TangoPoseData.POSE_INITIALIZING) { mPoseStatusTextView.setText(R.string.pose_initializing); } else if (pose.statusCode == TangoPoseData.POSE_UNKNOWN) { mPoseStatusTextView.setText(R.string.pose_unknown); } } }); // NEW - Printing data to an output Log Log.d(TAG, "OUTPUT onPoseAvailable:" + " TStamp: " + mPosePreviousTimeStamp + " dTime: " + mDeltaTime + " T: " + translationString + " R: " + quaternionString + " Status: " + mPoseStatusTextView.getText().toString()); } @Override public void onXyzIjAvailable(final TangoXyzIjData xyzIj) { Log.v(TAG, "SOME SHIT IS GOIN ON"); mCurrentTimeStamp = (float) xyzIj.timestamp; final float frameDelta = (mCurrentTimeStamp - mXyIjPreviousTimeStamp) * SECS_TO_MILLISECS; mXyIjPreviousTimeStamp = mCurrentTimeStamp; byte[] buffer = new byte[xyzIj.xyzCount * 3 * 4]; FileInputStream fileStream = new FileInputStream(xyzIj.xyzParcelFileDescriptor.getFileDescriptor()); try { fileStream.read(buffer, xyzIj.xyzParcelFileDescriptorOffset, buffer.length); fileStream.close(); } catch (IOException e) { e.printStackTrace(); } try { TangoPoseData pointCloudPose = mTango.getPoseAtTime(mCurrentTimeStamp, framePairs.get(0)); // NEW - Printing data to an output Log float[] translations = pointCloudPose.getTranslationAsFloats(); float[] rotations = pointCloudPose.getRotationAsFloats(); FloatBuffer mPointCloudFloatBuffer; mPointCloudFloatBuffer = ByteBuffer.wrap(buffer).order(ByteOrder.nativeOrder()).asFloatBuffer(); PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter(outFile, true))); Log.d(TAG, "OUTPUT onxyzjiNEW:" + mPointCloudFloatBuffer.toString()); p.println(mPointCloudFloatBuffer.get(xyzIj.xyzCount) + ", " + mPointCloudFloatBuffer.get(xyzIj.xyzCount + 1) + ", " + mPointCloudFloatBuffer.get(xyzIj.xyzCount + 2)); p.close(); mRenderer.getPointCloud().UpdatePoints(buffer, xyzIj.xyzCount); mRenderer.getModelMatCalculator().updatePointCloudModelMatrix( pointCloudPose.getTranslationAsFloats(), pointCloudPose.getRotationAsFloats()); mRenderer.getPointCloud() .setModelMatrix(mRenderer.getModelMatCalculator().getPointCloudModelMatrixCopy()); } catch (IOException e) { e.printStackTrace(); } catch (TangoErrorException e) { Toast.makeText(getApplicationContext(), R.string.TangoError, Toast.LENGTH_SHORT).show(); } catch (IndexOutOfBoundsException e) { Toast.makeText(getApplicationContext(), "SHIT IS FUCKED", Toast.LENGTH_SHORT).show(); } catch (TangoInvalidException e) { Toast.makeText(getApplicationContext(), R.string.TangoError, Toast.LENGTH_SHORT).show(); } // Must run UI changes on the UI thread. Running in the Tango // service thread // will result in an error. runOnUiThread(new Runnable() { DecimalFormat threeDec = new DecimalFormat("0.000"); @Override public void run() { // Display number of points in the point cloud mPointCountTextView.setText(Integer.toString(xyzIj.xyzCount)); mFrequencyTextView.setText("" + threeDec.format(frameDelta)); mAverageZTextView.setText("" + threeDec.format(mRenderer.getPointCloud().getAverageZ())); } }); } @Override public void onTangoEvent(final TangoEvent event) { runOnUiThread(new Runnable() { @Override public void run() { mTangoEventTextView.setText(event.eventKey + ": " + event.eventValue); } }); Log.v(TAG, "onTangoEvent" + event.eventKey + ": " + event.eventValue); } }); }