Choreonoid  1.8
SceneRenderer.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_UTIL_SCENE_RENDERER_H
7 #define CNOID_UTIL_SCENE_RENDERER_H
8 
9 #include "SceneGraph.h"
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 class CNOID_EXPORT SceneRenderer
16 {
17  class Impl;
18 
19 public:
20  SceneRenderer();
21  virtual ~SceneRenderer();
22 
23  void setName(const std::string& name);
24  const std::string& name() const;
25 
26  static void addExtension(std::function<void(SceneRenderer* renderer)> func);
27  virtual void applyExtensions();
28  virtual bool applyNewExtensions();
29 
30  virtual SgGroup* sceneRoot() = 0;
31  virtual SgGroup* scene() = 0;
32  virtual void clearScene();
33 
36 
37  virtual PolymorphicSceneNodeFunctionSet* renderingFunctions() = 0;
38  virtual void renderCustomGroup(SgGroup* group, std::function<void()> traverseFunction) = 0;
39  virtual void renderCustomTransform(SgTransform* transform, std::function<void()> traverseFunction) = 0;
40  virtual void renderNode(SgNode* node) = 0;
41 
42  typedef std::function<SgNode*(SgNode* targetNode)> NodeDecorationFunction;
43  virtual void addNodeDecoration(SgNode* targetNode, NodeDecorationFunction func, int id) = 0;
44  virtual void clearNodeDecorations(int id) = 0;
45 
46  int numCameras() const;
47  SgCamera* camera(int index);
48  const SgNodePath& cameraPath(int index) const;
49  const Isometry3& cameraPosition(int index) const;
50  const Isometry3& currentCameraPosition() const;
51  SignalProxy<void()> sigCamerasChanged() const;
52  SgCamera* currentCamera() const;
53  int currentCameraIndex() const;
54  void setCurrentCamera(int index);
55  bool setCurrentCamera(SgCamera* camera);
56  SignalProxy<void()> sigCurrentCameraChanged();
57  std::vector<std::string> simplifiedCameraPathStrings(int cameraIndex);
58  bool getSimplifiedCameraPathStrings(int cameraIndex, std::vector<std::string>& out_pathStrings);
59  int findCameraPath(const std::vector<std::string>& simplifiedPathStrings);
60  bool setCurrentCameraPath(const std::vector<std::string>& simplifiedPathStrings);
61  void setCurrentCameraAutoRestorationMode(bool on);
62 
63  int numLights() const;
64  void getLightInfo(int index, SgLight*& out_light, Isometry3& out_position) const;
65  void setAsDefaultLight(SgLight* light);
66  void unsetDefaultLight(SgLight* light);
67  SgLight* headLight();
68  void setHeadLight(SgLight* light);
69  void enableAdditionalLights(bool on);
70 
71  void enableFog(bool on);
72  bool isFogEnabled() const;
73  int numFogs() const;
74  SgFog* fog(int index) const;
75 
76  virtual const Affine3& currentModelTransform() const = 0;
77  virtual const Matrix4& projectionMatrix() const = 0;
78  virtual double projectedPixelSizeRatio(const Vector3& position) const = 0;
79 
84  void extractPreprocessedNodes();
85 
86  /*
87  This flag variable is used to check if the tree of preprocessed nodes
88  must be updated when the extractPreprocessedNodes function is executed.
89  You can skip the redundant update process by setting false to the flag
90  when the tree is not changed.
91  */
92  void setFlagVariableToUpdatePreprocessedNodeTree(bool& flag);
93 
94  void render();
95  bool pick(int x, int y);
96 
97  virtual bool isRenderingPickingImage() const;
98 
99  class CNOID_EXPORT PropertyKey {
100  int id;
101  public:
102  PropertyKey(const std::string& key);
103  friend class SceneRenderer::Impl;
104  };
105 
106  void setProperty(PropertyKey key, bool value);
107  void setProperty(PropertyKey key, int value);
108  void setProperty(PropertyKey key, double value);
109  bool property(PropertyKey key, bool defaultValue) const;
110  int property(PropertyKey key, int defaultValue) const;
111  double property(PropertyKey key, double defaultValue) const;
112 
113 protected:
114  virtual void doRender() = 0;
115  virtual bool doPick(int x, int y);
116 
117 private:
118  Impl* impl;
119 };
120 
121 }
122 
123 #endif
cnoid::SgTransform
Definition: SceneGraph.h:336
cnoid::Vector3
Eigen::Vector3d Vector3
Definition: EigenTypes.h:57
cnoid::SgGroup
Definition: SceneGraph.h:220
cnoid::Isometry3
Eigen::Isometry3d Isometry3
Definition: EigenTypes.h:73
cnoid::SceneRenderer::PropertyKey
Definition: SceneRenderer.h:99
cnoid::SgCamera
Definition: SceneCameras.h:14
cnoid::SgLight
Definition: SceneLights.h:14
cnoid::Matrix4
Eigen::Matrix4d Matrix4
Definition: EigenTypes.h:58
cnoid::SgFog
Definition: SceneEffects.h:69
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::SceneRenderer::NodeDecorationFunction
std::function< SgNode *(SgNode *targetNode)> NodeDecorationFunction
Definition: SceneRenderer.h:42
cnoid::PolymorphicSceneNodeFunctionSet
Definition: PolymorphicSceneNodeFunctionSet.h:10
SceneGraph.h
cnoid::SgNodePath
std::vector< SgNode * > SgNodePath
Definition: SceneGraph.h:24
cnoid::SignalProxy
Definition: Signal.h:470
cnoid::SgNode
Definition: SceneGraph.h:157
PolymorphicSceneNodeFunctionSet.h
cnoid::Affine3
Eigen::Affine3d Affine3
Definition: EigenTypes.h:62
cnoid::SceneRenderer::NodeFunctionSet
PolymorphicSceneNodeFunctionSet NodeFunctionSet
Definition: SceneRenderer.h:35
cnoid::SceneRenderer
Definition: SceneRenderer.h:15