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 
26 class XUSD_RenderVar;
27 class XUSD_RenderProduct;
30 
31 class HUSD_HuskEngine;
33 class HUSD_RenderVar;
34 class HUSD_RenderProduct;
36 class IMG_FileParms;
37 
38 namespace HUSD_RenderTokens
39 {
40  // From UsdRenderTokens
41  HUSD_API const char *productName();
42  HUSD_API const char *productType();
43  HUSD_API const char *dataType();
44  HUSD_API const char *aspectRatioConformPolicy();
45  HUSD_API const char *dataWindowNDC();
46  HUSD_API const char *disableMotionBlur();
47  HUSD_API const char *pixelAspectRatio();
48  HUSD_API const char *resolution();
49  HUSD_API const char *raster();
50 
51  // From HdAovTokens
52  HUSD_API const char *color();
53  HUSD_API const char *cameraDepth();
54 };
55 
56 /// Wrapper around XUSD_RenderSettings objects that has no dependencies on pxr
57 /// libraries.
59  : public UT_NonCopyable
60 {
61 public:
63  virtual ~HUSD_RenderSettingsContext();
64 
65  /// During initialization of the HUSD_RenderSettings, this class gets a
66  /// call back to initialize any defaults that make sense. The @c
67  /// lookupSetting class provides an interface to lookup very simple POD
68  /// types from the render settings primitive.
70  {
71  public:
72  lookupSetting(const void *data)
73  : myData(data)
74  {
75  }
76  /// Will lookup up bool, int32 or int64 values
77  bool lookup(const char *token, int64 &val) const;
78 
79  /// Will lookup up bool, int32 or int64, fpreal32, or fpreal64
80  bool lookup(const char *token, fpreal64 &val) const;
81 
82  /// Will lookup up GfVec2i
83  bool lookup(const char *token, UT_Vector2i &val) const;
84  private:
85  const void *myData;
86  };
87 
89  {
90  public:
92  : myData(data)
93  {
94  }
95  void store(const char *token, bool val);
96  void store(const char *token, int32 val);
97  void store(const char *token, int64 val);
98  void store(const char *token, fpreal32 val);
99  void store(const char *token, fpreal64 val);
100  void store(const char *token, const char *val);
101  void store(const char *token, const std::string &val);
102  void store(const char *token, const UT_Array<const char *> &val);
103 
104  // Store as a TfToken
105  void storeTfToken(const char *token, const char *val);
106 
107  private:
108  void *myData;
109  };
110 
111  // If the settings context has access to a rendering engine, this allows
112  // the context to provide default AOV descriptors etc.
113  virtual const HUSD_HuskEngine *huskEngine() const { return nullptr; }
114 
115  // Initialize any state data from the RenderSettings primitive
116  virtual void initFromSettings(const lookupSetting &lookup) {}
117 
118  // Store state data in the RenderSettingsMap for the RenderSettings
119  virtual void setDefaultSettings(const HUSD_RenderSettings &settings,
120  storeProperty &writer) const {};
121 
122  // Override any state data in the RenderSettingsMap for the RenderSettings
123  virtual void overrideSettings(const HUSD_RenderSettings &settings,
124  storeProperty &writer) const {};
125 
126  virtual UT_StringHolder renderer() const = 0;
128  { return UT_StringHolder(); }
129 
130  /// @{
131  /// Default & override product name. The @c raster_index is the offset
132  /// into the list of ordered raster products. If the product is @b not a
133  /// raster product, the product index is -1.
134  virtual const char *defaultProductName() const { return nullptr; }
135  virtual const char *overrideProductName(const HUSD_RenderProduct &p,
136  int raster_index) const
137  { return nullptr; }
138  /// @}
139  /// Default path for snapshots (in husk)
140  virtual const char *overrideSnapshotPath(const HUSD_RenderProduct &p,
141  int raster_index) const
142  { return nullptr; }
143 
144  /// Override the snapshot suffix (in husk)
145  virtual const char *overrideSnapshotSuffix(const HUSD_RenderProduct &p,
146  int raster_index) const
147  { return "_part"; }
148 
149  /// @{
150  /// Default & override render purpose
151  virtual const char *defaultPurpose() const
152  {
153  const char *p = overridePurpose();
154  return p ? p : "geometry,render";
155  }
156  virtual const char *overridePurpose() const { return nullptr; }
157  /// @}
158 
159  /// @{
160  /// Resolution, aspect ratio, data window and motion blur overrides
161  virtual UT_Vector2i defaultResolution() const = 0;
162  virtual UT_Vector2i overrideResolution(const UT_Vector2i &res) const
163  { return res; }
165  { return v; }
167  { return pa; }
168  virtual bool overrideDisableMotionBlur(bool is) const
169  { return is; }
170  /// @}
171 
172  /// @{
173  /// When composing an image with tiles, these options provide the image
174  /// suffix and tile index
175  virtual const char *tileSuffix() const { return nullptr; }
176  virtual int tileIndex() const { return 0; }
177  /// @}
178 
179  // First frame to be rendered
180  virtual fpreal startFrame() const = 0;
181  /// Frame increment, when computing sequences
182  virtual fpreal frameInc() const { return 1; }
183  /// Return the number of frames being rendered
184  virtual int frameCount() const { return 1; }
185  /// Return the FPS
186  virtual fpreal fps() const { return 24; }
187 
188  /// Current frame (when rendering a sequence)
189  virtual fpreal evalTime() const = 0;
190 
191  /// Allow render options to be applied without a camera present.
192  virtual bool allowCameraless() const { return false; }
193 
194  const PXR_NS::XUSD_RenderSettingsContext &impl() const { return *myImpl; }
195  PXR_NS::XUSD_RenderSettingsContext &impl() { return *myImpl; }
196 private:
197  PXR_NS::XUSD_RenderSettingsContext *myImpl;
198 };
199 
201  : public UT_NonCopyable
202 {
203 public:
204  HUSD_RenderVar();
205  virtual ~HUSD_RenderVar();
206 
207  /// Method to clone this render var to another render product
209  {
210  UT_UniquePtr<HUSD_RenderVar> v = doClone(); // Create new object
211  v->copyDataFrom(*this);
212  return v;
213  }
214 
215  /// @{
216  /// Query settings
217  UT_StringHolder aovName() const;
218  UT_StringHolder aovToken() const;
219  UT_StringHolder dataType() const;
220  UT_StringHolder sourceName() const;
221  UT_StringHolder sourceType() const;
222 
223  PXL_DataFormat pxlFormat() const;
224  PXL_Packing pxlPacking() const;
225  /// @}
226 
227  /// @{
228  /// Query the AOV settings on the underlying render settings map
229  bool lookup(const char *token, int64 &val) const;
230  bool lookup(const char *token, fpreal64 &val) const;
231  bool lookup(const char *token, UT_Vector2i &val) const;
232  bool lookup(const char *token, UT_StringHolder &val) const;
233  /// @}
234 
235  /// @{
236  /// For debugging
237  void dump() const;
238  void dump(UT_JSONWriter &w) const;
239  /// @}
240 
241  /// @private - Data for implementation
242  PXR_NS::XUSD_RenderVar *myOwner;
243 protected:
244  /// Create a new sub-class of HUSD_RenderVar
246  {
247  return UTmakeUnique<HUSD_RenderVar>();
248  }
249 private:
250  void copyDataFrom(const HUSD_RenderVar &src);
251 };
252 
254  : public UT_NonCopyable
255 {
256 public:
258  virtual ~HUSD_RenderProduct();
259 
260  /// Allocate a new render variable for this product
261  virtual UT_UniquePtr<HUSD_RenderVar> newRenderVar() const;
262 
263  /// Provide a default filename
265  { return UT_StringHolder(); }
266 
267  /// @{
268  /// Query settings on the underlying render settings map
269  bool lookup(const char *token, int64 &val) const;
270  bool lookup(const char *token, fpreal64 &val) const;
271  bool lookup(const char *token, UT_Vector2i &val) const;
272  bool lookup(const char *token, UT_StringHolder &val) const;
273  /// @}
274 
275  /// Create a "writer" to store settings in this objects settings
277 
278  /// Copy a property from the render settings to this render product
279  /// This is typically used during initialization (before the USD product
280  /// settings are applied).
281  void copySetting(const HUSD_RenderSettings &settings,
282  const char *token);
283 
284  /// Clone from a list of render vars
285  void addRenderVars(const UT_Array<const HUSD_RenderVar *> &vars);
286 
287  /// @{
288  /// Access render vars
289  exint size() const;
290  const HUSD_RenderVar *renderVar(exint i) const;
291  /// @}
292 
293  /// @{
294  /// Query methods
296  UT_StringHolder productName(int frame=0) const;
297  UT_StringHolder outputName() const; // Current product name
298  /// @}
299 
300  /// Test if the render product is a raster product
301  bool isRaster() const;
302 
303  /// @{
304  /// For debugging
305  void dump() const;
306  void dump(UT_JSONWriter &w) const;
307  /// @}
308 
309  /// Add meta data to the IMG_FileParms
310  void addMetaData(IMG_FileParms &fparms) const;
311 
312  /// @private - Data for implementation
313  PXR_NS::XUSD_RenderProduct *myOwner;
314 protected:
315  // Access to the current filename and partname
316  const UT_StringHolder &filename() const;
317  const UT_StringHolder &partname() const;
318 
319 };
320 
322  : public UT_NonCopyable
323 {
324 public:
326 
327  HUSD_RenderSettings(const UT_StringHolder &prim_path,
328  const UT_StringHolder &filename,
329  time_t file_timestamp);
330  virtual ~HUSD_RenderSettings();
331 
332  // Create directories required to create the file given by the path
333  static bool makeFilePathDirs(const char *path);
334 
335  virtual bool supportedDelegate(const UT_StringRef &name) const;
336 
337  /// Allocate a new HUSD_RenderProduct for this subclass
338  virtual UT_UniquePtr<HUSD_RenderProduct> newRenderProduct() const;
339 
340  /// Initialize the settings, loading the settings, products and render vars
341  /// from the path given. The context is able to override settings during
342  /// initialization.
343  bool init(const HUSD_HuskEngine &engine,
344  const UT_StringHolder &settings_path,
346 
347  /// Return the name for the dummy render product name when there are no
348  /// raster products being rendered.
349  static const char *huskNullRasterName();
350 
351  /// Resolve products defined in the engine. This is called separately from
352  /// initialization to allow the client to initialize the engine and check
353  /// for valid products. Resolving will bind the render var AOVs and set up
354  /// all the settings associated with the product. After products are
355  /// resolved, the products are partitioned into product groups.
356  ///
357  /// If there are no "raster" products, but there are delegate render
358  /// products, create a dummy raster product so that delegates will function
359  /// properly. Creation of the dummy product will set the product name to
360  /// `huskNullRaster()`. The dummy product will pick a render var
361  /// referenced by the delegate render products, and will fail if there are
362  /// no render vars on any delegate render products.
363  bool resolveProducts(const HUSD_HuskEngine &engine,
365  bool create_dummy_raster_product);
366 
367 
368  /// Set up to render the given @c frame and @c product_group. This will
369  /// update the husk engine contained in the settings context, expand all
370  /// the product filenames and optionally create output directories for the
371  /// products.
372  ///
373  /// See `resolveProducts()` for help on `create_dummy_render_product`
374  bool updateFrame(HUSD_RenderSettingsContext &ctx,
375  int frame,
376  int product_group,
377  bool make_product_directories,
378  bool process_delegate_products,
379  bool create_dummy_render_product);
380 
381  /// @{
382  /// Query settings on the underlying render setting
383  bool lookup(const char *token, int64 &val) const;
384  bool lookup(const char *token, fpreal64 &val) const;
385  bool lookup(const char *token, UT_Vector2i &val) const;
386  bool lookup(const char *token, UT_StringHolder &val) const;
387  /// @}
388 
389  /// Create a "writer" to store settings in this objects settings
391 
392  /// @{
393  /// Query settings that are shared with all products
394  UT_StringHolder renderer() const;
395  void purpose(UT_StringArray &purposes) const;
396  /// @}
397 
398  /// Return the output name for all the products in the product group
399  UT_StringHolder outputName(int product_group) const;
400 
401  /// @{
402  /// Query settings which can be overridden by products
403  UT_StringHolder cameraPath(const HUSD_RenderProduct *p) const;
404  double shutterOpen(const HUSD_RenderProduct *p) const;
405  double shutterClose(const HUSD_RenderProduct *p) const;
406  int xres(const HUSD_RenderProduct *p) const;
407  int yres(const HUSD_RenderProduct *p) const;
408  UT_Vector2i res(const HUSD_RenderProduct *p) const;
409  fpreal pixelAspect(const HUSD_RenderProduct *p) const;
410  UT_Vector4 dataWindowF(const HUSD_RenderProduct *p) const;
411  UT_DimRect dataWindow(const HUSD_RenderProduct *p) const;
412  bool disableMotionBlur(const HUSD_RenderProduct *p) const;
413 
414  UT_StringHolder cameraPath(int product_group) const
415  { return cameraPath(productInGroup(product_group)); }
416  double shutterOpen(int product_group) const
417  { return shutterOpen(productInGroup(product_group)); }
418  double shutterClose(int product_group) const
419  { return shutterClose(productInGroup(product_group)); }
420  int xres(int product_group) const
421  { return xres(productInGroup(product_group)); }
422  int yres(int product_group) const
423  { return yres(productInGroup(product_group)); }
424  UT_Vector2i res(int product_group) const
425  { return res(productInGroup(product_group)); }
426  fpreal pixelAspect(int product_group) const
427  { return pixelAspect(productInGroup(product_group)); }
428  UT_Vector4 dataWindowF(int product_group) const
429  { return dataWindowF(productInGroup(product_group)); }
430  UT_DimRect dataWindow(int product_group) const
431  { return dataWindow(productInGroup(product_group)); }
432  bool disableMotionBlur(int product_group) const
433  { return disableMotionBlur(productInGroup(product_group)); }
434  /// @}
435 
436  /// @{
437  /// For debugging
438  void dump() const;
439  void dump(UT_JSONWriter &w) const;
440  /// @}
441 
442  void printSettings() const;
443 
444  /// HUSD_RenderSettings will partition the HUSD_RenderProducts into
445  /// "groups". Each group has similar properties, for example, the same
446  /// rendering camera. This method returns the number of distinct product
447  /// groups.
448  exint productGroupSize() const;
449 
450  /// Get a list of all the render products in a given product group
451  void productGroup(int product_group, ProductGroup &products) const;
452 
453  /// Return the number of render products in a given render product group
454  exint productsInGroup(exint group) const;
455 
456  /// Get access to a product inside a product group
457  const HUSD_RenderProduct *product(exint prod_group, exint product) const;
458 
459  /// @private - Data for implementation
460  PXR_NS::XUSD_RenderSettings *myOwner;
461 
462 protected:
463  bool expandProducts(const HUSD_RenderSettingsContext &ctx,
464  int fnum,
465  int product_group);
466 
467  // Find any product in the given product group
468  const HUSD_RenderProduct *productInGroup(int product_group) const;
469 
470  exint totalProductCount() const;
471  void allProducts(ProductGroup &group) const;
472 
473  // Adding a product - this method will fail if the product has already been
474  // added to a different render setting.
475  bool addProduct(UT_UniquePtr<HUSD_RenderProduct> p, int prod_group);
476  void removeProduct(exint i);
477 };
478 
479 #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
HUSD_API const char * cameraDepth()
GLsizeiptr size
Definition: glcorearb.h:664
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
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.