73{
74 TCLAP::CmdLine cmd(
75 "Add values to raster.\n\n"
76 "OpenGeoSys-6 software, version " +
78 ".\n"
79 "Copyright (c) 2012-2024, OpenGeoSys Community "
80 "(http://www.opengeosys.org)",
82
83 TCLAP::ValueArg<std::string> out_raster_arg(
84 "o",
85 "output_raster",
86 "the output raster is stored to a file of this name",
87 true,
88 "",
89 "filename for raster output");
90 cmd.add(out_raster_arg);
91
92 TCLAP::ValueArg<double> scaling_arg(
93 "",
94 "scaling_value",
95 "value the function sin(x pi) sin(y pi) will be scaled with",
96 false,
97 1,
98 "double value");
99 cmd.add(scaling_arg);
100
101 TCLAP::ValueArg<double> offset_arg(
102 "",
103 "offset_value",
104 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
105 false,
106 0,
107 "double value");
108 cmd.add(offset_arg);
109
110 TCLAP::ValueArg<double> ll_x_arg(
111 "",
112 "ll_x",
113 "x coordinate of lower left point of axis aligned rectangular region",
114 false,
115 0,
116 "double value");
117 cmd.add(ll_x_arg);
118 TCLAP::ValueArg<double> ll_y_arg(
119 "",
120 "ll_y",
121 "y coordinate of lower left point of axis aligned rectangular region",
122 false,
123 0,
124 "double value");
125 cmd.add(ll_y_arg);
126 TCLAP::ValueArg<double> ur_x_arg("",
127 "ur_x",
128 "x coordinate of the upper right point of "
129 "axis aligned rectangular region",
130 false,
131 0,
132 "double value");
133 cmd.add(ur_x_arg);
134 TCLAP::ValueArg<double> ur_y_arg("",
135 "ur_y",
136 "y coordinate of the upper right point of "
137 "axis aligned rectangular region",
138 false,
139 0,
140 "double value");
141
142 cmd.add(ur_y_arg);
143 std::vector<std::string> allowed_functions_vector{"sinxsiny", "exp",
144 "step"};
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");
154 cmd.add(input_arg);
155
156 cmd.parse(argc, argv);
157
158#ifdef USE_PETSC
159 MPI_Init(&argc, &argv);
160#endif
161
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)};
166
167 auto const s = scaling_arg.getValue();
168 auto const offset = offset_arg.getValue();
169
170 std::unique_ptr<GeoLib::Raster> const raster(
172 input_arg.getValue()));
173 auto const& header = raster->getHeader();
174 auto const& origin = header.origin;
175
176 auto function_selector = [](std::string const& function_string)
179 {
180 if (function_string == "sinxsiny")
181 {
183 }
184 if (function_string == "exp")
185 {
187 }
188 if (function_string == "step")
189 {
191 }
192 OGS_FATAL(
"Function '{}' isn't implemented.", function_string);
193 };
195 computeFunctionValue = function_selector(function_arg.getValue());
196
197 for (std::size_t r = 0; r < header.n_rows; r++)
198 {
199 for (std::size_t c = 0;
c < header.n_cols;
c++)
200 {
202 origin[1] + header.cell_size * (r + 0.5),
203 0.0}};
204 if (!aabb.
containsPoint(p, std::numeric_limits<double>::epsilon()))
205 {
206 continue;
207 }
208
209 (*raster)(r,
c) += offset + s * computeFunctionValue(p, aabb);
210 }
211 }
212
214 out_raster_arg.getValue());
215#ifdef USE_PETSC
216 MPI_Finalize();
217#endif
218 return EXIT_SUCCESS;
219}
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