23int main(
int argc,
char* argv[])
26 "Edit material IDs of mesh elements.\n\n"
27 "OpenGeoSys-6 software, version " +
30 "Copyright (c) 2012-2024, OpenGeoSys Community "
31 "(http://www.opengeosys.org)",
33 TCLAP::SwitchArg replaceArg(
"r",
"replace",
"replace material IDs",
false);
34 TCLAP::SwitchArg condenseArg(
"c",
"condense",
"condense material IDs",
36 TCLAP::SwitchArg specifyArg(
37 "s",
"specify",
"specify material IDs by element types (-e)",
false);
38 std::vector<TCLAP::Arg*> vec_xors;
39 vec_xors.push_back(&replaceArg);
40 vec_xors.push_back(&condenseArg);
41 vec_xors.push_back(&specifyArg);
43 TCLAP::ValueArg<std::string> mesh_in(
44 "i",
"mesh-input-file",
45 "the name of the file containing the input mesh",
true,
"",
48 TCLAP::ValueArg<std::string> mesh_out(
49 "o",
"mesh-output-file",
50 "the name of the file the mesh will be written to",
true,
"",
53 TCLAP::MultiArg<unsigned> matIDArg(
"m",
"current-material-id",
54 "current material id to be replaced",
57 TCLAP::ValueArg<unsigned> newIDArg(
"n",
"new-material-id",
58 "new material id",
false, 0,
"number");
61 TCLAP::ValuesConstraint<std::string> allowedVals(eleList);
62 TCLAP::ValueArg<std::string> eleTypeArg(
"e",
"element-type",
"element type",
63 false,
"", &allowedVals);
66 cmd.parse(argc, argv);
70 if (!replaceArg.isSet() && !condenseArg.isSet() && !specifyArg.isSet())
72 INFO(
"Please select editing mode: -r or -c or -s");
75 if (replaceArg.isSet() && condenseArg.isSet())
77 INFO(
"Please select only one editing mode: -r or -c or -s");
80 if (replaceArg.isSet())
82 if (!matIDArg.isSet() || !newIDArg.isSet())
85 "current and new material IDs must be provided for "
90 else if (specifyArg.isSet())
92 if (!eleTypeArg.isSet() || !newIDArg.isSet())
95 "element type and new material IDs must be provided to specify "
101 std::unique_ptr<MeshLib::Mesh> mesh(
103 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
104 mesh->getNumberOfElements());
106 if (condenseArg.isSet())
108 INFO(
"Condensing material ID...");
109 INFO(
"The MaterialIDs of the input file: [{}]",
113 INFO(
"The MaterialIDs of the output file: [{}]",
117 else if (replaceArg.isSet())
119 INFO(
"Replacing material ID...");
120 INFO(
"The MaterialIDs of the input file: [{}]",
124 const auto vecOldID = matIDArg.getValue();
125 const unsigned newID = newIDArg.getValue();
126 for (
auto oldID : vecOldID)
128 INFO(
"{:d} -> {:d}", oldID, newID);
132 INFO(
"The MaterialIDs of the output file: [{}]",
136 else if (specifyArg.isSet())
138 INFO(
"Specifying material ID...");
139 INFO(
"The MaterialIDs of the input file: [{}]",
143 const std::string eleTypeName(eleTypeArg.getValue());
146 const unsigned newID = newIDArg.getValue();
148 *mesh, eleType, newID);
149 INFO(
"updated {:d} elements", cnt);
150 INFO(
"The MaterialIDs of the output file: [{}]",