Skip to content

Commit

Permalink
Additional point styling options for outline and scaling by distance.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbirkner committed Dec 15, 2023
1 parent d66e2c1 commit c472dd2
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 32 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ rule that matches it.
Each rule within the YAML `rules` array can have the following fields. Any field marked with __`*`__ is optional:

| Field | Description | Type | Example Value |
|----------------|------------------------------------------------------------------------------------------------------|------------------------------------------------------------|---------------------|
| `geometry` | List of feature geometry type(s) the rule applies to. | At least one of `"point"`,`"mesh"`, `"line"`, `"polygon"`. | `["point", "mesh"]` |
| `type`__*__ | A regular expression to match against a feature type. | String | `"Lane\|Boundary"` |
| `filter`__*__ | A [simfil](https://github.com/klebert-engineering/simfil) filter expression. | String | `*roadClass == 4` |
| `color`__*__ | A hexadecimal color code or [CSS color name](https://www.w3.org/wiki/CSS/Properties/color/keywords). | String | `"#FF5733"`, `red` |
| `opacity`__*__ | A float value between 0 and 1 indicating the opacity. | Float | `0.8` |
| `width`__*__ | Specifies the line width or point diameter (default in pixels). | Float | `4.5` |
| `flat`__*__ | Clamps the feature to the ground (meshes not supported) | Boolean | `true`, `false` |
| Field | Description | Type | Example Value |
|-----------------------|------------------------------------------------------------------------------------------------------|------------------------------------------------------------|----------------------|
| `geometry` | List of feature geometry type(s) the rule applies to. | At least one of `"point"`,`"mesh"`, `"line"`, `"polygon"`. | `["point", "mesh"]` |
| `type`__*__ | A regular expression to match against a feature type. | String | `"Lane\|Boundary"` |
| `filter`__*__ | A [simfil](https://github.com/klebert-engineering/simfil) filter expression. | String | `*roadClass == 4` |
| `color`__*__ | A hexadecimal color code or [CSS color name](https://www.w3.org/wiki/CSS/Properties/color/keywords). | String | `"#FF5733"`, `red` |
| `opacity`__*__ | A float value between 0 and 1 indicating the opacity. | Float | `0.8` |
| `width`__*__ | Specifies the line width or point diameter (default in pixels). | Float | `4.5` |
| `flat`__*__ | Clamps the feature to the ground (Does not work for meshes). | Boolean | `true`, `false` |
| `outline-color`__*__ | Feature outline color (works only for points). | String | `green`, `#fff` |
| `outline-width`__*__ | Point outline width in px. | Float | `3.6` |
| `near-far-scale`__*__ | For points, indicate (`near-alt-meters`, `near-scale`, `far-alt-meters`, `far-scale`). | Array of four Floats. | `[1.5e2,10,8.0e6,0]` |

**A brief example:**

Expand Down
9 changes: 5 additions & 4 deletions libs/core/include/erdblick/cesium-interface/cesium.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ struct CesiumLib
CesiumClass Geometry;
CesiumClass GeometryAttribute;
CesiumClass GeometryInstance;
CesiumClass GroundPolylineGeometry;
CesiumClass GroundPolylinePrimitive;
CesiumClass GroundPrimitive;
CesiumClass Material;
CesiumClass NearFarScalar;
CesiumClass PerInstanceColorAppearance;
CesiumClass PointPrimitiveCollection;
CesiumClass PolygonGeometry;
CesiumClass PolygonHierarchy;
CesiumClass PolylineColorAppearance;
Expand All @@ -26,10 +31,6 @@ struct CesiumLib
CesiumClass Primitive;
CesiumClass PrimitiveCollection;
CesiumClass PrimitiveType;
CesiumClass GroundPolylineGeometry;
CesiumClass GroundPolylinePrimitive;
CesiumClass GroundPrimitive;
CesiumClass PointPrimitiveCollection;

[[nodiscard]] JsValue MaterialFromType(std::string const& type, JsValue const& options);

Expand Down
7 changes: 7 additions & 0 deletions libs/core/include/erdblick/rule.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class FeatureStyleRule
[[nodiscard]] glm::fvec4 const& color() const;
[[nodiscard]] float width() const;
[[nodiscard]] bool flat() const;
[[nodiscard]] glm::fvec4 const& outlineColor() const;
[[nodiscard]] float outlineWidth() const;
[[nodiscard]] std::optional<std::array<float, 4>> const& nearFarScale() const;

private:
static inline uint32_t geomTypeBit(mapget::Geometry::GeomType const& g) {
Expand All @@ -33,6 +36,10 @@ class FeatureStyleRule
glm::fvec4 color_{.0, .0, .0, 1.};
float width_ = 1.;
bool flat_ = false;

glm::fvec4 outlineColor_{.0, .0, .0, .0};
float outlineWidth_ = .0;
std::optional<std::array<float, 4>> nearFarScale_;
};

}
3 changes: 3 additions & 0 deletions libs/core/include/erdblick/testdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ class TestDataProvider
type: "PointOfNoInterest"
color: "#e74c3c" # Red color for Points of No Interest
width: 5
outline-color: orange
outline-width: 3
near-far-scale: [1.5e2, 3, 8.0e6, 0.0]
)yaml"));
}

Expand Down
12 changes: 6 additions & 6 deletions libs/core/src/cesium-interface/cesium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ CesiumLib::CesiumLib() :
Geometry("Geometry"),
GeometryAttribute("GeometryAttribute"),
GeometryInstance("GeometryInstance"),
GroundPolylineGeometry("GroundPolylineGeometry"),
GroundPolylinePrimitive("GroundPolylinePrimitive"),
GroundPrimitive("GroundPrimitive"),
Material("Material"),
NearFarScalar("NearFarScalar"),
PerInstanceColorAppearance("PerInstanceColorAppearance"),
PointPrimitiveCollection("PointPrimitiveCollection"),
PolygonGeometry("PolygonGeometry"),
PolygonHierarchy("PolygonHierarchy"),
PolylineColorAppearance("PolylineColorAppearance"),
PolylineGeometry("PolylineGeometry"),
PolylineMaterialAppearance("PolylineMaterialAppearance"),
Primitive("Primitive"),
PrimitiveCollection("PrimitiveCollection"),
PrimitiveType("PrimitiveType"),
GroundPolylineGeometry("GroundPolylineGeometry"),
GroundPolylinePrimitive("GroundPolylinePrimitive"),
GroundPrimitive("GroundPrimitive"),
PrimitiveType("PrimitiveType"),
PointPrimitiveCollection("PointPrimitiveCollection")
PrimitiveType("PrimitiveType")
{
}

Expand Down
31 changes: 18 additions & 13 deletions libs/core/src/cesium-interface/points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ void CesiumPointPrimitiveCollection::addPoint(
uint32_t id)
{
auto const& color = style.color();

pointPrimitiveCollection_.call<void>("add",
*JsValue::Dict({
{"position", position},
{"color", Cesium().Color.New(
color.r,
color.g,
color.b,
color.a)
},
{"pixelSize", JsValue(style.width())},
{"id", JsValue(id)}
}));
auto const& oColor = style.outlineColor();

auto options = JsValue::Dict({
{"position", position},
{"color", Cesium().Color.New(color.r, color.g, color.b, color.a)},
{"pixelSize", JsValue(style.width())},
{"id", JsValue(id)},
{"outlineColor", Cesium().Color.New(oColor.r, oColor.g, oColor.b, oColor.a)},
{"outlineWidth", JsValue(style.outlineWidth())},
});

if (auto const& nfs = style.nearFarScale()) {
options.set(
"scaleByDistance",
Cesium().NearFarScalar.New((*nfs)[0], (*nfs)[1], (*nfs)[2], (*nfs)[3]));
}

pointPrimitiveCollection_.call<void>("add", *options);
++numGeometryInstances_;
}

Expand Down
31 changes: 31 additions & 0 deletions libs/core/src/rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ FeatureStyleRule::FeatureStyleRule(YAML::Node const& yaml)
// Parse option to clamp feature to ground (ignoring height), defaults to false
flat_ = yaml["flat"].as<bool>();
}
if (yaml["outline-color"].IsDefined()) {
// Parse option to have a feature outline color.
outlineColor_ = Color(yaml["outline-color"].as<std::string>()).toFVec4();
}
if (yaml["outline-width"].IsDefined()) {
// Parse option for the width of the feature outline color.
outlineWidth_ = yaml["outline-width"].as<float>();
}
if (yaml["near-far-scale"].IsDefined()) {
// Parse option for the scale of the feature depending on camera distance.
auto components = yaml["near-far-scale"].as<std::vector<float>>();
if (components.size() >= 4) {
nearFarScale_ = {.0};
std::copy(components.begin(), components.begin()+4, nearFarScale_->begin());
}
}
}

bool FeatureStyleRule::match(mapget::Feature& feature) const
Expand Down Expand Up @@ -99,4 +115,19 @@ bool FeatureStyleRule::flat() const
return flat_;
}

glm::fvec4 const& FeatureStyleRule::outlineColor() const
{
return outlineColor_;
}

float FeatureStyleRule::outlineWidth() const
{
return outlineWidth_;
}

std::optional<std::array<float, 4>> const& FeatureStyleRule::nearFarScale() const
{
return nearFarScale_;
}

}

0 comments on commit c472dd2

Please sign in to comment.