Skip to content

Commit

Permalink
Optimiced updateCenteringBoundary() in all network elements. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent e3aa453 commit 87ff2c1
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 74 deletions.
18 changes: 7 additions & 11 deletions src/netedit/elements/network/GNEConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,15 @@ GNEConnection::getExaggeration(const GUIVisualizationSettings& s) const {
}


Boundary
GNEConnection::getCenteringBoundary() const {
return myContour.getContourBoundary();
}


void
GNEConnection::updateCenteringBoundary(const bool /*updateGrid*/) {
// calculate boundary
if (myConnectionGeometry.getShape().size() == 0) {
// we need to use the center of junction parent as boundary if shape is empty
const Position junctionParentPosition = myFromLane->getParentEdge()->getToJunction()->getPositionInView();
myBoundary = Boundary(junctionParentPosition.x() - 0.1, junctionParentPosition.y() - 0.1,
junctionParentPosition.x() + 0.1, junctionParentPosition.x() + 0.1);
} else {
myBoundary = myConnectionGeometry.getShape().getBoxBoundary();
}
// grow
myBoundary.grow(10);
// nothing to update
}


Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/network/GNEConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class GNEConnection : public GNENetworkElement {
/// @brief return exaggeration associated with this GLObject
double getExaggeration(const GUIVisualizationSettings& s) const;

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;

/// @brief update centering boundary (implies change in RTREE)
void updateCenteringBoundary(const bool updateGrid);

Expand Down
22 changes: 7 additions & 15 deletions src/netedit/elements/network/GNECrossing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,15 @@ GNECrossing::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
}


Boundary
GNECrossing::getCenteringBoundary() const {
return myContour.getContourBoundary();
}


void
GNECrossing::updateCenteringBoundary(const bool /*updateGrid*/) {
const auto crossing = getNBCrossing();
if (crossing) {
if (crossing->customShape.size() > 0) {
myBoundary = crossing->customShape.getBoxBoundary();
myBoundary.grow(10);
} else if (crossing->shape.size() > 0) {
myBoundary = crossing->shape.getBoxBoundary();
myBoundary.grow(10);
} else {
myBoundary = myParentJunction->getCenteringBoundary();
}
} else {
// in other case use boundary of parent junction
myBoundary = myParentJunction->getCenteringBoundary();
}
// nothing to update
}


Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/network/GNECrossing.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class GNECrossing : public GNENetworkElement {
*/
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;

/// @brief update centering boundary (implies change in RTREE)
void updateCenteringBoundary(const bool updateGrid);

Expand Down
40 changes: 26 additions & 14 deletions src/netedit/elements/network/GNEEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,34 +483,46 @@ GNEEdge::getExaggeration(const GUIVisualizationSettings& s) const {
}


Boundary
GNEEdge::getCenteringBoundary() const {
return myEdgeBoundary;
}


void
GNEEdge::updateCenteringBoundary(const bool updateGrid) {
// Remove object from net
if (updateGrid) {
myNet->removeGLObjectFromGrid(this);
}
// use as boundary the first lane boundary
myBoundary = myLanes.front()->getCenteringBoundary();
// first add edge boundary
myEdgeBoundary = myNBEdge->getGeometry().getBoxBoundary();
// add lane boundaries
for (const auto& lane : myLanes) {
lane->updateCenteringBoundary(false);
myBoundary.add(lane->getCenteringBoundary());
// add parkingArea boundaries
for (const auto& additional : lane->getChildAdditionals()) {
if (additional->getTagProperty().getTag() == SUMO_TAG_PARKING_AREA) {
myBoundary.add(additional->getCenteringBoundary());
const auto laneBoundary = lane->getCenteringBoundary();
if (laneBoundary.isInitialised()) {
myEdgeBoundary.add(laneBoundary);
// add additional and demand boundaries
for (const auto& additional : lane->getChildAdditionals()) {
const auto additionalBoundary = additional->getCenteringBoundary();
if (additionalBoundary.isInitialised()) {
myEdgeBoundary.add(additional->getCenteringBoundary());
}
}
}
}
// ensure that geometry points are selectable even if the lane geometry is strange
for (const Position& pos : myNBEdge->getGeometry()) {
myBoundary.add(pos);
// add additional and demand boundaries
for (const auto& additional : getChildAdditionals()) {
const auto additionalBoundary = additional->getCenteringBoundary();
if (additionalBoundary.isInitialised()) {
myEdgeBoundary.add(additionalBoundary);
}
}
// add junction positions
myBoundary.add(getFromJunction()->getPositionInView());
myBoundary.add(getToJunction()->getPositionInView());
myEdgeBoundary.add(getFromJunction()->getPositionInView());
myEdgeBoundary.add(getToJunction()->getPositionInView());
// grow boundary
myBoundary.grow(10);
myEdgeBoundary.grow(5);
// add object into net
if (updateGrid) {
myNet->addGLObjectIntoGrid(this);
Expand Down
6 changes: 6 additions & 0 deletions src/netedit/elements/network/GNEEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class GNEEdge : public GNENetworkElement, public GNECandidateElement {
/// @brief return exaggeration associated with this GLObject
double getExaggeration(const GUIVisualizationSettings& s) const;

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;

/// @brief update centering boundary (implies change in RTREE)
void updateCenteringBoundary(const bool updateGrid);

Expand Down Expand Up @@ -403,6 +406,9 @@ class GNEEdge : public GNENetworkElement, public GNECandidateElement {
const std::vector<GNEDemandElement*>& getDemandElements() const;
};

/// @brief edge boundary
Boundary myEdgeBoundary;

/// @brief flag to enable/disable update geometry of lanes (used mainly by setNumLanes)
bool myUpdateGeometry;

Expand Down
6 changes: 6 additions & 0 deletions src/netedit/elements/network/GNEEdgeType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ GNEEdgeType::getPopUpMenu(GUIMainWindow& /*app*/, GUISUMOAbstractView& /*parent*
}


Boundary
GNEEdgeType::getCenteringBoundary() const {
return myContour.getContourBoundary();
}


void
GNEEdgeType::updateCenteringBoundary(const bool /*updateGrid*/) {
// nothing to do
Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/network/GNEEdgeType.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ class GNEEdgeType : public GNENetworkElement, public Parameterised, public NBTyp
*/
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;

/// @brief update centering boundary (implies change in RTREE)
void updateCenteringBoundary(const bool updateGrid);

Expand Down
9 changes: 7 additions & 2 deletions src/netedit/elements/network/GNEInternalLane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,15 @@ GNEInternalLane::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&) {
}


Boundary
GNEInternalLane::getCenteringBoundary() const {
return myContour.getContourBoundary();
}


void
GNEInternalLane::updateCenteringBoundary(const bool /*updateGrid*/) {
myBoundary = myInternalLaneGeometry.getShape().getBoxBoundary();
myBoundary.grow(10);
// nothing to update
}


Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/network/GNEInternalLane.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ class GNEInternalLane : public GNENetworkElement, public FXDelegator {
*/
GUIParameterTableWindow* getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& parent);

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;

/// @brief update centering boundary (implies change in RTREE)
void updateCenteringBoundary(const bool updateGrid);

Expand Down
43 changes: 34 additions & 9 deletions src/netedit/elements/network/GNEJunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,23 +555,48 @@ GNEJunction::getExaggeration(const GUIVisualizationSettings& s) const {
}


Boundary
GNEJunction::getCenteringBoundary() const {
return myJunctionBoundary;
}


void
GNEJunction::updateCenteringBoundary(const bool updateGrid) {
// Remove object from net
if (updateGrid) {
myNet->removeGLObjectFromGrid(this);
}
// update boundary
// calculate boundary using a radius bigger than geometry point
myJunctionBoundary = Boundary(myNBNode->getPosition().x() - 1, myNBNode->getPosition().y() - 1,
myNBNode->getPosition().x() + 1, myNBNode->getPosition().y() + 1);
myJunctionBoundary.grow(10);
// add shape
if (myNBNode->getShape().size() > 0) {
myBoundary = myNBNode->getShape().getBoxBoundary();
} else {
// calculate boundary using EXTENT as size
const double EXTENT = 2;
Boundary b(myNBNode->getPosition().x() - EXTENT, myNBNode->getPosition().y() - EXTENT,
myNBNode->getPosition().x() + EXTENT, myNBNode->getPosition().y() + EXTENT);
myBoundary = b;
myJunctionBoundary.add(myNBNode->getShape().getBoxBoundary());
myJunctionBoundary.grow(5);
}
// add boundaries of all connections, walking areas and crossings
for (const auto &edge : myGNEIncomingEdges) {
for (const auto &connection : edge->getGNEConnections()) {
const auto boundary = connection->getCenteringBoundary();
if (boundary.isInitialised()) {
myJunctionBoundary.add(boundary);
}
}
}
for (const auto &crossing : myGNECrossings) {
const auto boundary = crossing->getCenteringBoundary();
if (boundary.isInitialised()) {
myJunctionBoundary.add(boundary);
}
}
for (const auto &walkingArea : myGNEWalkingAreas) {
const auto boundary = walkingArea->getCenteringBoundary();
if (boundary.isInitialised()) {
myJunctionBoundary.add(boundary);
}
}
myBoundary.grow(10);
// add object into net
if (updateGrid) {
myNet->addGLObjectIntoGrid(this);
Expand Down
6 changes: 6 additions & 0 deletions src/netedit/elements/network/GNEJunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class GNEJunction : public GNENetworkElement, public GNECandidateElement {
/// @brief return exaggeration associated with this GLObject
double getExaggeration(const GUIVisualizationSettings& s) const;

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;

/// @brief update centering boundary (implies change in RTREE)
void updateCenteringBoundary(const bool updateGrid);

Expand Down Expand Up @@ -293,6 +296,9 @@ class GNEJunction : public GNENetworkElement, public GNECandidateElement {
void removeInternalLane(const GNEInternalLane* internalLane);

protected:
/// @brief edge boundary
Boundary myJunctionBoundary;

/// @brief A reference to the represented junction
NBNode* myNBNode;

Expand Down
12 changes: 7 additions & 5 deletions src/netedit/elements/network/GNELane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,13 +806,15 @@ GNELane::getExaggeration(const GUIVisualizationSettings& s) const {
}


Boundary
GNELane::getCenteringBoundary() const {
return myContour.getContourBoundary();
}


void
GNELane::updateCenteringBoundary(const bool /*updateGrid*/) {
if (myParentEdge->getNBEdge()->getLaneStruct(myIndex).customShape.size() == 0) {
myBoundary = myParentEdge->getNBEdge()->getLaneStruct(myIndex).shape.getBoxBoundary();
} else {
myBoundary = myParentEdge->getNBEdge()->getLaneStruct(myIndex).customShape.getBoxBoundary();
}
// nothing to update
}


Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/network/GNELane.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class GNELane : public GNENetworkElement, public GNECandidateElement, public FXD
/// @brief return exaggeration associated with this GLObject
double getExaggeration(const GUIVisualizationSettings& s) const;

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;

/// @brief update centering boundary (implies change in RTREE)
void updateCenteringBoundary(const bool updateGrid);

Expand Down
6 changes: 6 additions & 0 deletions src/netedit/elements/network/GNELaneType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ GNELaneType::getPopUpMenu(GUIMainWindow& /*app*/, GUISUMOAbstractView& /*parent*
}


Boundary
GNELaneType::getCenteringBoundary() const {
return myContour.getContourBoundary();
}


void
GNELaneType::updateCenteringBoundary(const bool /*updateGrid*/) {
// nothing to do
Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/network/GNELaneType.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class GNELaneType : public GNENetworkElement, public Parameterised, public NBTyp
*/
GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent);

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;

/// @brief update centering boundary (implies change in RTREE)
void updateCenteringBoundary(const bool updateGrid);

Expand Down
6 changes: 0 additions & 6 deletions src/netedit/elements/network/GNENetworkElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ GNENetworkElement::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView&)
}


Boundary
GNENetworkElement::getCenteringBoundary() const {
return myBoundary;
}


bool
GNENetworkElement::isGLObjectLocked() const {
if (myNet->getViewNet()->getEditModes().isCurrentSupermodeNetwork()) {
Expand Down
5 changes: 1 addition & 4 deletions src/netedit/elements/network/GNENetworkElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class GNENetworkElement : public GUIGlObject, public GNEHierarchicalElement, pub
virtual GUIGLObjectPopupMenu* getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) = 0;

/// @brief Returns the boundary to which the view shall be centered in order to show the object
Boundary getCenteringBoundary() const;
virtual Boundary getCenteringBoundary() const = 0;

/// @brief update centering boundary (implies change in RTREE)
virtual void updateCenteringBoundary(const bool updateGrid) = 0;
Expand Down Expand Up @@ -201,9 +201,6 @@ class GNENetworkElement : public GUIGlObject, public GNEHierarchicalElement, pub
virtual const Parameterised::Map& getACParametersMap() const = 0;

protected:
/// @brief object boundary
Boundary myBoundary;

/// @brief flag to check if element shape is being edited
bool myShapeEdited;

Expand Down
15 changes: 7 additions & 8 deletions src/netedit/elements/network/GNEWalkingArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,16 +223,15 @@ GNEWalkingArea::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
}


Boundary
GNEWalkingArea::getCenteringBoundary() const {
return myContour.getContourBoundary();
}


void
GNEWalkingArea::updateCenteringBoundary(const bool /*updateGrid*/) {
// in other case use boundary of parent junction
const PositionVector& shape = myParentJunction->getNBNode()->getWalkingArea(getID()).shape;
if (shape.size() == 0) {
myBoundary = myParentJunction->getCenteringBoundary();
} else {
myBoundary = shape.getBoxBoundary();
myBoundary.grow(10);
}
// nothing to update
}


Expand Down

0 comments on commit 87ff2c1

Please sign in to comment.