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