Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
SingleLensObserver.h
Go to the documentation of this file.
1#pragma once
2
4#include "SDL/sdl_interface.h"
6#include "Math/TVector2.h"
7
8#include <Common/primitive_type.h>
9
10#include <memory>
11#include <optional>
12
13namespace ph { class PinholeCamera; }
14namespace ph { class ThinLensCamera; }
15
16namespace ph
17{
18
20{
21public:
22 inline SingleLensObserver() = default;
23
24 void cook(const CoreCookingContext& ctx, CoreCookedUnit& cooked) override;
25
26 float64 getLensRadius() const;
27 float64 getFocalDistance() const;
29 float64 getSensorOffset(const CoreCookingContext& ctx) const;
30
31protected:
33 void genPinholeCamera(const CoreCookingContext& ctx, CoreCookedUnit& cooked);
34 void genThinLensCamera(const CoreCookingContext& ctx, CoreCookedUnit& cooked);
35
36private:
37 real m_lensRadiusMM;
38 real m_focalDistanceMM;
39 real m_sensorWidthMM;
40 real m_sensorOffsetMM;
41 std::optional<real> m_fovDegrees;
42
43public:
45 {
46 ClassType clazz("single-lens");
47 clazz.docName("Single-Lens Observer");
48 clazz.description(
49 "As its name suggests, the lens system in this observer is assumed to have "
50 "just a single lens. The biggest advantage of it is that depth of field "
51 "effects are possible under this model. In case of the lens radius is zero, "
52 "the lens system will be reduced to a pinhole. Images captured by this "
53 "observer is similar to how a normal human perceives the world but with "
54 "several simplifications.");
55 clazz.baseOn<OrientedRasterObserver>();
56
57 TSdlReal<OwnerType> lensRadiusMM("lens-radius-mm", &OwnerType::m_lensRadiusMM);
58 lensRadiusMM.description("Radius of the lens in millimeters.");
59 lensRadiusMM.defaultTo(0);
60 lensRadiusMM.optional();
61 clazz.addField(lensRadiusMM);
62
63 TSdlReal<OwnerType> focalDistanceMM("focal-distance-mm", &OwnerType::m_focalDistanceMM);
64 focalDistanceMM.description("The distance in millimeters that the observer is focusing on.");
65 focalDistanceMM.defaultTo(150);
66 focalDistanceMM.optional();
67 clazz.addField(focalDistanceMM);
68
69 TSdlReal<OwnerType> sensorWidthMM("sensor-width-mm", &OwnerType::m_sensorWidthMM);
70 sensorWidthMM.description("Width of the sensor used by this observer in millimeters.");
71 sensorWidthMM.defaultTo(36);
72 sensorWidthMM.optional();
73 clazz.addField(sensorWidthMM);
74
75 TSdlReal<OwnerType> sensorOffsetMM("sensor-offset-mm", &OwnerType::m_sensorOffsetMM);
76 sensorOffsetMM.description(
77 "Distance between sensor and light entry (more commonly known as focal length). "
78 "Will be overridden if FoV is provided.");
79 sensorOffsetMM.defaultTo(36);
80 sensorOffsetMM.optional();
81 clazz.addField(sensorOffsetMM);
82
83 TSdlOptionalReal<OwnerType> fovDegrees("fov-degrees", &OwnerType::m_fovDegrees);
84 fovDegrees.description(
85 "Field of view of this observer in degrees. If provided, it will be used to "
86 "adjust sensor offset such that the desired FoV is reached.");
87 clazz.addField(fovDegrees);
88
89 return clazz;
90 }
91};
92
93// In-header Implementations:
94
96{
97 return m_lensRadiusMM / 1000.0;
98}
99
101{
102 return m_focalDistanceMM / 1000.0;
103}
104
105}// end namespace ph
Definition CoreCookedUnit.h:19
Definition CoreCookingContext.h:15
Definition OrientedRasterObserver.h:19
Definition SingleLensObserver.h:20
math::Vector2D getSensorSize(const CoreCookingContext &ctx) const
Definition SingleLensObserver.cpp:68
PH_DEFINE_SDL_CLASS(TSdlOwnerClass< SingleLensObserver >)
Definition SingleLensObserver.h:44
void cook(const CoreCookingContext &ctx, CoreCookedUnit &cooked) override
Definition SingleLensObserver.cpp:15
float64 getLensRadius() const
Definition SingleLensObserver.h:95
float64 getSensorOffset(const CoreCookingContext &ctx) const
Definition SingleLensObserver.cpp:74
float64 getFocalDistance() const
Definition SingleLensObserver.h:100
void genPinholeCamera(const CoreCookingContext &ctx, CoreCookedUnit &cooked)
Definition SingleLensObserver.cpp:87
void genThinLensCamera(const CoreCookingContext &ctx, CoreCookedUnit &cooked)
Definition SingleLensObserver.cpp:106
SingleLensObserver()=default
math::TDecomposedTransform< float64 > makeRasterToSensor(const CoreCookingContext &ctx) const
Definition SingleLensObserver.cpp:27
SDL binding type for a canonical SDL resource class.
Definition TSdlOwnerClass.h:23
A field class that binds a floating point member variable.
Definition TSdlReal.h:21
TSdlValue & description(std::string descriptionStr)
Definition TSdlValue.ipp:95
TSdlValue & optional()
Definition TSdlValue.ipp:103
TSdlValue & defaultTo(T defaultValue)
Definition TSdlValue.ipp:71
Perform affine transformations in decomposed form.
Definition TDecomposedTransform.h:24
The root for all renderer implementations.
Definition EEngineProject.h:6