void SaveMeshDialog::accept() { QString const& file_name (this->fileNameEdit->text()); if (file_name.isEmpty()) { OGSError::box("No file name entered."); return; } QFileInfo fi(file_name); if (fi.suffix().toLower() == "vtu") { int dataMode = this->dataModeBox->currentIndex(); bool compress (this->compressionCheckBox->isChecked()); MeshLib::IO::VtuInterface vtkIO(&_mesh, dataMode, compress); vtkIO.writeToFile(file_name.toStdString().c_str()); } if (fi.suffix().toLower() == "msh") { MeshLib::IO::Legacy::MeshIO meshIO; meshIO.setMesh(&_mesh); meshIO.writeToFile(file_name.toStdString().c_str()); } LastSavedFileDirectory::setDir(file_name); this->done(QDialog::Accepted); }
void writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name) { if (BaseLib::hasFileExtension("msh", file_name)) { MeshLib::IO::Legacy::MeshIO meshIO; meshIO.setMesh(&mesh); meshIO.writeToFile(file_name); } else if (BaseLib::hasFileExtension("vtu", file_name)) { MeshLib::IO::VtuInterface writer(&mesh); writer.writeToFile(file_name); } else { ERR("writeMeshToFile(): Unknown mesh file format in file %s.", file_name.c_str()); } }
int main (int argc, char* argv[]) { ApplicationsLib::LogogSetup logog_setup; 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 (MeshLib::IO::VtuInterface::readVTUFile(mesh_in.getValue())); INFO("Mesh read: %d nodes, %d elements.", mesh->getNumberOfNodes(), mesh->getNumberOfElements()); MeshLib::IO::Legacy::MeshIO meshIO; meshIO.setMesh(mesh); meshIO.writeToFile(mesh_out.getValue()); return EXIT_SUCCESS; }