/// <summary> /// creates a mesh from the current volume and tries to save it to a file /// </summary> /// <param name="volume">the volume</param> /// <param name="pkdp">the data package the mesh origined from</param> /// <param name="flipAxes">should achses be flipped?</param> static void exportMesh(ColorReconstruction volume, KinectDataPackage pkdp, bool flipAxes) { ColorMesh mesh = volume.CalculateMesh(1); Microsoft.Win32.SaveFileDialog dialog = new Microsoft.Win32.SaveFileDialog(); dialog.FileName = "KinectFusionMesh_" + pkdp.usedConfig.name + DateTime.UtcNow.ToShortDateString() + ".stl"; dialog.Filter = "STL Mesh Files|*.stl|All Files|*.*"; if (true == dialog.ShowDialog()) { using (BinaryWriter writer = new BinaryWriter(dialog.OpenFile())) { if (null == mesh || null == writer) { return; } var vertices = mesh.GetVertices(); var normals = mesh.GetNormals(); var indices = mesh.GetTriangleIndexes(); // Check mesh arguments if (0 == vertices.Count || 0 != vertices.Count % 3 || vertices.Count != indices.Count) { throw new Exception("Invalid Mesh Arguments"); } char[] header = new char[80]; writer.Write(header); // Write number of triangles int triangles = vertices.Count / 3; writer.Write(triangles); // Sequentially write the normal, 3 vertices of the triangle and attribute, for each triangle for (int i = 0; i < triangles; i++) { // Write normal var normal = normals[i * 3]; writer.Write(normal.X); writer.Write(flipAxes ? -normal.Y : normal.Y); writer.Write(flipAxes ? -normal.Z : normal.Z); // Write vertices for (int j = 0; j < 3; j++) { var vertex = vertices[(i * 3) + j]; writer.Write(vertex.X); writer.Write(flipAxes ? -vertex.Y : vertex.Y); writer.Write(flipAxes ? -vertex.Z : vertex.Z); } ushort attribute = 0; writer.Write(attribute); } } } }
void save() { ColorMesh mesh; mesh = reconstruction.CalculateMesh(3); using (var writer = new StreamWriter(@"mesh.ply", false, System.Text.Encoding.ASCII)) { KinectFusionHelper.SaveAsciiPlyMesh(mesh, writer, true, true); } }
/// <summary> /// constructor, creates a hashset of points from the mesh /// </summary> /// <param name="pVolume">the current reconstruction volume</param> public PointCloud(ColorReconstruction pVolume) { //takes the recontruction volume, exports the mesh and extracts the pointcloud from it ColorMesh mesh = pVolume.CalculateMesh(1); IReadOnlyCollection <Vector3> temp = mesh.GetVertices(); //create a hashset pointcloud_hs = createHashset(temp); }
private void CalculateMesh() { try { ColorMesh m = volume.CalculateMesh(2); currentMesh = m; CVMesh mesh = CVMesh.ConvertToMesh(m); master.RetrieveMesh(mesh); reader = null; sensor.Close(); CaptureCurrent = false; } catch (Exception ex) { Debug.Write(ex.Message); } }
private void WriteToMemory() { ColorMesh m = volume.CalculateMesh(1); PCDExporter.Output(m); //output your mesh somehow }