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 
35 #include "pxr/base/gf/matrix4d.h"
36 #include "pxr/base/gf/range1f.h"
37 
38 #include <vector>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
47 #define HD_CAMERA_TOKENS \
48  /* frustum */ \
49  (projection) \
50  (horizontalAperture) \
51  (verticalAperture) \
52  (horizontalApertureOffset) \
53  (verticalApertureOffset) \
54  (focalLength) \
55  (clippingRange) \
56  (clipPlanes) \
57  \
58  /* depth of field */ \
59  (fStop) \
60  (focusDistance) \
61  \
62  /* shutter/lighting */ \
63  (shutterOpen) \
64  (shutterClose) \
65  (exposure) \
66  \
67  /* how to match window with different aspect */ \
68  (windowPolicy)
69 
70 TF_DECLARE_PUBLIC_TOKENS(HdCameraTokens, HD_API, HD_CAMERA_TOKENS);
71 
79 class HdCamera : public HdSprim
80 {
81 public:
82  using ClipPlanesVector = std::vector<GfVec4d>;
83 
84  HD_API
85  HdCamera(SdfPath const & id);
86  HD_API
87  ~HdCamera() override;
88 
89  // change tracking for HdCamera
90  enum DirtyBits : HdDirtyBits
91  {
92  Clean = 0,
93  DirtyTransform = 1 << 0,
94  DirtyParams = 1 << 1,
95  DirtyClipPlanes = 1 << 2,
96  DirtyWindowPolicy = 1 << 3,
97  AllDirty = (DirtyTransform
98  |DirtyParams
99  |DirtyClipPlanes
100  |DirtyWindowPolicy)
101  };
102 
103  enum Projection {
104  Perspective = 0,
105  Orthographic
106  };
107 
108  // ---------------------------------------------------------------------- //
110  // ---------------------------------------------------------------------- //
111 
113  HD_API
114  void Sync(HdSceneDelegate *sceneDelegate,
115  HdRenderParam *renderParam,
116  HdDirtyBits *dirtyBits) override;
117 
118 
122  HD_API
123  HdDirtyBits GetInitialDirtyBitsMask() const override;
124 
125  // ---------------------------------------------------------------------- //
127  // ---------------------------------------------------------------------- //
128 
130  GfMatrix4d const& GetTransform() const {
131  return _transform;
132  }
133 
135  Projection GetProjection() const {
136  return _projection;
137  }
138 
140  float GetHorizontalAperture() const {
141  return _horizontalAperture;
142  }
143 
145  float GetVerticalAperture() const {
146  return _verticalAperture;
147  }
148 
151  return _horizontalApertureOffset;
152  }
153 
156  return _verticalApertureOffset;
157  }
158 
160  float GetFocalLength() const {
161  return _focalLength;
162  }
163 
165  GfRange1f const &GetClippingRange() const {
166  return _clippingRange;
167  }
168 
170  std::vector<GfVec4d> const& GetClipPlanes() const {
171  return _clipPlanes;
172  }
173 
175  float GetFStop() const {
176  return _fStop;
177  }
178 
180  float GetFocusDistance() const {
181  return _focusDistance;
182  }
183 
184  double GetShutterOpen() const {
185  return _shutterOpen;
186  }
187 
188  double GetShutterClose() const {
189  return _shutterClose;
190  }
191 
192  float GetExposure() const {
193  return _exposure;
194  }
195 
198  CameraUtilConformWindowPolicy const& GetWindowPolicy() const {
199  return _windowPolicy;
200  }
201 
202  // ---------------------------------------------------------------------- //
204  // ---------------------------------------------------------------------- //
205 
208  HD_API
210 
211 protected:
212  // frustum
213  GfMatrix4d _transform;
214  Projection _projection;
215  float _horizontalAperture;
216  float _verticalAperture;
217  float _horizontalApertureOffset;
218  float _verticalApertureOffset;
219  float _focalLength;
220  GfRange1f _clippingRange;
221  std::vector<GfVec4d> _clipPlanes;
222 
223  // focus
224  float _fStop;
225  float _focusDistance;
226 
227  // shutter/lighting
228  double _shutterOpen;
229  double _shutterClose;
230  float _exposure;
231 
232  // Camera's opinion how it display in a window with
233  // a different aspect ratio
234  CameraUtilConformWindowPolicy _windowPolicy;
235 };
236 
237 PXR_NAMESPACE_CLOSE_SCOPE
238 
239 #endif // PXR_IMAGING_HD_CAMERA_H
std::vector< GfVec4d > const & GetClipPlanes() const
Returns any additional clipping planes defined in camera space.
Definition: camera.h:170
GfRange1f const & GetClippingRange() const
Returns near and far plane in world units.
Definition: camera.h:165
Hydra schema for a camera that pulls the params (see above) during Sync.
Definition: camera.h:79
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
float GetFocalLength() const
Returns focal length in world units.
Definition: camera.h:160
float GetVerticalApertureOffset() const
Returns vertical aperture offset in world units.
Definition: camera.h:155
HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
Sprim API.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Adapter class providing data exchange with the client scene graph.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
float GetVerticalAperture() const
Returns vertical aperture in world units.
Definition: camera.h:145
Projection GetProjection() const
Returns whether camera is orthographic and perspective.
Definition: camera.h:135
Basic type: 1-dimensional floating point range.
Definition: range1f.h:62
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
CameraUtilConformWindowPolicy const & GetWindowPolicy() const
Returns the window policy of the camera.
Definition: camera.h:198
float GetFocusDistance() const
Returns focus distance in world units.
Definition: camera.h:180
Sprim (state prim) is a base class of managing state for non-drawable scene entity (e....
Definition: sprim.h:51
HD_API GfMatrix4d ComputeProjectionMatrix() const
Convenience API for rasterizers.
float GetHorizontalAperture() const
Returns horizontal aperture in world units.
Definition: camera.h:140
This file defines some macros that are useful for declaring and using static TfTokens.
GfMatrix4d const & GetTransform() const
Camera parameters accessor API.
Definition: camera.h:130
float GetFStop() const
Returns fstop of camera.
Definition: camera.h:175
float GetHorizontalApertureOffset() const
Returns horizontal aperture offset in world units.
Definition: camera.h:150
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...