Point Cloud Library (PCL)  1.9.1
tree.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, 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  * $Id: $
37  * @authors: Cedric Cagniart, Koen Buys
38  */
39 
40 #ifndef PCL_GPU_PEOPLE_TREE_H_
41 #define PCL_GPU_PEOPLE_TREE_H_
42 
43 #include "label_common.h"
44 #include <boost/cstdint.hpp>
45 #include <iostream>
46 #include <vector>
47 
48 namespace pcl
49 {
50  namespace gpu
51  {
52  namespace people
53  {
54  namespace trees
55  {
56  // this has nothing to do here...
57  static const double focal = 1000.;
58 
59  // ###############################################
60  // compile type values
61  enum { NUM_ATTRIBS = 2000 };
62  enum { NUM_LABELS = 32 };
63 
64  // ###############################################
65  // base data types used in the structures
66 
67  using boost::uint8_t;
68  using boost::int16_t;
69  using boost::uint16_t;
70  using boost::int32_t;
71  using boost::uint32_t;
72 
73  typedef int16_t Attrib;
74  typedef uint8_t Label;
75  typedef uint32_t Label32;
76  typedef uint16_t Depth;
77 
79  {
80  inline AttribLocation () {du1=dv1=du2=dv2=0;}
81  inline AttribLocation (int u1, int v1, int u2, int v2): du1 (static_cast<int16_t>(u1)),
82  dv1 (static_cast<int16_t>(v1)),
83  du2 (static_cast<int16_t>(u2)),
84  dv2 (static_cast<int16_t>(v2))
85  {}
86 
87  int16_t du1,dv1,du2,dv2;
88  };
89 
90  ////////////////////////////////////////////////
91  // Tree basic Structure
92  struct Node
93  {
94  Node () {}
95  Node (const AttribLocation& l, const Attrib& t) : loc(l), thresh(t) {}
97  Attrib thresh;
98  };
99 
100  struct Histogram
101  {
102  float label_prob[NUM_PARTS];
103  };
104 
105  ////////////////////////////////////////////////
106  // tree_io - Reading and writing AttributeLocations
107  inline std::ostream& operator << (std::ostream& os, const AttribLocation& aloc ) { return os<<aloc.du1<<" "<<aloc.dv1<<" "<<aloc.du2<<" "<<aloc.dv2<<"\n"; }
108  inline std::istream& operator >> (std::istream& is, AttribLocation& aloc ) { return is >> aloc.du1 >> aloc.dv1 >> aloc.du2 >> aloc.dv2; }
109  inline std::istream& operator >> (std::istream& is, Node& n) { return is >> n.loc >> n.thresh; }
110 
111  void writeAttribLocs( const std::string& filename, const std::vector<AttribLocation>& alocs );
112  void readAttribLocs( const std::string& filename, std::vector<AttribLocation>& alocs );
113  void readThreshs( const std::string& filename, std::vector<Attrib>& threshs );
114  void writeThreshs( const std::string& filename, const std::vector<Attrib>& threshs );
115 
116  ////////////////////////////////////////////////
117  // tree_run
118 
119  /** The stream points to ascii data that goes:
120  * ##################
121  * TreeHeight
122  * du1 dv1 du2 dv2 thresh
123  * du1 dv1 du2 dv2 thresh
124  * ............
125  * label
126  * label
127  * ##################
128  *
129  * there are 2^threeheight -1 nodes ( [du1 dv1 du2 dv2 thresh] lines )
130  * there are 2^threeheight leaves ( [label] lines )
131  */
132  int loadTree( std::istream& is, std::vector<Node>& tree, std::vector<Label>& leaves );
133  int loadTree( const std::string& filename, std::vector<Node>& tree, std::vector<Label>& leaves );
134  void runThroughTree( int maxDepth, const std::vector<Node>& tree, const std::vector<Label>& leaves, int W, int H, const uint16_t* dmap, Label* lmap );
135 
136  } // end namespace Trees
137  } // end namespace people
138  } // end namespace gpu
139 } // end namespace pcl
140 #endif // PCL_GPU_PEOPLE_TREES_TREE_H_
std::ostream & operator<<(std::ostream &os, const AttribLocation &aloc)
Definition: tree.h:107
std::istream & operator>>(std::istream &is, AttribLocation &aloc)
Definition: tree.h:108
void readThreshs(const std::string &filename, std::vector< Attrib > &threshs)
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void readAttribLocs(const std::string &filename, std::vector< AttribLocation > &alocs)
int loadTree(std::istream &is, std::vector< Node > &tree, std::vector< Label > &leaves)
The stream points to ascii data that goes: TreeHeight du1 dv1 du2 dv2 thresh du1 dv1 du2 dv2 thresh ...
void writeThreshs(const std::string &filename, const std::vector< Attrib > &threshs)
AttribLocation(int u1, int v1, int u2, int v2)
Definition: tree.h:81
uint32_t Label32
Definition: tree.h:75
static const double focal
Definition: tree.h:57
Node(const AttribLocation &l, const Attrib &t)
Definition: tree.h:95
void runThroughTree(int maxDepth, const std::vector< Node > &tree, const std::vector< Label > &leaves, int W, int H, const uint16_t *dmap, Label *lmap)
void writeAttribLocs(const std::string &filename, const std::vector< AttribLocation > &alocs)
uint16_t Depth
Definition: tree.h:76
AttribLocation loc
Definition: tree.h:96