HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SOP_GroomUtils.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 Library (C++)
7  *
8  * COMMENTS:
9  * Helper classes for working with hair and fur grooms.
10  */
11 
12 #ifndef __SOP_GroomUtils_h__
13 #define __SOP_GroomUtils_h__
14 
15 #include <GA/GA_AttributeRefMap.h>
16 #include <GEO/GEO_PointTree.h>
17 #include <GU/GU_Detail.h>
18 #include <UT/UT_LineTree.h>
19 #include <UT/UT_Ramp.h>
20 #include <UT/UT_Tuple.h>
21 #include <UT/UT_UniquePtr.h>
22 #include "SOP_NodeVerb.h"
23 
24 // A tree that can be built using an arbitrary prim or point attribute as the
25 // point position. When using a prim attribute, this allows direct lookup of
26 // curve primitives.
28 {
29 public:
30  /// Rebuilds the tree with the given detail and primitive group,
31  /// This creates a point per primitive using the primitive attribute of the
32  /// specified name as the point position.
33  /// if primgroup is NULL then all primitives are used.
34  void
35  build(
36  const GEO_Detail *gdp,
37  const GA_PrimitiveGroup *primgroup,
38  const char *attrib,
39  bool enable_multithreading=true);
40 
41  // Methods that must delegate to base class due to overloads
42  void build(
43  const GEO_Detail *gdp,
44  const GA_PointGroup *ptgroup,
45  bool enable_multithreading = true)
46  {
47  GEO_PointTreeGAOffset::build(gdp, ptgroup, enable_multithreading);
48  }
49 
50  void build(
51  const GEO_Detail *gdp,
52  const GA_PointGroup *ptgroup,
53  const char *attrib,
54  bool enable_multithreading = true)
55  {
56  GEO_PointTreeGAOffset::build(gdp, ptgroup, attrib, enable_multithreading);
57  }
58 };
59 
61 {
62 public:
63  sop_FastRamp(int numsamples=1000)
64  : numsamples(numsamples)
65  {}
66 
67  bool update(const UT_Ramp *widthramp);
68 
69  float lookup(float u) const;
70 
71  float lookupNearest(float u) const;
72 
73 private:
75  int numsamples;
76 };
77 
79 {
80 public:
82  GU_Detail *dest,
83  const GU_Detail *source,
84  const GA_AttributeOwner destowner)
85  : dest(dest)
86  , source(source)
87  , destowner(destowner)
88  {}
89 
90  using AttribMatchTuple = std::pair<GA_AttributeOwner, UT_StringHolder>;
91 
92  void addSourceAttribs(
93  const GA_AttributeOwner sourceowner,
94  const char *matchpattern,
95  UT_Set<AttribMatchTuple> &alreadymapped);
96 
98  {
102  };
103 
104  class CacheData
105  {
106  private:
107  UT_ValArray<int> targetindices;
110  UT_ValArray<int> typeids;
111  UT_ValArray<int> tuplesizes;
112  UT_ValArray<GA_DataId> dataids;
113 
114  friend sop_SourceAttribList;
115 
116  };
117 
119  GA_AttributeRefMap &map) const
120  {
121  mapAndCreateAttribs(map, nullptr);
122  }
123 
124 
125  void mapAndCreateAttrib(
126  GA_AttributeRefMap &map,
127  const UT_ValArray<AttribChange> *changes,
128  int index) const;
129 
130  void mapAndCreateAttribs(
131  GA_AttributeRefMap &map,
132  const UT_ValArray<AttribChange> *changes) const;
133 
135  GA_AttributeRefMap &map,
136  const UT_ValArray<AttribChange> *changes) const;
137 
139  GA_AttributeRefMap &map,
140  const UT_ValArray<AttribChange> *changes) const;
141 
142  bool updateCache(
143  UT_UniquePtr<CacheData> &cachedata,
144  UT_ValArray<AttribChange> &changes) const;
145 
146 private:
147  CacheData* getCacheData() const;
148 
149  const GU_Detail *source;
150  UT_ValArray<const GA_Attribute*> sourceattribs;
151  GU_Detail *dest;
152  const GA_AttributeOwner destowner;
153 };
154 
156 {
158  const GU_Detail &gdp,
159  const GA_ROHandleV3 &restattrib,
160  const SOP_NodeVerb::CookParms &cookparms);
161 
162  bool attribMissing() { return myAttribMissing; }
163 
168 
169 private:
170  bool myAttribMissing;
171 };
172 
174 {
175 public:
177  {
178  void setArraySize(unsigned int size)
179  {
180  lines.setSize(size);
181  dist2s.setSize(size);
182  }
183 
186  };
187 
188  sop_PartingLineLookup(unsigned int maxpartlines)
189  : myMaxPartLines(maxpartlines)
190  {}
191 
192  static const GA_PrimitiveGroup*
193  getGroup(const GU_Detail &gdp)
194  {
195  return gdp.findPrimitiveGroup("partinglines");
196  }
197 
198  void
199  setLines(
200  const GU_Detail &gdp,
201  const GA_ROHandleV3 &restattrib,
202  const GA_PrimitiveGroup &partlinesgroup);
203 
204  float
206  const UT_Vector3 &posA,
207  const UT_Vector3 &posB,
209  UT_ThreadSpecificValue<PerThreadData> &threadvalues) const;
210 
211 private:
212  const unsigned int myMaxPartLines;
213 
214  class sop_PartLineTree : public UT_LineTree
215  {
216  public:
217  int addLine(const GA_Offset ptoff1, const UT_Vector3 &pt1,
218  const GA_Offset ptoff2, const UT_Vector3 &pt2);
219 
220  void setCapacity( unsigned capacity );
221 
222  GA_Offset getLineOffset1(int id) const
223  { return myOffsets(2 * id); }
224 
225  GA_Offset getLineOffset2(int id) const
226  { return myOffsets(2 * id + 1); }
227 
228  private:
229  GA_OffsetArray myOffsets;
230  };
231 
232  sop_PartLineTree myLineTree;
233 };
234 
235 uint sop_vexHash(float seed);
236 uint sop_vexHash(float seed1, float seed2);
237 float sop_vexRandom(uint seed);
238 float sop_vexRand(uint seed);
239 
241 float sop_unitLengthToUnitDomain(UT_Vector3Array &pos, float ulength);
242 float sop_unitToUnitLengthDomain(UT_Vector3Array &pos, float uparm);
243 
244 void sop_skinPrimError(const SOP_NodeVerb::CookParms &cookparms);
245 
246 #endif
bool update(const UT_Ramp *widthramp)
SYS_FORCE_INLINE const GA_PrimitiveGroup * findPrimitiveGroup(const UT_StringRef &name) const
Definition: GA_Detail.h:1196
Definition: UT_Set.h:58
float sop_unitToUnitLengthDomain(UT_Vector3Array &pos, float uparm)
GLsizeiptr size
Definition: glew.h:1681
GLuint index
Definition: glew.h:1814
const GLint * attribs
Definition: glew.h:14385
float computePartingWeight(const UT_Vector3 &posA, const UT_Vector3 &posB, const sop_PartingLineAttribs &attribs, UT_ThreadSpecificValue< PerThreadData > &threadvalues) const
void build(const GEO_Detail *gdp, const GA_PointGroup *ptgroup=NULL, bool enable_multithreading=true)
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
void setArraySize(unsigned int size)
sop_PartingLineAttribs(const GU_Detail &gdp, const GA_ROHandleV3 &restattrib, const SOP_NodeVerb::CookParms &cookparms)
float lookupNearest(float u) const
float sop_unitLengthToUnitDomain(UT_Vector3Array &pos, float ulength)
void setSize(exint newsize)
Definition: UT_Array.h:478
uint sop_vexHash(float seed)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
void sop_skinPrimError(const SOP_NodeVerb::CookParms &cookparms)
GA_Size GA_Offset
Definition: GA_Types.h:639
std::pair< GA_AttributeOwner, UT_StringHolder > AttribMatchTuple
sop_PartingLineLookup(unsigned int maxpartlines)
void addSourceAttribs(const GA_AttributeOwner sourceowner, const char *matchpattern, UT_Set< AttribMatchTuple > &alreadymapped)
void mapAndCreateNonRealAttribs(GA_AttributeRefMap &map, const UT_ValArray< AttribChange > *changes) const
float sop_vexRand(uint seed)
GLuint const GLuint * names
Definition: glew.h:2690
void mapAndCreateAttribs(GA_AttributeRefMap &map) const
A handle to simplify manipulation of multiple attributes.
const GA_ROHandleV3 & rest
bool updateCache(UT_UniquePtr< CacheData > &cachedata, UT_ValArray< AttribChange > &changes) const
sop_SourceAttribList(GU_Detail *dest, const GU_Detail *source, const GA_AttributeOwner destowner)
void build(const GEO_Detail *gdp, const GA_PointGroup *ptgroup, const char *attrib, bool enable_multithreading=true)
GA_AttributeOwner
Definition: GA_Types.h:33
fpreal64 fpreal
Definition: SYS_Types.h:277
Utility class for containing a color ramp.
Definition: UT_Ramp.h:84
static const GA_PrimitiveGroup * getGroup(const GU_Detail &gdp)
sop_FastRamp(int numsamples=1000)
fpreal sop_calcPerimeter(UT_Vector3Array &pos)
void setLines(const GU_Detail &gdp, const GA_ROHandleV3 &restattrib, const GA_PrimitiveGroup &partlinesgroup)
GLsizei samples
Definition: glew.h:2998
void build(const GEO_Detail *gdp, const GA_PrimitiveGroup *primgroup, const char *attrib, bool enable_multithreading=true)
float sop_vexRandom(uint seed)
void mapAndCreateRealAttribs(GA_AttributeRefMap &map, const UT_ValArray< AttribChange > *changes) const
void mapAndCreateAttrib(GA_AttributeRefMap &map, const UT_ValArray< AttribChange > *changes, int index) const
unsigned int uint
Definition: SYS_Types.h:45
float lookup(float u) const
void build(const GEO_Detail *gdp, const GA_PointGroup *ptgroup, bool enable_multithreading=true)