Loading...
Searching...
No Matches
camera.h
1//
2// Copyright 2017 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_IMAGING_HD_CAMERA_H
25#define PXR_IMAGING_HD_CAMERA_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hd/api.h"
29#include "pxr/imaging/hd/version.h"
30#include "pxr/imaging/hd/sprim.h"
31
32#include "pxr/imaging/cameraUtil/conformWindow.h"
33
36#include "pxr/base/gf/range1f.h"
37#include "pxr/base/gf/vec2f.h"
38
39#include <vector>
40
41PXR_NAMESPACE_OPEN_SCOPE
42
48#define HD_CAMERA_TOKENS \
49 /* frustum */ \
50 (projection) \
51 (horizontalAperture) \
52 (verticalAperture) \
53 (horizontalApertureOffset) \
54 (verticalApertureOffset) \
55 (focalLength) \
56 (clippingRange) \
57 (clipPlanes) \
58 \
59 /* depth of field */ \
60 (fStop) \
61 (focusDistance) \
62 (focusOn) \
63 (dofAspect) \
64 ((splitDiopterCount, "splitDiopter:count")) \
65 ((splitDiopterAngle, "splitDiopter:angle")) \
66 ((splitDiopterOffset1, "splitDiopter:offset1")) \
67 ((splitDiopterWidth1, "splitDiopter:width1")) \
68 ((splitDiopterFocusDistance1, "splitDiopter:focusDistance1")) \
69 ((splitDiopterOffset2, "splitDiopter:offset2")) \
70 ((splitDiopterWidth2, "splitDiopter:width2")) \
71 ((splitDiopterFocusDistance2, "splitDiopter:focusDistance2")) \
72 \
73 /* shutter/lighting */ \
74 (shutterOpen) \
75 (shutterClose) \
76 (exposure) \
77 \
78 /* how to match window with different aspect */ \
79 (windowPolicy) \
80 \
81 /* lens distortion */ \
82 (standard) \
83 (fisheye) \
84 ((lensDistortionType, "lensDistortion:type")) \
85 ((lensDistortionK1, "lensDistortion:k1")) \
86 ((lensDistortionK2, "lensDistortion:k2")) \
87 ((lensDistortionCenter, "lensDistortion:center")) \
88 ((lensDistortionAnaSq, "lensDistortion:anaSq")) \
89 ((lensDistortionAsym, "lensDistortion:asym")) \
90 ((lensDistortionScale, "lensDistortion:scale")) \
91 ((lensDistortionIor, "lensDistortion:ior"))
92
93
94TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS);
95
103class HdCamera : public HdSprim
104{
105public:
106 using ClipPlanesVector = std::vector<GfVec4d>;
107
108 HD_API
109 HdCamera(SdfPath const & id);
110 HD_API
111 ~HdCamera() override;
112
113 // change tracking for HdCamera
114 enum DirtyBits : HdDirtyBits
115 {
116 Clean = 0,
117 DirtyTransform = 1 << 0,
118 DirtyParams = 1 << 1,
119 DirtyClipPlanes = 1 << 2,
120 DirtyWindowPolicy = 1 << 3,
121 AllDirty = (DirtyTransform
122 |DirtyParams
123 |DirtyClipPlanes
124 |DirtyWindowPolicy)
125 };
126
127 enum Projection {
128 Perspective = 0,
129 Orthographic
130 };
131
132 // ---------------------------------------------------------------------- //
134 // ---------------------------------------------------------------------- //
135
137 HD_API
138 void Sync(HdSceneDelegate *sceneDelegate,
139 HdRenderParam *renderParam,
140 HdDirtyBits *dirtyBits) override;
141
142
146 HD_API
147 HdDirtyBits GetInitialDirtyBitsMask() const override;
148
149 // ---------------------------------------------------------------------- //
151 // ---------------------------------------------------------------------- //
152
154 GfMatrix4d const& GetTransform() const {
155 return _transform;
156 }
157
159 Projection GetProjection() const {
160 return _projection;
161 }
162
164 float GetHorizontalAperture() const {
165 return _horizontalAperture;
166 }
167
169 float GetVerticalAperture() const {
170 return _verticalAperture;
171 }
172
175 return _horizontalApertureOffset;
176 }
177
180 return _verticalApertureOffset;
181 }
182
184 float GetFocalLength() const {
185 return _focalLength;
186 }
187
190 return _clippingRange;
191 }
192
194 std::vector<GfVec4d> const& GetClipPlanes() const {
195 return _clipPlanes;
196 }
197
199 float GetFStop() const {
200 return _fStop;
201 }
202
204 float GetFocusDistance() const {
205 return _focusDistance;
206 }
207
208 bool GetFocusOn() const {
209 return _focusOn;
210 }
211
212 float GetDofAspect() const {
213 return _dofAspect;
214 }
215
216 int GetSplitDiopterCount() const {
217 return _splitDiopterCount;
218 }
219
220 float GetSplitDiopterAngle() const {
221 return _splitDiopterAngle;
222 }
223
224 float GetSplitDiopterOffset1() const {
225 return _splitDiopterOffset1;
226 }
227
228 float GetSplitDiopterWidth1() const {
229 return _splitDiopterWidth1;
230 }
231
232 float GetSplitDiopterFocusDistance1() const {
233 return _splitDiopterFocusDistance1;
234 }
235
236 float GetSplitDiopterOffset2() const {
237 return _splitDiopterOffset2;
238 }
239
240 float GetSplitDiopterWidth2() const {
241 return _splitDiopterWidth2;
242 }
243
244 float GetSplitDiopterFocusDistance2() const {
245 return _splitDiopterFocusDistance2;
246 }
247
248 double GetShutterOpen() const {
249 return _shutterOpen;
250 }
251
252 double GetShutterClose() const {
253 return _shutterClose;
254 }
255
256 float GetExposure() const {
257 return _exposure;
258 }
259
260 TfToken GetLensDistortionType() const {
261 return _lensDistortionType;
262 }
263
264 float GetLensDistortionK1() const {
265 return _lensDistortionK1;
266 }
267
268 float GetLensDistortionK2() const {
269 return _lensDistortionK2;
270 }
271
272 const GfVec2f& GetLensDistortionCenter() const {
273 return _lensDistortionCenter;
274 }
275
276 float GetLensDistortionAnaSq() const {
277 return _lensDistortionAnaSq;
278 }
279
280 const GfVec2f& GetLensDistortionAsym() const {
281 return _lensDistortionAsym;
282 }
283
284 float GetLensDistortionScale() const {
285 return _lensDistortionScale;
286 }
287
288 float GetLensDistortionIor() const {
289 return _lensDistortionIor;
290 }
291
294 const CameraUtilConformWindowPolicy& GetWindowPolicy() const {
295 return _windowPolicy;
296 }
297
298 // ---------------------------------------------------------------------- //
300 // ---------------------------------------------------------------------- //
301
304 HD_API
306
307protected:
308 // frustum
309 GfMatrix4d _transform;
310 Projection _projection;
311 float _horizontalAperture;
312 float _verticalAperture;
313 float _horizontalApertureOffset;
314 float _verticalApertureOffset;
315 float _focalLength;
316 GfRange1f _clippingRange;
317 std::vector<GfVec4d> _clipPlanes;
318
319 // focus
320 float _fStop;
321 float _focusDistance;
322 bool _focusOn;
323 float _dofAspect;
324 int _splitDiopterCount;
325 float _splitDiopterAngle;
326 float _splitDiopterOffset1;
327 float _splitDiopterWidth1;
328 float _splitDiopterFocusDistance1;
329 float _splitDiopterOffset2;
330 float _splitDiopterWidth2;
331 float _splitDiopterFocusDistance2;
332
333 // shutter/lighting
334 double _shutterOpen;
335 double _shutterClose;
336 float _exposure;
337
338 // lens distortion
339 TfToken _lensDistortionType;
340 float _lensDistortionK1;
341 float _lensDistortionK2;
342 GfVec2f _lensDistortionCenter;
343 float _lensDistortionAnaSq;
344 GfVec2f _lensDistortionAsym;
345 float _lensDistortionScale;
346 float _lensDistortionIor;
347
348 // Camera's opinion how it display in a window with
349 // a different aspect ratio
350 CameraUtilConformWindowPolicy _windowPolicy;
351};
352
353PXR_NAMESPACE_CLOSE_SCOPE
354
355#endif // PXR_IMAGING_HD_CAMERA_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: 1-dimensional floating point range.
Definition: range1f.h:62
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
Hydra schema for a camera that pulls the params (see above) during Sync.
Definition: camera.h:104
float GetHorizontalApertureOffset() const
Returns horizontal aperture offset in world units.
Definition: camera.h:174
float GetFocusDistance() const
Returns focus distance in world units.
Definition: camera.h:204
float GetHorizontalAperture() const
Returns horizontal aperture in world units.
Definition: camera.h:164
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Sprim API.
GfMatrix4d const & GetTransform() const
Camera parameters accessor API.
Definition: camera.h:154
std::vector< GfVec4d > const & GetClipPlanes() const
Returns any additional clipping planes defined in camera space.
Definition: camera.h:194
float GetFStop() const
Returns fstop of camera.
Definition: camera.h:199
float GetVerticalAperture() const
Returns vertical aperture in world units.
Definition: camera.h:169
float GetFocalLength() const
Returns focal length in world units.
Definition: camera.h:184
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:179
HD_API GfMatrix4d ComputeProjectionMatrix() const
Convenience API for rasterizers.
Projection GetProjection() const
Returns whether camera is orthographic and perspective.
Definition: camera.h:159
GfRange1f const & GetClippingRange() const
Returns near and far plane in world units.
Definition: camera.h:189
const CameraUtilConformWindowPolicy & GetWindowPolicy() const
Returns the window policy of the camera.
Definition: camera.h:294
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:52
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
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:98