GammaLib 2.0.0
Loading...
Searching...
No Matches
GBilinear.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GBilinear.cpp - Bilinear interpolator class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2015 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GBilinear.cpp
23 * @brief Bilinear interpolator class interface implementation
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include "GBilinear.hpp"
32#include "GTools.hpp"
33
34/* __ Method name definitions ____________________________________________ */
35
36/* __ Macros _____________________________________________________________ */
37
38/* __ Coding definitions _________________________________________________ */
39
40/* __ Debug definitions __________________________________________________ */
41
42/* __ Constants __________________________________________________________ */
43
44
45/*==========================================================================
46 = =
47 = Constructors/destructors =
48 = =
49 ==========================================================================*/
50
51/***********************************************************************//**
52 * @brief Void constructor
53 ***************************************************************************/
55{
56 // Initialise class members for clean destruction
58
59 // Return
60 return;
61}
62
63
64/***********************************************************************//**
65 * @brief Copy constructor
66 *
67 * @param[in] interpolator Bilinear interpolator.
68 ***************************************************************************/
69GBilinear::GBilinear(const GBilinear& interpolator)
70{
71 // Initialise class members for clean destruction
73
74 // Copy members
75 copy_members(interpolator);
76
77 // Return
78 return;
79}
80
81
82/***********************************************************************//**
83 * @brief Destructor
84 ***************************************************************************/
86{
87 // Free members
89
90 // Return
91 return;
92}
93
94
95/*==========================================================================
96 = =
97 = Operators =
98 = =
99 ==========================================================================*/
100
101/***********************************************************************//**
102 * @brief Assignment operator
103 *
104 * @param[in] interpolator Bilinear interpolator.
105 * @return Bilinear interpolator.
106 ***************************************************************************/
108{
109 // Execute only if object is not identical
110 if (this != &interpolator) {
111
112 // Free members
113 free_members();
114
115 // Initialise private members
116 init_members();
117
118 // Copy members
119 copy_members(interpolator);
120
121 } // endif: object was not identical
122
123 // Return this object
124 return *this;
125}
126
127
128/***********************************************************************//**
129 * @brief Interpolator
130 *
131 * @param[in] array Bilinear interpolator.
132 * @return Interpolated value.
133 ***************************************************************************/
134double GBilinear::operator()(const double* array)
135{
136 // Perform interpolation
137 double value = m_wgt1 * array[m_inx1] +
138 m_wgt2 * array[m_inx2] +
139 m_wgt3 * array[m_inx3] +
140 m_wgt4 * array[m_inx4];
141
142 // Return interpolated value
143 return value;
144}
145
146
147/*==========================================================================
148 = =
149 = Public methods =
150 = =
151 ==========================================================================*/
152
153/***********************************************************************//**
154 * @brief Clear node array
155 ***************************************************************************/
157{
158 // Free class members
159 free_members();
160
161 // Initialise members
162 init_members();
163
164 // Return
165 return;
166}
167
168
169/***********************************************************************//**
170 * @brief Clone bilinear interolator
171 *
172 * @return Pointer to deep copy of bilinear interolator.
173 ***************************************************************************/
175{
176 return new GBilinear(*this);
177}
178
179
180/***********************************************************************//**
181 * @brief Print nodes
182 *
183 * @param[in] chatter Chattiness (defaults to NORMAL).
184 * @return String containing nodes information.
185 ***************************************************************************/
186std::string GBilinear::print(const GChatter& chatter) const
187{
188 // Initialise result string
189 std::string result;
190
191 // Continue only if chatter is not silent
192 if (chatter != SILENT) {
193
194 // Append header
195 result.append("=== GBilinear ===");
196
197 // Append indices
198 result.append("\n"+gammalib::parformat("Indices"));
199 result.append(gammalib::str(m_inx1)+" ");
200 result.append(gammalib::str(m_inx2)+" ");
201 result.append(gammalib::str(m_inx3)+" ");
202 result.append(gammalib::str(m_inx4));
203
204 // Append weights
205 result.append("\n"+gammalib::parformat("Weights"));
206 result.append(gammalib::str(m_wgt1)+" ");
207 result.append(gammalib::str(m_wgt2)+" ");
208 result.append(gammalib::str(m_wgt3)+" ");
209 result.append(gammalib::str(m_wgt4));
210
211 } // endif: chatter was not silent
212
213 // Return result
214 return result;
215}
216
217
218/*==========================================================================
219 = =
220 = Private methods =
221 = =
222 ==========================================================================*/
223
224/***********************************************************************//**
225 * @brief Initialise class members
226 ***************************************************************************/
228{
229 // Initialise members
230 m_inx1 = 0;
231 m_inx2 = 0;
232 m_inx3 = 0;
233 m_inx4 = 0;
234 m_wgt1 = 0.0;
235 m_wgt2 = 0.0;
236 m_wgt3 = 0.0;
237 m_wgt4 = 0.0;
238
239 // Return
240 return;
241}
242
243
244/***********************************************************************//**
245 * @brief Copy class members
246 *
247 * @param[in] interpolator Bilinear interpolator.
248 ***************************************************************************/
249void GBilinear::copy_members(const GBilinear& interpolator)
250{
251 // Copy members
252 m_inx1 = interpolator.m_inx1;
253 m_inx2 = interpolator.m_inx2;
254 m_inx3 = interpolator.m_inx3;
255 m_inx4 = interpolator.m_inx4;
256 m_wgt1 = interpolator.m_wgt1;
257 m_wgt2 = interpolator.m_wgt2;
258 m_wgt3 = interpolator.m_wgt3;
259 m_wgt4 = interpolator.m_wgt4;
260
261 // Return
262 return;
263}
264
265
266/***********************************************************************//**
267 * @brief Delete class members
268 ***************************************************************************/
270{
271 // Return
272 return;
273}
Bilinear interpolator class interface definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
Bilinear interpolator class.
Definition GBilinear.hpp:40
double m_wgt4
Definition GBilinear.hpp:80
void init_members(void)
Initialise class members.
GBilinear & operator=(const GBilinear &interpolator)
Assignment operator.
double m_wgt3
Definition GBilinear.hpp:79
double operator()(const double *array)
Interpolator.
double m_wgt2
Definition GBilinear.hpp:78
void copy_members(const GBilinear &interpolator)
Copy class members.
void clear(void)
Clear node array.
GBilinear * clone(void) const
Clone bilinear interolator.
std::string print(const GChatter &chatter=NORMAL) const
Print nodes.
GBilinear(void)
Void constructor.
Definition GBilinear.cpp:54
void free_members(void)
Delete class members.
double m_wgt1
Definition GBilinear.hpp:77
virtual ~GBilinear(void)
Destructor.
Definition GBilinear.cpp:85
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1143
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:489