38 #ifndef PCL_ML_FERNS_FERN
39 #define PCL_ML_FERNS_FERN
41 #include <pcl/common/common.h>
50 template <
class FeatureType,
class NodeType>
57 : num_of_decisions_ (0)
73 num_of_decisions_ = num_of_decisions;
74 features_.resize (num_of_decisions_);
75 thresholds_.resize (num_of_decisions_, std::numeric_limits<float>::quiet_NaN ());
76 nodes_.resize (0x1 << num_of_decisions_);
83 return 0x1U << num_of_decisions_;
90 return num_of_decisions_;
101 stream.write (reinterpret_cast<const char*> (&num_of_decisions_),
sizeof (num_of_decisions_));
103 for (
size_t feature_index = 0; feature_index < features_.size (); ++feature_index)
105 features_[feature_index].serialize (stream);
108 for (
size_t threshold_index = 0; threshold_index < thresholds_.size (); ++threshold_index)
110 stream.write (reinterpret_cast<const char*> (&(thresholds_[threshold_index])),
sizeof (thresholds_[threshold_index]));
113 for (
size_t node_index = 0; node_index < nodes_.size (); ++node_index)
115 nodes_[node_index].serialize (stream);
124 stream.read (reinterpret_cast<char*> (&num_of_decisions_),
sizeof (num_of_decisions_));
126 features_.resize (num_of_decisions_);
127 thresholds_.resize (num_of_decisions_);
128 nodes_.resize (0x1 << num_of_decisions_);
130 for (
size_t feature_index = 0; feature_index < features_.size (); ++feature_index)
132 features_[feature_index].deserialize (stream);
135 for (
size_t threshold_index = 0; threshold_index < thresholds_.size (); ++threshold_index)
137 stream.read (reinterpret_cast<char*> (&(thresholds_[threshold_index])),
sizeof (thresholds_[threshold_index]));
140 for (
size_t node_index = 0; node_index < nodes_.size (); ++node_index)
142 nodes_[node_index].deserialize (stream);
150 operator[] (
const size_t node_index)
152 return nodes_[node_index];
158 inline const NodeType &
159 operator[] (
const size_t node_index)
const
161 return nodes_[node_index];
170 return features_[feature_index];
176 inline const FeatureType &
179 return features_[feature_index];
188 return thresholds_[threshold_index];
197 return thresholds_[threshold_index];
202 size_t num_of_decisions_;
204 std::vector<FeatureType> features_;
206 std::vector<float> thresholds_;
209 std::vector<NodeType> nodes_;
size_t getNumOfFeatures()
Returns the number of features the Fern has.
This file defines compatibility wrappers for low level I/O functions.
float & accessThreshold(const size_t threshold_index)
Access operator for thresholds.
FeatureType & accessFeature(const size_t feature_index)
Access operator for features.
void deserialize(::std::istream &stream)
Deserializes the fern.
void serialize(::std::ostream &stream) const
Serializes the fern.
size_t getNumOfNodes()
Returns the number of nodes the Fern has.
Class representing a Fern.
void initialize(const size_t num_of_decisions)
Initializes the fern.
const FeatureType & accessFeature(const size_t feature_index) const
Access operator for features.
virtual ~Fern()
Destructor.
const float & accessThreshold(const size_t threshold_index) const
Access operator for thresholds.