3#include <SimoxUtility/math/pose/invert.h>
4#include <SimoxUtility/math/pose/pose.h>
39 Eigen::Vector3f normal,
40 Eigen::Vector3f center)
42 initAlignedPointCloud(cloud, normal, center);
49 for (
size_t i = 0; i <
numSteps; ++i)
63 const pcl::PointCloud<FitKnownRectangleRotationMaxPoints::PointT>& cloud,
64 Eigen::Vector3f normal,
65 Eigen::Vector3f center)
72 FitKnownRectangleRotationMaxPoints::initAlignedPointCloud(
73 const pcl::PointCloud<FitKnownRectangleRotationMaxPoints::PointT>& cloud,
74 Eigen::Vector3f normal,
75 Eigen::Vector3f center)
77 using namespace Eigen;
80 Eigen::Matrix4f transform = simox::math::pose(-center);
83 simox::math::pose(Quaternionf::FromTwoVectors(normal, Vector3f::UnitZ())) * transform;
86 pcl::transformPointCloud(cloud, *
aligned, transform);
90 FitKnownRectangleRotationMaxPoints::getAlignedPointCloud() const
97 FitKnownRectangleRotationMaxPoints::setRotated(
float angle)
const
99 const Eigen::Matrix3f rot =
100 Eigen::AngleAxisf(-
angle, Eigen::Vector3f::UnitZ()).toRotationMatrix();
101 pcl::transformPointCloud(*
aligned, *
rotated, simox::math::pose(rot));
105 FitKnownRectangleRotationMaxPoints::isInlier(
const PointT& p)
const
116 long count = std::count_if(
118 return size_t(count);
127 pcl::PointIndicesPtr indices(
new pcl::PointIndices);
128 for (
size_t i = 0; i <
rotated->size(); ++i)
130 if (isInlier(
rotated->points[i]))
132 indices->indices.push_back(
int(i));
142 Eigen::AngleAxisf localRotation(
angle, Eigen::Vector3f::UnitZ());
143 return simox::math::inverted_pose(
alignedTransform) * simox::math::pose(localRotation);
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr aligned
Transformed so center is at 0 and z = normal.
Eigen::Vector2f rectangleSize
The rectangle size.
std::vector< size_t > inlierCounts
The inlier counts per step.
float bestAngle
The best angle.
void setInputCloud(const pcl::PointCloud< PointT > &cloud, Eigen::Vector3f normal, Eigen::Vector3f center)
Set the input cloud and the rectangle's position and normal.
std::vector< size_t > getInlierCounts() const
Get the inlier counts per step.
float getBestAngle() const
Get the best local rotation angle.
pcl::PointIndicesPtr findInliersOfAngle(float angle) const
Get the inliers for a given local rotation angle.
float stepToAngle(Int step) const
Get the local rotation angle of a solution step.
Eigen::Matrix4f alignedTransform
Transformation applied to get aligned.
void setNumSteps(const size_t &value)
Set the number of solution steps, i.e. the resolution of the solution space.
Eigen::Matrix4f angleToPose(float angle)
Get the global pose corresponding to a local rotation angle.
FitKnownRectangleRotationMaxPoints()
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr rotated
Buffer for point clouds rotated for inlier counting.
size_t numSteps
The number of steps (i.e. resolution of solution space).
size_t countInliersOfAngle(float angle) const
Count the inliers for a given local rotation angle.
size_t getNumSteps() const
Eigen::Matrix4f fit()
Count the number of inliers per rotation step, and return the global pose corresponding to the rotati...
Eigen::Vector2f getRectangleSize() const
void setRectangleSize(const Eigen::Vector2f &value)
Set the rectangle size.
pcl::PointCloud< Point > PointCloud
double angle(const Point &a, const Point &b, const Point &c)