27 #include <QGraphicsLineItem>
28 #include <QGraphicsView>
60 Qt::QueuedConnection);
62 widget.deviceComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
onDeviceSelected(
int)));
68 laserScannerUnit = getProxy<LaserScannerUnitInterfacePrx>(laserScannerUnitName);
69 std::string topicName = laserScannerUnit->getReportTopicName();
72 laserScanners = laserScannerUnit->getConnectedDevices();
81 dialog->addProxyFinder<LaserScannerUnitInterfacePrx>({
"LaserScannerUnit",
"",
"*"});
83 return qobject_cast<SimpleConfigDialog*>(dialog);
91 laserScannerUnitName = dialog->getProxyName(
"LaserScannerUnit");
97 const std::string& name,
98 const LaserScan& newScan,
99 const TimestampBasePtr& timestamp,
100 const Ice::Current&
c)
103 std::unique_lock lock(scanMutex);
105 LaserScan& scan = scans[device];
116 QComboBox* deviceBox = widget.deviceComboBox;
118 std::unique_lock lock(scanMutex);
119 for (
auto& pair : scans)
121 QString deviceName(QString::fromStdString(pair.first.c_str()));
122 if (deviceBox->findText(deviceName) < 0)
124 deviceBox->addItem(deviceName);
128 std::string deviceName(deviceBox->currentText().toUtf8().data());
129 float stepSize = 0.25f;
130 for (LaserScannerInfo
const& scanner : laserScanners)
132 if (scanner.device == deviceName)
134 stepSize = scanner.stepSize;
138 QGraphicsView* view = widget.graphicsView;
140 scene.reset(
new QGraphicsScene());
141 widget.graphicsView->setScene(scene.get());
142 int outerR =
std::min(view->width() / 2, view->height() / 2);
143 scene->addEllipse(-outerR, -outerR, 2 * outerR, 2 * outerR, QPen(QColor(255, 255, 255)));
146 QColor stepColor(QColor::fromRgb(100, 100, 255));
147 QPen stepPen(stepColor);
148 QBrush stepBrush(stepColor);
149 auto line = [&](
float angle,
float d)
152 QGraphicsEllipseItem* item =
153 scene->addEllipse(-di, -di, 2 * di, 2 * di, stepPen, stepBrush);
155 item->setStartAngle(std::round(16.0f *
angle * 180.0 /
M_PI) + 90 * 16);
156 item->setSpanAngle(std::round(stepSize * 16.0f * 180.0 /
M_PI));
159 LaserScan& scan = scans[deviceName];
160 float maxDistance = 1000.0f;
161 for (LaserScanStep& step : scan)
163 if (step.distance > maxDistance)
165 maxDistance = step.distance;
168 float ringDistance = 1000.0f;
169 int numberOfRings = (std::size_t)std::ceil(maxDistance / ringDistance);
170 std::deque<int>& history = numberOfRingsHistory[deviceName];
171 history.push_back(numberOfRings);
172 if (history.size() > 256)
176 int maxNumberOfRings = *std::max_element(history.begin(), history.end());
177 float outerRadius = maxNumberOfRings * ringDistance;
179 for (LaserScanStep& step : scan)
181 line(step.angle, step.distance / outerRadius);
184 for (
int ringIndex = 1; ringIndex <= maxNumberOfRings; ++ringIndex)
186 float ri = 1.0f * ringIndex / maxNumberOfRings * r;
187 scene->addEllipse(-ri, -ri, 2 * ri, 2 * ri, QPen(QColor(200, 200, 200)));
190 view->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
196 if (index < 0 && index >= widget.deviceComboBox->count())
200 std::string deviceName = widget.deviceComboBox->itemText(
index).toStdString();
201 for (LaserScannerInfo
const& scanner : laserScanners)
203 if (scanner.device == deviceName)
205 widget.frameLabel->setText(QString::fromStdString(scanner.frame));
206 widget.minAngleLabel->setText(QString::number(scanner.minAngle));
207 widget.maxAngleLabel->setText(QString::number(scanner.minAngle));
208 widget.stepSizeLabel->setText(QString::number(scanner.stepSize));