-
Notifications
You must be signed in to change notification settings - Fork 455
/
Copy pathFisheyeSensor.h
138 lines (117 loc) · 3.9 KB
/
FisheyeSensor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) Meta Platforms, Inc. and its affiliates.
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#ifndef ESP_SENSOR_FISHEYESENSOR_H_
#define ESP_SENSOR_FISHEYESENSOR_H_
#include <Corrade/Containers/Optional.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/Magnum.h>
#include "CubeMapSensorBase.h"
#include "esp/core/Esp.h"
#include "esp/gfx/CubeMap.h"
#include "esp/gfx/CubeMapCamera.h"
#include "esp/gfx/CubeMapShaderBase.h"
#include "esp/gfx/RenderTarget.h"
namespace esp {
// forward declaration
namespace sim {
class Simulator;
}
namespace sensor {
enum class FisheyeSensorModelType : Mn::UnsignedInt {
// Vladyslav Usenko, Nikolaus Demmel and Daniel Cremers: The Double Sphere
// Camera Model, The International Conference on 3D Vision (3DV), 2018
DoubleSphere = 0,
// TODO:
// User can implement her own model such as:
// FieldOfView = 1,
// KannalaBrandt = 2,
// All future supported models go above this
EndFisheyeSensorModelType,
};
struct FisheyeSensorSpec : public CubeMapSensorBaseSpec {
FisheyeSensorModelType fisheyeModelType;
/**
* @brief Focal length, fx, fy, the distance between the pinhole and the image
* plane.
* In practice, fx and fy can differ for a number of reasons. See
* details here: http://ksimek.github.io/2013/08/13/intrinsic/
*/
Mn::Vector2 focalLength;
/**
* @brief Principal Point Offset in pixel, cx, cy, location of the principal
* point relative to the image plane's origin. None will place it in the
* middle of the image (height/2, width/2).
*/
Cr::Containers::Optional<Mn::Vector2> principalPointOffset;
/**
* @brief Constructor
*/
FisheyeSensorSpec();
/**
* @brief operator ==, check if 2 specs are equal
*/
bool operator==(const FisheyeSensorSpec& a) const;
/**
* @brief check if the specification is legal
*/
void sanityCheck() const override;
ESP_SMART_POINTERS(FisheyeSensorSpec)
};
struct FisheyeSensorDoubleSphereSpec : public FisheyeSensorSpec {
/**
* @brief alpha and xi are specific to "double sphere" camera model.
* see details (value ranges) in:
* Vladyslav Usenko, Nikolaus Demmel and Daniel Cremers: The Double Sphere
* Camera Model, The International Conference on 3D Vision (3DV), 2018
*/
float alpha = 0.59;
float xi = -0.18;
/**
* @brief constructor
*/
FisheyeSensorDoubleSphereSpec() : FisheyeSensorSpec() {}
/**
* @brief check if the specification is legal
*/
void sanityCheck() const override;
ESP_SMART_POINTERS(FisheyeSensorDoubleSphereSpec)
};
// TODO:
// struct FisheyeFieldOfViewSpec : public FisheyeSensorSpec {};
// struct FisheyeKannalaBrandtSpec : public FisheyeSensorSpec {};
class FisheyeSensor : public CubeMapSensorBase {
public:
static constexpr const char* FISH_EYE_SHADER_KEY_TEMPLATE =
"fisheye-model-type={}-flags={}";
/**
* @brief constructor
* NOTE: the status of the camera sensor is "valid" after construction, and
* user can use them immediately
*/
explicit FisheyeSensor(scene::SceneNode& cameraNode,
const FisheyeSensorSpec::ptr& spec);
/**
* @brief destructor
*/
~FisheyeSensor() override = default;
/**
* @brief Draw an observation to the frame buffer
* @return true if success, otherwise false (e.g., frame buffer is not set)
* @param[in] sim Instance of Simulator class for which the observation needs
* to be drawn
*/
bool drawObservation(sim::Simulator& sim) override;
/**
* @brief Return a pointer to this fisheye sensor's SensorSpec
*/
FisheyeSensorSpec::ptr specification() const { return fisheyeSensorSpec_; }
protected:
FisheyeSensorSpec::ptr fisheyeSensorSpec_ =
std::dynamic_pointer_cast<FisheyeSensorSpec>(spec_);
Mn::ResourceKey getShaderKey() override;
ESP_SMART_POINTERS(FisheyeSensor)
};
} // namespace sensor
} // namespace esp
#endif