/* This example uses the dp_rand_isosurf function to produce an isosurface * from data points at random 3D locations. The dp_boundbox routine is * used to provide bounds for the surface. */ #include #include #include #include /* Macro to ease checking of error return codes */ #define ERRCHK( string ) if (!(string)) fprintf(stderr,"ERROR!\n") /* Number of data points to define the isosurface */ #define RAND_ISOSURF_PTS 1000 /* This function returns a float between 0.0 and 1.0. */ static float get_random_flt() { float result; result= (float)(0.5*(double)random()/(double)(2<<30-1)); return(result); } /* This function generates a single randomly located data point. The * val field provides the data values from which the isosurface is * extracted, and the val2 field provides values mapped to colors * on the surface. */ static void gen_ran_iso_point( float *x, float *y, float *z, float *val, float *val2 ) { *x= get_random_flt() - 0.5; *y= get_random_flt() - 0.5; *z= get_random_flt() - 0.5; *val= sqrt( ( *x * *x ) + ( *y * *y ) + ( *z * *z ) ); *val2= *z; } /* This routine actually creates the isosurface. */ static void rand_iso_demo() { int npts= RAND_ISOSURF_PTS; float data[5*RAND_ISOSURF_PTS], *dataptr= data; int i; float ival= 0.48; /* This is the constant value of the isosurface */ /* Corners for the bounding box, and a color */ P_Point p1= { -0.5, -0.5, -0.5 }; P_Point p2= { 0.5, 0.5, 0.5 }; P_Color blue = { 0, 0.0, 0.0, 1.0, 1.0 }; /* Generate the data */ for (i=0; i