Point Cloud Library (PCL)  1.14.0-dev
branch_estimator.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, 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 #pragma once
39 
40 #include <pcl/common/common.h>
41 #include <pcl/common/utils.h> // pcl::utils::ignore
42 #include <pcl/ml/stats_estimator.h>
43 
44 namespace pcl {
45 
46 /** Interface for branch estimators. */
48 public:
49  /** Destructor. */
50  virtual ~BranchEstimator() = default;
51 
52  /** Returns the number of branches the corresponding tree has. */
53  virtual std::size_t
54  getNumOfBranches() const = 0;
55 
56  /** Computes the branch index for the specified result.
57  *
58  * \param[in] result the result the branch index will be computed for
59  * \param[in] flag the flag corresponding to the specified result
60  * \param[in] threshold the threshold used to compute the branch index
61  * \param[out] branch_index the destination for the computed branch index
62  */
63  virtual void
64  computeBranchIndex(const float result,
65  const unsigned char flag,
66  const float threshold,
67  unsigned char& branch_index) const = 0;
68 };
69 
70 /** Branch estimator for binary trees where the branch is computed only from the
71  * threshold. */
73 public:
74  /** Constructor. */
76  /** Destructor. */
77  inline ~BinaryTreeThresholdBasedBranchEstimator() override = default;
78 
79  /** Returns the number of branches the corresponding tree has. */
80  inline std::size_t
81  getNumOfBranches() const override
82  {
83  return 2;
84  }
85 
86  /** Computes the branch index for the specified result.
87  *
88  * \param[in] result the result the branch index will be computed for
89  * \param[in] flag the flag corresponding to the specified result
90  * \param[in] threshold the threshold used to compute the branch index
91  * \param[out] branch_index the destination for the computed branch index
92  */
93  inline void
94  computeBranchIndex(const float result,
95  const unsigned char flag,
96  const float threshold,
97  unsigned char& branch_index) const override
98  {
99  pcl::utils::ignore(flag);
100  branch_index = (result > threshold) ? 1 : 0;
101  }
102 };
103 
104 /** Branch estimator for ternary trees where one branch is used for missing data
105  * (indicated by flag != 0). */
107 public:
108  /** Constructor. */
110  /** Destructor. */
111  inline ~TernaryTreeMissingDataBranchEstimator() override = default;
112 
113  /** \brief Returns the number of branches the corresponding tree has. */
114  inline std::size_t
115  getNumOfBranches() const override
116  {
117  return 3;
118  }
119 
120  /** Computes the branch index for the specified result.
121  *
122  * \param[in] result the result the branch index will be computed for
123  * \param[in] flag the flag corresponding to the specified result
124  * \param[in] threshold the threshold used to compute the branch index
125  * \param[out] branch_index the destination for the computed branch index
126  */
127  inline void
128  computeBranchIndex(const float result,
129  const unsigned char flag,
130  const float threshold,
131  unsigned char& branch_index) const override
132  {
133  if (flag == 0)
134  branch_index = (result > threshold) ? 1 : 0;
135  else
136  branch_index = 2;
137  }
138 };
139 
140 } // namespace pcl
Branch estimator for binary trees where the branch is computed only from the threshold.
void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const override
Computes the branch index for the specified result.
std::size_t getNumOfBranches() const override
Returns the number of branches the corresponding tree has.
BinaryTreeThresholdBasedBranchEstimator()=default
Constructor.
~BinaryTreeThresholdBasedBranchEstimator() override=default
Destructor.
Interface for branch estimators.
virtual std::size_t getNumOfBranches() const =0
Returns the number of branches the corresponding tree has.
virtual void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const =0
Computes the branch index for the specified result.
virtual ~BranchEstimator()=default
Destructor.
Branch estimator for ternary trees where one branch is used for missing data (indicated by flag !...
std::size_t getNumOfBranches() const override
Returns the number of branches the corresponding tree has.
TernaryTreeMissingDataBranchEstimator()=default
Constructor.
void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const override
Computes the branch index for the specified result.
~TernaryTreeMissingDataBranchEstimator() override=default
Destructor.
Define standard C methods and C++ classes that are common to all methods.
void ignore(const T &...)
Utility function to eliminate unused variable warnings.
Definition: utils.h:62
#define PCL_EXPORTS
Definition: pcl_macros.h:323