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

« back to all changes in this revision

Viewing changes to raster3d/r3.out.vtk/writeVTKHead.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
1
 
2
2
/****************************************************************************
3
 
*
4
 
* MODULE:       r3.out.vtk  
5
 
*               
6
 
* AUTHOR(S):    Original author 
7
 
*               Soeren Gebbert soerengebbert at gmx de
8
 
*               27 Feb 2006 Berlin
9
 
* PURPOSE:      Converts 3D raster maps (G3D) into the VTK-Ascii format  
10
 
*
11
 
* COPYRIGHT:    (C) 2005 by the GRASS Development Team
12
 
*
13
 
*               This program is free software under the GNU General Public
14
 
*               License (>=v2). Read the file COPYING that comes with GRASS
15
 
*               for details.
16
 
*
17
 
*****************************************************************************/
 
3
 *
 
4
 * MODULE:       r3.out.vtk  
 
5
 *              
 
6
 * AUTHOR(S):    Original author 
 
7
 *               Soeren Gebbert soerengebbert at gmx de
 
8
 *              27 Feb 2006 Berlin
 
9
 * PURPOSE:      Converts 3D raster maps (RASTER3D) into the VTK-Ascii format  
 
10
 *
 
11
 * COPYRIGHT:    (C) 2005 by the GRASS Development Team
 
12
 *
 
13
 *               This program is free software under the GNU General Public
 
14
 *              License (>=v2). Read the file COPYING that comes with GRASS
 
15
 *              for details.
 
16
 *
 
17
 *****************************************************************************/
18
18
#include <stdio.h>
19
19
#include <stdlib.h>
20
20
#include <string.h>
21
21
#include <grass/gis.h>
22
 
#include <grass/G3d.h>
 
22
#include <grass/raster3d.h>
23
23
#include <grass/glocale.h>
24
24
#include "globalDefs.h"
25
25
#include "writeVTKHead.h"
29
29
 
30
30
 
31
31
/* ************************************************************************* */
32
 
/* Writes the strcutured points Header ************************************* */
 
32
/* Writes the structured points Header ************************************* */
 
33
 
33
34
/* ************************************************************************* */
34
35
void write_vtk_structured_point_header(FILE * fp, char *vtkFile,
35
 
                                       G3D_Region region, int dp,
36
 
                                       double scale)
 
36
                                       RASTER3D_Region region, int dp,
 
37
                                       double scale)
37
38
{
38
39
    G_debug(3,
39
 
            _("write_vtk_structured_point_header: Writing VTKStructuredPoint-Header"));
 
40
            "write_vtk_structured_point_header: Writing VTKStructuredPoint-Header");
40
41
 
41
42
    /*Simple vtk ASCII header */
42
43
 
43
44
    fprintf(fp, "# vtk DataFile Version 3.0\n");
44
 
    fprintf(fp, "GRASS 6 Export\n");
 
45
    fprintf(fp, "GRASS GIS 7 Export\n");
45
46
    fprintf(fp, "ASCII\n");
46
 
    fprintf(fp, "DATASET STRUCTURED_POINTS\n"); /*We are using the structured point dataset. */
 
47
    fprintf(fp, "DATASET STRUCTURED_POINTS\n"); /*We are using the structured point dataset. */
47
48
 
48
49
    if (param.point->answer)
49
 
        fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows,
50
 
                region.depths);
 
50
        fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows,
 
51
                region.depths);
51
52
    else
52
 
        fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols + 1, region.rows + 1,
53
 
                region.depths + 1);
 
53
        fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols + 1, region.rows + 1,
 
54
                region.depths + 1);
54
55
 
55
56
    fprintf(fp, "SPACING %.*f %.*f %.*f\n", dp, region.ew_res, dp,
56
 
            region.ns_res, dp, (region.tb_res * scale));
 
57
            region.ns_res, dp, (region.tb_res * scale));
57
58
 
58
59
    if (param.point->answer) {
59
 
        if (param.origin->answer)
60
 
            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp,
61
 
                    (region.west + region.ew_res / 2) - x_extent, dp,
62
 
                    (region.south + region.ns_res / 2) - y_extent, dp,
63
 
                    region.bottom * scale + (region.tb_res * scale) / 2);
64
 
        else
65
 
            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp,
66
 
                    (region.west + region.ew_res / 2) - x_extent, dp,
67
 
                    (region.south + region.ns_res / 2) - y_extent, dp,
68
 
                    region.bottom + (region.tb_res * scale) / 2);
69
 
    }
70
 
    else {
71
 
        if (param.origin->answer)
72
 
            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
73
 
                    dp, region.south - y_extent, dp, region.bottom * scale);
74
 
        else
75
 
            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
76
 
                    dp, region.south - y_extent, dp, region.bottom);
 
60
        if (param.origin->answer)
 
61
            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp,
 
62
                    (region.west + region.ew_res / 2) - x_extent, dp,
 
63
                    (region.south + region.ns_res / 2) - y_extent, dp,
 
64
                    region.bottom * scale + (region.tb_res * scale) / 2);
 
65
        else
 
66
            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp,
 
67
                    (region.west + region.ew_res / 2) - x_extent, dp,
 
68
                    (region.south + region.ns_res / 2) - y_extent, dp,
 
69
                    region.bottom + (region.tb_res * scale) / 2);
 
70
    } else {
 
71
        if (param.origin->answer)
 
72
            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
 
73
                    dp, region.south - y_extent, dp, region.bottom * scale);
 
74
        else
 
75
            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
 
76
                    dp, region.south - y_extent, dp, region.bottom);
77
77
    }
78
78
 
79
79
    if (param.point->answer)
80
 
        fprintf(fp, "POINT_DATA %i\n", region.cols * region.rows * region.depths);      /*We have pointdata */
 
80
        fprintf(fp, "POINT_DATA %i\n", region.cols * region.rows * region.depths); /*We have pointdata */
81
81
    else
82
 
        fprintf(fp, "CELL_DATA %i\n", region.cols * region.rows * region.depths);       /*We have celldata */
 
82
        fprintf(fp, "CELL_DATA %i\n", region.cols * region.rows * region.depths); /*We have celldata */
83
83
 
84
84
    return;
85
85
}
87
87
 
88
88
/* ************************************************************************* */
89
89
/* Writes the strcutured grid header **************************************** */
 
90
 
90
91
/* ************************************************************************* */
91
92
void write_vtk_structured_grid_header(FILE * fp, char *vtkFile,
92
 
                                      G3D_Region region)
 
93
                                      RASTER3D_Region region)
93
94
{
94
95
    G_debug(3,
95
 
            _("write_vtk_structured_grid_header: Writing VTKStructuredGrid-Header"));
 
96
            "write_vtk_structured_grid_header: Writing VTKStructuredGrid-Header");
96
97
    fprintf(fp, "# vtk DataFile Version 3.0\n");
97
 
    fprintf(fp, "GRASS 6 Export\n");
 
98
    fprintf(fp, "GRASS GIS 7 Export\n");
98
99
    fprintf(fp, "ASCII\n");
99
 
    fprintf(fp, "DATASET STRUCTURED_GRID\n");   /*We are using the structured grid dataset. */
 
100
    fprintf(fp, "DATASET STRUCTURED_GRID\n"); /*We are using the structured grid dataset. */
100
101
    fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows,
101
 
            region.depths);
 
102
            region.depths);
102
103
    /*Only point data is available */
103
104
    fprintf(fp, "POINTS %i float\n",
104
 
            region.cols * region.rows * region.depths);
 
105
            region.cols * region.rows * region.depths);
105
106
 
106
107
    return;
107
108
}
108
109
 
109
110
/* ************************************************************************* */
110
111
/* Writes the unstrcutured grid header ************************************* */
 
112
 
111
113
/* ************************************************************************* */
112
114
void write_vtk_unstructured_grid_header(FILE * fp, char *vtkFile,
113
 
                                        G3D_Region region)
 
115
                                        RASTER3D_Region region)
114
116
{
115
117
    G_debug(3,
116
 
            _("write_vtk_unstructured_grid_header: Writing VTKUnstructuredGrid-Header"));
 
118
            "write_vtk_unstructured_grid_header: Writing VTKUnstructuredGrid-Header");
117
119
    fprintf(fp, "# vtk DataFile Version 3.0\n");
118
 
    fprintf(fp, "GRASS 6 Export\n");
 
120
    fprintf(fp, "GRASS GIS 7 Export\n");
119
121
    fprintf(fp, "ASCII\n");
120
 
    fprintf(fp, "DATASET UNSTRUCTURED_GRID\n"); /*We are using the unstructured grid dataset. */
 
122
    fprintf(fp, "DATASET UNSTRUCTURED_GRID\n"); /*We are using the unstructured grid dataset. */
121
123
    /*Only cell data is available, because we creating a hexaeder/vtk-voxel for every voxel */
122
 
    fprintf(fp, "POINTS %i float\n", region.cols * region.rows * region.depths * 8);    /*a Voxel has 8 points */
 
124
    fprintf(fp, "POINTS %i float\n", region.cols * region.rows * region.depths * 8); /*a Voxel has 8 points */
123
125
 
124
126
    return;
125
127
}