Choreonoid  1.8
Camera.h
Go to the documentation of this file.
1 
6 #ifndef CNOID_BODY_CAMERA_H
7 #define CNOID_BODY_CAMERA_H
8 
9 #include "Device.h"
10 #include <cnoid/Image>
11 #include <memory>
12 #include "exportdecl.h"
13 
14 namespace cnoid {
15 
16 class Mapping;
17 
18 class CNOID_EXPORT Camera : public Device
19 {
20 public:
21  Camera();
22  Camera(const Camera& org, bool copyStateOnly = false);
23 
24  virtual const char* typeName() const override;
25  void copyStateFrom(const Camera& other);
26  virtual void copyStateFrom(const DeviceState& other) override;
27  virtual DeviceState* cloneState() const override;
28  virtual void forEachActualType(std::function<bool(const std::type_info& type)> func) override;
29  virtual void clearState() override;
30 
31  void setImageStateClonable(bool on) { isImageStateClonable_ = on; }
32  bool isImageStateClonable() const { return isImageStateClonable_; }
33 
34  enum ImageType { NO_IMAGE, COLOR_IMAGE, GRAYSCALE_IMAGE };
35  enum LensType { NORMAL_LENS, FISHEYE_LENS, DUAL_FISHEYE_LENS };
36 
37  ImageType imageType() const { return imageType_; }
38  void setImageType(ImageType type) { imageType_ = type; }
39 
40  LensType lensType() const { return lensType_; }
41  void setLensType(LensType type) { lensType_ = type; }
42 
43  virtual bool on() const override;
44  virtual void on(bool on) override;
45 
46  double nearClipDistance() const { return nearClipDistance_; }
47  void setNearClipDistance(double d) { nearClipDistance_ = d; }
48  double farClipDistance() const { return farClipDistance_; }
49  void setFarClipDistance(double d) { farClipDistance_ = d; }
50 
51 #ifdef CNOID_BACKWARD_COMPATIBILITY
52  double nearDistance() const { return nearClipDistance_; }
53  void setNearDistance(double d) { nearClipDistance_ = d; }
54  double farDistance() const { return farClipDistance_; }
55  void setFarDistance(double d) { farClipDistance_ = d; }
56 #endif
57 
58  double fieldOfView() const { return fieldOfView_; }
59  void setFieldOfView(double f) { fieldOfView_ = f; }
60 
61  void setResolution(int x, int y) {
62  resolutionX_ = x; resolutionY_ = y;
63  }
64  void setResolutionX(int x) { resolutionX_ = x; }
65  void setResolutionY(int y) { resolutionY_ = y; }
66 
67  int resolutionX() const { return resolutionX_; }
68  int resolutionY() const { return resolutionY_; }
69 
70  void setFrameRate(double r) { frameRate_ = r; }
71  double frameRate() const { return frameRate_; }
72 
73  const Image& image() const;
74  const Image& constImage() const { return *image_; }
75  Image& image();
76  Image& newImage();
77 
78  std::shared_ptr<const Image> sharedImage() const { return image_; }
79 
85  void setImage(std::shared_ptr<Image>& image);
86 
87  void clearImage();
88 
92  double delay() const { return delay_; }
93  void setDelay(double time) { delay_ = time; }
94 
95  virtual int stateSize() const override;
96  virtual const double* readState(const double* buf) override;
97  virtual double* writeState(double* out_buf) const override;
98 
99  bool readSpecifications(const Mapping* info);
100  bool writeSpecifications(Mapping* info) const;
101 
102 protected:
103  virtual Referenced* doClone(CloneMap* cloneMap) const override;
104 
105 private:
106  bool on_;
107  bool isImageStateClonable_; // Non state variable
108  ImageType imageType_;
109  LensType lensType_;
110  int resolutionX_;
111  int resolutionY_;
112  double nearClipDistance_;
113  double farClipDistance_;
114  double fieldOfView_;
115  double frameRate_;
116  double delay_;
117  std::shared_ptr<Image> image_;
118 
119  void copyCameraStateFrom(const Camera& other);
120 };
121 
123 
124 }
125 
126 #endif
cnoid::CameraPtr
ref_ptr< Camera > CameraPtr
Definition: Camera.h:122
cnoid::Mapping
Definition: ValueTree.h:253
Device.h
cnoid::Camera::resolutionY
int resolutionY() const
Definition: Camera.h:68
cnoid::Camera::nearClipDistance
double nearClipDistance() const
Definition: Camera.h:46
cnoid::Camera::imageType
ImageType imageType() const
Definition: Camera.h:37
cnoid::Camera::setResolution
void setResolution(int x, int y)
Definition: Camera.h:61
cnoid::Camera::delay
double delay() const
Definition: Camera.h:92
cnoid::Camera::isImageStateClonable
bool isImageStateClonable() const
Definition: Camera.h:32
cnoid::Camera
Definition: Camera.h:18
cnoid::Camera::constImage
const Image & constImage() const
Definition: Camera.h:74
cnoid::Camera::setResolutionX
void setResolutionX(int x)
Definition: Camera.h:64
cnoid::ref_ptr
Definition: Referenced.h:103
cnoid::Camera::setFarClipDistance
void setFarClipDistance(double d)
Definition: Camera.h:49
cnoid::Camera::setNearClipDistance
void setNearClipDistance(double d)
Definition: Camera.h:47
cnoid::Camera::resolutionX
int resolutionX() const
Definition: Camera.h:67
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::CloneMap
Definition: CloneMap.h:13
cnoid::DeviceState
Definition: Device.h:20
cnoid::Camera::setImageStateClonable
void setImageStateClonable(bool on)
Definition: Camera.h:31
cnoid::Camera::NO_IMAGE
@ NO_IMAGE
Definition: Camera.h:34
cnoid::Camera::setResolutionY
void setResolutionY(int y)
Definition: Camera.h:65
cnoid::Camera::sharedImage
std::shared_ptr< const Image > sharedImage() const
Definition: Camera.h:78
cnoid::Camera::lensType
LensType lensType() const
Definition: Camera.h:40
cnoid::Referenced
Definition: Referenced.h:54
cnoid::Camera::ImageType
ImageType
Definition: Camera.h:34
cnoid::Image
Definition: Image.h:16
cnoid::Device
Definition: Device.h:53
cnoid::Camera::setDelay
void setDelay(double time)
Definition: Camera.h:93
cnoid::Camera::farClipDistance
double farClipDistance() const
Definition: Camera.h:48
cnoid::Camera::setImageType
void setImageType(ImageType type)
Definition: Camera.h:38
cnoid::Camera::fieldOfView
double fieldOfView() const
Definition: Camera.h:58
cnoid::Camera::setFieldOfView
void setFieldOfView(double f)
Definition: Camera.h:59
cnoid::Camera::setLensType
void setLensType(LensType type)
Definition: Camera.h:41
cnoid::Camera::NORMAL_LENS
@ NORMAL_LENS
Definition: Camera.h:35
cnoid::Camera::frameRate
double frameRate() const
Definition: Camera.h:71
cnoid::Camera::setFrameRate
void setFrameRate(double r)
Definition: Camera.h:70
cnoid::Camera::LensType
LensType
Definition: Camera.h:35