Skip to content

Commit

Permalink
Refactoring and fixes
Browse files Browse the repository at this point in the history
Changed copypixels from int to bool
Change logic in clearbounds to use separate input / output streams
  • Loading branch information
Ritchie333 committed Jun 12, 2024
1 parent b021275 commit 9ddf4a8
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 93 deletions.
56 changes: 20 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -121,14 +99,14 @@ add_executable(testcas

target_include_directories(warp-sabre PUBLIC
${PROJECT_SOURCE_DIR}/libmorph
${PROJECT_SOURCE_DIR}/newmat-10
)

target_link_libraries(warp-sabre
PRIVATE ImageMagick::MagickWand
PRIVATE Boost::system
PRIVATE morph
PRIVATE newmat
PRIVATE warp-sabre-lib
)

target_include_directories(gentiles PUBLIC
Expand All @@ -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
Expand All @@ -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
Expand All @@ -165,4 +147,6 @@ target_link_libraries(clearbounds
PRIVATE Boost::thread
PRIVATE Boost::system
PRIVATE morph
PRIVATE warp-sabre-lib
PRIVATE gentiles-lib
)
7 changes: 5 additions & 2 deletions src/ClearBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand Down
84 changes: 42 additions & 42 deletions src/CopyPixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand All @@ -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();
Expand All @@ -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))
Expand All @@ -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();
Expand All @@ -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);
Expand Down
22 changes: 11 additions & 11 deletions src/CopyPixels.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,18 +17,18 @@ 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
{
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
Expand All @@ -42,45 +42,45 @@ class CopyPixelsWithOsI : public CopyPixelsWithRawMask
{
public:
CopyPixelsWithOsI() {}
virtual int CheckIfInBox(double lat, double lon);
virtual bool CheckIfInBox(double lat, double lon);
};

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
{
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
{
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<double> gVertx;
Expand Down
Loading

0 comments on commit 9ddf4a8

Please sign in to comment.