HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
frameRecorder.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 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 USDAPPUTILS_FRAME_RECORDER_H
25 #define USDAPPUTILS_FRAME_RECORDER_H
26 
27 /// \file usdAppUtils/frameRecorder.h
28 
29 #include "pxr/pxr.h"
31 
32 #include "pxr/base/tf/diagnostic.h"
33 #include "pxr/base/tf/token.h"
34 #include "pxr/usd/usd/stage.h"
35 #include "pxr/usd/usd/timeCode.h"
36 #include "pxr/usd/usdGeom/camera.h"
38 
39 #include <string>
40 
41 
43 
44 
45 /// \class UsdAppUtilsFrameRecorder
46 ///
47 /// A utility class for recording images of USD stages.
48 ///
49 /// UsdAppUtilsFrameRecorder uses Hydra to produce recorded images of a USD
50 /// stage looking through a particular UsdGeomCamera on that stage at a
51 /// particular UsdTimeCode. The images generated will be effectively the same
52 /// as what you would see in the viewer in usdview.
53 ///
54 /// Note that it is assumed that an OpenGL context has already been setup.
56 {
57 public:
60 
61  /// Gets the ID of the Hydra renderer plugin that will be used for
62  /// recording.
64  return _imagingEngine.GetCurrentRendererId();
65  }
66 
67  /// Sets the Hydra renderer plugin to be used for recording.
68  bool SetRendererPlugin(const TfToken& id) {
69  return _imagingEngine.SetRendererPlugin(id);
70  }
71 
72  /// Sets the width of the recorded image.
73  ///
74  /// The height of the recorded image will be computed using this value and
75  /// the aspect ratio of the camera used for recording.
76  ///
77  /// The default image width is 960 pixels.
78  void SetImageWidth(const size_t imageWidth) {
79  if (imageWidth == 0u) {
80  TF_CODING_ERROR("Image width cannot be zero");
81  return;
82  }
83  _imageWidth = imageWidth;
84  }
85 
86  /// Sets the level of refinement complexity.
87  ///
88  /// The default complexity is "low" (1.0).
89  void SetComplexity(const float complexity) {
90  _complexity = complexity;
91  }
92 
93  /// Sets the color correction mode to be used for recording.
94  ///
95  /// By default, color correction is disabled.
96  void SetColorCorrectionMode(const TfToken& colorCorrectionMode) {
97  _colorCorrectionMode = colorCorrectionMode;
98  }
99 
100  /// Sets the UsdGeomImageable purposes to be used for rendering
101  ///
102  /// We will __always__ include "default" purpose, and by default,
103  /// we will also include UsdGeomTokens->proxy. Use this method
104  /// to explicitly enumerate an alternate set of purposes to be
105  /// included along with "default".
107  void SetIncludedPurposes(const TfTokenVector& purposes);
108 
109  /// Records an image and writes the result to \p outputImagePath.
110  ///
111  /// The recorded image will represent the view from \p usdCamera looking at
112  /// the imageable prims on USD stage \p stage at time \p timeCode.
113  ///
114  /// If \p usdCamera is not a valid camera, a camera will be computed
115  /// to automatically frame the stage geometry.
116  ///
117  /// Returns true if the image was generated and written successfully, or
118  /// false otherwise.
120  bool Record(
121  const UsdStagePtr& stage,
122  const UsdGeomCamera& usdCamera,
123  const UsdTimeCode timeCode,
124  const std::string& outputImagePath);
125 
126 private:
127  UsdImagingGLEngine _imagingEngine;
128  size_t _imageWidth;
129  float _complexity;
130  TfToken _colorCorrectionMode;
131  TfTokenVector _purposes;
132 };
133 
134 
136 
137 
138 #endif
USDIMAGINGGL_API TfToken GetCurrentRendererId() const
Return the id of the currently used renderer plugin.
USDAPPUTILS_API UsdAppUtilsFrameRecorder()
bool SetRendererPlugin(const TfToken &id)
Sets the Hydra renderer plugin to be used for recording.
Definition: frameRecorder.h:68
void SetColorCorrectionMode(const TfToken &colorCorrectionMode)
Definition: frameRecorder.h:96
#define TF_CODING_ERROR
#define USDAPPUTILS_API
Definition: api.h:40
USDIMAGINGGL_API bool SetRendererPlugin(TfToken const &id)
Definition: token.h:89
USDAPPUTILS_API bool Record(const UsdStagePtr &stage, const UsdGeomCamera &usdCamera, const UsdTimeCode timeCode, const std::string &outputImagePath)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
TfToken GetCurrentRendererId() const
Definition: frameRecorder.h:63
USDAPPUTILS_API void SetIncludedPurposes(const TfTokenVector &purposes)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
void SetImageWidth(const size_t imageWidth)
Definition: frameRecorder.h:78
void SetComplexity(const float complexity)
Definition: frameRecorder.h:89