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  /// @}
237 
238  /// @{
239  /// For debugging
240  void dump() const;
241  void dump(UT_JSONWriter &w) const;
242  /// @}
243 
244  /// @private - Data for implementation
245  PXR_NS::XUSD_RenderVar *myOwner;
246 protected:
247  /// Create a new sub-class of HUSD_RenderVar
249  {
250  return UTmakeUnique<HUSD_RenderVar>();
251  }
252 private:
253  void copyDataFrom(const HUSD_RenderVar &src);
254 };
255 
257  : public UT_NonCopyable
258 {
259 public:
261  virtual ~HUSD_RenderProduct();
262 
263  /// Allocate a new render variable for this product
264  virtual UT_UniquePtr<HUSD_RenderVar> newRenderVar() const;
265 
266  /// Provide a default filename
268  { return UT_StringHolder(); }
269 
270  /// @{
271  /// Query settings on the underlying render settings map
272  bool lookup(const char *token, int64 &val) const;
273  bool lookup(const char *token, fpreal64 &val) const;
274  bool lookup(const char *token, UT_Vector2i &val) const;
275  bool lookup(const char *token, UT_StringHolder &val) const;
276  /// @}
277 
278  /// Create a "writer" to store settings in this objects settings
280 
281  /// Copy a property from the render settings to this render product
282  /// This is typically used during initialization (before the USD product
283  /// settings are applied).
284  void copySetting(const HUSD_RenderSettings &settings,
285  const char *token);
286 
287  /// Clone from a list of render vars
288  void addRenderVars(const UT_Array<const HUSD_RenderVar *> &vars);
289 
290  /// @{
291  /// Access render vars
292  exint size() const;
293  const HUSD_RenderVar *renderVar(exint i) const;
294  /// @}
295 
296  /// @{
297  /// Query methods
299  UT_StringHolder productName(int frame=0) const;
300  UT_StringHolder outputName() const; // Current product name
301  UT_StringHolder fullOutputName() const; // Product name without tile suffix
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  // Create a directory (the path is the directory path, not the file path)
340  static bool makeDirPathDirs(const char *dir_path);
341 
342  virtual bool supportedDelegate(const UT_StringRef &name) const;
343 
344  /// Allocate a new HUSD_RenderProduct for this subclass
345  virtual UT_UniquePtr<HUSD_RenderProduct> newRenderProduct() const;
346 
347  /// Initialize the settings, loading the settings, products and render vars
348  /// from the path given. The context is able to override settings during
349  /// initialization.
350  bool init(const HUSD_HuskImaging &engine,
351  const UT_StringHolder &settings_path,
353 
354  /// Check to see if the karma random seed property is authored on the prim
355  bool getKarmaRandomSeed(int64 &seed,
356  const HUSD_RenderSettingsContext &ctx) const;
357 
358  /// Return the name for the dummy render product name when there are no
359  /// raster products being rendered.
360  static const char *huskNullRasterName();
361 
362  /// Resolve products defined in the engine. This is called separately from
363  /// initialization to allow the client to initialize the engine and check
364  /// for valid products. Resolving will bind the render var AOVs and set up
365  /// all the settings associated with the product. After products are
366  /// resolved, the products are partitioned into product groups.
367  ///
368  /// If there are no "raster" products, but there are delegate render
369  /// products, create a dummy raster product so that delegates will function
370  /// properly. Creation of the dummy product will set the product name to
371  /// `huskNullRaster()`. The dummy product will pick a render var
372  /// referenced by the delegate render products, and will fail if there are
373  /// no render vars on any delegate render products.
374  bool resolveProducts(const HUSD_HuskImaging &engine,
376  HUSD_CustomProductAction custom_product_action);
377 
378 
379  /// Set up to render the given @c frame and @c product_group. This will
380  /// update the husk engine contained in the settings context, expand all
381  /// the product filenames and optionally create output directories for the
382  /// products.
383  ///
384  /// See `resolveProducts()` for help on `create_dummy_render_product`
385  bool updateFrame(HUSD_RenderSettingsContext &ctx,
386  int frame,
387  int product_group,
388  bool process_delegate_products,
389  HUSD_CustomProductAction custom_product_action);
390 
391  /// @{
392  /// Query settings on the underlying render setting
393  bool lookup(const char *token, int64 &val) const;
394  bool lookup(const char *token, fpreal64 &val) const;
395  bool lookup(const char *token, UT_Vector2i &val) const;
396  bool lookup(const char *token, UT_StringHolder &val) const;
397  /// @}
398 
399  /// Create a "writer" to store settings in this objects settings
401 
402  /// @{
403  /// Query settings that are shared with all products
404  void purpose(UT_StringArray &purposes) const;
405  /// @}
406 
407  /// Return the output name for all the products in the product group
408  UT_StringHolder outputName(int product_group) const;
409 
410  /// @{
411  /// Query settings which can be overridden by products
412  UT_StringHolder cameraPath(const HUSD_RenderProduct *p) const;
413  double shutterOpen(const HUSD_RenderProduct *p) const;
414  double shutterClose(const HUSD_RenderProduct *p) const;
415  int xres(const HUSD_RenderProduct *p) const;
416  int yres(const HUSD_RenderProduct *p) const;
417  UT_Vector2i res(const HUSD_RenderProduct *p) const;
418  fpreal pixelAspect(const HUSD_RenderProduct *p) const;
419  UT_Vector4 dataWindowF(const HUSD_RenderProduct *p) const;
420  UT_DimRect dataWindow(const HUSD_RenderProduct *p) const;
421  bool disableMotionBlur(const HUSD_RenderProduct *p) const;
422 
423  UT_StringHolder cameraPath(int product_group) const
424  { return cameraPath(productInGroup(product_group)); }
425  double shutterOpen(int product_group) const
426  { return shutterOpen(productInGroup(product_group)); }
427  double shutterClose(int product_group) const
428  { return shutterClose(productInGroup(product_group)); }
429  int xres(int product_group) const
430  { return xres(productInGroup(product_group)); }
431  int yres(int product_group) const
432  { return yres(productInGroup(product_group)); }
433  UT_Vector2i res(int product_group) const
434  { return res(productInGroup(product_group)); }
435  fpreal pixelAspect(int product_group) const
436  { return pixelAspect(productInGroup(product_group)); }
437  UT_Vector4 dataWindowF(int product_group) const
438  { return dataWindowF(productInGroup(product_group)); }
439  UT_DimRect dataWindow(int product_group) const
440  { return dataWindow(productInGroup(product_group)); }
441  bool disableMotionBlur(int product_group) const
442  { return disableMotionBlur(productInGroup(product_group)); }
443  /// @}
444 
445  /// @{
446  /// For debugging
447  void dump() const;
448  void dump(UT_JSONWriter &w) const;
449  /// @}
450 
451  void printSettings() const;
452 
453  /// HUSD_RenderSettings will partition the HUSD_RenderProducts into
454  /// "groups". Each group has similar properties, for example, the same
455  /// rendering camera. This method returns the number of distinct product
456  /// groups.
457  exint productGroupSize() const;
458 
459  /// Get a list of all the render products in a given product group
460  void productGroup(int product_group, ProductGroup &products) const;
461 
462  /// Return the number of render products in a given render product group
463  exint productsInGroup(exint group) const;
464 
465  /// Get access to a product inside a product group
466  const HUSD_RenderProduct *product(exint prod_group, exint product) const;
467 
468  /// @private - Data for implementation
469  PXR_NS::XUSD_RenderSettings *myOwner;
470 
471 protected:
472  bool expandProducts(const HUSD_RenderSettingsContext &ctx,
473  int fnum,
474  int product_group,
475  bool delegate_products);
476 
477  // Find any product in the given product group
478  const HUSD_RenderProduct *productInGroup(int product_group) const;
479 
480  exint totalProductCount() const;
481  void allProducts(ProductGroup &group) const;
482 
483  // Adding a product - this method will fail if the product has already been
484  // added to a different render setting.
485  bool addProduct(UT_UniquePtr<HUSD_RenderProduct> p, int prod_group);
486  void removeProduct(exint i);
487 };
488 
489 #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.
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: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:1425
virtual fpreal overridePixelAspect(fpreal pa) const
fpreal64 fpreal
Definition: SYS_Types.h:278
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:129
virtual UT_StringHolder defaultFilename() const
Provide a default filename.