Skip to content

Commit

Permalink
Updated GUIDottedGeometry. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 98c866e commit e7c9522
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
52 changes: 33 additions & 19 deletions src/utils/gui/div/GUIDottedGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,21 @@ GUIDottedGeometry::GUIDottedGeometry() {}

GUIDottedGeometry::GUIDottedGeometry(const GUIVisualizationSettings& s, PositionVector shape,
const bool closeShape, const bool resample) {
// set shape as unresampled shape
myUnresampledShape = shape;
// check if shape has to be closed
if (closeShape && (shape.size() > 2)) {
shape.closePolygon();
if (closeShape && (myUnresampledShape.size() > 2)) {
myUnresampledShape.closePolygon();
}
if (shape.size() > 1) {
if (myUnresampledShape.size() > 1) {
// get shape
for (int i = 1; i < (int)shape.size(); i++) {
myDottedGeometrySegments.push_back(Segment({shape[i - 1], shape[i]}));
for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
myDottedGeometrySegments.push_back(Segment({myUnresampledShape[i - 1], myUnresampledShape[i]}));
}
// calculate segment length
double segmentLength = s.dottedContourSettings.segmentLength;
if (shape.length2D() > MAXIMUM_DOTTEDGEOMETRYLENGTH) {
segmentLength = shape.length2D() / (MAXIMUM_DOTTEDGEOMETRYLENGTH * 0.5);
if (myUnresampledShape.length2D() > MAXIMUM_DOTTEDGEOMETRYLENGTH) {
segmentLength = myUnresampledShape.length2D() / (MAXIMUM_DOTTEDGEOMETRYLENGTH * 0.5);
}
// check if resample
if (resample) {
Expand All @@ -177,11 +179,13 @@ GUIDottedGeometry::GUIDottedGeometry(const GUIVisualizationSettings& s, Position
void
GUIDottedGeometry::updateDottedGeometry(const GUIVisualizationSettings& s, const PositionVector& laneShape,
const bool resample) {
// set shape as unresampled shape
myUnresampledShape = laneShape;
// reset segments
myDottedGeometrySegments.clear();
// get shape
for (int i = 1; i < (int)laneShape.size(); i++) {
myDottedGeometrySegments.push_back(Segment({laneShape[i - 1], laneShape[i]}));
for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
myDottedGeometrySegments.push_back(Segment({myUnresampledShape[i - 1], myUnresampledShape[i]}));
}
// check if resample
if (resample) {
Expand All @@ -197,16 +201,18 @@ GUIDottedGeometry::updateDottedGeometry(const GUIVisualizationSettings& s, const
void
GUIDottedGeometry::updateDottedGeometry(const GUIVisualizationSettings& s, PositionVector shape, const bool closeShape,
const bool resample) {
// set shape as unresampled shape
myUnresampledShape = shape;
// reset segments
myDottedGeometrySegments.clear();
// check if shape has to be closed
if (closeShape && (shape.size() > 2)) {
shape.closePolygon();
if (closeShape && (myUnresampledShape.size() > 2)) {
myUnresampledShape.closePolygon();
}
if (shape.size() > 1) {
if (myUnresampledShape.size() > 1) {
// get shape
for (int i = 1; i < (int)shape.size(); i++) {
myDottedGeometrySegments.push_back(Segment({shape[i - 1], shape[i]}));
for (int i = 1; i < (int)myUnresampledShape.size(); i++) {
myDottedGeometrySegments.push_back(Segment({myUnresampledShape[i - 1], myUnresampledShape[i]}));
}
// check if resample
if (resample) {
Expand Down Expand Up @@ -254,17 +260,19 @@ GUIDottedGeometry::drawInnenGeometry(const double lineWidth) const {

void
GUIDottedGeometry::moveShapeToSide(const double value) {
// move 2 side
// move to side all dotted geometry segments
for (auto& segment : myDottedGeometrySegments) {
segment.shape.move2side(value);
}
// also unresampled shape
myUnresampledShape.move2side(value);
}


Position
GUIDottedGeometry::getFrontPosition() const {
if (myDottedGeometrySegments.size() > 0 && myDottedGeometrySegments.front().shape.size() > 0) {
return myDottedGeometrySegments.front().shape.front();
if (myUnresampledShape.size() > 0) {
return myUnresampledShape.front();
} else {
return Position::INVALID;
}
Expand All @@ -273,14 +281,20 @@ GUIDottedGeometry::getFrontPosition() const {

Position
GUIDottedGeometry::getBackPosition() const {
if (myDottedGeometrySegments.size() > 0 && myDottedGeometrySegments.back().shape.size() > 0) {
return myDottedGeometrySegments.back().shape.back();
if (myUnresampledShape.size() > 0) {
return myUnresampledShape.back();
} else {
return Position::INVALID;
}
}


const PositionVector&
GUIDottedGeometry::getUnresampledShape() {
return myUnresampledShape;
}


void
GUIDottedGeometry::calculateShapeRotationsAndLengths() {
// iterate over all segments
Expand Down
6 changes: 6 additions & 0 deletions src/utils/gui/div/GUIDottedGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,16 @@ class GUIDottedGeometry {
/// @brief get back position
Position getBackPosition() const;

/// @brief get simple shape (the shape without resampling)
const PositionVector &getUnresampledShape();

private:
/// @brief calculate shape rotations and lengths
void calculateShapeRotationsAndLengths();

/// @brief shape without resampling
PositionVector myUnresampledShape;

/// @brief dotted element shape (note: It's centered in 0,0 due scaling)
std::vector<GUIDottedGeometry::Segment> myDottedGeometrySegments;
};

0 comments on commit e7c9522

Please sign in to comment.