Skip to content

Commit

Permalink
move ToPoint to src
Browse files Browse the repository at this point in the history
  • Loading branch information
chao committed Sep 29, 2021
1 parent 70b69fe commit 2edc932
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
16 changes: 15 additions & 1 deletion src/lidar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ LidarModel::LidarModel(const std::string& metadata) {
azimuths = TransformDeg2Rad(info.beam_azimuth_angles);
}

Eigen::Vector3f LidarModel::ToPoint(float range,
float theta_enc,
int row) const {
const float n = beam_offset;
const float d = range - n;
const float phi = altitudes[row];
const float cos_phi = std::cos(phi);
const float theta = theta_enc - azimuths[row];

return {d * std::cos(theta) * cos_phi + n * std::cos(theta_enc),
d * std::sin(theta) * cos_phi + n * std::sin(theta_enc),
d * std::sin(phi)};
}

void LidarModel::UpdateCameraInfo(sensor_msgs::CameraInfo& cinfo) const {
cinfo.height = rows;
cinfo.width = cols;
Expand Down Expand Up @@ -146,7 +160,7 @@ void LidarScan::DecodeColumn(const uint8_t* const col_buf,
auto& pt = cloud.at(icol, ipx);
auto& px = image.at<ImageData>(ipx, im_col);
if (col_valid && min_range < range && range < max_range) {
pt.getArray3fMap() = model.ToPoint(range, theta_enc, ipx);
pt.getVector3fMap() = model.ToPoint(range, theta_enc, ipx);

// https://github.com/ouster-lidar/ouster_example/issues/128
// Intensity: whereas most "normal" surfaces lie in between 0 - 1000
Expand Down
18 changes: 4 additions & 14 deletions src/lidar.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,7 @@ struct LidarModel {
///
[[nodiscard]] Eigen::Vector3f ToPoint(float range,
float theta_enc,
int row) const {
const float n = beam_offset;
const float d = range - n;
const float phi = altitudes[row];
const float cos_phi = std::cos(phi);
const float theta = theta_enc - azimuths[row];

return {d * std::cos(theta) * cos_phi + n * std::cos(theta_enc),
d * std::sin(theta) * cos_phi + n * std::sin(theta_enc),
d * std::sin(phi)};
}
int row) const;

/// @brief Return a unique id for a measurement
[[nodiscard]] int Uid(int fid, int mid) const noexcept {
Expand Down Expand Up @@ -105,13 +95,13 @@ struct LidarScan {
/// @brief Starting column of this scan
[[nodiscard]] int StartingCol() const noexcept { return iscan * cols(); }

/// @brief Allocate storage for the scan
void Allocate(int rows, int cols);

/// @brief Detect if there is a jump in the lidar data
/// @return 0 - no jump, >0 - jump forward in time, <0 - jump backward in time
[[nodiscard]] int DetectJump(int uid) noexcept;

/// @brief Allocate storage for the scan
void Allocate(int rows, int cols);

/// @brief Hard reset internal counters and prev_uid
void HardReset() noexcept;

Expand Down

0 comments on commit 2edc932

Please sign in to comment.