1 //This is brl/bbas/volm/volm_spherical_shell_container.h
2 #ifndef volm_spherical_shell_container_h_
3 #define volm_spherical_shell_container_h_
4 //:
5 // \file
6 // \brief  A class to represent a container of points uniformly distributed on a spherical surface.
7 // The radius of that sphere is pre-defined. Each point represents the ray from sphere center (0,0,0) to the surface point.
8 // The uniform distribution is accomplished by triangle division on octahedron to certain density.
9 // The points are stored both as cartesian coordinates and spherical coordinates.
10 // The spherical coordinate system is based on bbas/vsph:
11 //  elevation is zero at the North pole and 180 at the South pole
12 //  azimuth is zero pointing along X and positive rotating towards Y
13 //  azimuth is +- 180 pointing along -X
14 //
15 // \author Yi Dong
16 // \date October 24, 2012
17 // \verbatim
18 //  Modifications
19 // February 2, 2013
20 // Replaced the internals of this class by the more basic vsph_unit_sphere
21 // Older constructors are maintained for compatibility. For example,
22 // radius_ is no longer needed since its value is always one. Note also that
23 // cap_angle is no longer used since min,max theta accomplish the same
24 // purpose.
25 // \endverbatim
26 //
27 
28 #include <vector>
29 #include <iostream>
30 #include <cstddef>
31 #include <vbl/vbl_ref_count.h>
32 #ifdef _MSC_VER
33 #  include <vcl_msvc_warnings.h>
34 #endif
35 #include <vgl/vgl_point_3d.h>
36 #include <vsph/vsph_spherical_coord_sptr.h>
37 #include <vsph/vsph_spherical_coord.h>
38 #include <vsph/vsph_sph_point_3d.h>
39 #include <vsph/vsph_unit_sphere.h>
40 #include <vil/vil_image_view.h>
41 
42 class volm_spherical_shell_container : public vbl_ref_count
43 {
44  public:
45   //: Default constructor
46   volm_spherical_shell_container() = default;
47   //: Legacy Constructor
48   volm_spherical_shell_container(double radius, float cap_angle, float point_angle, float top_angle, float bottom_angle);
49   //: Minimal constructor (to internally construct vsph_unit_sphere)
50   volm_spherical_shell_container(double point_angle, double min_theta,
51                                  double max_theta);
52   //: Construct using an existing unit sphere smart ptr
volm_spherical_shell_container(vsph_unit_sphere_sptr usph_ptr)53  volm_spherical_shell_container(vsph_unit_sphere_sptr usph_ptr) :
54   usph_(usph_ptr){}
55 
56   // === accessors ===
57 
cap_angle()58   double cap_angle() const { return 180.0; }
radius()59   double radius() const { return 1.0; }
point_angle()60   double point_angle() const { return usph_->point_angle(); }
top_angle()61   double top_angle() const { return usph_->min_theta(); }
bottom_angle()62   double bottom_angle() const {return 180.0 - usph_->max_theta(); }
cent()63   vgl_point_3d<double> cent() const { return {0.0, 0.0, 0.0}; }
64   std::vector<vgl_point_3d<double> > cart_points() const;
65 
66   std::vector<vsph_sph_point_3d> sph_points() const;
67 
unit_sphere()68   vsph_unit_sphere_sptr unit_sphere() const {return usph_;}
69 
get_container_size()70   std::size_t get_container_size() const { return usph_->size(); }
71 
72   void draw_template(const std::string& vrml_file_name);
73   //: draw each disk with a color with respect to the values, the size and order of the values should be the size and order of the cart_points
74   void draw_template(const std::string& vrml_file_name, std::vector<unsigned char>& values, unsigned char special);
75 
76   //: generate panaroma image
77   void panaroma_img(vil_image_view<vil_rgb<vxl_byte> >& img, std::vector<unsigned char>& values);
78   void panaroma_img_class_labels(vil_image_view<vil_rgb<vxl_byte> >& img, std::vector<unsigned char>& values);
79   void panaroma_img_orientations(vil_image_view<vil_rgb<vxl_byte> >& img, std::vector<unsigned char>& values);
80   void panaroma_images_from_combined(vil_image_view<vil_rgb<vxl_byte> >& img_orientation, vil_image_view<vil_rgb<vxl_byte> >& img, std::vector<unsigned char>& values);
81 
82   // ===========  binary I/O ================
83 
84   //: version
version()85   unsigned version() const {return 1;}
86 
87   //: binary IO write
88   void b_write(vsl_b_ostream& os);
89 
90   //: binary IO read
91   void b_read(vsl_b_istream& is);
92 
93   bool operator== (const volm_spherical_shell_container &other) const;
94 
95  protected:
96   vsph_unit_sphere_sptr usph_;
97 };
98 
99 #endif  // volm_spherical_shell_container_h_
100