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