Point Cloud Library (PCL)  1.9.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
decision_forest.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 #ifndef PCL_ML_DT_DECISION_FOREST_H_
39 #define PCL_ML_DT_DECISION_FOREST_H_
40 
41 #include <pcl/common/common.h>
42 
43 #include <pcl/ml/dt/decision_tree.h>
44 
45 #include <istream>
46 #include <ostream>
47 
48 namespace pcl
49 {
50 
51  /** \brief Class representing a decision forest. */
52  template <class NodeType>
53  class PCL_EXPORTS DecisionForest
54  : public std::vector<pcl::DecisionTree<NodeType> >
55  {
56 
57  public:
58 
59  /** \brief Constructor. */
61  /** \brief Destructor. */
62  virtual
64 
65  /* \brief Adds the specified tree to the forest.
66  * \param[in] tree The tree to be added to the forest. */
67  //
68  //void
69  //addTree (DecisionTree<NodeType> & tree)
70  //{
71  // trees_.push_back (tree);
72  //}
73 
74  ///brief Returns the number of trees in the forest.
75  //inline size_t
76 
77  /** \brief Serializes the decision tree.
78  * \param[out] stream The destination for the serialization.
79  */
80  void
81  serialize (::std::ostream &stream) const
82  {
83  const int num_of_trees = static_cast<int> (this->size ());
84  stream.write (reinterpret_cast<const char*> (&num_of_trees), sizeof (num_of_trees));
85 
86  for (size_t tree_index = 0; tree_index < this->size (); ++tree_index)
87  {
88  (*this) [tree_index].serialize (stream);
89  }
90 
91  //const int num_of_trees = static_cast<int> (trees_.size ());
92  //stream.write (reinterpret_cast<const char*> (&num_of_trees), sizeof (num_of_trees));
93 
94  //for (size_t tree_index = 0; tree_index < trees_.size (); ++tree_index)
95  //{
96  // tree_[tree_index].serialize (stream);
97  //}
98  }
99 
100  /** \brief Deserializes the decision tree.
101  * \param[in] stream The source for the deserialization.
102  */
103  void
104  deserialize (::std::istream & stream)
105  {
106  int num_of_trees;
107  stream.read (reinterpret_cast<char*> (&num_of_trees), sizeof (num_of_trees));
108  this->resize (num_of_trees);
109 
110  for (size_t tree_index = 0; tree_index < this->size (); ++tree_index)
111  {
112  (*this) [tree_index].deserialize (stream);
113  }
114 
115  //int num_of_trees;
116  //stream.read (reinterpret_cast<char*> (&num_of_trees), sizeof (num_of_trees));
117  //trees_.resize (num_of_trees);
118 
119  //for (size_t tree_index = 0; tree_index < trees_.size (); ++tree_index)
120  //{
121  // tree_[tree_index].deserialize (stream);
122  //}
123  }
124 
125  private:
126 
127  /** \brief The decision trees contained in the forest. */
128  //std::vector<DecisionTree<NodeType> > trees_;
129 
130  };
131 
132 
133 }
134 
135 #endif
Class representing a decision forest.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void serialize(::std::ostream &stream) const
brief Returns the number of trees in the forest.
void deserialize(::std::istream &stream)
Deserializes the decision tree.
DecisionForest()
Constructor.
virtual ~DecisionForest()
Destructor.