Skip to content

Commit

Permalink
Move matrix identity checks out of inner loops in cropbox to increase…
Browse files Browse the repository at this point in the history
… performance.
  • Loading branch information
gregjklein committed Apr 15, 2015
1 parent 22106da commit 3fc968a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
11 changes: 8 additions & 3 deletions filters/include/pcl/filters/impl/crop_box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2009-2011, Willow Garage, Inc.
* Copyright (c) 2015, Google, Inc.
*
* All rights reserved.
*
Expand Down Expand Up @@ -89,6 +90,10 @@ pcl::CropBox<PointT>::applyFilter (std::vector<int> &indices)
inverse_transform = transform.inverse ();
}

bool transform_matrix_is_identity = transform_.matrix ().isIdentity ();
bool translation_is_zero = (translation_ != Eigen::Vector3f::Zero ());
bool inverse_transform_matrix_is_identity = inverse_transform.matrix ().isIdentity ();

for (size_t index = 0; index < indices_->size (); ++index)
{
if (!input_->is_dense)
Expand All @@ -100,18 +105,18 @@ pcl::CropBox<PointT>::applyFilter (std::vector<int> &indices)
PointT local_pt = input_->points[(*indices_)[index]];

// Transform point to world space
if (!(transform_.matrix ().isIdentity ()))
if (!transform_matrix_is_identity)
local_pt = pcl::transformPoint<PointT> (local_pt, transform_);

if (translation_ != Eigen::Vector3f::Zero ())
if (translation_is_zero)
{
local_pt.x -= translation_ (0);
local_pt.y -= translation_ (1);
local_pt.z -= translation_ (2);
}

// Transform point to local space of crop box
if (!(inverse_transform.matrix ().isIdentity ()))
if (!inverse_transform_matrix_is_identity)
local_pt = pcl::transformPoint<PointT> (local_pt, inverse_transform);

// If outside the cropbox
Expand Down
21 changes: 15 additions & 6 deletions filters/src/crop_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2009, Willow Garage, Inc.
* Copyright (c) 2012-, Open Perception, Inc.
* Copyright (c) 2015, Google, Inc.
*
* All rights reserved.
*
Expand Down Expand Up @@ -70,6 +71,10 @@ pcl::CropBox<pcl::PCLPointCloud2>::applyFilter (PCLPointCloud2 &output)
//PointXYZ local_pt;
Eigen::Vector3f local_pt (Eigen::Vector3f::Zero ());

bool transform_matrix_is_identity = transform_.matrix ().isIdentity ();
bool translation_is_zero = (translation_ != Eigen::Vector3f::Zero ());
bool inverse_transform_matrix_is_identity = inverse_transform.matrix ().isIdentity ();

for (size_t index = 0; index < indices_->size (); ++index)
{
// Get local point
Expand All @@ -84,18 +89,18 @@ pcl::CropBox<pcl::PCLPointCloud2>::applyFilter (PCLPointCloud2 &output)
continue;

// Transform point to world space
if (!(transform_.matrix().isIdentity()))
if (!transform_matrix_is_identity)
local_pt = transform_ * local_pt;

if (translation_ != Eigen::Vector3f::Zero ())
if (translation_is_zero)
{
local_pt.x () = local_pt.x () - translation_ (0);
local_pt.y () = local_pt.y () - translation_ (1);
local_pt.z () = local_pt.z () - translation_ (2);
}

// Transform point to local space of crop box
if (!(inverse_transform.matrix ().isIdentity ()))
if (!inverse_transform_matrix_is_identity)
local_pt = inverse_transform * local_pt;

// If outside the cropbox
Expand Down Expand Up @@ -156,6 +161,10 @@ pcl::CropBox<pcl::PCLPointCloud2>::applyFilter (std::vector<int> &indices)
//PointXYZ local_pt;
Eigen::Vector3f local_pt (Eigen::Vector3f::Zero ());

bool transform_matrix_is_identity = transform_.matrix ().isIdentity ();
bool translation_is_zero = (translation_ != Eigen::Vector3f::Zero ());
bool inverse_transform_matrix_is_identity = inverse_transform.matrix ().isIdentity ();

for (size_t index = 0; index < indices_->size (); index++)
{
// Get local point
Expand All @@ -164,18 +173,18 @@ pcl::CropBox<pcl::PCLPointCloud2>::applyFilter (std::vector<int> &indices)
memcpy (&local_pt, &input_->data[offset], sizeof (float)*3);

// Transform point to world space
if (!(transform_.matrix().isIdentity()))
if (!transform_matrix_is_identity)
local_pt = transform_ * local_pt;

if (translation_ != Eigen::Vector3f::Zero ())
if (translation_is_zero)
{
local_pt.x () -= translation_ (0);
local_pt.y () -= translation_ (1);
local_pt.z () -= translation_ (2);
}

// Transform point to local space of crop box
if (!(inverse_transform.matrix().isIdentity()))
if (!(inverse_transform_matrix_is_identity))
local_pt = inverse_transform * local_pt;

// If outside the cropbox
Expand Down

0 comments on commit 3fc968a

Please sign in to comment.