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