40#include "ErrorStatus.h"
41#include "CommonTypes.h"
42#include "profiler/parameters/ScanParameters.h"
44#include "ProfilerInfo.h"
46constexpr double kPitch = 1e-3;
47constexpr long long kInitEncoderValue = 0x0FFFFFFF;
54 std::cout <<
"........................................." << std::endl;
55 std::cout <<
"Profiler Model Name: " << profilerInfo.
model << std::endl;
56 std::cout <<
"Controller Serial Number: " << profilerInfo.
controllerSN << std::endl;
57 std::cout <<
"Sensor Serial Number: " << profilerInfo.
sensorSN << std::endl;
58 std::cout <<
"Profiler IP Address: " << profilerInfo.
ipAddress << std::endl;
59 std::cout <<
"Profiler IP Subnet Mask: " << profilerInfo.
subnetMask << std::endl;
60 std::cout <<
"Profiler IP Assignment Method: "
63 std::cout <<
"Hardware Version: "
65 std::cout <<
"Firmware Version: "
67 std::cout <<
"........................................." << std::endl;
68 std::cout << std::endl;
73 std::cout <<
".....Profiler temperatures....." << std::endl;
74 std::cout <<
"Controller CPU: " << std::setprecision(4)
76 std::cout <<
"Sensor CPU: " << std::setprecision(4)
78 std::cout <<
"..............................." << std::endl;
79 std::cout << std::endl;
88 std::cout <<
"Find Mech-Eye 3D Laser Profilers..." << std::endl;
89 std::vector<mmind::eye::ProfilerInfo> profilerInfoList =
92 if (profilerInfoList.empty()) {
93 std::cout <<
"No Mech-Eye 3D Laser Profiler found." << std::endl;
97 for (
int i = 0; i < profilerInfoList.size(); i++) {
98 std::cout <<
"Mech-Eye 3D Laser profiler index : " << i << std::endl;
99 printProfilerInfo(profilerInfoList[i]);
102 std::cout <<
"Please enter the profiler index you want to connect: ";
103 unsigned inputIndex = 0;
108 if (std::regex_match(str.begin(), str.end(), std::regex{
"[0-9]+"}) &&
109 atoi(str.c_str()) < profilerInfoList.size()) {
110 inputIndex = atoi(str.c_str());
113 std::cout <<
"Input invalid! Please enter the profiler index you want to connect: ";
117 status = profiler.
connect(profilerInfoList[inputIndex]);
119 if (!status.
isOK()) {
124 std::cout <<
"Connect Mech-Eye 3D Laser Profiler Successfully." << std::endl;
128inline std::vector<mmind::eye::Profiler> findAndConnectMultiProfiler()
130 std::cout <<
"Find Mech-Eye 3D Laser Profilers..." << std::endl;
131 std::vector<mmind::eye::ProfilerInfo> profilerInfoList =
134 if (profilerInfoList.empty()) {
135 std::cout <<
"No Mech-Eye 3D Laser Profilers found." << std::endl;
139 for (
int i = 0; i < profilerInfoList.size(); i++) {
140 std::cout <<
"Mech-Eye 3D Laser Profiler index : " << i << std::endl;
141 printProfilerInfo(profilerInfoList[i]);
145 std::set<unsigned> indices;
148 std::cout <<
"Please enter the device index you want to connect: " << std::endl;
149 std::cout <<
"Enter the character 'c' to terminate adding devices" << std::endl;
154 if (std::regex_match(str.begin(), str.end(), std::regex{
"[0-9]+"}) &&
155 atoi(str.c_str()) < profilerInfoList.size())
156 indices.insert(atoi(str.c_str()));
158 std::cout <<
"Input invalid. Please enter the device index you want to connect: ";
161 std::vector<mmind::eye::Profiler> profilerList{};
163 auto iter = indices.cbegin();
164 for (
int i = 0; i < indices.size(); ++i, ++iter) {
166 auto status = profiler.
connect(profilerInfoList[*iter]);
168 profilerList.push_back(profiler);
176inline bool confirmCapture()
178 std::cout <<
"Do you want the profiler to capture image? Please input y/n to confirm: "
181 std::string confirmStr;
182 std::cin >> confirmStr;
183 if (confirmStr ==
"y") {
185 }
else if (confirmStr ==
"n") {
186 std::cout <<
"program ends!" << std::endl;
189 std::cout <<
"Please input y/n again!" << std::endl;
194int shiftEncoderValsAroundZero(
unsigned int oriVal,
long long initValue = kInitEncoderValue)
196 return static_cast<int>(oriVal - initValue);
199bool saveDataToPly(
float* data,
int* yValues,
int captureLineCount,
int dataWidth,
float xUnit,
200 float yUnit,
const std::string& fileName,
bool isOrganized)
202 FILE* fp = fopen(fileName.c_str(),
"w");
207 unsigned validPointCount{0};
209 for (
int y = 0; y < captureLineCount; ++y) {
210 for (
int x = 0; x < dataWidth; ++x) {
211 if (!std::isnan(data[y * dataWidth + x]))
217 fprintf(fp,
"ply\n");
218 fprintf(fp,
"format ascii 1.0\n");
219 fprintf(fp,
"comment File generated\n");
220 fprintf(fp,
"comment x y z data unit in mm\n");
221 fprintf(fp,
"element vertex %u\n",
222 isOrganized ?
static_cast<unsigned>(captureLineCount * dataWidth) : validPointCount);
223 fprintf(fp,
"property float x\n");
224 fprintf(fp,
"property float y\n");
225 fprintf(fp,
"property float z\n");
226 fprintf(fp,
"end_header\n");
228 for (
int y = 0; y < captureLineCount; ++y) {
229 for (
int x = 0; x < dataWidth; ++x) {
230 if (!std::isnan(data[y * dataWidth + x]))
231 fprintf(fp,
"%f %f %f\n",
static_cast<float>(x * xUnit * kPitch),
232 static_cast<float>(yValues[y] * yUnit * kPitch), data[y * dataWidth + x]);
233 else if (isOrganized)
234 fprintf(fp,
"nan nan nan\n");
242bool saveDataToCsv(
float* data,
int* yValues,
int captureLineCount,
int dataWidth,
float xUnit,
243 float yUnit,
const std::string& fileName,
bool isOrganized)
245 FILE* fp = fopen(fileName.c_str(),
"w");
250 fprintf(fp,
"X,Y,Z\n");
252 for (
int y = 0; y < captureLineCount; ++y) {
253 for (
int x = 0; x < dataWidth; ++x) {
254 if (!std::isnan(data[y * dataWidth + x]))
255 fprintf(fp,
"%f,%f,%f\n",
static_cast<float>(x * xUnit * kPitch),
256 static_cast<float>(yValues[y] * yUnit * kPitch), data[y * dataWidth + x]);
257 else if (isOrganized)
258 fprintf(fp,
"nan,nan,nan\n");
267 bool savePLY =
true,
bool saveCSV =
true,
bool isOrganized =
true)
275 userSet.
getFloatValue(mmind::eye::point_cloud_resolutions::XAxisResolution::name, xUnit);
276 if (!status.
isOK()) {
283 status = userSet.
getFloatValue(mmind::eye::point_cloud_resolutions::YResolution::name, yUnit);
284 if (!status.
isOK()) {
306 int lineScanTriggerSource{};
307 status = userSet.
getEnumValue(mmind::eye::trigger_settings::LineScanTriggerSource::name,
308 lineScanTriggerSource);
309 if (!status.
isOK()) {
314 bool useEncoderValues =
315 lineScanTriggerSource ==
316 static_cast<int>(mmind::eye::trigger_settings::LineScanTriggerSource::Value::Encoder);
318 int triggerInterval{};
319 status = userSet.
getIntValue(mmind::eye::trigger_settings::EncoderTriggerInterval::name,
321 if (!status.
isOK()) {
327 std::vector<int> encoderVals;
328 encoderVals.reserve(batch.
height());
330 for (
int r = 0; r < batch.
height(); ++r)
331 encoderVals.push_back(
332 useEncoderValues ? shiftEncoderValsAroundZero(encoder[r], encoder[0]) / triggerInterval
335 std::cout <<
"Save the point cloud." << std::endl;
338 xUnit, yUnit,
"PointCloud.csv", isOrganized);
341 xUnit, yUnit,
"PointCloud.ply", isOrganized);
const ElementData * data() const
Returns the pointer to the element data.
Represents a batch of profiles, which can be obtained by calling Profiler::retrieveBatchData()....
bool isEmpty() const
Checks if the ProfileBatch object has no elements.
EncoderArray getEncoderArray() const
Gets an array of encoder values of all profiles in the batch. Each profile data corresponds to an enc...
size_t width() const
Returns the width of the ProfileBatch object (the number of data points per profile).
size_t height() const
Returns the height of the ProfileBatch object (the number of profiles in the batch).
DepthMap getDepthMap() const
Gets the depth map data in the batch. Each point in DepthMap contains the Z information in the laser ...
Operates the laser profiler. Use Profiler::connect to connect an available laser profiler,...
static std::vector< ProfilerInfo > discoverProfilers()
Discovers all available laser profilers, and returns the laser profiler information list....
ErrorStatus connect(const ProfilerInfo &info, unsigned int timeoutMs=5000)
Connects to a laser profiler via ProfilerInfo.
ErrorStatus getIntValue(const std::string ¶meterName, int &value) const
Gets the current value of an _Int-type device parameter. See Parameter for details.
ErrorStatus getFloatValue(const std::string ¶meterName, double &value) const
Gets the current value of a _Float-type device parameter. See Parameter for details.
ErrorStatus getEnumValue(const std::string ¶meterName, int &value) const
Gets the current value of an _Enum-type device parameter in the form of the integer value....
std::string toString() const
Converts a Version object to a string.
Describes the types of errors.
bool isOK() const
Returns true if the operation succeeded.
Describes the laser profiler information.
Version hardwareVersion
The version of the hardware. The hardware cannot be upgraded.
Version firmwareVersion
The version of the firmware. The firmware can be upgraded.
std::string subnetMask
The IP subnet mask of the laser profiler.
IpAssignmentMethod ipAssignmentMethod
The IP address assignment method of the laser profiler.
std::string model
The laser profiler model.
std::string controllerSN
The controller serial number.
std::string sensorSN
The sensor serial number.
std::string ipAddress
The IP address of the laser profiler.
Describes the laser profiler's statuses.
float controllerCpuTemperature
The temperature (in °C) of the controller CPU.
float sensorCpuTemperature
The temperature (in °C) of the FPGA.