Point Cloud Library (PCL)  1.9.1-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/ml/stats_estimator.h>
42 
43 #include <istream>
44 #include <ostream>
45 
46 namespace pcl {
47 
48 /** Interface for branch estimators. */
50 public:
51  /** Destructor. */
52  virtual ~BranchEstimator() {}
53 
54  /** Returns the number of branches the corresponding tree has. */
55  virtual std::size_t
56  getNumOfBranches() const = 0;
57 
58  /** Computes the branch index for the specified result.
59  *
60  * \param[in] result the result the branch index will be computed for
61  * \param[in] flag the flag corresponding to the specified result
62  * \param[in] threshold the threshold used to compute the branch index
63  * \param[out] branch_index the destination for the computed branch index
64  */
65  virtual void
66  computeBranchIndex(const float result,
67  const unsigned char flag,
68  const float threshold,
69  unsigned char& branch_index) const = 0;
70 };
71 
72 /** Branch estimator for binary trees where the branch is computed only from the
73  * threshold. */
75 public:
76  /** Constructor. */
78  /** Destructor. */
80 
81  /** Returns the number of branches the corresponding tree has. */
82  inline std::size_t
83  getNumOfBranches() const override
84  {
85  return 2;
86  }
87 
88  /** Computes the branch index for the specified result.
89  *
90  * \param[in] result the result the branch index will be computed for
91  * \param[in] flag the flag corresponding to the specified result
92  * \param[in] threshold the threshold used to compute the branch index
93  * \param[out] branch_index the destination for the computed branch index
94  */
95  inline void
96  computeBranchIndex(const float result,
97  const unsigned char flag,
98  const float threshold,
99  unsigned char& branch_index) const override
100  {
101  (void)flag;
102  branch_index = (result > threshold) ? 1 : 0;
103  }
104 };
105 
106 /** Branch estimator for ternary trees where one branch is used for missing data
107  * (indicated by flag != 0). */
109 public:
110  /** Constructor. */
112  /** Destructor. */
114 
115  /** \brief Returns the number of branches the corresponding tree has. */
116  inline std::size_t
117  getNumOfBranches() const override
118  {
119  return 3;
120  }
121 
122  /** Computes the branch index for the specified result.
123  *
124  * \param[in] result the result the branch index will be computed for
125  * \param[in] flag the flag corresponding to the specified result
126  * \param[in] threshold the threshold used to compute the branch index
127  * \param[out] branch_index the destination for the computed branch index
128  */
129  inline void
130  computeBranchIndex(const float result,
131  const unsigned char flag,
132  const float threshold,
133  unsigned char& branch_index) const override
134  {
135  if (flag == 0)
136  branch_index = (result > threshold) ? 1 : 0;
137  else
138  branch_index = 2;
139  }
140 };
141 
142 } // namespace pcl
std::size_t getNumOfBranches() const override
Returns the number of branches the corresponding tree has.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
std::size_t getNumOfBranches() const override
Returns the number of branches the corresponding tree has.
Branch estimator for binary trees where the branch is computed only from the threshold.
Define standard C methods and C++ classes that are common to all methods.
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.
Branch estimator for ternary trees where one branch is used for missing data (indicated by flag != 0)...
virtual ~BranchEstimator()
Destructor.
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.
#define PCL_EXPORTS
Definition: pcl_macros.h:241
Interface for branch estimators.