Skip to content

Commit

Permalink
Improved efficiency selecting elements using a rectangle. Refs #15844
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Jan 17, 2025
1 parent 8700bd1 commit 696c6ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/utils/gui/div/GUIViewObjectsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,7 @@ GUIViewObjectsHandler::selectObject(const GUIGlObject* GLObject, const double la
return false;
} else {
auto& layerContainer = mySortedSelectedObjects[layer * -1];
if (layerContainer.size() == 10) {
layerContainer.reserve(10000000);
}
layerContainer.push_back(ObjectContainer(GLObject));
layerContainer.append(ObjectContainer(GLObject));
mySelectedObjects[GLObject] = std::make_pair(fullBoundary, segment);
myNumberOfSelectedObjects++;
return true;
Expand Down Expand Up @@ -305,7 +302,7 @@ GUIViewObjectsHandler::selectGeometryPoint(const GUIGlObject* GLObject, const in
}
// no element found then add it
auto& layerContainer = mySortedSelectedObjects[layer * -1];
layerContainer.push_back(ObjectContainer(GLObject));
layerContainer.append(ObjectContainer(GLObject));
layerContainer.back().geometryPoints.push_back(newIndex);
mySelectedObjects[GLObject] = std::make_pair(false, nullptr);
myNumberOfSelectedObjects++;
Expand Down Expand Up @@ -333,7 +330,7 @@ GUIViewObjectsHandler::selectPositionOverShape(const GUIGlObject* GLObject, cons
}
// no element found then add it
auto& layerContainer = mySortedSelectedObjects[layer * -1];
layerContainer.push_back(ObjectContainer(GLObject));
layerContainer.append(ObjectContainer(GLObject));
layerContainer.back().posOverShape = pos;
mySelectedObjects[GLObject] = std::make_pair(false, nullptr);
myNumberOfSelectedObjects++;
Expand Down Expand Up @@ -478,7 +475,7 @@ GUIViewObjectsHandler::updateFrontObject(const GUIGlObject* GLObject) {
}
// add element again wit a new layer
if (frontElement.object) {
mySortedSelectedObjects[(double)GLO_FRONTELEMENT].push_back(frontElement);
mySortedSelectedObjects[(double)GLO_FRONTELEMENT].append(frontElement);
}
}

Expand All @@ -500,8 +497,21 @@ GUIViewObjectsHandler::isolateEdgeGeometryPoints() {
// clear all selected objects
mySortedSelectedObjects.clear();
// add edge with geometry points as front element
mySortedSelectedObjects[(double)GLO_FRONTELEMENT].push_back(edgeWithGeometryPoints);
mySortedSelectedObjects[(double)GLO_FRONTELEMENT].append(edgeWithGeometryPoints);
}
}


void
GUIViewObjectsHandler::ObjectContainerLayer::append(const ObjectContainer& objectContainer) {
if (capacity() == size()) {
if (size() < 10) {
reserve(size() + 10);
} else {
reserve(size() + 1000);
}
}
push_back(objectContainer);
}

/****************************************************************************/
12 changes: 11 additions & 1 deletion src/utils/gui/div/GUIViewObjectsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,18 @@ class GUIViewObjectsHandler {
double offset = 0;
};

/// @brief object container layer
struct ObjectContainerLayer : public std::vector<ObjectContainer> {

/// @brief parameter constructor
ObjectContainerLayer() {}

// @brief append object container and resize if neccesary
void append(const ObjectContainer &objectContainer);
};

/// @brief typedef for pack elements sorted by layer
typedef std::map<double, std::vector<ObjectContainer> > GLObjectsSortedContainer;
typedef std::map<double, ObjectContainerLayer > GLObjectsSortedContainer;

/// @brief constructor
GUIViewObjectsHandler();
Expand Down

0 comments on commit 696c6ae

Please sign in to comment.