70int main(
int argc,
char* argv[])
73 "Add values to raster.\n\n"
74 "OpenGeoSys-6 software, version " +
77 "Copyright (c) 2012-2024, OpenGeoSys Community "
78 "(http://www.opengeosys.org)",
81 TCLAP::ValueArg<std::string> out_raster_arg(
84 "the output raster is stored to a file of this name",
87 "filename for raster output");
88 cmd.add(out_raster_arg);
90 TCLAP::ValueArg<double> scaling_arg(
93 "value the function sin(x pi) sin(y pi) will be scaled with",
99 TCLAP::ValueArg<double> offset_arg(
102 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
108 TCLAP::ValueArg<double> ll_x_arg(
111 "x coordinate of lower left point of axis aligned rectangular region",
116 TCLAP::ValueArg<double> ll_y_arg(
119 "y coordinate of lower left point of axis aligned rectangular region",
124 TCLAP::ValueArg<double> ur_x_arg(
"",
126 "x coordinate of the upper right point of "
127 "axis aligned rectangular region",
132 TCLAP::ValueArg<double> ur_y_arg(
"",
134 "y coordinate of the upper right point of "
135 "axis aligned rectangular region",
141 std::vector<std::string> allowed_functions_vector{
"sinxsiny",
"exp",
143 TCLAP::ValuesConstraint<std::string> allowed_functions(
144 allowed_functions_vector);
145 TCLAP::ValueArg<std::string> function_arg(
146 "f",
"function",
"Name of the function used to modify the raster",
true,
147 "", &allowed_functions);
148 cmd.add(function_arg);
149 TCLAP::ValueArg<std::string> input_arg(
"i",
"input",
150 "Name of the input raster (*.asc)",
151 true,
"",
"input file name");
154 cmd.parse(argc, argv);
157 MPI_Init(&argc, &argv);
160 std::array input_points = {
161 GeoLib::Point{{ll_x_arg.getValue(), ll_y_arg.getValue(), 0}},
162 GeoLib::Point{{ur_x_arg.getValue(), ur_y_arg.getValue(), 0}}};
163 GeoLib::AABB const aabb{std::begin(input_points), std::end(input_points)};
165 auto const s = scaling_arg.getValue();
166 auto const offset = offset_arg.getValue();
168 std::unique_ptr<GeoLib::Raster>
const raster(
170 input_arg.getValue()));
171 auto const& header = raster->getHeader();
172 auto const& origin = header.origin;
174 auto function_selector = [](std::string
const& function_string)
178 if (function_string ==
"sinxsiny")
182 if (function_string ==
"exp")
186 if (function_string ==
"step")
190 OGS_FATAL(
"Function '{}' isn't implemented.", function_string);
193 computeFunctionValue = function_selector(function_arg.getValue());
195 for (std::size_t r = 0; r < header.n_rows; r++)
197 for (std::size_t c = 0; c < header.n_cols; c++)
199 GeoLib::Point const p{{origin[0] + header.cell_size * (c + 0.5),
200 origin[1] + header.cell_size * (r + 0.5),
202 if (!aabb.
containsPoint(p, std::numeric_limits<double>::epsilon()))
207 (*raster)(r, c) += offset + s * computeFunctionValue(p, aabb);
212 out_raster_arg.getValue());