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

« back to all changes in this revision

Viewing changes to lib/raster3d/getblock.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 <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <sys/types.h>
 
4
#include <unistd.h>
 
5
 
 
6
#include <grass/raster.h>
 
7
#include "raster3d_intern.h"
 
8
 
 
9
/*---------------------------------------------------------------------------*/
 
10
 
 
11
void
 
12
Rast3d_get_block_nocache(RASTER3D_Map * map, int x0, int y0, int z0, int nx, int ny,
 
13
                    int nz, void *block, int type)
 
14
{
 
15
    void *tile;
 
16
    int tileX0, tileY0, tileZ0, tileOffsX0, tileOffsY0, tileOffsZ0;
 
17
    int tileX1, tileY1, tileZ1, tileOffsX1, tileOffsY1, tileOffsZ1;
 
18
    int tx, ty, tz, dx, dy, dz, x, y, z, rows, cols, depths;
 
19
    int tileIndex;
 
20
 
 
21
    if (!map->useCache)
 
22
        tile = Rast3d_alloc_tiles_type(map, 1, type);
 
23
    if (tile == NULL)
 
24
        Rast3d_fatal_error("Rast3d_get_block_nocache: error in Rast3d_alloc_tiles");
 
25
 
 
26
    Rast3d_coord2tile_coord(map, x0, y0, z0, &tileX0, &tileY0, &tileZ0,
 
27
                        &tileOffsX0, &tileOffsY0, &tileOffsZ0);
 
28
    Rast3d_coord2tile_coord(map, x0 + nx - 1, y0 + ny - 1, z0 + nz - 1,
 
29
                        &tileX1, &tileY1, &tileZ1,
 
30
                        &tileOffsX1, &tileOffsY1, &tileOffsZ1);
 
31
 
 
32
    for (tz = tileZ0; tz <= tileZ1; tz++) {
 
33
        dz = (tz - tileZ0) * map->tileZ - tileOffsZ0;
 
34
        for (ty = tileY0; ty <= tileY1; ty++) {
 
35
            dy = (ty - tileY0) * map->tileY - tileOffsY0;
 
36
            for (tx = tileX0; tx <= tileX1; tx++) {
 
37
                dx = (tx - tileX0) * map->tileX - tileOffsX0;
 
38
 
 
39
                tileIndex = Rast3d_tile2tile_index(map, tx, ty, tz);
 
40
 
 
41
                if (Rast3d_tile_index_in_range(map, tileIndex))
 
42
                    if (map->useCache) {
 
43
                        tile = Rast3d_get_tile_ptr(map, tileIndex);
 
44
                        if (tile == NULL)
 
45
                            Rast3d_fatal_error
 
46
                                ("Rast3d_get_block_nocache: error in Rast3d_get_tile_ptr");
 
47
                    }
 
48
                    else {
 
49
                        if (!Rast3d_read_tile
 
50
                            (map, tileIndex, tile, map->typeIntern))
 
51
                            Rast3d_fatal_error
 
52
                                ("Rast3d_get_block_nocache: error in Rast3d_read_tile");
 
53
                    }
 
54
 
 
55
                else
 
56
                    Rast3d_set_null_tile(map, tile);
 
57
 
 
58
                cols = (tx == tileX1 ? tileOffsX1 : map->tileX - 1);
 
59
                rows = (ty == tileY1 ? tileOffsY1 : map->tileY - 1);
 
60
                depths = (tz == tileZ1 ? tileOffsZ1 : map->tileZ - 1);
 
61
 
 
62
                x = (tx == tileX0 ? tileOffsX0 : 0);
 
63
 
 
64
                for (z = (tz == tileZ0 ? tileOffsZ0 : 0); z <= depths; z++)
 
65
                    for (y = (ty == tileY0 ? tileOffsY0 : 0); y <= rows; y++) {
 
66
                        Rast3d_copy_values(tile,
 
67
                                       z * map->tileXY + y * map->tileX + x,
 
68
                                       map->typeIntern,
 
69
                                       block,
 
70
                                       (z + dz) * nx * ny + (y + dy) * nx +
 
71
                                       (x + dx), type, cols - x + 1);
 
72
                    }
 
73
            }
 
74
        }
 
75
    }
 
76
 
 
77
    if (!map->useCache)
 
78
        Rast3d_free_tiles(tile);
 
79
}
 
80
 
 
81
/*---------------------------------------------------------------------------*/
 
82
 
 
83
 
 
84
/*!
 
85
 * \brief 
 
86
 *
 
87
 * Copies the cells contained in the block (cube) with vertices 
 
88
 * <em>(x0, y0, z0)</em> and <em>(x0 + nx - 1, y0 + ny - 1, z0 + nz - 1)</em>
 
89
 * into <em>block</em>. The cell-values in <em>block</em> are of <em>type</em>.
 
90
 * The source code can be found in <em>getblock.c</em>.
 
91
 *
 
92
 *  \param map
 
93
 *  \param x0
 
94
 *  \param y0
 
95
 *  \param z0
 
96
 *  \param nx
 
97
 *  \param ny
 
98
 *  \param nz
 
99
 *  \param block
 
100
 *  \param type
 
101
 *  \return void
 
102
 */
 
103
 
 
104
void
 
105
Rast3d_get_block(RASTER3D_Map * map, int x0, int y0, int z0, int nx, int ny, int nz,
 
106
             void *block, int type)
 
107
{
 
108
    int x, y, z, nNull, x1, y1, z1, length;
 
109
 
 
110
    if (!map->useCache) {
 
111
        Rast3d_get_block_nocache(map, x0, y0, z0, nx, ny, nz, block, type);
 
112
        return;
 
113
    }
 
114
 
 
115
    x1 = RASTER3D_MIN(x0 + nx, map->region.cols);
 
116
    y1 = RASTER3D_MIN(y0 + ny, map->region.rows);
 
117
    z1 = RASTER3D_MIN(z0 + nz, map->region.depths);
 
118
 
 
119
    length = Rast3d_length(type);
 
120
 
 
121
    for (z = z0; z < z1; z++) {
 
122
        for (y = y0; y < y1; y++) {
 
123
            for (x = x0; x < x1; x++) {
 
124
                Rast3d_get_value_region(map, x, y, z, block, type);
 
125
                block = G_incr_void_ptr(block, length);
 
126
            }
 
127
            nNull = x0 + nx - x;
 
128
            Rast3d_set_null_value(block, nNull, type);
 
129
            block = G_incr_void_ptr(block, length * nNull);
 
130
        }
 
131
        nNull = (y0 + ny - y) * nx;
 
132
        Rast3d_set_null_value(block, nNull, type);
 
133
        block = G_incr_void_ptr(block, length * nNull);
 
134
    }
 
135
    nNull = (z0 + nz - z) * ny * nx;
 
136
    Rast3d_set_null_value(block, nNull, type);
 
137
}