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 <pxr/pxr.h>
16 #include <UT/UT_StringHolder.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_UniquePtr.h>
19 #include <UT/UT_Rect.h>
20 #include <UT/UT_Vector2.h>
21 #include <UT/UT_Vector4.h>
22 #include <PXL/PXL_Common.h>
23 #include <vector>
24 
27 class XUSD_RenderVar;
28 class XUSD_RenderProduct;
31 
32 class HUSD_HuskEngine;
34 class HUSD_RenderVar;
35 class HUSD_RenderProduct;
37 class IMG_FileParms;
38 
39 namespace HUSD_RenderTokens
40 {
41  // From UsdRenderTokens
42  HUSD_API const char *productName();
43  HUSD_API const char *productType();
44  HUSD_API const char *dataType();
45  HUSD_API const char *aspectRatioConformPolicy();
46  HUSD_API const char *dataWindowNDC();
47  HUSD_API const char *disableMotionBlur();
48  HUSD_API const char *pixelAspectRatio();
49  HUSD_API const char *resolution();
50  HUSD_API const char *raster();
51 
52  // From HdAovTokens
53  HUSD_API const char *color();
54  HUSD_API const char *cameraDepth();
55 };
56 
57 /// Wrapper around XUSD_RenderSettings objects that has no dependencies on pxr
58 /// libraries.
60  : public UT_NonCopyable
61 {
62 public:
64  virtual ~HUSD_RenderSettingsContext();
65 
66  /// During initialization of the HUSD_RenderSettings, this class gets a
67  /// call back to initialize any defaults that make sense. The @c
68  /// lookupSetting class provides an interface to lookup very simple POD
69  /// types from the render settings primitive.
71  {
72  public:
73  lookupSetting(const void *data)
74  : myData(data)
75  {
76  }
77  /// Will lookup up bool, int32 or int64 values
78  bool lookup(const char *token, int64 &val) const;
79 
80  /// Will lookup up bool, int32 or int64, fpreal32, or fpreal64
81  bool lookup(const char *token, fpreal64 &val) const;
82 
83  /// Will lookup up GfVec2i
84  bool lookup(const char *token, UT_Vector2i &val) const;
85  private:
86  const void *myData;
87  };
88 
90  {
91  public:
93  : myData(data)
94  {
95  }
96  void store(const char *token, bool val);
97  void store(const char *token, int32 val);
98  void store(const char *token, int64 val);
99  void store(const char *token, fpreal32 val);
100  void store(const char *token, fpreal64 val);
101  void store(const char *token, const char *val);
102  void store(const char *token, const std::string &val);
103  void store(const char *token, const UT_Array<const char *> &val);
104 
105  // Store as a TfToken
106  void storeTfToken(const char *token, const char *val);
107 
108  private:
109  void *myData;
110  };
111 
112  // If the settings context has access to a rendering engine, this allows
113  // the context to provide default AOV descriptors etc.
114  virtual const HUSD_HuskEngine *huskEngine() const { return nullptr; }
115 
116  // Initialize any state data from the RenderSettings primitive
117  virtual void initFromSettings(const lookupSetting &lookup) {}
118 
119  // Store state data in the RenderSettingsMap for the RenderSettings
120  virtual void setDefaultSettings(const HUSD_RenderSettings &settings,
121  storeProperty &writer) const {};
122 
123  // Override any state data in the RenderSettingsMap for the RenderSettings
124  virtual void overrideSettings(const HUSD_RenderSettings &settings,
125  storeProperty &writer) const {};
126 
127  virtual UT_StringHolder renderer() const = 0;
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  /// @{
174  /// When composing an image with tiles, these options provide the image
175  /// suffix and tile index
176  virtual const char *tileSuffix() const { return nullptr; }
177  virtual int tileIndex() const { return 0; }
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  /// @}
302 
303  /// Test if the render product is a raster product
304  bool isRaster() const;
305 
306  /// @{
307  /// For debugging
308  void dump() const;
309  void dump(UT_JSONWriter &w) const;
310  /// @}
311 
312  /// Add meta data to the IMG_FileParms
313  void addMetaData(IMG_FileParms &fparms) const;
314 
315  /// @private - Data for implementation
316  PXR_NS::XUSD_RenderProduct *myOwner;
317 protected:
318  // Access to the current filename and partname
319  const UT_StringHolder &filename() const;
320  const UT_StringHolder &partname() const;
321 
322 };
323 
325  : public UT_NonCopyable
326 {
327 public:
329 
330  HUSD_RenderSettings(const UT_StringHolder &prim_path,
331  const UT_StringHolder &filename,
332  time_t file_timestamp);
333  virtual ~HUSD_RenderSettings();
334 
335  // Create directories required to create the file given by the path
336  static bool makeFilePathDirs(const char *path);
337 
338  virtual bool supportedDelegate(const UT_StringRef &name) const;
339 
340  /// Allocate a new HUSD_RenderProduct for this subclass
341  virtual UT_UniquePtr<HUSD_RenderProduct> newRenderProduct() const;
342 
343  /// Initialize the settings, loading the settings, products and render vars
344  /// from the path given. The context is able to override settings during
345  /// initialization.
346  bool init(const HUSD_HuskEngine &engine,
347  const UT_StringHolder &settings_path,
349 
350  /// Return the name for the dummy render product name when there are no
351  /// raster products being rendered.
352  static const char *huskNullRasterName();
353 
354  /// Resolve products defined in the engine. This is called separately from
355  /// initialization to allow the client to initialize the engine and check
356  /// for valid products. Resolving will bind the render var AOVs and set up
357  /// all the settings associated with the product. After products are
358  /// resolved, the products are partitioned into product groups.
359  ///
360  /// If there are no "raster" products, but there are delegate render
361  /// products, create a dummy raster product so that delegates will function
362  /// properly. Creation of the dummy product will set the product name to
363  /// `huskNullRaster()`. The dummy product will pick a render var
364  /// referenced by the delegate render products, and will fail if there are
365  /// no render vars on any delegate render products.
366  bool resolveProducts(const HUSD_HuskEngine &engine,
368  bool create_dummy_raster_product);
369 
370 
371  /// Set up to render the given @c frame and @c product_group. This will
372  /// update the husk engine contained in the settings context, expand all
373  /// the product filenames and optionally create output directories for the
374  /// products.
375  ///
376  /// See `resolveProducts()` for help on `create_dummy_render_product`
377  bool updateFrame(HUSD_RenderSettingsContext &ctx,
378  int frame,
379  int product_group,
380  bool make_product_directories,
381  bool process_delegate_products,
382  bool create_dummy_render_product);
383 
384  /// @{
385  /// Query settings on the underlying render setting
386  bool lookup(const char *token, int64 &val) const;
387  bool lookup(const char *token, fpreal64 &val) const;
388  bool lookup(const char *token, UT_Vector2i &val) const;
389  bool lookup(const char *token, UT_StringHolder &val) const;
390  /// @}
391 
392  /// Create a "writer" to store settings in this objects settings
394 
395  /// @{
396  /// Query settings that are shared with all products
397  UT_StringHolder renderer() const;
398  void purpose(UT_StringArray &purposes) const;
399  /// @}
400 
401  /// Return the output name for all the products in the product group
402  UT_StringHolder outputName(int product_group) const;
403 
404  /// @{
405  /// Query settings which can be overridden by products
406  UT_StringHolder cameraPath(const HUSD_RenderProduct *p) const;
407  double shutterOpen(const HUSD_RenderProduct *p) const;
408  double shutterClose(const HUSD_RenderProduct *p) const;
409  int xres(const HUSD_RenderProduct *p) const;
410  int yres(const HUSD_RenderProduct *p) const;
411  UT_Vector2i res(const HUSD_RenderProduct *p) const;
412  fpreal pixelAspect(const HUSD_RenderProduct *p) const;
413  UT_Vector4 dataWindowF(const HUSD_RenderProduct *p) const;
414  UT_DimRect dataWindow(const HUSD_RenderProduct *p) const;
415  bool disableMotionBlur(const HUSD_RenderProduct *p) const;
416 
417  UT_StringHolder cameraPath(int product_group) const
418  { return cameraPath(productInGroup(product_group)); }
419  double shutterOpen(int product_group) const
420  { return shutterOpen(productInGroup(product_group)); }
421  double shutterClose(int product_group) const
422  { return shutterClose(productInGroup(product_group)); }
423  int xres(int product_group) const
424  { return xres(productInGroup(product_group)); }
425  int yres(int product_group) const
426  { return yres(productInGroup(product_group)); }
427  UT_Vector2i res(int product_group) const
428  { return res(productInGroup(product_group)); }
429  fpreal pixelAspect(int product_group) const
430  { return pixelAspect(productInGroup(product_group)); }
431  UT_Vector4 dataWindowF(int product_group) const
432  { return dataWindowF(productInGroup(product_group)); }
433  UT_DimRect dataWindow(int product_group) const
434  { return dataWindow(productInGroup(product_group)); }
435  bool disableMotionBlur(int product_group) const
436  { return disableMotionBlur(productInGroup(product_group)); }
437  /// @}
438 
439  /// @{
440  /// For debugging
441  void dump() const;
442  void dump(UT_JSONWriter &w) const;
443  /// @}
444 
445  void printSettings() const;
446 
447  /// HUSD_RenderSettings will partition the HUSD_RenderProducts into
448  /// "groups". Each group has similar properties, for example, the same
449  /// rendering camera. This method returns the number of distinct product
450  /// groups.
451  exint productGroupSize() const;
452 
453  /// Get a list of all the render products in a given product group
454  void productGroup(int product_group, ProductGroup &products) const;
455 
456  /// Return the number of render products in a given render product group
457  exint productsInGroup(exint group) const;
458 
459  /// Get access to a product inside a product group
460  const HUSD_RenderProduct *product(exint prod_group, exint product) const;
461 
462  /// @private - Data for implementation
463  PXR_NS::XUSD_RenderSettings *myOwner;
464 
465 protected:
466  bool expandProducts(const HUSD_RenderSettingsContext &ctx,
467  int fnum,
468  int product_group);
469 
470  // Find any product in the given product group
471  const HUSD_RenderProduct *productInGroup(int product_group) const;
472 
473  exint totalProductCount() const;
474  void allProducts(ProductGroup &group) const;
475 
476  // Adding a product - this method will fail if the product has already been
477  // added to a different render setting.
478  bool addProduct(UT_UniquePtr<HUSD_RenderProduct> p, int prod_group);
479  void removeProduct(exint i);
480 };
481 
482 #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
virtual UT_StringHolder defaultFilename() const
Provide a default filename.