Address some review comments

This commit is contained in:
Ashley Rogers 2025-06-03 11:00:18 -04:00
parent ee98084630
commit 0ac80a9405
12 changed files with 60 additions and 121 deletions

View File

@ -163,5 +163,7 @@ void ImageAsset::convertToChannels(
this->pixelData = std::move(newPixelData);
}
this->channels = newChannels;
}
} // namespace CesiumGltf

View File

@ -36,6 +36,8 @@ TEST_CASE("ImageAsset::convertToChannels") {
CHECK(asset.pixelData[5] == std::byte{0x11});
CHECK(asset.pixelData[6] == std::byte{0x9a});
CHECK(asset.pixelData[7] == std::byte{0x9b});
CHECK(asset.channels == 2);
CHECK(asset.pixelData.size() == 8);
}
SUBCASE("Converts to more channels") {
@ -56,5 +58,7 @@ TEST_CASE("ImageAsset::convertToChannels") {
CHECK(asset.pixelData[5] == std::byte{0x99});
CHECK(asset.pixelData[6] == std::byte{0xde});
CHECK(asset.pixelData[7] == std::byte{0x99});
CHECK(asset.channels == 2);
CHECK(asset.pixelData.size() == 8);
}
}

View File

@ -7,8 +7,8 @@
#include <CesiumRasterOverlays/Library.h>
#include <CesiumRasterOverlays/RasterOverlay.h>
#include <CesiumRasterOverlays/RasterOverlayTileProvider.h>
#include <CesiumUtility/Color.h>
#include <CesiumUtility/IntrusivePointer.h>
#include <CesiumVectorData/Color.h>
#include <CesiumVectorData/GeoJsonDocument.h>
#include <CesiumVectorData/GeoJsonObject.h>
#include <CesiumVectorData/VectorStyle.h>

View File

@ -10,9 +10,9 @@
#include <CesiumRasterOverlays/RasterOverlayTile.h>
#include <CesiumRasterOverlays/RasterOverlayTileProvider.h>
#include <CesiumRasterOverlays/RasterizedPolygonsOverlay.h>
#include <CesiumUtility/Color.h>
#include <CesiumUtility/CreditSystem.h>
#include <CesiumUtility/IntrusivePointer.h>
#include <CesiumVectorData/Color.h>
#include <CesiumVectorData/VectorRasterizer.h>
#include <CesiumVectorData/VectorStyle.h>
@ -43,15 +43,15 @@ void rasterizePolygons(
CesiumGltf::ImageAsset& image = loaded.pImage.emplace();
std::byte insideColor;
std::byte outsideColor;
uint8_t insideColor;
uint8_t outsideColor;
if (invertSelection) {
insideColor = static_cast<std::byte>(0);
outsideColor = static_cast<std::byte>(0xff);
insideColor = 0;
outsideColor = 0xff;
} else {
insideColor = static_cast<std::byte>(0xff);
outsideColor = static_cast<std::byte>(0);
insideColor = 0xff;
outsideColor = 0;
}
// create a 1x1 mask if the rectangle is completely inside a polygon
@ -63,7 +63,7 @@ void rasterizePolygons(
image.height = 1;
image.channels = 1;
image.bytesPerChannel = 1;
image.pixelData.resize(1, insideColor);
image.pixelData.resize(1, std::byte{insideColor});
return;
}
@ -86,7 +86,7 @@ void rasterizePolygons(
image.height = 1;
image.channels = 1;
image.bytesPerChannel = 1;
image.pixelData.resize(1, outsideColor);
image.pixelData.resize(1, std::byte{outsideColor});
return;
}
@ -96,24 +96,19 @@ void rasterizePolygons(
image.height = int32_t(glm::round(textureSize.y));
image.channels = 4;
image.bytesPerChannel = 1;
image.pixelData.resize(size_t(image.width * image.height * 4), outsideColor);
image.pixelData.resize(
size_t(image.width * image.height * 4),
std::byte{outsideColor});
CesiumVectorData::VectorRasterizer rasterizer(
rectangle,
loaded.pImage,
0,
ellipsoid);
rasterizer.clear(CesiumVectorData::Color{
outsideColor,
std::byte{0x00},
std::byte{0x00},
std::byte{0xff}});
rasterizer.clear(CesiumUtility::Color{outsideColor, 0x00, 0x00, 0xff});
CesiumVectorData::VectorStyle insideStyle{CesiumVectorData::Color{
insideColor,
std::byte{0x00},
std::byte{0x00},
std::byte{0xff}}};
CesiumVectorData::VectorStyle insideStyle{
CesiumUtility::Color{insideColor, 0x00, 0x00, 0xff}};
for (const CartographicPolygon& selection : cartographicPolygons) {
rasterizer.drawPolygon(selection, insideStyle);
}

View File

@ -1,7 +1,5 @@
#include "CesiumAsync/Future.h"
#include "CesiumVectorData/VectorStyle.h"
#include <CesiumAsync/AsyncSystem.h>
#include <CesiumAsync/Future.h>
#include <CesiumAsync/IAssetAccessor.h>
#include <CesiumGeospatial/BoundingRegionBuilder.h>
#include <CesiumGeospatial/Cartographic.h>
@ -23,6 +21,7 @@
#include <CesiumVectorData/GeoJsonDocument.h>
#include <CesiumVectorData/GeoJsonObject.h>
#include <CesiumVectorData/VectorRasterizer.h>
#include <CesiumVectorData/VectorStyle.h>
#include <fmt/format.h>
#include <glm/common.hpp>
@ -546,23 +545,10 @@ public:
private:
void recomputeStyles(GeoJsonObject* pObject) {
struct SetStyleVisitor {
const std::optional<VectorStyle>& style;
void operator()(GeoJsonPoint& o) { o.style = style; }
void operator()(GeoJsonMultiPoint& o) { o.style = style; }
void operator()(GeoJsonLineString& o) { o.style = style; }
void operator()(GeoJsonMultiLineString& o) { o.style = style; }
void operator()(GeoJsonPolygon& o) { o.style = style; }
void operator()(GeoJsonMultiPolygon& o) { o.style = style; }
void operator()(GeoJsonFeature& o) { o.style = style; }
void operator()(GeoJsonFeatureCollection& o) { o.style = style; }
void operator()(GeoJsonGeometryCollection& o) { o.style = style; }
};
if (this->_styleCallback) {
const std::optional<VectorStyle>& style =
(*this->_styleCallback)(this->_document, pObject);
std::visit(SetStyleVisitor{style}, pObject->value);
pObject->getStyle() = style;
}
struct RecomputeChildStylesVisitor {

View File

@ -1,36 +1,20 @@
#pragma once
#include <cstddef>
#include <cstdint>
namespace CesiumVectorData {
namespace CesiumUtility {
/**
* @brief Represents an RGBA color value.
*/
struct Color {
/** @brief The red component. */
std::byte r;
uint32_t r;
/** @brief The green component. */
std::byte g;
uint32_t g;
/** @brief The blue component. */
std::byte b;
uint32_t b;
/** @brief The alpha component. */
std::byte a;
/**
* @brief Creates a new Color from the given components.
*
* @param r_ The red component.
* @param g_ The green component.
* @param b_ The blue component.
* @param a_ The alpha component.
*/
Color(
std::byte r_,
std::byte g_,
std::byte b_,
std::byte a_ = std::byte{0xff})
: r(r_), g(g_), b(b_), a(a_) {}
uint32_t a;
/**
* @brief Creates a new Color from the given components.
@ -41,10 +25,7 @@ struct Color {
* @param a_ The alpha component.
*/
Color(uint8_t r_, uint8_t g_, uint8_t b_, uint8_t a_ = 0xff)
: r(std::byte{r_}),
g(std::byte{g_}),
b(std::byte{b_}),
a(std::byte{a_}) {}
: r(r_), g(g_), b(b_), a(a_) {}
/**
* @brief Converts this color to a packed 32-bit number in the form
@ -52,4 +33,4 @@ struct Color {
*/
uint32_t toRgba32() const;
};
} // namespace CesiumVectorData
} // namespace CesiumUtility

View File

@ -0,0 +1,7 @@
#include <CesiumUtility/Color.h>
namespace CesiumUtility {
uint32_t Color::toRgba32() const {
return this->a << 24 | this->r << 16 | this->g << 8 | this->b;
}
} // namespace CesiumUtility

View File

@ -1,7 +1,5 @@
#pragma once
#include "CesiumGeospatial/Cartographic.h"
#include "Color.h"
#include "VectorStyle.h"
#include <CesiumGeometry/Rectangle.h>
@ -9,6 +7,7 @@
#include <CesiumGeospatial/Ellipsoid.h>
#include <CesiumGeospatial/GlobeRectangle.h>
#include <CesiumGltf/ImageAsset.h>
#include <CesiumUtility/Color.h>
#include <CesiumUtility/IntrusivePointer.h>
#include <CesiumUtility/ReferenceCounted.h>
#include <CesiumVectorData/GeoJsonObject.h>
@ -35,7 +34,7 @@ public:
* @param imageAsset The destination image asset. This \ref
* CesiumGltf::ImageAsset must be four channels, with
* only one byte per channel (RGBA32).
* @param mipLevel The rasterizer will rasterize the given mip level for the
* @param mipLevel The mip level that the rasterizer should rasterize for the
* image.
* @param ellipsoid The ellipsoid to use.
*/
@ -98,7 +97,7 @@ public:
*
* @param clearColor The color to use to clear the canvas.
*/
void clear(const Color& clearColor);
void clear(const CesiumUtility::Color& clearColor);
/**
* @brief Finalizes the rasterization operations, flushing all draw calls to

View File

@ -1,6 +1,6 @@
#pragma once
#include "Color.h"
#include <CesiumUtility/Color.h>
namespace CesiumVectorData {
@ -27,7 +27,7 @@ enum class ColorMode : uint8_t {
*/
struct ColorStyle {
/** @brief The color to be used. */
Color color = Color(0xff, 0xff, 0xff, 0xff);
CesiumUtility::Color color = CesiumUtility::Color(0xff, 0xff, 0xff, 0xff);
/** @brief The color mode to be used. */
ColorMode colorMode = ColorMode::Normal;
@ -38,7 +38,7 @@ struct ColorStyle {
* `ColorMode::Random`, this returns a randomized value obtained based on
* the rules described in \ref ColorMode.
*/
Color getColor() const;
CesiumUtility::Color getColor() const;
};
/** @brief The style used to draw a Polygon. */
@ -106,6 +106,7 @@ struct VectorStyle {
/**
* @brief Initializes all styles to the given color.
*/
VectorStyle(const Color& color) : line{{color}}, polygon{{color}} {}
VectorStyle(const CesiumUtility::Color& color)
: line{{color}}, polygon{{color}} {}
};
} // namespace CesiumVectorData

View File

@ -1,10 +0,0 @@
#include <CesiumVectorData/Color.h>
#include <cstdint>
namespace CesiumVectorData {
uint32_t Color::toRgba32() const {
return (uint32_t)this->a << 24 | (uint32_t)this->r << 16 |
(uint32_t)this->g << 8 | (uint32_t)this->b;
}
} // namespace CesiumVectorData

View File

@ -4,8 +4,8 @@
#include <CesiumGeospatial/GlobeRectangle.h>
#include <CesiumGltf/ImageAsset.h>
#include <CesiumUtility/Assert.h>
#include <CesiumUtility/Color.h>
#include <CesiumUtility/IntrusivePointer.h>
#include <CesiumVectorData/Color.h>
#include <CesiumVectorData/GeoJsonObject.h>
#include <CesiumVectorData/VectorRasterizer.h>
#include <CesiumVectorData/VectorStyle.h>
@ -23,7 +23,6 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <span>
#include <variant>
#include <vector>
@ -225,7 +224,7 @@ void VectorRasterizer::drawGeoJsonObject(
std::visit(PrimitiveDrawVisitor{*this, style}, geoJsonObject->value);
}
void VectorRasterizer::clear(const Color& clearColor) {
void VectorRasterizer::clear(const CesiumUtility::Color& clearColor) {
if (_finalized) {
return;
}

View File

@ -1,6 +1,7 @@
#include <CesiumGeospatial/CartographicPolygon.h>
#include <CesiumGeospatial/GlobeRectangle.h>
#include <CesiumGltf/ImageAsset.h>
#include <CesiumUtility/Color.h>
#include <CesiumUtility/IntrusivePointer.h>
#include <CesiumVectorData/VectorRasterizer.h>
@ -44,13 +45,7 @@ TEST_CASE("VectorRasterizer::rasterize") {
Math::degreesToRadians(0.75),
Math::degreesToRadians(0.25))});
rasterizer.drawPolygon(
triangle,
VectorStyle{Color{
std::byte{0},
std::byte{255},
std::byte{255},
std::byte{255}}});
rasterizer.drawPolygon(triangle, VectorStyle{Color{0, 255, 255, 255}});
rasterizer.finalize();
asset->writeTga("triangle.tga");
}
@ -72,8 +67,7 @@ TEST_CASE("VectorRasterizer::rasterize") {
glm::dvec2(
Math::degreesToRadians(0.75),
Math::degreesToRadians(0.25))});
VectorStyle style{
Color{std::byte{0}, std::byte{255}, std::byte{255}, std::byte{255}}};
VectorStyle style{Color{0, 255, 255, 255}};
{
VectorRasterizer rasterizer(rect, asset);
@ -137,13 +131,7 @@ TEST_CASE("VectorRasterizer::rasterize") {
glm::dvec3(0.8, 0.9, 0.0),
glm::dvec3(0.9, 0.9, 0.0)};
rasterizer.drawPolyline(
polyline,
VectorStyle{Color{
std::byte{81},
std::byte{33},
std::byte{255},
std::byte{255}}});
rasterizer.drawPolyline(polyline, VectorStyle{Color{81, 33, 255, 255}});
rasterizer.finalize();
asset->writeTga("polyline.tga");
}
@ -175,13 +163,7 @@ TEST_CASE("VectorRasterizer::rasterize") {
Math::degreesToRadians(0.625),
Math::degreesToRadians(0.3125))});
rasterizer.drawPolygon(
triangle,
VectorStyle{Color{
std::byte{255},
std::byte{127},
std::byte{100},
std::byte{255}}});
rasterizer.drawPolygon(triangle, VectorStyle{Color{255, 127, 100, 255}});
rasterizer.finalize();
asset->writeTga("triangle-scaled.tga");
}
@ -213,13 +195,7 @@ TEST_CASE("VectorRasterizer::rasterize") {
glm::dvec3(0.6, 0.4, 0.0),
glm::dvec3(0.4, 0.4, 0.0)}};
rasterizer.drawPolygon(
composite,
VectorStyle{Color{
std::byte{255},
std::byte{50},
std::byte{12},
std::byte{255}}});
rasterizer.drawPolygon(composite, VectorStyle{Color{255, 50, 12, 255}});
rasterizer.finalize();
asset->writeTga("polygon-holes.tga");
}
@ -250,8 +226,7 @@ TEST_CASE("VectorRasterizer::rasterize") {
glm::dvec3(0.8, 1.0, 0.0),
glm::dvec3(0.8, 0.9, 0.0),
glm::dvec3(0.9, 0.9, 0.0)};
VectorStyle style{
Color{std::byte{255}, std::byte{50}, std::byte{12}, std::byte{255}}};
VectorStyle style{Color{255, 50, 12, 255}};
for (uint32_t i = 0; i < 4; i++) {
VectorRasterizer rasterizer(rect, asset, i);
@ -345,10 +320,10 @@ TEST_CASE("VectorRasterizer::rasterize benchmark") {
Math::degreesToRadians(uniformDist(rand))),
});
styles.emplace_back(Color{
(std::byte)(uniformDist(rand) * 255.0),
(std::byte)(uniformDist(rand) * 255.0),
(std::byte)(uniformDist(rand) * 255.0),
(std::byte)(uniformDist(rand) * 255.0)});
(uint8_t)(uniformDist(rand) * 255.0),
(uint8_t)(uniformDist(rand) * 255.0),
(uint8_t)(uniformDist(rand) * 255.0),
(uint8_t)(uniformDist(rand) * 255.0)});
}
std::chrono::steady_clock::time_point start = clock.now();