From f32fdaecee6151c22e50e4dadfa6565c673da6c7 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Fri, 21 Sep 2012 11:45:53 +0200
Subject: [PATCH] added utility programme to create structured quad meshes

---
 CMakeLists.txt                                |  4 ++
 Utils/SimpleMeshCreation/CMakeLists.txt       | 25 ++++++++
 .../generateStructuredQuadMesh.cpp            | 61 +++++++++++++++++++
 3 files changed, 90 insertions(+)
 create mode 100644 Utils/SimpleMeshCreation/CMakeLists.txt
 create mode 100644 Utils/SimpleMeshCreation/generateStructuredQuadMesh.cpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index ca7884bd6c9..30b3b673bd1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,6 +45,7 @@ OPTION(OGS_DONT_USE_QT "Disables all Qt specific code." OFF)
 OPTION(OGS_BUILD_CLI "Should the OGS simulator be built?" ON)
 OPTION(OGS_BUILD_TESTS "Should the test executables be built?" ON)
 OPTION(OGS_BUILD_GUI "Should the Data Explorer be built?" OFF)
+OPTION(OGS_BUILD_UTILS "Should the utilities programms be built?" OFF)
 
 OPTION(OGS_NO_EXTERNAL_LIBS "Builds OGS without any external dependencies." OFF)
 
@@ -97,6 +98,9 @@ IF(OGS_BUILD_GUI)
 	ADD_DEFINITIONS(-DOGS_BUILD_GUI)
 	ADD_SUBDIRECTORY(Gui)
 ENDIF() # OGS_BUILD_GUI
+IF(OGS_BUILD_UTILS)
+	ADD_SUBDIRECTORY( Utils/SimpleMeshCreation )
+ENDIF() # OGS_BUILD_UTILS
 
 CONFIGURE_FILE (BaseLib/BuildInfo.h.in ${PROJECT_BINARY_DIR}/BaseLib/BuildInfo.h)
 CONFIGURE_FILE (BaseLib/Configure.h.in ${PROJECT_BINARY_DIR}/BaseLib/Configure.h)
diff --git a/Utils/SimpleMeshCreation/CMakeLists.txt b/Utils/SimpleMeshCreation/CMakeLists.txt
new file mode 100644
index 00000000000..43cc6153f7b
--- /dev/null
+++ b/Utils/SimpleMeshCreation/CMakeLists.txt
@@ -0,0 +1,25 @@
+
+INCLUDE_DIRECTORIES(
+	${CMAKE_SOURCE_DIR}
+	${CMAKE_SOURCE_DIR}/BaseLib
+	${CMAKE_SOURCE_DIR}/FileIO
+	${CMAKE_SOURCE_DIR}/FileIO/Legacy
+	${CMAKE_SOURCE_DIR}/MeshLib
+	${CMAKE_SOURCE_DIR}/Gui/VtkVis
+)
+
+INCLUDE( ${VTK_USE_FILE} )
+
+# Create executables
+IF(QT4_FOUND)
+	ADD_EXECUTABLE( generateStructuredQuadMesh generateStructuredQuadMesh.cpp )
+	SET_TARGET_PROPERTIES( generateStructuredQuadMesh PROPERTIES FOLDER Utils)
+	TARGET_LINK_LIBRARIES( generateStructuredQuadMesh
+		MeshLib
+		FileIO
+		VtkVis	
+		vtkRendering
+		${QT_LIBRARIES}
+	)
+ENDIF() # QT4_FOUND
+
diff --git a/Utils/SimpleMeshCreation/generateStructuredQuadMesh.cpp b/Utils/SimpleMeshCreation/generateStructuredQuadMesh.cpp
new file mode 100644
index 00000000000..0c52a87f0b0
--- /dev/null
+++ b/Utils/SimpleMeshCreation/generateStructuredQuadMesh.cpp
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.net)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.net/LICENSE.txt
+ *
+ * \file generateStructuredQuadMesh.cpp
+ *
+ *  Created on  Sep 21, 2012 by Thomas Fischer
+ */
+
+// BaseLib
+#include "tclap/CmdLine.h"
+
+// FileIO/Legacy
+#include "MeshIO.h"
+
+// Gui/VtkVis
+#include "VtkMeshConverter.h"
+
+// MeshLib
+#include "Mesh.h"
+
+int main (int argc, char* argv[])
+{
+	TCLAP::CmdLine cmd("Simple mesh creator for unstructured meshes", ' ', "0.1");
+	TCLAP::ValueArg<std::string> mesh_arg("m", "mesh", "the mesh is stored to this file", true, "test.msh", "filename");
+	cmd.add( mesh_arg );
+	TCLAP::ValueArg<unsigned> width_arg("c","columns","the number of columns of the structured mesh", true, 1000, "number of cols");
+	cmd.add( width_arg );
+	TCLAP::ValueArg<unsigned> height_arg("r","rows","the number of rows of the structured mesh", true, 1000, "number of rows");
+	cmd.add( height_arg );
+	TCLAP::ValueArg<double> edge_length_arg("e","edge-length","the size of the edge length", false, 1, "edge length");
+	cmd.add( edge_length_arg );
+	TCLAP::ValueArg<double> origin_x_arg("x","origin-x","x coordinate of the origin of the mesh", false, 0.0, "x coords");
+	cmd.add( origin_x_arg );
+	TCLAP::ValueArg<double> origin_y_arg("y","origin-y","y coordinate of the origin of the mesh", false, 0.0, "y coords");
+	cmd.add( origin_y_arg );
+	TCLAP::ValueArg<double> origin_z_arg("z","origin-z","z coordinate of the origin of the mesh", false, 0.0, "z coords");
+	cmd.add( origin_z_arg );
+
+	cmd.parse( argc, argv );
+
+	// thanks to KR for this algorithm
+	unsigned height(height_arg.getValue()), width(width_arg.getValue());
+	double edge_length(edge_length_arg.getValue());
+	const unsigned size (height*width);
+	double* values (new double[size]);
+	const double origin[3] = {origin_x_arg.getValue() + edge_length/2, origin_y_arg.getValue() + edge_length/2, origin_z_arg.getValue()};
+	for (unsigned i=0; i<size; ++i) values[i]=0;
+	MeshLib::Mesh* mesh(VtkMeshConverter::convertImgToMesh(values, origin, height, width, edge_length, MshElemType::QUAD, UseIntensityAs::MATERIAL));
+
+	delete [] values;
+
+	FileIO::MeshIO mesh_writer;
+	mesh_writer.setMesh(mesh);
+	mesh_writer.setPrecision(12);
+	mesh_writer.writeToFile(mesh_arg.getValue());
+
+	delete mesh;
+}
-- 
GitLab