Choreonoid  1.5
GLSceneRenderer.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_BASE_GL_SCENE_RENDERER_H
7 #define CNOID_BASE_GL_SCENE_RENDERER_H
8 
9 #include <cnoid/SceneGraph>
10 #include <cnoid/SceneRenderer>
11 #include <boost/function.hpp>
12 #include "exportdecl.h"
13 
14 namespace cnoid {
15 
16 class GLSceneRendererImpl;
17 class SgCustomGLNode;
18 class Mapping;
19 
21 {
22 public:
24  GLSceneRenderer(SgGroup* root);
25  virtual ~GLSceneRenderer();
26 
27  virtual SgGroup* sceneRoot();
28  virtual SgGroup* scene();
29  virtual void clearScene();
30 
31  virtual int numCameras() const;
32  virtual SgCamera* camera(int index);
33  virtual const SgNodePath& cameraPath(int index) const;
34  virtual SignalProxy<void()> sigCamerasChanged() const;
35 
36  virtual SgCamera* currentCamera() const;
37  virtual int currentCameraIndex() const;
38  virtual void setCurrentCamera(int index);
39  virtual bool setCurrentCamera(SgCamera* camera);
40  virtual SignalProxy<void()> sigCurrentCameraChanged();
41 
42  virtual void setViewport(int x, int y, int width, int height);
43  virtual Array4i viewport() const;
44  void getViewport(int& out_x, int& out_y, int& out_width, int& out_height) const;
45  virtual double aspectRatio() const; // width / height;
46 
47  virtual const Affine3& currentModelTransform() const;
48  virtual const Affine3& currentCameraPosition() const;
49  virtual const Matrix4& projectionMatrix() const;
50 
51  void getViewFrustum(const SgPerspectiveCamera& camera,
52  double& left, double& right, double& bottom, double& top) const;
53  void getViewVolume(const SgOrthographicCamera& camera,
54  double& left, double& right, double& bottom, double& top) const;
55 
56  bool initializeGL();
57 
58  // The following functions cannot be called bofore calling the initializeGL() function.
59  bool setSwapInterval(int interval);
60  int getSwapInterval() const;
61 
70  virtual void initializeRendering();
71 
72  virtual SignalProxy<void()> sigRenderingRequest();
73 
74  void extractPreprocessedNodes();
75 
76  virtual void beginRendering();
77  virtual void endRendering();
78  virtual void render();
79  virtual void flush();
80 
81  bool pick(int x, int y);
82  const Vector3& pickedPoint() const;
83  const SgNodePath& pickedNodePath() const;
84 
85  const Vector3f& backgroundColor() const;
86  void setBackgroundColor(const Vector3f& color);
87 
88  virtual SgLight* headLight();
89  virtual void setHeadLight(SgLight* light);
90  void setHeadLightLightingFromBackEnabled(bool on);
91 
92  void setAsDefaultLight(SgLight* light);
93  void unsetDefaultLight(SgLight* light);
94 
95  void enableAdditionalLights(bool on);
96 
97  enum PolygonMode { FILL_MODE, LINE_MODE, POINT_MODE };
98  void setPolygonMode(PolygonMode mode);
99 
100  void setDefaultLighting(bool on);
101  void setDefaultSmoothShading(bool on);
102  SgMaterial* defaultMaterial();
103  void setDefaultColor(const Vector4f& color);
104  void enableTexture(bool on);
105  void setDefaultPointSize(double size);
106  void setDefaultLineWidth(double width);
107  void enableFog(bool on);
108  SgFog* currentFog();
109 
110  void setNewDisplayListDoubleRenderingEnabled(bool on);
111 
112  void showNormalVectors(double length);
113 
114  void requestToClearCache();
115 
121  virtual void enableUnusedCacheCheck(bool on);
122 
123  virtual void visitGroup(SgGroup* group);
124  virtual void visitInvariantGroup(SgInvariantGroup* group);
125  virtual void visitTransform(SgTransform* transform);
126  virtual void visitUnpickableGroup(SgUnpickableGroup* group);
127  virtual void visitShape(SgShape* shape);
128  virtual void visitPointSet(SgPointSet* pointSet);
129  virtual void visitLineSet(SgLineSet* lineSet);
130  virtual void visitPreprocessed(SgPreprocessed* preprocessed);
131  virtual void visitLight(SgLight* light);
132  virtual void visitOverlay(SgOverlay* overlay);
133  virtual void visitOutlineGroup(SgOutlineGroup* outline);
134 
135  bool isPicking();
136 
137  void setColor(const Vector4f& color);
138  void enableColorMaterial(bool on);
139  void setDiffuseColor(const Vector4f& color);
140  void setAmbientColor(const Vector4f& color);
141  void setEmissionColor(const Vector4f& color);
142  void setSpecularColor(const Vector4f& color);
143  void setShininess(float shininess);
144  void enableCullFace(bool on);
145  void setFrontCCW(bool on);
146  void enableLighting(bool on);
147  void setLightModelTwoSide(bool on);
148  void enableBlend(bool on);
149  void enableDepthMask(bool on);
150  void setPointSize(float size);
151  void setLineWidth(float width);
152 
153 private:
154  GLSceneRendererImpl* impl;
155  friend class SgCustomGLNode;
156 };
157 
158 
160 {
161 public:
162  typedef boost::function<void(GLSceneRenderer& renderer)> RenderingFunction;
163 
165  SgCustomGLNode(RenderingFunction f) : renderingFunction(f) { }
166  virtual SgObject* clone(SgCloneMap& cloneMap) const;
167  virtual void accept(SceneVisitor& visitor);
168  virtual void render(GLSceneRenderer& renderer);
169  void setRenderingFunction(RenderingFunction f);
170 
171 protected:
172  SgCustomGLNode(const SgCustomGLNode& org, SgCloneMap& cloneMap) : SgGroup(org, cloneMap) { }
173 
174 private:
175  RenderingFunction renderingFunction;
176 };
178 }
179 
180 #endif
Definition: SceneLights.h:14
Definition: SceneGraph.h:381
SgCustomGLNode(const SgCustomGLNode &org, SgCloneMap &cloneMap)
Definition: GLSceneRenderer.h:172
Definition: GLSceneRenderer.h:159
Definition: SceneGraph.h:394
Eigen::Matrix4d Matrix4
Definition: EigenTypes.h:60
Definition: SceneDrawables.h:17
SgCustomGLNode(RenderingFunction f)
Definition: GLSceneRenderer.h:165
Definition: SceneEffects.h:36
Definition: SceneCameras.h:14
Definition: SceneDrawables.h:509
Eigen::Affine3d Affine3
Definition: EigenTypes.h:64
Definition: SceneGraph.h:56
Definition: SceneEffects.h:14
std::vector< SgNode * > SgNodePath
Definition: SceneGraph.h:140
Definition: SceneGraph.h:262
Definition: SceneRenderer.h:15
Definition: SceneCameras.h:58
Definition: SceneGraph.h:160
Defines the minimum processing for performing pasing file for STL.
Definition: AbstractSceneLoader.h:9
Definition: SceneDrawables.h:590
boost::function< void(GLSceneRenderer &renderer)> RenderingFunction
Definition: GLSceneRenderer.h:162
Definition: SceneCameras.h:81
Definition: SceneDrawables.h:420
ref_ptr< SgCustomGLNode > SgCustomGLNodePtr
Definition: GLSceneRenderer.h:177
Eigen::Vector3d Vector3
Definition: EigenTypes.h:58
PolygonMode
Definition: GLSceneRenderer.h:97
Definition: SceneDrawables.h:532
#define CNOID_EXPORT
Definition: Util/exportdecl.h:37
Definition: GLSceneRenderer.h:20
Definition: Signal.h:380
Definition: SceneVisitor.h:15
Definition: SceneGraph.h:249
Definition: SceneGraph.h:79
SgCustomGLNode()
Definition: GLSceneRenderer.h:164