Exemple #1
0
int main(int argc, char *argv[])
{
	LOGOG_INITIALIZE();
	BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter);
	logog::Cout *logogCout(new logog::Cout);
	logogCout->SetFormatter(*custom_format);

	TCLAP::CmdLine cmd("Moves the mesh nodes using the given displacement vector or if no displacement vector is given, moves the mesh nodes such that the centroid of the given mesh is in the origin.", ' ', "0.1");
	// Define a value argument and add it to the command line.
	// A value arg defines a flag and a type of value that it expects,
	// such as "-m meshfile".
	TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"","string");

	// Add the argument mesh_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( mesh_arg );

	TCLAP::ValueArg<double> x_arg("x","x","displacement in x direction", false, 0.0,"floating point number");
	cmd.add(x_arg);
	TCLAP::ValueArg<double> y_arg("y","y","displacement in y direction", false, 0.0,"floating point number");
	cmd.add(y_arg);
	TCLAP::ValueArg<double> z_arg("z","z","displacement in z direction", false, 0.0,"floating point number");
	cmd.add(z_arg);

	TCLAP::ValueArg<std::string> mesh_out_arg("o","output-mesh","output mesh file", false, "", "string");
	cmd.add(mesh_out_arg);

	cmd.parse( argc, argv );

	std::string fname (mesh_arg.getValue());

	MeshLib::Mesh* mesh = FileIO::readMeshFromFile(fname);

	MeshLib::Node displacement(0.0, 0.0, 0.0);
	if (fabs(x_arg.getValue()) < std::numeric_limits<double>::epsilon()
		&& fabs(y_arg.getValue()) < std::numeric_limits<double>::epsilon()
		&& fabs(z_arg.getValue()) < std::numeric_limits<double>::epsilon()) {
		GeoLib::AABB<MeshLib::Node> aabb(mesh->getNodes().begin(), mesh->getNodes().end());
		displacement[0] = -(aabb.getMaxPoint()[0] + aabb.getMinPoint()[0])/2.0;
		displacement[1] = -(aabb.getMaxPoint()[1] + aabb.getMinPoint()[1])/2.0;
		displacement[2] = -(aabb.getMaxPoint()[2] + aabb.getMinPoint()[2])/2.0;
	} else {
		displacement[0] = x_arg.getValue();
		displacement[1] = y_arg.getValue();
		displacement[2] = z_arg.getValue();
	}

	INFO("translate model (%f, %f, %f).", displacement[0], displacement[1], displacement[2]);
	MeshLib::moveMeshNodes(
		mesh->getNodes().begin(),
		mesh->getNodes().end(),
		displacement);

	std::string out_fname(mesh_out_arg.getValue());
	if (out_fname.empty()) {
		out_fname = BaseLib::dropFileExtension(mesh_out_arg.getValue());
		out_fname += "_displaced.vtu";
	}

	FileIO::VtuInterface mesh_io(mesh);
	mesh_io.writeToFile(out_fname);

	delete mesh;
	delete logogCout;
	delete custom_format;
	LOGOG_SHUTDOWN();
}
Exemple #2
0
int main (int argc, char* argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Prepares OGS-meshes for use in Unity.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::git_describe +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::git_describe);

    TCLAP::ValueArg<std::string> mesh_arg("i", "input",
        "the file containing the original OGS mesh", true,
        "", "input file name");
    cmd.add(mesh_arg);

    TCLAP::ValueArg<std::string> mesh_out_arg("o", "output",
        "the file name the result will be written to", true,
        "", "output file name");
    cmd.add(mesh_out_arg);

    cmd.parse(argc, argv);

    INFO("Reading mesh '%s' ... ", mesh_arg.getValue().c_str());
    std::unique_ptr<MeshLib::Mesh> mesh {MeshLib::IO::readMeshFromFile(mesh_arg.getValue())};
    if (!mesh)
        return EXIT_FAILURE;
    INFO("done.\n");

    INFO("Checking for line elements...");
    std::array<unsigned, 7> const& n_element_types =
        MeshLib::MeshInformation::getNumberOfElementTypes(*mesh);
    std::unique_ptr<MeshLib::Mesh> result;
    if (n_element_types[0] == 0)
    {
        INFO ("No line elements found.\n");
        result = std::move(mesh);
    }
    else if (n_element_types[0] == mesh->getNumberOfElements())
    {
        INFO ("Keeping line mesh.\n");
        result = std::move(mesh);
    }
    else
    {
        MeshLib::ElementSearch searcher(*mesh);
        std::size_t const n_rem_elems = searcher.searchByElementType(MeshLib::MeshElemType::LINE);
        result.reset(MeshLib::removeElements(*mesh, searcher.getSearchedElementIDs(), "temp mesh"));
        INFO ("%d line elements found and removed.\n", n_rem_elems);
    }

    INFO("Checking for cell-arrays...");
    if (containsCellVecs(*result))
        result.reset(constructMesh(*result));
    else
        INFO("No cell arrays found, keeping mesh structure.\n");

    INFO("Writing mesh '%s' ... ", mesh_out_arg.getValue().c_str());
    MeshLib::IO::VtuInterface writer(result.get(), vtkXMLWriter::Ascii, false);
    writer.writeToFile(mesh_out_arg.getValue());
    INFO("done.");

    return EXIT_SUCCESS;
}
int main (int argc, char* argv[])
{
	ApplicationsLib::LogogSetup logog_setup;

	TCLAP::CmdLine cmd(
		"Creates a layered 3D OGS mesh from an existing 2D OGS mesh and raster "
		"files representing subsurface layers. Supported raster formats are "
		"ArcGIS ascii rasters (*.asc) and Surfer Grids (*.grd)."
		"",
		' ',
		"1.0");

	TCLAP::ValueArg<std::string> mesh_arg("i", "input-mesh-file",
		"The name of the file containing the 2D input mesh.", true, "", "input file name");
	cmd.add(mesh_arg);

	TCLAP::ValueArg<std::string> mesh_out_arg("o", "output-mesh-file",
		"The name of the file to which the resulting 3D mesh will be written.",
		true, "", "output file name");
	cmd.add(mesh_out_arg);

	TCLAP::ValueArg<std::string> raster_path_arg("r", "raster-list", 
		"An ascii-file containing a list of raster files, starting from top (DEM) to bottom.",
		true, "", "list of raster files");
	cmd.add(raster_path_arg);

	double min_thickness (std::numeric_limits<double>::epsilon());
	TCLAP::ValueArg<double> min_thickness_arg("t", "thickness",
		"The minimum thickness of a layer to be integrated at any given location.",
		false, min_thickness, "minimum layer thickness");
	cmd.add(min_thickness_arg);

	cmd.parse(argc, argv);

	if (min_thickness_arg.isSet())
	{
		min_thickness = min_thickness_arg.getValue();
		if (min_thickness < 0)
		{
			ERR("Minimum layer thickness must be non-negative value.");
			return EXIT_FAILURE;
		}
	}

	INFO("Reading mesh \"%s\" ... ", mesh_arg.getValue().c_str());
	std::unique_ptr<MeshLib::Mesh> const sfc_mesh (FileIO::readMeshFromFile(mesh_arg.getValue()));
	if (!sfc_mesh) {
		ERR("Error reading mesh \"%s\".", mesh_arg.getValue().c_str());
		return EXIT_FAILURE;
	}
	if (sfc_mesh->getDimension() != 2) {
		ERR("Input mesh needs to be a 2D mesh.");
		return EXIT_FAILURE;
	}
	INFO("done.");

	std::vector<std::string> raster_paths;
	if (readRasterPaths(raster_path_arg.getValue(), raster_paths) != 0)
		return EXIT_FAILURE;

	MeshLib::MeshLayerMapper mapper;
	if (auto rasters = FileIO::readRasters(raster_paths))
	{
		if (!mapper.createLayers(*sfc_mesh, *rasters, min_thickness))
			return EXIT_FAILURE;
	}
	else
		return EXIT_FAILURE;

	std::string output_name (mesh_out_arg.getValue());
	if (!BaseLib::hasFileExtension("vtu", output_name))
		output_name.append(".vtu");
	INFO("Writing mesh \"%s\" ... ", output_name.c_str());
	FileIO::writeMeshToFile(*(mapper.getMesh("SubsurfaceMesh").release()), output_name);
	INFO("done.");

	return EXIT_SUCCESS;
}
Exemple #4
0
int main(int argc, char *argv[])
{
    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Moves the mesh nodes using the given displacement vector or if no "
        "displacement vector is given, moves the mesh nodes such that the "
        "centroid of the given mesh is in the origin.\n\n"
        "OpenGeoSys-6 software, version " +
            BaseLib::BuildInfo::ogs_version +
            ".\n"
            "Copyright (c) 2012-2019, OpenGeoSys Community "
            "(http://www.opengeosys.org)",
        ' ', BaseLib::BuildInfo::ogs_version);
    // Define a value argument and add it to the command line.
    // A value arg defines a flag and a type of value that it expects,
    // such as "-m meshfile".
    TCLAP::ValueArg<std::string> mesh_arg("m","mesh","input mesh file",true,"","string");

    // Add the argument mesh_arg to the CmdLine object. The CmdLine object
    // uses this Arg to parse the command line.
    cmd.add( mesh_arg );

    TCLAP::ValueArg<double> x_arg("x","x","displacement in x direction", false, 0.0,"floating point number");
    cmd.add(x_arg);
    TCLAP::ValueArg<double> y_arg("y","y","displacement in y direction", false, 0.0,"floating point number");
    cmd.add(y_arg);
    TCLAP::ValueArg<double> z_arg("z","z","displacement in z direction", false, 0.0,"floating point number");
    cmd.add(z_arg);

    TCLAP::ValueArg<std::string> mesh_out_arg("o","output-mesh","output mesh file", false, "", "string");
    cmd.add(mesh_out_arg);

    cmd.parse( argc, argv );

    std::string fname (mesh_arg.getValue());

    std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(fname));

    if (!mesh) {
        ERR("Could not read mesh from file '%s'.", fname.c_str());
        return EXIT_FAILURE;
    }

    MeshLib::Node displacement(0.0, 0.0, 0.0);
    if (fabs(x_arg.getValue()) < std::numeric_limits<double>::epsilon()
        && fabs(y_arg.getValue()) < std::numeric_limits<double>::epsilon()
        && fabs(z_arg.getValue()) < std::numeric_limits<double>::epsilon()) {
        GeoLib::AABB aabb(mesh->getNodes().begin(), mesh->getNodes().end());
        displacement[0] = -(aabb.getMaxPoint()[0] + aabb.getMinPoint()[0])/2.0;
        displacement[1] = -(aabb.getMaxPoint()[1] + aabb.getMinPoint()[1])/2.0;
        displacement[2] = -(aabb.getMaxPoint()[2] + aabb.getMinPoint()[2])/2.0;
    } else {
        displacement[0] = x_arg.getValue();
        displacement[1] = y_arg.getValue();
        displacement[2] = z_arg.getValue();
    }

    INFO("translate model (%f, %f, %f).",
         displacement[0],
         displacement[1],
         displacement[2]);
    MeshLib::moveMeshNodes(
        mesh->getNodes().begin(), mesh->getNodes().end(), displacement);

    std::string out_fname(mesh_out_arg.getValue());
    if (out_fname.empty()) {
        out_fname = BaseLib::dropFileExtension(mesh_out_arg.getValue());
        out_fname += "_displaced.vtu";
    }

    MeshLib::IO::writeMeshToFile(*mesh, out_fname);

    return EXIT_SUCCESS;
}