1 // =============================================================================
2 // PROJECT CHRONO - http://projectchrono.org
3 //
4 // Copyright (c) 2019 projectchrono.org
5 // All rights reserved.
6 //
7 // Use of this source code is governed by a BSD-style license that can be found
8 // in the LICENSE file at the top level of the distribution and at
9 // http://projectchrono.org/license-chrono.txt.
10 //
11 // =============================================================================
12 // Authors: Asher Elmquist
13 // =============================================================================
14 //
15 // Container class for a camera sensor. This specifies a default ray tracing
16 // for cameras.
17 //
18 // =============================================================================
19 
20 #ifndef CHCAMERASENSOR_H
21 #define CHCAMERASENSOR_H
22 
23 #include "chrono_sensor/sensors/ChOptixSensor.h"
24 
25 namespace chrono {
26 namespace sensor {
27 
28 /// @addtogroup sensor_sensors
29 /// @{
30 
31 /// The type of lens model that camera can use for rendering
32 enum class CameraLensModelType {
33     PINHOLE,  ///< traditional computer graphics ideal camera model.
34     FOV_LENS  ///< Wide angle lens model based on single spherical lens.
35 };
36 
37 /// Camera class
38 class CH_SENSOR_API ChCameraSensor : public ChOptixSensor {
39   public:
40     /// @brief Constructor for the base camera class that defaults to a pinhole lens model
41     /// @param parent A shared pointer to a body on which the sensor should be attached.
42     /// @param updateRate The desired update rate of the sensor in Hz.
43     /// @param offsetPose The desired relative position and orientation of the sensor on the body.
44     /// @param w The width of the image the camera should generate.
45     /// @param h The height of the image the camera should generate.
46     /// @param hFOV The horizontal field of view of the camera lens.
47     /// @param supersample_factor The number of rays that should be sampled per pixel for antialiasing.
48     /// @param lens_model A enum specifying the desired lens model.
49     /// @param use_gi Enable the global illumination, with significant decrease in performace
50     /// @param gamma correction of the image, 1 for linear color space, 2.2 for sRGB
51     ChCameraSensor(std::shared_ptr<chrono::ChBody> parent,  // object to which the sensor is attached
52                    float updateRate,                        // rate at which the sensor updates
53                    chrono::ChFrame<double> offsetPose,      // position of sensor relative to parent object
54                    unsigned int w,                          // image width
55                    unsigned int h,                          // image height
56                    float hFOV,                              // horizontal field of view
57                    unsigned int supersample_factor = 1,     // number of samples per pixel for antialiasing
58                    CameraLensModelType lens_model = CameraLensModelType::PINHOLE,
59                    bool use_gi = false,  // camera model to use for rendering
60                    float gamma = 2.2);   // gamma correction value
61 
62     /// camera class destructor
63     ~ChCameraSensor();
64 
65     /// returns the camera's horizontal field of view. Vertical field of view is determined by the image aspect
66     /// ratio and the lens model
67     /// @return The horizontal field of view of the camera lens
GetHFOV()68     float GetHFOV() const { return m_hFOV; }
69 
70     /// returns the lens model type used for rendering
71     /// @return An enum specifying which lens model is being used. (0: PINHOLE, 1: SPHERICAL)
GetLensModelType()72     CameraLensModelType GetLensModelType() const { return m_lens_model_type; }
73 
74     /// returns if the cemera requesting global illumination
75     /// @return True if it does request
GetUseGI()76     bool GetUseGI() { return m_use_gi; }
77 
78     /// returns the gamma correction value of this camera.
79     /// 1 means no correction and the image is in linear color space. Useful for other ML applications
80     /// 2.2 means the image is in sRGB color space. Useful for display
81     /// @return Gamma value of the image
GetGamma()82     float GetGamma() { return m_gamma; }
83 
84   private:
85     float m_hFOV;                           ///< the horizontal field of view of the sensor
86     unsigned int m_supersample_factor;      ///< super sampling factor for antialiasing
87     CameraLensModelType m_lens_model_type;  ///< lens model used by the camera
88     bool m_use_gi;                          ///< to hold reference to whether user what to use GI or not
89     float m_gamma;
90 };
91 
92 /// @} sensor_sensors
93 
94 }  // namespace sensor
95 }  // namespace chrono
96 
97 #endif
98