diff --git a/CMakeLists.txt b/CMakeLists.txt index aef97a4..fdd5b67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,63 +55,41 @@ add_library(newmat STATIC src/newmat-10/newmat9.cpp ) -add_executable(warp-sabre +add_library(warp-sabre-lib STATIC src/ImageWarpByFunc.cpp src/ImgMagick.cpp - src/ReadDelimitedFile.cpp src/ProgramOptions.cpp + src/ReadDelimitedFile.cpp src/StringUtils.cpp src/Tile.cpp - src/TransformPoly.cpp - src/WarpOs.cpp - src/WriteKml.cpp src/ganzc/LatLong-OSGBconversion.cpp src/gbos1936/Gbos1936.cpp ) -add_executable(gentiles +add_library(gentiles-lib STATIC src/CopyPixels.cpp - src/GenTiles.cpp src/GetBounds.cpp src/ImageWarpByFunc.cpp - src/ImgMagick.cpp - src/ProgramOptions.cpp - src/ReadDelimitedFile.cpp src/ReadKmlFile.cpp src/SourceKml.cpp - src/StringUtils.cpp - src/Tile.cpp - src/gbos1936/Gbos1936.cpp +) + +add_executable(warp-sabre + src/TransformPoly.cpp + src/WarpOs.cpp + src/WriteKml.cpp +) + +add_executable(gentiles + src/GenTiles.cpp ) add_executable(cleartiles src/ClearTiles.cpp - src/CopyPixels.cpp - src/GetBounds.cpp - src/ImageWarpByFunc.cpp - src/ImgMagick.cpp - src/ProgramOptions.cpp - src/ReadDelimitedFile.cpp - src/ReadKmlFile.cpp - src/SourceKml.cpp - src/StringUtils.cpp - src/Tile.cpp - src/gbos1936/Gbos1936.cpp ) add_executable(clearbounds src/ClearBounds.cpp - src/CopyPixels.cpp - src/GetBounds.cpp - src/ImageWarpByFunc.cpp - src/ImgMagick.cpp - src/ProgramOptions.cpp - src/ReadDelimitedFile.cpp - src/ReadKmlFile.cpp - src/SourceKml.cpp - src/StringUtils.cpp - src/Tile.cpp - src/gbos1936/Gbos1936.cpp ) add_executable(testcas @@ -121,7 +99,6 @@ add_executable(testcas target_include_directories(warp-sabre PUBLIC ${PROJECT_SOURCE_DIR}/libmorph - ${PROJECT_SOURCE_DIR}/newmat-10 ) target_link_libraries(warp-sabre @@ -129,6 +106,7 @@ target_link_libraries(warp-sabre PRIVATE Boost::system PRIVATE morph PRIVATE newmat + PRIVATE warp-sabre-lib ) target_include_directories(gentiles PUBLIC @@ -141,6 +119,8 @@ target_link_libraries(gentiles PRIVATE Boost::thread PRIVATE Boost::system PRIVATE morph + PRIVATE warp-sabre-lib + PRIVATE gentiles-lib ) target_include_directories(cleartiles PUBLIC @@ -153,6 +133,8 @@ target_link_libraries(cleartiles PRIVATE Boost::thread PRIVATE Boost::system PRIVATE morph + PRIVATE warp-sabre-lib + PRIVATE gentiles-lib ) target_include_directories(clearbounds PUBLIC @@ -165,4 +147,6 @@ target_link_libraries(clearbounds PRIVATE Boost::thread PRIVATE Boost::system PRIVATE morph + PRIVATE warp-sabre-lib + PRIVATE gentiles-lib ) \ No newline at end of file diff --git a/src/ClearBounds.cpp b/src/ClearBounds.cpp index 3fb3d29..e3651a1 100644 --- a/src/ClearBounds.cpp +++ b/src/ClearBounds.cpp @@ -54,11 +54,14 @@ void ClearImage(const string &srcFilename, DelimitedFile &boundsFile, const int { mask->UpdateBoundingBox(srcKml.bounds[i].c_str()); } - mask->FastCopy(srcKml.image, srcKml.image, srcKml.tile, edge); + const ImgMagick& imgIn = srcKml.image; + ImgMagick imgOut( imgIn.GetWidth(), imgIn.GetHeight() ); + imgOut.Create(); + mask->FastCopy(imgIn, imgOut, srcKml.tile, edge); cout << "Saving file...." << endl; - srcKml.image.Save(srcKml.imgFilename.c_str()); + imgOut.Save(srcKml.imgFilename.c_str()); } int main(int argc, char *argv[]) diff --git a/src/CopyPixels.cpp b/src/CopyPixels.cpp index cc2c465..2deaccb 100644 --- a/src/CopyPixels.cpp +++ b/src/CopyPixels.cpp @@ -214,99 +214,99 @@ void CopyPixelsWithParisMercator::UpdateBoundingBox(const char *mapref) } } -int CopyPixelsWithOsMask::CheckIfInBox(double lat, double lon) +bool CopyPixelsWithOsMask::CheckIfInBox(double lat, double lon) { double pnorth, peast, palt; gConverter.ConvertWgs84ToGbos1936(lat, lon, 0.0, peast, pnorth, palt); if (pnorth < gsouth) - return 0; + return false; if (pnorth > gnorth) - return 0; + return false; if (peast < gwest) - return 0; + return false; if (peast > geast) - return 0; + return false; - return 1; + return true; } -int CopyPixelsWithOsI::CheckIfInBox(double lat, double lon) +bool CopyPixelsWithOsI::CheckIfInBox(double lat, double lon) { double pnorth, peast, palt; gConverter.ConvertWgs84ToOsi(lat, lon, 0.0, peast, pnorth, palt); if (pnorth < gsouth) - return 0; + return false; if (pnorth > gnorth) - return 0; + return false; if (peast < gwest) - return 0; + return false; if (peast > geast) - return 0; + return false; - return 1; + return true; } -int CopyPixelsWithCassini::CheckIfInBox(double lat, double lon) +bool CopyPixelsWithCassini::CheckIfInBox(double lat, double lon) { double pnorth, peast; gConverter.ConvertWgs84ToCas(lat, lon, 0.0, peast, pnorth); if (pnorth < gsouth) - return 0; + return false; if (pnorth > gnorth) - return 0; + return false; if (peast < gwest) - return 0; + return false; if (peast > geast) - return 0; - return 1; + return false; + return true; } -int CopyPixelsWithBonne::CheckIfInBox(double lat, double lon) +bool CopyPixelsWithBonne::CheckIfInBox(double lat, double lon) { double pnorth, peast; gConverter.ConvertWgs84ToBnS(lat, lon, 0.0, peast, pnorth); if (pnorth < gsouth) - return 0; + return false; if (pnorth > gnorth) - return 0; + return false; if (peast < gwest) - return 0; + return false; if (peast > geast) - return 0; - return 1; + return false; + return true; } -int CopyPixelsWithIrishBonne::CheckIfInBox(double lat, double lon) +bool CopyPixelsWithIrishBonne::CheckIfInBox(double lat, double lon) { double pnorth, peast; gConverter.ConvertWgs84ToBnI(lat, lon, 0.0, peast, pnorth); if (pnorth < gsouth) - return 0; + return false; if (pnorth > gnorth) - return 0; + return false; if (peast < gwest) - return 0; + return false; if (peast > geast) - return 0; - return 1; + return false; + return true; } -int CopyPixelsWithFrenchBonne::CheckIfInBox(double lat, double lon) +bool CopyPixelsWithFrenchBonne::CheckIfInBox(double lat, double lon) { double pnorth, peast; gConverter.ConvertWgs84ToBnF(lat, lon, 0.0, peast, pnorth); if (pnorth < gsouth) - return 0; + return false; if (pnorth > gnorth) - return 0; + return false; if (peast < gwest) - return 0; + return false; if (peast > geast) - return 0; - return 1; + return false; + return true; } -int CopyPixelsWithMercator::CheckIfInBox(double lat, double lon) +bool CopyPixelsWithMercator::CheckIfInBox(double lat, double lon) { int c = 0, i = 0, j = 0; for (i = 0, j = 3; i < 4; j = i++) @@ -320,7 +320,7 @@ int CopyPixelsWithMercator::CheckIfInBox(double lat, double lon) return c; } -void CopyPixels::FastCopy(class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const int tileSize) +void CopyPixels::FastCopy(const class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const int tileSize) { int width = imageIn.GetWidth(); int height = imageIn.GetHeight(); @@ -344,12 +344,12 @@ void CopyPixels::FastCopy(class ImgMagick &imageIn, class ImgMagick &imageOut, c } } -bool CopyPixels::CopyTile(class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const int i, const int j, const int k, const bool merge) +bool CopyPixels::CopyTile(const class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const int i, const int j, const int k, const bool merge) { double lat, lon; tile.UnProject(i, j, lat, lon); double val = imageIn.GetPix(i, j, k); - int inMask = this->CheckIfInBox(lat, lon); + bool inMask = this->CheckIfInBox(lat, lon); if (inMask) { if (!merge || (val > 0)) @@ -361,7 +361,7 @@ bool CopyPixels::CopyTile(class ImgMagick &imageIn, class ImgMagick &imageOut, c return false; } -void CopyPixels::Copy(class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const bool merge) +void CopyPixels::Copy(const class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const bool merge) { int width = imageIn.GetWidth(); int height = imageIn.GetHeight(); @@ -370,7 +370,7 @@ void CopyPixels::Copy(class ImgMagick &imageIn, class ImgMagick &imageOut, class // Check corners (quicker to check then exhaustively check each pixel) double lat, lon; tile.UnProject(0, 0, lat, lon); - int cornerCheck = this->CheckIfInBox(lat, lon); + bool cornerCheck = this->CheckIfInBox(lat, lon); tile.UnProject(width, 0, lat, lon); cornerCheck = cornerCheck && this->CheckIfInBox(lat, lon); tile.UnProject(width, height, lat, lon); diff --git a/src/CopyPixels.h b/src/CopyPixels.h index da969e8..2e74f56 100644 --- a/src/CopyPixels.h +++ b/src/CopyPixels.h @@ -3,7 +3,7 @@ class CopyPixels { private: - bool CopyTile(class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const int i, const int j, const int k, const bool merge); + bool CopyTile(const class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const int i, const int j, const int k, const bool merge); protected: double gnorth, gsouth, geast, gwest; @@ -17,10 +17,10 @@ class CopyPixels virtual ~CopyPixels(); virtual void UpdateBoundingBox(const char *mapref) = 0; - virtual int CheckIfInBox(double lat, double lon) = 0; - void Copy(class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const bool merge); + virtual bool CheckIfInBox(double lat, double lon) = 0; + void Copy(const class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const bool merge); // Like 'Copy' but only checks the outer 'n' pixels of an image. - void FastCopy(class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const int tileSize); + void FastCopy(const class ImgMagick &imageIn, class ImgMagick &imageOut, class Tile &tile, const int tileSize); }; class CopyPixelsWithOsMask : public CopyPixels @@ -28,7 +28,7 @@ class CopyPixelsWithOsMask : public CopyPixels public: CopyPixelsWithOsMask() {} virtual void UpdateBoundingBox(const char *mapref); - virtual int CheckIfInBox(double lat, double lon); + virtual bool CheckIfInBox(double lat, double lon); }; class CopyPixelsWithRawMask : public CopyPixelsWithOsMask @@ -42,7 +42,7 @@ class CopyPixelsWithOsI : public CopyPixelsWithRawMask { public: CopyPixelsWithOsI() {} - virtual int CheckIfInBox(double lat, double lon); + virtual bool CheckIfInBox(double lat, double lon); }; class CopyPixelsWithCassini : public CopyPixels @@ -50,7 +50,7 @@ class CopyPixelsWithCassini : public CopyPixels public: CopyPixelsWithCassini() {} virtual void UpdateBoundingBox(const char *mapref); - virtual int CheckIfInBox(double lat, double lon); + virtual bool CheckIfInBox(double lat, double lon); }; class CopyPixelsWithBonne : public CopyPixels @@ -58,21 +58,21 @@ class CopyPixelsWithBonne : public CopyPixels public: CopyPixelsWithBonne() {} virtual void UpdateBoundingBox(const char *mapref); - virtual int CheckIfInBox(double lat, double lon); + virtual bool CheckIfInBox(double lat, double lon); }; class CopyPixelsWithIrishBonne : public CopyPixelsWithBonne { public: CopyPixelsWithIrishBonne() {} - virtual int CheckIfInBox(double lat, double lon); + virtual bool CheckIfInBox(double lat, double lon); }; class CopyPixelsWithFrenchBonne : public CopyPixelsWithBonne { public: CopyPixelsWithFrenchBonne() {} - virtual int CheckIfInBox(double lat, double lon); + virtual bool CheckIfInBox(double lat, double lon); }; class CopyPixelsWithMercator : public CopyPixels @@ -80,7 +80,7 @@ class CopyPixelsWithMercator : public CopyPixels public: CopyPixelsWithMercator() {} virtual void UpdateBoundingBox(const char *mapref); - virtual int CheckIfInBox(double lat, double lon); + virtual bool CheckIfInBox(double lat, double lon); protected: std::vector gVertx; diff --git a/src/ImgMagick.cpp b/src/ImgMagick.cpp index bb6abdc..6f372ae 100644 --- a/src/ImgMagick.cpp +++ b/src/ImgMagick.cpp @@ -95,7 +95,7 @@ void ImgMagick::Clear() raw = 0; } -int ImgMagick::Ready() +int ImgMagick::Ready() const { return (raw != 0); } diff --git a/src/ImgMagick.h b/src/ImgMagick.h index e87bb0d..8fc747d 100644 --- a/src/ImgMagick.h +++ b/src/ImgMagick.h @@ -17,7 +17,7 @@ class ImgMagick : public ImgFrameBase virtual int Save(const char *filename); virtual void Clear(); virtual void Close(); - virtual int Ready(); + virtual int Ready() const; // Pixel data virtual double GetPix(int x, int y, unsigned int channel) const;