[cig-commits] r21399 - seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu
elliott.sales.de.andrade at geodynamics.org
elliott.sales.de.andrade at geodynamics.org
Mon Feb 25 23:37:37 PST 2013
Author: elliott.sales.de.andrade
Date: 2013-02-25 23:37:37 -0800 (Mon, 25 Feb 2013)
New Revision: 21399
Removed:
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/cell2vtu.pl
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/mesh2vtu.pl
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/points2vtu.pl
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/surf2vtu.pl
Modified:
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/Makefile
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/cell2vtu.cxx
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/mesh2vtu.cxx
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/surf2vtu.cxx
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/ugrid.cxx
seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/ugrid_pts.cxx
Log:
Simplify mesh2vtu code.
Remove Perl wrappers, as you can just use getopt directly within the C
code instead. Stop allocating arrays for values that are used
immediately and never again.
Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/Makefile
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/Makefile 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/Makefile 2013-02-26 07:37:37 UTC (rev 21399)
@@ -18,7 +18,7 @@
VTK_LDFLAGS := -L$(VTK)/lib64/vtk -L$(VTK)/lib/vtk -lvtkCommon -lvtkIO -lvtkFiltering -lvtkGraphics
endif
-CPPFLAGS = -O3 $(VTK_CPPFLAGS) -Wno-deprecated
+CPPFLAGS = -O3 $(VTK_CPPFLAGS) -Wall -Wno-deprecated
LIBS = $(VTK_LDFLAGS)
#############################################################
Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/cell2vtu.cxx
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/cell2vtu.cxx 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/cell2vtu.cxx 2013-02-26 07:37:37 UTC (rev 21399)
@@ -49,56 +49,106 @@
#include <vtk/vtkPointSet.h>
#include <vtk/vtkHexahedron.h>
+void usage(char *progname)
+{
+ printf("Usage: %s -i input-file -o output-file\n"
+ " Takes an input file (binary) with a number of points and a number of cells\n"
+ " and transforms them into an unstructured grid file\n"
+ "\n"
+ " -i input-file (Binary file)\n"
+ " -o output-file (XML Unstructured Grid File)\n"
+ "\n"
+ " Input Binary files have this structure:\n"
+ " number_of_points integer (4 bytes)\n"
+ " x_1, y_1, z_1 3 reals (4 bytes each)\n"
+ " ...\n"
+ " x_n, y_n, z_n 3 reals (4 bytes each)\n"
+ " number_of_cells integer (4 bytes)\n"
+ " cell_1 (eight points), scalar_1 8 integers (4 bytes each), 1 real (4 bytes)\n"
+ " ...\n"
+ " cell_n, scalar_n 8 integers (4 bytes each), 1 real (4 bytes)\n"
+ "\n", progname);
+}
-int main(int argc, char** argv) {
+bool parse_args(int argc, char **argv, char **input, char **output)
+{
+ int c;
- if (argc < 3) {
- printf("Usage: cell2vtu input_file output_file\n");
- return 0;
+ *input = *output = NULL;
+
+ while ( (c = getopt(argc, argv, "i:o:")) != -1) {
+ switch (c) {
+ case 'i':
+ *input = optarg;
+ break;
+ case 'o':
+ *output = optarg;
+ break;
+ case '?':
+ usage(argv[0]);
+ return false;
+ default:
+ printf("?? getopt returned character code 0%o ??\n", c);
+ return false;
+ }
}
+ if (*input == NULL) {
+ printf("ERROR: Must specify input file -i input-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ if (*output == NULL) {
+ printf("ERROR: Must specify output file -o output-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ return true;
+}
+
+int main(int argc, char** argv) {
+ char *input, *output;
float xyz[3];
+ float scalar;
int cell[8];
- FILE *file;
int i, j;
int npts, ncells;
- int pid[8];
-
int fd;
- if((fd = open(argv[1], O_RDONLY)) == -1) {
- printf("Error opening file: %s.\n", argv[1]);
- return 0;
+ if (!parse_args(argc, argv, &input, &output)) {
+ return 1;
}
+ if ((fd = open(input, O_RDONLY)) == -1) {
+ printf("Error opening file: %s.\n", input);
+ return 1;
+ }
+
if(read(fd, &npts, sizeof(int)) != sizeof(int)) {
- printf("Bad read on file (in points): %s\n", argv[1]);
+ printf("Bad read on file (in points): %s\n", input);
+ return 1;
}
vtkUnstructuredGrid *dataSet = vtkUnstructuredGrid::New();
- float *xV = new float[npts];
- float *yV = new float[npts];
- float *zV = new float[npts];
vtkPoints *newPts = vtkPoints::New();
vtkFloatArray *newScalars = vtkFloatArray::New();
printf("cell2vtu: Reading in points: %d\n", npts);
for (i = 0 ; i < npts ; i++)
{
- read(fd, &xV[i], sizeof(float));
- read(fd, &yV[i], sizeof(float));
- read(fd, &zV[i], sizeof(float));
- xyz[0] = xV[i];
- xyz[1] = yV[i];
- xyz[2] = zV[i];
+ read(fd, &xyz[0], sizeof(float));
+ read(fd, &xyz[1], sizeof(float));
+ read(fd, &xyz[2], sizeof(float));
newPts -> InsertPoint(i, xyz);
}
vtkCellArray *cells = vtkCellArray::New();
if(read(fd, &ncells, sizeof(int)) != sizeof(int)) {
- printf("Bad read on file (in cells): %s\n", argv[1]);
+ printf("Bad read on file (in cells): %s\n", input);
+ return 1;
}
printf("cell2vtu: Reading in cells: %d\n", ncells);
- float *sV = new float[ncells];
int *cellTypes = new int[ncells];
vtkHexahedron *hex = vtkHexahedron::New();
@@ -111,8 +161,8 @@
}
cells->InsertNextCell(hex);
cellTypes[i] = hex->GetCellType();
- read(fd, &sV[i], sizeof(float));
- newScalars -> InsertValue(i, sV[i]);
+ read(fd, &scalar, sizeof(float));
+ newScalars -> InsertValue(i, scalar);
}
close(fd);
@@ -123,7 +173,7 @@
vtkXMLUnstructuredGridWriter* writer = vtkXMLUnstructuredGridWriter::New();
writer -> SetInput(dataSet);
- writer -> SetFileName(argv[2]);
+ writer -> SetFileName(output);
writer -> Write();
writer -> Delete();
Deleted: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/cell2vtu.pl
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/cell2vtu.pl 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/cell2vtu.pl 2013-02-26 07:37:37 UTC (rev 21399)
@@ -1,50 +0,0 @@
-#!/usr/bin/perl
-
-use Getopt::Std;
-use FindBin;
-
-$cell2vtu = "$FindBin::Bin/cell2vtu";
-
-sub Usage {
- print STDERR <<END;
-Usage: $0 -i input-file -o output-file
- Takes an input file (binary) with a number of points and a number of cells
- and transforms them into an unstructured grid file
-
- -i input-file (Binary file)
- -o output-file (XML Unstructured Grid File)
-
- Input Binary files have this structure:
- number_of_points integer (4 bytes)
- x_1, y_1, z_1 3 reals (4 bytes each)
- ...
- x_n, y_n, z_n 3 reals (4 bytes each)
- number_of_cells integer (4 bytes)
- cell_1 (eight points), scalar_1 8 integers (4 bytes each), 1 real (4 bytes)
- ...
- cell_n, scalar_n 8 integers (4 bytes each), 1 real (4 bytes)
-
- This is a wrapper around cell2vtu
-
- Brian Savage 6/26/2004
-
-END
- exit(-1);
-}
-
-if(@ARGV == 0) {
- Usage ();
-}
-
-if(!getopts('i:o:')){die "Check input paramaters \n";}
-
-if(!defined($opt_i)) {
- die "$0: Must specify input file -i input-file\n";
-}
-if(!defined($opt_o)) {
- die "$0: Must specify output file -o output-file\n";
-}
-#print "$cell2vtu $opt_i $opt_o\n";
-system("$cell2vtu $opt_i $opt_o");
-
-1;
Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/mesh2vtu.cxx
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/mesh2vtu.cxx 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/mesh2vtu.cxx 2013-02-26 07:37:37 UTC (rev 21399)
@@ -51,31 +51,86 @@
#include <vtk/vtkPointSet.h>
#include <vtk/vtkHexahedron.h>
+void usage(char *progname)
+{
+ printf("Usage: %s -i input-file -o output-file\n"
+ " Takes an input file (binary) with a number of points and a number of cells\n"
+ " and transforms them into an unstructured grid file\n"
+ "\n"
+ " -i input-file (Binary file)\n"
+ " -o output-file (XML Unstructured Grid File)\n"
+ "\n"
+ " Input Binary files have this structure:\n"
+ " number_of_points integer (4 bytes)\n"
+ " x_1, y_1, z_1, scalar_1 4 reals (4 bytes each)\n"
+ " ...\n"
+ " x_n, y_n, z_n, scalar_n 4 reals (4 bytes each)\n"
+ " number_of_cells integer (4 bytes)\n"
+ " cell_1 (eight points) 8 integers (4 bytes each)\n"
+ " ...\n"
+ " cell_n 8 integers (4 bytes each)\n"
+ "\n", progname);
+}
-int main(int argc, char** argv) {
+bool parse_args(int argc, char **argv, char **input, char **output)
+{
+ int c;
- if (argc < 3) {
- printf("Usage: mesh2vtu input_file output_file\n");
- return 0;
+ *input = *output = NULL;
+
+ while ( (c = getopt(argc, argv, "i:o:")) != -1) {
+ switch (c) {
+ case 'i':
+ *input = optarg;
+ break;
+ case 'o':
+ *output = optarg;
+ break;
+ case '?':
+ usage(argv[0]);
+ return false;
+ default:
+ printf("?? getopt returned character code 0%o ??\n", c);
+ return false;
+ }
}
+ if (*input == NULL) {
+ printf("ERROR: Must specify input file -i input-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ if (*output == NULL) {
+ printf("ERROR: Must specify output file -o output-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ return true;
+}
+
+int main(int argc, char** argv) {
+ char *input, *output;
float xyz[3];
float scalar;
int cell[8];
- FILE *file;
int i, j;
int npts, ncells;
- int pid[8];
-
int fd;
- if((fd = open(argv[1], O_RDONLY)) == -1) {
- printf("Error opening file: %s.\n", argv[1]);
- return 0;
+ if (!parse_args(argc, argv, &input, &output)) {
+ return 1;
}
+ if ((fd = open(input, O_RDONLY)) == -1) {
+ printf("Error opening file: %s.\n", input);
+ return 1;
+ }
+
if(read(fd, &npts, sizeof(int)) != sizeof(int)) {
- printf("Bad read on file (in points): %s\n", argv[1]);
+ printf("Bad read on file (in points): %s\n", input);
+ return 1;
}
printf("mesh2vtu: Reading in points: %d\n", npts);
@@ -95,7 +150,8 @@
vtkCellArray *cells = vtkCellArray::New();
if(read(fd, &ncells, sizeof(int)) != sizeof(int)) {
- printf("Bad read on file (in cells): %s\n", argv[1]);
+ printf("Bad read on file (in cells): %s\n", input);
+ return 1;
}
printf("mesh2vtu: Reading in cells: %d\n", ncells);
@@ -130,7 +186,7 @@
vtkXMLUnstructuredGridWriter* writer = vtkXMLUnstructuredGridWriter::New();
writer -> SetInput(dataSet);
- writer -> SetFileName(argv[2]);
+ writer -> SetFileName(output);
writer -> Write();
writer -> Delete();
Deleted: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/mesh2vtu.pl
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/mesh2vtu.pl 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/mesh2vtu.pl 2013-02-26 07:37:37 UTC (rev 21399)
@@ -1,50 +0,0 @@
-#!/usr/bin/perl
-
-use Getopt::Std;
-use FindBin;
-
-$mesh2vtu = "$FindBin::Bin/mesh2vtu";
-
-sub Usage {
- print STDERR <<END;
-Usage: $0 -i input-file -o output-file
- Takes an input file (binary) with a number of points and a number of cells
- and transforms them into an unstructured grid file
-
- -i input-file (Binary file)
- -o output-file (XML Unstructured Grid File)
-
- Input Binary files have this structure:
- number_of_points integer (4 bytes)
- x_1, y_1, z_1, scalar_1 4 reals (4 bytes each)
- ...
- x_n, y_n, z_n, scalar_n 4 reals (4 bytes each)
- number_of_cells integer (4 bytes)
- cell_1 (eight points) 8 integers (4 bytes each)
- ...
- cell_n 8 integers (4 bytes each)
-
- This is a wrapper around mesh2vtu
-
- Brian Savage 6/26/2004
-
-END
- exit(-1);
-}
-
-if(@ARGV == 0) {
- Usage ();
-}
-
-if(!getopts('i:o:')){die "Check input paramaters \n";}
-
-if(!defined($opt_i)) {
- die "$0: Must specify input file -i input-file\n";
-}
-if(!defined($opt_o)) {
- die "$0: Must specify output file -o output-file\n";
-}
-#print "$mesh2vtu $opt_i $opt_o\n";
-system("$mesh2vtu $opt_i $opt_o");
-
-1;
Deleted: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/points2vtu.pl
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/points2vtu.pl 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/points2vtu.pl 2013-02-26 07:37:37 UTC (rev 21399)
@@ -1,84 +0,0 @@
-#!/usr/bin/perl
-
-use Getopt::Std;
-use FindBin;
-use POSIX;
-
-$ugrid = "$FindBin::Bin/ugrid_pts";
-
-sub Usage {
- print STDERR <<END;
-Usage: $0 -i input-file -o output-file
- Takes an input file (ascii) with a number of points
- and transforms them into an unstructured grid file
-
- -i input-file (ascii file)
- -o output-file (XML Unstructured Grid File)
- -L - input is in lon lat depth scalar
-
- Input ascii files have this structure:
- number_of_points
- x_1 y_1 z_1 scalar_1
- ...
- x_n y_n z_n scalar_n
-
- This is a wrapper around ugrid_pts
-
- Brian Savage 6/26/2004
-
-END
- exit(-1);
-}
-
-if(@ARGV == 0) {
- Usage ();
-}
-
-if(!getopts('i:o:L')){die "Check input paramaters \n";}
-
-if(!defined($opt_i)) {
- die "$0: Must specify input file -i input-file\n";
-}
-if(!defined($opt_o)) {
- die "$0: Must specify output file -o output-file\n";
-}
-#print "$ugrid $opt_i $opt_o\n";
-if($opt_L){
- open(FILE, "$opt_i");
- @lines = <FILE>;
- close(FILE);
- print "Converting to xyzm\n";
- open(OUT,">points2vtu.tempfile");
- # print @lines . "\n";
- print OUT "@lines[0]";
- foreach $line (@lines[1..$#lines]) {
- ($lon,$lat,$depth,$mag) = split(/\s+/,$line);
- @pt = lat_lon_depth_2_xyz($lat, $lon, $depth);
- print OUT "@pt $mag\n";
- }
- print "Running ugrid\n";
- system("$ugrid points2vtu.tempfile $opt_o");
-}
-else{
- system("$ugrid $opt_i $opt_o");
-}
-
-1;
-sub lat_lon_depth_2_xyz {
- my($lat, $lon, $depth) = @_;
- my($PI, $D2R, $theta, $phi, $r0, $r, $x, $y, $z);
-
- $R_EARTH_KM = 6371.0;
- $PI = 3.141592653589793;
- $D2R = $PI/180.0;
-
- $theta = ($PI/2.0) - atan(0.99329534*tan($lat*$D2R));
- $phi = $lon * $D2R;
- $r0 = 1.0;
-
- $r = ($R_EARTH_KM - $depth) / $R_EARTH_KM;
- $x = $r * sin($theta) * cos($phi);
- $y = $r * sin($theta) * sin($phi);
- $z = $r * cos($theta);
- return($x, $y, $z);
-}
Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/surf2vtu.cxx
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/surf2vtu.cxx 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/surf2vtu.cxx 2013-02-26 07:37:37 UTC (rev 21399)
@@ -22,7 +22,7 @@
// integer number of quad cells
// 4 integers (1-4) cell 0
// ... define a hexahedron of 8 points
-// 4 integers (1-8) cell n-1
+// 4 integers (1-4) cell n-1
//
// Date: 4 June 2004 ver 1.0 (was ugrid)
// - original version, only read in x,y,z,s points
@@ -30,7 +30,7 @@
// - reads in cell definition
// - input is done in binary
// 29 Sep 2005 modified to quad2vtu
-// - to deal with quad elements instead of Hexhedron
+// - to deal with quad elements instead of Hexahedron
//
//-----------------------------------------------------------------------------
@@ -53,59 +53,109 @@
#include <vtk/vtkPointSet.h>
#include <vtk/vtkQuad.h>
+void usage(char *progname)
+{
+ printf("Usage: %s -i input-file -o output-file\n"
+ " Takes an input file (binary) with a number of points and a number of cells\n"
+ " and transforms them into an unstructured grid file\n"
+ "\n"
+ " -i input-file (Binary file)\n"
+ " -o output-file (XML Unstructured Grid File)\n"
+ "\n"
+ " Input Binary files have this structure:\n"
+ " number_of_points integer (4 bytes)\n"
+ " x_1, y_1, z_1, scalar_1 4 reals (4 bytes each)\n"
+ " ...\n"
+ " x_n, y_n, z_n, scalar_n 4 reals (4 bytes each)\n"
+ " number_of_cells integer (4 bytes)\n"
+ " cell_1 (four points) 4 integers (4 bytes each)\n"
+ " ...\n"
+ " cell_n 4 integers (4 bytes each)\n"
+ "\n", progname);
+}
-int main(int argc, char** argv) {
+bool parse_args(int argc, char **argv, char **input, char **output)
+{
+ int c;
- if (argc < 3) {
- printf("Usage: surf2vtu input_file output_file\n");
- return 0;
+ *input = *output = NULL;
+
+ while ( (c = getopt(argc, argv, "i:o:")) != -1) {
+ switch (c) {
+ case 'i':
+ *input = optarg;
+ break;
+ case 'o':
+ *output = optarg;
+ break;
+ case '?':
+ usage(argv[0]);
+ return false;
+ default:
+ printf("?? getopt returned character code 0%o ??\n", c);
+ return false;
+ }
}
+ if (*input == NULL) {
+ printf("ERROR: Must specify input file -i input-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ if (*output == NULL) {
+ printf("ERROR: Must specify output file -o output-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ return true;
+}
+
+int main(int argc, char** argv) {
+ char *input, *output;
float xyz[3];
+ float scalar;
int cell[8];
- FILE *file;
int i, j;
int npts, ncells;
- int pid[8];
-
int fd;
- if((fd = open(argv[1], O_RDONLY)) == -1) {
- printf("Error opening file: %s.\n", argv[1]);
- return 0;
+ if (!parse_args(argc, argv, &input, &output)) {
+ return 1;
}
+ if ((fd = open(input, O_RDONLY)) == -1) {
+ printf("Error opening file: %s.\n", input);
+ return 1;
+ }
+
if(read(fd, &npts, sizeof(int)) != sizeof(int)) {
- printf("Bad read on file (in points): %s\n", argv[1]);
+ printf("Bad read on file (in points): %s\n", input);
+ return 1;
}
vtkUnstructuredGrid *dataSet = vtkUnstructuredGrid::New();
- float *xV = new float[npts];
- float *yV = new float[npts];
- float *zV = new float[npts];
- float *sV = new float[npts];
vtkPoints *newPts = vtkPoints::New();
vtkFloatArray *newScalars = vtkFloatArray::New();
- printf("mesh2vtu: Reading in points: %d\n", npts);
+ printf("surf2vtu: Reading in points: %d\n", npts);
for (i = 0 ; i < npts ; i++)
{
- read(fd, &xV[i], sizeof(float));
- read(fd, &yV[i], sizeof(float));
- read(fd, &zV[i], sizeof(float));
- read(fd, &sV[i], sizeof(float));
- xyz[0] = xV[i];
- xyz[1] = yV[i];
- xyz[2] = zV[i];
+ read(fd, &xyz[0], sizeof(float));
+ read(fd, &xyz[1], sizeof(float));
+ read(fd, &xyz[2], sizeof(float));
+ read(fd, &scalar, sizeof(float));
newPts -> InsertPoint(i, xyz);
- newScalars -> InsertValue(i, sV[i]);
+ newScalars -> InsertValue(i, scalar);
}
vtkCellArray *cells = vtkCellArray::New();
if(read(fd, &ncells, sizeof(int)) != sizeof(int)) {
- printf("Bad read on file (in cells): %s\n", argv[1]);
+ printf("Bad read on file (in cells): %s\n", input);
+ return 1;
}
- printf("mesh2vtu: Reading in cells: %d\n", ncells);
+ printf("surf2vtu: Reading in cells: %d\n", ncells);
int *cellTypes = new int[ncells];
vtkQuad *quad = vtkQuad::New();
quad->GetPointIds()->SetNumberOfIds(4);
@@ -127,7 +177,7 @@
vtkXMLUnstructuredGridWriter* writer = vtkXMLUnstructuredGridWriter::New();
writer -> SetInput(dataSet);
- writer -> SetFileName(argv[2]);
+ writer -> SetFileName(output);
writer -> Write();
writer -> Delete();
@@ -136,7 +186,7 @@
dataSet -> Delete();
cells -> Delete();
- // printf("Done.\n");
+ printf("Done.\n");
return 0;
Deleted: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/surf2vtu.pl
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/surf2vtu.pl 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/surf2vtu.pl 2013-02-26 07:37:37 UTC (rev 21399)
@@ -1,51 +0,0 @@
-#!/usr/bin/perl
-
-use Getopt::Std;
-use FindBin;
-
-$surf2vtu = "$FindBin::Bin/surf2vtu";
-
-sub Usage {
- print STDERR <<END;
-Usage: $0 -i input-file -o output-file
- Takes an input file (binary) with a number of points and a number of cells
- and transforms them into an unstructured grid file
-
- -i input-file (Binary file)
- -o output-file (XML Unstructured Grid File)
-
- Input Binary files have this structure:
- number_of_points integer (4 bytes)
- x_1, y_1, z_1, scalar_1 4 reals (4 bytes each)
- ...
- x_n, y_n, z_n, scalar_n 4 reals (4 bytes each)
- number_of_cells integer (4 bytes)
- cell_1 (four points) 4 integers (4 bytes each)
- ...
- cell_n 4 integers (4 bytes each)
-
- This is a wrapper around surf2vtu
-
- Brian Savage 6/26/2004
- Qinya Liu 9/29/2005 modified to deal with quad elements
-
-END
- exit(-1);
-}
-
-if(@ARGV == 0) {
- Usage ();
-}
-
-if(!getopts('i:o:')){die "Check input paramaters \n";}
-
-if(!defined($opt_i)) {
- die "$0: Must specify input file -i input-file\n";
-}
-if(!defined($opt_o)) {
- die "$0: Must specify output file -o output-file\n";
-}
-#print "$surf2vtu $opt_i $opt_o\n";
-system("$surf2vtu $opt_i $opt_o");
-
-1;
Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/ugrid.cxx
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/ugrid.cxx 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/ugrid.cxx 2013-02-26 07:37:37 UTC (rev 21399)
@@ -9,6 +9,7 @@
//-----------------------------------------------------------------------------
#include <stdio.h>
+#include <unistd.h>
#include <vtk/vtkHexahedron.h>
#include <vtk/vtkCellArray.h>
#include <vtk/vtkFloatArray.h>
@@ -17,54 +18,102 @@
#include <vtk/vtkUnstructuredGrid.h>
#include <vtk/vtkXMLUnstructuredGridWriter.h>
-int main(int argc, char** argv) {
+void usage(char *progname)
+{
+ printf("Usage: %s -i input-file -o output-file\n"
+ " Takes an input file (ascii) with a number of points\n"
+ " and transforms them into an unstructured grid file\n"
+ "\n"
+ " -i input-file (ascii file)\n"
+ " -o output-file (XML Unstructured Grid File)\n"
+ " -L - input is in lon lat depth scalar\n"
+ "\n"
+ " Input ascii files have this structure:\n"
+ " number_of_points\n"
+ " x_1 y_1 z_1 scalar_1\n"
+ " ...\n"
+ " x_n y_n z_n scalar_n\n"
+ "\n", progname);
+}
- if (argc < 3) {
- printf("Usage: ugrid input_file output_file\n");
- return 0;
+bool parse_args(int argc, char **argv, char **input, char **output)
+{
+ int c;
+
+ *input = *output = NULL;
+
+ while ( (c = getopt(argc, argv, "i:o:L")) != -1) {
+ switch (c) {
+ case 'i':
+ *input = optarg;
+ break;
+ case 'o':
+ *output = optarg;
+ break;
+ case '?':
+ usage(argv[0]);
+ return false;
+ default:
+ printf("?? getopt returned character code 0%o ??\n", c);
+ return false;
+ }
}
+ if (*input == NULL) {
+ printf("ERROR: Must specify input file -i input-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ if (*output == NULL) {
+ printf("ERROR: Must specify output file -o output-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ return true;
+}
+
+int main(int argc, char** argv) {
+ char *input, *output;
float xyz[3];
+ float scalar;
FILE *file;
int i;
int npts, ncells;
int pid[8];
+
+ if (!parse_args(argc, argv, &input, &output)) {
+ return 1;
+ }
+
fprintf(stderr,"Welcome to ugrid\n");
- if ((file = fopen(argv[1], "r")) == 0)
+ if ((file = fopen(input, "r")) == 0)
{
- //cerr << "ERROR: Can't read file: " << filename << "\n";
- return 0;
+ cerr << "ERROR: Can't read file: " << input << "\n";
+ return 1;
}
-
// get points
fscanf(file, "%d", &npts);
fprintf(stderr, "npts: %d\n", npts);
vtkUnstructuredGrid *dataSet = vtkUnstructuredGrid::New();
- float *xV = new float[npts];
- float *yV = new float[npts];
- float *zV = new float[npts];
- float *sV = new float[npts];
vtkPoints *newPts = vtkPoints::New();
vtkFloatArray *newScalars = vtkFloatArray::New();
for (i = 0 ; i < npts ; i++)
{
- fscanf(file, "%f", &xV[i]);
- fscanf(file, "%f", &yV[i]);
- fscanf(file, "%f", &zV[i]);
- fscanf(file, "%f", &sV[i]);
- fprintf(stderr, "%f %f %f %f\n", xV[i], yV[i], zV[i], sV[i]);
- xyz[0] = xV[i];
- xyz[1] = yV[i];
- xyz[2] = zV[i];
+ fscanf(file, "%f", &xyz[0]);
+ fscanf(file, "%f", &xyz[1]);
+ fscanf(file, "%f", &xyz[2]);
+ fscanf(file, "%f", &scalar);
+ fprintf(stderr, "%f %f %f %f\n", xyz[0], xyz[1], xyz[2], scalar);
newPts -> InsertPoint(i, xyz);
- newScalars -> InsertValue(i, sV[i]);
+ newScalars -> InsertValue(i, scalar);
}
-
// get cells
fscanf(file, "%d", &ncells);
@@ -90,17 +139,16 @@
dataSet -> SetPoints(newPts);
dataSet -> GetPointData() -> SetScalars(newScalars);
-
vtkXMLUnstructuredGridWriter* writer = vtkXMLUnstructuredGridWriter::New();
writer -> SetInput(dataSet);
- writer -> SetFileName(argv[2]);
+ writer -> SetFileName(output);
writer -> Write();
writer -> Delete();
newPts -> Delete();
newScalars -> Delete();
dataSet -> Delete();
-
+
return 0;
}
Modified: seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/ugrid_pts.cxx
===================================================================
--- seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/ugrid_pts.cxx 2013-02-26 07:37:31 UTC (rev 21398)
+++ seismo/3D/SPECFEM3D_GLOBE/trunk/utils/Visualization/VTK_ParaView/mesh2vtu/ugrid_pts.cxx 2013-02-26 07:37:37 UTC (rev 21399)
@@ -9,52 +9,131 @@
//-----------------------------------------------------------------------------
#include <stdio.h>
+#include <unistd.h>
#include <vtk/vtkFloatArray.h>
#include <vtk/vtkPoints.h>
#include <vtk/vtkPointData.h>
#include <vtk/vtkUnstructuredGrid.h>
#include <vtk/vtkXMLUnstructuredGridWriter.h>
-int main(int argc, char** argv) {
+void usage(char *progname)
+{
+ printf("Usage: %s -i input-file -o output-file\n"
+ " Takes an input file (ascii) with a number of points\n"
+ " and transforms them into an unstructured grid file\n"
+ "\n"
+ " -i input-file (ascii file)\n"
+ " -o output-file (XML Unstructured Grid File)\n"
+ " -L - input is in lon lat depth scalar\n"
+ "\n"
+ " Input ascii files have this structure:\n"
+ " number_of_points\n"
+ " x_1 y_1 z_1 scalar_1\n"
+ " ...\n"
+ " x_n y_n z_n scalar_n\n"
+ "\n", progname);
+}
- if (argc < 3) {
- printf("Usage: ugrid_pts input_file output_file\n");
- return 0;
+bool parse_args(int argc, char **argv, char **input, char **output, bool *latlon)
+{
+ int c;
+
+ *input = *output = NULL;
+ *latlon = false;
+
+ while ( (c = getopt(argc, argv, "i:o:L")) != -1) {
+ switch (c) {
+ case 'i':
+ *input = optarg;
+ break;
+ case 'o':
+ *output = optarg;
+ break;
+ case 'L':
+ *latlon = true;
+ break;
+ case '?':
+ usage(argv[0]);
+ return false;
+ default:
+ printf("?? getopt returned character code 0%o ??\n", c);
+ return false;
+ }
}
+ if (*input == NULL) {
+ printf("ERROR: Must specify input file -i input-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ if (*output == NULL) {
+ printf("ERROR: Must specify output file -o output-file\n\n");
+ usage(argv[0]);
+ return false;
+ }
+
+ return true;
+}
+
+void lat_lon_depth_2_xyz(float *x, float *y, float *z)
+{
+ float lat, lon, depth;
+ float theta, phi, r;
+
+ const float R_EARTH_KM = 6371.0;
+ const float PI = 3.141592653589793;
+ const float D2R = PI/180.0;
+
+ lat = *x; lon = *y; depth = *z;
+
+ theta = (PI / 2.0) - atan(0.99329534 * tan(lat * D2R));
+ phi = lon * D2R;
+
+ r = (R_EARTH_KM - depth) / R_EARTH_KM;
+ *x = r * sin(theta) * cos(phi);
+ *y = r * sin(theta) * sin(phi);
+ *z = r * cos(theta);
+}
+
+int main(int argc, char** argv) {
+ char *input, *output;
+ bool latlon;
float xyz[3];
+ float scalar;
FILE *file;
int i;
int npts;
- if ((file = fopen(argv[1], "r")) == 0)
+ if (!parse_args(argc, argv, &input, &output, &latlon)) {
+ return 1;
+ }
+
+ if ((file = fopen(input, "r")) == 0)
{
- //cerr << "ERROR: Can't read file: " << filename << "\n";
- return 0;
+ cerr << "ERROR: Can't read file: " << input << "\n";
+ return 1;
}
fscanf(file, "%d", &npts);
vtkUnstructuredGrid *dataSet = vtkUnstructuredGrid::New();
- float *xV = new float[npts];
- float *yV = new float[npts];
- float *zV = new float[npts];
- float *sV = new float[npts];
vtkPoints *newPts = vtkPoints::New();
vtkFloatArray *newScalars = vtkFloatArray::New();
for(i = 0; i < npts; i++)
{
- fscanf(file, "%f", &xV[i]);
- fscanf(file, "%f", &yV[i]);
- fscanf(file, "%f", &zV[i]);
- fscanf(file, "%f", &sV[i]);
- xyz[0] = xV[i];
- xyz[1] = yV[i];
- xyz[2] = zV[i];
+ fscanf(file, "%f", &xyz[0]);
+ fscanf(file, "%f", &xyz[1]);
+ fscanf(file, "%f", &xyz[2]);
+ fscanf(file, "%f", &scalar);
+ if (latlon)
+ {
+ lat_lon_depth_2_xyz(&xyz[0], &xyz[1], &xyz[2]);
+ }
newPts -> InsertPoint(i, xyz);
- newScalars -> InsertValue(i, sV[i]);
+ newScalars -> InsertValue(i, scalar);
}
dataSet -> SetPoints(newPts);
@@ -62,7 +141,7 @@
vtkXMLUnstructuredGridWriter* writer = vtkXMLUnstructuredGridWriter::New();
writer -> SetInput(dataSet);
- writer -> SetFileName(argv[2]);
+ writer -> SetFileName(output);
writer -> Write();
writer -> Delete();
More information about the CIG-COMMITS
mailing list