Переглянути джерело

Modified r3.out.vtk to use the correct g3d cube coordinate system. Added
a test script and reference data.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@46720 15284696-431f-4ddb-bdfa-cd5b030d7da7

Soeren Gebbert 14 роки тому
батько
коміт
3a9cc69975

+ 338 - 339
raster3d/r3.out.vtk/main.c

@@ -1,20 +1,20 @@
 
 /****************************************************************************
-*
-* MODULE:       r3.out.vtk  
-*   	    	
-* AUTHOR(S):    Original author 
-*               Soeren Gebbert soerengebbert at gmx de
-* 		27 Feb 2006 Berlin
-* PURPOSE:      Converts 3D raster maps (G3D) into the VTK-Ascii format  
-*
-* COPYRIGHT:    (C) 2005 by the GRASS Development Team
-*
-*               This program is free software under the GNU General Public
-*   	    	License (>=v2). Read the file COPYING that comes with GRASS
-*   	    	for details.
-*
-*****************************************************************************/
+ *
+ * MODULE:       r3.out.vtk  
+ *   	    	
+ * AUTHOR(S):    Original author 
+ *               Soeren Gebbert soerengebbert at gmx de
+ * 		27 Feb 2006 Berlin
+ * PURPOSE:      Converts 3D raster maps (G3D) into the VTK-Ascii format  
+ *
+ * COPYRIGHT:    (C) 2005 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *   	    	License (>=v2). Read the file COPYING that comes with GRASS
+ *   	    	for details.
+ *
+ *****************************************************************************/
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -31,7 +31,7 @@
 #include "writeVTKHead.h"
 #include "errorHandling.h"
 
-paramType param;		/*Parameters */
+paramType param; /*Parameters */
 
 double x_extent;
 double y_extent;
@@ -40,11 +40,11 @@ double y_extent;
 
 /*Open the rgb voxel maps and write the data to the output */
 static void open_write_rgb_maps(input_maps * in, G3D_Region region, FILE * fp,
-				int dp);
+                                int dp);
 
 /*Open the rgb voxel maps and write the data to the output */
 static void open_write_vector_maps(input_maps * in, G3D_Region region,
-				   FILE * fp, int dp);
+                                   FILE * fp, int dp);
 
 /*opens a raster input map */
 static int open_input_map(const char *name, const char *mapset);
@@ -59,12 +59,13 @@ static input_maps *create_input_maps_struct(void);
 
 /* ************************************************************************* */
 /* Open the raster input map *********************************************** */
+
 /* ************************************************************************* */
 input_maps *create_input_maps_struct(void)
 {
     input_maps *in;
 
-    in = (input_maps *) calloc(1, sizeof(input_maps));
+    in = (input_maps *) calloc(1, sizeof (input_maps));
 
     in->map = NULL;
     in->map_r = NULL;
@@ -89,6 +90,7 @@ input_maps *create_input_maps_struct(void)
 
 /* ************************************************************************* */
 /* Open the raster input map *********************************************** */
+
 /* ************************************************************************* */
 int open_input_map(const char *name, const char *mapset)
 {
@@ -101,6 +103,7 @@ int open_input_map(const char *name, const char *mapset)
 
 /* ************************************************************************* */
 /* Check the input maps **************************************************** */
+
 /* ************************************************************************* */
 void check_input_maps(void)
 {
@@ -110,68 +113,66 @@ void check_input_maps(void)
     /*Check top and bottom if surface is requested */
     if (param.structgrid->answer) {
 
-	if (!param.top->answer || !param.bottom->answer)
-	    G3d_fatalError(_("You have to specify top and bottom map"));
-
-	mapset = NULL;
-	name = NULL;
-	name = param.top->answer;
-	mapset = G_find_raster2(name, "");
-	if (mapset == NULL) {
-	    G3d_fatalError(_("Top cell map <%s> not found"),
-			   param.top->answer);
-	}
-
-	mapset = NULL;
-	name = NULL;
-	name = param.bottom->answer;
-	mapset = G_find_raster2(name, "");
-	if (mapset == NULL) {
-	    G3d_fatalError(_("Bottom cell map <%s> not found"),
-			   param.bottom->answer);
-	}
+        if (!param.top->answer || !param.bottom->answer)
+            G3d_fatalError(_("You have to specify top and bottom map"));
+
+        mapset = NULL;
+        name = NULL;
+        name = param.top->answer;
+        mapset = G_find_raster2(name, "");
+        if (mapset == NULL) {
+            G3d_fatalError(_("Top cell map <%s> not found"),
+                           param.top->answer);
+        }
+
+        mapset = NULL;
+        name = NULL;
+        name = param.bottom->answer;
+        mapset = G_find_raster2(name, "");
+        if (mapset == NULL) {
+            G3d_fatalError(_("Bottom cell map <%s> not found"),
+                           param.bottom->answer);
+        }
     }
 
     /*If input maps are provided, check them */
     if (param.input->answers != NULL) {
-	for (i = 0; param.input->answers[i] != NULL; i++) {
-	    if (NULL == G_find_grid3(param.input->answers[i], ""))
-		G3d_fatalError(_("Requested 3d raster map <%s> not found"),
-			       param.input->answers[i]);
-	}
+        for (i = 0; param.input->answers[i] != NULL; i++) {
+            if (NULL == G_find_grid3(param.input->answers[i], ""))
+                G3d_fatalError(_("Requested 3d raster map <%s> not found"),
+                               param.input->answers[i]);
+        }
     }
 
     /*Check for rgb maps. */
     if (param.rgbmaps->answers != NULL) {
-	for (i = 0; i < 3; i++) {
-	    if (param.rgbmaps->answers[i] != NULL) {
-		if (NULL == G_find_grid3(param.rgbmaps->answers[i], ""))
-		    G3d_fatalError(_("Requested g3d RGB map <%s> not found"),
-				   param.rgbmaps->answers[i]);
-	    }
-	    else {
-		G3d_fatalError(_("Please provide three g3d RGB maps"));
-	    }
-	}
+        for (i = 0; i < 3; i++) {
+            if (param.rgbmaps->answers[i] != NULL) {
+                if (NULL == G_find_grid3(param.rgbmaps->answers[i], ""))
+                    G3d_fatalError(_("Requested g3d RGB map <%s> not found"),
+                                   param.rgbmaps->answers[i]);
+            } else {
+                G3d_fatalError(_("Please provide three g3d RGB maps"));
+            }
+        }
     }
 
     /*Check for vector maps. */
     if (param.vectormaps->answers != NULL) {
-	for (i = 0; i < 3; i++) {
-	    if (param.vectormaps->answers[i] != NULL) {
-		if (NULL == G_find_grid3(param.vectormaps->answers[i], ""))
-		    G3d_fatalError(_("Requested g3d vector map <%s> not found"),
-				   param.vectormaps->answers[i]);
-	    }
-	    else {
-		G3d_fatalError(_("Please provide three g3d vector maps [x,y,z]"));
-	    }
-	}
+        for (i = 0; i < 3; i++) {
+            if (param.vectormaps->answers[i] != NULL) {
+                if (NULL == G_find_grid3(param.vectormaps->answers[i], ""))
+                    G3d_fatalError(_("Requested g3d vector map <%s> not found"),
+                                   param.vectormaps->answers[i]);
+            } else {
+                G3d_fatalError(_("Please provide three g3d vector maps [x,y,z]"));
+            }
+        }
     }
 
     if (param.input->answers == NULL && param.rgbmaps->answers == NULL &&
-	param.vectormaps->answers == NULL) {
-	G_warning(_("No g3d data, RGB or xyz-vector maps are provided! Will only write the geometry."));
+        param.vectormaps->answers == NULL) {
+        G_warning(_("No g3d data, RGB or xyz-vector maps are provided! Will only write the geometry."));
     }
 
     return;
@@ -180,168 +181,170 @@ void check_input_maps(void)
 
 /* ************************************************************************* */
 /* Prepare the VTK RGB voxel data for writing ****************************** */
+
 /* ************************************************************************* */
 void open_write_rgb_maps(input_maps * in, G3D_Region region, FILE * fp,
-			 int dp)
+                         int dp)
 {
-    int i, changemask[3] = { 0, 0, 0 };
+    int i, changemask[3] = {0, 0, 0};
     void *maprgb = NULL;
 
     if (param.rgbmaps->answers != NULL) {
 
-	/*Loop over all input maps! */
-	for (i = 0; i < 3; i++) {
-	    G_debug(3, _("Open rgb 3d raster map %s"),
-		    param.rgbmaps->answers[i]);
-
-	    maprgb = NULL;
-	    /*Open the map */
-	    maprgb =
-		G3d_openCellOld(param.rgbmaps->answers[i],
-				G_find_grid3(param.rgbmaps->answers[i], ""),
-				&region, G3D_TILE_SAME_AS_FILE,
-				G3D_USE_CACHE_DEFAULT);
-	    if (maprgb == NULL) {
-		G_warning(_("Error opening 3d raster map <%s>"),
-			  param.rgbmaps->answers[i]);
-		fatal_error(_("No RGB Data will be created."), in);
-	    }
-
-	    /*if requested set the Mask on */
-	    if (param.mask->answer) {
-		if (G3d_maskFileExists()) {
-		    changemask[i] = 0;
-		    if (G3d_maskIsOff(maprgb)) {
-			G3d_maskOn(maprgb);
-			changemask[i] = 1;
-		    }
-		}
-	    }
-
-	    if (i == 0)
-		in->map_r = maprgb;
-	    if (i == 1)
-		in->map_g = maprgb;
-	    if (i == 2)
-		in->map_b = maprgb;
-	}
-
-
-	G_debug(3, "Writing VTK VoxelData");
-	write_vtk_rgb_data(in->map_r, in->map_g, in->map_b, fp, "RGB_Voxel",
-			   region, dp);
-
-	for (i = 0; i < 3; i++) {
-	    if (i == 0)
-		maprgb = in->map_r;
-	    if (i == 1)
-		maprgb = in->map_g;
-	    if (i == 2)
-		maprgb = in->map_b;
-
-	    /*We set the Mask off, if it was off before */
-	    if (param.mask->answer) {
-		if (G3d_maskFileExists())
-		    if (G3d_maskIsOn(maprgb) && changemask[i])
-			G3d_maskOff(maprgb);
-	    }
-	    /* Close the 3d raster map */
-	    if (!G3d_closeCell(maprgb)) {
-		fatal_error(_("Error closing g3d rgb map."), in);
-	    }
-
-	    /*Set the pointer to null so we noe later that these files are already closed */
-	    if (i == 0)
-		in->map_r = NULL;
-	    if (i == 1)
-		in->map_g = NULL;
-	    if (i == 2)
-		in->map_b = NULL;
-	}
+        /*Loop over all input maps! */
+        for (i = 0; i < 3; i++) {
+            G_debug(3, _("Open rgb 3d raster map %s"),
+                    param.rgbmaps->answers[i]);
+
+            maprgb = NULL;
+            /*Open the map */
+            maprgb =
+                G3d_openCellOld(param.rgbmaps->answers[i],
+                                G_find_grid3(param.rgbmaps->answers[i], ""),
+                                &region, G3D_TILE_SAME_AS_FILE,
+                                G3D_USE_CACHE_DEFAULT);
+            if (maprgb == NULL) {
+                G_warning(_("Error opening 3d raster map <%s>"),
+                          param.rgbmaps->answers[i]);
+                fatal_error(_("No RGB Data will be created."), in);
+            }
+
+            /*if requested set the Mask on */
+            if (param.mask->answer) {
+                if (G3d_maskFileExists()) {
+                    changemask[i] = 0;
+                    if (G3d_maskIsOff(maprgb)) {
+                        G3d_maskOn(maprgb);
+                        changemask[i] = 1;
+                    }
+                }
+            }
+
+            if (i == 0)
+                in->map_r = maprgb;
+            if (i == 1)
+                in->map_g = maprgb;
+            if (i == 2)
+                in->map_b = maprgb;
+        }
+
+
+        G_debug(3, "Writing VTK VoxelData");
+        write_vtk_rgb_data(in->map_r, in->map_g, in->map_b, fp, "RGB_Voxel",
+                           region, dp);
+
+        for (i = 0; i < 3; i++) {
+            if (i == 0)
+                maprgb = in->map_r;
+            if (i == 1)
+                maprgb = in->map_g;
+            if (i == 2)
+                maprgb = in->map_b;
+
+            /*We set the Mask off, if it was off before */
+            if (param.mask->answer) {
+                if (G3d_maskFileExists())
+                    if (G3d_maskIsOn(maprgb) && changemask[i])
+                        G3d_maskOff(maprgb);
+            }
+            /* Close the 3d raster map */
+            if (!G3d_closeCell(maprgb)) {
+                fatal_error(_("Error closing g3d rgb map."), in);
+            }
+
+            /*Set the pointer to null so we noe later that these files are already closed */
+            if (i == 0)
+                in->map_r = NULL;
+            if (i == 1)
+                in->map_g = NULL;
+            if (i == 2)
+                in->map_b = NULL;
+        }
     }
     return;
 }
 
 /* ************************************************************************* */
 /* Prepare the VTK vector data for writing ********************************* */
+
 /* ************************************************************************* */
 void open_write_vector_maps(input_maps * in, G3D_Region region, FILE * fp,
-			    int dp)
+                            int dp)
 {
-    int i, changemask[3] = { 0, 0, 0 };
+    int i, changemask[3] = {0, 0, 0};
     void *mapvect = NULL;
 
     if (param.vectormaps->answers != NULL) {
 
-	/*Loop over all input maps! */
-	for (i = 0; i < 3; i++) {
-	    G_debug(3, "Open vector 3d raster map %s",
-		    param.vectormaps->answers[i]);
-
-	    mapvect = NULL;
-	    /*Open the map */
-	    mapvect =
-		G3d_openCellOld(param.vectormaps->answers[i],
-				G_find_grid3(param.vectormaps->answers[i],
-					     ""), &region,
-				G3D_TILE_SAME_AS_FILE, G3D_USE_CACHE_DEFAULT);
-	    if (mapvect == NULL) {
-		G_warning(_("Error opening 3d raster map <%s>"),
-			  param.vectormaps->answers[i]);
-		fatal_error(_("No vector data will be created."), in);
-	    }
-
-	    /*if requested set the Mask on */
-	    if (param.mask->answer) {
-		if (G3d_maskFileExists()) {
-		    changemask[i] = 0;
-		    if (G3d_maskIsOff(mapvect)) {
-			G3d_maskOn(mapvect);
-			changemask[i] = 1;
-		    }
-		}
-	    }
-
-	    if (i == 0)
-		in->map_x = mapvect;
-	    if (i == 1)
-		in->map_y = mapvect;
-	    if (i == 2)
-		in->map_z = mapvect;
-	}
-
-
-	G_debug(3, "Writing VTK Vector Data");
-	write_vtk_vector_data(in->map_x, in->map_y, in->map_z, fp,
-			      "Vector_Data", region, dp);
-
-	for (i = 0; i < 3; i++) {
-	    if (i == 0)
-		mapvect = in->map_x;
-	    if (i == 1)
-		mapvect = in->map_y;
-	    if (i == 2)
-		mapvect = in->map_z;
-
-	    /*We set the Mask off, if it was off before */
-	    if (param.mask->answer) {
-		if (G3d_maskFileExists())
-		    if (G3d_maskIsOn(mapvect) && changemask[i])
-			G3d_maskOff(mapvect);
-	    }
-
-	    /* Close the 3d raster map */
-	    if (!G3d_closeCell(mapvect)) {
-		fatal_error(_("Error closing g3d vector map."), in);
-	    }
-	    /*Set the pointer to null so we noe later that these files are already closed */
-	    if (i == 0)
-		in->map_x = NULL;
-	    if (i == 1)
-		in->map_y = NULL;
-	    if (i == 2)
-		in->map_z = NULL;
-	}
+        /*Loop over all input maps! */
+        for (i = 0; i < 3; i++) {
+            G_debug(3, "Open vector 3d raster map %s",
+                    param.vectormaps->answers[i]);
+
+            mapvect = NULL;
+            /*Open the map */
+            mapvect =
+                G3d_openCellOld(param.vectormaps->answers[i],
+                                G_find_grid3(param.vectormaps->answers[i],
+                                             ""), &region,
+                                G3D_TILE_SAME_AS_FILE, G3D_USE_CACHE_DEFAULT);
+            if (mapvect == NULL) {
+                G_warning(_("Error opening 3d raster map <%s>"),
+                          param.vectormaps->answers[i]);
+                fatal_error(_("No vector data will be created."), in);
+            }
+
+            /*if requested set the Mask on */
+            if (param.mask->answer) {
+                if (G3d_maskFileExists()) {
+                    changemask[i] = 0;
+                    if (G3d_maskIsOff(mapvect)) {
+                        G3d_maskOn(mapvect);
+                        changemask[i] = 1;
+                    }
+                }
+            }
+
+            if (i == 0)
+                in->map_x = mapvect;
+            if (i == 1)
+                in->map_y = mapvect;
+            if (i == 2)
+                in->map_z = mapvect;
+        }
+
+
+        G_debug(3, "Writing VTK Vector Data");
+        write_vtk_vector_data(in->map_x, in->map_y, in->map_z, fp,
+                              "Vector_Data", region, dp);
+
+        for (i = 0; i < 3; i++) {
+            if (i == 0)
+                mapvect = in->map_x;
+            if (i == 1)
+                mapvect = in->map_y;
+            if (i == 2)
+                mapvect = in->map_z;
+
+            /*We set the Mask off, if it was off before */
+            if (param.mask->answer) {
+                if (G3d_maskFileExists())
+                    if (G3d_maskIsOn(mapvect) && changemask[i])
+                        G3d_maskOff(mapvect);
+            }
+
+            /* Close the 3d raster map */
+            if (!G3d_closeCell(mapvect)) {
+                fatal_error(_("Error closing g3d vector map."), in);
+            }
+            /*Set the pointer to null so we noe later that these files are already closed */
+            if (i == 0)
+                in->map_x = NULL;
+            if (i == 1)
+                in->map_y = NULL;
+            if (i == 2)
+                in->map_z = NULL;
+        }
     }
     return;
 }
@@ -349,6 +352,7 @@ void open_write_vector_maps(input_maps * in, G3D_Region region, FILE * fp,
 
 /* ************************************************************************* */
 /* Main function, opens most of the input and output files ***************** */
+
 /* ************************************************************************* */
 int main(int argc, char *argv[])
 {
@@ -373,23 +377,22 @@ int main(int argc, char *argv[])
     G_add_keyword(_("voxel"));
     G_add_keyword(_("export"));
     module->description =
-	_("Converts 3D raster maps into the VTK-ASCII format.");
+        _("Converts 3D raster maps into the VTK-ASCII format.");
 
     /* Get parameters from user */
     set_params();
 
     /* Have GRASS get inputs */
     if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
+        exit(EXIT_FAILURE);
     /*The precision of the output */
     if (param.decimals->answer) {
-	if (sscanf(param.decimals->answer, "%d", &dp) != 1)
-	    G_fatal_error(_("failed to interpret dp as an integer"));
-	if (dp > 20 || dp < 0)
-	    G_fatal_error(_("dp has to be from 0 to 20"));
-    }
-    else {
-	dp = 8;			/*This value is taken from the lib settings in G_format_easting */
+        if (sscanf(param.decimals->answer, "%d", &dp) != 1)
+            G_fatal_error(_("failed to interpret dp as an integer"));
+        if (dp > 20 || dp < 0)
+            G_fatal_error(_("dp has to be from 0 to 20"));
+    } else {
+        dp = 8; /*This value is taken from the lib settings in G_format_easting */
     }
 
     /*Check the input */
@@ -397,29 +400,27 @@ int main(int argc, char *argv[])
 
     /*Correct the coordinates, so the precision of VTK is not hurt :( */
     if (param.coorcorr->answer) {
-	/*Get the default region for coordiante correction */
-	G_get_default_window(&default_region);
-
-	/*Use the center of the current region as extent */
-	y_extent = (default_region.north + default_region.south) / 2;
-	x_extent = (default_region.west + default_region.east) / 2;
-    }
-    else {
-	x_extent = 0;
-	y_extent = 0;
+        /*Get the default region for coordiante correction */
+        G_get_default_window(&default_region);
+
+        /*Use the center of the current region as extent */
+        y_extent = (default_region.north + default_region.south) / 2;
+        x_extent = (default_region.west + default_region.east) / 2;
+    } else {
+        x_extent = 0;
+        y_extent = 0;
     }
 
     /*open the output */
     if (param.output->answer) {
-	fp = fopen(param.output->answer, "w");
-	if (fp == NULL) {
-	    perror(param.output->answer);
-	    G_usage();
-	    exit(EXIT_FAILURE);
-	}
-    }
-    else
-	fp = stdout;
+        fp = fopen(param.output->answer, "w");
+        if (fp == NULL) {
+            perror(param.output->answer);
+            G_usage();
+            exit(EXIT_FAILURE);
+        }
+    } else
+        fp = stdout;
 
     /* Figure out the region from the map */
     G3d_initDefaults();
@@ -433,117 +434,115 @@ int main(int argc, char *argv[])
     sscanf(param.elevscale->answer, "%lf", &scale);
     /*if LL projection, convert the elevation values to degrees */
     if (region.proj == PROJECTION_LL) {
-	llscale = M_PI / (180) * 6378137;
-	scale /= llscale;
+        llscale = M_PI / (180) * 6378137;
+        scale /= llscale;
     }
 
     /*Open the top and bottom file */
     if (param.structgrid->answer) {
 
-	/*Check if the g3d-region is equal to the 2d rows and cols */
-	rows = Rast_window_rows();
-	cols = Rast_window_cols();
-
-	/*If not equal, set the 2D windows correct */
-	if (rows != region.rows || cols != region.cols) {
-	    G_message(_("The 2d and 3d region settings are different. The g3d settings are used to adjust the 2d region."));
-	    G_get_set_window(&window2d);
-	    window2d.ns_res = region.ns_res;
-	    window2d.ew_res = region.ew_res;
-	    window2d.rows = region.rows;
-	    window2d.cols = region.cols;
-	    Rast_set_window(&window2d);
-	}
-
-	/*open top */
-	mapset = NULL;
-	name = NULL;
-	name = param.top->answer;
-	mapset = G_find_raster2(name, "");
-	in->top = open_input_map(name, mapset);
-	in->topMapType = Rast_get_map_type(in->top);
-
-	/*open bottom */
-	mapset = NULL;
-	name = NULL;
-	name = param.bottom->answer;
-	mapset = G_find_raster2(name, "");
-	in->bottom = open_input_map(name, mapset);
-	in->bottomMapType = Rast_get_map_type(in->bottom);
-
-	/* Write the vtk-header and the points */
-	if (param.point->answer) {
-	    write_vtk_structured_grid_header(fp, output, region);
-	    write_vtk_points(in, fp, region, dp, 1, scale);
-	}
-	else {
-	    write_vtk_unstructured_grid_header(fp, output, region);
-	    write_vtk_points(in, fp, region, dp, 0, scale);
-	    write_vtk_unstructured_grid_cells(fp, region);
-	}
-
-	Rast_close(in->top);
-
-	in->top = -1;
-
-	Rast_close(in->bottom);
-
-	in->bottom = -1;
-    }
-    else {
-	/* Write the structured point vtk-header */
-	write_vtk_structured_point_header(fp, output, region, dp, scale);
+        /*Check if the g3d-region is equal to the 2d rows and cols */
+        rows = Rast_window_rows();
+        cols = Rast_window_cols();
+
+        /*If not equal, set the 2D windows correct */
+        if (rows != region.rows || cols != region.cols) {
+            G_message(_("The 2d and 3d region settings are different. The g3d settings are used to adjust the 2d region."));
+            G_get_set_window(&window2d);
+            window2d.ns_res = region.ns_res;
+            window2d.ew_res = region.ew_res;
+            window2d.rows = region.rows;
+            window2d.cols = region.cols;
+            Rast_set_window(&window2d);
+        }
+
+        /*open top */
+        mapset = NULL;
+        name = NULL;
+        name = param.top->answer;
+        mapset = G_find_raster2(name, "");
+        in->top = open_input_map(name, mapset);
+        in->topMapType = Rast_get_map_type(in->top);
+
+        /*open bottom */
+        mapset = NULL;
+        name = NULL;
+        name = param.bottom->answer;
+        mapset = G_find_raster2(name, "");
+        in->bottom = open_input_map(name, mapset);
+        in->bottomMapType = Rast_get_map_type(in->bottom);
+
+        /* Write the vtk-header and the points */
+        if (param.point->answer) {
+            write_vtk_structured_grid_header(fp, output, region);
+            write_vtk_points(in, fp, region, dp, 1, scale);
+        } else {
+            write_vtk_unstructured_grid_header(fp, output, region);
+            write_vtk_points(in, fp, region, dp, 0, scale);
+            write_vtk_unstructured_grid_cells(fp, region);
+        }
+
+        Rast_close(in->top);
+
+        in->top = -1;
+
+        Rast_close(in->bottom);
+
+        in->bottom = -1;
+    } else {
+        /* Write the structured point vtk-header */
+        write_vtk_structured_point_header(fp, output, region, dp, scale);
     }
 
     /*Write the normal VTK data (cell or point data) */
     /*Loop over all 3d input maps! */
     if (param.input->answers != NULL) {
-	for (i = 0; param.input->answers[i] != NULL; i++) {
-
-	    G_debug(3, "Open 3d raster map %s", param.input->answers[i]);
-
-	    /*Open the map */
-	    in->map =
-		G3d_openCellOld(param.input->answers[i],
-				G_find_grid3(param.input->answers[i], ""),
-				&region, G3D_TILE_SAME_AS_FILE,
-				G3D_USE_CACHE_DEFAULT);
-	    if (in->map == NULL) {
-		G_warning(_("Error opening 3d raster map <%s>"),
-			  param.input->answers[i]);
-		fatal_error(" ", in);
-	    }
-
-	    /*if requested set the Mask on */
-	    if (param.mask->answer) {
-		if (G3d_maskFileExists()) {
-		    changemask = 0;
-		    if (G3d_maskIsOff(in->map)) {
-			G3d_maskOn(in->map);
-			changemask = 1;
-		    }
-		}
-	    }
-
-	    /* Write the point or cell data */
-	    write_vtk_data(fp, in->map, region, param.input->answers[i], dp);
-
-	    /*We set the Mask off, if it was off before */
-	    if (param.mask->answer) {
-		if (G3d_maskFileExists())
-		    if (G3d_maskIsOn(in->map) && changemask)
-			G3d_maskOff(in->map);
-	    }
-
-	    /* Close the 3d raster map */
-	    if (!G3d_closeCell(in->map)) {
-		in->map = NULL;
-		fatal_error(_("Error closing 3d raster map, the VTK file may be incomplete."),
-			    in);
-	    }
-
-	    in->map = NULL;
-	}
+        for (i = 0; param.input->answers[i] != NULL; i++) {
+
+            G_debug(3, "Open 3d raster map %s", param.input->answers[i]);
+
+            /*Open the map */
+            in->map =
+                G3d_openCellOld(param.input->answers[i],
+                                G_find_grid3(param.input->answers[i], ""),
+                                &region, G3D_TILE_SAME_AS_FILE,
+                                G3D_USE_CACHE_DEFAULT);
+            if (in->map == NULL) {
+                G_warning(_("Error opening 3d raster map <%s>"),
+                          param.input->answers[i]);
+                fatal_error(" ", in);
+            }
+
+            /*if requested set the Mask on */
+            if (param.mask->answer) {
+                if (G3d_maskFileExists()) {
+                    changemask = 0;
+                    if (G3d_maskIsOff(in->map)) {
+                        G3d_maskOn(in->map);
+                        changemask = 1;
+                    }
+                }
+            }
+
+            /* Write the point or cell data */
+            write_vtk_data(fp, in->map, region, param.input->answers[i], dp);
+
+            /*We set the Mask off, if it was off before */
+            if (param.mask->answer) {
+                if (G3d_maskFileExists())
+                    if (G3d_maskIsOn(in->map) && changemask)
+                        G3d_maskOff(in->map);
+            }
+
+            /* Close the 3d raster map */
+            if (!G3d_closeCell(in->map)) {
+                in->map = NULL;
+                fatal_error(_("Error closing 3d raster map, the VTK file may be incomplete."),
+                            in);
+            }
+
+            in->map = NULL;
+        }
     }
 
     /*Write the RGB voxel data */
@@ -552,8 +551,8 @@ int main(int argc, char *argv[])
 
     /*Close the output file */
     if (param.output->answer && fp != NULL)
-	if (fclose(fp))
-	    fatal_error(_("Error closing VTK-ASCII file"), in);
+        if (fclose(fp))
+            fatal_error(_("Error closing VTK-ASCII file"), in);
 
     /*close all open maps and free memory */
     release_input_maps_struct(in);

+ 39 - 0
raster3d/r3.out.vtk/test.r3.out.vtk.sh

@@ -0,0 +1,39 @@
+# This script tests the export of voxel data
+# into the VTK format. Almost all options of
+# r3.out.vtk are tested. Validation data for each test
+# is located in the module source directory
+
+# We need to set a specific region in the
+# @preprocess step of this test. We generate
+# raster and voxel data with r.mapcalc and r3.mapcalc
+# The region setting should work for UTM and LL test locations
+g.region s=0 n=80 w=0 e=120 b=0 t=50 res=10 res3=10 -p3
+# Now generate two elevation maps, we have 8 rows and use
+# them for elevation computation. The rows are counted from north
+# to south. So in the south the elevation must have a maximum.
+r.mapcalc --o expr="elev_bottom = row()"
+r.mapcalc --o expr="elev_top = row() + 50"
+# Now create a voxel map with value = col + row + depth. Beware the 
+# raaster3d module count from south to north.
+r3.mapcalc --o expr="volume = col() + row() + depth()"
+# Add null value information
+r3.mapcalc --o expr="volume_null = if(row() == 2 || row() == 7, null(), volume)"
+# Create the rgb maps
+r3.mapcalc --o expr="volume_rgb = volume_null * 5"
+
+# The first @test just exports the volume map as cell and point data
+# using alow precision and replaces the default null value with 0
+# the created @files should be compared with the reference data 
+r3.out.vtk --o input=volume_null output=test_volume_null_1_cells.vtk dp=3 null=0
+r3.out.vtk -p --o input=volume_null output=test_volume_null_1_points.vtk dp=3 null=0
+
+# The second @test adds rgb and vector maps. We re-use the created volume map
+# for vector creation. The rgb value must range fom 0 - 255. The generated @files
+# should be compared with the reference data.
+r3.out.vtk --o rgbmaps=volume_rgb,volume_rgb,volume_rgb vectormaps=volume_null,volume_null,volume_null input=volume_null output=test_volume_null_1_cells_rgb_vect.vtk dp=3 null=-1.0
+r3.out.vtk -p --o rgbmaps=volume_rgb,volume_rgb,volume_rgb vectormaps=volume_null,volume_null,volume_null input=volume_null output=test_volume_null_1_points_rgb_vect.vtk dp=3 null=-1.0
+
+# The third @test uses raster maps to create volume data with an elevation surface
+# The maximum elevation should be in the south. Reference @files are present for validation.
+r3.out.vtk -s --o top=elev_top bottom=elev_bottom input=volume_null output=test_volume_null_1_cells_elevation.vtk dp=3 null=0
+r3.out.vtk -sp --o top=elev_top bottom=elev_bottom input=volume_null output=test_volume_null_1_points_elevation.vtk dp=3 null=0

+ 50 - 0
raster3d/r3.out.vtk/test_volume_null_1_cells.ref

@@ -0,0 +1,50 @@
+# vtk DataFile Version 3.0
+GRASS GIS 7 Export
+ASCII
+DATASET STRUCTURED_POINTS
+DIMENSIONS 13 9 6
+SPACING 10.000 10.000 10.000
+ORIGIN 0.000 0.000 0.000
+CELL_DATA 480
+SCALARS volume_null float 1
+LOOKUP_TABLE default
+3.000 4.000 5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+4.000 5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 24.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 24.000 25.000 

Різницю між файлами не показано, бо вона завелика
+ 4850 - 0
raster3d/r3.out.vtk/test_volume_null_1_cells_elevation.ref


Різницю між файлами не показано, бо вона завелика
+ 1012 - 0
raster3d/r3.out.vtk/test_volume_null_1_cells_rgb_vect.ref


+ 50 - 0
raster3d/r3.out.vtk/test_volume_null_1_points.ref

@@ -0,0 +1,50 @@
+# vtk DataFile Version 3.0
+GRASS GIS 7 Export
+ASCII
+DATASET STRUCTURED_POINTS
+DIMENSIONS 12 8 5
+SPACING 10.000 10.000 10.000
+ORIGIN 5.000 5.000 5.000
+POINT_DATA 480
+SCALARS volume_null float 1
+LOOKUP_TABLE default
+3.000 4.000 5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+4.000 5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 24.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 24.000 25.000 

+ 529 - 0
raster3d/r3.out.vtk/test_volume_null_1_points_elevation.ref

@@ -0,0 +1,529 @@
+# vtk DataFile Version 3.0
+GRASS GIS 7 Export
+ASCII
+DATASET STRUCTURED_GRID
+DIMENSIONS 12 8 5
+POINTS 480 float
+5.000 75.000 1.000
+15.000 75.000 1.000
+25.000 75.000 1.000
+35.000 75.000 1.000
+45.000 75.000 1.000
+55.000 75.000 1.000
+65.000 75.000 1.000
+75.000 75.000 1.000
+85.000 75.000 1.000
+95.000 75.000 1.000
+105.000 75.000 1.000
+115.000 75.000 1.000
+5.000 65.000 2.000
+15.000 65.000 2.000
+25.000 65.000 2.000
+35.000 65.000 2.000
+45.000 65.000 2.000
+55.000 65.000 2.000
+65.000 65.000 2.000
+75.000 65.000 2.000
+85.000 65.000 2.000
+95.000 65.000 2.000
+105.000 65.000 2.000
+115.000 65.000 2.000
+5.000 55.000 3.000
+15.000 55.000 3.000
+25.000 55.000 3.000
+35.000 55.000 3.000
+45.000 55.000 3.000
+55.000 55.000 3.000
+65.000 55.000 3.000
+75.000 55.000 3.000
+85.000 55.000 3.000
+95.000 55.000 3.000
+105.000 55.000 3.000
+115.000 55.000 3.000
+5.000 45.000 4.000
+15.000 45.000 4.000
+25.000 45.000 4.000
+35.000 45.000 4.000
+45.000 45.000 4.000
+55.000 45.000 4.000
+65.000 45.000 4.000
+75.000 45.000 4.000
+85.000 45.000 4.000
+95.000 45.000 4.000
+105.000 45.000 4.000
+115.000 45.000 4.000
+5.000 35.000 5.000
+15.000 35.000 5.000
+25.000 35.000 5.000
+35.000 35.000 5.000
+45.000 35.000 5.000
+55.000 35.000 5.000
+65.000 35.000 5.000
+75.000 35.000 5.000
+85.000 35.000 5.000
+95.000 35.000 5.000
+105.000 35.000 5.000
+115.000 35.000 5.000
+5.000 25.000 6.000
+15.000 25.000 6.000
+25.000 25.000 6.000
+35.000 25.000 6.000
+45.000 25.000 6.000
+55.000 25.000 6.000
+65.000 25.000 6.000
+75.000 25.000 6.000
+85.000 25.000 6.000
+95.000 25.000 6.000
+105.000 25.000 6.000
+115.000 25.000 6.000
+5.000 15.000 7.000
+15.000 15.000 7.000
+25.000 15.000 7.000
+35.000 15.000 7.000
+45.000 15.000 7.000
+55.000 15.000 7.000
+65.000 15.000 7.000
+75.000 15.000 7.000
+85.000 15.000 7.000
+95.000 15.000 7.000
+105.000 15.000 7.000
+115.000 15.000 7.000
+5.000 5.000 8.000
+15.000 5.000 8.000
+25.000 5.000 8.000
+35.000 5.000 8.000
+45.000 5.000 8.000
+55.000 5.000 8.000
+65.000 5.000 8.000
+75.000 5.000 8.000
+85.000 5.000 8.000
+95.000 5.000 8.000
+105.000 5.000 8.000
+115.000 5.000 8.000
+5.000 75.000 13.500
+15.000 75.000 13.500
+25.000 75.000 13.500
+35.000 75.000 13.500
+45.000 75.000 13.500
+55.000 75.000 13.500
+65.000 75.000 13.500
+75.000 75.000 13.500
+85.000 75.000 13.500
+95.000 75.000 13.500
+105.000 75.000 13.500
+115.000 75.000 13.500
+5.000 65.000 14.500
+15.000 65.000 14.500
+25.000 65.000 14.500
+35.000 65.000 14.500
+45.000 65.000 14.500
+55.000 65.000 14.500
+65.000 65.000 14.500
+75.000 65.000 14.500
+85.000 65.000 14.500
+95.000 65.000 14.500
+105.000 65.000 14.500
+115.000 65.000 14.500
+5.000 55.000 15.500
+15.000 55.000 15.500
+25.000 55.000 15.500
+35.000 55.000 15.500
+45.000 55.000 15.500
+55.000 55.000 15.500
+65.000 55.000 15.500
+75.000 55.000 15.500
+85.000 55.000 15.500
+95.000 55.000 15.500
+105.000 55.000 15.500
+115.000 55.000 15.500
+5.000 45.000 16.500
+15.000 45.000 16.500
+25.000 45.000 16.500
+35.000 45.000 16.500
+45.000 45.000 16.500
+55.000 45.000 16.500
+65.000 45.000 16.500
+75.000 45.000 16.500
+85.000 45.000 16.500
+95.000 45.000 16.500
+105.000 45.000 16.500
+115.000 45.000 16.500
+5.000 35.000 17.500
+15.000 35.000 17.500
+25.000 35.000 17.500
+35.000 35.000 17.500
+45.000 35.000 17.500
+55.000 35.000 17.500
+65.000 35.000 17.500
+75.000 35.000 17.500
+85.000 35.000 17.500
+95.000 35.000 17.500
+105.000 35.000 17.500
+115.000 35.000 17.500
+5.000 25.000 18.500
+15.000 25.000 18.500
+25.000 25.000 18.500
+35.000 25.000 18.500
+45.000 25.000 18.500
+55.000 25.000 18.500
+65.000 25.000 18.500
+75.000 25.000 18.500
+85.000 25.000 18.500
+95.000 25.000 18.500
+105.000 25.000 18.500
+115.000 25.000 18.500
+5.000 15.000 19.500
+15.000 15.000 19.500
+25.000 15.000 19.500
+35.000 15.000 19.500
+45.000 15.000 19.500
+55.000 15.000 19.500
+65.000 15.000 19.500
+75.000 15.000 19.500
+85.000 15.000 19.500
+95.000 15.000 19.500
+105.000 15.000 19.500
+115.000 15.000 19.500
+5.000 5.000 20.500
+15.000 5.000 20.500
+25.000 5.000 20.500
+35.000 5.000 20.500
+45.000 5.000 20.500
+55.000 5.000 20.500
+65.000 5.000 20.500
+75.000 5.000 20.500
+85.000 5.000 20.500
+95.000 5.000 20.500
+105.000 5.000 20.500
+115.000 5.000 20.500
+5.000 75.000 26.000
+15.000 75.000 26.000
+25.000 75.000 26.000
+35.000 75.000 26.000
+45.000 75.000 26.000
+55.000 75.000 26.000
+65.000 75.000 26.000
+75.000 75.000 26.000
+85.000 75.000 26.000
+95.000 75.000 26.000
+105.000 75.000 26.000
+115.000 75.000 26.000
+5.000 65.000 27.000
+15.000 65.000 27.000
+25.000 65.000 27.000
+35.000 65.000 27.000
+45.000 65.000 27.000
+55.000 65.000 27.000
+65.000 65.000 27.000
+75.000 65.000 27.000
+85.000 65.000 27.000
+95.000 65.000 27.000
+105.000 65.000 27.000
+115.000 65.000 27.000
+5.000 55.000 28.000
+15.000 55.000 28.000
+25.000 55.000 28.000
+35.000 55.000 28.000
+45.000 55.000 28.000
+55.000 55.000 28.000
+65.000 55.000 28.000
+75.000 55.000 28.000
+85.000 55.000 28.000
+95.000 55.000 28.000
+105.000 55.000 28.000
+115.000 55.000 28.000
+5.000 45.000 29.000
+15.000 45.000 29.000
+25.000 45.000 29.000
+35.000 45.000 29.000
+45.000 45.000 29.000
+55.000 45.000 29.000
+65.000 45.000 29.000
+75.000 45.000 29.000
+85.000 45.000 29.000
+95.000 45.000 29.000
+105.000 45.000 29.000
+115.000 45.000 29.000
+5.000 35.000 30.000
+15.000 35.000 30.000
+25.000 35.000 30.000
+35.000 35.000 30.000
+45.000 35.000 30.000
+55.000 35.000 30.000
+65.000 35.000 30.000
+75.000 35.000 30.000
+85.000 35.000 30.000
+95.000 35.000 30.000
+105.000 35.000 30.000
+115.000 35.000 30.000
+5.000 25.000 31.000
+15.000 25.000 31.000
+25.000 25.000 31.000
+35.000 25.000 31.000
+45.000 25.000 31.000
+55.000 25.000 31.000
+65.000 25.000 31.000
+75.000 25.000 31.000
+85.000 25.000 31.000
+95.000 25.000 31.000
+105.000 25.000 31.000
+115.000 25.000 31.000
+5.000 15.000 32.000
+15.000 15.000 32.000
+25.000 15.000 32.000
+35.000 15.000 32.000
+45.000 15.000 32.000
+55.000 15.000 32.000
+65.000 15.000 32.000
+75.000 15.000 32.000
+85.000 15.000 32.000
+95.000 15.000 32.000
+105.000 15.000 32.000
+115.000 15.000 32.000
+5.000 5.000 33.000
+15.000 5.000 33.000
+25.000 5.000 33.000
+35.000 5.000 33.000
+45.000 5.000 33.000
+55.000 5.000 33.000
+65.000 5.000 33.000
+75.000 5.000 33.000
+85.000 5.000 33.000
+95.000 5.000 33.000
+105.000 5.000 33.000
+115.000 5.000 33.000
+5.000 75.000 38.500
+15.000 75.000 38.500
+25.000 75.000 38.500
+35.000 75.000 38.500
+45.000 75.000 38.500
+55.000 75.000 38.500
+65.000 75.000 38.500
+75.000 75.000 38.500
+85.000 75.000 38.500
+95.000 75.000 38.500
+105.000 75.000 38.500
+115.000 75.000 38.500
+5.000 65.000 39.500
+15.000 65.000 39.500
+25.000 65.000 39.500
+35.000 65.000 39.500
+45.000 65.000 39.500
+55.000 65.000 39.500
+65.000 65.000 39.500
+75.000 65.000 39.500
+85.000 65.000 39.500
+95.000 65.000 39.500
+105.000 65.000 39.500
+115.000 65.000 39.500
+5.000 55.000 40.500
+15.000 55.000 40.500
+25.000 55.000 40.500
+35.000 55.000 40.500
+45.000 55.000 40.500
+55.000 55.000 40.500
+65.000 55.000 40.500
+75.000 55.000 40.500
+85.000 55.000 40.500
+95.000 55.000 40.500
+105.000 55.000 40.500
+115.000 55.000 40.500
+5.000 45.000 41.500
+15.000 45.000 41.500
+25.000 45.000 41.500
+35.000 45.000 41.500
+45.000 45.000 41.500
+55.000 45.000 41.500
+65.000 45.000 41.500
+75.000 45.000 41.500
+85.000 45.000 41.500
+95.000 45.000 41.500
+105.000 45.000 41.500
+115.000 45.000 41.500
+5.000 35.000 42.500
+15.000 35.000 42.500
+25.000 35.000 42.500
+35.000 35.000 42.500
+45.000 35.000 42.500
+55.000 35.000 42.500
+65.000 35.000 42.500
+75.000 35.000 42.500
+85.000 35.000 42.500
+95.000 35.000 42.500
+105.000 35.000 42.500
+115.000 35.000 42.500
+5.000 25.000 43.500
+15.000 25.000 43.500
+25.000 25.000 43.500
+35.000 25.000 43.500
+45.000 25.000 43.500
+55.000 25.000 43.500
+65.000 25.000 43.500
+75.000 25.000 43.500
+85.000 25.000 43.500
+95.000 25.000 43.500
+105.000 25.000 43.500
+115.000 25.000 43.500
+5.000 15.000 44.500
+15.000 15.000 44.500
+25.000 15.000 44.500
+35.000 15.000 44.500
+45.000 15.000 44.500
+55.000 15.000 44.500
+65.000 15.000 44.500
+75.000 15.000 44.500
+85.000 15.000 44.500
+95.000 15.000 44.500
+105.000 15.000 44.500
+115.000 15.000 44.500
+5.000 5.000 45.500
+15.000 5.000 45.500
+25.000 5.000 45.500
+35.000 5.000 45.500
+45.000 5.000 45.500
+55.000 5.000 45.500
+65.000 5.000 45.500
+75.000 5.000 45.500
+85.000 5.000 45.500
+95.000 5.000 45.500
+105.000 5.000 45.500
+115.000 5.000 45.500
+5.000 75.000 51.000
+15.000 75.000 51.000
+25.000 75.000 51.000
+35.000 75.000 51.000
+45.000 75.000 51.000
+55.000 75.000 51.000
+65.000 75.000 51.000
+75.000 75.000 51.000
+85.000 75.000 51.000
+95.000 75.000 51.000
+105.000 75.000 51.000
+115.000 75.000 51.000
+5.000 65.000 52.000
+15.000 65.000 52.000
+25.000 65.000 52.000
+35.000 65.000 52.000
+45.000 65.000 52.000
+55.000 65.000 52.000
+65.000 65.000 52.000
+75.000 65.000 52.000
+85.000 65.000 52.000
+95.000 65.000 52.000
+105.000 65.000 52.000
+115.000 65.000 52.000
+5.000 55.000 53.000
+15.000 55.000 53.000
+25.000 55.000 53.000
+35.000 55.000 53.000
+45.000 55.000 53.000
+55.000 55.000 53.000
+65.000 55.000 53.000
+75.000 55.000 53.000
+85.000 55.000 53.000
+95.000 55.000 53.000
+105.000 55.000 53.000
+115.000 55.000 53.000
+5.000 45.000 54.000
+15.000 45.000 54.000
+25.000 45.000 54.000
+35.000 45.000 54.000
+45.000 45.000 54.000
+55.000 45.000 54.000
+65.000 45.000 54.000
+75.000 45.000 54.000
+85.000 45.000 54.000
+95.000 45.000 54.000
+105.000 45.000 54.000
+115.000 45.000 54.000
+5.000 35.000 55.000
+15.000 35.000 55.000
+25.000 35.000 55.000
+35.000 35.000 55.000
+45.000 35.000 55.000
+55.000 35.000 55.000
+65.000 35.000 55.000
+75.000 35.000 55.000
+85.000 35.000 55.000
+95.000 35.000 55.000
+105.000 35.000 55.000
+115.000 35.000 55.000
+5.000 25.000 56.000
+15.000 25.000 56.000
+25.000 25.000 56.000
+35.000 25.000 56.000
+45.000 25.000 56.000
+55.000 25.000 56.000
+65.000 25.000 56.000
+75.000 25.000 56.000
+85.000 25.000 56.000
+95.000 25.000 56.000
+105.000 25.000 56.000
+115.000 25.000 56.000
+5.000 15.000 57.000
+15.000 15.000 57.000
+25.000 15.000 57.000
+35.000 15.000 57.000
+45.000 15.000 57.000
+55.000 15.000 57.000
+65.000 15.000 57.000
+75.000 15.000 57.000
+85.000 15.000 57.000
+95.000 15.000 57.000
+105.000 15.000 57.000
+115.000 15.000 57.000
+5.000 5.000 58.000
+15.000 5.000 58.000
+25.000 5.000 58.000
+35.000 5.000 58.000
+45.000 5.000 58.000
+55.000 5.000 58.000
+65.000 5.000 58.000
+75.000 5.000 58.000
+85.000 5.000 58.000
+95.000 5.000 58.000
+105.000 5.000 58.000
+115.000 5.000 58.000
+POINT_DATA 480
+SCALARS volume_null float 1
+LOOKUP_TABLE default
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+3.000 4.000 5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+4.000 5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 
+12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+5.000 6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 
+13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 24.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+6.000 7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 
+14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 24.000 25.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 23.000 
+11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 22.000 
+10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 21.000 
+9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 19.000 20.000 
+0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 
+7.000 8.000 9.000 10.000 11.000 12.000 13.000 14.000 15.000 16.000 17.000 18.000 

Різницю між файлами не показано, бо вона завелика
+ 1012 - 0
raster3d/r3.out.vtk/test_volume_null_1_points_rgb_vect.ref


+ 318 - 358
raster3d/r3.out.vtk/writeVTKData.c

@@ -1,20 +1,20 @@
 
 /****************************************************************************
-*
-* MODULE:       r3.out.vtk  
-*   	    	
-* AUTHOR(S):    Original author 
-*               Soeren Gebbert soerengebbert at gmx de
-* 		27 Feb 2006 Berlin
-* PURPOSE:      Converts 3D raster maps (G3D) into the VTK-Ascii format  
-*
-* COPYRIGHT:    (C) 2005 by the GRASS Development Team
-*
-*               This program is free software under the GNU General Public
-*   	    	License (>=v2). Read the file COPYING that comes with GRASS
-*   	    	for details.
-*
-*****************************************************************************/
+ *
+ * MODULE:       r3.out.vtk  
+ *   	    	
+ * AUTHOR(S):    Original author 
+ *               Soeren Gebbert soerengebbert at gmx de
+ * 		27 Feb 2006 Berlin
+ * PURPOSE:      Converts 3D raster maps (G3D) into the VTK-Ascii format  
+ *
+ * COPYRIGHT:    (C) 2005 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *   	    	License (>=v2). Read the file COPYING that comes with GRASS
+ *   	    	for details.
+ *
+ *****************************************************************************/
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -29,41 +29,39 @@
 
 /*local prototypes */
 static double get_raster_value_as_double(int maptype, void *ptr,
-					 double nullval);
+                                         double nullval);
 static double get_g3d_raster_value_as_double(void *map, int x, int y, int z,
-					     int type, double nullval);
+                                             int type, double nullval);
 
 
 /* ************************************************************************* */
 /* Get the value of the current raster pointer as double ******************* */
+
 /* ************************************************************************* */
 double get_raster_value_as_double(int MapType, void *ptr, double nullval)
 {
     double val = nullval;
 
     if (MapType == CELL_TYPE) {
-	if (Rast_is_null_value(ptr, MapType)) {
-	    val = nullval;
-	}
-	else {
-	    val = *(CELL *) ptr;
-	}
+        if (Rast_is_null_value(ptr, MapType)) {
+            val = nullval;
+        } else {
+            val = *(CELL *) ptr;
+        }
     }
     if (MapType == FCELL_TYPE) {
-	if (Rast_is_null_value(ptr, MapType)) {
-	    val = nullval;
-	}
-	else {
-	    val = *(FCELL *) ptr;
-	}
+        if (Rast_is_null_value(ptr, MapType)) {
+            val = nullval;
+        } else {
+            val = *(FCELL *) ptr;
+        }
     }
     if (MapType == DCELL_TYPE) {
-	if (Rast_is_null_value(ptr, MapType)) {
-	    val = nullval;
-	}
-	else {
-	    val = *(DCELL *) ptr;
-	}
+        if (Rast_is_null_value(ptr, MapType)) {
+            val = nullval;
+        } else {
+            val = *(DCELL *) ptr;
+        }
     }
 
     return val;
@@ -71,27 +69,27 @@ double get_raster_value_as_double(int MapType, void *ptr, double nullval)
 
 /* ************************************************************************* */
 /* Get the value of the 3d raster map as double *************************** */
+
 /* ************************************************************************* */
 double get_g3d_raster_value_as_double(void *map, int x, int y, int z,
-				      int type, double nullval)
+                                      int type, double nullval)
 {
     double val = 0;
     float fvalue;
     double dvalue;
 
     if (type == FCELL_TYPE) {
-	G3d_getValue(map, x, y, z, &fvalue, type);
-	if (G3d_isNullValueNum(&fvalue, FCELL_TYPE))
-	    val = nullval;
-	else
-	    val = (double)fvalue;
-    }
-    else {
-	G3d_getValue(map, x, y, z, &dvalue, type);
-	if (G3d_isNullValueNum(&dvalue, DCELL_TYPE))
-	    val = nullval;
-	else
-	    val = dvalue;
+        G3d_getValue(map, x, y, z, &fvalue, type);
+        if (G3d_isNullValueNum(&fvalue, FCELL_TYPE))
+            val = nullval;
+        else
+            val = (double) fvalue;
+    } else {
+        G3d_getValue(map, x, y, z, &dvalue, type);
+        if (G3d_isNullValueNum(&dvalue, DCELL_TYPE))
+            val = nullval;
+        else
+            val = dvalue;
     }
 
     return val;
@@ -99,11 +97,12 @@ double get_g3d_raster_value_as_double(void *map, int x, int y, int z,
 
 /* ************************************************************************* */
 /* This function writes the point coordinates ****************************** */
+
 /* ************************************************************************* */
 void write_vtk_points(input_maps * in, FILE * fp, G3D_Region region, int dp,
-		      int type, double scale)
+                      int type, double scale)
 {
-    int x, y, z, status = 0;
+    int x, y, z, percentage = 0;
     int rows, cols, depths;
     void *rast_top = NULL;
     void *rast_bottom = NULL;
@@ -124,127 +123,130 @@ void write_vtk_points(input_maps * in, FILE * fp, G3D_Region region, int dp,
 
     for (z = 0; z < depths; z++) {
 
-	for (y = 0; y < rows; y++) {
-	    G_percent(status, (rows * depths - 1), 10);
-	    status++;
-
-	    Rast_get_row(in->top, rast_top, y, in->topMapType);
-
-	    Rast_get_row(in->bottom, rast_bottom, y, in->bottomMapType);
-
-	    for (x = 0, ptr_top = rast_top, ptr_bottom = rast_bottom;
-		 x < cols;
-		 x++, ptr_top =
-		 G_incr_void_ptr(ptr_top, Rast_cell_size(in->topMapType)),
-		 ptr_bottom =
-		 G_incr_void_ptr(ptr_bottom,
-				 Rast_cell_size(in->bottomMapType))) {
-
-		/*Get the values */
-		topval =
-		    get_raster_value_as_double(in->topMapType, ptr_top, 0.0);
-		bottomval =
-		    get_raster_value_as_double(in->bottomMapType, ptr_bottom,
-					       0.0);
-
-		if (type == 1) {	/*Structured Grid */
-		    /*Calculate the coordinates */
-		    xcoor =
-			region.west + (region.ew_res / 2 +
-				       region.ew_res * (x));
-		    ycoor =
-			region.north - (region.ns_res / 2 +
-					region.ns_res * (y));
-		    zcoor =
-			(bottomval +
-			 z * (topval - bottomval) / (depths - 1)) * scale;
-
-		    xcoor -= x_extent;
-		    ycoor -= y_extent;
-
-		    fprintf(fp, "%.*f ", dp, xcoor);
-		    fprintf(fp, "%.*f ", dp, ycoor);
-		    fprintf(fp, "%.*f\n", dp, zcoor);
-		}
-		else {		/*Unstructured Grid */
-		    /*Write for every cell the coordinates for a hexahedron -> 8 points */
-		    /*VTK Hexaeder */
-		    /* bottom
-		     * 3 --- 2
-		     * |     |
-		     * 0 --- 1
-
-		     * top
-		     * 7 --- 6
-		     * |     |
-		     * 4 --- 5
-
-		     */
-		    xcoor = region.west + (region.ew_res * (x));	/*0, 3, 4, 7 */
-		    ycoor = region.north - (region.ns_res * (y));	/*2, 3, 6, 7 */
-		    zcoor = (bottomval + z * (topval - bottomval) / (depths)) * scale;	/*0, 1, 2, 3 */
-
-		    xcoor1 = region.west + (region.ew_res + region.ew_res * (x));	/*1, 2, 5, 6 */
-		    ycoor1 = region.north - (region.ns_res + region.ns_res * (y));	/*0, 1, 4, 5 */
-		    zcoor1 = (bottomval + z * (topval - bottomval) / (depths) + (topval - bottomval) / (depths)) * scale;	/*4, 5, ,6 ,7 */
-
-		    xcoor -= x_extent;
-		    ycoor -= y_extent;
-
-		    xcoor1 -= x_extent;
-		    ycoor1 -= y_extent;
-
-
-		    /*0 */
-		    fprintf(fp, "%.*f ", dp, xcoor);
-		    fprintf(fp, "%.*f ", dp, ycoor1);
-		    fprintf(fp, "%.*f\n", dp, zcoor);
-		    /*1 */
-		    fprintf(fp, "%.*f ", dp, xcoor1);
-		    fprintf(fp, "%.*f ", dp, ycoor1);
-		    fprintf(fp, "%.*f\n", dp, zcoor);
-		    /*2 */
-		    fprintf(fp, "%.*f ", dp, xcoor1);
-		    fprintf(fp, "%.*f ", dp, ycoor);
-		    fprintf(fp, "%.*f\n", dp, zcoor);
-		    /*3 */
-		    fprintf(fp, "%.*f ", dp, xcoor);
-		    fprintf(fp, "%.*f ", dp, ycoor);
-		    fprintf(fp, "%.*f\n", dp, zcoor);
-
-		    /*4 */
-		    fprintf(fp, "%.*f ", dp, xcoor);
-		    fprintf(fp, "%.*f ", dp, ycoor1);
-		    fprintf(fp, "%.*f\n", dp, zcoor1);
-		    /*5 */
-		    fprintf(fp, "%.*f ", dp, xcoor1);
-		    fprintf(fp, "%.*f ", dp, ycoor1);
-		    fprintf(fp, "%.*f\n", dp, zcoor1);
-		    /*6 */
-		    fprintf(fp, "%.*f ", dp, xcoor1);
-		    fprintf(fp, "%.*f ", dp, ycoor);
-		    fprintf(fp, "%.*f\n", dp, zcoor1);
-		    /*7 */
-		    fprintf(fp, "%.*f ", dp, xcoor);
-		    fprintf(fp, "%.*f ", dp, ycoor);
-		    fprintf(fp, "%.*f\n", dp, zcoor1);
-		}
-	    }
-	}
+        for (y = 0; y < rows; y++) {
+            G_percent(percentage, (rows * depths - 1), 10);
+            percentage++;
+
+            Rast_get_row(in->top, rast_top, y, in->topMapType);
+
+            Rast_get_row(in->bottom, rast_bottom, y, in->bottomMapType);
+
+            for (x = 0, ptr_top = rast_top, ptr_bottom = rast_bottom;
+                x < cols;
+                x++, ptr_top =
+                G_incr_void_ptr(ptr_top, Rast_cell_size(in->topMapType)),
+                ptr_bottom =
+                G_incr_void_ptr(ptr_bottom,
+                                Rast_cell_size(in->bottomMapType))) {
+
+                /*Get the values */
+                topval =
+                    get_raster_value_as_double(in->topMapType, ptr_top, 0.0);
+                bottomval =
+                    get_raster_value_as_double(in->bottomMapType, ptr_bottom,
+                                               0.0);
+
+                if (type == 1) { /*Structured Grid */
+                    /*Calculate the coordinates */
+                    xcoor =
+                        region.west + (region.ew_res / 2 +
+                        region.ew_res * (x));
+                    /* Here the raster north->south coordinate system is used */
+                    ycoor =
+                        region.north - (region.ns_res / 2 +
+                        region.ns_res * (y));
+                    zcoor =
+                        (bottomval +
+                        z * (topval - bottomval) / (depths - 1)) * scale;
+
+                    xcoor -= x_extent;
+                    ycoor -= y_extent;
+
+                    fprintf(fp, "%.*f ", dp, xcoor);
+                    fprintf(fp, "%.*f ", dp, ycoor);
+                    fprintf(fp, "%.*f\n", dp, zcoor);
+                } else { /*Unstructured Grid */
+                    /*Write for every cell the coordinates for a hexahedron -> 8 points */
+                    /*VTK Hexaeder */
+                    /* bottom
+                     * 3 --- 2
+                     * |     |
+                     * 0 --- 1
+
+                     * top
+                     * 7 --- 6
+                     * |     |
+                     * 4 --- 5
+
+                     */
+                    xcoor = region.west + (region.ew_res * (x)); /*0, 3, 4, 7 */
+                    /* Here the raster north->south coordinate system is used */
+                    ycoor = region.north - (region.ns_res * (y)); /*2, 3, 6, 7 */
+                    zcoor = (bottomval + z * (topval - bottomval) / (depths)) * scale; /*0, 1, 2, 3 */
+
+                    xcoor1 = region.west + (region.ew_res + region.ew_res * (x)); /*1, 2, 5, 6 */
+                    /* Here the raster north->south coordinate system is used */
+                    ycoor1 = region.north - (region.ns_res + region.ns_res * (y)); /*0, 1, 4, 5 */
+                    zcoor1 = (bottomval + z * (topval - bottomval) / (depths) + (topval - bottomval) / (depths)) * scale; /*4, 5, ,6 ,7 */
+
+                    xcoor -= x_extent;
+                    ycoor -= y_extent;
+
+                    xcoor1 -= x_extent;
+                    ycoor1 -= y_extent;
+
+
+                    /*0 */
+                    fprintf(fp, "%.*f ", dp, xcoor);
+                    fprintf(fp, "%.*f ", dp, ycoor1);
+                    fprintf(fp, "%.*f\n", dp, zcoor);
+                    /*1 */
+                    fprintf(fp, "%.*f ", dp, xcoor1);
+                    fprintf(fp, "%.*f ", dp, ycoor1);
+                    fprintf(fp, "%.*f\n", dp, zcoor);
+                    /*2 */
+                    fprintf(fp, "%.*f ", dp, xcoor1);
+                    fprintf(fp, "%.*f ", dp, ycoor);
+                    fprintf(fp, "%.*f\n", dp, zcoor);
+                    /*3 */
+                    fprintf(fp, "%.*f ", dp, xcoor);
+                    fprintf(fp, "%.*f ", dp, ycoor);
+                    fprintf(fp, "%.*f\n", dp, zcoor);
+
+                    /*4 */
+                    fprintf(fp, "%.*f ", dp, xcoor);
+                    fprintf(fp, "%.*f ", dp, ycoor1);
+                    fprintf(fp, "%.*f\n", dp, zcoor1);
+                    /*5 */
+                    fprintf(fp, "%.*f ", dp, xcoor1);
+                    fprintf(fp, "%.*f ", dp, ycoor1);
+                    fprintf(fp, "%.*f\n", dp, zcoor1);
+                    /*6 */
+                    fprintf(fp, "%.*f ", dp, xcoor1);
+                    fprintf(fp, "%.*f ", dp, ycoor);
+                    fprintf(fp, "%.*f\n", dp, zcoor1);
+                    /*7 */
+                    fprintf(fp, "%.*f ", dp, xcoor);
+                    fprintf(fp, "%.*f ", dp, ycoor);
+                    fprintf(fp, "%.*f\n", dp, zcoor1);
+                }
+            }
+        }
     }
 
     if (type == 1)
-	fprintf(fp, "POINT_DATA %i\n", region.cols * region.rows * region.depths);	/*We have pointdata */
+        fprintf(fp, "POINT_DATA %i\n", region.cols * region.rows * region.depths); /*We have pointdata */
 
     return;
 }
 
 /* ************************************************************************* */
 /* This function writes the cell for the unstructured grid ***************** */
+
 /* ************************************************************************* */
 void write_vtk_unstructured_grid_cells(FILE * fp, G3D_Region region)
 {
-    int x, y, z, status;
+    int x, y, z, percentage;
     int rows, cols, depths, count;
 
     rows = region.rows;
@@ -254,54 +256,54 @@ void write_vtk_unstructured_grid_cells(FILE * fp, G3D_Region region)
     G_debug(3, _("write_vtk_unstructured_grid_cells: Writing the cells"));
 
     fprintf(fp, "CELLS %i %i\n", region.cols * region.rows * region.depths,
-	    region.cols * region.rows * region.depths * 9);
+            region.cols * region.rows * region.depths * 9);
 
     count = 0;
-    status = 0;
+    percentage = 0;
 
     /*The point - cell links */
     for (z = 0; z < depths; z++) {
-	for (y = 0; y < rows; y++) {
-	    G_percent(status, (rows * depths - 1), 10);
-	    status++;
-
-	    for (x = 0; x < cols; x++) {
-		/*Voxel */
-		fprintf(fp, "%i %i %i %i %i %i %i %i %i\n", 8,
-			count * 8, count * 8 + 1, count * 8 + 3,
-			count * 8 + 2, count * 8 + 4, count * 8 + 5,
-			count * 8 + 7, count * 8 + 6);
-
-		/*Hexaeder 
-		 * fprintf(fp, "%i %i %i %i %i %i %i %i %i\n", 8,
-		 * count * 8, count * 8 + 1, count * 8 + 2, count * 8 + 3,
-		 * count * 8 + 4, count * 8 + 5, count * 8 + 6,
-		 * count * 8 + 7);
-		 */
-		count++;
-	    }
-	}
+        for (y = 0; y < rows; y++) {
+            G_percent(percentage, (rows * depths - 1), 10);
+            percentage++;
+
+            for (x = 0; x < cols; x++) {
+                /*Voxel */
+                fprintf(fp, "%i %i %i %i %i %i %i %i %i\n", 8,
+                        count * 8, count * 8 + 1, count * 8 + 3,
+                        count * 8 + 2, count * 8 + 4, count * 8 + 5,
+                        count * 8 + 7, count * 8 + 6);
+
+                /*Hexaeder 
+                 * fprintf(fp, "%i %i %i %i %i %i %i %i %i\n", 8,
+                 * count * 8, count * 8 + 1, count * 8 + 2, count * 8 + 3,
+                 * count * 8 + 4, count * 8 + 5, count * 8 + 6,
+                 * count * 8 + 7);
+                 */
+                count++;
+            }
+        }
     }
-    status = 0;
+    percentage = 0;
 
     fprintf(fp, "CELL_TYPES %i\n", region.cols * region.rows * region.depths);
     /*the cell types */
     for (z = 0; z < depths; z++) {
-	for (y = 0; y < rows; y++) {
-	    G_percent(status, (rows * depths - 1), 10);
-	    status++;
-
-	    for (x = 0; x < cols; x++) {
-		/*Voxel */
-		fprintf(fp, "11\n");
-		/*Hexaeder 
-		 * fprintf(fp, "12\n");
-		 */
-	    }
-	}
+        for (y = 0; y < rows; y++) {
+            G_percent(percentage, (rows * depths - 1), 10);
+            percentage++;
+
+            for (x = 0; x < cols; x++) {
+                /*Voxel */
+                fprintf(fp, "11\n");
+                /*Hexaeder 
+                 * fprintf(fp, "12\n");
+                 */
+            }
+        }
     }
 
-    fprintf(fp, "CELL_DATA %i\n", region.cols * region.rows * region.depths);	/*We have celldata  */
+    fprintf(fp, "CELL_DATA %i\n", region.cols * region.rows * region.depths); /*We have celldata  */
 
     return;
 }
@@ -309,13 +311,14 @@ void write_vtk_unstructured_grid_cells(FILE * fp, G3D_Region region)
 
 /* ************************************************************************* */
 /* Write the VTK Cell or point data **************************************** */
+
 /* ************************************************************************* */
 void write_vtk_data(FILE * fp, void *map, G3D_Region region, char *varname,
-		    int dp)
+                    int dp)
 {
     double value;
     double nullvalue;
-    int x, y, z, status;
+    int x, y, z, percentage;
     int rows, cols, depths, typeIntern;
 
     rows = region.rows;
@@ -324,65 +327,66 @@ void write_vtk_data(FILE * fp, void *map, G3D_Region region, char *varname,
 
     /*the nullvalue */
     if (!sscanf(param.null_val->answer, "%lf", &nullvalue)) {
-	G_warning("Null value is not valid, using 0 instead.");
-	nullvalue = 0;
+        G_warning("Null value is not valid, using 0 instead.");
+        nullvalue = 0;
     }
 
     G_debug(3,
-	    _("write_vtk_data: Writing Celldata %s with rows %i cols %i depths %i to vtk-ascii file"),
-	    varname, rows, cols, depths);
+            _("write_vtk_data: Writing Celldata %s with rows %i cols %i depths %i to vtk-ascii file"),
+            varname, rows, cols, depths);
 
     fprintf(fp, "SCALARS %s float 1\n", varname);
     fprintf(fp, "LOOKUP_TABLE default\n");
 
     typeIntern = G3d_tileTypeMap(map);
 
-    status = 0;
+    percentage = 0;
 
     for (z = 0; z < depths; z++) {
-	if (!param.structgrid->answer) {
-	    for (y = 0; y < rows; y++) {
-		G_percent(status, (rows * depths - 1), 10);
-		status++;
-
-		for (x = 0; x < cols; x++) {
-		    value =
-			get_g3d_raster_value_as_double(map, x, y, z,
-						       typeIntern, nullvalue);
-		    fprintf(fp, "%.*f ", dp, value);
-
-		}
-		fprintf(fp, "\n");
-	    }
-	}
-	else {
-	    for (y = rows - 1; y >= 0; y--) {
-		G_percent(status, (rows * depths - 1), 10);
-		status++;
-
-		for (x = 0; x < cols; x++) {
-		    value =
-			get_g3d_raster_value_as_double(map, x, y, z,
-						       typeIntern, nullvalue);
-		    fprintf(fp, "%.*f ", dp, value);
-
-		}
-		fprintf(fp, "\n");
-	    }
-	}
+        if (param.structgrid->answer) {
+            /* In case of structured grid data, the point/cell coordinates
+               are computed based on the north->south raster coordinate system 
+             */
+            for (y = rows - 1; y >= 0; y--) {
+                G_percent(percentage, (rows * depths - 1), 10);
+                percentage++;
+
+                for (x = 0; x < cols; x++) {
+                    value =
+                        get_g3d_raster_value_as_double(map, x, y, z,
+                                                       typeIntern, nullvalue);
+                    fprintf(fp, "%.*f ", dp, value);
+                }
+                fprintf(fp, "\n");
+            }
+        } else {
+            for (y = 0; y < rows; y++) {
+                G_percent(percentage, (rows * depths - 1), 10);
+                percentage++;
+
+                for (x = 0; x < cols; x++) {
+                    value =
+                        get_g3d_raster_value_as_double(map, x, y, z,
+                                                       typeIntern, nullvalue);
+                    fprintf(fp, "%.*f ", dp, value);
+                }
+                fprintf(fp, "\n");
+            }
+        }
     }
 }
 
 
 /* ************************************************************************* */
 /* Write the VTK RGB Voxel Data ******************************************** */
+
 /* ************************************************************************* */
 void write_vtk_rgb_data(void *map_r, void *map_g, void *map_b,
-			FILE * fp, const char *varname,
-			G3D_Region region, int dp)
+                        FILE * fp, const char *varname,
+                        G3D_Region region, int dp)
 {
     double value = 0;
-    int x, y, z, status, k;
+    int x, y, z, percentage, k;
     int rows, cols, depths;
     int typeIntern[3];
     void *maprgb = NULL;
@@ -397,78 +401,51 @@ void write_vtk_rgb_data(void *map_r, void *map_g, void *map_b,
     typeIntern[1] = G3d_tileTypeMap(map_g);
     typeIntern[2] = G3d_tileTypeMap(map_b);
 
-    status = 0;
+    percentage = 0;
 
     /********************** WRITE RGB VOXEL DATA; CELL OR POINT ****************/
     fprintf(fp, "COLOR_SCALARS %s 3\n", varname);
 
-    for (z = 0; z < depths; z++) {	/*From the bottom to the top */
-	if (!param.structgrid->answer) {
-	    for (y = 0; y < rows; y++) {
-		G_percent(status, (rows * depths - 1), 10);
-		status++;
-
-		for (x = 0; x < cols; x++) {
-		    for (k = 0; k < 3; k++) {
-
-			if (k == 0)
-			    maprgb = map_r;
-			if (k == 1)
-			    maprgb = map_g;
-			if (k == 2)
-			    maprgb = map_b;
-
-			value =
-			    get_g3d_raster_value_as_double(maprgb, x, y, z,
-							   typeIntern[k],
-							   0.0);
-			/*Test of value range, the data should be 1 byte gray values */
-			if (value > 255 || value < 0) {
-			    G_warning(_("Wrong 3d raster map values! Values should in between 0 and 255!\n"));
-			    fprintf(fp, "0 ");
-			}
-			else {
-
-			    fprintf(fp, "%.*f ", dp, (value / 255));
-			}
-		    }
-		    fprintf(fp, "\n");
-		}
-	    }
-	}
-	else {
-	    for (y = rows - 1; y >= 0; y--) {	/*From south to the north */
-		G_percent(status, (rows * depths - 1), 10);
-		status++;
-
-		for (x = 0; x < cols; x++) {
-		    for (k = 0; k < 3; k++) {
-
-			if (k == 0)
-			    maprgb = map_r;
-			if (k == 1)
-			    maprgb = map_g;
-			if (k == 2)
-			    maprgb = map_b;
-
-			value =
-			    get_g3d_raster_value_as_double(maprgb, x, y, z,
-							   typeIntern[k],
-							   0.0);
-			/*Test of value range, the data should be 1 byte gray values */
-			if (value > 255 || value < 0) {
-			    G_warning(_("Wrong 3d raster map values! Values should in between 0 and 255!\n"));
-			    fprintf(fp, "0 ");
-			}
-			else {
-
-			    fprintf(fp, "%.*f ", dp, (value / 255));
-			}
-		    }
-		    fprintf(fp, "\n");
-		}
-	    }
-	}
+    for (z = 0; z < depths; z++) {
+        for (y = 0; y < rows; y++) {
+            G_percent(percentage, (rows * depths - 1), 10);
+            percentage++;
+
+            for (x = 0; x < cols; x++) {
+                for (k = 0; k < 3; k++) {
+
+                    if (k == 0)
+                        maprgb = map_r;
+                    if (k == 1)
+                        maprgb = map_g;
+                    if (k == 2)
+                        maprgb = map_b;
+
+                    /* In case of structured grid data, the point/cell coordinates
+                       are computed based on the north->south raster coordinate system 
+                     */
+                    if (param.structgrid->answer)
+                        value =
+                        get_g3d_raster_value_as_double(maprgb, x, rows - y - 1, z,
+                                                       typeIntern[k],
+                                                       0.0);
+                    else
+                        value =
+                        get_g3d_raster_value_as_double(maprgb, x, y, z,
+                                                       typeIntern[k],
+                                                       0.0);
+                    /*Test of value range, the data should be 1 byte gray values */
+                    if (value > 255 || value < 0) {
+                        G_warning(_("Wrong 3d raster map values! Values should in between 0 and 255!\n"));
+                        fprintf(fp, "0 ");
+                    } else {
+
+                        fprintf(fp, "%.*f ", dp, (value / 255));
+                    }
+                }
+                fprintf(fp, "\n");
+            }
+        }
     }
     return;
 }
@@ -476,13 +453,14 @@ void write_vtk_rgb_data(void *map_r, void *map_g, void *map_b,
 
 /* ************************************************************************* */
 /* Write the VTK vector Data *********************************************** */
+
 /* ************************************************************************* */
 void write_vtk_vector_data(void *map_x, void *map_y, void *map_z,
-			   FILE * fp, const char *varname,
-			   G3D_Region region, int dp)
+                           FILE * fp, const char *varname,
+                           G3D_Region region, int dp)
 {
     double value = 0;
-    int x, y, z, status, k;
+    int x, y, z, percentage, k;
     int rows, cols, depths;
     int typeIntern[3];
     void *mapvect = NULL;
@@ -497,62 +475,44 @@ void write_vtk_vector_data(void *map_x, void *map_y, void *map_z,
     typeIntern[1] = G3d_tileTypeMap(map_y);
     typeIntern[2] = G3d_tileTypeMap(map_z);
 
-    status = 0;
+    percentage = 0;
 
     /********************** WRITE VECTOR DATA; CELL OR POINT ****************/
     fprintf(fp, "VECTORS %s float\n", varname);
 
-    for (z = 0; z < depths; z++) {	/*From the bottom to the top */
-	if (!param.structgrid->answer) {
-	    for (y = 0; y < rows; y++) {
-		G_percent(status, (rows * depths - 1), 10);
-		status++;
-
-		for (x = 0; x < cols; x++) {
-		    for (k = 0; k < 3; k++) {
-
-			if (k == 0)
-			    mapvect = map_x;
-			if (k == 1)
-			    mapvect = map_y;
-			if (k == 2)
-			    mapvect = map_z;
-
-			value =
-			    get_g3d_raster_value_as_double(mapvect, x, y, z,
-							   typeIntern[k],
-							   0.0);
-			fprintf(fp, "%.*f ", dp, value);
-		    }
-		    fprintf(fp, "\n");
-		}
-	    }
-	}
-	else {
-	    for (y = rows - 1; y >= 0; y--) {	/*From south to the north */
-		G_percent(status, (rows * depths - 1), 10);
-		status++;
-
-		for (x = 0; x < cols; x++) {
-		    for (k = 0; k < 3; k++) {
-
-			if (k == 0)
-			    mapvect = map_x;
-			if (k == 1)
-			    mapvect = map_y;
-			if (k == 2)
-			    mapvect = map_z;
-
-			value =
-			    get_g3d_raster_value_as_double(mapvect, x, y, z,
-							   typeIntern[k],
-							   0.0);
-			fprintf(fp, "%.*f ", dp, value);
-		    }
-		    fprintf(fp, "\n");
-		}
-	    }
-	}
+    for (z = 0; z < depths; z++) { /*From the bottom to the top */
+        for (y = 0; y < rows; y++) {
+            G_percent(percentage, (rows * depths - 1), 10);
+            percentage++;
+
+            for (x = 0; x < cols; x++) {
+                for (k = 0; k < 3; k++) {
+
+                    if (k == 0)
+                        mapvect = map_x;
+                    if (k == 1)
+                        mapvect = map_y;
+                    if (k == 2)
+                        mapvect = map_z;
+
+                    /* In case of structured grid data, the point/cell coordinates
+                       are computed based on the north->south raster coordinate system 
+                     */
+                    if (param.structgrid->answer)
+                        value =
+                        get_g3d_raster_value_as_double(mapvect, x, rows - y - 1, z,
+                                                       typeIntern[k],
+                                                       0.0);
+                    else
+                        value =
+                        get_g3d_raster_value_as_double(mapvect, x, y, z,
+                                                       typeIntern[k],
+                                                       0.0);
+                    fprintf(fp, "%.*f ", dp, value);
+                }
+                fprintf(fp, "\n");
+            }
+        }
     }
     return;
 }

+ 56 - 54
raster3d/r3.out.vtk/writeVTKHead.c

@@ -1,20 +1,20 @@
 
 /****************************************************************************
-*
-* MODULE:       r3.out.vtk  
-*   	    	
-* AUTHOR(S):    Original author 
-*               Soeren Gebbert soerengebbert at gmx de
-* 		27 Feb 2006 Berlin
-* PURPOSE:      Converts 3D raster maps (G3D) into the VTK-Ascii format  
-*
-* COPYRIGHT:    (C) 2005 by the GRASS Development Team
-*
-*               This program is free software under the GNU General Public
-*   	    	License (>=v2). Read the file COPYING that comes with GRASS
-*   	    	for details.
-*
-*****************************************************************************/
+ *
+ * MODULE:       r3.out.vtk  
+ *   	    	
+ * AUTHOR(S):    Original author 
+ *               Soeren Gebbert soerengebbert at gmx de
+ * 		27 Feb 2006 Berlin
+ * PURPOSE:      Converts 3D raster maps (G3D) into the VTK-Ascii format  
+ *
+ * COPYRIGHT:    (C) 2005 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *   	    	License (>=v2). Read the file COPYING that comes with GRASS
+ *   	    	for details.
+ *
+ *****************************************************************************/
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -29,57 +29,57 @@
 
 
 /* ************************************************************************* */
-/* Writes the strcutured points Header ************************************* */
+/* Writes the structured points Header ************************************* */
+
 /* ************************************************************************* */
 void write_vtk_structured_point_header(FILE * fp, char *vtkFile,
-				       G3D_Region region, int dp,
-				       double scale)
+                                       G3D_Region region, int dp,
+                                       double scale)
 {
     G_debug(3,
-	    _("write_vtk_structured_point_header: Writing VTKStructuredPoint-Header"));
+            _("write_vtk_structured_point_header: Writing VTKStructuredPoint-Header"));
 
     /*Simple vtk ASCII header */
 
     fprintf(fp, "# vtk DataFile Version 3.0\n");
     fprintf(fp, "GRASS GIS 7 Export\n");
     fprintf(fp, "ASCII\n");
-    fprintf(fp, "DATASET STRUCTURED_POINTS\n");	/*We are using the structured point dataset. */
+    fprintf(fp, "DATASET STRUCTURED_POINTS\n"); /*We are using the structured point dataset. */
 
     if (param.point->answer)
-	fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows,
-		region.depths);
+        fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows,
+                region.depths);
     else
-	fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols + 1, region.rows + 1,
-		region.depths + 1);
+        fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols + 1, region.rows + 1,
+                region.depths + 1);
 
     fprintf(fp, "SPACING %.*f %.*f %.*f\n", dp, region.ew_res, dp,
-	    region.ns_res, dp, (region.tb_res * scale));
+            region.ns_res, dp, (region.tb_res * scale));
 
     if (param.point->answer) {
-	if (param.origin->answer)
-	    fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp,
-		    (region.west + region.ew_res / 2) - x_extent, dp,
-		    (region.south + region.ns_res / 2) - y_extent, dp,
-		    region.bottom * scale + (region.tb_res * scale) / 2);
-	else
-	    fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp,
-		    (region.west + region.ew_res / 2) - x_extent, dp,
-		    (region.south + region.ns_res / 2) - y_extent, dp,
-		    region.bottom + (region.tb_res * scale) / 2);
-    }
-    else {
-	if (param.origin->answer)
-	    fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
-		    dp, region.south - y_extent, dp, region.bottom * scale);
-	else
-	    fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
-		    dp, region.south - y_extent, dp, region.bottom);
+        if (param.origin->answer)
+            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp,
+                    (region.west + region.ew_res / 2) - x_extent, dp,
+                    (region.south + region.ns_res / 2) - y_extent, dp,
+                    region.bottom * scale + (region.tb_res * scale) / 2);
+        else
+            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp,
+                    (region.west + region.ew_res / 2) - x_extent, dp,
+                    (region.south + region.ns_res / 2) - y_extent, dp,
+                    region.bottom + (region.tb_res * scale) / 2);
+    } else {
+        if (param.origin->answer)
+            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
+                    dp, region.south - y_extent, dp, region.bottom * scale);
+        else
+            fprintf(fp, "ORIGIN %.*f %.*f %.*f\n", dp, region.west - x_extent,
+                    dp, region.south - y_extent, dp, region.bottom);
     }
 
     if (param.point->answer)
-	fprintf(fp, "POINT_DATA %i\n", region.cols * region.rows * region.depths);	/*We have pointdata */
+        fprintf(fp, "POINT_DATA %i\n", region.cols * region.rows * region.depths); /*We have pointdata */
     else
-	fprintf(fp, "CELL_DATA %i\n", region.cols * region.rows * region.depths);	/*We have celldata */
+        fprintf(fp, "CELL_DATA %i\n", region.cols * region.rows * region.depths); /*We have celldata */
 
     return;
 }
@@ -87,39 +87,41 @@ void write_vtk_structured_point_header(FILE * fp, char *vtkFile,
 
 /* ************************************************************************* */
 /* Writes the strcutured grid header **************************************** */
+
 /* ************************************************************************* */
 void write_vtk_structured_grid_header(FILE * fp, char *vtkFile,
-				      G3D_Region region)
+                                      G3D_Region region)
 {
     G_debug(3,
-	    _("write_vtk_structured_grid_header: Writing VTKStructuredGrid-Header"));
+            _("write_vtk_structured_grid_header: Writing VTKStructuredGrid-Header"));
     fprintf(fp, "# vtk DataFile Version 3.0\n");
     fprintf(fp, "GRASS GIS 7 Export\n");
     fprintf(fp, "ASCII\n");
-    fprintf(fp, "DATASET STRUCTURED_GRID\n");	/*We are using the structured grid dataset. */
+    fprintf(fp, "DATASET STRUCTURED_GRID\n"); /*We are using the structured grid dataset. */
     fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows,
-	    region.depths);
+            region.depths);
     /*Only point data is available */
     fprintf(fp, "POINTS %i float\n",
-	    region.cols * region.rows * region.depths);
+            region.cols * region.rows * region.depths);
 
     return;
 }
 
 /* ************************************************************************* */
 /* Writes the unstrcutured grid header ************************************* */
+
 /* ************************************************************************* */
 void write_vtk_unstructured_grid_header(FILE * fp, char *vtkFile,
-					G3D_Region region)
+                                        G3D_Region region)
 {
     G_debug(3,
-	    _("write_vtk_unstructured_grid_header: Writing VTKUnstructuredGrid-Header"));
+            _("write_vtk_unstructured_grid_header: Writing VTKUnstructuredGrid-Header"));
     fprintf(fp, "# vtk DataFile Version 3.0\n");
     fprintf(fp, "GRASS GIS 7 Export\n");
     fprintf(fp, "ASCII\n");
-    fprintf(fp, "DATASET UNSTRUCTURED_GRID\n");	/*We are using the unstructured grid dataset. */
+    fprintf(fp, "DATASET UNSTRUCTURED_GRID\n"); /*We are using the unstructured grid dataset. */
     /*Only cell data is available, because we creating a hexaeder/vtk-voxel for every voxel */
-    fprintf(fp, "POINTS %i float\n", region.cols * region.rows * region.depths * 8);	/*a Voxel has 8 points */
+    fprintf(fp, "POINTS %i float\n", region.cols * region.rows * region.depths * 8); /*a Voxel has 8 points */
 
     return;
 }