HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_RenderSettings.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: HUSD_RenderSettings.h (HUSD Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __HUSD_RenderSettings__
12 #define __HUSD_RenderSettings__
13 
14 #include "HUSD_API.h"
15 #include "HUSD_Utils.h"
16 #include <pxr/pxr.h>
17 #include <UT/UT_StringHolder.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_UniquePtr.h>
20 #include <UT/UT_Rect.h>
21 #include <UT/UT_Vector2.h>
22 #include <UT/UT_Vector4.h>
23 #include <PXL/PXL_Common.h>
24 #include <vector>
25 
28 class XUSD_RenderVar;
29 class XUSD_RenderProduct;
32 
33 class HUSD_HuskImaging;
35 class HUSD_RenderVar;
36 class HUSD_RenderProduct;
38 class IMG_FileParms;
39 
40 namespace HUSD_RenderTokens
41 {
42  // From UsdRenderTokens
43  HUSD_API const char *productName();
44  HUSD_API const char *productType();
45  HUSD_API const char *dataType();
46  HUSD_API const char *aspectRatioConformPolicy();
47  HUSD_API const char *dataWindowNDC();
48  HUSD_API const char *disableMotionBlur();
49  HUSD_API const char *pixelAspectRatio();
50  HUSD_API const char *resolution();
51  HUSD_API const char *raster();
52 
53  // From HdAovTokens
54  HUSD_API const char *color();
55  HUSD_API const char *cameraDepth();
56 };
57 
58 /// Wrapper around XUSD_RenderSettings objects that has no dependencies on pxr
59 /// libraries.
61  : public UT_NonCopyable
62 {
63 public:
65  virtual ~HUSD_RenderSettingsContext();
66 
67  /// During initialization of the HUSD_RenderSettings, this class gets a
68  /// call back to initialize any defaults that make sense. The @c
69  /// lookupSetting class provides an interface to lookup very simple POD
70  /// types from the render settings primitive.
72  {
73  public:
74  lookupSetting(const void *data)
75  : myData(data)
76  {
77  }
78  /// Will lookup up bool, int32 or int64 values
79  bool lookup(const char *token, int64 &val) const;
80 
81  /// Will lookup up bool, int32 or int64, fpreal32, or fpreal64
82  bool lookup(const char *token, fpreal64 &val) const;
83 
84  /// Will lookup up GfVec2i
85  bool lookup(const char *token, UT_Vector2i &val) const;
86  private:
87  const void *myData;
88  };
89 
91  {
92  public:
94  : myData(data)
95  {
96  }
97  void store(const char *token, bool val);
98  void store(const char *token, int32 val);
99  void store(const char *token, int64 val);
100  void store(const char *token, fpreal32 val);
101  void store(const char *token, fpreal64 val);
102  void store(const char *token, const char *val);
103  void store(const char *token, const std::string &val);
104  void store(const char *token, const UT_Array<const char *> &val);
105 
106  // Store as a TfToken
107  void storeTfToken(const char *token, const char *val);
108 
109  private:
110  void *myData;
111  };
112 
113  // If the settings context has access to a rendering engine, this allows
114  // the context to provide default AOV descriptors etc.
115  virtual const HUSD_HuskImaging *huskEngine() const { return nullptr; }
116 
117  // Initialize any state data from the RenderSettings primitive
118  virtual void initFromSettings(const lookupSetting &lookup) {}
119 
120  // Store state data in the RenderSettingsMap for the RenderSettings
121  virtual void setDefaultSettings(const HUSD_RenderSettings &settings,
122  storeProperty &writer) const {};
123 
124  // Override any state data in the RenderSettingsMap for the RenderSettings
125  virtual void overrideSettings(const HUSD_RenderSettings &settings,
126  storeProperty &writer) const {};
127 
129  { return UT_StringHolder(); }
130 
131  /// @{
132  /// Default & override product name. The @c raster_index is the offset
133  /// into the list of ordered raster products. If the product is @b not a
134  /// raster product, the product index is -1.
135  virtual const char *defaultProductName() const { return nullptr; }
136  virtual const char *overrideProductName(const HUSD_RenderProduct &p,
137  int raster_index) const
138  { return nullptr; }
139  /// @}
140  /// Default path for snapshots (in husk)
141  virtual const char *overrideSnapshotPath(const HUSD_RenderProduct &p,
142  int raster_index) const
143  { return nullptr; }
144 
145  /// Override the snapshot suffix (in husk)
146  virtual const char *overrideSnapshotSuffix(const HUSD_RenderProduct &p,
147  int raster_index) const
148  { return "_part"; }
149 
150  /// @{
151  /// Default & override render purpose
152  virtual const char *defaultPurpose() const
153  {
154  const char *p = overridePurpose();
155  return p ? p : "geometry,render";
156  }
157  virtual const char *overridePurpose() const { return nullptr; }
158  /// @}
159 
160  /// @{
161  /// Resolution, aspect ratio, data window and motion blur overrides
162  virtual UT_Vector2i defaultResolution() const = 0;
163  virtual UT_Vector2i overrideResolution(const UT_Vector2i &res) const
164  { return res; }
166  { return v; }
168  { return pa; }
169  virtual bool overrideDisableMotionBlur(bool is) const
170  { return is; }
171  /// @}
172 
173  /// When composing an image with tiles, this method allows the context to
174  /// modify the product name.
175  virtual UT_StringHolder addTileSuffix(const UT_StringHolder &fname) const
176  {
177  return fname;
178  }
179 
180  // First frame to be rendered
181  virtual fpreal startFrame() const = 0;
182  /// Frame increment, when computing sequences
183  virtual fpreal frameInc() const { return 1; }
184  /// Return the number of frames being rendered
185  virtual int frameCount() const { return 1; }
186  /// Return the FPS
187  virtual fpreal fps() const { return 24; }
188  /// Return a list of frames (if available)
189  virtual const std::vector<fpreal> *frameList() const { return nullptr; }
190 
191  /// Current frame (when rendering a sequence)
192  virtual fpreal evalTime() const = 0;
193 
194  /// Allow render options to be applied without a camera present.
195  virtual bool allowCameraless() const { return false; }
196 
197  const PXR_NS::XUSD_RenderSettingsContext &impl() const { return *myImpl; }
198  PXR_NS::XUSD_RenderSettingsContext &impl() { return *myImpl; }
199 private:
200  PXR_NS::XUSD_RenderSettingsContext *myImpl;
201 };
202 
204  : public UT_NonCopyable
205 {
206 public:
207  HUSD_RenderVar();
208  virtual ~HUSD_RenderVar();
209 
210  /// Method to clone this render var to another render product
212  {
213  UT_UniquePtr<HUSD_RenderVar> v = doClone(); // Create new object
214  v->copyDataFrom(*this);
215  return v;
216  }
217 
218  /// @{
219  /// Query settings
220  UT_StringHolder aovName() const;
221  UT_StringHolder aovToken() const;
222  UT_StringHolder dataType() const;
223  UT_StringHolder sourceName() const;
224  UT_StringHolder sourceType() const;
225 
226  PXL_DataFormat pxlFormat() const;
227  PXL_Packing pxlPacking() const;
228  /// @}
229 
230  /// @{
231  /// Query the AOV settings on the underlying render settings map
232  bool lookup(const char *token, int64 &val) const;
233  bool lookup(const char *token, fpreal64 &val) const;
234  bool lookup(const char *token, UT_Vector2i &val) const;
235  bool lookup(const char *token, UT_StringHolder &val) const;
236  bool lookup(const char *token, UT_Array<fpreal64> &val) const;
237  bool lookup(const char *token, UT_StringArray &val) const;
238  /// @}
239 
240  /// @{
241  /// For debugging
242  void dump() const;
243  void dump(UT_JSONWriter &w) const;
244  /// @}
245 
246  /// @private - Data for implementation
247  PXR_NS::XUSD_RenderVar *myOwner;
248 protected:
249  /// Create a new sub-class of HUSD_RenderVar
251  {
252  return UTmakeUnique<HUSD_RenderVar>();
253  }
254 private:
255  void copyDataFrom(const HUSD_RenderVar &src);
256 };
257 
259  : public UT_NonCopyable
260 {
261 public:
263  virtual ~HUSD_RenderProduct();
264 
265  /// Allocate a new render variable for this product
266  virtual UT_UniquePtr<HUSD_RenderVar> newRenderVar() const;
267 
268  /// Provide a default filename
270  { return UT_StringHolder(); }
271 
272  /// @{
273  /// Query settings on the underlying render settings map
274  bool lookup(const char *token, int64 &val) const;
275  bool lookup(const char *token, fpreal64 &val) const;
276  bool lookup(const char *token, UT_Vector2i &val) const;
277  bool lookup(const char *token, UT_StringHolder &val) const;
278  bool lookup(const char *token, UT_Array<fpreal64> &val) const;
279  bool lookup(const char *token, UT_StringArray &val) const;
280  /// @}
281 
282  /// Create a "writer" to store settings in this objects settings
284 
285  /// Copy a property from the render settings to this render product
286  /// This is typically used during initialization (before the USD product
287  /// settings are applied).
288  void copySetting(const HUSD_RenderSettings &settings,
289  const char *token);
290 
291  /// Clone from a list of render vars
292  void addRenderVars(const UT_Array<const HUSD_RenderVar *> &vars);
293 
294  /// @{
295  /// Access render vars
296  exint size() const;
297  const HUSD_RenderVar *renderVar(exint i) const;
298  /// @}
299 
300  /// @{
301  /// Query methods
303  UT_StringHolder productName(int frame=0) const;
304  UT_StringHolder outputName() const; // Current product name
305  UT_StringHolder fullOutputName() const; // Product name without tile suffix
306  /// @}
307 
308  /// Utility function to insert @c extra text just before the filename
309  /// extension. For example "_part".
310  static UT_StringHolder insertExtraBeforeExtension(
311  const UT_StringHolder &filename,
312  const char *extra,
313  const char *path = nullptr);
314 
315  /// Test if the render product is a raster product
316  bool isRaster() const;
317 
318  /// @{
319  /// For debugging
320  void dump() const;
321  void dump(UT_JSONWriter &w) const;
322  /// @}
323 
324  /// Add meta data to the IMG_FileParms
325  void addMetaData(IMG_FileParms &fparms) const;
326 
327  /// @private - Data for implementation
328  PXR_NS::XUSD_RenderProduct *myOwner;
329 protected:
330  // Access to the current filename and partname
331  const UT_StringHolder &filename() const;
332  const UT_StringHolder &partname() const;
333 
334 };
335 
337  : public UT_NonCopyable
338 {
339 public:
341 
342  HUSD_RenderSettings(const UT_StringHolder &prim_path,
343  const UT_StringHolder &filename,
344  time_t file_timestamp);
345  virtual ~HUSD_RenderSettings();
346 
347  // Create directories required to create the file given by the path
348  static bool makeFilePathDirs(const char *path);
349 
350  // Create a directory (the path is the directory path, not the file path)
351  static bool makeDirPathDirs(const char *dir_path);
352 
353  virtual bool supportedDelegate(const UT_StringRef &name) const;
354 
355  /// Allocate a new HUSD_RenderProduct for this subclass
356  virtual UT_UniquePtr<HUSD_RenderProduct> newRenderProduct() const;
357 
358  /// Initialize the settings, loading the settings, products and render vars
359  /// from the path given. The context is able to override settings during
360  /// initialization.
361  bool init(const HUSD_HuskImaging &engine,
362  const UT_StringHolder &settings_path,
364 
365  /// Check to see if the karma random seed property is authored on the prim
366  bool getKarmaRandomSeed(int64 &seed,
367  const HUSD_RenderSettingsContext &ctx) const;
368 
369  /// Return the name for the dummy render product name when there are no
370  /// raster products being rendered.
371  static const char *huskNullRasterName();
372 
373  /// Resolve products defined in the engine. This is called separately from
374  /// initialization to allow the client to initialize the engine and check
375  /// for valid products. Resolving will bind the render var AOVs and set up
376  /// all the settings associated with the product. After products are
377  /// resolved, the products are partitioned into product groups.
378  ///
379  /// If there are no "raster" products, but there are delegate render
380  /// products, create a dummy raster product so that delegates will function
381  /// properly. Creation of the dummy product will set the product name to
382  /// `huskNullRaster()`. The dummy product will pick a render var
383  /// referenced by the delegate render products, and will fail if there are
384  /// no render vars on any delegate render products.
385  bool resolveProducts(const HUSD_HuskImaging &engine,
387  HUSD_CustomProductAction custom_product_action);
388 
389 
390  /// Set up to render the given @c frame and @c product_group. This will
391  /// update the husk engine contained in the settings context, expand all
392  /// the product filenames and optionally create output directories for the
393  /// products.
394  ///
395  /// See `resolveProducts()` for help on `create_dummy_render_product`
396  bool updateFrame(HUSD_RenderSettingsContext &ctx,
397  int frame,
398  int product_group,
399  bool process_delegate_products,
400  HUSD_CustomProductAction custom_product_action);
401 
402  /// @{
403  /// Query settings on the underlying render setting
404  bool lookup(const char *token, int64 &val) const;
405  bool lookup(const char *token, fpreal64 &val) const;
406  bool lookup(const char *token, UT_Vector2i &val) const;
407  bool lookup(const char *token, UT_StringHolder &val) const;
408  bool lookup(const char *token, UT_Array<fpreal64> &val) const;
409  bool lookup(const char *token, UT_StringArray &val) const;
410  /// @}
411 
412  /// Create a "writer" to store settings in this objects settings
414 
415  /// @{
416  /// Query settings that are shared with all products
417  void purpose(UT_StringArray &purposes) const;
418  /// @}
419 
420  /// Return the output name for all the products in the product group
421  UT_StringHolder outputName(int product_group) const;
422 
423  /// @{
424  /// Query settings which can be overridden by products
425  UT_StringHolder cameraPath(const HUSD_RenderProduct *p) const;
426  double shutterOpen(const HUSD_RenderProduct *p) const;
427  double shutterClose(const HUSD_RenderProduct *p) const;
428  int xres(const HUSD_RenderProduct *p) const;
429  int yres(const HUSD_RenderProduct *p) const;
430  UT_Vector2i res(const HUSD_RenderProduct *p) const;
431  fpreal pixelAspect(const HUSD_RenderProduct *p) const;
432  UT_Vector4 dataWindowF(const HUSD_RenderProduct *p) const;
433  UT_DimRect dataWindow(const HUSD_RenderProduct *p) const;
434  bool disableMotionBlur(const HUSD_RenderProduct *p) const;
435 
436  UT_StringHolder cameraPath(int product_group) const
437  { return cameraPath(productInGroup(product_group)); }
438  double shutterOpen(int product_group) const
439  { return shutterOpen(productInGroup(product_group)); }
440  double shutterClose(int product_group) const
441  { return shutterClose(productInGroup(product_group)); }
442  int xres(int product_group) const
443  { return xres(productInGroup(product_group)); }
444  int yres(int product_group) const
445  { return yres(productInGroup(product_group)); }
446  UT_Vector2i res(int product_group) const
447  { return res(productInGroup(product_group)); }
448  fpreal pixelAspect(int product_group) const
449  { return pixelAspect(productInGroup(product_group)); }
450  UT_Vector4 dataWindowF(int product_group) const
451  { return dataWindowF(productInGroup(product_group)); }
452  UT_DimRect dataWindow(int product_group) const
453  { return dataWindow(productInGroup(product_group)); }
454  bool disableMotionBlur(int product_group) const
455  { return disableMotionBlur(productInGroup(product_group)); }
456  /// @}
457 
458  /// @{
459  /// For debugging
460  void dump() const;
461  void dump(UT_JSONWriter &w) const;
462  /// @}
463 
464  /// Add meta data to the IMG_FileParms
465  void addMetaData(IMG_FileParms &fparms) const;
466 
467  void printSettings() const;
468 
469  /// HUSD_RenderSettings will partition the HUSD_RenderProducts into
470  /// "groups". Each group has similar properties, for example, the same
471  /// rendering camera. This method returns the number of distinct product
472  /// groups.
473  exint productGroupSize() const;
474 
475  /// Get a list of all the render products in a given product group
476  void productGroup(int product_group, ProductGroup &products) const;
477 
478  /// Return the number of render products in a given render product group
479  exint productsInGroup(exint group) const;
480 
481  /// Get access to a product inside a product group
482  const HUSD_RenderProduct *product(exint prod_group, exint product) const;
483 
484  /// @private - Data for implementation
485  PXR_NS::XUSD_RenderSettings *myOwner;
486 
487 protected:
488  bool expandProducts(const HUSD_RenderSettingsContext &ctx,
489  int fnum,
490  int product_group,
491  bool delegate_products);
492 
493  // Find any product in the given product group
494  const HUSD_RenderProduct *productInGroup(int product_group) const;
495 
496  exint totalProductCount() const;
497  void allProducts(ProductGroup &group) const;
498 
499  // Adding a product - this method will fail if the product has already been
500  // added to a different render setting.
501  bool addProduct(UT_UniquePtr<HUSD_RenderProduct> p, int prod_group);
502  void removeProduct(exint i);
503 };
504 
505 #endif
virtual int frameCount() const
Return the number of frames being rendered.
virtual UT_StringHolder addTileSuffix(const UT_StringHolder &fname) const
bool disableMotionBlur(int product_group) const
GT_API const UT_StringHolder filename
const PXR_NS::XUSD_RenderSettingsContext & impl() const
int int32
Definition: SYS_Types.h:39
UT_Vector4 dataWindowF(int product_group) const
const GLdouble * v
Definition: glcorearb.h:837
virtual const HUSD_HuskImaging * huskEngine() const
XUSD_RenderSettings contains the HdRenderSettings for the render.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
double shutterClose(int product_group) const
int64 exint
Definition: SYS_Types.h:125
#define HUSD_API
Definition: HUSD_API.h:31
virtual const char * overrideSnapshotSuffix(const HUSD_RenderProduct &p, int raster_index) const
Override the snapshot suffix (in husk)
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:39
UT_DimRect dataWindow(int product_group) const
HUSD_API const char * aspectRatioConformPolicy()
virtual const char * overrideProductName(const HUSD_RenderProduct &p, int raster_index) const
float fpreal32
Definition: SYS_Types.h:200
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
double fpreal64
Definition: SYS_Types.h:201
UT_UniquePtr< HUSD_RenderVar > clone() const
Method to clone this render var to another render product.
double shutterOpen(int product_group) const
virtual const char * overrideSnapshotPath(const HUSD_RenderProduct &p, int raster_index) const
virtual void setDefaultSettings(const HUSD_RenderSettings &settings, storeProperty &writer) const
PXR_NS::XUSD_RenderSettingsContext & impl()
virtual bool overrideDisableMotionBlur(bool is) const
virtual UT_Vector4 overrideDataWindow(const UT_Vector4 &v) const
int yres(int product_group) const
HUSD_API const char * color()
virtual fpreal frameInc() const
Frame increment, when computing sequences.
PXL_Packing
Definition: PXL_Common.h:32
HUSD_API const char * raster()
long long int64
Definition: SYS_Types.h:116
HUSD_API const char * resolution()
GLuint const GLchar * name
Definition: glcorearb.h:786
PXL_DataFormat
Definition: PXL_Common.h:20
virtual UT_StringHolder overrideCamera() const
HUSD_API const char * pixelAspectRatio()
virtual const char * defaultProductName() const
virtual const std::vector< fpreal > * frameList() const
Return a list of frames (if available)
HUSD_API const char * cameraDepth()
GLsizeiptr size
Definition: glcorearb.h:664
virtual fpreal overridePixelAspect(fpreal pa) const
fpreal64 fpreal
Definition: SYS_Types.h:283
virtual void overrideSettings(const HUSD_RenderSettings &settings, storeProperty &writer) const
virtual void initFromSettings(const lookupSetting &lookup)
File options for manipulating image data on load or save. This class allows you to modify the incomin...
Definition: IMG_FileParms.h:39
virtual bool allowCameraless() const
Allow render options to be applied without a camera present.
GLuint GLfloat * val
Definition: glcorearb.h:1608
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
UT_StringHolder cameraPath(int product_group) const
UT_Vector2i res(int product_group) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
HUSD_API const char * productType()
virtual UT_UniquePtr< HUSD_RenderVar > doClone() const
Create a new sub-class of HUSD_RenderVar.
HUSD_API const char * dataWindowNDC()
int xres(int product_group) const
fpreal pixelAspect(int product_group) const
virtual const char * overridePurpose() const
HUSD_API const char * dataType()
HUSD_API const char * productName()
virtual const char * defaultPurpose() const
Definition: format.h:1821
virtual fpreal fps() const
Return the FPS.
virtual UT_Vector2i overrideResolution(const UT_Vector2i &res) const
HUSD_API const char * disableMotionBlur()
GLenum src
Definition: glcorearb.h:1793
HUSD_CustomProductAction
Definition: HUSD_Utils.h:128
virtual UT_StringHolder defaultFilename() const
Provide a default filename.