Home| general |src.lib|raster| Raster Index

Raster

Syntax
void *Raster(int wdt,int hgt,int sparse,int type,void *zero,int poly,float *pnt,int *vertex,void *value);
Header
general/raster.h
Library
raster
Description

The Raster function uses linear interpolation to extrapolate data values from a limited set of points arranged in a grid.

The function returns a two-dimensional array, whose extents are equal to the arguments wdt and hgt. The array is in row major form. The remaining arguments describe the grid of input data.

If the argument sparse has a non-zero value then the input grid is sparsely populated and not all cells have an assigned value. In this case a slower algorithm must be used to interpolate the data.

The argument type determines the type of input data, possible values are:

raster_INTSigned integer.
raster_FLOATSingle precision floating point.
raster_DOUBLEDouble precision floating point.

The data type of the returned array matches that of the input grid.

The argument zero is a pointer to the value to use for points in the array that have no interpolated value. The pointer should be to the same data type as the input grid.

The x and y co-ordinates of each grid point are described by pairs of elements from the array pnt. The range of the x and y coordinates should be between zero and wdt.

The associated data value for each grid point is defined by the elements of the array value.

The arrangement of the grid is described in terms of four sided polygons formed by linking grid points together. The argument poly defines the number of polygons in the grid and a complete polygon is described by a group of four elements from the array vertex. The elements of the array define the grid points at the four vertices of a polygon.

Returns
Returns a pointer to an array containing the interpolated data. If an error occurs a NULL pointer is returned.
Errors
If an error occurs a NULL pointer is returned.
Example



Source Code: Raster.c

/* Raster.c
   ========
   Author: R.J.Barnes
 Copyright (c) 2012 The Johns Hopkins University/Applied Physics Laboratory

This file is part of the Radar Software Toolkit (RST).

RST is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

Modifications:




#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "rmath.h"
#include "rtypes.h"
#include "rxml.h"
#include "option.h"
#include "rfbuffer.h"
#include "polygon.h"
#include "rplot.h"
#include "raster.h"

double value[]={2.0, 1.5, 1.0, 1.1, 1.2,
                1.5, 1.7, 1.0, 1.1, 1.1,
		1.0, 1.0, 1.0, 0.6, 0.8,
	        0.6, 1.0, 0.6, 0.1, 0.5,
		0.2, 1.0, 0.6, 0.5, 0.5};

float pnt[]={ 0,0,   100,0,   200,0,   300,0,   400,0,
            0,100,  100,100,  200,100,  300,100,  400,100,
	    0,200, 100,200, 200,200, 300,200, 400,200,
	    0,300, 100,300, 200,300, 300,300, 400,300,
	    0,400, 100,400, 200,400, 300,400, 400,400};
	    
	   
int vertex[]={0,1,6,5,     1,2,7,6,     2,3,8,7,   3,4,9,8,
              5,6,11,10,   6,7,12,11,   7,8,13,12, 8,9,14,13,
	      10,11,16,15, 11,12,17,16, 12,13,18,17, 13,14,19,17,
	      15,16,21,20, 16,17,22,21, 17,18,23,22, 18,19,24,23};

struct FrameBuffer *img;


int stream(char *buf,int sze,void *data) {
  FILE *fp;
  fp=(FILE *) data;
  fwrite(buf,sze,1,stdout);
  return 0;
} 

int main(int argc,char *argv[]) {

  struct Rplot *rplot=NULL;
  int x,y;
  float wdt=400,hgt=400;
  double zeroval=1e31;
  double *zbuf=NULL;

  img=FrameBufferMake("dummy",wdt,hgt,8);

  zbuf=Raster(wdt,hgt,0,raster_DOUBLE,&zeroval,16,pnt,vertex,value);

  for (y=0;y<hgt;y++) {
    for (x=0;x<wdt;x++) {
      img->img[y*(int) wdt+x]=255*zbuf[y*(int) wdt+x]/2.0;
    }
  }

  rplot=RplotMake();
  RplotSetText(rplot,stream,stdout);   
  RplotMakeDocument(rplot,"Raster","1",wdt,hgt,24);
  RplotMakePlot(rplot,"Raster",wdt,hgt,24);

  RplotImage(rplot,NULL,img,0x0f,0,0,1);  
             
  RplotEndPlot(rplot);
  RplotEndDocument(rplot);
  return 0;
}