00001 // This is brl/bbas/bgui3d/bgui3d_viewer_tableau.h 00002 #ifndef bgui3d_viewer_tableau_h_ 00003 #define bgui3d_viewer_tableau_h_ 00004 //: 00005 // \file 00006 // \brief Abstract base tableau for 3D viewers 00007 // \author Matt Leotta (mleotta@lems.brown.edu) 00008 // \date May 25, 2004 00009 // 00010 // \verbatim 00011 // Modifications 00012 // <none yet> 00013 // \endverbatim 00014 00015 #include "bgui3d_tableau.h" 00016 00017 // forward declarations 00018 class SoCamera; 00019 class SoDirectionalLight; 00020 class SoGroup; 00021 class SoOrthographicCamera; 00022 class SoPerspectiveCamera; 00023 class SoSwitch; 00024 class SoText2; 00025 00026 00027 //: Abstract base tableau for 3D viewers 00028 class bgui3d_viewer_tableau : public bgui3d_tableau 00029 { 00030 protected: 00031 //: Constructor 00032 bgui3d_viewer_tableau(SoNode * scene_root = NULL); 00033 00034 //: Destructor 00035 virtual ~bgui3d_viewer_tableau(); 00036 00037 public: 00038 //: Handle vgui events 00039 virtual bool handle(const vgui_event& event) = 0; 00040 00041 //: Return the type name of this tableau 00042 virtual vcl_string type_name() const = 0; 00043 00044 //: Set the scene root 00045 virtual void set_scene_root(SoNode* scene_root); 00046 00047 //: Return the root node in the users portion of the scene graph 00048 SoNode* user_scene_root() const { return user_scene_root_; } 00049 00050 //--------------Camera Methods-------------------- 00051 enum camera_type_enum {PERSPECTIVE, ORTHOGONAL}; 00052 00053 //: Set the scene camera 00054 // Generate an SoCamera from a camera matrix and use it 00055 virtual bool set_camera(const vpgl_proj_camera<double>& camera); 00056 00057 //: Get the scene camera 00058 // Creates a vpgl camera (either perspective or affine) from the active SoCamera 00059 virtual vcl_auto_ptr<vpgl_proj_camera<double> > camera() const; 00060 00061 //: Set the camera viewing the scene 00062 virtual void set_camera(SoCamera *camera); 00063 00064 //: Select the active camera by index 00065 // A negative index selects the first user scene camera 00066 void select_camera(int camera_index); 00067 00068 //: Return the camera viewing the scene 00069 SoCamera* camera_node() const; 00070 00071 //: Set the camera type (Perspective or Orthogonal) 00072 virtual void set_camera_type(camera_type_enum type); 00073 00074 //: Return the camera type (Perspective or Orthogonal) 00075 camera_type_enum camera_type() const; 00076 00077 //: Toggle the camera type between Perspective and Orthogonal 00078 virtual void toggle_camera_type(); 00079 00080 //: Adjust the camera to view the entire scene 00081 virtual void view_all(); 00082 00083 //: Save the current camera as the home position 00084 virtual void save_home_position(); 00085 00086 //: Restore the saved home position of the camera 00087 virtual void reset_to_home_position(); 00088 00089 virtual void set_clipping_planes(); 00090 //------------------------------------------------- 00091 00092 //-------------Headlight Methods------------------- 00093 //: Activate a headlight 00094 virtual void set_headlight(bool enable); 00095 00096 //: Is the headlight active 00097 bool is_headlight() const; 00098 00099 //: Return the headlight 00100 SoDirectionalLight* headlight() const; 00101 //------------------------------------------------- 00102 00103 //-------------Text Methods------------------- 00104 //: set the text 00105 void setText( const vcl_string& string ); 00106 00107 protected: 00108 //: Find the parent nodes in the scene graph 00109 vcl_vector<SoGroup*> get_parents_of_node(SoNode * node); 00110 00111 //: Convert to perspective 00112 void convertOrtho2Perspective(const SoOrthographicCamera * in, 00113 SoPerspectiveCamera * out); 00114 //: Convert to orthographic 00115 void convertPerspective2Ortho(const SoPerspectiveCamera * in, 00116 SoOrthographicCamera * out); 00117 00118 //: Find the camera nodes in the scenegraph 00119 vcl_vector<SoCamera*> find_cameras(SoNode* root) const; 00120 00121 //: Find the VRML viewpoint nodes in the scenegraph and make camera 00122 // The cameras are added to the camera group (outside the user scene) 00123 void collect_vrml_cameras(SoNode* root) const; 00124 00125 protected: 00126 00127 //: The subgraph provided by the user 00128 SoNode* user_scene_root_; 00129 00130 SoSwitch* camera_group_; 00131 00132 SoCamera* scene_camera_; 00133 SoNode* stored_camera_; 00134 00135 camera_type_enum camera_type_; 00136 00137 SoDirectionalLight * headlight_; 00138 00139 SoText2* text_; 00140 }; 00141 00142 #endif // bgui3d_viewer_tableau_h_