OGS
addDataToRaster.cpp File Reference

Detailed Description

Definition in file addDataToRaster.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include <algorithm>
#include <boost/math/constants/constants.hpp>
#include <cmath>
#include <memory>
#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] *
49 boost::math::double_constants::pi) *
50 std::sin((point[1] - offset[1]) / aabb_size[1] *
51 boost::math::double_constants::pi);
52}

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

55{
56 auto const aabb_size = aabb.getMaxPoint() - aabb.getMinPoint();
57 auto const min = aabb.getMinPoint();
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 if ((point[0] - min[0]) / aabb_size[0] >= 0.5 &&
65 (point[1] - min[1]) / aabb_size[1] >= 0.5)
66 {
67 return 1;
68 }
69 return 0;
70}

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

Referenced by main().

◆ main()

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

Definition at line 72 of file addDataToRaster.cpp.

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