public void WriteDepthToLogFile(TangoXYZij depth, float[] pointData, int[] indices, int rows, int cols) { if (!playbackData) { UpdatePoints(pointData, depth.xyz_count); } if (depthFileWriter == null) { return; } debugText2 = "Writing Depth: " + depth.xyz_count.ToString(); depthFileWriter.Write("depthframe\n"); depthFileWriter.Write(depth.timestamp + "\n"); depthFileWriter.Write(depth.xyz_count + "\n"); for (int i = 0; i < depth.xyz_count; i++) { depthFileWriter.Write(pointData[3 * i]); depthFileWriter.Write(pointData[3 * i + 1]); depthFileWriter.Write(pointData[3 * i + 2]); } depthFileWriter.Flush(); }
public int ReadDepthFromFile(BinaryReader reader, ref TangoXYZij depthFrame, ref float[] points) { string frameMarker; try { frameMarker = reader.ReadString(); } catch (EndOfStreamException x) { reader.BaseStream.Position = 0; Reset(); print("Restating log file: " + x.ToString()); frameMarker = reader.ReadString(); } if (frameMarker.CompareTo("depthframe\n") != 0) { debugText = "Failed to read depth"; return(-1); } depthFrame.timestamp = double.Parse(reader.ReadString()); depthFrame.xyz_count = int.Parse(reader.ReadString()); //load up the data for (int i = 0; i < depthFrame.xyz_count; i++) { points[3 * i] = reader.ReadSingle(); points[3 * i + 1] = reader.ReadSingle(); points[3 * i + 2] = reader.ReadSingle(); } return(0); }
public int LoadDepthFromLogFile(BinaryReader reader, ref TangoXYZij depthFrame, ref float[] points) { string frameMarker; try { frameMarker = reader.ReadString(); } catch (EndOfStreamException x) { reader.BaseStream.Position = 0; print("Restating log file: " + x.ToString()); frameMarker = reader.ReadString(); } if (frameMarker.CompareTo("depthframe\n") != 0) { debugText = "Failed to load"; return(-1); } depthFrame.timestamp = double.Parse(reader.ReadString()); depthFrame.xyz_count = int.Parse(reader.ReadString()); debugText2 = depthFrame.timestamp.ToString(); debugText3 = depthFrame.xyz_count.ToString(); //if we are too small increase the memory array with some room to spare if (depthFrame.xyz_count * 3 > loadedRawPoints.Length) { loadedRawPoints = new float[2 * 3 * depthFrame.xyz_count]; } //load up the data for (int i = 0; i < depthFrame.xyz_count; i++) { loadedRawPoints[3 * i] = reader.ReadSingle(); loadedRawPoints[3 * i + 1] = reader.ReadSingle(); loadedRawPoints[3 * i + 2] = reader.ReadSingle(); } //randomly subsample for (int i = 0; i < renderCount; i++) { int srcIndex = UnityEngine.Random.Range(0, depthFrame.xyz_count - 1); points[3 * i] = loadedRawPoints[3 * srcIndex]; points[3 * i + 1] = loadedRawPoints[3 * srcIndex + 1]; points[3 * i + 2] = loadedRawPoints[3 * srcIndex + 2]; } return(0); }
/// <summary> /// Callback that gets called when depth is available /// from the Tango Service. /// DO NOT USE THE UNITY API FROM INSIDE THIS FUNCTION! /// </summary> /// <param name="callbackContext">Callback context.</param> /// <param name="xyzij">Xyzij.</param> protected override void _OnDepthAvailable(IntPtr callbackContext, TangoXYZij xyzij) { // Calculate the time since the last successful depth data // collection. if (m_previousDepthDeltaTime == 0.0) { m_previousDepthDeltaTime = xyzij.timestamp; } else { m_numberOfDepthSamples++; m_timeSinceLastDepthFrame = xyzij.timestamp - m_previousDepthDeltaTime; m_previousDepthDeltaTime = xyzij.timestamp; } // Fill in the data to draw the point cloud. if (xyzij != null && m_vertices != null) { int numberOfActiveVertices = xyzij.xyz_count; m_pointsCount = numberOfActiveVertices; if (numberOfActiveVertices > 0) { float[] allPositions = new float[numberOfActiveVertices * 3]; Marshal.Copy(xyzij.xyz[0], allPositions, 0, allPositions.Length); for (int i = 0; i < m_vertices.Length; ++i) { if (i < xyzij.xyz_count) { m_vertices[i].x = allPositions[i * 3]; m_vertices[i].y = allPositions[(i * 3) + 1]; m_vertices[i].z = allPositions[(i * 3) + 2]; } else { m_vertices[i].x = m_vertices[i].y = m_vertices[i].z = 0.0f; } } m_isDirty = true; } } }
public void WriteDepthToFile(BinaryWriter writer, TangoXYZij depth, float[] pointData) { if (writer == null) { return; } writer.Write("depthframe\n"); writer.Write(depth.timestamp + "\n"); writer.Write(depth.xyz_count + "\n"); for (int i = 0; i < depth.xyz_count; i++) { writer.Write(pointData[3 * i]); writer.Write(pointData[3 * i + 1]); writer.Write(pointData[3 * i + 2]); } writer.Flush(); }
/// <summary> /// Callback that gets called when depth is available /// from the Tango Service. /// </summary> /// <param name="callbackContext">Callback context.</param> /// <param name="xyzij">Xyzij.</param> protected abstract void _OnDepthAvailable(IntPtr callbackContext, TangoXYZij xyzij);
public void LoadLogFile(string filename, ref TangoXYZij depthFrame, ref float[] points) { depthFileReader = new BinaryReader(File.Open(Application.persistentDataPath + "/" + filename, FileMode.Open)); debugText = "Loading from: " + filename + " " + depthFileReader.ToString(); LoadDepthFromLogFile(depthFileReader, ref depthFrame, ref points); }