HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
grapherOptions.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_EXEC_VDF_GRAPHER_OPTIONS_H
8 #define PXR_EXEC_VDF_GRAPHER_OPTIONS_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
15 #include "pxr/exec/vdf/grapher.h"
16 #include "pxr/exec/vdf/object.h"
17 
18 #include "pxr/base/tf/hashmap.h"
19 #include "pxr/base/tf/stl.h"
20 
21 #include <functional>
22 #include <string>
23 #include <vector>
24 
26 
27 class VdfNode;
28 
29 ////////////////////////////////////////////////////////////////////////////////
30 ///
31 /// \class VdfGrapherOptions
32 ///
33 /// This class can be used to configure aspects of VdfGrapher's output.
34 ///
36 {
37 
38 public:
39 
40  /// The display styles for nodes.
41  ///
42  /// DisplayStyleFull: this is the default style and draws the full node.
43  /// DisplayStyleNoLabels: this draws the node as a box with a name in it.
44  /// DisplayStyleSummary: this draws the node as a small filled circle.
45  ///
46  enum DisplayStyle {
50  };
51 
52  /// This typedef describes the function signature for callbacks used to
53  /// filter nodes out of the graph. Returns true if node should be in
54  /// the graph, false if it should be left out.
55  ///
56  using NodeFilterCallback = std::function<
57  bool (const VdfNode &nodeToFilter)>;
58 
59  /// This callback is used to determine what style a specific node should
60  /// be rendered with regardless what was set via SetDisplayStyle().
61  ///
62  using NodeStyleCallback = std::function<
63  DisplayStyle (
64  const VdfNode &node,
65  const VdfConnectionVector &drawnIn,
66  const VdfConnectionVector &drawnOut)>;
67 
68  /// This struct is used to allow the grapher to graph a subset of the
69  /// nodes.
70  ///
71  struct NodeLimit {
72  NodeLimit(const VdfNode *n, int maxin, int maxout) :
73  node(n),
74  maxInDepth(maxin),
75  maxOutDepth(maxout)
76  {}
77 
78  const VdfNode *node;
81  };
82 
83  typedef std::vector<NodeLimit> NodeLimitVector;
84 
85 public:
86 
87  VDF_API
89 
90  /// When \p drawMasks is \c true, the masks on the connections will
91  /// be drawn.
92  ///
93  void SetDrawMasks(bool drawMasks) { _drawMasks = drawMasks; }
94 
95  /// When \p drawMasks is \c true, the affects masks on node outputs will
96  /// be drawn. Setting this to true implies SetPrintSingleOutputs() true
97  /// as well.
98  ///
99  void SetDrawAffectsMasks(bool drawMasks) { _drawAffectsMasks = drawMasks; }
100 
101  /// Returns whether or not masks will be draw on the connections.
102  ///
103  bool GetDrawMasks() const { return _drawMasks; }
104 
105  /// Returns whether or not masks will be draw on the connections.
106  ///
107  bool GetDrawAffectsMasks() const { return _drawAffectsMasks; }
108 
109  /// When \p enable is false, nodes containing only a single output, won't
110  /// render their full connector to reduce clutter.
111  ///
112  void SetPrintSingleOutputs(bool enable) {
113  _printSingleOutputs = enable; }
114 
115  /// Returns true, if skipping single outputs is enabled.
116  ///
117  bool GetPrintSingleOutputs() const {
118  return _printSingleOutputs; }
119 
120  /// Sets the desired size of the page output. Setting the width and height
121  /// to -1 will disable the page statement in the dot file altogther (which
122  /// is useful when outputting as .tif file).
123  ///
124  void SetPageSize(double width, double height) {
125  _pageWidth = width;
126  _pageHeight = height;
127  }
128 
129  /// Returns the page height
130  ///
131  double GetPageHeight() const { return _pageHeight; }
132 
133  /// Returns the page width
134  ///
135  double GetPageWidth() const { return _pageWidth; }
136 
137  /// When \p uniqueIds is \c false, the graph will be printed without using
138  /// unique ids for node names and ports.
139  ///
140  /// This will likely produce a graph that is not valid for graphing,
141  /// but can be very useful for comparing output in a test, where we need ids
142  /// to be exactly the same after each run.
143  ///
144  void SetUniqueIds(bool uniqueIds) { _uniqueIds = uniqueIds; }
145 
146  /// Returns whether or not the graph should use unique ids.
147  ///
148  bool GetUniqueIds() const { return _uniqueIds; }
149 
150  /// When \p omit is set, unconnected specs will be omitted.
151  ///
152  void SetOmitUnconnectedSpecs(bool omit) { _omitUnconnectedSpecs = omit; }
153 
154  /// Returns whether or not the produced graph should include unconnected
155  /// specs (ie. input and output ports).
156  ///
157  bool GetOmitUnconnectedSpecs() const { return _omitUnconnectedSpecs; }
158 
159  /// When \p drawColorizedConnectionsOnly is set, only connections that have
160  /// a color set via SetColor() will be drawn.
161  ///
162  void SetDrawColorizedConnectionsOnly(bool drawColorizedConnectionsOnly) {
163  _drawColorizedConnectionsOnly = drawColorizedConnectionsOnly;
164  }
165 
166  /// Returns whether connections that have not a color set via SetColor()
167  /// should not be drawn.
168  ///
170  return _drawColorizedConnectionsOnly;
171  }
172 
173  /// Adds \p node to the list of nodes to be graphed.
174  ///
175  /// If this list is empty, the entire graph will be printed.
176  /// The parameters \p maxInDepth and \p maxOutDepth determine the
177  /// the depths of the traversal in both directions.
178  ///
179  void AddNodeToGraph(const VdfNode &node, int maxInDepth, int maxOutDepth) {
180  _nodesToGraph.push_back(NodeLimit(&node, maxInDepth, maxOutDepth));
181  }
182 
183  /// Sets a \p color for \p object which can be a connection or node.
184  ///
185  /// Color must be in a format that is understood by dot. Lowercase English
186  /// color names usually work, (e.g. "red", "green", "blue").
187  ///
188  void SetColor(const VdfObjectPtr &object, const TfToken &color) {
189 
190  if (!color.IsEmpty())
191  _objectColors[object] = color;
192  }
193 
194  /// Returns the color for \p object or the empty TfToken if none was set.
195  ///
196  TfToken GetColor(const VdfObjectPtr &object) const {
197  return TfMapLookupByValue(_objectColors, object, TfToken());
198  }
199 
200  /// Sets an annotation \p text for \p object which gets rendered for the
201  /// object.
202  ///
203  void SetAnnotation(const VdfObjectPtr &object, const std::string &text) {
204  _objectAnnotations[object] = text;
205  }
206 
207  /// Returns the annotation for \p object or the empty string if none was
208  /// set.
209  ///
210  std::string GetAnnotation(const VdfObjectPtr &object) const {
211  return TfMapLookupByValue(_objectAnnotations, object, std::string());
212  }
213 
214  /// Returns the list of nodes that should be graphed.
215  ///
216  const NodeLimitVector &GetNodesToGraph() const { return _nodesToGraph; }
217 
218  /// Sets the callback used used to filter nodes out of the graph.
219  ///
220  /// If callback returns true the node should be in the graph,
221  /// if false if it should be left out.
222  ///
224  _nodeFilterCallback = callback;
225  }
226 
227  /// Returns the callback used to filter nodes out of the graph
229  return _nodeFilterCallback;
230  }
231 
232  /// Sets the callback used used to style nodes. This style will override
233  /// the default style set via SetDisplayStyle().
234  ///
235  void SetNodeStyleCallback(const NodeStyleCallback &callback) {
236  _nodeStyleCallback = callback;
237  }
238 
239  /// Returns the (optional) callback used to style nodes.
240  ///
242  return _nodeStyleCallback;
243  }
244 
245  /// Filters nodes based on debug names, when used as a NodeFilterCallback.
246  ///
247  /// If any of the strings in \p nameList are a substring of the debug
248  /// name of \p node, returns \p includeIfInNameList, including/excluding
249  /// \p node from the graph.
250  ///
251  VDF_API
252  static bool DebugNameFilter(
253  const std::vector<std::string> &nameList,
254  bool includeIfInNameList,
255  const VdfNode &node );
256 
257  /// Sets the default display style for nodes.
258  ///
260  _displayStyle = style;
261  }
262 
263  /// Returns the default display style for a node.
264  ///
265  DisplayStyle GetDisplayStyle() const { return _displayStyle; }
266 
267 private:
268 
269  // Draws the masks on the connections if true.
270  bool _drawMasks;
271 
272  // Draws the affects masks on outputs if true.
273  bool _drawAffectsMasks;
274 
275  // The width of the page
276  double _pageWidth;
277 
278  // The height of the page
279  double _pageHeight;
280 
281  // Determines whether or not unique IDs are used.
282  bool _uniqueIds;
283 
284  // The subset of nodes to draw. If this list is empty, everything
285  // in the network is drawn.
286  NodeLimitVector _nodesToGraph;
287 
288  // The callback used to filter nodes out of the graph.
289  NodeFilterCallback _nodeFilterCallback;
290 
291  // The callback used to style nodes.
292  NodeStyleCallback _nodeStyleCallback;
293 
294  // The display style for the nodes
295  DisplayStyle _displayStyle;
296 
297  // If true, nodes that have a single output, will render that output.
298  bool _printSingleOutputs;
299 
300  // Map of colored objects to color name.
302 
303  // Map of annotated objects to annotation.
305 
306  // If true, unconnected inputs/outputs will be omitted.
307  bool _omitUnconnectedSpecs;
308 
309  // If true, draw connections with explicitly SetColor() only.
310  bool _drawColorizedConnectionsOnly;
311 };
312 
314 
315 #endif
bool GetPrintSingleOutputs() const
VDF_API VdfGrapherOptions()
void AddNodeToGraph(const VdfNode &node, int maxInDepth, int maxOutDepth)
double GetPageWidth() const
NodeLimit(const VdfNode *n, int maxin, int maxout)
const NodeFilterCallback & GetNodeFilterCallback() const
Returns the callback used to filter nodes out of the graph.
void SetPageSize(double width, double height)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
std::function< DisplayStyle(const VdfNode &node, const VdfConnectionVector &drawnIn, const VdfConnectionVector &drawnOut)> NodeStyleCallback
double GetPageHeight() const
std::string GetAnnotation(const VdfObjectPtr &object) const
Definition: node.h:52
std::vector< NodeLimit > NodeLimitVector
DisplayStyle GetDisplayStyle() const
void SetDrawColorizedConnectionsOnly(bool drawColorizedConnectionsOnly)
#define VDF_API
Definition: api.h:25
OutGridT const XformOp bool bool
static VDF_API bool DebugNameFilter(const std::vector< std::string > &nameList, bool includeIfInNameList, const VdfNode &node)
void SetColor(const VdfObjectPtr &object, const TfToken &color)
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
GLdouble n
Definition: glcorearb.h:2008
void SetNodeStyleCallback(const NodeStyleCallback &callback)
Definition: token.h:70
void SetDrawAffectsMasks(bool drawMasks)
std::function< bool(const VdfNode &nodeToFilter)> NodeFilterCallback
bool GetDrawMasks() const
void SetOmitUnconnectedSpecs(bool omit)
void SetDisplayStyle(DisplayStyle style)
void SetAnnotation(const VdfObjectPtr &object, const std::string &text)
const NodeLimitVector & GetNodesToGraph() const
GLuint color
Definition: glcorearb.h:1261
bool GetDrawColorizedConnectionsOnly() const
TfToken GetColor(const VdfObjectPtr &object) const
bool GetDrawAffectsMasks() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GLint GLsizei width
Definition: glcorearb.h:103
bool GetUniqueIds() const
const NodeStyleCallback & GetNodeStyleCallback() const
void SetPrintSingleOutputs(bool enable)
void SetNodeFilterCallback(const NodeFilterCallback &callback)
bool GetOmitUnconnectedSpecs() const
void SetDrawMasks(bool drawMasks)
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:288
void SetUniqueIds(bool uniqueIds)
const Result TfMapLookupByValue(Container const &map, Key const &key, const Result &defaultValue)
Definition: stl.h:95