HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VIS_Visualizer.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: VIS_Visualizer.h (VIS Library, C++)
7  *
8  * COMMENTS:
9  * A VIS_Visualizer is a custom display option which can be toggled on/off
10  * and contain any arbitrary settings.
11  */
12 
13 #ifndef __VIS_Visualizer__
14 #define __VIS_Visualizer__
15 
16 #include "VIS_API.h"
17 #include "VIS_Defines.h"
18 #include "VIS_Handle.h"
19 
20 #include <UT/UT_Lock.h>
21 #include <UT/UT_Options.h>
22 #include <UT/UT_String.h>
23 #include <UT/UT_Vector3.h>
24 #include <UT/UT_VectorTypes.h>
25 
26 #include <UT/UT_JSONParser.h>
27 #include <UT/UT_JSONWriter.h>
28 
29 #include <CH/CH_EventManager.h>
30 
31 #include <PRM/PRM_ParmList.h>
32 #include <PRM/PRM_Template.h>
33 
34 #include <GA/GA_Types.h>
35 
36 
37 class VIS_Visualizer;
38 class VIS_Mount;
39 class VIS_Type;
40 class VIS_Primitive;
41 class VISF_Visualizer;
42 class GUI_DetailLook;
43 class GUI_GeoRender;
44 class UT_Ramp;
45 
47 {
48 public:
49  VIS_ParmsMicroNode(VIS_Visualizer *vis) : myVisualizer(vis) {}
50  void getInputs(DEP_MicroNodeList &inputs) const override;
51  void getOutputs(DEP_MicroNodeList &inputs) const override;
52 
53 private:
54  VIS_Visualizer *myVisualizer;
55 };
56 
58 {
59 public:
61  virtual ~VIS_Visualizer();
62 
63  PRM_ParmList *getParmList();
64 
65  /// This virtual is called when a visualizer parameter is changed
66  /// to allow changing the visibility or enabled state of related
67  /// parameters.
68  virtual bool updateParmsFlags() { return false; }
69 
70  virtual
71  PRM_Template *getTemplateList() const = 0;
72 
73  /// Helper methods to enable/disable or set visibility of parameters
74  bool enableParm(const char *pn, int state, int v = -1);
75  bool setVisibleState(const char *pn, bool state, int v = -1);
76 
77  /// Save and load method: these only write or read the visualizers
78  /// parameters to or from the given stream.
79  bool save(std::ostream &os);
80  bool load(UT_IStream &is);
81 
82  int getTypeId() const { return myTypeId; }
83 
84  VIS_ParmsMicroNode *getParmsMicroNode() { return &myParmsMicroNode; }
85 
86  /// Request for an update or refinement due to changes in visualizer
87  /// parameters. These are to be used only from the visualizers cook
88  /// method (cookMyVisualizer). They take effect if the visualizer is
89  /// active in some context or else when the visualizer becomes first
90  /// active in some context. Note that the flags NeedsRefine and
91  /// NeedsUpdate ensure that a refinement or update is triggered for
92  /// the visualizer if it has "missed" the latest occurrence of these
93  /// events due to being inactive. However, the visualizer must explicitly
94  /// request for updates or refinements after cooking its parameters or else
95  /// its parameter list version is not bumped. This is to prevent
96  /// automatic updates and refinements due to parameter change and to only
97  /// trigger them for changes to parameters that truly affect the
98  /// existing or created geometry.
99  void requestRefinement();
100  void requestUpdate();
101 
102  /// Request the named attribute be "filled" during the update
103  /// of any GR_Primitive in a detail on which this visualizer acts.
104  /// This is used, e.g., for preparing decoration rendering based
105  /// on a particualr attribute.
106  void requestAttribute(const char *attr,
107  GA_AttributeOwner owner =
109 
110  VIS_Mount *getMount() const { return myMount; }
111 
112  /// Get or set one or more of the visualizer flags.
113  uint32 getFlags(uint32 mask) const;
114  void setFlags(uint32 mask, bool onoff);
115 
116  // Helper callbacks for Attribute and Group Parameters
117  static void buildGroups(void *data,
118  PRM_Name *menuEntries,
119  int thelistsize,
120  const PRM_SpareData *spare,
121  const PRM_Parm *parm);
122 
123  static void buildAttributes(void *data,
124  PRM_Name *menuEntries,
125  int thelistsize,
126  const PRM_SpareData *spare,
127  const PRM_Parm *parm);
128 
129  void updateRampFromMultiParm(fpreal t,
130  const PRM_Parm &m,
131  UT_Ramp &ramp,
132  bool *time_dep = NULL);
133 
134  /// Returns the visualizer's construction serial number. This
135  /// is copied from a global counter which is incremented each time
136  /// a visualizer (of any type) is created. It is used, e.g., in
137  /// VISF_Primitive to ensure that visualizer being referenced by the
138  /// primitive is the same as the one which has created it.
139  int getSerialNum() { return mySerialNum; }
140 
141  /// We may need to bump the serial number manually. One example is
142  /// when the visualizer is moved from one table to another, particularly
143  /// from one node's table to another.
144  void bumpSerialNum();
145 
146 
147  /// Set the values of common parameters to those of other_vis.
148  virtual void copyParmValues(const VIS_Visualizer *other_vis);
149 
150  virtual VISF_Visualizer *castToVISF();
151 
152 protected:
153  /// Copy constructore
155 
156  /// cookMyVisualizer is called during prior to a viewport render
157  /// if since the last "cook" the visualizer parameters have changed.
158  /// The purpose of cookMyVisualizer method is to:
159  /// 1. read the parameters and cache their values,
160  /// 2. determine whether any of the changes in parameters warrant
161  /// requesting for an update or refinement and submit the request,
162  /// 3. set visualizer flags according to its current state,
163  /// 4. possibly anything else that involves changing the member
164  /// variables of the visualizer particularly since essentially
165  /// all other virtual methods on a visualizer, most importatly
166  /// createPrimitive and filterPrimitive are const due to
167  /// fact that at the state of the visualizer should not change
168  /// by or depend on its processing of any particular primitive.
169  virtual void cookMyVisualizer() = 0;
170 
171  int cookVersion() const { return myCookVersion; }
172 
174 private:
175  // Type is set by the VIS_VisualizerType class which is
176  // used to create a visualizer instances.
177  friend class VIS_Type;
178  friend class VIS_Table;
179  friend class VIS_Mount;
180  friend class VIS_Manager;
181  friend class VISF_Dispatcher;
182  friend class VISF_Setup;
183 
184  void setTypeId(int id) { myTypeId = id; }
185  void setMount(VIS_Mount *mnt) { myMount = mnt; }
186 
187  bool refinementRequested(bool reset = true);
188  bool updateRequested(bool reset = true);
189 
190  UT_StringArray &getRequestedAttributes()
191  { return myRequestedAttributes; }
192 
193  /// Called whenever a parameter is changed
194  void bumpVersion() { myParmsVersion++; }
195 
196  /// Call by DM_VPortAgent in each render cycle to
197  bool setup();
198 
199  static void handleParmsChange(void *, CH_CHANGE_TYPE, int);
200 
201  static int theLastVisSerialNum;
202 
203  // data members
204 
205  int myTypeId;
206  uint32 myFlags;
207 
208  bool myRefinementRequested : 1;
209  bool myUpdateRequested: 1;
210  bool myClearRequestedAttribs : 1;
211  UT_StringArray myRequestedAttributes;
212 
213  int mySerialNum; // bumped upon creation
214  // to notice mount type changes
215  int myParmsVersion; // bumped when parms change
216  int myCookVersion; // cathes up with myParmsVersion
217  // after cooking
218 
219  UT_Lock myCookLock; // must acquired before
220  // cooking the visualiezer
221 
222  VIS_Mount *myMount;
223  VIS_ParmsMicroNode myParmsMicroNode;
224 
225 };
226 
228 {
229 public:
231  myVisUniqueId(-1),
232  myVisualizedNodes(NULL)
233  {}
234  void setVisUniqueId(int id)
235  { myVisUniqueId = id; }
237  { return myVisUniqueId; }
238  void setVisualizedNode(UT_IntArray const *nodes)
239  { myVisualizedNodes = nodes; }
241  { return myVisualizedNodes; }
242 private:
243  int myVisUniqueId;
244  UT_IntArray const *myVisualizedNodes; // Used as hint of what nodes
245  // are being visualized to help
246  // populate attrib/group menu
247 };
248 
249 #endif
VIS_ParmsMicroNode(VIS_Visualizer *vis)
void setVisualizedNode(UT_IntArray const *nodes)
const GLdouble * v
Definition: glcorearb.h:837
UT_IntArray const * getVisualizedNodes()
int getFlags(int version)
Definition: ImfVersion.h:104
void getOutputs(DEP_MicroNodeList &inputs) const override
GLboolean reset
Definition: glad.h:5138
CH_CHANGE_TYPE
int cookVersion() const
GLint GLuint mask
Definition: glcorearb.h:124
GLuint id
Definition: glcorearb.h:655
#define VIS_API
Definition: VIS_API.h:10
VIS_Mount * getMount() const
GLdouble t
Definition: glad.h:2397
GA_AttributeOwner
Definition: GA_Types.h:35
int getTypeId() const
fpreal64 fpreal
Definition: SYS_Types.h:277
Utility class for containing a color ramp.
Definition: UT_Ramp.h:92
VIS_ParmsMicroNode * getParmsMicroNode()
void getInputs(DEP_MicroNodeList &inputs) const override
void setVisUniqueId(int id)
unsigned int uint32
Definition: SYS_Types.h:40
virtual bool updateParmsFlags()
PRM_ParmList * myParmList
Definition: format.h:895
GLenum src
Definition: glcorearb.h:1793