HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XUSD_RenderSettings.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * NAME: XUSD_RenderSettings.h (karma Library, C++)
17  *
18  * COMMENTS:
19  */
20 
21 #ifndef __XUSD_RenderSettings__
22 #define __XUSD_RenderSettings__
23 
24 #include "HUSD_API.h"
25 #include <PXL/PXL_Common.h>
26 #include <UT/UT_UniquePtr.h>
27 #include <UT/UT_Rect.h>
28 #include <UT/UT_NonCopyable.h>
29 #include <UT/UT_StringArray.h>
30 #include <pxr/pxr.h>
31 #include <pxr/imaging/hd/aov.h>
33 #include <pxr/usd/usdRender/var.h>
36 
37 class UT_JSONWriter;
38 
40 
42 
44  : public UT_NonCopyable
45 {
46 public:
48  virtual ~XUSD_RenderSettingsContext();
49 
50  /// Update any settings from the render settings primitive. This allows
51  /// the context to look at custom attributes on the RenderSettings.
52  ///
53  /// This function will always be called - even if there are no settings.
54  virtual void initFromUSD(UsdRenderSettings &settings) { }
55 
56  /// Return the name of the render delegate
57  virtual TfToken renderer() const = 0;
58 
59  /// Override the path to the camera
60  virtual SdfPath overrideCamera() const
61  {
62  return SdfPath();
63  }
64 
65  /// Return the default resolution for rendering products
66  virtual GfVec2i defaultResolution() const = 0;
67 
68  /// Optionally override the resolution of the product
69  virtual GfVec2i overrideResolution(const GfVec2i &res) const
70  {
71  return res;
72  }
73 
74  /// Optionally, override the pixel aspect ratio.
75  virtual fpreal overridePixelAspect(fpreal pa) const { return pa; }
76 
77  /// Return if there's an overridden purpose for the render
78  virtual const char *overridePurpose() const { return nullptr; }
79 
80  /// Return the default purpose (this is a comma separated list)
81  virtual const char *defaultPurpose() const
82  {
83  const char *p = overridePurpose();
84  if (!p)
85  p = "geometry,render";
86  return p;
87  }
88 
89  /// Start frame for a render sequence
90  virtual fpreal startFrame() const = 0;
91 
92  /// Frame increment, when computing sequences
93  virtual fpreal frameInc() const { return 1; }
94 
95  /// Return the number of frames being rendered
96  virtual int frameCount() const { return 1; }
97 
98  /// Start frame for a render sequence
99  virtual UsdTimeCode evalTime() const = 0;
100 
101  /// Get a default rendering descriptor for a given AOV
102  virtual HdAovDescriptor defaultAovDescriptor(const TfToken &aov) const
103  {
104  return HdAovDescriptor();
105  }
106 
107  /// Default product name
108  virtual const char *defaultProductName() const { return nullptr; }
109 
110  /// Return a product name override
111  virtual const char *overrideProductName() const { return nullptr; }
112 
113  /// Build initial render settings map
114  virtual void setDefaultSettings(const XUSD_RenderSettings &rset,
115  HdRenderSettingsMap &settings) const
116  { }
117 
118  /// After the products have been loaded, apply any overrides
119  virtual void overrideSettings(const XUSD_RenderSettings &rset,
120  HdRenderSettingsMap &settings) const
121  { }
122 
123  /// Allow render options to be applied without a camera present.
124  virtual bool allowCameraless() const { return false; }
125 };
126 
128  : public UT_NonCopyable
129 {
130 public:
131  XUSD_RenderVar();
132  virtual ~XUSD_RenderVar();
133 
134  bool loadFrom(const UsdRenderVar &prim,
135  const XUSD_RenderSettingsContext &ctx);
136  bool resolveFrom(const UsdRenderVar &prim,
137  const XUSD_RenderSettingsContext &ctx);
138  bool buildDefault(const XUSD_RenderSettingsContext &ctx);
139 
140  const std::string &aovName() const { return myAovName; }
141  const TfToken &aovToken() const { return myAovToken; }
142  const TfToken &dataType() const;
143  const std::string &sourceName() const;
144  const TfToken &sourceType() const;
145 
146  const HdAovDescriptor &desc() const { return myHdDesc; }
147  PXL_DataFormat pxlFormat() const { return myDataFormat; }
148  PXL_Packing pxlPacking() const { return myPacking; }
149 
150  /// Print out the settings
151  void dump(UT_JSONWriter &w) const;
152 
153 protected:
159 };
160 
162  : public UT_NonCopyable
163 {
164 public:
167 
169  virtual ~XUSD_RenderProduct();
170 
171  bool loadFrom(const UsdStageRefPtr &usd,
172  const UsdRenderProduct &prim,
173  const XUSD_RenderSettingsContext &ctx);
174  bool resolveFrom(const UsdStageRefPtr &usd,
175  const UsdRenderProduct &prim,
176  const XUSD_RenderSettingsContext &ctx);
177  bool buildDefault(const XUSD_RenderSettingsContext &ctx);
178 
179  const TfToken &productType() const;
180  const TfToken &productName() const;
181 
182  // Current output filename (with all variables expanded)
183  const UT_StringHolder &outputName() const { return myFilename; }
184 
185  const RenderVarList &vars() const { return myVars; }
186 
187  const_iterator begin() const { return myVars.begin(); }
188  const_iterator end() const { return myVars.end(); }
189 
190  /// Expand product name variables. Returns false if there are multiple
191  /// frames, but no frame expansion.
192  bool expandProduct(
193  const XUSD_RenderSettingsContext &opts,
194  int frame);
195  bool collectAovs(TfTokenVector &aovs,
196  HdAovDescriptorList &descs) const;
197 
198  /// User settings for this product
199  const HdAovSettingsMap &settings() const { return mySettings; }
200 
201  /// Print out the settings
202  void dump(UT_JSONWriter &w) const;
203 
204 protected:
205  /// If you have a sub-class of XUSD_RenderVar, you can create it here
207  {
208  return UTmakeUnique<XUSD_RenderVar>();
209  }
210 
211  // Member data
216 };
217 
218 /// XUSD_RenderSettings contains the HdRenderSettings for the render
220  : public UT_NonCopyable
221 {
222 public:
225 
227  virtual ~XUSD_RenderSettings();
228 
229  static void findCameras(UT_Array<SdfPath> &list, UsdPrim prim);
230 
231  /// Since the settings primitive may specify values used by the render
232  /// settings context (like frame count, etc.) we pass in a
233  /// non-const @c context so the initialization process so we can call
234  /// initFromUSD() once we've found the render settings.
235  bool init(const UsdStageRefPtr &usd,
236  const SdfPath &settings_path,
238 
239  /// Resolve products/vars
240  bool resolveProducts(const UsdStageRefPtr &usd,
241  const XUSD_RenderSettingsContext &ctx);
242 
243  /// Get the render settings
244  UsdPrim prim() const { return myUsdSettings.GetPrim(); }
245 
246  /// Rendering head
247  const TfToken &renderer() const { return myRenderer; }
248 
249  /// Properties from the render settings
250  const SdfPath &cameraPath() const { return myCameraPath; }
251  double shutterOpen() const { return myShutter[0]; }
252  double shutterClose() const { return myShutter[1]; }
253  int xres() const { return myRes[0]; }
254  int yres() const { return myRes[1]; }
255  const GfVec2i &res() const { return myRes; }
256  float pixelAspect() const { return myPixelAspect; }
257  const GfVec4f &dataWindowF() const { return myDataWindowF; }
258  const VtArray<TfToken> &purpose() const { return myPurpose; }
259 
260  const UT_DimRect &dataWindow() const { return myDataWindow; }
261 
262  UT_StringHolder outputName() const;
263 
264  const HdRenderSettingsMap &renderSettings() const { return mySettings; }
265 
266  /// @{
267  /// Render Products
268  const ProductList &products() const { return myProducts; }
269  const_iterator begin() const { return myProducts.begin(); }
270  const_iterator end() const { return myProducts.end(); }
271  /// @}
272 
273  /// Expand product name variables
274  bool expandProducts(const XUSD_RenderSettingsContext &ctx,
275  int frame);
276 
277  /// Print out the settings to UT_ErrorLog
278  void printSettings() const;
279  void dump(UT_JSONWriter &w) const;
280 
281  bool collectAovs(TfTokenVector &aovs,
282  HdAovDescriptorList &descs) const;
283 
285  {
286  INVALID = -1,
287  EXPAND_APERTURE,
288  CROP_APERTURE,
289  ADJUST_HAPERTURE,
290  ADJUST_VAPERTURE,
291  ADJUST_PIXEL_ASPECT,
292  DEFAULT = EXPAND_APERTURE
293  };
294  static HUSD_AspectConformPolicy conformPolicy(const TfToken &t);
295  static TfToken conformPolicy(HUSD_AspectConformPolicy policy);
296 
297  /// When the camera aspect ratio doesn't match the image aspect ratio, USD
298  /// specifies five different approatches to resolving this difference.
299  /// HoudiniGL and Karma only use the vertical aperture and thus have a
300  /// fixed way to resolve aspect ratio differences. This method will adjust
301  /// the vertical aspect or pixel aspect ratio to fit with the five
302  /// different methods described in USD. The method returns true if values
303  /// were changed. The method is templated on single/double precision
304  template <typename T>
305  static bool aspectConform(HUSD_AspectConformPolicy conform,
306  T &vaperture, T &pixel_aspect,
307  T cam_aspect, T img_aspect);
308 
309  /// This method assumes you have render settings defined
310  template <typename T>
311  bool aspectConform(const XUSD_RenderSettingsContext &ctx,
312  T &vaperture, T &pixel_aspect,
313  T cam_aspect, T img_aspect) const;
314 
315  HUSD_AspectConformPolicy conformPolicy(
316  const XUSD_RenderSettingsContext &c) const;
317 
318 protected:
320  {
321  return UTmakeUnique<XUSD_RenderProduct>();
322  }
323  void computeImageWindows(const UsdStageRefPtr &usd,
324  const XUSD_RenderSettingsContext &ctx);
325  void setDefaults(const UsdStageRefPtr &usd,
326  const XUSD_RenderSettingsContext &ctx);
327  bool loadFromPrim(const UsdStageRefPtr &usd,
328  const XUSD_RenderSettingsContext &ctx);
329  bool loadFromOptions(const UsdStageRefPtr &usd,
330  const XUSD_RenderSettingsContext &ctx);
331  void buildRenderSettings(const UsdStageRefPtr &usd,
332  const XUSD_RenderSettingsContext &ctx);
333 
339  double myShutter[2];
345 };
346 
348 
349 #endif
double shutterClose() const
const GfVec2i & res() const
const_iterator end() const
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
Definition: SYS_MathCbrt.h:35
Definition: vec2i.h:61
const RenderVarList & vars() const
const TfToken & renderer() const
Rendering head.
double shutterOpen() const
const UT_DimRect & dataWindow() const
virtual SdfPath overrideCamera() const
Override the path to the camera.
UsdRenderSettings myUsdSettings
PXL_DataFormat pxlFormat() const
const VtArray< TfToken > & purpose() const
XUSD_RenderSettings contains the HdRenderSettings for the render.
virtual void setDefaultSettings(const XUSD_RenderSettings &rset, HdRenderSettingsMap &settings) const
Build initial render settings map.
#define HUSD_API
Definition: HUSD_API.h:32
virtual GfVec2i overrideResolution(const GfVec2i &res) const
Optionally override the resolution of the product.
float pixelAspect() const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
virtual const char * overrideProductName() const
Return a product name override.
const UT_StringHolder & outputName() const
const_iterator begin() const
const SdfPath & cameraPath() const
Properties from the render settings.
virtual const char * defaultPurpose() const
Return the default purpose (this is a comma separated list)
const TfToken & aovToken() const
virtual UT_UniquePtr< XUSD_RenderVar > newRenderVar() const
If you have a sub-class of XUSD_RenderVar, you can create it here.
virtual void overrideSettings(const XUSD_RenderSettings &rset, HdRenderSettingsMap &settings) const
After the products have been loaded, apply any overrides.
virtual const char * defaultProductName() const
Default product name.
Definition: token.h:89
PXL_DataFormat myDataFormat
const_iterator begin() const
simple inheritance: W = L * pW
PXR_NAMESPACE_OPEN_SCOPE typedef TfHashMap< TfToken, VtValue, TfToken::HashFunctor > HdAovSettingsMap
Definition: aov.h:38
HdAovSettingsMap mySettings
const HdAovDescriptor & desc() const
virtual HdAovDescriptor defaultAovDescriptor(const TfToken &aov) const
Get a default rendering descriptor for a given AOV.
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
const_iterator end() const
const HdAovSettingsMap & settings() const
User settings for this product.
const GLfloat * c
Definition: glew.h:16296
UT_StringHolder myFilename
const HdRenderSettingsMap & renderSettings() const
PXL_Packing
Definition: PXL_Common.h:29
Definition: prim.h:131
std::vector< HdAovDescriptor > HdAovDescriptorList
Definition: aov.h:79
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
PXL_DataFormat
Definition: PXL_Common.h:19
INT GLenum dataType
Definition: wglew.h:145
Definition: path.h:287
HdAovDescriptor myHdDesc
virtual bool allowCameraless() const
Allow render options to be applied without a camera present.
const ProductList & products() const
PXL_Packing pxlPacking() const
VtArray< TfToken > myPurpose
Definition: vec4f.h:63
UT_StringHolder myPartname
UsdPrim GetPrim() const
Definition: prim.h:1644
GLfloat GLfloat p
Definition: glew.h:16321
GLsizei const GLchar *const * string
Definition: glew.h:1844
double fpreal
Definition: SYS_Types.h:276
const std::string & aovName() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
virtual void initFromUSD(UsdRenderSettings &settings)
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:47
virtual const char * overridePurpose() const
Return if there's an overridden purpose for the render.
virtual UT_UniquePtr< XUSD_RenderProduct > newRenderProduct() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
HdRenderSettingsMap mySettings
virtual fpreal frameInc() const
Frame increment, when computing sequences.
UsdPrim prim() const
Get the render settings.
const GfVec4f & dataWindowF() const
GLdouble GLdouble t
Definition: glew.h:1398
virtual fpreal overridePixelAspect(fpreal pa) const
Optionally, override the pixel aspect ratio.
GLuint res
Definition: glew.h:11507
virtual int frameCount() const
Return the number of frames being rendered.