OGS
addDataToRaster.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <numbers>
#include <numeric>
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/TCLAPArguments.h"
#include "GeoLib/AABB.h"
#include "GeoLib/IO/AsciiRasterInterface.h"
#include "GeoLib/Point.h"
#include "GeoLib/Raster.h"
#include "InfoLib/GitInfo.h"
Include dependency graph for addDataToRaster.cpp:

Go to the source code of this file.

Functions

double compute2DGaussBellCurveValues (GeoLib::Point const &point, GeoLib::AABB const &aabb)
double computeSinXSinY (GeoLib::Point const &point, GeoLib::AABB const &aabb)
double computeStepFunction (GeoLib::Point const &point, GeoLib::AABB const &aabb)
int main (int argc, char *argv[])

Function Documentation

◆ compute2DGaussBellCurveValues()

double compute2DGaussBellCurveValues ( GeoLib::Point const & point,
GeoLib::AABB const & aabb )

Definition at line 21 of file addDataToRaster.cpp.

23{
24 auto const sigma_x = (aabb.getMaxPoint() - aabb.getMinPoint())[0] / 3;
25 auto const sigma_y = (aabb.getMaxPoint() - aabb.getMinPoint())[1] / 3;
26
27 auto const mid_point = (aabb.getMaxPoint() + aabb.getMinPoint()) / 2;
28
29 return std::exp(
30 -0.5 * std::pow((point[0] - mid_point[0]), 2) / std::pow(sigma_x, 2) -
31 0.5 * std::pow((point[1] - mid_point[1]), 2) / std::pow(sigma_y, 2));
32}

References GeoLib::AABB::getMaxPoint(), and GeoLib::AABB::getMinPoint().

Referenced by main().

◆ computeSinXSinY()

double computeSinXSinY ( GeoLib::Point const & point,
GeoLib::AABB const & aabb )

Definition at line 34 of file addDataToRaster.cpp.

35{
36 auto const aabb_size = aabb.getMaxPoint() - aabb.getMinPoint();
37 auto const offset = aabb.getMinPoint();
38
39 return std::sin((point[0] - offset[0]) / aabb_size[0] * std::numbers::pi) *
40 std::sin((point[1] - offset[1]) / aabb_size[1] * std::numbers::pi);
41}

References GeoLib::AABB::getMaxPoint(), and GeoLib::AABB::getMinPoint().

Referenced by main().

◆ computeStepFunction()

double computeStepFunction ( GeoLib::Point const & point,
GeoLib::AABB const & aabb )

Definition at line 43 of file addDataToRaster.cpp.

44{
45 auto const aabb_size = aabb.getMaxPoint() - aabb.getMinPoint();
46 auto const min = aabb.getMinPoint();
47
48 if ((point[0] - min[0]) / aabb_size[0] < 0.5 &&
49 (point[1] - min[1]) / aabb_size[1] < 0.5)
50 {
51 return 1;
52 }
53 if ((point[0] - min[0]) / aabb_size[0] >= 0.5 &&
54 (point[1] - min[1]) / aabb_size[1] >= 0.5)
55 {
56 return 1;
57 }
58 return 0;
59}

References GeoLib::AABB::getMaxPoint(), and GeoLib::AABB::getMinPoint().

Referenced by main().

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 61 of file addDataToRaster.cpp.

62{
63 TCLAP::CmdLine cmd(
64 "Add values to raster.\n\n"
65 "OpenGeoSys-6 software, version " +
67 ".\n"
68 "Copyright (c) 2012-2026, OpenGeoSys Community "
69 "(http://www.opengeosys.org)",
71
72 TCLAP::ValueArg<std::string> out_raster_arg(
73 "o",
74 "output_raster",
75 "Output (.asc). The output raster is stored to a file of this name",
76 true,
77 "",
78 "OUTPUT_FILE");
79 cmd.add(out_raster_arg);
80
81 TCLAP::ValueArg<double> scaling_arg(
82 "",
83 "scaling_value",
84 "value the function sin(x pi) sin(y pi) will be scaled with",
85 false,
86 1,
87 "SCALING");
88 cmd.add(scaling_arg);
89
90 TCLAP::ValueArg<double> offset_arg(
91 "",
92 "offset_value",
93 "constant added to the function 'scaling * sin(x pi) * sin(y pi)'",
94 false,
95 0,
96 "OFFSET");
97 cmd.add(offset_arg);
98
99 TCLAP::ValueArg<double> ll_x_arg(
100 "",
101 "ll_x",
102 "x coordinate of lower left point of axis aligned rectangular region",
103 false,
104 0,
105 "LL_X");
106 cmd.add(ll_x_arg);
107 TCLAP::ValueArg<double> ll_y_arg(
108 "",
109 "ll_y",
110 "y coordinate of lower left point of axis aligned rectangular region",
111 false,
112 0,
113 "LL_Y");
114 cmd.add(ll_y_arg);
115 TCLAP::ValueArg<double> ur_x_arg("",
116 "ur_x",
117 "x coordinate of the upper right point of "
118 "axis aligned rectangular region",
119 false,
120 0,
121 "UR_X");
122 cmd.add(ur_x_arg);
123 TCLAP::ValueArg<double> ur_y_arg("",
124 "ur_y",
125 "y coordinate of the upper right point of "
126 "axis aligned rectangular region",
127 false,
128 0,
129 "UR_Y");
130
131 cmd.add(ur_y_arg);
132 std::vector<std::string> allowed_functions_vector{"sinxsiny", "exp",
133 "step"};
134 TCLAP::ValuesConstraint<std::string> allowed_functions(
135 allowed_functions_vector);
136 TCLAP::ValueArg<std::string> function_arg(
137 "f", "function", "Name of the function used to modify the raster", true,
138 "", &allowed_functions);
139 cmd.add(function_arg);
140 TCLAP::ValueArg<std::string> input_arg("i", "input",
141 "Input (.asc). "
142 "Name of the input raster file",
143 true, "", "INPUT_FILE");
144 cmd.add(input_arg);
145
146 auto log_level_arg = BaseLib::makeLogLevelArg();
147 cmd.add(log_level_arg);
148 cmd.parse(argc, argv);
149
150 BaseLib::MPI::Setup mpi_setup(argc, argv);
151 BaseLib::initOGSLogger(log_level_arg.getValue());
152
153 std::array input_points = {
154 GeoLib::Point{{ll_x_arg.getValue(), ll_y_arg.getValue(), 0}},
155 GeoLib::Point{{ur_x_arg.getValue(), ur_y_arg.getValue(), 0}}};
156 GeoLib::AABB const aabb{std::begin(input_points), std::end(input_points)};
157
158 auto const s = scaling_arg.getValue();
159 auto const offset = offset_arg.getValue();
160
161 std::unique_ptr<GeoLib::Raster> const raster(
163 input_arg.getValue()));
164 auto const& header = raster->getHeader();
165 auto const& origin = header.origin;
166
167 auto function_selector = [](std::string const& function_string)
168 -> std::function<double(GeoLib::Point const& p,
169 GeoLib::AABB const& aabb)>
170 {
171 if (function_string == "sinxsiny")
172 {
173 return computeSinXSinY;
174 }
175 if (function_string == "exp")
176 {
178 }
179 if (function_string == "step")
180 {
181 return computeStepFunction;
182 }
183 OGS_FATAL("Function '{}' isn't implemented.", function_string);
184 };
185 std::function<double(GeoLib::Point const& p, GeoLib::AABB const& aabb)>
186 computeFunctionValue = function_selector(function_arg.getValue());
187
188 for (std::size_t r = 0; r < header.n_rows; r++)
189 {
190 for (std::size_t c = 0; c < header.n_cols; c++)
191 {
192 GeoLib::Point const p{{origin[0] + header.cell_size * (c + 0.5),
193 origin[1] + header.cell_size * (r + 0.5),
194 0.0}};
195 if (!aabb.containsPoint(p, std::numeric_limits<double>::epsilon()))
196 {
197 continue;
198 }
199
200 (*raster)(r, c) += offset + s * computeFunctionValue(p, aabb);
201 }
202 }
203
205 out_raster_arg.getValue());
206 return EXIT_SUCCESS;
207}
#define OGS_FATAL(...)
Definition Error.h:19
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 ...
Definition AABB.h:45
bool containsPoint(T const &pnt, double eps) const
Definition AABB.h:132
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:56
GITINFOLIB_EXPORT const std::string ogs_version

References compute2DGaussBellCurveValues(), computeSinXSinY(), computeStepFunction(), GeoLib::AABB::containsPoint(), FileIO::AsciiRasterInterface::getRasterFromASCFile(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), OGS_FATAL, GitInfoLib::GitInfo::ogs_version, and FileIO::AsciiRasterInterface::writeRasterAsASC().