From 5b243b4d2353e97303dd469f7482e6a01c8efcb0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vladim=C3=ADr=20Ulman?= <ulman@mpi-cbg.de>
Date: Thu, 13 Oct 2016 23:08:49 +0200
Subject: [PATCH] Added ActiveMesh::ExportSTL().

---
 cmath3d/TriangleMesh.cpp | 22 ++++++++++++++++++++++
 cmath3d/TriangleMesh.h   |  1 +
 2 files changed, 23 insertions(+)

diff --git a/cmath3d/TriangleMesh.cpp b/cmath3d/TriangleMesh.cpp
index 834e676..56bb04e 100644
--- a/cmath3d/TriangleMesh.cpp
+++ b/cmath3d/TriangleMesh.cpp
@@ -181,6 +181,28 @@ int ActiveMesh::ImportSTL(const char *filename)
 	return(0);
 }
 
+int ActiveMesh::ExportSTL(const char *filename)
+{
+	//try to open the file
+	std::ofstream file(filename);
+	if (!file.is_open()) return(1);
+
+	file << "solid Vladimir Ulman - meshSurface testing app\n";
+
+	for (unsigned int i=0; i < ID.size(); i+=3)
+	{
+		file << "facet normal " << norm[i/3].x << " " << norm[i/3].y << " " << norm[i/3].z << "\n";
+		file << "outer loop\n";
+		file << "vertex " << Pos[ID[i+0]].x << " " << Pos[ID[i+0]].y << " " << Pos[ID[i+0]].z << "\n";
+		file << "vertex " << Pos[ID[i+1]].x << " " << Pos[ID[i+1]].y << " " << Pos[ID[i+1]].z << "\n";
+		file << "vertex " << Pos[ID[i+2]].x << " " << Pos[ID[i+2]].y << " " << Pos[ID[i+2]].z << "\n";
+		file << "endloop\nendfacet\n";
+	}
+
+	file.close();
+	return(0);
+}
+
 
 int ActiveMesh::ImportVTK(const char *filename) //surface version
 {
diff --git a/cmath3d/TriangleMesh.h b/cmath3d/TriangleMesh.h
index f332791..e28d8ca 100644
--- a/cmath3d/TriangleMesh.h
+++ b/cmath3d/TriangleMesh.h
@@ -96,6 +96,7 @@ class ActiveMesh
 	///input is filename
 	///returns 0 on success, otherwise non-zero
 	int ImportSTL(const char* filename);
+	int ExportSTL(const char* filename);
 	int ImportVTK(const char* filename);
 	int ImportVTK_Volumetric(const char* filename);
 
-- 
GitLab