diff --git a/CHANGELOG b/CHANGELOG index 046ea10..8e730db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ SIGNAL SERVER CHANGELOG +3.09 - 7 Feb 2018 +Meridian LIDAR cropping fix + 3.08 - 17 Dec 2017 Proper fix for nearfield void More LIDAR edge cases: 1x2, 2x1... diff --git a/inputs.cc b/inputs.cc index 57f9af3..7557d6d 100644 --- a/inputs.cc +++ b/inputs.cc @@ -166,6 +166,7 @@ int loadLIDAR(char *filenames, int resample) double TO_DEG = (180 / PI); FILE *fd; tile_t *tiles; + int eastF=0,westF=0; //flags for meridian fix // test for multiple files filename = strtok(filenames, " ,"); @@ -216,9 +217,15 @@ int loadLIDAR(char *filenames, int resample) if (tiles[indx].max_west > max_west) max_west = tiles[indx].max_west; + if (tiles[indx].min_west < min_west) min_west = tiles[indx].min_west; + if (tiles[indx].max_west > 358.0) + eastF=1; + if (tiles[indx].max_west < 2.0) + westF=1; + if (max_west == -1) { max_west = tiles[indx].max_west; } else { @@ -245,6 +252,16 @@ int loadLIDAR(char *filenames, int resample) } + // Meridian fix + if(eastF && westF){ + max_west=0; //reset + for (indx = 0; indx < fc; indx++) { + if(tiles[indx].max_west<2.0 && tiles[indx].max_west > max_west) + max_west=tiles[indx].max_west; + } + max_west*=1.0; // WGS84 to westing. -1.5 = 1.5 + + } /* Iterate through all of the tiles to find the smallest resolution. We will * need to rescale every tile from here on out to this value */ float smallest_res = 0; @@ -278,16 +295,21 @@ int loadLIDAR(char *filenames, int resample) } } + + + /* Now we work out the size of the giant lidar tile. */ double total_width = max_west - min_west >= 0 ? max_west - min_west : max_west + (360 - min_west); double total_height = max_north - min_north; if (debug) { fprintf(stderr,"totalh: %.7f - %.7f = %.7f totalw: %.7f - %.7f = %.7f fc: %d\n", max_north, min_north, total_height, max_west, min_west, total_width,fc); fprintf(stderr,"mw:%lf Mnw:%lf\n", max_west, min_west); + //exit(0); } + //detect problematic layouts eg. vertical rectangles // 1x2 - if(fc == 2 && desired_resolution < 28 && total_height > total_width){ + if(fc >= 2 && desired_resolution < 28 && total_height > total_width*1.2){ tiles[fc].max_north=max_north; tiles[fc].min_north=min_north; westoffset=westoffset-(total_height-total_width); // WGS84 for stdout only @@ -304,11 +326,11 @@ int loadLIDAR(char *filenames, int resample) //calculate deficit if (debug) { - fprintf(stderr,"deficit: %.4f cellsize: %.9f tiles needed to square: %.1f\n", total_width-total_height,avgCellsize,(total_width-total_height)/avgCellsize); + fprintf(stderr,"deficit: %.4f cellsize: %.9f tiles needed to square: %.1f, desired_resolution %d\n", total_width-total_height,avgCellsize,(total_width-total_height)/avgCellsize,desired_resolution); } } // 2x1 - if(fc == 2 && desired_resolution < 28 && total_width > total_height){ + if(fc >= 2 && desired_resolution < 28 && total_width > total_height*1.2){ tiles[fc].max_north=max_north+(total_width-total_height); tiles[fc].min_north=max_north; tiles[fc].max_west=max_west; // Positive westing diff --git a/main.cc b/main.cc index 316645f..ac2ed75 100644 --- a/main.cc +++ b/main.cc @@ -1,4 +1,4 @@ -double version = 3.08; +double version = 3.09; /****************************************************************************\ * Signal Server: Radio propagation simulator by Alex Farrant QCVS, 2E0TDW * ****************************************************************************** @@ -48,7 +48,7 @@ double earthradius, max_range = 0.0, forced_erp, dpp, ppd, yppd, fzone_clearance = 0.6, forced_freq, clutter, lat, lon, txh, tercon, terdic, north, east, south, west, dBm, loss, field_strength, min_north = 90, max_north = -90, min_west = 360, max_west = -1, westoffset=180, eastoffset=-180, delta=0, rxGain=0, - cropLat=-70, cropLon=0; + cropLat=-70, cropLon=0,cropLonNeg=0; int ippd, mpi, max_elevation = -32768, min_elevation = 32768, bzerror, contour_threshold, @@ -1714,13 +1714,26 @@ int main(int argc, char *argv[]) } ppd=(double) (height / (max_north-min_north)); - yppd=(double) (width / (max_west-min_west)); + //Meridian hack + if(max_west < 2 && min_west > 358){ + //yppd=(double) (width / (max_west+(360.0-min_west))); + yppd=ppd; + }else{ + yppd=(double) (width / (max_west-min_west)); + } + if(debug){ fprintf(stderr,"ppd %lf, yppd %lf, %.4f,%.4f,%.4f,%.4f,%d x %d\n",ppd,yppd,max_north,min_west,min_north,max_west,width,height); } + if(yppd0){ @@ -1831,7 +1844,7 @@ int main(int argc, char *argv[]) } } ppd=(double)ippd; - yppd=ppd; + //yppd=ppd; width = (unsigned)(ippd * ReduceAngle(max_west - min_west)); height = (unsigned)(ippd * ReduceAngle(max_north - min_north)); @@ -1886,25 +1899,26 @@ int main(int argc, char *argv[]) } if(cropping){ - // CROPPING. croplat assigned in propPathLoss() - max_north=cropLat; // MAX(path.lat[y]) - // Edge case #1 - EAST/WEST - if(cropLon>357 && tx_site[0].lon < 3) - cropLon=tx_site[0].lon+3; - // Edge case #2 - EAST/EAST - if(cropLon>359.5 && tx_site[0].lon > 359.5) - cropLon=362; - max_west=cropLon; // MAX(path.lon[y]) + // CROPPING. Factor is determined in propPathLoss(). + // cropLon is the circle radius in pixels at it's widest (east/west) + cropLon*=dpp; // pixels to degrees + max_north=cropLat; // degrees + max_west=cropLon+tx_site[0].lon; // degrees west (positive) cropLat-=tx_site[0].lat; // angle from tx to edge - cropLon-=tx_site[0].lon; - width=(int)((cropLon*ppd)*2); - height=(int)((cropLat*ppd)*2); - cropping = true; - if(width>3600*10){ - fprintf(stderr,"FATAL BOUNDS! max_west: %.4f cropLat: %.4f cropLon: %.4f longitude: %.5f\n",max_west,cropLat,cropLon,tx_site[0].lon); - return 0; - } + + if(debug) + fprintf(stderr,"Cropping 1: max_west: %.4f cropLat: %.4f cropLon: %.4f longitude: %.5f dpp %.7f\n",max_west,cropLat,cropLon,tx_site[0].lon,dpp); + width=(int)((cropLon*ppd)*2); + height=(int)((cropLat*ppd)*2); + + if(debug) + fprintf(stderr,"Cropping 2: max_west: %.4f cropLat: %.4f cropLon: %.7f longitude: %.5f width %d\n",max_west,cropLat,cropLon,tx_site[0].lon,width); + + if(width>3600*10 || cropLon < 0){ + fprintf(stderr,"FATAL BOUNDS! max_west: %.4f cropLat: %.4f cropLon: %.7f longitude: %.5f\n",max_west,cropLat,cropLon,tx_site[0].lon); + return 0; + } } // Write bitmap @@ -1918,10 +1932,10 @@ int main(int argc, char *argv[]) if( (result = DoSigStr(mapfile, geo, kml, ngs, tx_site,txsites)) != 0 ) return result; } - if(lidar){ + /*if(lidar){ east=eastoffset; west=westoffset; - } + }*/ if (tx_site[0].lon > 0.0){ tx_site[0].lon *= -1; diff --git a/models/los.cc b/models/los.cc index 52de478..87b48f4 100644 --- a/models/los.cc +++ b/models/los.cc @@ -687,8 +687,12 @@ void PlotPropPath(struct site source, struct site destination, if(path.lat[y]>cropLat) cropLat=path.lat[y]; - if(path.lon[y]>cropLon) - cropLon=path.lon[y]; + + if(y>cropLon) + cropLon=y; + + //if(cropLon>180) + // cropLon-=360; } void PlotLOSMap(struct site source, double altitude, char *plo_filename, diff --git a/outputs.cc b/outputs.cc index 6fdce53..322a942 100644 --- a/outputs.cc +++ b/outputs.cc @@ -109,11 +109,11 @@ void DoPathLoss(char *filename, unsigned char geo, unsigned char kml, ((double)dem[indx].max_west, lon))); // fix for multi-tile lidar - if(width==10000 && (indx==1 || indx==3)){ + /* if(width==10000 && (indx==1 || indx==3)){ if(y0 >= 3432){ //3535 y0=y0-3432; } - } + }*/ if (x0 >= 0 && x0 <= mpi && y0 >= 0 @@ -350,12 +350,12 @@ int DoSigStr(char *filename, unsigned char geo, unsigned char kml, lon))); // fix for multi-tile lidar - if(width==10000 && (indx==1 || indx==3)){ + /* if(width==10000 && (indx==1 || indx==3)){ if(y0 >= 3432){ //3535 y0=y0-3432; } } - + */ if (x0 >= 0 && x0 <= mpi && y0 >= 0 && y0 <= mpi) diff --git a/test.dcf b/test.dcf new file mode 100644 index 0000000..d6d5125 --- /dev/null +++ b/test.dcf @@ -0,0 +1,16 @@ + +0: 255, 0, 0 + -10: 255, 128, 0 + -20: 255, 165, 0 + -30: 255, 206, 0 + -40: 255, 255, 0 + -50: 184, 255, 0 + -60: 0, 255, 0 + -70: 0, 208, 0 + -80: 0, 196, 196 + -90: 0, 148, 255 +-100: 80, 80, 255 +-110: 0, 38, 255 +-120: 142, 63, 255 +-130: 196, 54, 255 +-140: 255, 0, 255 +-150: 255, 194, 204 diff --git a/tiles.cc b/tiles.cc index 186794d..87bc2df 100644 --- a/tiles.cc +++ b/tiles.cc @@ -53,7 +53,6 @@ int tile_load_lidar(tile_t *tile, char *filename){ tile->filename = strdup(filename); /* Perform xur calcs */ - // Degrees with GDAL option: -co "FORCE_CELLSIZE=YES" tile->xur = tile->xll+(tile->cellsize*tile->width); tile->yur = tile->yll+(tile->cellsize*tile->height); @@ -62,15 +61,15 @@ int tile_load_lidar(tile_t *tile, char *filename){ if (tile->xll < westoffset) westoffset = tile->xll; - // if (debug) - // fprintf(stderr,"%d, %d, %.7f, %.7f, %.7f, %.7f, %.7f\n",width,height,xll,yll,cellsize,yur,xur); + if (debug) + fprintf(stderr,"%d, %d, %.7f, %.7f, %.7f, %.7f, %.7f\n",tile->width,tile->height,tile->xll,tile->yll,tile->cellsize,tile->yur,tile->xur); // Greenwich straddling hack - // if (tile->xll <= 0 && tile->xur > 0) { - // tile->xll = (tile->xur - tile->xll); // full width - // tile->xur = 0.0; // budge it along so it's west of greenwich - // delta = eastoffset; // add to Tx longitude later - // } else { + /* if (tile->xll <= 0 && tile->xur > 0) { + tile->xll = (tile->xur - tile->xll); // full width + tile->xur = 0.0; // budge it along so it's west of greenwich + delta = eastoffset; // add to Tx longitude later + } else {*/ // Transform WGS84 longitudes into 'west' values as society finishes east of Greenwich ;) if (tile->xll >= 0) tile->xll = 360-tile->xll; @@ -121,6 +120,7 @@ int tile_load_lidar(tile_t *tile, char *filename){ // Round to nearest 0.5 tile->resolution = tile->precise_resolution < 0.5f ? 0.5f : ceil((tile->precise_resolution * 2)+0.5) / 2; + // Positive westing tile->width_deg = tile->max_west - tile->min_west >= 0 ? tile->max_west - tile->min_west : tile->max_west + (360 - tile->min_west); tile->height_deg = tile->max_north - tile->min_north;