Пример #1
0
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    ApplicationsLib::LogogSetup logog_setup;

    TCLAP::CmdLine cmd(
        "Moves the points of a geometry by a given displacement vector\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<double> z_arg
        ("z", "z", "displacement in z direction", false, 0.0, "z-displacement");
    cmd.add(z_arg);
    TCLAP::ValueArg<double> y_arg
        ("y", "y", "displacement in y direction", false, 0.0, "y-displacement");
    cmd.add(y_arg);
    TCLAP::ValueArg<double> x_arg
        ("x", "x", "displacement in x direction", false, 0.0, "x-displacement");
    cmd.add(x_arg);
    TCLAP::ValueArg<std::string> geo_output_arg
        ("o","output", "output geometry file (*.gml)", true, "", "output file");
    cmd.add(geo_output_arg);
    TCLAP::ValueArg<std::string> geo_input_arg
        ("i","input", "input geometry file (*.gml)", true, "", "input file");
    cmd.add(geo_input_arg);
    cmd.parse( argc, argv );

    GeoLib::GEOObjects geo_objects;
    GeoLib::IO::XmlGmlInterface xml(geo_objects);
    try
    {
        if (!xml.readFile(geo_input_arg.getValue()))
        {
            return EXIT_FAILURE;
        }
    }
    catch (std::runtime_error const& err)
    {
        ERR("Failed to read file `%s'.", geo_input_arg.getValue().c_str());
        ERR("%s", err.what());
        return EXIT_FAILURE;
    }

    MathLib::Vector3 displacement(0.0, 0.0, 0.0);
    if (x_arg.isSet())
        displacement[0] = x_arg.getValue();
    if (y_arg.isSet())
        displacement[1] = y_arg.getValue();
    if (z_arg.isSet())
        displacement[2] = z_arg.getValue();

    std::vector<std::string> geo_names;
    geo_objects.getGeometryNames(geo_names);

    std::vector<GeoLib::Point*> const* point_vec = geo_objects.getPointVec(geo_names[0]);
    std::size_t const n_points = point_vec->size();
    for (std::size_t i=0; i<n_points; ++i)
        for (std::size_t c=0; c<3; ++c)
            (*(*point_vec)[i])[c] += displacement[c];

    xml.setNameForExport(geo_names[0]);
    xml.writeToFile(geo_output_arg.getValue());

    return EXIT_SUCCESS;
}
Пример #2
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();
}
Пример #3
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;
}