KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pt_complete_state.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 by Kobus Barnard (author)
4  |
5  | Personal and educational use of this code is granted, provided that this
6  | header is kept intact, and that the authorship is not misrepresented, that
7  | its use is acknowledged in publications, and relevant papers are cited.
8  |
9  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10  |
11  | Please note that the code in this file has not necessarily been adequately
12  | tested. Naturally, there is no guarantee of performance, support, or fitness
13  | for any particular task. Nonetheless, I am interested in hearing about
14  | problems that you encounter.
15  |
16  | Author: Ernesto Brau, Jinyan Guan
17  * =========================================================================== */
18 
19 /* $Id$ */
20 
21 #ifndef PT_COMPLETE_STATE_H
22 #define PT_COMPLETE_STATE_H
23 
26 #include <m_cpp/m_vector.h>
27 #include <m_cpp/m_vector_d.h>
28 #include <detector_cpp/d_bbox.h>
29 #include <vector>
30 #include <limits>
31 #include <fstream>
32 #include <ios>
33 #include <iomanip>
34 
35 namespace kjb {
36 namespace pt {
37 
43 {
45  double body_dir;
48  bool face_com;
49 
52  body_dir(std::numeric_limits<double>::max()),
53  face_dir(std::numeric_limits<double>::max(),
54  std::numeric_limits<double>::max()),
55  attn_point(0),
56  face_com(false)
57  {}
58 
60  Complete_state(const Vector3& pos) :
61  position(pos),
62  body_dir(std::numeric_limits<double>::max()),
63  face_dir(std::numeric_limits<double>::max(),
64  std::numeric_limits<double>::max()),
65  attn_point(0),
66  face_com(false)
67  {}
68 
71  (
72  const Vector3& pos,
73  double body_direction,
74  const Vector2& face_directions
75  ) :
76  position(pos),
77  body_dir(body_direction),
78  face_dir(face_directions),
79  attn_point(0),
80  face_com(false)
81  {}
82 };
83 
85 inline
86 std::ostream& operator<<(std::ostream& ost, const Complete_state& cs)
87 {
88  ost << cs.position
89  << " " << std::setw(16) << std::setprecision(8) << cs.body_dir
90  << " " << cs.face_dir;
91  return ost;
92 }
93 
95 inline
96 double body_direction(const Vector& dir)
97 {
98  if(dir.magnitude() < FLT_EPSILON)
100 
101  Vector2 dir2(dir[2], dir[0]);
102  double ang = acos(dir2.normalized()[0]);
103 
104  if(dir2[1] < 0) ang = -ang;
105 
106  return ang;
107 }
108 
110 struct Head
111 {
112  double height;
113  double width;
114  double girth;
117 
118  Head(const Complete_state& cs, double h, double w, double g) :
119  height(h * HEIGHT_FRACTION),
120  width(w * WIDTH_FRACTION),
121  girth(g * GIRTH_FRACTION),
122  center(cs.position[0], h - height/2, cs.position[2]),
123  orientation(
124  cs.face_dir[1], cs.face_dir[0] + cs.body_dir, 0.0,
125  Quaternion::XYZS)
126  {}
127 
128  static const double HEIGHT_FRACTION;
129  static const double WIDTH_FRACTION;
130  static const double GIRTH_FRACTION;
131 };
132 
134 inline
136 (
137  const Complete_state& cs,
138  double height,
139  double width,
140  double girth,
141  double angle
142 )
143 {
144  static Matrix R(2, 2);
145  R(0, 0) = cos(cs.body_dir);
146  R(0, 1) = -sin(cs.body_dir);
147  R(1, 0) = sin(cs.body_dir);
148  R(1, 1) = cos(cs.body_dir);
149 
150  Vector p(0.5*girth*cos(angle), 0.5*width*sin(angle));
151  p = R*p;
152 
153  return Vector(cs.position[0] + p[1], height, cs.position[2] + p[0]);
154 }
155 
157 std::vector<Vector> body_ellipse
158 (
159  const Complete_state& cs,
160  double h,
161  double w,
162  double g,
163  size_t n = 12
164 );
165 
167 void cylinder_points
168 (
169  const Complete_state& cs,
170  double height,
171  double width,
172  double girth,
173  std::vector<Vector>& fpts,
174  std::vector<Vector>& bpts,
175  Vector& botc,
176  Vector& topc,
177  Vector& bodc
178 );
179 
181 std::vector<Vector> head_points
182 (
183  const Complete_state& cs,
184  double height,
185  double width,
186  double girth
187 );
188 
190 std::vector<Vector> face_features
191 (
192  const Complete_state& cs,
193  double height,
194  double width,
195  double girth
196 );
197 
200 (
201  const Complete_state& cs,
202  const Vector& cam_center,
203  double height,
204  double width,
205  double girth
206 );
207 
209 inline
210 Vector head_to_world(const Vector& vh, const Head& h, bool scale = false)
211 {
212  Vector vw = vh;
213  if(scale)
214  {
215  vw[0] *= h.width/2;
216  vw[1] *= h.height/2;
217  vw[2] *= h.girth/2;
218  }
219 
220  vw = h.center + h.orientation.rotate(vw);
221 
222  return vw;
223 }
224 
225 }} //namespace kjb::pt
226 
227 #endif /*PT_COMPLETE_STATE_H */
228 
Vector rotate(const Vector &v) const
Definition: g_quaternion.cpp:565
Complete_state()
Construct an empty (and invalid) complete state.
Definition: pt_complete_state.h:51
Int_matrix::Value_type max(const Int_matrix &mat)
Return the maximum value in this matrix.
Definition: l_int_matrix.h:1397
Vector head_to_world(const Vector &vh, const Head &h, bool scale=false)
Converts a point on the head to world coordinates.
Definition: pt_complete_state.h:210
double body_direction(const Vector &dir)
Gets the body direction from a direction vector.
Definition: pt_complete_state.h:96
Quaternion orientation
Definition: pt_complete_state.h:116
std::vector< Vector > head_points(const Complete_state &cs, double height, double width, double girth)
Sample points on head surface.
Definition: pt_complete_state.cpp:117
Vector_d< D > normalized() const
Non-mutating (functionally pure) version of normalize()
Definition: m_vector_d.impl.h:384
height
Definition: APPgetLargeConnectedEdges.m:33
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Simple struct representing a head.
Definition: pt_complete_state.h:110
Head(const Complete_state &cs, double h, double w, double g)
Definition: pt_complete_state.h:118
Vector center
Definition: pt_complete_state.h:115
Vector3 position
Definition: pt_complete_state.h:44
St_perspective_camera for modeling a perspective camera using the classic Forsyth and Ponce parametri...
Vector2 face_dir
Definition: pt_complete_state.h:46
std::vector< Vector > face_features(const Complete_state &cs, double height, double width, double girth)
Location of face features.
Definition: pt_complete_state.cpp:162
Definition: g_quaternion.h:40
static const double HEIGHT_FRACTION
Definition: pt_complete_state.h:128
static const double GIRTH_FRACTION
Definition: pt_complete_state.h:130
std::vector< Vector > body_ellipse(const Complete_state &cs, double h, double w, double g, size_t n=12)
Computes points on ellipse given by position and dimensions.
Definition: pt_complete_state.cpp:44
static const double WIDTH_FRACTION
Definition: pt_complete_state.h:129
Complete_state(const Vector3 &pos)
Construct a (invalid) complete state with the given position.
Definition: pt_complete_state.h:60
double girth
Definition: pt_complete_state.h:114
Value_type magnitude() const
Return this vector's magnitude.
Definition: m_vector.h:1490
bool face_com
Definition: pt_complete_state.h:48
double body_dir
Definition: pt_complete_state.h:45
Vector visible_head_point(const Complete_state &cs, const Vector &cam_center, double height, double width, double girth)
Find a point on face which is visible from the camera.
Definition: pt_complete_state.cpp:211
double width
Definition: pt_complete_state.h:113
std::ostream & operator<<(std::ostream &ost, const Complete_state &cs)
outputs the Complete_state.
Definition: pt_complete_state.h:86
double height
Definition: pt_complete_state.h:112
Vector ellipse_point(const Complete_state &cs, double height, double width, double girth, double angle)
Compute point on ellipse given body_dir and angle.
Definition: pt_complete_state.h:136
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
const Vector * attn_point
Definition: pt_complete_state.h:47
void scale(kjb::Axis_aligned_rectangle_2d &box, const kjb::Vector &s)
Definition: gr_2D_bounding_box.cpp:108
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
void cylinder_points(const Complete_state &cs, double height, double width, double girth, std::vector< Vector > &fpts, std::vector< Vector > &bpts, Vector &botc, Vector &topc, Vector &bodc)
Points on body cylinders.
Definition: pt_complete_state.cpp:65
Represents the state of an actor at a frame.
Definition: pt_complete_state.h:42