Funny problems with pfASD and pfdASDGen

New Message Reply Date view Thread view Subject view Author view

Robert Stein (rstein++at++ncsa.uiuc.edu)
Thu, 04 Mar 1999 15:41:00 -0600


Hi pfAll,

        I have been intrigued by earlier conversations about the capabilities the
pfASD node and particularly with doing paging ASD... I am pleased to say
that for the most part I've been able to work out most of the difficulties
that I've had by reading the documentation and by looking at code
snippets... But I have run across a problem in using the pfdASDGen code
that Yair Kurzion has so generously provided.
        I have modifyed the pagedASD.c code that is included with the ASDGen
distribution to read my own format of file... this is basically just a flat
array of elevation data (very simple) and have been successful at
converting some sizes of files over to the paging ASD format that is
required here... The dataset that I'm really interested in using is of
size 2300x1882...

        I've converted this file with a tile_size of 200 and just 3 asd_levels
(for sake of testing) The file loads with no problem, however at one of the
LODs there appear alot of these really long skinny triangles that run from
one end of the terrain clear over to the other (see this image for an example)
        http://wasatch.ncsa.uiuc.edu/~rstein/pfASD/2300_1882_grid.jpg

        In the very same way, I created a somewhat smaller file of size 1000x1000,
and the results are as they should be.
        http://wasatch.ncsa.uiuc.edu/~rstein/pfASD/1000_1000_grid.jpg

        I should mention that I see these wierd results in both the display code
that I wrote, and in asdfly... I the results don't seem to be related to
what data I'm using... I've tried with both real data and fake data that is
all zeros....
        I would really appreciate some help here... I've included some code that
is very similar to the pagedASD.c code mentioned above... it is what I'm
using to convert from my initial file format... after I run this code I
then run the convasd code as mentioned in the documentation to generate the
final paged asd files that I've been talking about...

Sincerely,

Robert Stein

----------------------------------------------------------------------------
------------
/*This file is based on Yair Kurzion's pagedASD.c code*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <strings.h>
#include <sys/resource.h>
#include <alloca.h>

#include <sys/types.h>
#include <sys/mman.h>

#include <Performer/pf.h>
#include <Performer/pfdu.h>

#include "pfdASDGen.h"

/*
 * ==================================================
 * prototypes.
 * ==================================================
 */

void init_globals(void);
void read_params(int argc, char *argv[]);
void init_mesh(void);
void make_mesh_level (int level, int new_size);
float fract (float v0, float v1);
void read_file (char *filename);
void read_bvt (char *filename);
float array_point (void *user_data, int x, int y);

/*
 * ==================================================
 * Global Variables
 * ==================================================
 */

static int size;
static float min_elevation, max_elevation;
static float origin_lat, origin_lon;
static float postSpacing;
static float metPerDegLat;
static float metPerDegLon;
static float random_intensity;
static int nof_levels;
static float x_span, y_span;
static float x_base, y_base;
static int is_zero_edge;
static char output_file[200];
static char config_file[200];
static int is_flatten_zero;
static int tile_size;
static int nof_asd_levels;
static char temp_base_filename[300];
static char base_filename[300];
static float prune_epsilon;
static int enable_prune;
static int is_sphere;
static float sphere_radius;
static pfVec3 sphere_center;

static int tile_lookahead[2];
static float* myData;

/*==========================================================================
=*/
void init_globals(void)
/*==========================================================================
=*/
{
min_elevation = -500.0;
max_elevation = 500.0;
random_intensity = 0.5;
x_span = 10000.0;
y_span = 10000.0;
x_base = 0.0;
y_base = 0.0;
is_zero_edge = 1;
is_flatten_zero = 1;
enable_prune = 0;
prune_epsilon = 0.001;

tile_lookahead [0] = 3;
tile_lookahead [1] = 3;

size = 5;
nof_levels = 5;
tile_size = 11;
nof_asd_levels = 5;

sprintf (temp_base_filename, "tmp/temp_new_asd");
sprintf (base_filename, "tmp/new_asd");

is_sphere = 0;
sphere_center[0] = 0.0;
sphere_center[1] = 0.0;
sphere_center[2] = 0.0;
sphere_radius = 20000.0;

}

/*==========================================================================
=*/
void main(int argc, char *argv[])
/*==========================================================================
=*/
{
    pfdASDGenerator *asdgen;

    init_globals();

    read_bvt(argv[1]);
    read_params(argc-1, &argv[1]);

    /*
     * =====================================================================
     * Generate an ASD from the data in my BVT file
     * =====================================================================
     */

    asdgen = pfdNewASDGen();

    pfdASDGenPlaneGeometry (asdgen, x_base, y_base, x_span, y_span);

    pfdASDGenElevationFunc (asdgen, array_point, (void*)myData);

    pfdASDGenPrune (asdgen, enable_prune, prune_epsilon);

    pfdASDGenGridSize (asdgen, x_span, y_span);

    pfdASDGenTileSize (asdgen, tile_size);

    pfdASDGenNofLevels (asdgen, nof_asd_levels);

    pfdASDGenTempFile (asdgen, temp_base_filename);

    pfdASDGenOutputFile (asdgen, base_filename);

    pfdASDGenLookahead (asdgen, tile_lookahead[0], tile_lookahead[1]);

    pfdASDGenerate (asdgen);
}

/*==========================================================================
=*/
void read_bvt( char* filename )
/*==========================================================================
=*/
{
  FILE *fp = fopen(filename, "r");
  if(!fp){
    fprintf(stderr, "Can't open file %s\n", filename);
    return;
  }
  int readPtr = fileno(fp);

  fread(&origin_lat, sizeof(float), 1, fp);
  fprintf(stderr, "%f\n", origin_lat);
  fread(&origin_lon, sizeof(float), 1, fp);
  fprintf(stderr, "%f\n", origin_lon);
  fread(&postSpacing, sizeof(float), 1, fp);
  fprintf(stderr, "%f\n", postSpacing);
  fread(&metPerDegLat, sizeof(float), 1, fp);
  fprintf(stderr, "%f\n", metPerDegLat);
  fread(&metPerDegLon, sizeof(float), 1, fp);
  fprintf(stderr, "%f\n", metPerDegLon);
  fread(&min_elevation, sizeof(float), 1, fp);
  fprintf(stderr, "%f\n", min_elevation);
  fread(&max_elevation, sizeof(float), 1, fp);
  fprintf(stderr, "%f\n", max_elevation);

  int xdim, ydim;
  fread(&ydim, sizeof(int), 1, fp);
  fread(&xdim, sizeof(int), 1, fp);
  x_span = (float)xdim; y_span = (float)ydim;

  //map the file contents into memory and store in our data structures
  myData = (float *)mmap(NULL, (sizeof(float)*x_span*y_span)+36,
                                PROT_READ, MAP_PRIVATE, readPtr, 0);
  if(!myData){
    fprintf(stderr, "MemMapping error\n");
    exit(0);
  }
  fprintf(stderr, "Done MMapping\n");
}

/*==========================================================================
=*/
void read_params(int argc, char *argv[])
/*==========================================================================
=*/
{
    int i;

    if (argc > 0)
        {
            i = 1;
            while (i < argc)
            {
                if (argv[i][0] == '-')
                {
                    switch (argv[i][1])
                    {
                        case 'o':
                            i ++;
                            strcpy(output_file, argv[i]);
                            break;

                        case 'c':
                            i ++;
                            strcpy(config_file, argv[i]);
                            break;

                        default:
                            fprintf (stderr, "Unknown option -%c\n",
                                argv[i][1]);
                            break;
                    }
                }
                else
                  read_file (argv[i]);
                 
                i ++;
            }
        }
}

/*=========================================================================*/
void read_file (char *filename)
/*=========================================================================*/
{
  fprintf(stderr, "Reading file!!!\n");
    FILE *fp;
    char s[200];

    if ((fp = fopen (filename, "r")) == NULL)
    {
        perror (filename);
        return;
    }

    while (! feof (fp))
    {
        s[0] = ';';
        fgets (s, 190, fp);

        if ((s[0] != ';') && (s[0] != ' ') && (s[0] != '\n'))
        {
            if (strncmp (s, "root_size", 9) == 0)
                size = atoi (&s[10]);
            else
            if (strncmp (s, "min_elevation", 13) == 0)
                min_elevation = atof (&s[14]);
            else
            if (strncmp (s, "max_elevation", 13) == 0)
                max_elevation = atof (&s[14]);
            else
            if (strncmp (s, "random_intensity", 16) == 0)
                random_intensity = atof (&s[17]);
            else
            if (strncmp (s, "nof_levels", 10) == 0)
                nof_levels = atoi (&s[11]);
            else
            if (strncmp (s, "x_span", 6) == 0)
                x_span = atof (&s[7]);
            else
            if (strncmp (s, "y_span", 6) == 0)
                y_span = atof (&s[7]);
            else
            if (strncmp (s, "x_base", 6) == 0)
                x_base = atof (&s[7]);
            else
            if (strncmp (s, "y_base", 6) == 0)
                y_base = atof (&s[7]);
            else
            if (strncmp (s, "zero_edge", 9) == 0)
                is_zero_edge = atoi (&s[10]);
            else
            if (strncmp (s, "flatten_zero", 12) == 0)
                is_flatten_zero = atoi (&s[13]);
            else
            if (strncmp (s, "tile_size", 9) == 0)
                sscanf (&s[10], "%d", &tile_size);
            else
            if (strncmp (s, "nof_asd_levels", 14) == 0)
                sscanf (&s[15], "%d", &nof_asd_levels);
            else
            if (strncmp (s, "tile_lookahead", 14) == 0)
                sscanf (&s[15], "%d%d", &tile_lookahead[0], &tile_lookahead[1]);
            else
            if (strncmp (s, "prune_epsilon", 13) == 0)
                sscanf (&s[13], "%f", &prune_epsilon);
            else
            if (strncmp (s, "enable_prune", 12) == 0)
                sscanf (&s[13], "%d", &enable_prune);
            else
            if (strncmp (s, "temp_base_filename", 18) == 0)
                sscanf (&s[18], "%s", temp_base_filename);
            else
            if (strncmp (s, "base_filename", 13) == 0)
                sscanf (&s[13], "%s", base_filename);
            else
            if (strncmp (s, "sphere", 6) == 0)
            {
                is_sphere = 1;
                sscanf (&s[7], "%f%f%f%f", &sphere_radius,
                                           &sphere_center[0],
                                           &sphere_center[1],
                                           &sphere_center[2]);
            }
            else
                fprintf (stderr, "Unknown option %s\n", s);
        }
    }

    printf ("Option Summary:\n");
    printf ("root_size %d\n", size);
    printf ("min_elevation %f\n", min_elevation);
    printf ("max_elevation %f\n", max_elevation);
    printf ("random_intensity %f\n", random_intensity);
    printf ("nof_levels %d\n", nof_levels);
    printf ("x_span %f\n", x_span);
    printf ("y_span %f\n", y_span);
    printf ("zero_edge %d\n", is_zero_edge);
    printf ("flatten_zero %d\n", is_flatten_zero);
    printf ("tile_size %d\n", tile_size);
    printf ("nof_asd_levels %d\n", nof_asd_levels);
    printf ("tile_lookahead [%d, %d]\n", tile_lookahead[0],
tile_lookahead[1]);
    printf ("prune = %d, epsilon = %f\n", enable_prune, prune_epsilon);
    if (is_sphere)
    {
        printf ("sphere radius = %f\n", sphere_radius);
        printf ("sphere center = (%f, %f, %f)\n",
                        sphere_center[0], sphere_center[1], sphere_center[2]);
    }
    printf ("temp_base_filename = %s\n", temp_base_filename);
    printf ("base_filename = %s\n", base_filename);

}

/*=========================================================================*/
float array_point (void *user_data, int x, int y)
/*=========================================================================*/
{
  float *mydata = (float*)user_data;
  return mydata[ (int)(y*x_span + x) ];
}

Robert J. Stein
National Center For Supercomputing Applications
405 N. Matthews, Urbana, IL
(217) 244-7584
rstein++at++ncsa.uiuc.edu
Robert J. Stein
National Center For Supercomputing Applications
405 N. Matthews, Urbana, IL
(217) 244-7584
rstein++at++ncsa.uiuc.edu


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Thu Mar 04 1999 - 13:41:06 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.