int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); logog_cout->SetFormatter(*custom_format); TCLAP::CmdLine cmd("Converts VTK mesh into OGS 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 mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); cmd.parse(argc, argv); MeshLib::Mesh* mesh (FileIO::BoostVtuInterface::readVTUFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(mesh); meshIO.writeToFile(mesh_out.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 0; }
int MshView::writeToFile() const { QModelIndex index = this->selectionModel()->currentIndex(); if (!index.isValid()) { OGSError::box("No mesh selected."); return 0; } const MeshLib::Mesh* mesh = static_cast<MshModel*>(this->model())->getMesh(index); if (mesh) { QString mshName = QString::fromStdString( static_cast<MshModel*>(this->model())->getMesh(index)->getName()); QString fileName = QFileDialog::getSaveFileName(NULL, "Save mesh as", LastSavedFileDirectory::getDir() + QString::fromStdString(mesh->getName()), "VTK Unstructured Grid (*.vtu);;GeoSys legacy mesh file (*.msh)"); if (!fileName.isEmpty()) { QFileInfo fi(fileName); if (fi.suffix().toLower() == "vtu") { FileIO::BoostVtuInterface vtkIO; vtkIO.setMesh(mesh); vtkIO.writeToFile(fileName.toStdString().c_str()); } if (fi.suffix().toLower() == "msh") { FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(mesh); meshIO.writeToFile(fileName.toStdString().c_str()); } LastSavedFileDirectory::setDir(fileName); return 1; } else OGSError::box("No file name entered."); } return 0; }
int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); logog_cout->SetFormatter(*custom_format); TCLAP::CmdLine cmd("Remove mesh elements.", ' ', "0.1"); // 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", "smallest 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", "smallest 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", "element type to be removed", false, "element type"); cmd.add(eleTypeArg); 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())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); MeshLib::ElementSearch ex(*mesh); // search elements IDs to be removed if (zveArg.isSet()) { const std::size_t n_removed_elements = ex.searchByContent(); INFO("%d zero volume elements found.", n_removed_elements); } if (eleTypeArg.isSet()) { const std::vector<std::string> eleTypeNames = eleTypeArg.getValue(); for (auto typeName : eleTypeNames) { const MeshLib::MeshElemType type = MeshLib::String2MeshElemType(typeName); if (type == MeshLib::MeshElemType::INVALID) continue; const std::size_t n_removed_elements = ex.searchByElementType(type); INFO("%d %s elements found.", n_removed_elements, typeName.c_str()); } } if (matIDArg.isSet()) { const std::vector<unsigned> vec_matID = matIDArg.getValue(); for (auto matID : vec_matID) { const std::size_t n_removed_elements = ex.searchByMaterialID(matID); INFO("%d elements with material ID %d found.", n_removed_elements, matID); } } 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; std::array<MathLib::Point3d, 2> extent({{ MathLib::Point3d(std::array<double,3>{{xSmallArg.getValue(), ySmallArg.getValue(), zSmallArg.getValue()}}), MathLib::Point3d(std::array<double,3>{{xLargeArg.getValue(), yLargeArg.getValue(), zLargeArg.getValue()}})}}); const std::size_t n_removed_elements = ex.searchByBoundingBox( GeoLib::AABB(extent.begin(), extent.end())); INFO("%d elements found.", n_removed_elements); } // remove the elements and create a new mesh object. MeshLib::Mesh const*const new_mesh = MeshLib::removeElements(*mesh, ex.getSearchedElementIDs(), mesh->getName()); // write into a file FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(new_mesh); meshIO.writeToFile(mesh_out.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 0; }
int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); logog_cout->SetFormatter(*custom_format); TCLAP::CmdLine cmd("Append line elements into a 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 mesh will be written to", true, "", "file name of output mesh"); cmd.add(mesh_out); TCLAP::ValueArg<std::string> geoFileArg("g", "geo-file", "the name of the geometry file which contains polylines", true, "", "the name of the geometry file"); cmd.add(geoFileArg); // parse arguments cmd.parse(argc, argv); // read GEO objects GeoLib::GEOObjects geo_objs; FileIO::BoostXmlGmlInterface xml(geo_objs); xml.readFile(geoFileArg.getValue()); std::vector<std::string> geo_names; geo_objs.getGeometryNames (geo_names); if (geo_names.empty ()) { std::cout << "no geometries found" << std::endl; return -1; } const GeoLib::PolylineVec* ply_vec (geo_objs.getPolylineVecObj(geo_names[0])); if (!ply_vec) { std::cout << "could not found polylines" << std::endl; return -1; } // read a mesh MeshLib::Mesh const*const mesh (FileIO::readMeshFromFile(mesh_in.getValue())); if (!mesh) { ERR("Mesh file %s not found", mesh_in.getValue().c_str()); return 1; } INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); // add line elements std::unique_ptr<MeshLib::Mesh> new_mesh = MeshGeoToolsLib::appendLinesAlongPolylines(*mesh, *ply_vec); INFO("Mesh created: %d nodes, %d elements.", new_mesh->getNNodes(), new_mesh->getNElements()); // write into a file FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(new_mesh.get()); meshIO.writeToFile(mesh_out.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 1; }
int main (int argc, char* argv[]) { LOGOG_INITIALIZE(); logog::Cout* logog_cout (new logog::Cout); BaseLib::LogogSimpleFormatter *custom_format (new BaseLib::LogogSimpleFormatter); 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); TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements", false); cmd.add(zveArg); TCLAP::MultiArg<std::string> eleTypeArg("t", "element-type", "element type to be removed", false, "element type"); cmd.add(eleTypeArg); TCLAP::MultiArg<unsigned> matIDArg("m", "material-id", "material id", false, "material id"); cmd.add(matIDArg); cmd.parse(argc, argv); MeshLib::Mesh* mesh (FileIO::readMeshFromFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNNodes(), mesh->getNElements()); // search elements IDs to be removed std::vector<std::size_t> vec_elementIDs_removed; if (zveArg.isSet()) { std::vector<std::size_t> vec_matched = searchByZeroContent(mesh->getElements()); updateUnion(vec_matched, vec_elementIDs_removed); INFO("%d zero volume elements found.", vec_matched.size()); } if (eleTypeArg.isSet()) { std::vector<std::string> eleTypeNames = eleTypeArg.getValue(); for (auto typeName : eleTypeNames) { MeshElemType type = String2MeshElemType(typeName); if (type == MeshElemType::INVALID) continue; std::vector<std::size_t> vec_matched = searchByElementType(mesh->getElements(), type); updateUnion(vec_matched, vec_elementIDs_removed); INFO("%d %s elements found.", vec_matched.size(), typeName.c_str()); } } if (matIDArg.isSet()) { std::vector<unsigned> vec_matID = matIDArg.getValue(); for (auto matID : vec_matID) { std::vector<std::size_t> vec_matched = searchByMaterialID(mesh->getElements(), matID); updateUnion(vec_matched, vec_elementIDs_removed); INFO("%d elements with material ID %d found.", vec_matched.size(), matID); } } // remove the elements INFO("Removing total %d elements...", vec_elementIDs_removed.size()); std::vector<MeshLib::Element*> tmp_eles = excludeElements(mesh->getElements(), vec_elementIDs_removed); INFO("%d elements remained.", tmp_eles.size()); std::vector<MeshLib::Node*> new_nodes; std::vector<MeshLib::Element*> new_eles; copyNodesElements(mesh->getNodes(), tmp_eles, new_nodes, new_eles); // create a new mesh object. Unsued nodes are removed while construction MeshLib::Mesh* new_mesh(new MeshLib::Mesh(mesh->getName(), new_nodes, new_eles)); // write into a file FileIO::Legacy::MeshIO meshIO; meshIO.setMesh(new_mesh); meshIO.writeToFile(mesh_out.getValue()); delete custom_format; delete logog_cout; LOGOG_SHUTDOWN(); return 0; }