39 #ifndef PCL_RECOGNITION_MODEL_LIBRARY_H_ 40 #define PCL_RECOGNITION_MODEL_LIBRARY_H_ 42 #include "auxiliary.h" 43 #include <pcl/recognition/ransac_based/voxel_structure.h> 44 #include <pcl/recognition/ransac_based/orr_octree.h> 46 #include <pcl/pcl_exports.h> 47 #include <pcl/point_cloud.h> 69 Model (
const PointCloudIn& points,
const PointCloudN& normals,
float voxel_size,
const std::string& object_name,
70 float frac_of_points_for_registration,
void* user_data = NULL)
71 : obj_name_(object_name),
72 user_data_ (user_data)
74 octree_.build (points, voxel_size, &normals);
76 const std::vector<ORROctree::Node*>& full_leaves = octree_.getFullLeaves ();
77 if ( full_leaves.empty () )
81 std::vector<ORROctree::Node*>::const_iterator it = full_leaves.begin ();
82 const float *p = (*it)->getData ()->getPoint ();
84 bounds_of_octree_points_[0] = bounds_of_octree_points_[1] = p[0];
85 bounds_of_octree_points_[2] = bounds_of_octree_points_[3] = p[1];
86 bounds_of_octree_points_[4] = bounds_of_octree_points_[5] = p[2];
89 for ( ++it ; it != full_leaves.end () ; ++it )
91 aux::add3 (octree_center_of_mass_, (*it)->getData ()->getPoint ());
95 int num_octree_points =
static_cast<int> (full_leaves.size ());
97 aux::mult3 (octree_center_of_mass_, 1.0f/static_cast<float> (num_octree_points));
99 int num_points_for_registration =
static_cast<int> (
static_cast<float> (num_octree_points)*frac_of_points_for_registration);
100 points_for_registration_.resize (static_cast<size_t> (num_points_for_registration));
103 std::vector<int> ids (num_octree_points);
104 for (
int i = 0 ; i < num_octree_points ; ++i )
111 for (
int i = 0 ; i < num_points_for_registration ; ++i )
114 randgen.
setParameters (0, static_cast<int> (ids.size ()) - 1);
115 int rand_pos = randgen.
run ();
118 aux::copy3 (octree_.getFullLeaves ()[ids[rand_pos]]->getData ()->getPoint (), points_for_registration_[i]);
121 ids.erase (ids.begin() + rand_pos);
129 inline const std::string&
150 return (octree_center_of_mass_);
156 return (bounds_of_octree_points_);
159 inline const PointCloudIn&
162 return (points_for_registration_);
168 float octree_center_of_mass_[3];
169 float bounds_of_octree_points_[6];
174 typedef std::list<std::pair<const ORROctree::Node::Data*, const ORROctree::Node::Data*> >
node_data_pair_list;
181 ModelLibrary (
float pair_width,
float voxel_size,
float max_coplanarity_angle = 3.0f*AUX_DEG_TO_RADIANS);
197 max_coplanarity_angle_ = max_coplanarity_angle_degrees*AUX_DEG_TO_RADIANS;
205 ignore_coplanar_opps_ =
true;
213 ignore_coplanar_opps_ =
false;
226 addModel (
const PointCloudIn& points,
const PointCloudN& normals,
const std::string& object_name,
227 float frac_of_points_for_registration,
void* user_data = NULL);
230 inline const HashTable&
233 return (hash_table_);
239 std::map<std::string,Model*>::const_iterator it = models_.find (name);
240 if ( it != models_.end () )
246 inline const std::map<std::string,Model*>&
269 int num_of_cells_[3];
274 #endif // PCL_RECOGNITION_MODEL_LIBRARY_H_ float max_coplanarity_angle_
bool ignore_coplanar_opps_
void mult3(T *v, T scalar)
v = scalar*v.
Stores some information about the model.
void ignoreCoplanarPointPairsOn()
Call this method in order NOT to add co-planar point pairs to the hash table.
std::list< std::pair< const ORROctree::Node::Data *, const ORROctree::Node::Data * > > node_data_pair_list
void ignoreCoplanarPointPairsOff()
Call this method in order to add all point pairs (co-planar as well) to the hash table.
const std::string obj_name_
void * getUserData() const
void expandBoundingBoxToContainPoint(T bbox[6], const T p[3])
Expands the bounding box 'bbox' such that it contains the point 'p'.
PointCloudIn points_for_registration_
const float * getOctreeCenterOfMass() const
VoxelStructure< HashTableCell, float > HashTable
Defines all the PCL implemented PointT point type structures.
const float * getBoundsOfOctreePoints() const
Model(const PointCloudIn &points, const PointCloudN &normals, float voxel_size, const std::string &object_name, float frac_of_points_for_registration, void *user_data=NULL)
std::map< std::string, Model * > models_
const HashTable & getHashTable() const
Returns the hash table built by this instance.
void setMaxCoplanarityAngleDegrees(float max_coplanarity_angle_degrees)
This is a threshold.
const ORROctree & getOctree() const
const std::map< std::string, Model * > & getModels() const
void copy3(const T src[3], T dst[3])
dst = src
pcl::PointCloud< pcl::Normal > PointCloudN
std::map< const Model *, node_data_pair_list > HashTableCell
void add3(T a[3], const T b[3])
a += b
pcl::PointCloud< pcl::PointXYZ > PointCloudIn
CloudGenerator class generates a point cloud using some randoom number generator. ...
const PointCloudIn & getPointsForRegistration() const
const Model * getModel(const std::string &name) const
const std::string & getObjectName() const
That's a very specialized and simple octree class.