41 #include "auxiliary.h"
42 #include <pcl/recognition/ransac_based/voxel_structure.h>
43 #include <pcl/recognition/ransac_based/orr_octree.h>
45 #include <pcl/pcl_exports.h>
46 #include <pcl/point_cloud.h>
68 float frac_of_points_for_registration,
void* user_data =
nullptr)
69 : obj_name_(object_name),
70 user_data_ (user_data)
72 octree_.build (points, voxel_size, &normals);
74 const std::vector<ORROctree::Node*>& full_leaves = octree_.getFullLeaves ();
75 if ( full_leaves.empty () )
79 auto it = full_leaves.begin ();
80 const float *p = (*it)->getData ()->getPoint ();
82 bounds_of_octree_points_[0] = bounds_of_octree_points_[1] = p[0];
83 bounds_of_octree_points_[2] = bounds_of_octree_points_[3] = p[1];
84 bounds_of_octree_points_[4] = bounds_of_octree_points_[5] = p[2];
87 for ( ++it ; it != full_leaves.end () ; ++it )
89 aux::add3 (octree_center_of_mass_, (*it)->getData ()->getPoint ());
93 int num_octree_points =
static_cast<int> (full_leaves.size ());
95 aux::mult3 (octree_center_of_mass_, 1.0f/
static_cast<float> (num_octree_points));
97 int num_points_for_registration =
static_cast<int> (
static_cast<float> (num_octree_points)*frac_of_points_for_registration);
98 points_for_registration_.resize (
static_cast<std::size_t
> (num_points_for_registration));
101 std::vector<int> ids (num_octree_points);
102 for (
int i = 0 ; i < num_octree_points ; ++i )
109 for (
int i = 0 ; i < num_points_for_registration ; ++i )
112 randgen.
setParameters (0,
static_cast<int> (ids.size ()) - 1);
113 int rand_pos = randgen.
run ();
116 aux::copy3 (octree_.getFullLeaves ()[ids[rand_pos]]->getData ()->getPoint (), points_for_registration_[i]);
119 ids.erase (ids.begin() + rand_pos);
125 inline const std::string&
146 return (octree_center_of_mass_);
152 return (bounds_of_octree_points_);
158 return (points_for_registration_);
164 float octree_center_of_mass_[3];
165 float bounds_of_octree_points_[6];
170 using node_data_pair_list = std::list<std::pair<const ORROctree::Node::Data*, const ORROctree::Node::Data*> >;
177 ModelLibrary (
float pair_width,
float voxel_size,
float max_coplanarity_angle = 3.0f*AUX_DEG_TO_RADIANS);
193 max_coplanarity_angle_ = max_coplanarity_angle_degrees*AUX_DEG_TO_RADIANS;
201 ignore_coplanar_opps_ =
true;
209 ignore_coplanar_opps_ =
false;
223 float frac_of_points_for_registration,
void* user_data =
nullptr);
229 return (hash_table_);
235 auto it = models_.find (name);
236 if ( it != models_.end () )
242 inline const std::map<std::string,Model*>&
261 bool ignore_coplanar_opps_{
true};
265 int num_of_cells_[3];
Stores some information about the model.
void * getUserData() const
const std::string & getObjectName() const
const ORROctree & getOctree() const
const float * getOctreeCenterOfMass() const
const float * getBoundsOfOctreePoints() const
const std::string obj_name_
Model(const PointCloudIn &points, const PointCloudN &normals, float voxel_size, const std::string &object_name, float frac_of_points_for_registration, void *user_data=nullptr)
const PointCloudIn & getPointsForRegistration() const
PointCloudIn points_for_registration_
float max_coplanarity_angle_
const std::map< std::string, Model * > & getModels() const
void clear()
Removes all models from the library and destroys the hash table.
void removeAllModels()
Removes all models from the library and clears the hash table.
bool addModel(const PointCloudIn &points, const PointCloudN &normals, const std::string &object_name, float frac_of_points_for_registration, void *user_data=nullptr)
Adds a model to the hash table.
ModelLibrary(float pair_width, float voxel_size, float max_coplanarity_angle=3.0f *AUX_DEG_TO_RADIANS)
This class is used by 'ObjRecRANSAC' to maintain the object models to be recognized.
void setMaxCoplanarityAngleDegrees(float max_coplanarity_angle_degrees)
This is a threshold.
void ignoreCoplanarPointPairsOff()
Call this method in order to add all point pairs (co-planar as well) to the hash table.
bool addToHashTable(Model *model, const ORROctree::Node::Data *data1, const ORROctree::Node::Data *data2)
Returns true if the oriented point pair was added to the hash table and false otherwise.
std::map< const Model *, node_data_pair_list > HashTableCell
const Model * getModel(const std::string &name) const
const HashTable & getHashTable() const
Returns the hash table built by this instance.
std::list< std::pair< const ORROctree::Node::Data *, const ORROctree::Node::Data * > > node_data_pair_list
void ignoreCoplanarPointPairsOn()
Call this method in order NOT to add co-planar point pairs to the hash table.
std::map< std::string, Model * > models_
That's a very specialized and simple octree class.
Defines all the PCL implemented PointT point type structures.
void expandBoundingBoxToContainPoint(T bbox[6], const T p[3])
Expands the bounding box 'bbox' such that it contains the point 'p'.
void mult3(T *v, T scalar)
v = scalar*v.
void add3(T a[3], const T b[3])
a += b
void copy3(const T src[3], T dst[3])
dst = src
CloudGenerator class generates a point cloud using some random number generator.