25 #include <QGraphicsView>
26 #include <QGraphicsLineItem>
60 connect(widget.deviceComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
onDeviceSelected(
int)));
66 laserScannerUnit = getProxy<LaserScannerUnitInterfacePrx>(laserScannerUnitName);
67 std::string topicName = laserScannerUnit->getReportTopicName();
70 laserScanners = laserScannerUnit->getConnectedDevices();
78 dialog->addProxyFinder<LaserScannerUnitInterfacePrx>({
"LaserScannerUnit",
"",
"*"});
80 return qobject_cast<SimpleConfigDialog*>(dialog);
87 laserScannerUnitName = dialog->getProxyName(
"LaserScannerUnit");
94 std::unique_lock lock(scanMutex);
96 LaserScan& scan = scans[device];
106 QComboBox* deviceBox = widget.deviceComboBox;
108 std::unique_lock lock(scanMutex);
109 for (
auto& pair : scans)
111 QString deviceName(QString::fromStdString(pair.first.c_str()));
112 if (deviceBox->findText(deviceName) < 0)
114 deviceBox->addItem(deviceName);
118 std::string deviceName(deviceBox->currentText().toUtf8().data());
119 float stepSize = 0.25f;
120 for (LaserScannerInfo
const& scanner : laserScanners)
122 if (scanner.device == deviceName)
124 stepSize = scanner.stepSize;
128 QGraphicsView* view = widget.graphicsView;
130 scene.reset(
new QGraphicsScene());
131 widget.graphicsView->setScene(scene.get());
132 int outerR =
std::min(view->width() / 2, view->height() / 2);
133 scene->addEllipse(-outerR, -outerR, 2 * outerR, 2 * outerR, QPen(QColor(255, 255, 255)));
136 QColor stepColor(QColor::fromRgb(100, 100, 255));
137 QPen stepPen(stepColor);
138 QBrush stepBrush(stepColor);
139 auto line = [&](
float angle,
float d)
142 QGraphicsEllipseItem* item = scene->addEllipse(-di, -di, 2 * di, 2 * di, stepPen, stepBrush);
144 item->setStartAngle(std::round(16.0f *
angle * 180.0 /
M_PI) + 90 * 16);
145 item->setSpanAngle(std::round(stepSize * 16.0f * 180.0 /
M_PI));
148 LaserScan& scan = scans[deviceName];
149 float maxDistance = 1000.0f;
150 for (LaserScanStep& step : scan)
152 if (step.distance > maxDistance)
154 maxDistance = step.distance;
157 float ringDistance = 1000.0f;
158 int numberOfRings = (std::size_t)std::ceil(maxDistance / ringDistance);
159 std::deque<int>& history = numberOfRingsHistory[deviceName];
160 history.push_back(numberOfRings);
161 if (history.size() > 256)
165 int maxNumberOfRings = *std::max_element(history.begin(), history.end());
166 float outerRadius = maxNumberOfRings * ringDistance;
168 for (LaserScanStep& step : scan)
170 line(step.angle, step.distance / outerRadius);
173 for (
int ringIndex = 1; ringIndex <= maxNumberOfRings; ++ringIndex)
175 float ri = 1.0f * ringIndex / maxNumberOfRings * r;
176 scene->addEllipse(-ri, -ri, 2 * ri, 2 * ri, QPen(QColor(200, 200, 200)));
179 view->fitInView(scene->itemsBoundingRect(), Qt::KeepAspectRatio);
184 if (index < 0 && index >= widget.deviceComboBox->count())
188 std::string deviceName = widget.deviceComboBox->itemText(
index).toStdString();
189 for (LaserScannerInfo
const& scanner : laserScanners)
191 if (scanner.device == deviceName)
193 widget.frameLabel->setText(QString::fromStdString(scanner.frame));
194 widget.minAngleLabel->setText(QString::number(scanner.minAngle));
195 widget.maxAngleLabel->setText(QString::number(scanner.minAngle));
196 widget.stepSizeLabel->setText(QString::number(scanner.stepSize));