1 // This is brl/bbas/bgui3d/bgui3d_viewer_tableau.h
2 #ifndef bgui3d_viewer_tableau_h_
3 #define bgui3d_viewer_tableau_h_
4 //:
5 // \file
6 // \brief  Abstract base tableau for 3D viewers
7 // \author Matt Leotta (mleotta@lems.brown.edu)
8 // \date   May 25, 2004
9 //
10 // \verbatim
11 //  Modifications
12 //   <none yet>
13 // \endverbatim
14 
15 #include "bgui3d_tableau.h"
16 
17 // forward declarations
18 class SoCamera;
19 class SoDirectionalLight;
20 class SoGroup;
21 class SoOrthographicCamera;
22 class SoPerspectiveCamera;
23 class SoSwitch;
24 class SoText2;
25 
26 
27 //:  Abstract base tableau for 3D viewers
28 class bgui3d_viewer_tableau : public bgui3d_tableau
29 {
30  protected:
31   //: Constructor
32   bgui3d_viewer_tableau(SoNode * scene_root = NULL);
33 
34   //: Destructor
35   virtual ~bgui3d_viewer_tableau();
36 
37  public:
38   //: Handle vgui events
39   virtual bool handle(const vgui_event& event) = 0;
40 
41   //: Return the type name of this tableau
42   virtual std::string type_name() const = 0;
43 
44   //: Set the scene root
45   virtual void set_scene_root(SoNode* scene_root);
46 
47   //: Return the root node in the users portion of the scene graph
user_scene_root()48   SoNode* user_scene_root() const { return user_scene_root_; }
49 
50   //--------------Camera Methods--------------------
51   enum camera_type_enum {PERSPECTIVE, ORTHOGONAL};
52 
53   //: Set the scene camera
54   // Generate an SoCamera from a camera matrix and use it
55   virtual bool set_camera(const vpgl_proj_camera<double>& camera);
56 
57   //: Get the scene camera
58   // Creates a vpgl camera (either perspective or affine) from the active SoCamera
59   virtual std::unique_ptr<vpgl_proj_camera<double> > camera() const;
60 
61   //: Set the camera viewing the scene
62   virtual void set_camera(SoCamera *camera);
63 
64   //: Select the active camera by index
65   // A negative index selects the first user scene camera
66   void select_camera(int camera_index);
67 
68   //: Return the camera viewing the scene
69   SoCamera* camera_node() const;
70 
71   //: Set the camera type (Perspective or Orthogonal)
72   virtual void set_camera_type(camera_type_enum type);
73 
74   //: Return the camera type (Perspective or Orthogonal)
75   camera_type_enum camera_type() const;
76 
77   //: Toggle the camera type between Perspective and Orthogonal
78   virtual void toggle_camera_type();
79 
80   //: Adjust the camera to view the entire scene
81   virtual void view_all();
82 
83   //: Save the current camera as the home position
84   virtual void save_home_position();
85 
86   //: Restore the saved home position of the camera
87   virtual void reset_to_home_position();
88 
89   virtual void set_clipping_planes();
90   //-------------------------------------------------
91 
92   //-------------Headlight Methods-------------------
93   //: Activate a headlight
94   virtual void set_headlight(bool enable);
95 
96   //: Is the headlight active
97   bool is_headlight() const;
98 
99   //: Return the headlight
100   SoDirectionalLight* headlight() const;
101   //-------------------------------------------------
102 
103   //-------------Text Methods-------------------
104   //: set the text
105   void setText( const std::string& string );
106 
107  protected:
108   //: Find the parent nodes in the scene graph
109   std::vector<SoGroup*> get_parents_of_node(SoNode * node);
110 
111   //: Convert to perspective
112   void convertOrtho2Perspective(const SoOrthographicCamera * in,
113                                 SoPerspectiveCamera * out);
114   //: Convert to orthographic
115   void convertPerspective2Ortho(const SoPerspectiveCamera * in,
116                                 SoOrthographicCamera * out);
117 
118   //: Find the camera nodes in the scenegraph
119   std::vector<SoCamera*> find_cameras(SoNode* root) const;
120 
121   //: Find the VRML viewpoint nodes in the scenegraph and make camera
122   // The cameras are added to the camera group (outside the user scene)
123   void collect_vrml_cameras(SoNode* root) const;
124 
125  protected:
126 
127   //: The subgraph provided by the user
128   SoNode* user_scene_root_;
129 
130   SoSwitch* camera_group_;
131 
132   SoCamera* scene_camera_;
133   SoNode* stored_camera_;
134 
135   camera_type_enum camera_type_;
136 
137   SoDirectionalLight * headlight_;
138 
139   SoText2* text_;
140 };
141 
142 #endif // bgui3d_viewer_tableau_h_
143