71{
72 TCLAP::CmdLine cmd(
73 "Add values to raster.\n\n"
74 "OpenGeoSys-6 software, version " +
76 ".\n"
77 "Copyright (c) 2012-2024, OpenGeoSys Community "
78 "(http://www.opengeosys.org)",
80
81 TCLAP::ValueArg<std::string> out_raster_arg(
82 "o",
83 "output_raster",
84 "the output raster is stored to a file of this name",
85 true,
86 "",
87 "filename for raster output");
88 cmd.add(out_raster_arg);
89
90 TCLAP::ValueArg<double> scaling_arg(
91 "",
92 "scaling_value",
93 "value the function sin(x pi) sin(y pi) will be scaled with",
94 false,
95 1,
96 "double value");
97 cmd.add(scaling_arg);
98
99 TCLAP::ValueArg<double> offset_arg(
100 "",
101 "offset_value",
102 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
103 false,
104 0,
105 "double value");
106 cmd.add(offset_arg);
107
108 TCLAP::ValueArg<double> ll_x_arg(
109 "",
110 "ll_x",
111 "x coordinate of lower left point of axis aligned rectangular region",
112 false,
113 0,
114 "double value");
115 cmd.add(ll_x_arg);
116 TCLAP::ValueArg<double> ll_y_arg(
117 "",
118 "ll_y",
119 "y coordinate of lower left point of axis aligned rectangular region",
120 false,
121 0,
122 "double value");
123 cmd.add(ll_y_arg);
124 TCLAP::ValueArg<double> ur_x_arg("",
125 "ur_x",
126 "x coordinate of the upper right point of "
127 "axis aligned rectangular region",
128 false,
129 0,
130 "double value");
131 cmd.add(ur_x_arg);
132 TCLAP::ValueArg<double> ur_y_arg("",
133 "ur_y",
134 "y coordinate of the upper right point of "
135 "axis aligned rectangular region",
136 false,
137 0,
138 "double value");
139
140 cmd.add(ur_y_arg);
141 std::vector<std::string> allowed_functions_vector{"sinxsiny", "exp",
142 "step"};
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");
152 cmd.add(input_arg);
153
154 cmd.parse(argc, argv);
155
156#ifdef USE_PETSC
157 MPI_Init(&argc, &argv);
158#endif
159
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)};
164
165 auto const s = scaling_arg.getValue();
166 auto const offset = offset_arg.getValue();
167
168 std::unique_ptr<GeoLib::Raster> const raster(
170 input_arg.getValue()));
171 auto const& header = raster->getHeader();
172 auto const& origin = header.origin;
173
174 auto function_selector = [](std::string const& function_string)
177 {
178 if (function_string == "sinxsiny")
179 {
181 }
182 if (function_string == "exp")
183 {
185 }
186 if (function_string == "step")
187 {
189 }
190 OGS_FATAL(
"Function '{}' isn't implemented.", function_string);
191 };
193 computeFunctionValue = function_selector(function_arg.getValue());
194
195 for (std::size_t r = 0; r < header.n_rows; r++)
196 {
197 for (std::size_t c = 0;
c < header.n_cols;
c++)
198 {
200 origin[1] + header.cell_size * (r + 0.5),
201 0.0}};
202 if (!aabb.
containsPoint(p, std::numeric_limits<double>::epsilon()))
203 {
204 continue;
205 }
206
207 (*raster)(r,
c) += offset + s * computeFunctionValue(p, aabb);
208 }
209 }
210
212 out_raster_arg.getValue());
213#ifdef USE_PETSC
214 MPI_Finalize();
215#endif
216 return EXIT_SUCCESS;
217}
double computeSinXSinY(GeoLib::Point const &point, GeoLib::AABB const &aabb)
double compute2DGaussBellCurveValues(GeoLib::Point const &point, GeoLib::AABB const &aabb)
double computeStepFunction(GeoLib::Point const &point, GeoLib::AABB const &aabb)
static void writeRasterAsASC(GeoLib::Raster const &raster, std::string const &file_name)
Writes an Esri asc-file.
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
bool containsPoint(T const &pnt, double eps) const
GITINFOLIB_EXPORT const std::string ogs_version