Choreonoid  1.8
SceneDevice.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_BODY_SCENE_DEVICE_H
6 #define CNOID_BODY_SCENE_DEVICE_H
7 
8 #include <cnoid/SceneGraph>
9 #include <functional>
10 #include "exportdecl.h"
11 
12 namespace cnoid {
13 
14 class Device;
15 class Camera;
16 class Light;
17 class PointLight;
18 class SpotLight;
19 
20 class CNOID_EXPORT SceneDevice : public SgPosTransform
21 {
22 public:
23  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 
25  // for integrating new device types
26  typedef std::function<SceneDevice*(Device* device)> SceneDeviceFactory;
27  template<class DeviceType>
28  static void registerSceneDeviceFactory(const SceneDeviceFactory& factory){
29  registerSceneDeviceFactory_(typeid(DeviceType), factory);
30  }
31 
32  template<class DeviceType>
34  FactoryRegistration(const SceneDeviceFactory& factory){
35  registerSceneDeviceFactory_(typeid(DeviceType), factory);
36  }
37  };
38 
39  static SceneDevice* create(Device* device);
40 
41  SceneDevice(Device* device);
43  Device* device, SgNode* sceneNode,
44  std::function<void()> functionOnStateChanged = nullptr,
45  std::function<void(double time)> functionOnTimeChanged = nullptr);
46 
47  template <class DeviceType> DeviceType* device() {
48  return static_cast<DeviceType*>(device_);
49  }
50  template <class DeviceType> const DeviceType* device() const {
51  return static_cast<DeviceType*>(device_);
52  }
53  Device* device() { return device_; }
54  const Device* device() const { return device_; }
55 
56  void setFunctionOnStateChanged(std::function<void()> function);
58  void setSceneUpdateFunction(std::function<void()> function){
59  setFunctionOnStateChanged(function); };
60  void setFunctionOnTimeChanged(std::function<void(double time)> function);
61 
62  void updateScene(double time) {
63  if(functionOnStateChanged) functionOnStateChanged();
64  if(functionOnTimeChanged) functionOnTimeChanged(time);
65  }
66 
67  void setSceneUpdateConnection(bool on);
68 
69 protected:
70  ~SceneDevice();
71 
72 private:
73  SceneDevice(const SceneDevice& org);
74  Device* device_;
75  std::function<void()> functionOnStateChanged;
76  std::function<void(double time)> functionOnTimeChanged;
77  Connection stateChangeConnection;
78  Connection timeChangeConnection;
79 
80  static void registerSceneDeviceFactory_(const std::type_info& type, const SceneDeviceFactory& factory);
81 };
82 
84 
85 }
86 
87 #endif
cnoid::SgPosTransform
Definition: SceneGraph.h:357
cnoid::SceneDevice::FactoryRegistration::FactoryRegistration
FactoryRegistration(const SceneDeviceFactory &factory)
Definition: SceneDevice.h:34
cnoid::SceneDevice::device
const DeviceType * device() const
Definition: SceneDevice.h:50
cnoid::SceneDevicePtr
ref_ptr< SceneDevice > SceneDevicePtr
Definition: SceneDevice.h:83
cnoid::SceneDevice::device
DeviceType * device()
Definition: SceneDevice.h:47
cnoid::ref_ptr
Definition: Referenced.h:103
cnoid::SceneDevice::setSceneUpdateFunction
void setSceneUpdateFunction(std::function< void()> function)
Definition: SceneDevice.h:58
cnoid::SceneDevice::registerSceneDeviceFactory
static void registerSceneDeviceFactory(const SceneDeviceFactory &factory)
Definition: SceneDevice.h:28
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::SceneDevice::device
const Device * device() const
Definition: SceneDevice.h:54
cnoid::SceneDevice::updateScene
void updateScene(double time)
Definition: SceneDevice.h:62
cnoid::SceneDevice::FactoryRegistration
Definition: SceneDevice.h:33
cnoid::Device
Definition: Device.h:53
cnoid::Connection
Definition: Signal.h:206
cnoid::SgNode
Definition: SceneGraph.h:157
cnoid::SceneDevice::device
Device * device()
Definition: SceneDevice.h:53
cnoid::SceneDevice
Definition: SceneDevice.h:20