72int main(
int argc,
char* argv[])
75 "Add values to raster.\n\n"
76 "OpenGeoSys-6 software, version " +
79 "Copyright (c) 2012-2024, OpenGeoSys Community "
80 "(http://www.opengeosys.org)",
83 TCLAP::ValueArg<std::string> out_raster_arg(
86 "the output raster is stored to a file of this name",
89 "filename for raster output");
90 cmd.add(out_raster_arg);
92 TCLAP::ValueArg<double> scaling_arg(
95 "value the function sin(x pi) sin(y pi) will be scaled with",
101 TCLAP::ValueArg<double> offset_arg(
104 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
110 TCLAP::ValueArg<double> ll_x_arg(
113 "x coordinate of lower left point of axis aligned rectangular region",
118 TCLAP::ValueArg<double> ll_y_arg(
121 "y coordinate of lower left point of axis aligned rectangular region",
126 TCLAP::ValueArg<double> ur_x_arg(
"",
128 "x coordinate of the upper right point of "
129 "axis aligned rectangular region",
134 TCLAP::ValueArg<double> ur_y_arg(
"",
136 "y coordinate of the upper right point of "
137 "axis aligned rectangular region",
143 std::vector<std::string> allowed_functions_vector{
"sinxsiny",
"exp",
145 TCLAP::ValuesConstraint<std::string> allowed_functions(
146 allowed_functions_vector);
147 TCLAP::ValueArg<std::string> function_arg(
148 "f",
"function",
"Name of the function used to modify the raster",
true,
149 "", &allowed_functions);
150 cmd.add(function_arg);
151 TCLAP::ValueArg<std::string> input_arg(
"i",
"input",
152 "Name of the input raster (*.asc)",
153 true,
"",
"input file name");
156 cmd.parse(argc, argv);
159 MPI_Init(&argc, &argv);
162 std::array input_points = {
163 GeoLib::Point{{ll_x_arg.getValue(), ll_y_arg.getValue(), 0}},
164 GeoLib::Point{{ur_x_arg.getValue(), ur_y_arg.getValue(), 0}}};
165 GeoLib::AABB const aabb{std::begin(input_points), std::end(input_points)};
167 auto const s = scaling_arg.getValue();
168 auto const offset = offset_arg.getValue();
170 std::unique_ptr<GeoLib::Raster>
const raster(
172 input_arg.getValue()));
173 auto const& header = raster->getHeader();
174 auto const& origin = header.origin;
176 auto function_selector = [](std::string
const& function_string)
180 if (function_string ==
"sinxsiny")
184 if (function_string ==
"exp")
188 if (function_string ==
"step")
192 OGS_FATAL(
"Function '{}' isn't implemented.", function_string);
195 computeFunctionValue = function_selector(function_arg.getValue());
197 for (std::size_t r = 0; r < header.n_rows; r++)
199 for (std::size_t c = 0; c < header.n_cols; c++)
201 GeoLib::Point const p{{origin[0] + header.cell_size * (c + 0.5),
202 origin[1] + header.cell_size * (r + 0.5),
204 if (!aabb.
containsPoint(p, std::numeric_limits<double>::epsilon()))
209 (*raster)(r, c) += offset + s * computeFunctionValue(p, aabb);
214 out_raster_arg.getValue());