예제 #1
0
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(
	    MeshLib::IO::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";
	MeshLib::IO::writeMeshToFile(*surface_mesh, out_fname);

	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("Collapse mesh nodes and, if necessary, remove elements", ' ', "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> input_mesh_arg("m","mesh","input mesh file name",true,"","string");
	// Add the argument mesh_arg to the CmdLine object. The CmdLine object
	// uses this Arg to parse the command line.
	cmd.add( input_mesh_arg );

	TCLAP::ValueArg<std::string> output_mesh_arg("","out-mesh","mesh file name for output",false,"","string");
	cmd.add( output_mesh_arg );

	TCLAP::ValueArg<double> distance_arg("d","collapse-distance","maximal distance two nodes are collapsed",false,0.01,"for example you can set this parameter to 10^{-6} times maximal area length");
	cmd.add( distance_arg );

	cmd.parse( argc, argv );

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

	FileIO::MeshIO mesh_io;
#ifndef WIN32
	BaseLib::MemWatch mem_watch;
	unsigned long mem_without_mesh (mem_watch.getVirtMemUsage());
	BaseLib::RunTime run_time;
	run_time.start();
#endif
	MeshLib::Mesh* mesh = mesh_io.loadMeshFromFile(fname);
#ifndef WIN32
	if (mesh) {
		unsigned long mem_with_mesh (mem_watch.getVirtMemUsage());
		INFO ("mem for mesh: %i MB", (mem_with_mesh - mem_without_mesh)/(1024*1024));
	}
	run_time.stop();
	if (mesh) {
		INFO ("time for reading: %f s", run_time.elapsed());
	}
#endif

#ifndef WIN32
	unsigned long mem_without_meshgrid (mem_watch.getVirtMemUsage());
	run_time.start();
#endif
	MeshLib::MeshCoarsener mesh_coarsener(mesh);
	MeshLib::Mesh *collapsed_mesh(mesh_coarsener (distance_arg.getValue()));

#ifndef WIN32
	run_time.stop();
	unsigned long mem_with_meshgrid (mem_watch.getVirtMemUsage());
	INFO ("mem for meshgrid: %i MB", (mem_with_meshgrid - mem_without_meshgrid)/(1024*1024));
	INFO ("time for collapsing: %f s", run_time.elapsed());
#endif

	mesh_io.setMesh(collapsed_mesh);
	std::string out_fname (output_mesh_arg.getValue());
	if (out_fname.empty()) {
		out_fname = "/home/fischeth/workspace/OGS-6/Build/CollapsedMesh.msh";
	}
	INFO ("writing collapsed mesh to %s", out_fname.c_str());
	mesh_io.writeToFile(out_fname);
	INFO ("done");

	delete mesh;
	delete collapsed_mesh;
	delete custom_format;
	delete logogCout;
	LOGOG_SHUTDOWN();

	return 0;
}
예제 #3
0
파일: MoveMesh.cpp 프로젝트: LEONOB2014/ogs
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();
}
예제 #4
0
파일: MoveMesh.cpp 프로젝트: TomFischer/ogs
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;
}