OGS
addDataToRaster.cpp File Reference

Detailed Description

Definition in file addDataToRaster.cpp.

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

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

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

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

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

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

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

Referenced by main().

◆ main()

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

Definition at line 70 of file addDataToRaster.cpp.

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)
175 -> std::function<double(GeoLib::Point const& p,
176 GeoLib::AABB const& aabb)>
177 {
178 if (function_string == "sinxsiny")
179 {
180 return computeSinXSinY;
181 }
182 if (function_string == "exp")
183 {
185 }
186 if (function_string == "step")
187 {
188 return computeStepFunction;
189 }
190 OGS_FATAL("Function '{}' isn't implemented.", function_string);
191 };
192 std::function<double(GeoLib::Point const& p, GeoLib::AABB const& aabb)>
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 {
199 GeoLib::Point const p{{origin[0] + header.cell_size * (c + 0.5),
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}
#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().