This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 \
61 /* how to match window with different aspect */ \
62 (windowPolicy) \
63 \
64 /* lens distortion */ \
65 (standard) \
66 (fisheye) \
67 ((lensDistortionType, "lensDistortion:type")) \
68 ((lensDistortionK1, "lensDistortion:k1")) \
69 ((lensDistortionK2, "lensDistortion:k2")) \
70 ((lensDistortionCenter, "lensDistortion:center")) \
71 ((lensDistortionAnaSq, "lensDistortion:anaSq")) \
72 ((lensDistortionAsym, "lensDistortion:asym")) \
73 ((lensDistortionScale, "lensDistortion:scale")) \
74 ((lensDistortionIor, "lensDistortion:ior"))
75
76
77TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS);
78
86class HdCamera : public HdSprim
87{
88public:
89 using ClipPlanesVector = std::vector<GfVec4d>;
90
91 HD_API
92 HdCamera(SdfPath const & id);
93 HD_API
94 ~HdCamera() override;
95
96 // change tracking for HdCamera
97 enum DirtyBits : HdDirtyBits
98 {
99 Clean = 0,
100 DirtyTransform = 1 << 0,
101 DirtyParams = 1 << 1,
102 DirtyClipPlanes = 1 << 2,
103 DirtyWindowPolicy = 1 << 3,
104 AllDirty = (DirtyTransform
105 |DirtyParams
106 |DirtyClipPlanes
107 |DirtyWindowPolicy)
108 };
109
110 enum Projection {
111 Perspective = 0,
112 Orthographic
113 };
114
115 // ---------------------------------------------------------------------- //
117 // ---------------------------------------------------------------------- //
118
120 HD_API
121 void Sync(HdSceneDelegate *sceneDelegate,
122 HdRenderParam *renderParam,
123 HdDirtyBits *dirtyBits) override;
124
125
129 HD_API
130 HdDirtyBits GetInitialDirtyBitsMask() const override;
131
132 // ---------------------------------------------------------------------- //
134 // ---------------------------------------------------------------------- //
135
137 GfMatrix4d const& GetTransform() const {
138 return _transform;
139 }
140
142 Projection GetProjection() const {
143 return _projection;
144 }
145
147 float GetHorizontalAperture() const {
148 return _horizontalAperture;
149 }
150
152 float GetVerticalAperture() const {
153 return _verticalAperture;
154 }
155
158 return _horizontalApertureOffset;
159 }
160
163 return _verticalApertureOffset;
164 }
165
167 float GetFocalLength() const {
168 return _focalLength;
169 }
170
173 return _clippingRange;
174 }
175
177 std::vector<GfVec4d> const& GetClipPlanes() const {
178 return _clipPlanes;
179 }
180
182 float GetFStop() const {
183 return _fStop;
184 }
185
187 float GetFocusDistance() const {
188 return _focusDistance;
189 }
190
191 bool GetFocusOn() const {
192 return _focusOn;
193 }
194
195 float GetDofAspect() const {
196 return _dofAspect;
197 }
198
199 int GetSplitDiopterCount() const {
200 return _splitDiopterCount;
201 }
202
203 float GetSplitDiopterAngle() const {
204 return _splitDiopterAngle;
205 }
206
207 float GetSplitDiopterOffset1() const {
208 return _splitDiopterOffset1;
209 }
210
211 float GetSplitDiopterWidth1() const {
212 return _splitDiopterWidth1;
213 }
214
215 float GetSplitDiopterFocusDistance1() const {
216 return _splitDiopterFocusDistance1;
217 }
218
219 float GetSplitDiopterOffset2() const {
220 return _splitDiopterOffset2;
221 }
222
223 float GetSplitDiopterWidth2() const {
224 return _splitDiopterWidth2;
225 }
226
227 float GetSplitDiopterFocusDistance2() const {
228 return _splitDiopterFocusDistance2;
229 }
230
231 double GetShutterOpen() const {
232 return _shutterOpen;
233 }
234
235 double GetShutterClose() const {
236 return _shutterClose;
237 }
238
239 float GetExposure() const {
240 return _exposure;
241 }
242
243 TfToken GetLensDistortionType() const {
244 return _lensDistortionType;
245 }
246
247 float GetLensDistortionK1() const {
248 return _lensDistortionK1;
249 }
250
251 float GetLensDistortionK2() const {
252 return _lensDistortionK2;
253 }
254
255 const GfVec2f& GetLensDistortionCenter() const {
256 return _lensDistortionCenter;
257 }
258
259 float GetLensDistortionAnaSq() const {
260 return _lensDistortionAnaSq;
261 }
262
263 const GfVec2f& GetLensDistortionAsym() const {
264 return _lensDistortionAsym;
265 }
266
267 float GetLensDistortionScale() const {
268 return _lensDistortionScale;
269 }
270
271 float GetLensDistortionIor() const {
272 return _lensDistortionIor;
273 }
274
277 const CameraUtilConformWindowPolicy& GetWindowPolicy() const {
278 return _windowPolicy;
279 }
280
281 // ---------------------------------------------------------------------- //
283 // ---------------------------------------------------------------------- //
284
287 HD_API
289
290protected:
291 // frustum
292 GfMatrix4d _transform;
293 Projection _projection;
294 float _horizontalAperture;
295 float _verticalAperture;
296 float _horizontalApertureOffset;
297 float _verticalApertureOffset;
298 float _focalLength;
299 GfRange1f _clippingRange;
300 std::vector<GfVec4d> _clipPlanes;
301
302 // focus
303 float _fStop;
304 float _focusDistance;
305 bool _focusOn;
306 float _dofAspect;
307 int _splitDiopterCount;
308 float _splitDiopterAngle;
309 float _splitDiopterOffset1;
310 float _splitDiopterWidth1;
311 float _splitDiopterFocusDistance1;
312 float _splitDiopterOffset2;
313 float _splitDiopterWidth2;
314 float _splitDiopterFocusDistance2;
315
316 // shutter/lighting
317 double _shutterOpen;
318 double _shutterClose;
319 float _exposure;
320
321 // lens distortion
322 TfToken _lensDistortionType;
323 float _lensDistortionK1;
324 float _lensDistortionK2;
325 GfVec2f _lensDistortionCenter;
326 float _lensDistortionAnaSq;
327 GfVec2f _lensDistortionAsym;
328 float _lensDistortionScale;
329 float _lensDistortionIor;
330
331 // Camera's opinion how it display in a window with
332 // a different aspect ratio
333 CameraUtilConformWindowPolicy _windowPolicy;
334};
335
336PXR_NAMESPACE_CLOSE_SCOPE
337
338#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:87
float GetHorizontalApertureOffset() const
Returns horizontal aperture offset in world units.
Definition: camera.h:157
float GetFocusDistance() const
Returns focus distance in world units.
Definition: camera.h:187
float GetHorizontalAperture() const
Returns horizontal aperture in world units.
Definition: camera.h:147
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Sprim API.
GfMatrix4d const & GetTransform() const
Camera parameters accessor API.
Definition: camera.h:137
std::vector< GfVec4d > const & GetClipPlanes() const
Returns any additional clipping planes defined in camera space.
Definition: camera.h:177
float GetFStop() const
Returns fstop of camera.
Definition: camera.h:182
float GetVerticalAperture() const
Returns vertical aperture in world units.
Definition: camera.h:152
float GetFocalLength() const
Returns focal length in world units.
Definition: camera.h:167
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:162
HD_API GfMatrix4d ComputeProjectionMatrix() const
Convenience API for rasterizers.
Projection GetProjection() const
Returns whether camera is orthographic and perspective.
Definition: camera.h:142
GfRange1f const & GetClippingRange() const
Returns near and far plane in world units.
Definition: camera.h:172
const CameraUtilConformWindowPolicy & GetWindowPolicy() const
Returns the window policy of the camera.
Definition: camera.h:277
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:81