HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_Muscle.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: SOP_Muscle.h (SOP Library, C++)
7  *
8  * COMMENTS: A SOP that generates a muscle object using a
9  * metaball surface.
10  *
11  */
12 
13 #ifndef __SOP_Muscle_h__
14 #define __SOP_Muscle_h__
15 
16 #include "SOP_API.h"
17 #include <CH/CH_Channel.h>
18 #include <PRM/PRM_Include.h>
19 #include <PRM/PRM_Shared.h>
20 #include <PRM/PRM_Name.h>
21 #include <UT/UT_ValArray.h>
22 #include <UT/UT_Array.h>
23 #include <UT/UT_FloatArray.h>
24 #include "SOP_Node.h"
25 
26 enum {
28 
29 #define SOP_MUSCLE_NUM_MUSCLE_PARMS (25)
34 
35 #define SOP_MUSCLE_NUM_MODEL_PARMS (17)
37 
39 
43 
48 
53 
58 
61 
63 
65 
66 #define SOP_MUSCLE_NUM_PREFERENCE_PARMS (5)
72 
73 #define SOP_MUSCLE_NUM_CENTERLINE_PARMS (5)
79 
81 };
82 
83 // Display types
87 };
88 
89 // Contro types
93 };
94 
95 #define NUM_SEGMENTS 4
96 #define DEFAULT_CENTER_GROUP "center"
97 
98 class GU_DetailHandle;
99 class GU_PrimPoly;
100 class GU_MuscleParms;
101 class GU_Muscle;
102 
103 class UT_String;
104 
106 {
107 public:
108  SOP_Muscle(OP_Network *net, const char *name, OP_Operator *entry);
109  ~SOP_Muscle() override;
110 
111  bool updateParmsFlags() override;
112 
113  static OP_Node *myConstructor(OP_Network *net, const char *name,
114  OP_Operator *entry);
115 
116  static PRM_Template myTemplateList[];
117 
118  // A function used to indicate to this node that its color gradient
119  // channel has been changed
121  { myGradientChanged = true; }
122 
123  // Indicate to this node that the input names have been changed,
124  // so that we can update myAnchorInputs
125  void changeInputs();
126 
127  bool getTranslates(OP_Context &context,
128  UT_Array<UT_Matrix4> &translates);
129 
130  bool getRotates(OP_Context &context,
131  UT_Array<UT_Matrix4> &rotates);
132 
133  const GEO_PrimPoly *getCenterCurve(OP_Context &context);
134 
136  {
137  color[0] = myCurrColorValuesRGB[0];
138  color[1] = myCurrColorValuesRGB[1];
139  color[2] = myCurrColorValuesRGB[2];
140  }
141 
142 protected:
143  OP_ERROR cookMySop(OP_Context &context) override;
144  const char *inputLabel(unsigned idx) const override;
145 
146  // Overridden function so that we can determine whether or not
147  // any of the profile changes have been modified prior to a cook
149  CH_Channel *ch,
150  CH_CHANGE_TYPE reason) override;
151 
152 private:
153 
154  // A function used to set up extra inputs based on the specified
155  // muscle anchor points. Also modifieds numInputs to store the
156  // actual number of inputs added
157  OP_ERROR setupInputs(int numInputs);
158 
159  // A function which is called when a failure occurs during cooking
160  void cookFailed();
161 
162  // A function that sets up color gradient values, so that we don't
163  // have to evaluate the parameter 20 times every time we cook.
164  void setupGradientValues(int numMeta, fpreal t);
165 
166  // Verify that the muscle name specified is proper.
167  void verifyNames();
168 
169  void setupMuscleParms(GU_MuscleParms &parms,
170  fpreal &t);
171 
172  bool getInputsChanged();
173 
174  GU_Muscle *getGUMuscle();
175 
176  // Functions for retrieving user-specified parameters
177  int NUMINPUTS()
178  {
179  return evalInt(SOP_MUSCLE_NUMINPUTS, 0, 0);
180  }
181 
182  void INPUTSTRING(int i, UT_String &str)
183  {
184  evalStringInst("inputname#", &i, str, 0, 0);
185  }
186 
187  void RESTANCHOR(UT_String &str)
188  {
189  evalString(str, SOP_MUSCLE_RESTANCHOR, 0, 0);
190  }
191 
192  void CENTERGROUP(UT_String &str)
193  {
194  str = DEFAULT_CENTER_GROUP;
195  }
196 
197  float POSITIONBIAS()
198  {
199  return evalFloat(SOP_MUSCLE_POSITIONBIAS, 0, 0);
200  }
201 
202  SOP_MuscleType MUSCLETYPE()
203  {
204  int type = evalInt(SOP_MUSCLE_TYPE, 0, 0);
205 
206  switch (type)
207  {
208  case SOP_MUSCLE_META:
209  return SOP_MUSCLE_META;
210  case SOP_MUSCLE_SPHERE:
211  return SOP_MUSCLE_SPHERE;
212  default:
213  return SOP_MUSCLE_META;
214  }
215  }
216 
217  void MUSCLENAME(UT_String &str)
218  {
219  evalString(str, SOP_MUSCLE_NAME, 0, 0);
220  }
221 
222  bool DOCOLOR()
223  {
224  return evalInt(SOP_MUSCLE_COLORTOGGLE, 0, 0);
225  }
226 
227  float CR(fpreal t)
228  {
229  return evalFloat(SOP_MUSCLE_COLOR, 0, t);
230  }
231 
232  float CG(fpreal t)
233  {
234  return evalFloat(SOP_MUSCLE_COLOR, 1, t);
235  }
236 
237  float CB(fpreal t)
238  {
239  return evalFloat(SOP_MUSCLE_COLOR, 2, t);
240  }
241 
242  int BASIS()
243  {
244  return evalInt(SOP_MUSCLE_BASIS, 0, 0);
245  }
246 
247  int SAMPLEDIVS(fpreal t)
248  {
249  return evalInt(SOP_MUSCLE_SAMPLEDIVS, 0, t);
250  }
251 
252  int FIRSTCV(fpreal t)
253  {
254  return evalInt(SOP_MUSCLE_FIRSTCV, 0, t);
255  }
256 
257  int LASTCV(fpreal t)
258  {
259  return evalInt(SOP_MUSCLE_LASTCV, 0, t);
260  }
261 
262  float CVTENSION(fpreal t)
263  {
264  return evalFloat(SOP_MUSCLE_CVTENSION, 0, t);
265  }
266 
267  bool DOGRADIENT()
268  {
269  return evalInt(SOP_MUSCLE_ENABLEGRADIENT, 0, 0);
270  }
271 
272  float GRADIENT(fpreal t)
273  {
274  return evalFloat(SOP_MUSCLE_GRADIENT, 0, t);
275  }
276 
277  float CONTROL1SCALE(int i, fpreal t)
278  {
279  return evalFloat(SOP_MUSCLE_CONTROL1SCALE, i, t);
280  }
281 
282  float CONTROL2SCALE(int i, fpreal t)
283  {
284  return evalFloat(SOP_MUSCLE_CONTROL2SCALE, i, t);
285  }
286 
287  float CONTROL3SCALE(int i, fpreal t)
288  {
289  return evalFloat(SOP_MUSCLE_CONTROL3SCALE, i, t);
290  }
291 
292  float CONTROL4SCALE(int i, fpreal t)
293  {
294  return evalFloat(SOP_MUSCLE_CONTROL4SCALE, i, t);
295  }
296 
297  float CONTROL5SCALE(int i, fpreal t)
298  {
299  return evalFloat(SOP_MUSCLE_CONTROL5SCALE, i, t);
300  }
301 
302  float CONTROL2POS(fpreal t)
303  {
304  return evalFloat(SOP_MUSCLE_CONTROL2POS, 0, t);
305  }
306 
307  float CONTROL3POS(fpreal t)
308  {
309  return evalFloat(SOP_MUSCLE_CONTROL3POS, 0, t);
310  }
311 
312  float CONTROL4POS(fpreal t)
313  {
314  return evalFloat(SOP_MUSCLE_CONTROL4POS, 0, t);
315  }
316 
317  int PRIMSPERSEGMENT()
318  {
319  return evalInt(SOP_MUSCLE_PRIMSPERSEGMENT, 0, 0);
320  }
321 
322  float MUSCLESCALE(int i, fpreal t)
323  {
324  return evalFloat(SOP_MUSCLE_SCALE, i, t);
325  }
326 
327 private:
328 
329  // Stores the primitives (spheres or metaballs)
330  // currently used by this muscle
331  GA_PrimitiveGroup *myPrimitives;
332 
333  // Stores the number of metaballs we are currently
334  // storing
335  int myNumPrimitives;
336 
337  // Stores the centre curve for this muscle
338  //GU_PrimPoly *myCenterCurve;
339 
340  // Stores the centre curve points for this
341  // muscle
342  GA_PointGroup *myCenterPoints;
343 
344  // An array storing the object inputs for the muscle
345  UT_ValArray<OP_Node *> myAnchorInputs;
346 
347  // Stores SOP inputs for the muscle anchor points, if
348  // they are to be used
349  UT_ValArray<SOP_Node *> mySOPInputs;
350 
351  // An array of inputs storing the gdh's for our SOP inputs
352  UT_Array<GU_DetailHandle> myAnchorGdhs;
353 
354  // An array of gdps for our SOP inputs
355  UT_ValArray<const GU_Detail *> myAnchorGdps;
356 
357  // Cached input paths, so that we can avoid having to do
358  // parameter evaluation every cook
359  UT_Array<UT_String> myAnchorPaths;
360 
361  // Flags to indicate when the colour gradient has been changed
362  // and needs to be updated
363  bool myGradientChanged;
364 
365  // An array used to store gradient values
366  UT_FloatArray myGradientValues;
367 
368  // Color values of the muscle as it was last cooked
369  UT_Vector3 myCurrColorValuesRGB;
370 
371  // A flag to indicate that this node is "dirty" - set after
372  // a cook fails so that everything gets rebuilt in the next
373  // cook
374  bool myIsDirty;
375 
376  // Flag to indicate that the input names have changed -
377  // TODO: when it is actually used, clear at the end of each cook
378  bool myInputsChanged;
379 
380  // The current muscle type
381  SOP_MuscleType myCurrentType;
382 
383  // An extra gdp used to generate any intermediate geometry
384  // required during a cook
385  GU_Detail *myExtraGdp;
386 
387  GU_Muscle *myMuscle;
388 
389  GU_MuscleParms *myMuscleParms;
390 };
391 
392 #endif
virtual bool updateParmsFlags()
virtual const char * inputLabel(unsigned idx) const
fpreal evalFloat(int pi, int vi, fpreal t) const
UT_ErrorSeverity
Definition: UT_Error.h:25
#define DEFAULT_CENTER_GROUP
Definition: SOP_Muscle.h:96
void checkChannelDependencies(CH_Channel *ch, CH_CHANGE_TYPE reason) override
sop_MuscleControlType
Definition: SOP_Muscle.h:90
CH_CHANGE_TYPE
void getCurrColorValues(UT_Vector3 &color)
Definition: SOP_Muscle.h:135
void evalString(UT_String &val, int pi, int vi, fpreal t) const
GLuint const GLchar * name
Definition: glcorearb.h:786
GLdouble t
Definition: glad.h:2397
void evalStringInst(const UT_StringRef &name, const int *inst, UT_String &val, int vi, fpreal t, int nestlevel=1) const
GLuint color
Definition: glcorearb.h:1261
fpreal64 fpreal
Definition: SYS_Types.h:277
void changeGradient()
Definition: SOP_Muscle.h:120
#define SOP_API
Definition: SOP_API.h:10
exint evalInt(int pi, int vi, fpreal t) const
SOP_MuscleType
Definition: SOP_Muscle.h:84
virtual OP_ERROR cookMySop(OP_Context &context)=0
type
Definition: core.h:1059