HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
framing.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_CAMERA_UTIL_FRAMING_H
8 #define PXR_IMAGING_CAMERA_UTIL_FRAMING_H
9 
10 #include "pxr/pxr.h"
12 
14 
15 #include "pxr/base/gf/rect2i.h"
16 #include "pxr/base/gf/range2f.h"
17 
19 
20 /// \class CameraUtilFraming
21 ///
22 /// Framing information. That is information determining how the filmback
23 /// plane of a camera maps to the pixels of the rendered image (displayWindow
24 /// together with pixelAspectRatio and window policy) and what pixels of the
25 /// image will be filled by the renderer (dataWindow).
26 ///
27 /// The concepts of displayWindow and dataWindow are similar to the ones in
28 /// OpenEXR, including that the x- and y-axis of the coordinate system point
29 /// right and down, respectively.
30 ///
31 /// In fact, these windows mean the same here and in OpenEXR if the
32 /// displayWindow has the same aspect ratio (when accounting for the
33 /// pixelAspectRatio) as the filmback plane of the camera (that is the
34 /// ratio of the horizontalAperture to verticalAperture of, e.g., Usd's Camera
35 /// or GfCamera).
36 ///
37 /// In particular, overscan can be achieved by making the dataWindow larger
38 /// than the displayWindow.
39 ///
40 /// If the aspect ratios differ, a window policy is applied to the
41 /// displayWindow to determine how the pixels correspond to the
42 /// filmback plane. One such window policy is to take the largest
43 /// rect that fits (centered) into the displayWindow and has the
44 /// camera's aspect ratio. For example, if the displayWindow and dataWindow
45 /// are the same and both have an aspect ratio smaller than the camera, the
46 /// image is created by enlarging the camera frustum slightly in the bottom
47 /// and top direction.
48 ///
49 /// When using the AOVs, the render buffer size is determined
50 /// independently from the framing info. However, the dataWindow is
51 /// supposed to be contained in the render buffer rect (in particular,
52 /// the dataWindow cannot contain pixels with negative coordinates -
53 /// this restriction does not apply if, e.g., hdPrman circumvents AOVs
54 /// and writes directly to EXR). In other words, unlike in OpenEXR,
55 /// the rect of pixels for which we allocate storage can differ from
56 /// the rect the renderer fills with data (dataWindow).
57 ///
58 /// For example, an application can set the render buffer size to match
59 /// the widget size but use a dataWindow and displayWindow that only fills
60 /// the render buffer horizontally to have slates at the top and bottom.
61 ///
62 class CameraUtilFraming final
63 {
64 public:
65  /// Creates an invalid framing, i.e., with empty display and data
66  /// window.
69 
70  /// Creates a framing with given display and data window and pixel
71  /// aspect ratio.
72  ///
75  const GfRange2f &displayWindow,
76  const GfRect2i &dataWindow,
77  float pixelAspectRatio = 1.0);
78 
79  /// Creates a framing with equal display and data window (and
80  /// assuming square pixels).
81  ///
83  explicit CameraUtilFraming(
84  const GfRect2i &dataWindow);
85 
86  /// Is display and data window non-empty.
88  bool IsValid() const;
89 
91  bool operator==(const CameraUtilFraming& other) const;
92 
94  bool operator!=(const CameraUtilFraming& other) const;
95 
96  /// The filmback window is the rectangle in pixel space corresponding
97  /// to the filmback plane. It is obtained by conforming the display
98  /// window using the camera's aspect ratio.
99  ///
100  /// Note that the window policy describes how the camera frustum is
101  /// modified to match the display window's aspect ratio. The filmback
102  /// window is transforming differently: if, e.g., the camera frustum's
103  /// height had to be increased to match the displayWindow's aspect ratio
104  /// (since it is less than the camera's aspect ratio and the policy is
105  /// CameraUtilFit), then the filmback window height will be less than
106  /// that of the displayWindow. In other words, imagine an application
107  /// window too tall to display the camera. We will increase the camera
108  /// frustum's height to fill the entire window. To show only what the
109  /// camera would see, we need to add slates on the bottom and top.
110  /// The filmback window is the rect cut out by the slates.
111  ///
114  float cameraAspectRatio,
115  CameraUtilConformWindowPolicy windowPolicy) const;
116 
117  /// Given the projectionMatrix computed from a camera, applies
118  /// the framing. To obtain a correct result, a rasterizer needs
119  /// to use the resulting projection matrix and set the viewport
120  /// to the data window.
121  ///
124  const GfMatrix4d &projectionMatrix,
125  CameraUtilConformWindowPolicy windowPolicy) const;
126 
127  /// The display window.
129 
130  /// The data window. That is the rect of pixels that the renderer
131  /// will fill.
133 
134  /// The ratio of the width to the height of a pixel - same as
135  /// OpenEXR.
137 };
138 
140 
141 #endif
GfRange2f displayWindow
The display window.
Definition: framing.h:128
GfRect2i dataWindow
Definition: framing.h:132
CAMERAUTIL_API GfMatrix4d ApplyToProjectionMatrix(const GfMatrix4d &projectionMatrix, CameraUtilConformWindowPolicy windowPolicy) const
CAMERAUTIL_API GfRange2f ComputeFilmbackWindow(float cameraAspectRatio, CameraUtilConformWindowPolicy windowPolicy) const
CameraUtilConformWindowPolicy
Definition: conformWindow.h:27
CAMERAUTIL_API bool operator==(const CameraUtilFraming &other) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
float pixelAspectRatio
Definition: framing.h:136
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define CAMERAUTIL_API
Definition: api.h:23
CAMERAUTIL_API bool operator!=(const CameraUtilFraming &other) const
CAMERAUTIL_API bool IsValid() const
Is display and data window non-empty.
CAMERAUTIL_API CameraUtilFraming()