11 #include <tclap/CmdLine.h>
23 template <
typename T1,
typename T2>
26 std::string
const& property_vector_name_in,
27 std::string
const& property_vector_name_out)
33 return std::make_pair(
false,
34 "Original property vector '" +
35 property_vector_name_in +
"' not found.");
41 return std::make_pair(
false,
42 "Could not create new property vector '" +
43 property_vector_name_in +
"' not found.");
45 new_pv->resize(orig_pv->getNumberOfTuples());
46 for (std::size_t i(0); i < new_pv->getNumberOfTuples(); ++i)
48 (*new_pv)[i] =
static_cast<T2
>((*orig_pv)[i]);
50 return std::make_pair(
true,
"");
53 int main(
int argc,
char* argv[])
56 "Converts a double or floating point cell data array of a vtk "
57 "unstructured grid into a int or double cell data array.\n\n"
58 "OpenGeoSys-6 software, version " +
61 "Copyright (c) 2012-2021, OpenGeoSys Community "
62 "(http://www.opengeosys.org)",
65 TCLAP::ValueArg<std::string> new_property_data_type_arg(
67 "new-property-data-type",
68 "the name of the data type as string (int or double)",
71 "data type as string");
72 cmd.add(new_property_data_type_arg);
74 TCLAP::ValueArg<std::string> new_property_arg(
77 "the name of the new cell data array (PropertyVector) the values are "
81 "name of the new cell data array (PropertyVector) as string");
82 cmd.add(new_property_arg);
84 TCLAP::ValueArg<std::string> out_mesh_arg(
85 "o",
"out-mesh",
"output mesh file name",
true,
"",
"file name");
86 cmd.add(out_mesh_arg);
88 TCLAP::ValueArg<std::string> property_arg(
90 "existing-property-name",
91 "the name of the existing cell data array (PropertyVector)",
94 "property name as string");
95 cmd.add(property_arg);
97 TCLAP::ValueArg<std::string> mesh_arg(
98 "i",
"in-mesh",
"input mesh file name",
true,
"",
"file name");
101 cmd.parse(argc, argv);
103 std::unique_ptr<MeshLib::Mesh> mesh(
111 bool success =
false;
112 std::string err_msg =
"Could not find cell data array '" +
113 property_arg.getValue() +
"' in the mesh '" +
114 mesh_arg.getValue() +
"'";
116 if (new_property_data_type_arg.getValue() ==
"int")
118 if (mesh->getProperties().existsPropertyVector<
double>(
121 std::tie(success, err_msg) =
122 castPropertyVectorToPropertyVector<double, int>(
123 mesh->getProperties(),
124 property_arg.getValue(),
125 new_property_arg.getValue());
128 if (mesh->getProperties().existsPropertyVector<
float>(
131 std::tie(success, err_msg) =
132 castPropertyVectorToPropertyVector<float, int>(
133 mesh->getProperties(),
134 property_arg.getValue(),
135 new_property_arg.getValue());
138 if (new_property_data_type_arg.getValue() ==
"double")
140 if (mesh->getProperties().existsPropertyVector<
float>(
143 std::tie(success, err_msg) =
144 castPropertyVectorToPropertyVector<float, double>(
145 mesh->getProperties(),
146 property_arg.getValue(),
147 new_property_arg.getValue());
153 ERR(
"{:s}", err_msg);
void ERR(char const *fmt, Args const &... args)
Definition of the Mesh class.
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
PropertyVector< T > const * getPropertyVector(std::string const &name) const
PropertyVector< T > * createNewPropertyVector(std::string const &name, MeshItemType mesh_item_type, std::size_t n_components=1)
int main(int argc, char *argv[])
std::pair< bool, std::string > castPropertyVectorToPropertyVector(MeshLib::Properties &properties, std::string const &property_vector_name_in, std::string const &property_vector_name_out)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)
Definition of readMeshFromFile function.