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 
34 #include "pxr/usd/sdf/path.h"
36 #include "pxr/base/gf/matrix4d.h"
37 #include "pxr/base/gf/range1f.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  \
63  /* shutter/lighting */ \
64  (shutterOpen) \
65  (shutterClose) \
66  (exposure) \
67  \
68  /* how to match window with different aspect */ \
69  (windowPolicy) \
70  \
71  /* OpenGL-style matrices, deprecated */ \
72  (worldToViewMatrix) \
73  (projectionMatrix)
74 
75 
77 
78 /// \class HdCamera
79 ///
80 /// Hydra schema for a camera that pulls the params (see above) during
81 /// Sync.
82 /// Backends that use additional camera parameters can inherit from HdCamera and
83 /// pull on them.
84 ///
85 class HdCamera : public HdSprim
86 {
87 public:
88  using ClipPlanesVector = std::vector<GfVec4d>;
89 
90  HD_API
91  HdCamera(SdfPath const & id);
92  HD_API
93  ~HdCamera() override;
94 
95  // change tracking for HdCamera
97  {
98  Clean = 0,
99  DirtyTransform = 1 << 0,
101  DirtyProjMatrix = 1 << 1, // deprecated
103  DirtyClipPlanes = 1 << 3,
104  DirtyParams = 1 << 4,
109  |DirtyParams)
110  };
111 
112  enum Projection {
115  };
116 
117  // ---------------------------------------------------------------------- //
118  /// Sprim API
119  // ---------------------------------------------------------------------- //
120 
121  /// Synchronizes state from the delegate to this object.
122  HD_API
123  void Sync(HdSceneDelegate *sceneDelegate,
124  HdRenderParam *renderParam,
125  HdDirtyBits *dirtyBits) override;
126 
127 
128  /// Returns the minimal set of dirty bits to place in the
129  /// change tracker for use in the first sync of this prim.
130  /// Typically this would be all dirty bits.
131  HD_API
132  HdDirtyBits GetInitialDirtyBitsMask() const override;
133 
134  // ---------------------------------------------------------------------- //
135  /// Camera parameters accessor API
136  // ---------------------------------------------------------------------- //
137 
138  /// Returns camera transform
139  GfMatrix4d const& GetTransform() const {
140  return _transform;
141  }
142 
143  /// Returns whether camera is orthographic and perspective
145  return _projection;
146  }
147 
148  /// Returns horizontal aperture in world units.
149  float GetHorizontalAperture() const {
150  return _horizontalAperture;
151  }
152 
153  /// Returns vertical aperture in world units.
154  float GetVerticalAperture() const {
155  return _verticalAperture;
156  }
157 
158  /// Returns horizontal aperture offset in world units.
161  }
162 
163  /// Returns vertical aperture offset in world units.
166  }
167 
168  /// Returns focal length in world units.
169  float GetFocalLength() const {
170  return _focalLength;
171  }
172 
173  /// Returns near and far plane in world units
174  GfRange1f const &GetClippingRange() const {
175  return _clippingRange;
176  }
177 
178  /// Returns any additional clipping planes defined in camera space.
179  std::vector<GfVec4d> const& GetClipPlanes() const {
180  return _clipPlanes;
181  }
182 
183  /// Returns fstop of camera
184  float GetFStop() const {
185  return _fStop;
186  }
187 
188  /// Returns focus distance in world units.
189  float GetFocusDistance() const {
190  return _focusDistance;
191  }
192 
193  double GetShutterOpen() const {
194  return _shutterOpen;
195  }
196 
197  double GetShutterClose() const {
198  return _shutterClose;
199  }
200 
201  float GetExposure() const {
202  return _exposure;
203  }
204 
205  /// Returns the window policy of the camera. If no opinion is authored, we
206  /// default to "CameraUtilFit"
208  return _windowPolicy;
209  }
210 
211  // ---------------------------------------------------------------------- //
212  /// Legacy camera parameters accessor API
213  // ---------------------------------------------------------------------- //
214 
215  /// Returns the matrix transformation from world to camera space.
216  /// \deprecated Use GetTransform instead
217  HD_API
218  GfMatrix4d GetViewMatrix() const;
219 
220  /// Returns the matrix transformation from camera to world space.
221  /// \deprecated Use GetTransform and invert instead
222  HD_API
224 
225  /// Returns the projection matrix for the camera.
226  /// \deprecated Compute from above physically based attributes
227  HD_API
229 
230 protected:
231  // frustum
240  std::vector<GfVec4d> _clipPlanes;
241 
242  // focus
243  float _fStop;
245 
246  // shutter/lighting
247  double _shutterOpen;
249  float _exposure;
250 
251  // Camera's opinion how it display in a window with
252  // a different aspect ratio
254 
255  // OpenGL-style matrices
259 };
260 
262 
263 #endif // PXR_IMAGING_HD_CAMERA_H
DirtyBits
Definition: camera.h:96
TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS)
Projection GetProjection() const
Returns whether camera is orthographic and perspective.
Definition: camera.h:144
uint32_t HdDirtyBits
Definition: types.h:127
GfMatrix4d const & GetTransform() const
Camera parameters accessor API.
Definition: camera.h:139
#define HD_API
Definition: api.h:40
float _fStop
Definition: camera.h:243
float GetHorizontalApertureOffset() const
Returns horizontal aperture offset in world units.
Definition: camera.h:159
HD_API GfMatrix4d GetProjectionMatrix() const
double GetShutterClose() const
Definition: camera.h:197
Projection
Definition: camera.h:112
GfRange1f _clippingRange
Definition: camera.h:239
float GetFocusDistance() const
Returns focus distance in world units.
Definition: camera.h:189
float _horizontalAperture
Definition: camera.h:234
double _shutterOpen
Definition: camera.h:247
CameraUtilConformWindowPolicy _windowPolicy
Definition: camera.h:253
GfMatrix4d _worldToViewInverseMatrix
Definition: camera.h:257
float _exposure
Definition: camera.h:249
float GetVerticalAperture() const
Returns vertical aperture in world units.
Definition: camera.h:154
GfRange1f const & GetClippingRange() const
Returns near and far plane in world units.
Definition: camera.h:174
std::vector< GfVec4d > _clipPlanes
Definition: camera.h:240
HD_API GfMatrix4d GetViewMatrix() const
Legacy camera parameters accessor API.
float GetExposure() const
Definition: camera.h:201
float GetFocalLength() const
Returns focal length in world units.
Definition: camera.h:169
Projection _projection
Definition: camera.h:233
GfMatrix4d _projectionMatrix
Definition: camera.h:258
GfMatrix4d _transform
Definition: camera.h:232
float GetHorizontalAperture() const
Returns horizontal aperture in world units.
Definition: camera.h:149
float _verticalApertureOffset
Definition: camera.h:237
Definition: path.h:288
HD_API GfMatrix4d GetViewInverseMatrix() const
CameraUtilConformWindowPolicy
Definition: conformWindow.h:44
Definition: sprim.h:52
HD_API HdCamera(SdfPath const &id)
double GetShutterOpen() const
Definition: camera.h:193
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
HD_API HdDirtyBits GetInitialDirtyBitsMask() const override
float _verticalAperture
Definition: camera.h:235
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
float _horizontalApertureOffset
Definition: camera.h:236
std::vector< GfVec4d > ClipPlanesVector
Definition: camera.h:88
std::vector< GfVec4d > const & GetClipPlanes() const
Returns any additional clipping planes defined in camera space.
Definition: camera.h:179
#define HD_CAMERA_TOKENS
Definition: camera.h:48
float GetVerticalApertureOffset() const
Returns vertical aperture offset in world units.
Definition: camera.h:164
HD_API ~HdCamera() override
float _focalLength
Definition: camera.h:238
float _focusDistance
Definition: camera.h:244
GfMatrix4d _worldToViewMatrix
Definition: camera.h:256
double _shutterClose
Definition: camera.h:248
float GetFStop() const
Returns fstop of camera.
Definition: camera.h:184
CameraUtilConformWindowPolicy const & GetWindowPolicy() const
Definition: camera.h:207
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Sprim API.