Skip to content

Commit d069447

Browse files
committed
Merge pull request PointCloudLibrary#1210 from gregjklein/cropbox
Performance improvement to cropbox
2 parents 22106da + 3fc968a commit d069447

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

filters/include/pcl/filters/impl/crop_box.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* Point Cloud Library (PCL) - www.pointclouds.org
55
* Copyright (c) 2009-2011, Willow Garage, Inc.
6+
* Copyright (c) 2015, Google, Inc.
67
*
78
* All rights reserved.
89
*
@@ -89,6 +90,10 @@ pcl::CropBox<PointT>::applyFilter (std::vector<int> &indices)
8990
inverse_transform = transform.inverse ();
9091
}
9192

93+
bool transform_matrix_is_identity = transform_.matrix ().isIdentity ();
94+
bool translation_is_zero = (translation_ != Eigen::Vector3f::Zero ());
95+
bool inverse_transform_matrix_is_identity = inverse_transform.matrix ().isIdentity ();
96+
9297
for (size_t index = 0; index < indices_->size (); ++index)
9398
{
9499
if (!input_->is_dense)
@@ -100,18 +105,18 @@ pcl::CropBox<PointT>::applyFilter (std::vector<int> &indices)
100105
PointT local_pt = input_->points[(*indices_)[index]];
101106

102107
// Transform point to world space
103-
if (!(transform_.matrix ().isIdentity ()))
108+
if (!transform_matrix_is_identity)
104109
local_pt = pcl::transformPoint<PointT> (local_pt, transform_);
105110

106-
if (translation_ != Eigen::Vector3f::Zero ())
111+
if (translation_is_zero)
107112
{
108113
local_pt.x -= translation_ (0);
109114
local_pt.y -= translation_ (1);
110115
local_pt.z -= translation_ (2);
111116
}
112117

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

117122
// If outside the cropbox

filters/src/crop_box.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Point Cloud Library (PCL) - www.pointclouds.org
55
* Copyright (c) 2009, Willow Garage, Inc.
66
* Copyright (c) 2012-, Open Perception, Inc.
7+
* Copyright (c) 2015, Google, Inc.
78
*
89
* All rights reserved.
910
*
@@ -70,6 +71,10 @@ pcl::CropBox<pcl::PCLPointCloud2>::applyFilter (PCLPointCloud2 &output)
7071
//PointXYZ local_pt;
7172
Eigen::Vector3f local_pt (Eigen::Vector3f::Zero ());
7273

74+
bool transform_matrix_is_identity = transform_.matrix ().isIdentity ();
75+
bool translation_is_zero = (translation_ != Eigen::Vector3f::Zero ());
76+
bool inverse_transform_matrix_is_identity = inverse_transform.matrix ().isIdentity ();
77+
7378
for (size_t index = 0; index < indices_->size (); ++index)
7479
{
7580
// Get local point
@@ -84,18 +89,18 @@ pcl::CropBox<pcl::PCLPointCloud2>::applyFilter (PCLPointCloud2 &output)
8489
continue;
8590

8691
// Transform point to world space
87-
if (!(transform_.matrix().isIdentity()))
92+
if (!transform_matrix_is_identity)
8893
local_pt = transform_ * local_pt;
8994

90-
if (translation_ != Eigen::Vector3f::Zero ())
95+
if (translation_is_zero)
9196
{
9297
local_pt.x () = local_pt.x () - translation_ (0);
9398
local_pt.y () = local_pt.y () - translation_ (1);
9499
local_pt.z () = local_pt.z () - translation_ (2);
95100
}
96101

97102
// Transform point to local space of crop box
98-
if (!(inverse_transform.matrix ().isIdentity ()))
103+
if (!inverse_transform_matrix_is_identity)
99104
local_pt = inverse_transform * local_pt;
100105

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

164+
bool transform_matrix_is_identity = transform_.matrix ().isIdentity ();
165+
bool translation_is_zero = (translation_ != Eigen::Vector3f::Zero ());
166+
bool inverse_transform_matrix_is_identity = inverse_transform.matrix ().isIdentity ();
167+
159168
for (size_t index = 0; index < indices_->size (); index++)
160169
{
161170
// Get local point
@@ -164,18 +173,18 @@ pcl::CropBox<pcl::PCLPointCloud2>::applyFilter (std::vector<int> &indices)
164173
memcpy (&local_pt, &input_->data[offset], sizeof (float)*3);
165174

166175
// Transform point to world space
167-
if (!(transform_.matrix().isIdentity()))
176+
if (!transform_matrix_is_identity)
168177
local_pt = transform_ * local_pt;
169178

170-
if (translation_ != Eigen::Vector3f::Zero ())
179+
if (translation_is_zero)
171180
{
172181
local_pt.x () -= translation_ (0);
173182
local_pt.y () -= translation_ (1);
174183
local_pt.z () -= translation_ (2);
175184
}
176185

177186
// Transform point to local space of crop box
178-
if (!(inverse_transform.matrix().isIdentity()))
187+
if (!(inverse_transform_matrix_is_identity))
179188
local_pt = inverse_transform * local_pt;
180189

181190
// If outside the cropbox

0 commit comments

Comments
 (0)