Point Cloud Library (PCL)  1.14.1-dev
face_common.h
1 #pragma once
2 
3 #include <pcl/features/integral_image2D.h>
4 #include <pcl/memory.h>
5 #include <pcl/pcl_macros.h>
6 
7 #include <Eigen/Core>
8 
9 namespace pcl
10 {
11  namespace face_detection
12  {
14  {
15  public:
16  std::vector<pcl::IntegralImage2D<float, 1>::Ptr> iimages_; //also pointer to the respective integral image
17  int row_, col_;
18  int wsize_;
19  int label_;
20 
21  //save pose head information
22  Eigen::Vector3f trans_;
23  Eigen::Vector3f rot_;
25  };
26 
28  {
29  public:
30  int row1_, col1_;
31  int row2_, col2_;
32 
35 
36  float threshold_;
37  int used_ii_;
38 
40  {
41  used_ii_ = 0;
42  }
43 
44  void serialize(std::ostream & stream) const
45  {
46  stream.write (reinterpret_cast<const char*> (&row1_), sizeof(row1_));
47  stream.write (reinterpret_cast<const char*> (&col1_), sizeof(col1_));
48  stream.write (reinterpret_cast<const char*> (&row2_), sizeof(row2_));
49  stream.write (reinterpret_cast<const char*> (&col2_), sizeof(col2_));
50  stream.write (reinterpret_cast<const char*> (&wsizex1_), sizeof(wsizex1_));
51  stream.write (reinterpret_cast<const char*> (&wsizex2_), sizeof(wsizex2_));
52  stream.write (reinterpret_cast<const char*> (&wsizey1_), sizeof(wsizey1_));
53  stream.write (reinterpret_cast<const char*> (&wsizey2_), sizeof(wsizey2_));
54  stream.write (reinterpret_cast<const char*> (&threshold_), sizeof(threshold_));
55  stream.write (reinterpret_cast<const char*> (&used_ii_), sizeof(used_ii_));
56  }
57 
58  inline void deserialize(std::istream & stream)
59  {
60  stream.read (reinterpret_cast<char*> (&row1_), sizeof(row1_));
61  stream.read (reinterpret_cast<char*> (&col1_), sizeof(col1_));
62  stream.read (reinterpret_cast<char*> (&row2_), sizeof(row2_));
63  stream.read (reinterpret_cast<char*> (&col2_), sizeof(col2_));
64  stream.read (reinterpret_cast<char*> (&wsizex1_), sizeof(wsizex1_));
65  stream.read (reinterpret_cast<char*> (&wsizex2_), sizeof(wsizex2_));
66  stream.read (reinterpret_cast<char*> (&wsizey1_), sizeof(wsizey1_));
67  stream.read (reinterpret_cast<char*> (&wsizey2_), sizeof(wsizey2_));
68  stream.read (reinterpret_cast<char*> (&threshold_), sizeof(threshold_));
69  stream.read (reinterpret_cast<char*> (&used_ii_), sizeof(used_ii_));
70  }
71  };
72 
73  template<class FeatureType>
74  class RFTreeNode
75  {
76  public:
77  float threshold;
79  std::vector<RFTreeNode> sub_nodes;
80  float value;
81  float variance;
82 
83  Eigen::Vector3d trans_mean_;
84  Eigen::Vector3d rot_mean_;
85 
86  float purity_;
87  Eigen::Matrix3d covariance_trans_;
88  Eigen::Matrix3d covariance_rot_;
89 
91 
92  void serialize(::std::ostream & stream) const
93  {
94 
95  const int num_of_sub_nodes = static_cast<int> (sub_nodes.size ());
96  stream.write (reinterpret_cast<const char*> (&num_of_sub_nodes), sizeof(num_of_sub_nodes));
97 
98  if (!sub_nodes.empty ())
99  {
100  feature.serialize (stream);
101  stream.write (reinterpret_cast<const char*> (&threshold), sizeof(threshold));
102  }
103 
104  stream.write (reinterpret_cast<const char*> (&value), sizeof(value));
105  stream.write (reinterpret_cast<const char*> (&variance), sizeof(variance));
106 
107  for (std::size_t i = 0; i < 3; i++)
108  stream.write (reinterpret_cast<const char*> (&trans_mean_[i]), sizeof(trans_mean_[i]));
109 
110  for (std::size_t i = 0; i < 3; i++)
111  stream.write (reinterpret_cast<const char*> (&rot_mean_[i]), sizeof(rot_mean_[i]));
112 
113  for (std::size_t i = 0; i < 3; i++)
114  for (std::size_t j = 0; j < 3; j++)
115  stream.write (reinterpret_cast<const char*> (&covariance_trans_ (i, j)), sizeof(covariance_trans_ (i, j)));
116 
117  for (std::size_t i = 0; i < 3; i++)
118  for (std::size_t j = 0; j < 3; j++)
119  stream.write (reinterpret_cast<const char*> (&covariance_rot_ (i, j)), sizeof(covariance_rot_ (i, j)));
120 
121  for (int sub_node_index = 0; sub_node_index < num_of_sub_nodes; ++sub_node_index)
122  {
123  sub_nodes[sub_node_index].serialize (stream);
124  }
125  }
126 
127  inline void deserialize(::std::istream & stream)
128  {
129  int num_of_sub_nodes;
130  stream.read (reinterpret_cast<char*> (&num_of_sub_nodes), sizeof(num_of_sub_nodes));
131 
132  if (num_of_sub_nodes > 0)
133  {
134  feature.deserialize (stream);
135  stream.read (reinterpret_cast<char*> (&threshold), sizeof(threshold));
136  }
137 
138  stream.read (reinterpret_cast<char*> (&value), sizeof(value));
139  stream.read (reinterpret_cast<char*> (&variance), sizeof(variance));
140 
141  for (std::size_t i = 0; i < 3; i++)
142  stream.read (reinterpret_cast<char*> (&trans_mean_[i]), sizeof(trans_mean_[i]));
143 
144  for (std::size_t i = 0; i < 3; i++)
145  stream.read (reinterpret_cast<char*> (&rot_mean_[i]), sizeof(rot_mean_[i]));
146 
147  for (std::size_t i = 0; i < 3; i++)
148  for (std::size_t j = 0; j < 3; j++)
149  stream.read (reinterpret_cast<char*> (&covariance_trans_ (i, j)), sizeof(covariance_trans_ (i, j)));
150 
151  for (std::size_t i = 0; i < 3; i++)
152  for (std::size_t j = 0; j < 3; j++)
153  stream.read (reinterpret_cast<char*> (&covariance_rot_ (i, j)), sizeof(covariance_rot_ (i, j)));
154 
155  sub_nodes.resize (num_of_sub_nodes);
156 
157  if (num_of_sub_nodes > 0)
158  {
159  for (int sub_node_index = 0; sub_node_index < num_of_sub_nodes; ++sub_node_index)
160  {
161  sub_nodes[sub_node_index].deserialize (stream);
162  }
163  }
164  }
165  };
166  }
167 }
void deserialize(std::istream &stream)
Definition: face_common.h:58
void serialize(std::ostream &stream) const
Definition: face_common.h:44
void deserialize(::std::istream &stream)
Definition: face_common.h:127
Eigen::Matrix3d covariance_rot_
Definition: face_common.h:88
std::vector< RFTreeNode > sub_nodes
Definition: face_common.h:79
PCL_MAKE_ALIGNED_OPERATOR_NEW void serialize(::std::ostream &stream) const
Definition: face_common.h:92
Eigen::Matrix3d covariance_trans_
Definition: face_common.h:87
std::vector< pcl::IntegralImage2D< float, 1 >::Ptr > iimages_
Definition: face_common.h:16
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.