2
2
/****************************************************************************
6
* AUTHOR(S): Original author
7
* Soeren Gebbert soerengebbert at gmx de
9
* PURPOSE: Converts 3D raster maps (G3D) into the VTK-Ascii format
11
* COPYRIGHT: (C) 2005 by the GRASS Development Team
13
* This program is free software under the GNU General Public
14
* License (>=v2). Read the file COPYING that comes with GRASS
17
*****************************************************************************/
6
* AUTHOR(S): Original author
7
* Soeren Gebbert soerengebbert at gmx de
9
* PURPOSE: Converts 3D raster maps (RASTER3D) into the VTK-Ascii format
11
* COPYRIGHT: (C) 2005 by the GRASS Development Team
13
* This program is free software under the GNU General Public
14
* License (>=v2). Read the file COPYING that comes with GRASS
17
*****************************************************************************/
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"
31
31
/* ************************************************************************* */
32
/* Writes the strcutured points Header ************************************* */
32
/* Writes the structured points Header ************************************* */
33
34
/* ************************************************************************* */
34
35
void write_vtk_structured_point_header(FILE * fp, char *vtkFile,
35
G3D_Region region, int dp,
36
RASTER3D_Region region, int dp,
39
_("write_vtk_structured_point_header: Writing VTKStructuredPoint-Header"));
40
"write_vtk_structured_point_header: Writing VTKStructuredPoint-Header");
41
42
/*Simple vtk ASCII header */
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. */
48
49
if (param.point->answer)
49
fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows,
50
fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows,
52
fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols + 1, region.rows + 1,
53
fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols + 1, region.rows + 1,
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));
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);
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);
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);
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);
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);
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);
75
fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
76
dp, region.south - y_extent, dp, region.bottom);
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 */
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 */
88
88
/* ************************************************************************* */
89
89
/* Writes the strcutured grid header **************************************** */
90
91
/* ************************************************************************* */
91
92
void write_vtk_structured_grid_header(FILE * fp, char *vtkFile,
93
RASTER3D_Region region)
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,
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);
109
110
/* ************************************************************************* */
110
111
/* Writes the unstrcutured grid header ************************************* */
111
113
/* ************************************************************************* */
112
114
void write_vtk_unstructured_grid_header(FILE * fp, char *vtkFile,
115
RASTER3D_Region region)
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 */