OGS
addDataToRaster.cpp File Reference

Detailed Description

Definition in file addDataToRaster.cpp.

#include <tclap/CmdLine.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <numbers>
#include <numeric>
#include "BaseLib/MPI.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 27 of file addDataToRaster.cpp.

29{
30 auto const sigma_x = (aabb.getMaxPoint() - aabb.getMinPoint())[0] / 3;
31 auto const sigma_y = (aabb.getMaxPoint() - aabb.getMinPoint())[1] / 3;
32
33 auto const mid_point = (aabb.getMaxPoint() + aabb.getMinPoint()) / 2;
34
35 return std::exp(
36 -0.5 * std::pow((point[0] - mid_point[0]), 2) / std::pow(sigma_x, 2) -
37 0.5 * std::pow((point[1] - mid_point[1]), 2) / std::pow(sigma_y, 2));
38}

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 40 of file addDataToRaster.cpp.

41{
42 auto const aabb_size = aabb.getMaxPoint() - aabb.getMinPoint();
43 auto const offset = aabb.getMinPoint();
44
45 return std::sin((point[0] - offset[0]) / aabb_size[0] * std::numbers::pi) *
46 std::sin((point[1] - offset[1]) / aabb_size[1] * std::numbers::pi);
47}

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 49 of file addDataToRaster.cpp.

50{
51 auto const aabb_size = aabb.getMaxPoint() - aabb.getMinPoint();
52 auto const min = aabb.getMinPoint();
53
54 if ((point[0] - min[0]) / aabb_size[0] < 0.5 &&
55 (point[1] - min[1]) / aabb_size[1] < 0.5)
56 {
57 return 1;
58 }
59 if ((point[0] - min[0]) / aabb_size[0] >= 0.5 &&
60 (point[1] - min[1]) / aabb_size[1] >= 0.5)
61 {
62 return 1;
63 }
64 return 0;
65}

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

Referenced by main().

◆ main()

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

Definition at line 67 of file addDataToRaster.cpp.

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

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