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_HuskEngine;
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_HuskEngine *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 
128  virtual UT_StringHolder renderer() const = 0;
130  { return UT_StringHolder(); }
131 
132  /// @{
133  /// Default & override product name. The @c raster_index is the offset
134  /// into the list of ordered raster products. If the product is @b not a
135  /// raster product, the product index is -1.
136  virtual const char *defaultProductName() const { return nullptr; }
137  virtual const char *overrideProductName(const HUSD_RenderProduct &p,
138  int raster_index) const
139  { return nullptr; }
140  /// @}
141  /// Default path for snapshots (in husk)
142  virtual const char *overrideSnapshotPath(const HUSD_RenderProduct &p,
143  int raster_index) const
144  { return nullptr; }
145 
146  /// Override the snapshot suffix (in husk)
147  virtual const char *overrideSnapshotSuffix(const HUSD_RenderProduct &p,
148  int raster_index) const
149  { return "_part"; }
150 
151  /// @{
152  /// Default & override render purpose
153  virtual const char *defaultPurpose() const
154  {
155  const char *p = overridePurpose();
156  return p ? p : "geometry,render";
157  }
158  virtual const char *overridePurpose() const { return nullptr; }
159  /// @}
160 
161  /// @{
162  /// Resolution, aspect ratio, data window and motion blur overrides
163  virtual UT_Vector2i defaultResolution() const = 0;
164  virtual UT_Vector2i overrideResolution(const UT_Vector2i &res) const
165  { return res; }
167  { return v; }
169  { return pa; }
170  virtual bool overrideDisableMotionBlur(bool is) const
171  { return is; }
172  /// @}
173 
174  /// @{
175  /// When composing an image with tiles, these options provide the image
176  /// suffix and tile index
177  virtual const char *tileSuffix() const { return nullptr; }
178  virtual int tileIndex() const { return 0; }
179  /// @}
180 
181  // First frame to be rendered
182  virtual fpreal startFrame() const = 0;
183  /// Frame increment, when computing sequences
184  virtual fpreal frameInc() const { return 1; }
185  /// Return the number of frames being rendered
186  virtual int frameCount() const { return 1; }
187  /// Return the FPS
188  virtual fpreal fps() const { return 24; }
189  /// Return a list of frames (if available)
190  virtual const std::vector<fpreal> *frameList() const { return nullptr; }
191 
192  /// Current frame (when rendering a sequence)
193  virtual fpreal evalTime() const = 0;
194 
195  /// Allow render options to be applied without a camera present.
196  virtual bool allowCameraless() const { return false; }
197 
198  const PXR_NS::XUSD_RenderSettingsContext &impl() const { return *myImpl; }
199  PXR_NS::XUSD_RenderSettingsContext &impl() { return *myImpl; }
200 private:
201  PXR_NS::XUSD_RenderSettingsContext *myImpl;
202 };
203 
205  : public UT_NonCopyable
206 {
207 public:
208  HUSD_RenderVar();
209  virtual ~HUSD_RenderVar();
210 
211  /// Method to clone this render var to another render product
213  {
214  UT_UniquePtr<HUSD_RenderVar> v = doClone(); // Create new object
215  v->copyDataFrom(*this);
216  return v;
217  }
218 
219  /// @{
220  /// Query settings
221  UT_StringHolder aovName() const;
222  UT_StringHolder aovToken() const;
223  UT_StringHolder dataType() const;
224  UT_StringHolder sourceName() const;
225  UT_StringHolder sourceType() const;
226 
227  PXL_DataFormat pxlFormat() const;
228  PXL_Packing pxlPacking() const;
229  /// @}
230 
231  /// @{
232  /// Query the AOV settings on the underlying render settings map
233  bool lookup(const char *token, int64 &val) const;
234  bool lookup(const char *token, fpreal64 &val) const;
235  bool lookup(const char *token, UT_Vector2i &val) const;
236  bool lookup(const char *token, UT_StringHolder &val) const;
237  /// @}
238 
239  /// @{
240  /// For debugging
241  void dump() const;
242  void dump(UT_JSONWriter &w) const;
243  /// @}
244 
245  /// @private - Data for implementation
246  PXR_NS::XUSD_RenderVar *myOwner;
247 protected:
248  /// Create a new sub-class of HUSD_RenderVar
250  {
251  return UTmakeUnique<HUSD_RenderVar>();
252  }
253 private:
254  void copyDataFrom(const HUSD_RenderVar &src);
255 };
256 
258  : public UT_NonCopyable
259 {
260 public:
262  virtual ~HUSD_RenderProduct();
263 
264  /// Allocate a new render variable for this product
265  virtual UT_UniquePtr<HUSD_RenderVar> newRenderVar() const;
266 
267  /// Provide a default filename
269  { return UT_StringHolder(); }
270 
271  /// @{
272  /// Query settings on the underlying render settings map
273  bool lookup(const char *token, int64 &val) const;
274  bool lookup(const char *token, fpreal64 &val) const;
275  bool lookup(const char *token, UT_Vector2i &val) const;
276  bool lookup(const char *token, UT_StringHolder &val) const;
277  /// @}
278 
279  /// Create a "writer" to store settings in this objects settings
281 
282  /// Copy a property from the render settings to this render product
283  /// This is typically used during initialization (before the USD product
284  /// settings are applied).
285  void copySetting(const HUSD_RenderSettings &settings,
286  const char *token);
287 
288  /// Clone from a list of render vars
289  void addRenderVars(const UT_Array<const HUSD_RenderVar *> &vars);
290 
291  /// @{
292  /// Access render vars
293  exint size() const;
294  const HUSD_RenderVar *renderVar(exint i) const;
295  /// @}
296 
297  /// @{
298  /// Query methods
300  UT_StringHolder productName(int frame=0) const;
301  UT_StringHolder outputName() const; // Current product name
302  /// @}
303 
304  /// Test if the render product is a raster product
305  bool isRaster() const;
306 
307  /// @{
308  /// For debugging
309  void dump() const;
310  void dump(UT_JSONWriter &w) const;
311  /// @}
312 
313  /// Add meta data to the IMG_FileParms
314  void addMetaData(IMG_FileParms &fparms) const;
315 
316  /// @private - Data for implementation
317  PXR_NS::XUSD_RenderProduct *myOwner;
318 protected:
319  // Access to the current filename and partname
320  const UT_StringHolder &filename() const;
321  const UT_StringHolder &partname() const;
322 
323 };
324 
326  : public UT_NonCopyable
327 {
328 public:
330 
331  HUSD_RenderSettings(const UT_StringHolder &prim_path,
332  const UT_StringHolder &filename,
333  time_t file_timestamp);
334  virtual ~HUSD_RenderSettings();
335 
336  // Create directories required to create the file given by the path
337  static bool makeFilePathDirs(const char *path);
338 
339  virtual bool supportedDelegate(const UT_StringRef &name) const;
340 
341  /// Allocate a new HUSD_RenderProduct for this subclass
342  virtual UT_UniquePtr<HUSD_RenderProduct> newRenderProduct() const;
343 
344  /// Initialize the settings, loading the settings, products and render vars
345  /// from the path given. The context is able to override settings during
346  /// initialization.
347  bool init(const HUSD_HuskEngine &engine,
348  const UT_StringHolder &settings_path,
350 
351  /// Return the name for the dummy render product name when there are no
352  /// raster products being rendered.
353  static const char *huskNullRasterName();
354 
355  /// Resolve products defined in the engine. This is called separately from
356  /// initialization to allow the client to initialize the engine and check
357  /// for valid products. Resolving will bind the render var AOVs and set up
358  /// all the settings associated with the product. After products are
359  /// resolved, the products are partitioned into product groups.
360  ///
361  /// If there are no "raster" products, but there are delegate render
362  /// products, create a dummy raster product so that delegates will function
363  /// properly. Creation of the dummy product will set the product name to
364  /// `huskNullRaster()`. The dummy product will pick a render var
365  /// referenced by the delegate render products, and will fail if there are
366  /// no render vars on any delegate render products.
367  bool resolveProducts(const HUSD_HuskEngine &engine,
369  HUSD_CustomProductAction custom_product_action);
370 
371 
372  /// Set up to render the given @c frame and @c product_group. This will
373  /// update the husk engine contained in the settings context, expand all
374  /// the product filenames and optionally create output directories for the
375  /// products.
376  ///
377  /// See `resolveProducts()` for help on `create_dummy_render_product`
378  bool updateFrame(HUSD_RenderSettingsContext &ctx,
379  int frame,
380  int product_group,
381  bool make_product_directories,
382  bool process_delegate_products,
383  HUSD_CustomProductAction custom_product_action);
384 
385  /// @{
386  /// Query settings on the underlying render setting
387  bool lookup(const char *token, int64 &val) const;
388  bool lookup(const char *token, fpreal64 &val) const;
389  bool lookup(const char *token, UT_Vector2i &val) const;
390  bool lookup(const char *token, UT_StringHolder &val) const;
391  /// @}
392 
393  /// Create a "writer" to store settings in this objects settings
395 
396  /// @{
397  /// Query settings that are shared with all products
398  UT_StringHolder renderer() const;
399  void purpose(UT_StringArray &purposes) const;
400  /// @}
401 
402  /// Return the output name for all the products in the product group
403  UT_StringHolder outputName(int product_group) const;
404 
405  /// @{
406  /// Query settings which can be overridden by products
407  UT_StringHolder cameraPath(const HUSD_RenderProduct *p) const;
408  double shutterOpen(const HUSD_RenderProduct *p) const;
409  double shutterClose(const HUSD_RenderProduct *p) const;
410  int xres(const HUSD_RenderProduct *p) const;
411  int yres(const HUSD_RenderProduct *p) const;
412  UT_Vector2i res(const HUSD_RenderProduct *p) const;
413  fpreal pixelAspect(const HUSD_RenderProduct *p) const;
414  UT_Vector4 dataWindowF(const HUSD_RenderProduct *p) const;
415  UT_DimRect dataWindow(const HUSD_RenderProduct *p) const;
416  bool disableMotionBlur(const HUSD_RenderProduct *p) const;
417 
418  UT_StringHolder cameraPath(int product_group) const
419  { return cameraPath(productInGroup(product_group)); }
420  double shutterOpen(int product_group) const
421  { return shutterOpen(productInGroup(product_group)); }
422  double shutterClose(int product_group) const
423  { return shutterClose(productInGroup(product_group)); }
424  int xres(int product_group) const
425  { return xres(productInGroup(product_group)); }
426  int yres(int product_group) const
427  { return yres(productInGroup(product_group)); }
428  UT_Vector2i res(int product_group) const
429  { return res(productInGroup(product_group)); }
430  fpreal pixelAspect(int product_group) const
431  { return pixelAspect(productInGroup(product_group)); }
432  UT_Vector4 dataWindowF(int product_group) const
433  { return dataWindowF(productInGroup(product_group)); }
434  UT_DimRect dataWindow(int product_group) const
435  { return dataWindow(productInGroup(product_group)); }
436  bool disableMotionBlur(int product_group) const
437  { return disableMotionBlur(productInGroup(product_group)); }
438  /// @}
439 
440  /// @{
441  /// For debugging
442  void dump() const;
443  void dump(UT_JSONWriter &w) const;
444  /// @}
445 
446  void printSettings() const;
447 
448  /// HUSD_RenderSettings will partition the HUSD_RenderProducts into
449  /// "groups". Each group has similar properties, for example, the same
450  /// rendering camera. This method returns the number of distinct product
451  /// groups.
452  exint productGroupSize() const;
453 
454  /// Get a list of all the render products in a given product group
455  void productGroup(int product_group, ProductGroup &products) const;
456 
457  /// Return the number of render products in a given render product group
458  exint productsInGroup(exint group) const;
459 
460  /// Get access to a product inside a product group
461  const HUSD_RenderProduct *product(exint prod_group, exint product) const;
462 
463  /// @private - Data for implementation
464  PXR_NS::XUSD_RenderSettings *myOwner;
465 
466 protected:
467  bool expandProducts(const HUSD_RenderSettingsContext &ctx,
468  int fnum,
469  int product_group);
470 
471  // Find any product in the given product group
472  const HUSD_RenderProduct *productInGroup(int product_group) const;
473 
474  exint totalProductCount() const;
475  void allProducts(ProductGroup &group) const;
476 
477  // Adding a product - this method will fail if the product has already been
478  // added to a different render setting.
479  bool addProduct(UT_UniquePtr<HUSD_RenderProduct> p, int prod_group);
480  void removeProduct(exint i);
481 };
482 
483 #endif
virtual int frameCount() const
Return the number of frames being rendered.
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
XUSD_RenderSettings contains the HdRenderSettings for the render.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
virtual const char * tileSuffix() const
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:32
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:37
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
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
virtual fpreal overridePixelAspect(fpreal pa) const
virtual int tileIndex() const
fpreal64 fpreal
Definition: SYS_Types.h:277
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:38
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:91
virtual const HUSD_HuskEngine * huskEngine() const
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:895
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:123
virtual UT_StringHolder defaultFilename() const
Provide a default filename.