Skip to content

Commit 326fe85

Browse files
committed
Add item group for collisions
1 parent 430e4ee commit 326fe85

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

demos/rlPlanDemo/ConfigurationSpaceScene.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ConfigurationSpaceScene::ConfigurationSpaceScene(QObject* parent) :
4141
delta0(1),
4242
delta1(1),
4343
model(nullptr),
44+
collisions(nullptr),
4445
edges(nullptr),
4546
path(nullptr),
4647
scene(nullptr),
@@ -73,19 +74,17 @@ ConfigurationSpaceScene::addCollision(const qreal& x, const qreal& y, const qrea
7374
QBrush(QColor(rgb, rgb, rgb))
7475
);
7576

76-
rect->setParentItem(this->scene);
77-
rect->setZValue(1);
77+
this->collisions->addToGroup(rect);
7878
}
7979

8080
void
8181
ConfigurationSpaceScene::clear()
8282
{
83-
QList<QGraphicsItem*> items = this->items();
84-
85-
while (!items.isEmpty())
86-
{
87-
delete items.takeFirst();
88-
}
83+
QGraphicsScene::clear();
84+
this->collisions = nullptr;
85+
this->edges = nullptr;
86+
this->path = nullptr;
87+
this->scene = nullptr;
8988
}
9089

9190
void
@@ -104,8 +103,6 @@ ConfigurationSpaceScene::drawConfigurationEdge(const rl::math::Vector& u, const
104103
free ? QPen(QBrush(QColor(0, 128, 0)), 0) : QPen(QBrush(QColor(128, 0, 0)), 0)
105104
);
106105

107-
line->setZValue(2);
108-
109106
this->edges->addToGroup(line);
110107
}
111108

@@ -122,7 +119,7 @@ ConfigurationSpaceScene::drawConfigurationPath(const rl::plan::VectorList& path)
122119
rl::plan::VectorList::const_iterator i = path.begin();
123120
rl::plan::VectorList::const_iterator j = ++path.begin();
124121

125-
while (i != path.end() && j != path.end())
122+
for (; i != path.end() && j != path.end(); ++i, ++j)
126123
{
127124
QGraphicsLineItem* line = this->addLine(
128125
(*i)(this->axis0),
@@ -132,12 +129,7 @@ ConfigurationSpaceScene::drawConfigurationPath(const rl::plan::VectorList& path)
132129
QPen(QBrush(QColor(0, 255, 0)), 0)
133130
);
134131

135-
line->setZValue(3);
136-
137132
this->path->addToGroup(line);
138-
139-
++i;
140-
++j;
141133
}
142134
}
143135

@@ -235,8 +227,14 @@ ConfigurationSpaceScene::init()
235227

236228
this->setSceneRect(this->scene->boundingRect());
237229

238-
this->edges = new QGraphicsItemGroup(this->scene);
239-
this->path = new QGraphicsItemGroup(this->scene);
230+
this->collisions = this->createItemGroup(QList<QGraphicsItem*>());
231+
this->collisions->setZValue(1);
232+
233+
this->edges = this->createItemGroup(QList<QGraphicsItem*>());
234+
this->edges->setZValue(2);
235+
236+
this->path = this->createItemGroup(QList<QGraphicsItem*>());
237+
this->path->setZValue(3);
240238
}
241239

242240
void
@@ -295,6 +293,11 @@ ConfigurationSpaceScene::reset()
295293
void
296294
ConfigurationSpaceScene::resetEdges()
297295
{
296+
if (nullptr == this->edges)
297+
{
298+
return;
299+
}
300+
298301
QList<QGraphicsItem*> items = this->edges->childItems();
299302

300303
while (!items.isEmpty())
@@ -311,6 +314,11 @@ ConfigurationSpaceScene::resetLines()
311314
void
312315
ConfigurationSpaceScene::resetPath()
313316
{
317+
if (nullptr == this->path)
318+
{
319+
return;
320+
}
321+
314322
QList<QGraphicsItem*> items = this->path->childItems();
315323

316324
while (!items.isEmpty())

demos/rlPlanDemo/ConfigurationSpaceScene.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public slots:
108108
void mousePressEvent(QGraphicsSceneMouseEvent* mouseEvent);
109109

110110
private:
111+
QGraphicsItemGroup* collisions;
112+
111113
QGraphicsItemGroup* edges;
112114

113115
QGraphicsItemGroup* path;

0 commit comments

Comments
 (0)