[mapguide-commits] r9494 - in sandbox/jng/tiling_v2/Server/src: Services/Rendering UnitTesting
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Tue Apr 23 20:20:39 PDT 2019
Author: jng
Date: 2019-04-23 20:20:38 -0700 (Tue, 23 Apr 2019)
New Revision: 9494
Modified:
sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.cpp
sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.h
sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.cpp
sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.h
Log:
Consolidate the scaled dimension computation into a utility method
Modified: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.cpp
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.cpp 2019-04-23 04:05:11 UTC (rev 9493)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.cpp 2019-04-24 03:20:38 UTC (rev 9494)
@@ -341,48 +341,11 @@
if (tileExtentOffset < 0.0)
tileExtentOffset = MgConfigProperties::DefaultRenderingServicePropertyTileExtentOffset;
- // Image scaling logic ripped verbatim from RenderMap() overload that takes MgEnvelope
- //
- // If we need to scale the image (because of request for non-square
- // pixels) we will need to draw at one image size and then save at
- // another scaled size. Here we will compute the correct map scale
- // and render size for a requested extent and image size.
- double screenAR = (double)width / (double)height;
- double mapAR = extent.width() / extent.height();
-
- int drawWidth = width;
- int drawHeight = height;
+ INT32 drawWidth = width;
+ INT32 drawHeight = height;
double scale = 0.0;
+ ComputeScaledDimensions(extent, width, height, dpi, map->GetMetersPerUnit(), drawWidth, drawHeight, scale);
- if (mapAR >= screenAR)
- {
- scale = extent.width() * map->GetMetersPerUnit() / METERS_PER_INCH * (double)dpi / (double)width;
-
- // we based map scale on the image width, so adjust rendering
- // height to match the map aspect ratio
- drawHeight = (int)(width / mapAR);
-
- // ignore small perturbations in order to avoid rescaling the
- // end image in cases where the rescaling of width is less than
- // a pixel or so
- if (abs(drawHeight - height) <= 1)
- drawHeight = height;
- }
- else
- {
- scale = extent.height() * map->GetMetersPerUnit() / METERS_PER_INCH * (double)dpi / (double)height;
-
- // we based map scale on the image height, so adjust rendering
- // height to match the map aspect ratio
- drawWidth = (int)(height * mapAR);
-
- // ignore small perturbations, in order to avoid rescaling the
- // end image in cases where the rescaling of width is less than
- // a pixel or so
- if (abs(drawWidth - width) <= 1)
- drawWidth = width;
- }
-
//printf("XYZ(%d, %d, %d) -> [%f, %f] [%f, %f] at %f -- (w: %d, h: %d, mpu: %f)\n", x, y, z, mcsMinX, mcsMinY, mcsMaxX, mcsMaxY, scale, width, height, map->GetMetersPerUnit());
// sanity check - number of image pixels cannot exceed MAX_PIXELS
@@ -865,46 +828,11 @@
RS_Bounds b(ll->GetX(), ll->GetY(), ur->GetX(), ur->GetY());
- // If we need to scale the image (because of request for non-square
- // pixels) we will need to draw at one image size and then save at
- // another scaled size. Here we will compute the correct map scale
- // and render size for a requested extent and image size.
- double screenAR = (double)width / (double)height;
- double mapAR = b.width() / b.height();
-
- int drawWidth = width;
- int drawHeight = height;
+ INT32 drawWidth = width;
+ INT32 drawHeight = height;
double scale = 0.0;
+ ComputeScaledDimensions(b, width, height, dpi, metersPerUnit, drawWidth, drawHeight, scale);
- if (mapAR >= screenAR)
- {
- scale = b.width() * metersPerUnit / METERS_PER_INCH * (double)dpi / (double)width;
-
- // we based map scale on the image width, so adjust rendering
- // height to match the map aspect ratio
- drawHeight = (int)(width / mapAR);
-
- // ignore small perturbations in order to avoid rescaling the
- // end image in cases where the rescaling of width is less than
- // a pixel or so
- if (abs(drawHeight - height) <= 1)
- drawHeight = height;
- }
- else
- {
- scale = b.height() * metersPerUnit / METERS_PER_INCH * (double)dpi / (double)height;
-
- // we based map scale on the image height, so adjust rendering
- // height to match the map aspect ratio
- drawWidth = (int)(height * mapAR);
-
- // ignore small perturbations, in order to avoid rescaling the
- // end image in cases where the rescaling of width is less than
- // a pixel or so
- if (abs(drawWidth - width) <= 1)
- drawWidth = width;
- }
-
// sanity check - number of image pixels cannot exceed MAX_PIXELS
if (drawWidth * drawHeight > MAX_PIXELS)
throw new MgOutOfRangeException(L"MgServerRenderingService.RenderMap", __LINE__, __WFILE__, NULL, L"MgInvalidImageSizeTooBig", NULL);
@@ -2573,48 +2501,11 @@
StylizationUtil::ParseColor(map->GetBackgroundColor(), bgColor);
bgColor.alpha() = 0;
- // Image scaling logic ripped verbatim from RenderMap() overload that takes MgEnvelope
- //
- // If we need to scale the image (because of request for non-square
- // pixels) we will need to draw at one image size and then save at
- // another scaled size. Here we will compute the correct map scale
- // and render size for a requested extent and image size.
- double screenAR = (double)width / (double)height;
- double mapAR = extent.width() / extent.height();
-
- int drawWidth = width;
- int drawHeight = height;
+ INT32 drawWidth = width;
+ INT32 drawHeight = height;
double scale = 0.0;
+ ComputeScaledDimensions(extent, width, height, dpi, map->GetMetersPerUnit(), drawWidth, drawHeight, scale);
- if (mapAR >= screenAR)
- {
- scale = extent.width() * map->GetMetersPerUnit() / METERS_PER_INCH * (double)dpi / (double)width;
-
- // we based map scale on the image width, so adjust rendering
- // height to match the map aspect ratio
- drawHeight = (int)(width / mapAR);
-
- // ignore small perturbations in order to avoid rescaling the
- // end image in cases where the rescaling of width is less than
- // a pixel or so
- if (abs(drawHeight - height) <= 1)
- drawHeight = height;
- }
- else
- {
- scale = extent.height() * map->GetMetersPerUnit() / METERS_PER_INCH * (double)dpi / (double)height;
-
- // we based map scale on the image height, so adjust rendering
- // height to match the map aspect ratio
- drawWidth = (int)(height * mapAR);
-
- // ignore small perturbations, in order to avoid rescaling the
- // end image in cases where the rescaling of width is less than
- // a pixel or so
- if (abs(drawWidth - width) <= 1)
- drawWidth = width;
- }
-
//printf("XYZ(%d, %d, %d) -> [%f, %f] [%f, %f] at %f -- (w: %d, h: %d, mpu: %f)\n", x, y, z, mcsMinX, mcsMinY, mcsMaxX, mcsMaxY, scale, width, height, map->GetMetersPerUnit());
// sanity check - number of image pixels cannot exceed MAX_PIXELS
@@ -2649,4 +2540,49 @@
MG_CATCH_AND_THROW(L"MgServerRenderingService.RenderTileXYZ")
return ret.Detach();
+}
+
+void MgServerRenderingService::ComputeScaledDimensions(RS_Bounds& extent, INT32 width, INT32 height, INT32 dpi,
+ double metersPerUnit, INT32& drawWidth, INT32& drawHeight,
+ double& scale)
+{
+ // If we need to scale the image (because of request for non-square
+ // pixels) we will need to draw at one image size and then save at
+ // another scaled size. Here we will compute the correct map scale
+ // and render size for a requested extent and image size.
+ double screenAR = (double)width / (double)height;
+ double mapAR = extent.width() / extent.height();
+
+ drawWidth = width;
+ drawHeight = height;
+ scale = 0.0;
+
+ if (mapAR >= screenAR)
+ {
+ scale = extent.width() * metersPerUnit / METERS_PER_INCH * (double)dpi / (double)width;
+
+ // we based map scale on the image width, so adjust rendering
+ // height to match the map aspect ratio
+ drawHeight = (int)(width / mapAR);
+
+ // ignore small perturbations in order to avoid rescaling the
+ // end image in cases where the rescaling of width is less than
+ // a pixel or so
+ if (abs(drawHeight - height) <= 1)
+ drawHeight = height;
+ }
+ else
+ {
+ scale = extent.height() * metersPerUnit / METERS_PER_INCH * (double)dpi / (double)height;
+
+ // we based map scale on the image height, so adjust rendering
+ // height to match the map aspect ratio
+ drawWidth = (int)(height * mapAR);
+
+ // ignore small perturbations, in order to avoid rescaling the
+ // end image in cases where the rescaling of width is less than
+ // a pixel or so
+ if (abs(drawWidth - width) <= 1)
+ drawWidth = width;
+ }
}
\ No newline at end of file
Modified: sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.h
===================================================================
--- sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.h 2019-04-23 04:05:11 UTC (rev 9493)
+++ sandbox/jng/tiling_v2/Server/src/Services/Rendering/ServerRenderingService.h 2019-04-24 03:20:38 UTC (rev 9494)
@@ -268,6 +268,9 @@
INT32 metaTileFactor, INT32 subTileX, INT32 subTileY);
private:
+ static void ComputeScaledDimensions(RS_Bounds& extent, INT32 width, INT32 height, INT32 dpi,
+ double metersPerUnit, INT32& drawWidth, INT32& drawHeight, double& scale);
+
static void ComputeXYZTileExtents(MgMap* map, INT32 x, INT32 y, INT32 z, RS_Bounds& extent);
// used for tile generation
MgByteReader* RenderTileInternal(MgMap* map,
Modified: sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.cpp
===================================================================
--- sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.cpp 2019-04-23 04:05:11 UTC (rev 9493)
+++ sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.cpp 2019-04-24 03:20:38 UTC (rev 9494)
@@ -1716,37 +1716,22 @@
}
}
-void TestRenderingService::TestCase_RenderTileBaseline()
+void TestRenderingService::TestCase_RenderMetatile(CREFSTRING imageFormat, CREFSTRING extension)
{
try
{
Ptr<MgMap> map = CreateTestTiledMap();
map->SetViewScale(12500.0);
- Ptr<MgByteReader> tile4_6 = m_svcRendering->RenderTile(map, L"BaseLayers", 4, 6);
- Ptr<MgByteReader> tile4_7 = m_svcRendering->RenderTile(map, L"BaseLayers", 4, 7);
- Ptr<MgByteReader> tile5_6 = m_svcRendering->RenderTile(map, L"BaseLayers", 5, 6);
- Ptr<MgByteReader> tile5_7 = m_svcRendering->RenderTile(map, L"BaseLayers", 5, 7);
+ Ptr<MgByteReader> tile4_6_baseline = m_svcRendering->RenderTile(map, L"BaseLayers", 4, 6, MgTileParameters::tileWidth, MgTileParameters::tileHeight, MgTileParameters::tileDPI, imageFormat);
+ Ptr<MgByteReader> tile4_7_baseline = m_svcRendering->RenderTile(map, L"BaseLayers", 4, 7, MgTileParameters::tileWidth, MgTileParameters::tileHeight, MgTileParameters::tileDPI, imageFormat);
+ Ptr<MgByteReader> tile5_6_baseline = m_svcRendering->RenderTile(map, L"BaseLayers", 5, 6, MgTileParameters::tileWidth, MgTileParameters::tileHeight, MgTileParameters::tileDPI, imageFormat);
+ Ptr<MgByteReader> tile5_7_baseline = m_svcRendering->RenderTile(map, L"BaseLayers", 5, 7, MgTileParameters::tileWidth, MgTileParameters::tileHeight, MgTileParameters::tileDPI, imageFormat);
- tile4_6->ToFile(L"../UnitTestFiles/RenderTile_4_6_Baseline.png");
- tile4_7->ToFile(L"../UnitTestFiles/RenderTile_4_7_Baseline.png");
- tile5_6->ToFile(L"../UnitTestFiles/RenderTile_5_6_Baseline.png");
- tile5_7->ToFile(L"../UnitTestFiles/RenderTile_5_7_Baseline.png");
- }
- catch (MgException* e)
- {
- STRING message = e->GetDetails(TEST_LOCALE);
- SAFE_RELEASE(e);
- CPPUNIT_FAIL(MG_WCHAR_TO_CHAR(message.c_str()));
- }
-}
+ tile4_6_baseline->ToFile(GetPath(L"../UnitTestFiles/RenderTile_4_6_Baseline", imageFormat, extension));
+ tile4_7_baseline->ToFile(GetPath(L"../UnitTestFiles/RenderTile_4_7_Baseline", imageFormat, extension));
+ tile5_6_baseline->ToFile(GetPath(L"../UnitTestFiles/RenderTile_5_6_Baseline", imageFormat, extension));
+ tile5_7_baseline->ToFile(GetPath(L"../UnitTestFiles/RenderTile_5_7_Baseline", imageFormat, extension));
-void TestRenderingService::TestCase_RenderMetatile()
-{
- try
- {
- Ptr<MgMap> map = CreateTestTiledMap();
- map->SetViewScale(12500.0);
-
//This should be a server impl
MgServerRenderingService* renderSvc = dynamic_cast<MgServerRenderingService*>(m_svcRendering.p);
CPPUNIT_ASSERT(NULL != renderSvc);
@@ -1753,21 +1738,21 @@
// Render a 2x2 metatile which should cover the same tiles as the baseline test.
INT32 metaTileFactor = 2;
- Ptr<MgByteReader> metaTile = renderSvc->RenderTile(map, L"BaseLayers", 4, 6, MgTileParameters::tileWidth, MgTileParameters::tileHeight, MgTileParameters::tileDPI, MgImageFormats::Png, MgConfigProperties::DefaultRenderingServicePropertyTileExtentOffset, metaTileFactor);
+ Ptr<MgByteReader> metaTile = renderSvc->RenderTile(map, L"BaseLayers", 4, 6, MgTileParameters::tileWidth, MgTileParameters::tileHeight, MgTileParameters::tileDPI, imageFormat, MgConfigProperties::DefaultRenderingServicePropertyTileExtentOffset, metaTileFactor);
//metaTile->ToFile(L"../UnitTestFiles/RenderTile_Metatile at 4_6.png");
//CPPUNIT_ASSERT(metaTile->IsRewindable());
//metaTile->Rewind();
- Ptr<MgByteReader> tile4_6 = renderSvc->RenderTileFromMetaTile(map, metaTile, MgImageFormats::Png, MgTileParameters::tileWidth, MgTileParameters::tileHeight, 2, 0, 0);
- Ptr<MgByteReader> tile4_7 = renderSvc->RenderTileFromMetaTile(map, metaTile, MgImageFormats::Png, MgTileParameters::tileWidth, MgTileParameters::tileHeight, 2, 0, 1);
- Ptr<MgByteReader> tile5_6 = renderSvc->RenderTileFromMetaTile(map, metaTile, MgImageFormats::Png, MgTileParameters::tileWidth, MgTileParameters::tileHeight, 2, 1, 0);
- Ptr<MgByteReader> tile5_7 = renderSvc->RenderTileFromMetaTile(map, metaTile, MgImageFormats::Png, MgTileParameters::tileWidth, MgTileParameters::tileHeight, 2, 1, 1);
+ Ptr<MgByteReader> tile4_6 = renderSvc->RenderTileFromMetaTile(map, metaTile, imageFormat, MgTileParameters::tileWidth, MgTileParameters::tileHeight, 2, 0, 0);
+ Ptr<MgByteReader> tile4_7 = renderSvc->RenderTileFromMetaTile(map, metaTile, imageFormat, MgTileParameters::tileWidth, MgTileParameters::tileHeight, 2, 0, 1);
+ Ptr<MgByteReader> tile5_6 = renderSvc->RenderTileFromMetaTile(map, metaTile, imageFormat, MgTileParameters::tileWidth, MgTileParameters::tileHeight, 2, 1, 0);
+ Ptr<MgByteReader> tile5_7 = renderSvc->RenderTileFromMetaTile(map, metaTile, imageFormat, MgTileParameters::tileWidth, MgTileParameters::tileHeight, 2, 1, 1);
- tile4_6->ToFile(L"../UnitTestFiles/RenderTile_4_6_Metatiled.png");
- tile4_7->ToFile(L"../UnitTestFiles/RenderTile_4_7_Metatiled.png");
- tile5_6->ToFile(L"../UnitTestFiles/RenderTile_5_6_Metatiled.png");
- tile5_7->ToFile(L"../UnitTestFiles/RenderTile_5_7_Metatiled.png");
+ tile4_6->ToFile(GetPath(L"../UnitTestFiles/RenderTile_4_6_Metatiled", imageFormat, extension));
+ tile4_7->ToFile(GetPath(L"../UnitTestFiles/RenderTile_4_7_Metatiled", imageFormat, extension));
+ tile5_6->ToFile(GetPath(L"../UnitTestFiles/RenderTile_5_6_Metatiled", imageFormat, extension));
+ tile5_7->ToFile(GetPath(L"../UnitTestFiles/RenderTile_5_7_Metatiled", imageFormat, extension));
}
catch (MgException* e)
{
Modified: sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.h
===================================================================
--- sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.h 2019-04-23 04:05:11 UTC (rev 9493)
+++ sandbox/jng/tiling_v2/Server/src/UnitTesting/TestRenderingService.h 2019-04-24 03:20:38 UTC (rev 9494)
@@ -25,8 +25,10 @@
CPPUNIT_TEST_SUITE(TestRenderingService);
CPPUNIT_TEST(TestStart); // This must be the very first unit test
- CPPUNIT_TEST(TestCase_RenderTileBaseline);
- CPPUNIT_TEST(TestCase_RenderMetatile);
+ CPPUNIT_TEST(TestCase_RenderMetatilePNG);
+ CPPUNIT_TEST(TestCase_RenderMetatilePNG8);
+ CPPUNIT_TEST(TestCase_RenderMetatileJPG);
+ CPPUNIT_TEST(TestCase_RenderMetatileGIF);
CPPUNIT_TEST(TestCase_StylizationFunctionsPNG);
@@ -161,8 +163,7 @@
void TestEnd();
void TestCase_QueryFeatures();
- void TestCase_RenderTileBaseline();
- void TestCase_RenderMetatile();
+ void TestCase_RenderMetatile(CREFSTRING imageFormat, CREFSTRING extension);
void TestCase_RenderTile(CREFSTRING imageFormat, CREFSTRING extension);
void TestCase_RenderTileXYZ(CREFSTRING imageFormat, CREFSTRING extension);
@@ -306,6 +307,11 @@
//void TestCase_RendererPerformance();
+ void TestCase_RenderMetatilePNG() { TestCase_RenderMetatile(L"PNG", L"png"); }
+ void TestCase_RenderMetatilePNG8() { TestCase_RenderMetatile(L"PNG8", L"png"); }
+ void TestCase_RenderMetatileJPG() { TestCase_RenderMetatile(L"JPG", L"jpg"); }
+ void TestCase_RenderMetatileGIF() { TestCase_RenderMetatile(L"GIF", L"gif"); }
+
private:
MgMap* CreateTestMap();
MgMap* CreateTestTiledMap();
More information about the mapguide-commits
mailing list