// add waypoint BOOLINT minipoint::add(minipointdata *point) { int i; float posx,posy; int col,row; if (TILE==NULL) ERRORMSG(); if (POINTS==NULL) { COLS=TILE->getcols(); ROWS=TILE->getrows(); if ((POINTS=(minipointdata **)malloc(COLS*ROWS*sizeof(minipointdata *)))==NULL) MEMERROR(); if ((NUM=(int *)malloc(COLS*ROWS*sizeof(int)))==NULL) MEMERROR(); if ((MAXNUM=(int *)malloc(COLS*ROWS*sizeof(int)))==NULL) MEMERROR(); for (i=0; i<COLS*ROWS; i++) { POINTS[i]=NULL; MAXNUM[i]=NUM[i]=0; } } posx=(point->x-TILE->getcenterx())/TILE->getcoldim()+COLS/2.0f; posy=(-point->y-TILE->getcenterz())/TILE->getrowdim()+ROWS/2.0f; if (posx<0.0f || posx>COLS || posy<0.0f || posy>ROWS) return(FALSE); col=ftrc(posx); row=ftrc(posy); if (col==COLS) col--; if (row==ROWS) row--; if (NUM[col+row*COLS]>=MAXNUM[col+row*COLS]) { MAXNUM[col+row*COLS]=2*MAXNUM[col+row*COLS]+1; if (POINTS[col+row*COLS]==NULL) {if ((POINTS[col+row*COLS]=(minipointdata *)malloc(MAXNUM[col+row*COLS]*sizeof(minipointdata)))==NULL) MEMERROR();} else {if ((POINTS[col+row*COLS]=(minipointdata *)realloc(POINTS[col+row*COLS],MAXNUM[col+row*COLS]*sizeof(minipointdata)))==NULL) MEMERROR();} } point->number=PNUM++; if (strlen(point->comment)>0) parsecomment(point); point->size=0.0f; point->offset=0.0f; POINTS[col+row*COLS][NUM[col+row*COLS]++]=*point; return(TRUE); }
// parse option void minipoint::parseoption(minipointdata *point,lunascan *scanner) { int option; float value; char *name; option=scanner->gettoken(); scanner->next(); if (scanner->gettoken()==minipointopts::OPTION_EQ) { scanner->next(); if (scanner->gettoken()==lunascan::LUNA_VALUE || scanner->gettoken()==lunascan::LUNA_STRING) { value=scanner->getvalue(); name=scanner->getstring(); if (strcmp(name,"")==0) name=NULL; if (point->opts==NULL) point->opts=new minipointopts; switch (option) { case minipointopts::OPTION_TYPE: point->opts->type=ftrc(value+0.5f); break; case minipointopts::OPTION_SIGNPOSTSIZE: point->opts->signpostsize=value; break; case minipointopts::OPTION_SIGNPOSTHEIGHT: point->opts->signpostheight=value; break; case minipointopts::OPTION_SIGNPOSTNOAUTO: point->opts->signpostnoauto=ftrc(value+0.5f); break; case minipointopts::OPTION_SIGNPOSTTURN: point->opts->signpostturn=value; break; case minipointopts::OPTION_SIGNPOSTINCLINE: point->opts->signpostincline=value; break; case minipointopts::OPTION_SIGNPOSTALPHA: point->opts->signpostalpha=value; break; case minipointopts::OPTION_BRICKFILE: if (name!=NULL) point->opts->brickfile=strdup(name); break; case minipointopts::OPTION_BRICKSIZE: point->opts->bricksize=value; break; case minipointopts::OPTION_BRICKTURN: point->opts->brickturn=value; break; case minipointopts::OPTION_BRICKINCLINE: point->opts->brickincline=value; break; case minipointopts::OPTION_BRICKCOLOR_RED: point->opts->brickcolor_red=value; break; case minipointopts::OPTION_BRICKCOLOR_GREEN: point->opts->brickcolor_green=value; break; case minipointopts::OPTION_BRICKCOLOR_BLUE: point->opts->brickcolor_blue=value; break; case minipointopts::OPTION_BRICKALPHA: point->opts->brickalpha=value; break; case minipointopts::OPTION_DATAFILE: if (name!=NULL) point->opts->datafile=strdup(name); break; case minipointopts::OPTION_DATASIZE: point->opts->datasize=value; break; case minipointopts::OPTION_DATATURN: point->opts->dataturn=value; break; case minipointopts::OPTION_DATAINCLINE: point->opts->dataincline=value; break; case minipointopts::OPTION_DATACOLOR_RED: point->opts->datacolor_red=value; break; case minipointopts::OPTION_DATACOLOR_GREEN: point->opts->datacolor_green=value; break; case minipointopts::OPTION_DATACOLOR_BLUE: point->opts->datacolor_blue=value; break; case minipointopts::OPTION_DATAALPHA: point->opts->dataalpha=value; break; case minipointopts::OPTION_DATASWITCH: point->opts->dataswitch=ftrc(value+0.5f); break; case minipointopts::OPTION_DATACONTROL: point->opts->datacontrol=value; break; case minipointopts::OPTION_DATARANGE: point->opts->datarange=value; break; } } scanner->next(); } }
void loadvolume() { if (!VOLREN->loadvolume(FILENAME,GRADNAME, 0.0f,0.0f,0.0f,1.0f,1.0f,1.0f, VOL_BRICKSIZE,VOL_OVERMAX, GUI_xswap,GUI_yswap,GUI_zswap, GUI_xrot,GUI_zrot, GUI_extra,GUI_commands, ftrc(2.0f*GUI_histtweak*GUI_histmin)+1,2.0f*GUI_histslide*GUI_histfreq, GUI_kneigh,GUI_histstep)) exit(1); }
// render the volumes void minilod::render(float ex,float ey,float ez, float farp, float fovy,float aspect, float t, int phase) { int i,j; minibrickdata *brk; miniloddata *vol; minibrick *brick; float dist; int lod; // configure bricks for (i=0; i<BNUM; i++) for (j=0; j<BRICKS[i].lods; j++) BRICKS[i].brick[j].configure_stripeoffset(CONFIGURE_BRICKOFFSET); // render volumes for (i=MINIBRICK_FIRST_RENDER_PHASE; i<=MINIBRICK_LAST_RENDER_PHASE; i++) if (phase==MINIBRICK_ONE_RENDER_PHASE || i==phase) for (j=0; j<VNUM; j++) { // get actual volume vol=&VOLS[j]; // get indexed brick brk=&BRICKS[vol->index]; // calculate distance dist=fsqr((vol->x+OFFSETLON)*SCALEX-ex)+fsqr((vol->y+OFFSETLAT)*SCALEY-ez)+fsqr(vol->e*SCALEELEV-ey); dist/=fsqr(brk->brad); // calculate lod if (dist<=1.0f) lod=0; else lod=ftrc(flog(dist)/flog(brk->stagger)/2.0f+0.5f); if (lod>=brk->lods) lod=brk->lods-1; // get actual brick lod brick=&brk->brick[lod]; // set position brick->resetpos(vol->x,vol->y,vol->e,vol->dx,vol->dy,vol->de); // set color brick->addiso(0.5f,vol->r,vol->g,vol->b,vol->a); // render mesh brick->render(ex,ey,ez,0.0f,farp,fovy,aspect,0.0f,i); } }
// convert from float to unsigned short void convfloat(unsigned char *data,unsigned int bytes) { unsigned int i; unsigned char *ptr; float v,vmax; for (vmax=1.0f,ptr=data,i=0; i<bytes/4; i++,ptr+=4) { if (DDS_ISINTEL) DDS_swapuint((unsigned int *)ptr); v=fabs(*((float *)ptr)); if (v>vmax) vmax=v; } for (ptr=data,i=0; i<bytes/4; i++,ptr+=4) { v=fabs(*((float *)ptr))/vmax; data[2*i]=ftrc(65535.0f*v+0.5f)/256; data[2*i+1]=ftrc(65535.0f*v+0.5f)%256; } }
int main(int argc,char *argv[]) { int i; unsigned char *image1; int width1,height1,components1; unsigned char *image2; int width2,height2,components2; float red,green,blue,nir; float redmax,greenmax,bluemax,nirmax; float ndvi,trees,treemin,treemax; if (argc!=4) { printf("usage: %s <rgb.ppm> <nir.pgm> <ndvi.pgm>\n",argv[0]); exit(1); } if ((image1=readPNMfile(argv[1],&width1,&height1,&components1))==NULL) exit(1); if ((image2=readPNMfile(argv[2],&width2,&height2,&components2))==NULL) exit(1); if (width1!=width2 || height1!=height2 || components1!=3 || components2!=1) exit(1); redmax=greenmax=bluemax=nirmax=1.0f/255.0f; for (i=0; i<width1*height1; i++) { red=image1[3*i]/255.0f; green=image1[3*i+1]/255.0f; blue=image1[3*i+2]/255.0f; nir=image2[i]/255.0f; if (red>redmax) redmax=red; if (green>greenmax) greenmax=green; if (blue>bluemax) bluemax=blue; if (nir>nirmax) nirmax=nir; } redmax*=255.0f; greenmax*=255.0f; bluemax*=255.0f; nirmax*=255.0f; treemin=1.0f; treemax=2.0f; for (i=0; i<width1*height1; i++) { red=image1[3*i]/redmax; green=image1[3*i+1]/greenmax; blue=image1[3*i+2]/bluemax; nir=image2[i]/nirmax; if (red==0.0f || nir==0.0f) ndvi=0.0f; else ndvi=(nir-red)/(nir+red); ndvi+=0.3f; if (ndvi<0.0f) ndvi=0.0f; else if (ndvi>1.0f) ndvi=1.0f; trees=ndvi*((1.0f-red)+green+(1.0f-blue)); if (trees<treemin) treemin=trees; if (trees>treemax) treemax=trees; } for (i=0; i<width1*height1; i++) { red=image1[3*i]/redmax; green=image1[3*i+1]/greenmax; blue=image1[3*i+2]/bluemax; nir=image2[i]/nirmax; if (red==0.0f || nir==0.0f) ndvi=0.0f; else ndvi=(nir-red)/(nir+red); ndvi+=0.3f; if (ndvi<0.0f) ndvi=0.0f; else if (ndvi>1.0f) ndvi=1.0f; trees=ndvi*((1.0f-red)+green+(1.0f-blue)); trees=(trees-treemin)/(treemax-treemin); image2[i]=ftrc(255.0f*trees+0.5f); } writePNMimage(argv[3],image2,width2,height2,1); return(0); }
int main(int argc,char *argv[]) { int i; FILE *file; char dem_description[81]; int coord_sys,coord_zone,coord_datum; int coord_units,scaling_units; float coord_SW_x,coord_SW_y; float coord_NW_x,coord_NW_y; float coord_NE_x,coord_NE_y; float coord_SE_x,coord_SE_y; float cell_size_x,cell_size_y; float vertical_scaling; int missing_value; char *comment; unsigned char *image; int width,height, row,column; int elev; if (argc!=3 && argc!=4) { printf("usage: %s <input.dem> <output.pgm> [<missing value>]\n",argv[0]); printf("note: guaranteed to work for USGS 1:250,000 DEM quads only\n"); exit(1); } if ((file=fopen(argv[1],"rb"))==NULL) exit(1); // DEM descriptor for (i=0; i<80; i++) dem_description[i]=fgetc(file); dem_description[80]='\0'; for (i=0; i<29; i++) fgetc(file); // skip blank filler for (i=0; i<26; i++) fgetc(file); // skip geographic corner for (i=0; i<2; i++) fgetc(file); // skip process code for (i=0; i<3; i++) fgetc(file); // skip sectional indicator for (i=0; i<4; i++) fgetc(file); // skip origin code for (i=0; i<6; i++) fgetc(file); // skip DEM level code for (i=0; i<6; i++) fgetc(file); // skip elevation pattern // reference coordinate system coord_sys=ftrc(nextitem(file)); coord_zone=ftrc(nextitem(file)); coord_datum=0; if (coord_sys!=0) exit(1); // only 0=lat/lon supported for (i=0; i<15; i++) nextitem(file); // skip projection // reference units coord_units=ftrc(nextitem(file)); scaling_units=ftrc(nextitem(file)); // check units if (coord_units<0 || coord_units>3) exit(1); if (scaling_units<1 || scaling_units>2) exit(1); if (coord_units==3) coord_units=4; nextitem(file); // skip polygon sides // coordinates of corners coord_SW_x=nextitem(file); coord_SW_y=nextitem(file); coord_NW_x=nextitem(file); coord_NW_y=nextitem(file); coord_NE_x=nextitem(file); coord_NE_y=nextitem(file); coord_SE_x=nextitem(file); coord_SE_y=nextitem(file); nextitem(file); // skip minimum elevation nextitem(file); // skip maximum elevation // spatial resolution fseek(file,817,SEEK_SET); cell_size_x=nextitem(file); cell_size_y=nextitem(file); vertical_scaling=nextitem(file); // missing value missing_value=-9999; if (argc==4) if (sscanf(argv[3],"%d",&missing_value)!=1) exit(1); // DEM width if (ftrc(nextitem(file))!=1) exit(1); width=ftrc(nextitem(file)); // actual row/column/height of DEM profile row=ftrc(nextitem(file)); column=ftrc(nextitem(file)); height=ftrc(nextitem(file)); if ((image=(unsigned char *)malloc(2*width*height))==NULL) exit(1); while (row==1 && column>0 && column<=width) { for (i=0; i<6; i++) nextitem(file); // skip profile position // read elevations while (row++<=height) { elev=ftrc(nextitem(file)); if (elev<0) elev=65536+elev; image[2*(column-1+(height-row+1)*height)]=elev/256; image[2*(column-1+(height-row+1)*height)+1]=elev%256; } // next profile row=ftrc(nextitem(file)); column=ftrc(nextitem(file)); nextitem(file); // ignore number of samples } fclose(file); comment=putPNMparams(dem_description, coord_sys,coord_zone,coord_datum, coord_units, coord_SW_x,coord_SW_y, coord_NW_x,coord_NW_y, coord_NE_x,coord_NE_y, coord_SE_x,coord_SE_y, cell_size_x,cell_size_y, scaling_units, vertical_scaling, missing_value); writePNMimage(argv[2],image, width,height,2, comment); free(comment); return(0); }