HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_Lattice.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_Lattice.h (C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 
13 #ifndef __SOP_Lattice_h__
14 #define __SOP_Lattice_h__
15 
16 #include "SOP_API.h"
17 #include "SOP_Node.h"
18 
19 #include <GEO/GEO_PointTree.h>
20 
21 #include <math.h>
22 
23 
25 {
26 public:
28  float weight;
29 };
30 
31 class TS_MetaKernel;
32 
34 {
35 public:
36  SOP_Lattice(OP_Network *net, const char *name, OP_Operator *entry);
37  ~SOP_Lattice() override;
38 
40  int alone = 0) override;
41  int isRefInput(unsigned int i) const override;
42 
43  bool updateParmsFlags() override;
44 
45  bool unloadData() override;
46 
47  static OP_Node *myConstructor(OP_Network *net,
48  const char *name,
49  OP_Operator *entry);
50  static PRM_Template myTemplateList[];
51 
52  enum {
53  SOP_LATTICE_LATTICE = 0,
54  SOP_LATTICE_POINTCLOUD = 1
55  };
56 
57 protected:
58  OP_ERROR cookMySop(OP_Context &context) override;
59  OP_ERROR cookMyGuide1(OP_Context &context) override;
60  OP_ERROR cookMyGuide2(OP_Context &context) override;
61  const char *inputLabel(unsigned idx) const override;
62 
63 private:
64  void getGroups(UT_String &str, fpreal t)
65  { evalString(str, 0, 0, t); }
66 
67 
68  /// Correct any points we deformed during our last lattice pass
69  /// that are no longer within our lattice's area of deformation. See
70  /// cookMySop() for more details. This is for latticeDeform() only at the
71  /// moment, since pointDeform() currently always duplicates our source and
72  /// hence doesn't need to do this
73  void correctOldPoints(const GU_Detail *src, UT_BitArray &curr_pass);
74 
75  int DEFORMTYPE() { return evalInt(1, 0, 0); }
76 
77  int DIVSX(fpreal t) { return evalInt(2, 0, t); }
78  int DIVSY(fpreal t) { return evalInt(2, 1, t); }
79  int DIVSZ(fpreal t) { return evalInt(2, 2, t); }
80 
81  int INTERPTYPE() { return evalInt(3, 0, 0); }
82 
83  void RESTGROUP(UT_String &str, fpreal t)
84  { evalString(str, 4, 0, t); }
85 
86  void KERNEL(UT_String &str, fpreal t) { evalString(str, 5, 0, t); }
87  float RADIUS(fpreal t) { return evalFloat(6, 0, t); }
88  float NORMTHRESHOLD() { return evalFloat(7, 0, 0); }
89  int VISUALIZE() { return evalInt(8, 0, 0); }
90 
91  /// If we want the Lattice SOP to do a Lattice deformation, we call this
92  /// helper method. The caller of this method is expected to lock and
93  OP_ERROR latticeDeform (OP_Context &context);
94 
95  /// If we want the Lattice SOP to deform the points individually, we call
96  /// this helper method. The caller of this method is expected to lock and
97  /// unlock the inputs.
98  OP_ERROR pointDeform (OP_Context &context);
99 
100  /// Helper method to build our point tree. Will only build if myPointTree
101  /// is NULL. WARNING: Make sure this is called only within cookMySop(),
102  /// because it depends on myGroup, which will be invalid once cookMySop()
103  /// exits if the group was adhoc
104  void buildPointTree();
105 
106  /// Helper method to build our capture regions for our gdp's points. Will
107  /// only build if myRegions is NULL. WARNING: Make sure this is called only
108  /// within cookMySop(), because it depends on myRestGroup, which will be
109  /// invalid once cookMySop() exits if the group was adhoc
110  void buildCaptureRegions(const GU_Detail *rest,
111  const TS_MetaKernel *kernel,
112  const UT_FloatArray &curr_radii);
113 
114  /// Calculates the radius for each point in our 'rest' input and stores it
115  /// in curr_radii in the index corresponding to the point's number. Also
116  /// compares these new radii with the old ones in myOldRadii and returns
117  /// true if any of one of them are different, false otherwise. This method
118  /// will resize 'curr_radii' and 'myOldRadii' as necessary. WARNING: Make
119  /// sure this is called only within cookMySop(), because it depends on
120  /// myRestGroup, which will be invalid once cookMySop() exits if the group
121  /// was adhoc
122  bool calculateRadii(UT_FloatArray &curr_radii,
123  const GU_DetailHandle &rest_handle,
124  fpreal time);
125 
126  /// Small helper method to clean up the code. Deforms all points in source
127  /// affected by point in the rest geo specified by 'index'. Note that
128  /// 'index' is really the index for that point in 'diffarray' in
129  /// pointDeform(), which is not necessarily the true index/number of the
130  /// point (point->getNum()) when we have a rest group.
131  inline void deformSourcePointsForMe(int index, UT_Vector3 *diffarray);
132 
133  /// Small helper method to clean up the code. Creates the capture region for
134  /// the point position in the rest geo specified by 'pos'.
135  inline void createCaptureRegionForMe(int index, const TS_MetaKernel *kernel,
136  const UT_FloatArray &curr_radii,
137  UT_FloatArray &totals,
138  const UT_Vector3 &pos);
139 
140  GEO_PointTreeGAOffset *myPointTree;
141  int myNumRegions;
142 
143  /// One per point of rest geo. First int is number of captured points, then
144  /// are the capture data.
145  sop_capturedata **myRegions;
146 
147  int mySourceCookCount;
148  int myRestCookCount;
149 
150  /// When we cook our guide geometry and want to draw spheres around the
151  /// the guide's points to visualize the radius, we need to have the rest
152  /// group to iterate through (if one exists). But myRestGroup might be
153  /// adhoc, in which case it will be destroyed after cookMySop() completes.
154  /// So either we parse/create the point groups in the rest geo again in
155  /// cookMyGuide() (expensive), or we keep a simple array to remember the
156  /// points' indices.
157  GA_IndexArray myRestOffsetArray;
158 
159  UT_FloatArray myOldRadii;
160  UT_String myOldMethod;
161  float myOldThreshold; // normalization threshold
162 
163  /// Keeps track of which points in our src we change
164  UT_BitArray myLatticeDeformHistory;
165 
166  const GA_PointGroup *myGroup;
167  const GA_PointGroup *myRestGroup;
168 };
169 
170 #endif
171 
virtual bool updateParmsFlags()
GT_API const UT_StringHolder time
virtual const char * inputLabel(unsigned idx) const
fpreal evalFloat(int pi, int vi, fpreal t) const
UT_ErrorSeverity
Definition: UT_Error.h:25
GA_Size GA_Offset
Definition: GA_Types.h:641
virtual OP_ERROR cookMyGuide1(OP_Context &context)
void evalString(UT_String &val, int pi, int vi, fpreal t) const
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual OP_ERROR cookInputGroups(OP_Context &context, int alone=0)
GLdouble t
Definition: glad.h:2397
fpreal64 fpreal
Definition: SYS_Types.h:277
GLuint index
Definition: glcorearb.h:786
GA_Offset offset
Definition: SOP_Lattice.h:27
#define SOP_API
Definition: SOP_API.h:10
virtual OP_ERROR cookMyGuide2(OP_Context &context)
exint evalInt(int pi, int vi, fpreal t) const
virtual OP_ERROR cookMySop(OP_Context &context)=0
GA_API const UT_StringHolder rest
virtual int isRefInput(unsigned idx) const
GLenum src
Definition: glcorearb.h:1793
bool unloadData() override