contrib/brl/bbas/bgui/bgui_vsol_camera_tableau.h
Go to the documentation of this file.
00001 // This is brl/bbas/bgui/bgui_vsol_camera_tableau.h
00002 #ifndef bgui_vsol_camera_tableau_h_
00003 #define bgui_vsol_camera_tableau_h_
00004 //-----------------------------------------------------------------------------
00005 //:
00006 // \file
00007 // \brief A tableau that knows how to project 3-d vsol objects with a camera
00008 // \author
00009 //   J.L. Mundy
00010 //
00011 // \verbatim
00012 //  Created June 2, 2003
00013 //  Modifications:
00014 //   Peter Vanroose - 8 May 2004 - re-implemented add_vsol_box_3d() with a single polygon
00015 //   Now obsolete == do not use in new code === J.L. Mundy, March 1, 2008
00016 // \endverbatim
00017 //-----------------------------------------------------------------------------
00018 #include <vcl_vector.h>
00019 #include <vcl_map.h>
00020 #include <vgl/algo/vgl_p_matrix.h>
00021 #include <vgui/vgui_style.h>
00022 #include <vgl/vgl_point_2d.h>
00023 #include <vsol/vsol_spatial_object_3d_sptr.h>
00024 #include <vsol/vsol_point_3d_sptr.h>
00025 #include <vsol/vsol_line_3d_sptr.h>
00026 #include <vsol/vsol_polygon_3d_sptr.h>
00027 #include <vsol/vsol_box_3d_sptr.h>
00028 #include <vgui/vgui_tableau_sptr.h>
00029 #include <vgui/vgui_style_sptr.h>
00030 #include <vgui/vgui_image_tableau_sptr.h>
00031 #include <vgui/vgui_easy2D_tableau.h>
00032 
00033 #include "bgui_vsol_camera_tableau_sptr.h"
00034 class bgui_vsol_soview2D_point;
00035 class bgui_vsol_soview2D_line_seg;
00036 class bgui_vsol_soview2D_polygon;
00037 
00038 class bgui_vsol_camera_tableau : public vgui_easy2D_tableau
00039 {
00040  public:
00041   bgui_vsol_camera_tableau(const char* n="unnamed");
00042 
00043   bgui_vsol_camera_tableau(vgui_image_tableau_sptr const& it,
00044                            const char* n="unnamed");
00045 
00046   bgui_vsol_camera_tableau(vgui_tableau_sptr const& t,
00047                            const char* n="unnamed");
00048 
00049   ~bgui_vsol_camera_tableau();
00050 
00051   //:virtual handle method for events
00052   virtual bool handle(vgui_event const &);
00053 
00054   //:the projection camera
00055   void set_camera(vgl_p_matrix<double> const& camera) { camera_=camera; }
00056   vgl_p_matrix<double> get_camera() const { return camera_; }
00057 
00058   //: display for projected vsol_point_3d
00059   bgui_vsol_soview2D_point*
00060     add_vsol_point_3d(vsol_point_3d_sptr const& point);
00061 
00062   //: display for vsol_line_3d
00063   bgui_vsol_soview2D_line_seg*
00064     add_vsol_line_3d(vsol_line_3d_sptr const& line);
00065 
00066   //: display for vsol_polygon_3d
00067   bgui_vsol_soview2D_polygon*
00068     add_vsol_polygon_3d(vsol_polygon_3d_sptr const& poly);
00069 
00070   //:display for a 3D box
00071   bgui_vsol_soview2D_polygon*
00072     add_vsol_box_3d(vsol_box_3d_sptr const& box);
00073 
00074   //: display for general spatial object
00075   void add_spatial_object_3d(vsol_spatial_object_3d_sptr const& sos);
00076 
00077   //: display methods for sets of objects
00078   void add_spatial_objects_3d(vcl_vector<vsol_spatial_object_3d_sptr> const& sos);
00079 
00080   void add_points_3d(vcl_vector<vsol_point_3d_sptr> const & lines);
00081 
00082   void add_lines_3d(vcl_vector<vsol_line_3d_sptr> const & lines);
00083 
00084   void add_polygons_3d(vcl_vector<vsol_polygon_3d_sptr> const & lines);
00085 
00086   void add_boxes_3d(vcl_vector<vsol_box_3d_sptr> const & lines);
00087 
00088 
00089   //: clear the tableau including the highlight map
00090   void clear_all();
00091 
00092   //: Methods for getting mapped objects
00093   void enable_highlight() { highlight_ = true; }
00094   void disable_highlight() { highlight_ = false; }
00095 
00096   //: Methods for changing the default style of displayable objects
00097 
00098   void set_vsol_point_3d_style(const float r, const float g, const float b,
00099                                const float point_radius);
00100 
00101   void set_vsol_line_3d_style(const float r, const float g, const float b,
00102                               const float line_width);
00103 
00104   void set_vsol_polygon_3d_style(const float r, const float g, const float b,
00105                                  const float line_width);
00106 
00107   void set_vsol_box_3d_style(const float r, const float g, const float b,
00108                              const float line_width);
00109 
00110  protected:
00111   //internal methods
00112   vgl_point_2d<double>  project(vsol_point_3d_sptr const& p3d);
00113   //members
00114   bool highlight_;
00115   void init();
00116   vcl_map<int, vsol_spatial_object_3d_sptr> obj_map_;
00117   vcl_map<vcl_string, vgui_style_sptr> style_map_;
00118   int old_id_;
00119   vgui_style_sptr highlight_style_;
00120   vgui_style_sptr old_style_;
00121   vgl_p_matrix<double> camera_;
00122 };
00123 
00124 //this stuff is needed to establish inheritance between tableau  smart pointers
00125 //cloned from xcv_image_tableau
00126 struct bgui_vsol_camera_tableau_new : public bgui_vsol_camera_tableau_sptr
00127 {
00128   typedef bgui_vsol_camera_tableau_sptr base;
00129 
00130   bgui_vsol_camera_tableau_new(const char* n="unnamed") :
00131     base(new bgui_vsol_camera_tableau(n)) { }
00132   bgui_vsol_camera_tableau_new(vgui_image_tableau_sptr const& it,
00133                                const char* n="unnamed") :
00134     base(new bgui_vsol_camera_tableau(it,n)) { }
00135 
00136   bgui_vsol_camera_tableau_new(vgui_tableau_sptr const& t, const char* n="unnamed")
00137     :  base(new bgui_vsol_camera_tableau(t, n)) { }
00138 
00139   operator vgui_easy2D_tableau_sptr () const { vgui_easy2D_tableau_sptr tt; tt.vertical_cast(*this); return tt; }
00140 };
00141 
00142 #endif // bgui_vsol_camera_tableau_h_