Point Cloud Library (PCL)  1.14.0-dev
hypothesis.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  *
37  */
38 
39 /*
40  * hypothesis.h
41  *
42  * Created on: Mar 12, 2013
43  * Author: papazov
44  */
45 
46 #pragma once
47 
48 #include <pcl/recognition/ransac_based/model_library.h>
49 #include <pcl/recognition/ransac_based/auxiliary.h>
50 
51 namespace pcl
52 {
53  namespace recognition
54  {
56  {
57  public:
59  : obj_model_ (obj_model)
60  {}
61 
62  HypothesisBase (const ModelLibrary::Model* obj_model, const float* rigid_transform)
63  : obj_model_ (obj_model)
64  {
65  std::copy(rigid_transform, rigid_transform + 12, rigid_transform_);
66  }
67 
68  virtual ~HypothesisBase () = default;
69 
70  void
72  {
73  obj_model_ = model;
74  }
75 
76  public:
77  float rigid_transform_[12]{};
79  };
80 
81  class Hypothesis: public HypothesisBase
82  {
83  public:
84  Hypothesis (const ModelLibrary::Model* obj_model = nullptr)
85  : HypothesisBase (obj_model)
86  {
87  }
88 
89  Hypothesis (const Hypothesis& src)
93  {
94  }
95 
96  ~Hypothesis () override = default;
97 
98  const Hypothesis&
99  operator =(const Hypothesis& src)
100  {
101  std::copy(src.rigid_transform_, src.rigid_transform_ + 12, this->rigid_transform_);
102  this->obj_model_ = src.obj_model_;
105 
106  return *this;
107  }
108 
109  void
110  setLinearId (int id)
111  {
112  linear_id_ = id;
113  }
114 
115  int
116  getLinearId () const
117  {
118  return (linear_id_);
119  }
120 
121  void
122  computeBounds (float bounds[6]) const
123  {
124  const float *b = obj_model_->getBoundsOfOctreePoints ();
125  float p[3];
126 
127  // Initialize 'bounds'
128  aux::transform (rigid_transform_, b[0], b[2], b[4], p);
129  bounds[0] = bounds[1] = p[0];
130  bounds[2] = bounds[3] = p[1];
131  bounds[4] = bounds[5] = p[2];
132 
133  // Expand 'bounds' to contain the other 7 points of the octree bounding box
134  aux::transform (rigid_transform_, b[0], b[2], b[5], p); aux::expandBoundingBoxToContainPoint (bounds, p);
135  aux::transform (rigid_transform_, b[0], b[3], b[4], p); aux::expandBoundingBoxToContainPoint (bounds, p);
136  aux::transform (rigid_transform_, b[0], b[3], b[5], p); aux::expandBoundingBoxToContainPoint (bounds, p);
137  aux::transform (rigid_transform_, b[1], b[2], b[4], p); aux::expandBoundingBoxToContainPoint (bounds, p);
138  aux::transform (rigid_transform_, b[1], b[2], b[5], p); aux::expandBoundingBoxToContainPoint (bounds, p);
139  aux::transform (rigid_transform_, b[1], b[3], b[4], p); aux::expandBoundingBoxToContainPoint (bounds, p);
140  aux::transform (rigid_transform_, b[1], b[3], b[5], p); aux::expandBoundingBoxToContainPoint (bounds, p);
141  }
142 
143  void
144  computeCenterOfMass (float center_of_mass[3]) const
145  {
147  }
148 
149  public:
150  float match_confidence_{-1.0f};
151  std::set<int> explained_pixels_;
152  int linear_id_{-1};
153  };
154  } // namespace recognition
155 } // namespace pcl
HypothesisBase(const ModelLibrary::Model *obj_model)
Definition: hypothesis.h:58
void setModel(const ModelLibrary::Model *model)
Definition: hypothesis.h:71
virtual ~HypothesisBase()=default
HypothesisBase(const ModelLibrary::Model *obj_model, const float *rigid_transform)
Definition: hypothesis.h:62
const ModelLibrary::Model * obj_model_
Definition: hypothesis.h:78
~Hypothesis() override=default
void computeCenterOfMass(float center_of_mass[3]) const
Definition: hypothesis.h:144
std::set< int > explained_pixels_
Definition: hypothesis.h:151
Hypothesis(const Hypothesis &src)
Definition: hypothesis.h:89
Hypothesis(const ModelLibrary::Model *obj_model=nullptr)
Definition: hypothesis.h:84
const Hypothesis & operator=(const Hypothesis &src)
Definition: hypothesis.h:99
void computeBounds(float bounds[6]) const
Definition: hypothesis.h:122
Stores some information about the model.
Definition: model_library.h:65
const float * getOctreeCenterOfMass() const
const float * getBoundsOfOctreePoints() const
void expandBoundingBoxToContainPoint(T bbox[6], const T p[3])
Expands the bounding box 'bbox' such that it contains the point 'p'.
Definition: auxiliary.h:95
void transform(const T t[12], const T p[3], T out[3])
The first 9 elements of 't' are treated as a 3x3 matrix (row major order) and the last 3 as a transla...
Definition: auxiliary.h:304