67int main(
int argc,
char* argv[])
70 "Add values to raster.\n\n"
71 "OpenGeoSys-6 software, version " +
74 "Copyright (c) 2012-2024, OpenGeoSys Community "
75 "(http://www.opengeosys.org)",
78 TCLAP::ValueArg<std::string> out_raster_arg(
81 "the output raster is stored to a file of this name",
84 "filename for raster output");
85 cmd.add(out_raster_arg);
87 TCLAP::ValueArg<double> scaling_arg(
90 "value the function sin(x pi) sin(y pi) will be scaled with",
96 TCLAP::ValueArg<double> offset_arg(
99 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
105 TCLAP::ValueArg<double> ll_x_arg(
108 "x coordinate of lower left point of axis aligned rectangular region",
113 TCLAP::ValueArg<double> ll_y_arg(
116 "y coordinate of lower left point of axis aligned rectangular region",
121 TCLAP::ValueArg<double> ur_x_arg(
"",
123 "x coordinate of the upper right point of "
124 "axis aligned rectangular region",
129 TCLAP::ValueArg<double> ur_y_arg(
"",
131 "y coordinate of the upper right point of "
132 "axis aligned rectangular region",
138 std::vector<std::string> allowed_functions_vector{
"sinxsiny",
"exp",
140 TCLAP::ValuesConstraint<std::string> allowed_functions(
141 allowed_functions_vector);
142 TCLAP::ValueArg<std::string> function_arg(
143 "f",
"function",
"Name of the function used to modify the raster",
true,
144 "", &allowed_functions);
145 cmd.add(function_arg);
146 TCLAP::ValueArg<std::string> input_arg(
"i",
"input",
147 "Name of the input raster (*.asc)",
148 true,
"",
"input file name");
151 cmd.parse(argc, argv);
155 std::array input_points = {
156 GeoLib::Point{{ll_x_arg.getValue(), ll_y_arg.getValue(), 0}},
157 GeoLib::Point{{ur_x_arg.getValue(), ur_y_arg.getValue(), 0}}};
158 GeoLib::AABB const aabb{std::begin(input_points), std::end(input_points)};
160 auto const s = scaling_arg.getValue();
161 auto const offset = offset_arg.getValue();
163 std::unique_ptr<GeoLib::Raster>
const raster(
165 input_arg.getValue()));
166 auto const& header = raster->getHeader();
167 auto const& origin = header.origin;
169 auto function_selector = [](std::string
const& function_string)
173 if (function_string ==
"sinxsiny")
177 if (function_string ==
"exp")
181 if (function_string ==
"step")
185 OGS_FATAL(
"Function '{}' isn't implemented.", function_string);
188 computeFunctionValue = function_selector(function_arg.getValue());
190 for (std::size_t r = 0; r < header.n_rows; r++)
192 for (std::size_t c = 0; c < header.n_cols; c++)
194 GeoLib::Point const p{{origin[0] + header.cell_size * (c + 0.5),
195 origin[1] + header.cell_size * (r + 0.5),
197 if (!aabb.
containsPoint(p, std::numeric_limits<double>::epsilon()))
202 (*raster)(r, c) += offset + s * computeFunctionValue(p, aabb);
207 out_raster_arg.getValue());