/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Author: Piyush Agram # Copyright 2014, by the California Institute of Technology. ALL RIGHTS RESERVED. # United States Government Sponsorship acknowledged. # Any commercial use must be negotiated with the Office of Technology Transfer at # the California Institute of Technology. # This software may be subject to U.S. export control laws. # By accepting this software, the user agrees to comply with all applicable U.S. # export laws and regulations. User has the responsibility to obtain export licenses, # or other export authority as may be required before exporting such information to # foreign countries or providing access to foreign persons. # #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ #include "watermask.h" #include #include Polygon::Polygon() { npoints = 0; xy = NULL; } //Allocate memory void Polygon::allocate(int n) { npoints = n; xy = new double*[n]; for(int i=0; i 0) { //Deallocate memory for polygon for(int i=0; itesty) != (yj >testy)) && (testx < (xj-xi) * (testy-yi) / (yj-yi) + xi) ) c = 1-c; } // std::cout << testx << " " << testy << " " << c << std::endl; return c; } //Allocate memory WaterBody::WaterBody(int n) { nshapes = n; shapes = new Polygon[n]; } //Clear memory WaterBody::~WaterBody() { delete [] shapes; } //Check if given point is in water int WaterBody::isWater(double x, double y) { for(int i=0; i(line), width*sizeof(short)); } delete [] line; maskfile.close(); } void WaterBody::makemask(char* lonfile, char* latfile, char* outfile) { int i,j; double xx, yy; short * line; line = new short [width]; float *lat; float *lon; lat = new float[width]; lon = new float[width]; std::ofstream maskfile(outfile, std::ios::out | std::ios::binary); std::ifstream lonf(lonfile, std::ios::in | std::ios::binary); std::ifstream latf(lonfile, std::ios::in | std::ios::binary); // std::cout << "Dims : " << width << " " << height << std::endl; for(i=0; i< height;i++) { lonf.read((char*)(&lon[0]), sizeof(float)*width); latf.read((char*)(&lat[0]), sizeof(float)*width); if((i+1)%200 == 0) std::cout << "Line :" << i+1 << std::endl; for(j=0; j< width; j++) { xx = lon[j]; yy = lat[j]; line[j] = 1 - isWater(xx,yy); // std::cout << " " << xx << " " << yy << " " << line[j] << std::endl; } maskfile.write(reinterpret_cast(line), width*sizeof(short)); } delete [] lat; delete [] lon; delete [] line; maskfile.close(); lonf.close(); latf.close(); }