Skip to content
Snippets Groups Projects
Commit 19c981eb authored by Tom Fischer's avatar Tom Fischer
Browse files

Merge pull request #490 from rinkk/RemoveElementsAABB

Bounding box support for removeMeshElements tool
parents 6ac865c3 f40e200c
No related branches found
No related tags found
No related merge requests found
......@@ -12,14 +12,6 @@ INCLUDE_DIRECTORIES(
# Create executables
IF(QT4_FOUND)
ADD_EXECUTABLE( removeMeshNodes removeMeshNodes.cpp )
TARGET_LINK_LIBRARIES( removeMeshNodes
BaseLib
FileIO
MeshLib
${QT_LIBRARIES}
)
ADD_EXECUTABLE( moveMeshNodes moveMeshNodes.cpp )
TARGET_LINK_LIBRARIES( moveMeshNodes
BaseLib
......@@ -29,7 +21,7 @@ IF(QT4_FOUND)
${QT_LIBRARIES}
)
SET_TARGET_PROPERTIES(moveMeshNodes removeMeshNodes
SET_TARGET_PROPERTIES(moveMeshNodes
PROPERTIES FOLDER Utilities)
ENDIF() # QT4_FOUND
......
......@@ -39,14 +39,28 @@ int main (int argc, char* argv[])
logog_cout->SetFormatter(*custom_format);
TCLAP::CmdLine cmd("Remove mesh elements.", ' ', "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 mesh will be written to", true,
"", "file name of output mesh");
cmd.add(mesh_out);
// Bounding box params
TCLAP::ValueArg<double> zLargeArg("", "z-max", "largest allowed extent in z-dimension",
false, std::numeric_limits<double>::max(), "value");
cmd.add(zLargeArg);
TCLAP::ValueArg<double> zSmallArg("", "z-min", "largest allowed extent in z-dimension",
false, -1 * std::numeric_limits<double>::max(), "value");
cmd.add(zSmallArg);
TCLAP::ValueArg<double> yLargeArg("", "y-max", "largest allowed extent in y-dimension",
false, std::numeric_limits<double>::max(), "value");
cmd.add(yLargeArg);
TCLAP::ValueArg<double> ySmallArg("", "y-min", "largest allowed extent in y-dimension",
false, -1 * std::numeric_limits<double>::max(), "value");
cmd.add(ySmallArg);
TCLAP::ValueArg<double> xLargeArg("", "x-max", "largest allowed extent in x-dimension",
false, std::numeric_limits<double>::max(), "value");
cmd.add(xLargeArg);
TCLAP::ValueArg<double> xSmallArg("", "x-min", "smallest allowed extent in x-dimension",
false, -1 * std::numeric_limits<double>::max(), "value");
cmd.add(xSmallArg);
// Non-bounding-box params
TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", false);
cmd.add(zveArg);
TCLAP::MultiArg<std::string> eleTypeArg("t", "element-type",
......@@ -55,6 +69,17 @@ int main (int argc, char* argv[])
TCLAP::MultiArg<unsigned> matIDArg("m", "material-id",
"material id", false, "material id");
cmd.add(matIDArg);
// I/O params
TCLAP::ValueArg<std::string> mesh_out("o", "mesh-output-file",
"the name of the file the mesh will be written to", true,
"", "file name of output mesh");
cmd.add(mesh_out);
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);
cmd.parse(argc, argv);
MeshLib::Mesh const*const mesh (FileIO::readMeshFromFile(mesh_in.getValue()));
......@@ -83,6 +108,35 @@ int main (int argc, char* argv[])
}
}
if (xSmallArg.isSet() || xLargeArg.isSet() ||
ySmallArg.isSet() || yLargeArg.isSet() ||
zSmallArg.isSet() || zLargeArg.isSet())
{
bool aabb_error (false);
if (xSmallArg.getValue() >= xLargeArg.getValue())
{
ERR ("Minimum x-extent larger than maximum x-extent.");
aabb_error = true;
}
if (ySmallArg.getValue() >= yLargeArg.getValue())
{
ERR ("Minimum y-extent larger than maximum y-extent.");
aabb_error = true;
}
if (zSmallArg.getValue() >= zLargeArg.getValue())
{
ERR ("Minimum z-extent larger than maximum z-extent.");
aabb_error = true;
}
if (aabb_error)
return 1;
MeshLib::Node ll (xSmallArg.getValue(), ySmallArg.getValue(), zSmallArg.getValue());
MeshLib::Node ur (xLargeArg.getValue(), yLargeArg.getValue(), zLargeArg.getValue());
const std::size_t n_removed_elements = ex.searchByBoundingBox(ll, ur);
INFO("%d elements found.", n_removed_elements);
}
// remove the elements and create a new mesh object.
MeshLib::Mesh const*const new_mesh = ex.removeMeshElements(mesh->getName());
......
/**
* \file removeMeshNodes.cpp
* 2012/03/07 KR Initial implementation
*/
#include <QApplication>
#include "readMeshFromFile.h"
#include "Legacy/MeshIO.h"
#include "Mesh.h"
#include "Node.h"
#include "MeshEditing/removeMeshNodes.h"
int main (int argc, char* argv[])
{
QApplication app(argc, argv, false);
std::vector<std::string> keywords;
keywords.push_back("-Z_ABOVE");
keywords.push_back("-Z_BELOW");
if (argc != 4)
{
std::cout << "Removes mesh nodes and connected elements based on the given criterium." << std::endl;
std::cout << std::endl;
std::cout << "Usage: " << argv[0] << " <msh-file.msh> <keyword> <value>" << std::endl;
std::cout << "Available keywords:" << std::endl;
for (size_t i=0; i<keywords.size(); i++)
std::cout << "\t" << keywords[i] << std::endl;
return -1;
}
const std::string msh_name(argv[1]);
const std::string current_key(argv[2]);
double value(strtod(argv[3],0));
if (msh_name.substr(msh_name.length()-4, 4).compare(".msh") != 0)
{
std::cout << "Error: Parameter 1 should be a msh-file" << std::endl;
std::cout << "Usage: " << argv[0] << " <msh-file.gml> <keyword> <value>" << std::endl;
return -1;
}
bool is_keyword(false);
for (size_t i=0; i<keywords.size(); i++)
if (current_key.compare(keywords[i])==0)
{
is_keyword = true;
break;
}
if (!is_keyword)
{
std::cout << "Keyword not recognised. Available keywords:" << std::endl;
for (size_t i=0; i<keywords.size(); i++)
std::cout << keywords[i] << std::endl;
return -1;
}
MeshLib::Mesh* mesh (FileIO::readMeshFromFile(msh_name));
std::vector<size_t> del_nodes;
// Start keyword-specific selection of nodes
if ((current_key.compare("-Z_BELOW")==0) || (current_key.compare("-Z_ABOVE")==0))
{
int factor(1);
if (current_key.compare("-Z_ABOVE")==0)
{
factor=-1;
value*=-1;
}
const size_t nNodes(mesh->getNNodes());
for (size_t i=0; i<nNodes; i++)
{
const MeshLib::Node* node = mesh->getNode(i);
const double* coords(node->getCoords());
if ((factor*coords[2]) < value)
del_nodes.push_back(i);
}
}
/**** add other keywords here ****/
// remove nodes and write new file
MeshLib::removeMeshNodes(*mesh, del_nodes);
FileIO::Legacy::MeshIO meshIO;
meshIO.setMesh(mesh);
meshIO.setPrecision(9);
meshIO.writeToFile(msh_name.substr(0, msh_name.length()-4) + "_new.msh");
delete mesh;
return 1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment