~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/raster3d/getvalue.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <grass/raster.h>
 
2
#include "raster3d_intern.h"
 
3
 
 
4
/*---------------------------------------------------------------------------*/
 
5
 
 
6
/*!
 
7
 * \brief 
 
8
 *
 
9
 * Returns in <em>*value</em> the resampled cell-value of the cell with
 
10
 * window-coordinate <em>(x, y, z)</em>.  The value returned is of <em>type</em>.
 
11
 * This function invokes a fatal error if an error occurs.
 
12
 *
 
13
 *  \param map
 
14
 *  \param x
 
15
 *  \param y
 
16
 *  \param z
 
17
 *  \param value
 
18
 *  \param type
 
19
 *  \return void
 
20
 */
 
21
 
 
22
void Rast3d_get_value(RASTER3D_Map * map, int x, int y, int z, void *value, int type)
 
23
{
 
24
    /* get the resampled value */
 
25
    map->resampleFun(map, x, y, z, value, type);
 
26
}
 
27
 
 
28
/*---------------------------------------------------------------------------*/
 
29
 
 
30
/*!
 
31
 * \brief 
 
32
 *
 
33
 * Is equivalent to
 
34
 * <tt>Rast3d_get_value (map, x, y, z, &value, FCELL_TYPE);</tt> return value.
 
35
 *
 
36
 *  \param map
 
37
 *  \param x
 
38
 *  \param y
 
39
 *  \param z
 
40
 *  \return float
 
41
 */
 
42
 
 
43
float Rast3d_get_float(RASTER3D_Map * map, int x, int y, int z)
 
44
{
 
45
    float value;
 
46
 
 
47
    Rast3d_get_value(map, x, y, z, &value, FCELL_TYPE);
 
48
    return value;
 
49
}
 
50
 
 
51
/*---------------------------------------------------------------------------*/
 
52
 
 
53
/*!
 
54
 * \brief 
 
55
 *
 
56
 * Is equivalent
 
57
 * to <tt>Rast3d_get_value (map, x, y, z, &value, DCELL_TYPE);</tt> return value.
 
58
 *
 
59
 *  \param map
 
60
 *  \param x
 
61
 *  \param y
 
62
 *  \param z
 
63
 *  \return double
 
64
 */
 
65
 
 
66
double Rast3d_get_double(RASTER3D_Map * map, int x, int y, int z)
 
67
{
 
68
    double value;
 
69
 
 
70
    Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
 
71
    return value;
 
72
}
 
73
 
 
74
/*---------------------------------------------------------------------------*/
 
75
 
 
76
/*!
 
77
 * \brief 
 
78
 *
 
79
 * Returns in <em>value</em> the value of the <em>map</em> which corresponds to 
 
80
 * window coordinates <em>(north, east, top)</em>.  The
 
81
 * value is resampled using the resampling function specified for <em>map</em>. The
 
82
 * <em>value</em> is of <em>type</em>.
 
83
 *
 
84
 *  \param map
 
85
 *  \param north
 
86
 *  \param east
 
87
 *  \param top
 
88
 *  \param value
 
89
 *  \param type
 
90
 *  \return void
 
91
 */
 
92
 
 
93
void
 
94
Rast3d_get_window_value(RASTER3D_Map * map, double north, double east, double top,
 
95
                   void *value, int type)
 
96
{
 
97
    int col, row, depth;
 
98
 
 
99
    Rast3d_location2coord(&(map->window), north, east, top, &col, &row, &depth);
 
100
 
 
101
    /* if (row, col, depth) outside window return NULL value */
 
102
    if ((row < 0) || (row >= map->window.rows) ||
 
103
        (col < 0) || (col >= map->window.cols) ||
 
104
        (depth < 0) || (depth >= map->window.depths)) {
 
105
        Rast3d_set_null_value(value, 1, type);
 
106
        return;
 
107
    }
 
108
 
 
109
    /* Get the value from the map in map-region resolution */
 
110
        map->resampleFun(map, col, row, depth, value, type);
 
111
}
 
112
 
 
113
/*---------------------------------------------------------------------------*/
 
114
 
 
115
/*!
 
116
 * \brief 
 
117
 *
 
118
 * Returns in <em>value</em> the value of the <em>map</em> which corresponds to 
 
119
 * region coordinates <em>(north, east, top)</em>.
 
120
 *
 
121
 *  \param map
 
122
 *  \param north
 
123
 *  \param east
 
124
 *  \param top
 
125
 *  \param value
 
126
 *  \param type
 
127
 *  \return void
 
128
 */
 
129
 
 
130
void
 
131
Rast3d_get_region_value(RASTER3D_Map * map, double north, double east, double top,
 
132
                   void *value, int type)
 
133
{
 
134
    int row, col, depth;
 
135
 
 
136
    Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
 
137
 
 
138
    /* if (row, col, depth) outside region return NULL value */
 
139
    if ((row < 0) || (row >= map->region.rows) ||
 
140
        (col < 0) || (col >= map->region.cols) ||
 
141
        (depth < 0) || (depth >= map->region.depths)) {
 
142
        Rast3d_set_null_value(value, 1, type);
 
143
        return;
 
144
    }
 
145
 
 
146
    /* Get the value from the map in map-region resolution */
 
147
        Rast3d_get_value_region(map, col, row, depth, value, type);
 
148
}
 
149
 
 
150
/*---------------------------------------------------------------------------*/
 
151
 
 
152
/*!
 
153
 * \brief 
 
154
 *
 
155
 * Is equivalent to <tt>Rast3d_get_value_region (map, x, y, z, &value, FCELL_TYPE);</tt>
 
156
 * return value.
 
157
 *
 
158
 *  \param map
 
159
 *  \param x
 
160
 *  \param y
 
161
 *  \param z
 
162
 *  \return float
 
163
 */
 
164
 
 
165
float Rast3d_get_float_region(RASTER3D_Map * map, int x, int y, int z)
 
166
{
 
167
    int tileIndex, offs;
 
168
    float *tile;
 
169
    float value;
 
170
 
 
171
    if (map->typeIntern == DCELL_TYPE)
 
172
        return (float)Rast3d_get_double_region(map, x, y, z);
 
173
 
 
174
    /* In case of region coordinates out of bounds, return the Null value */
 
175
    if(x < 0 || y < 0 || z < 0 || x >= map->region.cols ||
 
176
       y >= map->region.rows || z >= map->region.depths) {
 
177
         Rast3d_set_null_value(&value, 1, FCELL_TYPE);
 
178
         return value;
 
179
    }   
 
180
 
 
181
    Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
 
182
    tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
 
183
 
 
184
    if (tile == NULL)
 
185
        Rast3d_fatal_error("Rast3d_get_float_region: error in Rast3d_get_tile_ptr." 
 
186
                           "Region coordinates x %i y %i z %i  tile index %i offset %i",
 
187
                           x, y, z, tileIndex, offs);
 
188
 
 
189
    return tile[offs];
 
190
}
 
191
 
 
192
/*---------------------------------------------------------------------------*/
 
193
 
 
194
/*!
 
195
 * \brief 
 
196
 *
 
197
 * Is equivalent to <tt>Rast3d_get_value_region (map, x, y, z, &value,
 
198
 * DCELL_TYPE);</tt> return value.
 
199
 *
 
200
 *  \param map
 
201
 *  \param x
 
202
 *  \param y
 
203
 *  \param z
 
204
 *  \return double
 
205
 */
 
206
 
 
207
double Rast3d_get_double_region(RASTER3D_Map * map, int x, int y, int z)
 
208
{
 
209
    int tileIndex, offs;
 
210
    double *tile;
 
211
    double value;
 
212
 
 
213
    if (map->typeIntern == FCELL_TYPE)
 
214
        return (double)Rast3d_get_float_region(map, x, y, z);
 
215
 
 
216
    /* In case of region coordinates out of bounds, return the Null value */
 
217
    if(x < 0 || y < 0 || z < 0 || x >= map->region.cols ||
 
218
       y >= map->region.rows || z >= map->region.depths) {
 
219
         Rast3d_set_null_value(&value, 1, DCELL_TYPE);
 
220
         return value;
 
221
    } 
 
222
 
 
223
    Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
 
224
    tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
 
225
 
 
226
    if (tile == NULL)
 
227
        Rast3d_fatal_error("Rast3d_get_double_region: error in Rast3d_get_tile_ptr." 
 
228
                           "Region coordinates x %i y %i z %i  tile index %i offset %i",
 
229
                           x, y, z, tileIndex, offs);
 
230
 
 
231
    return tile[offs];
 
232
}
 
233
 
 
234
/*---------------------------------------------------------------------------*/
 
235
 
 
236
/*!
 
237
 * \brief 
 
238
 *
 
239
 * Returns in <em>*value</em> the cell-value of the cell with
 
240
 * region-coordinate <em>(x, y, z)</em>.  The value returned is of <em>type</em>.
 
241
 * Here <em>region</em> means the coordinate in the cube of data in the file, i.e.
 
242
 * ignoring geographic coordinates.
 
243
 * In case the region coordinates are out of bounds, the Null value will be returned.
 
244
 * This function invokes a fatal error if an error occurs.
 
245
 *
 
246
 *  \param map
 
247
 *  \param x
 
248
 *  \param y
 
249
 *  \param z
 
250
 *  \param value
 
251
 *  \param type
 
252
 *  \return void
 
253
 */
 
254
 
 
255
void
 
256
Rast3d_get_value_region(RASTER3D_Map * map, int x, int y, int z, void *value, int type)
 
257
{
 
258
    if (type == FCELL_TYPE) {
 
259
        *((float *)value) = Rast3d_get_float_region(map, x, y, z);
 
260
        return;
 
261
    }
 
262
 
 
263
    *((double *)value) = Rast3d_get_double_region(map, x, y, z);
 
264
}