HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
camera.h
Go to the documentation of this file.
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 
33 
35 #include "pxr/base/gf/matrix4d.h"
36 #include "pxr/base/gf/range1f.h"
37 #include "pxr/base/gf/vec2f.h"
38 
39 #include <vector>
40 
42 
43 /// Camera state that can be requested from the scene delegate via
44 /// GetCameraParamValue(id, token). The parameters below mimic the
45 /// USD camera schema and GfCamera (with the exception of window
46 /// policy). All spatial units are in world units though and
47 /// projection is HdCamera::Projection rather than a token.
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 
95 
96 /// \class HdCamera
97 ///
98 /// Hydra schema for a camera that pulls the params (see above) during
99 /// Sync.
100 /// Backends that use additional camera parameters can inherit from HdCamera and
101 /// pull on them.
102 ///
103 class HdCamera : public HdSprim
104 {
105 public:
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
115  {
116  Clean = 0,
117  DirtyTransform = 1 << 0,
118  DirtyParams = 1 << 1,
119  DirtyClipPlanes = 1 << 2,
122  |DirtyParams
125  };
126 
127  enum Projection {
130  };
131 
132  // ---------------------------------------------------------------------- //
133  /// Sprim API
134  // ---------------------------------------------------------------------- //
135 
136  /// Synchronizes state from the delegate to this object.
137  HD_API
138  void Sync(HdSceneDelegate *sceneDelegate,
139  HdRenderParam *renderParam,
140  HdDirtyBits *dirtyBits) override;
141 
142 
143  /// Returns the minimal set of dirty bits to place in the
144  /// change tracker for use in the first sync of this prim.
145  /// Typically this would be all dirty bits.
146  HD_API
147  HdDirtyBits GetInitialDirtyBitsMask() const override;
148 
149  // ---------------------------------------------------------------------- //
150  /// Camera parameters accessor API
151  // ---------------------------------------------------------------------- //
152 
153  /// Returns camera transform
154  GfMatrix4d const& GetTransform() const {
155  return _transform;
156  }
157 
158  /// Returns whether camera is orthographic and perspective
160  return _projection;
161  }
162 
163  /// Returns horizontal aperture in world units.
164  float GetHorizontalAperture() const {
165  return _horizontalAperture;
166  }
167 
168  /// Returns vertical aperture in world units.
169  float GetVerticalAperture() const {
170  return _verticalAperture;
171  }
172 
173  /// Returns horizontal aperture offset in world units.
176  }
177 
178  /// Returns vertical aperture offset in world units.
181  }
182 
183  /// Returns focal length in world units.
184  float GetFocalLength() const {
185  return _focalLength;
186  }
187 
188  /// Returns near and far plane in world units
189  GfRange1f const &GetClippingRange() const {
190  return _clippingRange;
191  }
192 
193  /// Returns any additional clipping planes defined in camera space.
194  std::vector<GfVec4d> const& GetClipPlanes() const {
195  return _clipPlanes;
196  }
197 
198  /// Returns fstop of camera
199  float GetFStop() const {
200  return _fStop;
201  }
202 
203  /// Returns focus distance in world units.
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 
234  }
235 
236  float GetSplitDiopterOffset2() const {
237  return _splitDiopterOffset2;
238  }
239 
240  float GetSplitDiopterWidth2() const {
241  return _splitDiopterWidth2;
242  }
243 
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 
261  return _lensDistortionType;
262  }
263 
264  float GetLensDistortionK1() const {
265  return _lensDistortionK1;
266  }
267 
268  float GetLensDistortionK2() const {
269  return _lensDistortionK2;
270  }
271 
273  return _lensDistortionCenter;
274  }
275 
276  float GetLensDistortionAnaSq() const {
277  return _lensDistortionAnaSq;
278  }
279 
281  return _lensDistortionAsym;
282  }
283 
284  float GetLensDistortionScale() const {
285  return _lensDistortionScale;
286  }
287 
288  float GetLensDistortionIor() const {
289  return _lensDistortionIor;
290  }
291 
292  /// Returns the window policy of the camera. If no opinion is authored, we
293  /// default to "CameraUtilFit"
295  return _windowPolicy;
296  }
297 
298  // ---------------------------------------------------------------------- //
299  /// Convenience API for rasterizers
300  // ---------------------------------------------------------------------- //
301 
302  /// Computes the projection matrix for a camera from its physical
303  /// properties.
304  HD_API
306 
307 protected:
308  // frustum
317  std::vector<GfVec4d> _clipPlanes;
318 
319  // focus
320  float _fStop;
322  bool _focusOn;
323  float _dofAspect;
332 
333  // shutter/lighting
334  double _shutterOpen;
336  float _exposure;
337 
338  // lens distortion
347 
348  // Camera's opinion how it display in a window with
349  // a different aspect ratio
351 };
352 
354 
355 #endif // PXR_IMAGING_HD_CAMERA_H
DirtyBits
Definition: camera.h:114
float _splitDiopterOffset1
Definition: camera.h:326
float GetSplitDiopterWidth2() const
Definition: camera.h:240
bool GetFocusOn() const
Definition: camera.h:208
TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS)
Projection GetProjection() const
Returns whether camera is orthographic and perspective.
Definition: camera.h:159
float _dofAspect
Definition: camera.h:323
uint32_t HdDirtyBits
Definition: types.h:158
float GetSplitDiopterWidth1() const
Definition: camera.h:228
float _lensDistortionIor
Definition: camera.h:346
float GetLensDistortionK1() const
Definition: camera.h:264
float _splitDiopterOffset2
Definition: camera.h:329
GfMatrix4d const & GetTransform() const
Camera parameters accessor API.
Definition: camera.h:154
float GetLensDistortionAnaSq() const
Definition: camera.h:276
#define HD_API
Definition: api.h:40
float _fStop
Definition: camera.h:320
float GetHorizontalApertureOffset() const
Returns horizontal aperture offset in world units.
Definition: camera.h:174
float GetSplitDiopterFocusDistance1() const
Definition: camera.h:232
double GetShutterClose() const
Definition: camera.h:252
Projection
Definition: camera.h:127
GfVec2f _lensDistortionCenter
Definition: camera.h:342
GfRange1f _clippingRange
Definition: camera.h:316
float GetFocusDistance() const
Returns focus distance in world units.
Definition: camera.h:204
float _horizontalAperture
Definition: camera.h:311
float GetSplitDiopterOffset1() const
Definition: camera.h:224
double _shutterOpen
Definition: camera.h:334
GfVec2f _lensDistortionAsym
Definition: camera.h:344
CameraUtilConformWindowPolicy _windowPolicy
Definition: camera.h:350
const GfVec2f & GetLensDistortionCenter() const
Definition: camera.h:272
float _lensDistortionScale
Definition: camera.h:345
float GetDofAspect() const
Definition: camera.h:212
float GetSplitDiopterOffset2() const
Definition: camera.h:236
float _exposure
Definition: camera.h:336
float GetVerticalAperture() const
Returns vertical aperture in world units.
Definition: camera.h:169
Definition: token.h:87
GfRange1f const & GetClippingRange() const
Returns near and far plane in world units.
Definition: camera.h:189
std::vector< GfVec4d > _clipPlanes
Definition: camera.h:317
float GetExposure() const
Definition: camera.h:256
float GetFocalLength() const
Returns focal length in world units.
Definition: camera.h:184
TfToken _lensDistortionType
Definition: camera.h:339
Projection _projection
Definition: camera.h:310
GfMatrix4d _transform
Definition: camera.h:309
int _splitDiopterCount
Definition: camera.h:324
float GetHorizontalAperture() const
Returns horizontal aperture in world units.
Definition: camera.h:164
float _verticalApertureOffset
Definition: camera.h:314
float GetSplitDiopterAngle() const
Definition: camera.h:220
TfToken GetLensDistortionType() const
Definition: camera.h:260
float _lensDistortionAnaSq
Definition: camera.h:343
Definition: path.h:291
float _lensDistortionK1
Definition: camera.h:340
CameraUtilConformWindowPolicy
Definition: conformWindow.h:44
Definition: sprim.h:51
HD_API HdCamera(SdfPath const &id)
double GetShutterOpen() const
Definition: camera.h:248
const GfVec2f & GetLensDistortionAsym() const
Definition: camera.h:280
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
HD_API HdDirtyBits GetInitialDirtyBitsMask() const override
float GetLensDistortionScale() const
Definition: camera.h:284
const CameraUtilConformWindowPolicy & GetWindowPolicy() const
Definition: camera.h:294
float _splitDiopterWidth2
Definition: camera.h:330
Definition: vec2f.h:62
HD_API GfMatrix4d ComputeProjectionMatrix() const
Convenience API for rasterizers.
float _verticalAperture
Definition: camera.h:312
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
float _splitDiopterFocusDistance2
Definition: camera.h:331
float _horizontalApertureOffset
Definition: camera.h:313
std::vector< GfVec4d > ClipPlanesVector
Definition: camera.h:106
std::vector< GfVec4d > const & GetClipPlanes() const
Returns any additional clipping planes defined in camera space.
Definition: camera.h:194
int GetSplitDiopterCount() const
Definition: camera.h:216
#define HD_CAMERA_TOKENS
Definition: camera.h:48
float GetVerticalApertureOffset() const
Returns vertical aperture offset in world units.
Definition: camera.h:179
bool _focusOn
Definition: camera.h:322
HD_API ~HdCamera() override
float GetSplitDiopterFocusDistance2() const
Definition: camera.h:244
float _focalLength
Definition: camera.h:315
float _focusDistance
Definition: camera.h:321
float _lensDistortionK2
Definition: camera.h:341
double _shutterClose
Definition: camera.h:335
float _splitDiopterAngle
Definition: camera.h:325
float GetFStop() const
Returns fstop of camera.
Definition: camera.h:199
float _splitDiopterWidth1
Definition: camera.h:327
float GetLensDistortionIor() const
Definition: camera.h:288
float _splitDiopterFocusDistance1
Definition: camera.h:328
float GetLensDistortionK2() const
Definition: camera.h:268
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Sprim API.