[r36646]: trunk / contrib / brl / bbas / vsph / vsph_sph_box_2d.h  Maximize  Restore  History

Download this file

168 lines (135 with data), 6.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifndef vsph_sph_box_2d_h_
#define vsph_sph_box_2d_h_
//:
// \file
// \brief An axis-aligned box on the unit sphere.
// \author J.L. Mundy
// \date February 1, 2013
// \verbatim
// Modifications none
// \endverbatim
#include <vsl/vsl_binary_io.h>
#include <vcl_iostream.h>
#include <vsph/vsph_sph_point_2d.h>
#include <vcl_vector.h>
#include <vgl/vgl_vector_3d.h>
//:
// theta is elevation, phi is azimuth
//
// Note that the creation of intervals on the azimuth circle is not
// well-defined. In contrast to intervals on the real line,
// there is an ambiguity as to which portion of the circle is
// the bounded set of angles. That is two points divide the circle
// into two arcs and the bounded set could be either one. Thus it is
// necessary to have three points. Points a and b define the two arcs and
// point c determines which arc contains the bounded set.
//
// To infer the bounded set from a sequence of points it is necessary to assume
// the initial three points are "compact," that is that they all lie in the
// smaller of the two arcs. That is |b - a|<180 and a<c<b . In this case,
// the predicate < means counter clockwise, i.e., a<b indicates that
// rotation to go from a to b is less than 180 and is counter-clockwise.
//
class vsph_sph_box_2d
{
public:
//: Default constructor
vsph_sph_box_2d();
//: Specify units
vsph_sph_box_2d(bool in_radians);
//: Constructor from three points.
// Three points, pa, pb and pc, are needed to define an
// unambiguous order on azimuth having a cut at +-180.
// Two of the points, pa and pb, bound the interval and the third
// point, c, defines which complementary arc of the circle is "in" the box.
// pa < pb by definition. pc lies on the smaller or larger arc to
// break the ambiguity
vsph_sph_box_2d(vsph_sph_point_2d const& pa, vsph_sph_point_2d const& pb,
vsph_sph_point_2d const& pc);
~vsph_sph_box_2d() {}
void set(double min_theta, double max_theta, double a_phi, double b_phi,
double c_phi, bool in_radians = true);
//: the angle units (radians or degrees) maintained by *this box
bool in_radians() const {return in_radians_;}
//: bounds on azimuth and elevation, if in_radians == false.
// the return is in degrees.
double min_phi(bool in_radians = true) const;
double min_theta(bool in_radians = true) const;
double max_phi(bool in_radians = true) const;
double max_theta(bool in_radians = true) const;
double a_phi(bool in_radians = true) const;
double b_phi(bool in_radians = true) const;
double c_phi(bool in_radians = true) const;
vsph_sph_point_2d min_point(bool in_radians = true) const;
vsph_sph_point_2d max_point(bool in_radians = true) const;
//: is box empty, i.e. no points have been added
bool is_empty() const;
//: add point to update box bounds.
// assumes the box already has the three point basis
// or the added point sequence is from a "compact" set on the circle
void add( double theta, double phi, bool in_radians = true);
void add( vsph_sph_point_2d const& pt) { add(pt.theta_, pt.phi_, pt.in_radians_); }
//: does the box have enough added points to uniquely define interval bounds
bool defined() const;
//: is an azimuth angle contained in the current bounded azimuth interval
bool in_interval(double phi, bool in_radians=true) const;
//: does the box contain the specified spherical point ?
bool contains(double const& theta, double const& phi, bool in_radians = true) const;
bool contains(vsph_sph_point_2d const& p) const;
//: does *this box fully contain box b
bool contains(vsph_sph_box_2d const& b) const;
//: area on the surface of unit sphere
double area() const;
//: the spherical point corresponding to the center of the box
vsph_sph_point_2d center(bool in_radians = true) const;
//: transform the box on the unit sphere
vsph_sph_box_2d transform(double t_theta, double t_phi, double scale,
bool in_radians) const;
vsph_sph_box_2d transform(double t_theta,
double t_phi, double scale,
double theta_c,double phi_c,
bool in_radians) const;
//: decompose box into approximately planar quadrilaterals
void planar_quads(vcl_vector<vgl_vector_3d<double> >& verts,
vcl_vector<vcl_vector<int> >& quads,
double tol = 0.01) const;
//: display the box as a set of planar quadrilaterals in vrml
void display_box(vcl_ostream& os, float r, float g, float b,
double tol = 0.01,
double factor =1.0) const;
//: display a set of boxes
static void display_boxes(vcl_string const& path,
vcl_vector<vsph_sph_box_2d> const& boxes,
vcl_vector<vcl_vector<float> > colors,
double tol = 0.01,
double factor =1.0);
//: support for binary I/O
void print(vcl_ostream& os, bool in_radians = true) const;
void b_read(vsl_b_istream& is);
void b_write(vsl_b_ostream& os);
short version() const {return 1;}
private:
//: the value of pi in the units of *this box
double pye() const;
//: reduce phi to the range +-180 (assumed in *this angle units)
double reduce_phi(double phi) const;
//: bounds of ccw traversal of phi interval in *this angle units
void phi_bounds(double& phi_start, double& phi_end) const;
//: update the current theta bounds
void update_theta(double th);
//: the azimuth angle ph is outside the current interval so extend it
bool extend_interval(double ph);
//: the angle units of *this box
bool in_radians_;
//: the three azimuth angles that define an unambigous bounded set
// a and b define two circular intervals and c determines the bounded interval
double a_phi_, b_phi_, c_phi_;
//: the bounds on elevation
double min_th_, max_th_;
};
//: return a box that represents the intersection of two boxes (could be empty)
// note that it is possible to have two disjoint intervals in phi (2 boxes)
bool intersection(vsph_sph_box_2d const& b1, vsph_sph_box_2d const& b2,
vcl_vector<vsph_sph_box_2d>& boxes);
vcl_ostream& operator<<(vcl_ostream& os, vsph_sph_box_2d const& p);
#endif //vsph_sph_box_2d_h_

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks