Loading...
Searching...
No Matches
camera.h
1//
2// Copyright 2017 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_CAMERA_H
8#define PXR_IMAGING_HD_CAMERA_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/version.h"
13#include "pxr/imaging/hd/sprim.h"
14
15#include "pxr/imaging/cameraUtil/conformWindow.h"
16
19#include "pxr/base/gf/range1f.h"
20#include "pxr/base/gf/vec2f.h"
21
22#include <vector>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
31#define HD_CAMERA_TOKENS \
32 /* frustum */ \
33 (projection) \
34 (horizontalAperture) \
35 (verticalAperture) \
36 (horizontalApertureOffset) \
37 (verticalApertureOffset) \
38 (focalLength) \
39 (clippingRange) \
40 (clipPlanes) \
41 \
42 /* depth of field */ \
43 (fStop) \
44 (focusDistance) \
45 (focusOn) \
46 (dofAspect) \
47 ((splitDiopterCount, "splitDiopter:count")) \
48 ((splitDiopterAngle, "splitDiopter:angle")) \
49 ((splitDiopterOffset1, "splitDiopter:offset1")) \
50 ((splitDiopterWidth1, "splitDiopter:width1")) \
51 ((splitDiopterFocusDistance1, "splitDiopter:focusDistance1")) \
52 ((splitDiopterOffset2, "splitDiopter:offset2")) \
53 ((splitDiopterWidth2, "splitDiopter:width2")) \
54 ((splitDiopterFocusDistance2, "splitDiopter:focusDistance2")) \
55 \
56 /* shutter/lighting */ \
57 (shutterOpen) \
58 (shutterClose) \
59 (exposure) \
60 (exposureTime) \
61 (exposureIso) \
62 (exposureFStop) \
63 (exposureResponsivity) \
64 (linearExposureScale) \
65 \
66 /* how to match window with different aspect */ \
67 (windowPolicy) \
68 \
69 /* lens distortion */ \
70 (standard) \
71 (fisheye) \
72 ((lensDistortionType, "lensDistortion:type")) \
73 ((lensDistortionK1, "lensDistortion:k1")) \
74 ((lensDistortionK2, "lensDistortion:k2")) \
75 ((lensDistortionCenter, "lensDistortion:center")) \
76 ((lensDistortionAnaSq, "lensDistortion:anaSq")) \
77 ((lensDistortionAsym, "lensDistortion:asym")) \
78 ((lensDistortionScale, "lensDistortion:scale")) \
79 ((lensDistortionIor, "lensDistortion:ior"))
80
81
82TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS);
83
91class HdCamera : public HdSprim
92{
93public:
94 using ClipPlanesVector = std::vector<GfVec4d>;
95
96 HD_API
97 HdCamera(SdfPath const & id);
98 HD_API
99 ~HdCamera() override;
100
101 // change tracking for HdCamera
102 enum DirtyBits : HdDirtyBits
103 {
104 Clean = 0,
105 DirtyTransform = 1 << 0,
106 DirtyParams = 1 << 1,
107 DirtyClipPlanes = 1 << 2,
108 DirtyWindowPolicy = 1 << 3,
109 AllDirty = (DirtyTransform
110 |DirtyParams
111 |DirtyClipPlanes
112 |DirtyWindowPolicy)
113 };
114
115 enum Projection {
116 Perspective = 0,
117 Orthographic
118 };
119
120 // ---------------------------------------------------------------------- //
122 // ---------------------------------------------------------------------- //
123
125 HD_API
126 void Sync(HdSceneDelegate *sceneDelegate,
127 HdRenderParam *renderParam,
128 HdDirtyBits *dirtyBits) override;
129
130
134 HD_API
135 HdDirtyBits GetInitialDirtyBitsMask() const override;
136
137 // ---------------------------------------------------------------------- //
139 // ---------------------------------------------------------------------- //
140
142 GfMatrix4d const& GetTransform() const {
143 return _transform;
144 }
145
147 Projection GetProjection() const {
148 return _projection;
149 }
150
152 float GetHorizontalAperture() const {
153 return _horizontalAperture;
154 }
155
157 float GetVerticalAperture() const {
158 return _verticalAperture;
159 }
160
163 return _horizontalApertureOffset;
164 }
165
168 return _verticalApertureOffset;
169 }
170
172 float GetFocalLength() const {
173 return _focalLength;
174 }
175
178 return _clippingRange;
179 }
180
182 std::vector<GfVec4d> const& GetClipPlanes() const {
183 return _clipPlanes;
184 }
185
187 float GetFStop() const {
188 return _fStop;
189 }
190
192 float GetFocusDistance() const {
193 return _focusDistance;
194 }
195
196 bool GetFocusOn() const {
197 return _focusOn;
198 }
199
200 float GetDofAspect() const {
201 return _dofAspect;
202 }
203
204 int GetSplitDiopterCount() const {
205 return _splitDiopterCount;
206 }
207
208 float GetSplitDiopterAngle() const {
209 return _splitDiopterAngle;
210 }
211
212 float GetSplitDiopterOffset1() const {
213 return _splitDiopterOffset1;
214 }
215
216 float GetSplitDiopterWidth1() const {
217 return _splitDiopterWidth1;
218 }
219
220 float GetSplitDiopterFocusDistance1() const {
221 return _splitDiopterFocusDistance1;
222 }
223
224 float GetSplitDiopterOffset2() const {
225 return _splitDiopterOffset2;
226 }
227
228 float GetSplitDiopterWidth2() const {
229 return _splitDiopterWidth2;
230 }
231
232 float GetSplitDiopterFocusDistance2() const {
233 return _splitDiopterFocusDistance2;
234 }
235
236 double GetShutterOpen() const {
237 return _shutterOpen;
238 }
239
240 double GetShutterClose() const {
241 return _shutterClose;
242 }
243
251 float GetExposure() const {
252 return _exposure;
253 }
254
261 return _linearExposureScale;
262 }
263
264 TfToken GetLensDistortionType() const {
265 return _lensDistortionType;
266 }
267
268 float GetLensDistortionK1() const {
269 return _lensDistortionK1;
270 }
271
272 float GetLensDistortionK2() const {
273 return _lensDistortionK2;
274 }
275
276 const GfVec2f& GetLensDistortionCenter() const {
277 return _lensDistortionCenter;
278 }
279
280 float GetLensDistortionAnaSq() const {
281 return _lensDistortionAnaSq;
282 }
283
284 const GfVec2f& GetLensDistortionAsym() const {
285 return _lensDistortionAsym;
286 }
287
288 float GetLensDistortionScale() const {
289 return _lensDistortionScale;
290 }
291
292 float GetLensDistortionIor() const {
293 return _lensDistortionIor;
294 }
295
298 const CameraUtilConformWindowPolicy& GetWindowPolicy() const {
299 return _windowPolicy;
300 }
301
302 // ---------------------------------------------------------------------- //
304 // ---------------------------------------------------------------------- //
305
308 HD_API
310
311protected:
312 // frustum
313 GfMatrix4d _transform;
314 Projection _projection;
315 float _horizontalAperture;
316 float _verticalAperture;
317 float _horizontalApertureOffset;
318 float _verticalApertureOffset;
319 float _focalLength;
320 GfRange1f _clippingRange;
321 std::vector<GfVec4d> _clipPlanes;
322
323 // focus
324 float _fStop;
325 float _focusDistance;
326 bool _focusOn;
327 float _dofAspect;
328 int _splitDiopterCount;
329 float _splitDiopterAngle;
330 float _splitDiopterOffset1;
331 float _splitDiopterWidth1;
332 float _splitDiopterFocusDistance1;
333 float _splitDiopterOffset2;
334 float _splitDiopterWidth2;
335 float _splitDiopterFocusDistance2;
336
337 // shutter
338 double _shutterOpen;
339 double _shutterClose;
340
341 // exposure
342 float _exposure;
343 float _exposureTime;
344 float _exposureIso;
345 float _exposureFStop;
346 float _exposureResponsivity;
347 float _linearExposureScale;
348
349 // lens distortion
350 TfToken _lensDistortionType;
351 float _lensDistortionK1;
352 float _lensDistortionK2;
353 GfVec2f _lensDistortionCenter;
354 float _lensDistortionAnaSq;
355 GfVec2f _lensDistortionAsym;
356 float _lensDistortionScale;
357 float _lensDistortionIor;
358
359 // Camera's opinion how it display in a window with
360 // a different aspect ratio
361 CameraUtilConformWindowPolicy _windowPolicy;
362};
363
364PXR_NAMESPACE_CLOSE_SCOPE
365
366#endif // PXR_IMAGING_HD_CAMERA_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: 1-dimensional floating point range.
Definition: range1f.h:45
Basic type for a vector of 2 float components.
Definition: vec2f.h:46
Hydra schema for a camera that pulls the params (see above) during Sync.
Definition: camera.h:92
float GetHorizontalApertureOffset() const
Returns horizontal aperture offset in world units.
Definition: camera.h:162
float GetFocusDistance() const
Returns focus distance in world units.
Definition: camera.h:192
float GetHorizontalAperture() const
Returns horizontal aperture in world units.
Definition: camera.h:152
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Sprim API.
GfMatrix4d const & GetTransform() const
Camera parameters accessor API.
Definition: camera.h:142
std::vector< GfVec4d > const & GetClipPlanes() const
Returns any additional clipping planes defined in camera space.
Definition: camera.h:182
float GetLinearExposureScale() const
Get the computed linear exposure scale from the underlying camera.
Definition: camera.h:260
float GetFStop() const
Returns fstop of camera.
Definition: camera.h:187
float GetVerticalAperture() const
Returns vertical aperture in world units.
Definition: camera.h:157
float GetFocalLength() const
Returns focal length in world units.
Definition: camera.h:172
HD_API HdDirtyBits GetInitialDirtyBitsMask() const override
Returns the minimal set of dirty bits to place in the change tracker for use in the first sync of thi...
float GetVerticalApertureOffset() const
Returns vertical aperture offset in world units.
Definition: camera.h:167
HD_API GfMatrix4d ComputeProjectionMatrix() const
Convenience API for rasterizers.
Projection GetProjection() const
Returns whether camera is orthographic and perspective.
Definition: camera.h:147
GfRange1f const & GetClippingRange() const
Returns near and far plane in world units.
Definition: camera.h:177
const CameraUtilConformWindowPolicy & GetWindowPolicy() const
Returns the window policy of the camera.
Definition: camera.h:298
float GetExposure() const
Get the raw exposure exponent value.
Definition: camera.h:251
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Adapter class providing data exchange with the client scene graph.
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e....
Definition: sprim.h:35
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92