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