Point Cloud Library (PCL)  1.14.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 #include <pcl/ml/dt/decision_tree.h>
42 
43 #include <istream>
44 #include <ostream>
45 
46 namespace pcl {
47 
48 /** Class representing a decision forest. */
49 template <class NodeType>
50 class PCL_EXPORTS DecisionForest : public std::vector<pcl::DecisionTree<NodeType>> {
51 
52 public:
53  /** Constructor. */
54  DecisionForest() = default;
55 
56  /** Destructor. */
57  virtual ~DecisionForest() = default;
58 
59  /** Serializes the decision tree.
60  *
61  * \param[out] stream The destination for the serialization
62  */
63  void
64  serialize(::std::ostream& stream) const
65  {
66  const int num_of_trees = static_cast<int>(this->size());
67  stream.write(reinterpret_cast<const char*>(&num_of_trees), sizeof(num_of_trees));
68 
69  for (std::size_t tree_index = 0; tree_index < this->size(); ++tree_index) {
70  (*this)[tree_index].serialize(stream);
71  }
72 
73  // const int num_of_trees = static_cast<int> (trees_.size ());
74  // stream.write (reinterpret_cast<const char*> (&num_of_trees), sizeof
75  // (num_of_trees));
76 
77  // for (std::size_t tree_index = 0; tree_index < trees_.size (); ++tree_index)
78  //{
79  // tree_[tree_index].serialize (stream);
80  //}
81  }
82 
83  /** Deserializes the decision tree.
84  *
85  * \param[in] stream The source for the deserialization
86  */
87  void
88  deserialize(::std::istream& stream)
89  {
90  int num_of_trees;
91  stream.read(reinterpret_cast<char*>(&num_of_trees), sizeof(num_of_trees));
92  this->resize(num_of_trees);
93 
94  for (std::size_t tree_index = 0; tree_index < this->size(); ++tree_index) {
95  (*this)[tree_index].deserialize(stream);
96  }
97 
98  // int num_of_trees;
99  // stream.read (reinterpret_cast<char*> (&num_of_trees), sizeof (num_of_trees));
100  // trees_.resize (num_of_trees);
101 
102  // for (std::size_t tree_index = 0; tree_index < trees_.size (); ++tree_index)
103  //{
104  // tree_[tree_index].deserialize (stream);
105  //}
106  }
107 
108 private:
109  /** The decision trees contained in the forest. */
110  // std::vector<DecisionTree<NodeType> > trees_;
111 };
112 
113 } // namespace pcl
Class representing a decision forest.
DecisionForest()=default
Constructor.
void deserialize(::std::istream &stream)
Deserializes the decision tree.
virtual ~DecisionForest()=default
Destructor.
void serialize(::std::ostream &stream) const
Serializes the decision tree.
Define standard C methods and C++ classes that are common to all methods.
#define PCL_EXPORTS
Definition: pcl_macros.h:323