Skip to content

Commit

Permalink
Eliminate unnecessary virtual calls
Browse files Browse the repository at this point in the history
  • Loading branch information
victorreijgwart committed Sep 29, 2023
1 parent 4e0a172 commit 9219056
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class OusterProjector : public ProjectorBase {

explicit OusterProjector(const Config& config);

IndexElement getNumRows() const final { return config_.elevation.num_cells; }
IndexElement getNumColumns() const final { return config_.azimuth.num_cells; }
Vector2D getMinImageCoordinates() const final {
return {config_.elevation.min_angle, config_.azimuth.min_angle};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ class PinholeCameraProjector : public ProjectorBase {
using Config = PinholeCameraProjectorConfig;

explicit PinholeCameraProjector(const Config& config)
: ProjectorBase(Vector2D::Ones(), Vector2D::Zero()),
: ProjectorBase({config_.width, config_.height}, Vector2D::Ones(),
Vector2D::Zero()),
config_(config.checkValid()) {}

IndexElement getNumRows() const final { return config_.width; }
IndexElement getNumColumns() const final { return config_.height; }
Vector2D getMinImageCoordinates() const final {
return indexToImage(Index2D::Zero());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ class ProjectorBase {
using Ptr = std::shared_ptr<ProjectorBase>;
using ConstPtr = std::shared_ptr<const ProjectorBase>;

ProjectorBase(Vector2D index_to_image_scale_factor, Vector2D image_offset)
: index_to_image_scale_factor_(std::move(index_to_image_scale_factor)),
ProjectorBase(Index2D dimensions, Vector2D index_to_image_scale_factor,
Vector2D image_offset)
: dimensions_(std::move(dimensions)),
index_to_image_scale_factor_(std::move(index_to_image_scale_factor)),
image_offset_(std::move(image_offset)) {}
virtual ~ProjectorBase() = default;

virtual IndexElement getNumRows() const = 0;
virtual IndexElement getNumColumns() const = 0;
Index2D getDimensions() const { return {getNumRows(), getNumColumns()}; }
IndexElement getNumRows() const { dimensions_.x(); }
IndexElement getNumColumns() const { dimensions_.y(); }
Index2D getDimensions() const { return dimensions_; }
virtual Vector2D getMinImageCoordinates() const = 0;
virtual Vector2D getMaxImageCoordinates() const = 0;
virtual Eigen::Matrix<bool, 3, 1> sensorAxisIsPeriodic() const = 0;
Expand Down Expand Up @@ -90,6 +92,7 @@ class ProjectorBase {
const Point3D& t_W_C) const = 0;

protected:
const Index2D dimensions_;
const Vector2D index_to_image_scale_factor_;
const Vector2D image_to_index_scale_factor_ =
Vector2D::Ones().cwiseQuotient(index_to_image_scale_factor_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class SphericalProjector : public ProjectorBase {

explicit SphericalProjector(const Config& config);

IndexElement getNumRows() const final { return config_.elevation.num_cells; }
IndexElement getNumColumns() const final { return config_.azimuth.num_cells; }
Vector2D getMinImageCoordinates() const final {
return {config_.elevation.min_angle, config_.azimuth.min_angle};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace wavemap {
OusterProjector::OusterProjector(const OusterProjector::Config& config)
: ProjectorBase(
{config_.elevation.num_cells, config_.azimuth.num_cells},
Vector2D(config.elevation.max_angle - config.elevation.min_angle,
config.azimuth.max_angle - config.azimuth.min_angle)
.cwiseQuotient(Index2D(config.elevation.num_cells - 1,
config.azimuth.num_cells - 1)
.cast<FloatingPoint>()),
Vector2D(config.elevation.min_angle, config.azimuth.min_angle)),
{config.elevation.min_angle, config.azimuth.min_angle}),
config_(config.checkValid()) {}

Eigen::Matrix<bool, 3, 1> OusterProjector::sensorAxisIsPeriodic() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace wavemap {
SphericalProjector::SphericalProjector(const SphericalProjector::Config& config)
: ProjectorBase(
{config_.elevation.num_cells, config_.azimuth.num_cells},
Vector2D(config.elevation.max_angle - config.elevation.min_angle,
config.azimuth.max_angle - config.azimuth.min_angle)
.cwiseQuotient(Index2D(config.elevation.num_cells - 1,
config.azimuth.num_cells - 1)
.cast<FloatingPoint>()),
Vector2D(config.elevation.min_angle, config.azimuth.min_angle)),
{config.elevation.min_angle, config.azimuth.min_angle}),
config_(config.checkValid()) {}

Eigen::Matrix<bool, 3, 1> SphericalProjector::sensorAxisIsPeriodic() const {
Expand Down

0 comments on commit 9219056

Please sign in to comment.