/resources/languages/cpp/Camera.cpp

https://github.com/cyberbotics/webots · C++ · 132 lines · 89 code · 30 blank · 13 comment · 0 complexity · 84f898e992357743c64c6058e8f2939f MD5 · raw file

  1. // Copyright 1996-2020 Cyberbotics Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #define WB_ALLOW_MIXING_C_AND_CPP_API
  15. #include <webots/camera.h>
  16. #include <webots/Camera.hpp>
  17. using namespace std;
  18. using namespace webots;
  19. void Camera::enable(int sampling_period) {
  20. wb_camera_enable(getTag(), sampling_period);
  21. }
  22. void Camera::disable() {
  23. wb_camera_disable(getTag());
  24. }
  25. int Camera::getSamplingPeriod() const {
  26. return wb_camera_get_sampling_period(getTag());
  27. }
  28. const unsigned char *Camera::getImage() const {
  29. return wb_camera_get_image(getTag());
  30. }
  31. unsigned char Camera::imageGetRed(const unsigned char *image, int width, int x, int y) {
  32. return wb_camera_image_get_red(image, width, x, y);
  33. }
  34. unsigned char Camera::imageGetGreen(const unsigned char *image, int width, int x, int y) {
  35. return wb_camera_image_get_green(image, width, x, y);
  36. }
  37. unsigned char Camera::imageGetBlue(const unsigned char *image, int width, int x, int y) {
  38. return wb_camera_image_get_blue(image, width, x, y);
  39. }
  40. unsigned char Camera::imageGetGray(const unsigned char *image, int width, int x, int y) {
  41. return wb_camera_image_get_gray(image, width, x, y);
  42. }
  43. unsigned char Camera::imageGetGrey(const unsigned char *image, int width, int x, int y) {
  44. return wb_camera_image_get_grey(image, width, x, y);
  45. }
  46. int Camera::getWidth() const {
  47. return wb_camera_get_width(getTag());
  48. }
  49. int Camera::getHeight() const {
  50. return wb_camera_get_height(getTag());
  51. }
  52. double Camera::getFov() const {
  53. return wb_camera_get_fov(getTag());
  54. }
  55. double Camera::getMaxFov() const {
  56. return wb_camera_get_max_fov(getTag());
  57. }
  58. double Camera::getMinFov() const {
  59. return wb_camera_get_min_fov(getTag());
  60. }
  61. void Camera::setFov(double fov) {
  62. wb_camera_set_fov(getTag(), fov);
  63. }
  64. double Camera::getFocalLength() const {
  65. return wb_camera_get_focal_length(getTag());
  66. }
  67. double Camera::getFocalDistance() const {
  68. return wb_camera_get_focal_distance(getTag());
  69. }
  70. double Camera::getMaxFocalDistance() const {
  71. return wb_camera_get_max_focal_distance(getTag());
  72. }
  73. double Camera::getMinFocalDistance() const {
  74. return wb_camera_get_min_focal_distance(getTag());
  75. }
  76. void Camera::setFocalDistance(double focalDistance) {
  77. wb_camera_set_focal_distance(getTag(), focalDistance);
  78. }
  79. double Camera::getNear() const {
  80. return wb_camera_get_near(getTag());
  81. }
  82. int Camera::saveImage(const string &filename, int quality) const {
  83. return wb_camera_save_image(getTag(), filename.c_str(), quality);
  84. }
  85. bool Camera::hasRecognition() const {
  86. return wb_camera_has_recognition(getTag());
  87. }
  88. void Camera::recognitionEnable(int samplingPeriod) {
  89. wb_camera_recognition_enable(getTag(), samplingPeriod);
  90. }
  91. void Camera::recognitionDisable() {
  92. wb_camera_recognition_disable(getTag());
  93. }
  94. int Camera::getRecognitionSamplingPeriod() const {
  95. return wb_camera_recognition_get_sampling_period(getTag());
  96. }
  97. int Camera::getRecognitionNumberOfObjects() const {
  98. return wb_camera_recognition_get_number_of_objects(getTag());
  99. }
  100. const CameraRecognitionObject *Camera::getRecognitionObjects() const {
  101. return wb_camera_recognition_get_objects(getTag());
  102. }