From fa3b1cc421d53a1c5f333532c2f34289ec404575 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Wed, 27 Jan 2016 09:50:49 +0100
Subject: [PATCH] [A/U/ME] Initial impl. of ExtractSurface tool.

---
 Applications/Utils/MeshEdit/CMakeLists.txt    |  5 ++
 .../Utils/MeshEdit/ExtractSurface.cpp         | 80 +++++++++++++++++++
 2 files changed, 85 insertions(+)
 create mode 100644 Applications/Utils/MeshEdit/ExtractSurface.cpp

diff --git a/Applications/Utils/MeshEdit/CMakeLists.txt b/Applications/Utils/MeshEdit/CMakeLists.txt
index 58198ca2dc0..eca263320bb 100644
--- a/Applications/Utils/MeshEdit/CMakeLists.txt
+++ b/Applications/Utils/MeshEdit/CMakeLists.txt
@@ -80,6 +80,10 @@ add_executable(queryMesh queryMesh.cpp)
 target_link_libraries(queryMesh FileIO)
 set_target_properties(queryMesh PROPERTIES FOLDER Utilities)
 
+add_executable(ExtractSurface ExtractSurface.cpp)
+target_link_libraries(ExtractSurface FileIO MeshLib)
+set_target_properties(ExtractSurface PROPERTIES FOLDER Utilities)
+
 ####################
 ### Installation ###
 ####################
@@ -95,6 +99,7 @@ install(TARGETS
 	AddTopLayer
 	CreateBoundaryConditionsAlongPolylines
 	queryMesh
+	ExtractSurface
 	RUNTIME DESTINATION bin COMPONENT Utilities
 )
 if(QT4_FOUND)
diff --git a/Applications/Utils/MeshEdit/ExtractSurface.cpp b/Applications/Utils/MeshEdit/ExtractSurface.cpp
new file mode 100644
index 00000000000..3b1875eba40
--- /dev/null
+++ b/Applications/Utils/MeshEdit/ExtractSurface.cpp
@@ -0,0 +1,80 @@
+/**
+ * @brief Extracts the surface from the given mesh.
+ *
+ * @copyright
+ * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/LICENSE.txt
+ */
+
+#include <algorithm>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "tclap/CmdLine.h"
+
+#include "Applications/ApplicationsLib/LogogSetup.h"
+
+#include "BaseLib/StringTools.h"
+#include "BaseLib/FileTools.h"
+
+#include "FileIO/readMeshFromFile.h"
+#include "FileIO/writeMeshToFile.h"
+
+#include "MathLib/Vector3.h"
+
+#include "MeshLib/Mesh.h"
+#include "MeshLib/MeshSurfaceExtraction.h"
+
+int main (int argc, char* argv[])
+{
+	ApplicationsLib::LogogSetup logog_setup;
+
+	TCLAP::CmdLine cmd("Tool extracts the surface of the given mesh.", ' ',
+	                   "0.1");
+	TCLAP::ValueArg<std::string> mesh_in(
+	    "i", "mesh-input-file",
+	    "the name of the file containing the input mesh", true, "",
+	    "file name of input mesh");
+	cmd.add(mesh_in);
+	TCLAP::ValueArg<std::string> mesh_out(
+	    "o", "mesh-output-file",
+	    "the name of the file the surface mesh should be written to", false, "",
+	    "file name of output mesh");
+	cmd.add(mesh_out);
+	TCLAP::ValueArg<double> x("x", "x-component", "x component of the normal",
+	                          false, 0, "floating point value");
+	cmd.add(x);
+	TCLAP::ValueArg<double> y("y", "y-component", "y component of the normal",
+	                          false, 0, "floating point value");
+	cmd.add(y);
+	TCLAP::ValueArg<double> z("z", "z-component", "z component of the normal",
+	                          false, -1.0, "floating point value");
+	cmd.add(z);
+	TCLAP::ValueArg<double> angle_arg(
+	    "a", "angle", "angle between given normal and element normal", false,
+	    90, "floating point value");
+	cmd.add(angle_arg);
+
+	cmd.parse(argc, argv);
+
+	std::unique_ptr<MeshLib::Mesh const> mesh(
+	    FileIO::readMeshFromFile(mesh_in.getValue()));
+	INFO("Mesh read: %u nodes, %u elements.", mesh->getNNodes(), mesh->getNElements());
+
+	// extract surface
+	MathLib::Vector3 const dir(x.getValue(), y.getValue(), z.getValue());
+	double const angle(angle_arg.getValue());
+	std::unique_ptr<MeshLib::Mesh> surface_mesh(
+	    MeshLib::MeshSurfaceExtraction::getMeshSurface(
+	        *mesh, dir, angle, "OriginalSubsurfaceNodeIDs"));
+
+	std::string out_fname(mesh_out.getValue());
+	if (out_fname.empty())
+		out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
+	FileIO::writeMeshToFile(*surface_mesh, out_fname);
+
+	return EXIT_SUCCESS;
+}
-- 
GitLab