[Paraview] CSV Files and Volumetric Data

GILLILAND G. (929919) G.C.GILLILAND.929919 at swansea.ac.uk
Wed Apr 4 17:15:52 EDT 2018


Hi there,

I have assignment where data is produced in C, and i have to export it to a relevant file format that works with a visualisation software of my choice.

I've chosen Paraview, because i know that CSV files work with this software.

Rather than table to points, i want to be able to convert the points to a volumetric dataset... So i can have greater control over colour mapping. But i was told that the code that generates the dataset is missing some data, or i may have missed something in the way i export the file.

I've included the code below; i would love some help with this. I'm only decent with coding in Java and my lecturer has really given the class a lot of support.

Cheers

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

void gen_sally( int xs, int ys, int zs, int time, float *sally )
/*
 *  Gen_Sally creates a vector field of dimension [xs,ys,zs,3] from
 *  a proceedural function. By passing in different time arguements,
 *  a slightly different and rotating field is created.
 *
 *  The magnitude of the vector field is highest at some funnel shape
 *  and values range from 0.0 to around 0.4 (I think).
 *
 *  I just wrote these comments, 8 years after I wrote the function.
 *
 *  Developed by Sally of Sally University
 *
 */
{
  float x, y, z;
  int ix, iy, iz;
  float r, xc, yc, scale, temp, z0;
  float r2 = 8;
  float SMALL = 0.00000000001;
  float xdelta = 1.0 / (xs-1.0);
  float ydelta = 1.0 / (ys-1.0);
  float zdelta = 1.0 / (zs-1.0);

  for( iz = 0; iz < zs; iz++ )
  {
z = iz * zdelta;                        // map z to 0->1
xc = 0.5 + 0.1*sin(0.04*time+10.0*z);   // For each z-slice, determine the spiral circle.
yc = 0.5 + 0.1*cos(0.03*time+3.0*z);    //    (xc,yc) determine the center of the circle.
r = 0.1 + 0.4 * z*z + 0.1 * z * sin(8.0*z); //  The radius also changes at each z-slice.
r2 = 0.2 + 0.1*z;                           //    r is the center radius, r2 is for damping
for( iy = 0; iy < ys; iy++ )
{
y = iy * ydelta;
for( ix = 0; ix < xs; ix++ )
{
x = ix * xdelta;
temp = sqrt( (y-yc)*(y-yc) + (x-xc)*(x-xc) );
scale = fabs( r - temp );
/*
 *  I do not like this next line. It produces a discontinuity
 *  in the magnitude. Fix it later.
 *
 */
   if ( scale > r2 )
  scale = 0.8 - scale;
   else
  scale = 1.0;
z0 = 0.1 * (0.1 - temp*z );
   if ( z0 < 0.0 )  z0 = 0.0;
   temp = sqrt( temp*temp + z0*z0 );
scale = (r + r2 - temp) * scale / (temp + SMALL);
scale = scale / (1+z);
   *sally++ = scale * (y-yc) + 0.1*(x-xc);
   *sally++ = scale * -(x-xc) + 0.1*(y-yc);
   *sally++ = scale * z0;
}
}
  }
}


void create_csv(char* filename,float *sally, int size){
printf("1");
printf("\n Creating %s.csv file",filename);
FILE *fp;
fp=fopen(filename,"w");
fprintf(fp,"X,Y,Z\n");
int i;
int counter = 0;
for(i = 0; i< size; i++){
if(sally[i] == 0){
fprintf(fp,"0");
}
else{
fprintf(fp,"%f",sally[i]);
}
counter++;
if(counter == 3){
fprintf(fp, "\n");
counter = 0;
}
else{
fprintf(fp,",");
}
}
fclose(fp);
printf("\n %sfile created",filename);
}
int main(int argc, char *argv[]){
printf("1\n");
//read from args
int xs;
int ys;
int zs;
int time;
sscanf(argv[1],"%d",&xs);
sscanf(argv[2],"%d",&ys);
sscanf(argv[3],"%d",&zs);
sscanf(argv[4],"%d",&time);


int arraySize = xs*ys*zs*3;
//allocate memeory for array. This is done so that stack memory doesn't run out.'
float* sally;
sally = (float*)malloc((arraySize) * sizeof(float));

//runs the code. One of the args is a pointer so no return type is needed.
gen_sally(xs,ys,zs,time,sally);
//create varibles for file generation
char filename[20] = "results.csv";
create_csv(filename, sally, arraySize);

free(sally);
return 0;
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/paraview/attachments/20180404/db71ab60/attachment.html>


More information about the ParaView mailing list