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 2016 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 GF_CAMERA_H
25 #define GF_CAMERA_H
26 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/gf/matrix4d.h"
32 #include "pxr/base/gf/range1f.h"
33 #include "pxr/base/gf/vec4f.h"
34 #include "pxr/base/gf/api.h"
35 
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 class GfFrustum;
41 
49 class GfCamera
50 {
51 public:
53  enum Projection {
54  Perspective = 0,
55  Orthographic,
56  };
57 
59  enum FOVDirection {
60  FOVHorizontal = 0,
61  FOVVertical
62  };
63 
67  GF_API static const double APERTURE_UNIT;
69  GF_API static const double FOCAL_LENGTH_UNIT;
70 
74  GF_API static const double DEFAULT_HORIZONTAL_APERTURE;
75  GF_API static const double DEFAULT_VERTICAL_APERTURE;
76 
77 public:
78  GF_API GfCamera(
79  const GfMatrix4d &transform = GfMatrix4d(1.0),
80  Projection projection = Perspective,
81  float horizontalAperture = DEFAULT_HORIZONTAL_APERTURE,
82  float verticalAperture = DEFAULT_VERTICAL_APERTURE,
83  float horizontalApertureOffset = 0.0,
84  float verticalApertureOffset = 0.0,
85  float focalLength = 50.0,
86  const GfRange1f &clippingRange = GfRange1f(1, 1000000),
87  const std::vector<GfVec4f> &clippingPlanes = std::vector<GfVec4f>(),
88  float fStop = 0.0,
89  float focusDistance = 0.0);
90 
92  GF_API void SetTransform(const GfMatrix4d &val);
93 
95  GF_API void SetProjection(const Projection &val);
96 
98 
102 
104 
107  GF_API void SetFocalLength(const float val);
108 
111  GF_API void SetHorizontalAperture(const float val);
112 
115  GF_API void SetVerticalAperture(const float val);
116 
119  GF_API void SetHorizontalApertureOffset(const float val);
120 
123  GF_API void SetVerticalApertureOffset(const float val);
125 
128 
135 
137  float aspectRatio,
138  float fieldOfView,
139  FOVDirection direction,
140  float horizontalAperture = DEFAULT_HORIZONTAL_APERTURE);
141 
146 
148  float aspectRatio, float orthographicSize, FOVDirection direction);
149 
151 
153  GF_API void SetClippingRange(const GfRange1f &val);
154 
162  GF_API void SetClippingPlanes(const std::vector<GfVec4f> &val);
163 
165  GF_API void SetFStop(const float val);
166 
168  GF_API void SetFocusDistance(const float val);
169 
172  GF_API GfMatrix4d GetTransform() const;
173 
175  GF_API Projection GetProjection() const;
176 
179  GF_API float GetHorizontalAperture() const;
180 
183  GF_API float GetVerticalAperture() const;
184 
189  GF_API float GetHorizontalApertureOffset() const;
190 
193  GF_API float GetVerticalApertureOffset() const;
194 
196  GF_API float GetAspectRatio() const;
197 
200  GF_API float GetFocalLength() const;
201 
203  GF_API float GetFieldOfView(FOVDirection direction) const;
204 
206  GF_API GfRange1f GetClippingRange() const;
207 
209  GF_API const std::vector<GfVec4f> &GetClippingPlanes() const;
210 
213  GF_API GfFrustum GetFrustum() const;
214 
216  GF_API float GetFStop() const;
217 
219  GF_API float GetFocusDistance() const;
220 
222  GF_API bool operator==(const GfCamera& other) const;
223 
224  // Inequality operator. true iff not equality.
225  GF_API bool operator!=(const GfCamera& other) const;
226 
227 private:
228  // frustum
229  GfMatrix4d _transform;
230  Projection _projection;
231  float _horizontalAperture;
232  float _verticalAperture;
233  float _horizontalApertureOffset;
234  float _verticalApertureOffset;
235  float _focalLength;
236  GfRange1f _clippingRange;
237  std::vector<GfVec4f> _clippingPlanes;
238 
239  // focus
240  float _fStop;
241  float _focusDistance;
242 };
243 
244 PXR_NAMESPACE_CLOSE_SCOPE
245 
246 #endif // GF_CAMERA_H
GF_API const std::vector< GfVec4f > & GetClippingPlanes() const
Returns additional clipping planes.
static GF_API const double APERTURE_UNIT
The unit for horizontal and vertical aperture is one tenth of the world unit.
Definition: camera.h:67
GF_API void SetClippingPlanes(const std::vector< GfVec4f > &val)
Sets additional arbitrarily oriented clipping planes.
GF_API GfRange1f GetClippingRange() const
Returns the clipping range in world units.
GF_API GfFrustum GetFrustum() const
Returns the computed, world-space camera frustum.
Object-based representation of a camera.
Definition: camera.h:49
GF_API float GetAspectRatio() const
Returns the projector aperture aspect ratio.
GF_API float GetVerticalAperture() const
Returns the height of the projector aperture in tenths of a world unit (e.g., mm if the world unit is...
GF_API float GetHorizontalAperture() const
Returns the width of the projector aperture in tenths of a world unit (e.g., mm if the world unit is ...
GF_API void SetOrthographicFromAspectRatioAndSize(float aspectRatio, float orthographicSize, FOVDirection direction)
Sets the frustum to be orthographic such that it has the given aspectRatio and such that the orthogra...
GF_API void SetFocusDistance(const float val)
Sets the focus distance in world units.
static GF_API const double DEFAULT_HORIZONTAL_APERTURE
Default horizontal and vertical aperture, based on a 35mm (non-anamorphic) projector aperture (0...
Definition: camera.h:74
GF_API void SetProjection(const Projection &val)
Sets the projection type.
static GF_API const double FOCAL_LENGTH_UNIT
The unit for focal length. Similar to APERTURE_UNIT.
Definition: camera.h:69
GF_API void SetTransform(const GfMatrix4d &val)
Sets the transform of the filmback in world space to val.
GF_API void SetFStop(const float val)
Sets the lens aperture, unitless.
FOVDirection
Direction used for Field of View or orthographic size.
Definition: camera.h:59
GF_API float GetFStop() const
Returns the lens aperture.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: View frustum.
Definition: frustum.h:87
GF_API float GetFocalLength() const
Returns the focal length in tenths of a world unit (e.g., mm if the world unit is assumed to be cm)...
Basic type: 1-dimensional floating point range.
Definition: range1f.h:62
GF_API float GetHorizontalApertureOffset() const
Returns the horizontal offset of the projector aperture in tenths of a world unit (e...
GF_API float GetFocusDistance() const
Returns the focus distance in world units.
Projection
Projection type.
Definition: camera.h:53
GF_API void SetHorizontalApertureOffset(const float val)
Sets the horizontal offset of the projector aperture in tenths of a world unit (e.g., mm if the world unit is assumed to be cm).
GF_API void SetVerticalApertureOffset(const float val)
Sets the vertical offset of the projector aperture in tenths of a world unit (e.g., mm if the world unit is assumed to be cm).
GF_API GfMatrix4d GetTransform() const
Returns the transform of the filmback in world space.
GF_API void SetHorizontalAperture(const float val)
Sets the width of the projector aperture in tenths of a world unit (e.g., mm if the world unit is ass...
GF_API float GetFieldOfView(FOVDirection direction) const
Returns the horizontal or vertical field of view in degrees.
GF_API Projection GetProjection() const
Returns the projection type.
GF_API bool operator==(const GfCamera &other) const
Equality operator. true iff all parts match.
GF_API float GetVerticalApertureOffset() const
Returns the vertical offset of the projector aperture in tenths of a world unit (e.g., mm if the world unit is assumed to be cm).
GF_API void SetVerticalAperture(const float val)
Sets the height of the projector aperture in tenths of a world unit (e.g., mm if the world unit is as...
GF_API void SetPerspectiveFromAspectRatioAndFieldOfView(float aspectRatio, float fieldOfView, FOVDirection direction, float horizontalAperture=DEFAULT_HORIZONTAL_APERTURE)
Sets the frustum to be projective with the given aspectRatio and horizontal, respectively, vertical field of view fieldOfView (similar to gluPerspective when direction = FOVVertical).
GF_API void SetFocalLength(const float val)
These are the values actually stored in the class and they correspond to measurements of an actual ph...
GF_API void SetClippingRange(const GfRange1f &val)
Sets the clipping range in world units.