12#include <pcl/sample_consensus/sac_model.h>
13#include <pcl/sample_consensus/model_types.h>
22 const Eigen::ArrayXf &pts_x,
23 const Eigen::ArrayXf &pts_y,
24 const Eigen::ArrayXf &pts_z);
35 const float par_a (par [0]);
36 const float par_b (par [1]);
37 const float par_h (par [2]);
38 const float par_k (par [3]);
39 const float par_t (par [4]);
41 x = par_h + std::cos (par_t) * par_a * std::cos (th) - std::sin (par_t) * par_b * std::sin (th);
42 y = par_k + std::sin (par_t) * par_a * std::cos (th) + std::cos (par_t) * par_b * std::sin (th);
57 constexpr float phi (1.61803398874989484820f);
58 float tl (th_min), tu (th_max);
59 float ta = tl + (tu - tl) * (1.0f - 1.0f / phi);
60 float tb = tl + (tu - tl) * 1.0f / phi;
62 while ((tu - tl) > epsilon)
64 float x_a (0.0f), y_a (0.0f);
66 float squared_dist_ta = (u - x_a) * (u - x_a) + (v - y_a) * (v - y_a);
68 float x_b (0.0f), y_b (0.0f);
70 float squared_dist_tb = (u - x_b) * (u - x_b) + (v - y_b) * (v - y_b);
72 if (squared_dist_ta < squared_dist_tb)
76 ta = tl + (tu - tl) * (1.0f - 1.0f / phi);
78 else if (squared_dist_ta > squared_dist_tb)
82 tb = tl + (tu - tl) * 1.0f / phi;
88 ta = tl + (tu - tl) * (1.0f - 1.0f / phi);
89 tb = tl + (tu - tl) * 1.0f / phi;
92 return (tl + tu) / 2.0f;
102 inline Eigen::Vector2f
103 dvec2ellipse (
const Eigen::VectorXf& par,
float u,
float v,
float& th_opt)
105 const float par_h = par [2];
106 const float par_k = par [3];
108 const Eigen::Vector2f center (par_h, par_k);
109 Eigen::Vector2f p (u, v);
112 Eigen::Vector2f x_axis (0.0f, 0.0f);
116 Eigen::Vector2f y_axis (0.0f, 0.0f);
120 const float x_proj = p.dot (x_axis) / x_axis.norm ();
121 const float y_proj = p.dot (y_axis) / y_axis.norm ();
123 float th_min (0.0f), th_max (0.0f);
124 const float th = std::atan2 (y_proj, x_proj);
126 if (th < -
static_cast<float> (
M_PI / 2.0))
128 th_min = -
static_cast<float> (
M_PI);
129 th_max = -
static_cast<float> (
M_PI / 2.0);
133 th_min = -
static_cast<float> (
M_PI / 2.0);
136 else if (th <
static_cast<float> (
M_PI / 2.0))
139 th_max =
static_cast<float> (
M_PI / 2.0);
143 th_min =
static_cast<float> (
M_PI / 2.0);
144 th_max =
static_cast<float> (
M_PI);
148 float x (0.0f), y (0.0f);
150 return {u - x, v - y};
177 template <
typename Po
intT>
192 using Ptr = shared_ptr<SampleConsensusModelEllipse3D<PointT>>;
193 using ConstPtr = shared_ptr<const SampleConsensusModelEllipse3D<PointT>>;
252 Eigen::VectorXf &model_coefficients)
const override;
260 std::vector<double> &distances)
const override;
269 const double threshold,
280 const double threshold)
const override;
290 const Eigen::VectorXf &model_coefficients,
291 Eigen::VectorXf &optimized_coefficients)
const override;
301 const Eigen::VectorXf &model_coefficients,
303 bool copy_data_fields =
true)
const override;
312 const Eigen::VectorXf &model_coefficients,
313 const double threshold)
const override;
327 isModelValid (
const Eigen::VectorXf &model_coefficients)
const override;
337#ifdef PCL_NO_PRECOMPILE
338#include <pcl/sample_consensus/impl/sac_model_ellipse3d.hpp>
PointCloud represents the base class in PCL for storing collections of 3D points.
SampleConsensusModelEllipse3D defines a model for 3D ellipse segmentation.
typename SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
void optimizeModelCoefficients(const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const override
Recompute the 3d ellipse coefficients using the given inlier set and return them to the user.
typename SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
pcl::SacModel getModelType() const override
Return a unique id for this model (SACMODEL_ELLIPSE3D).
std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const override
Count all the points which respect the given model coefficients as inliers.
SampleConsensusModelEllipse3D(const SampleConsensusModelEllipse3D &source)
Copy constructor.
shared_ptr< const SampleConsensusModelEllipse3D< PointT > > ConstPtr
SampleConsensusModelEllipse3D & operator=(const SampleConsensusModelEllipse3D &source)
Copy constructor.
void projectPoints(const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true) const override
Create a new point cloud with inliers projected onto the 3d ellipse model.
bool computeModelCoefficients(const Indices &samples, Eigen::VectorXf &model_coefficients) const override
Check whether the given index samples can form a valid 3D ellipse model, compute the model coefficien...
SampleConsensusModelEllipse3D(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelEllipse3D.
~SampleConsensusModelEllipse3D() override=default
Empty destructor.
typename SampleConsensusModel< PointT >::PointCloud PointCloud
bool doSamplesVerifyModel(const std::set< index_t > &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const override
Verify whether a subset of indices verifies the given 3d ellipse model coefficients.
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Compute all distances from the cloud data to a given 3D ellipse model.
SampleConsensusModelEllipse3D(const PointCloudConstPtr &cloud, const Indices &indices, bool random=false)
Constructor for base SampleConsensusModelEllipse3D.
bool isSampleGood(const Indices &samples) const override
Check if a sample of indices results in a good sample of points indices.
bool isModelValid(const Eigen::VectorXf &model_coefficients) const override
Check whether a model is valid given the user constraints.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all distances from the cloud data to a given 3D ellipse model.
shared_ptr< SampleConsensusModelEllipse3D< PointT > > Ptr
SampleConsensusModel represents the base model class.
double radius_min_
The minimum and maximum radius limits for the model.
unsigned int sample_size_
The size of a sample from which the model is computed.
typename PointCloud::ConstPtr PointCloudConstPtr
IndicesPtr indices_
A pointer to the vector of point indices to use.
PointCloudConstPtr input_
A boost shared pointer to the point cloud data array.
std::string model_name_
The model name.
unsigned int model_size_
The number of coefficients in the model.
typename PointCloud::Ptr PointCloudPtr
std::vector< double > error_sqr_dists_
A vector holding the distances to the computed model.
void get_ellipse_point(const Eigen::VectorXf &par, float th, float &x, float &y)
Internal function to compute ellipse point from parametric coefficients and angle.
float golden_section_search(const Eigen::VectorXf &par, float u, float v, float th_min, float th_max, float epsilon)
Internal function to find the optimal angle using Golden Section Search.
Eigen::Vector2f dvec2ellipse(const Eigen::VectorXf &par, float u, float v, float &th_opt)
Internal function to compute the shortest distance vector from a point to an ellipse.
PCL_EXPORTS int optimizeModelCoefficientsEllipse3D(Eigen::VectorXf &coeff, const Eigen::ArrayXf &pts_x, const Eigen::ArrayXf &pts_y, const Eigen::ArrayXf &pts_z)
Internal function to optimize ellipse coefficients.
IndicesAllocator<> Indices
Type used for indices in PCL.
A point structure representing Euclidean xyz coordinates, and the RGB color.