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;
51  void getOutputs(DEP_MicroNodeList &inputs) const;
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_Primtive 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 
172 
173 private:
174  // Type is set by the VIS_VisualizerType class which is
175  // used to create a visualizer instances.
176  friend class VIS_Type;
177  friend class VIS_Table;
178  friend class VIS_Mount;
179  friend class VIS_Manager;
180  friend class VISF_Dispatcher;
181  friend class VISF_Setup;
182 
183  void setTypeId(int id) { myTypeId = id; }
184  void setMount(VIS_Mount *mnt) { myMount = mnt; }
185 
186  bool refinementRequested(bool reset = true);
187  bool updateRequested(bool reset = true);
188 
189  UT_StringArray &getRequestedAttributes()
190  { return myRequestedAttributes; }
191 
192  /// Called whenever a parameter is changed
193  void bumpVersion() { myParmsVersion++; }
194 
195  /// Call by DM_VPortAgent in each render cycle to
196  bool setup();
197 
198  static void handleParmsChange(void *, CH_CHANGE_TYPE, int);
199 
200  static int theLastVisSerialNum;
201 
202  // data members
203 
204  int myTypeId;
205  uint32 myFlags;
206 
207  bool myRefinementRequested : 1;
208  bool myUpdateRequested: 1;
209  bool myClearRequestedAttribs : 1;
210  UT_StringArray myRequestedAttributes;
211 
212  int mySerialNum; // bumped upon creation
213  // to notice mount type changes
214  int myParmsVersion; // bumped when parms change
215  int myCookVersion; // cathes up with myParmsVersion
216  // after cooking
217 
218  UT_Lock myCookLock; // must acquired before
219  // cooking the visualiezer
220 
221  VIS_Mount *myMount;
222  VIS_ParmsMicroNode myParmsMicroNode;
223 
224 };
225 
227 {
228 public:
230  myVisUniqueId(-1),
231  myVisualizedNodes(NULL)
232  {}
233  void setVisUniqueId(int id)
234  { myVisUniqueId = id; }
236  { return myVisUniqueId; }
237  void setVisualizedNode(UT_IntArray const *nodes)
238  { myVisualizedNodes = nodes; }
240  { return myVisualizedNodes; }
241 private:
242  int myVisUniqueId;
243  UT_IntArray const *myVisualizedNodes; // Used as hint of what nodes
244  // are being visualized to help
245  // populate attrib/group menu
246 };
247 
248 #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:270
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:36