HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Brush.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: GU_Brush.h ( GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_Brush__
12 #define __GU_Brush__
13 
14 #include "GU_API.h"
15 #include <UT/UT_Color.h>
16 #include <UT/UT_BitArray.h>
17 #include <UT/UT_Vector3Array.h>
18 #include <UT/UT_IntArray.h>
19 #include <UT/UT_Array.h>
20 
21 #include <GA/GA_Handle.h>
22 #include <GA/GA_Types.h>
23 #include <GEO/GEO_Detail.h>
24 
25 class GA_PrimitiveGroup;
26 class GA_PointGroup;
27 class GEO_Delta;
28 class GU_Detail;
29 class GEO_Primitive;
30 class GEO_PointTree;
31 class GEO_Hull;
32 class GEO_PrimPolySoup;
33 
35 {
36 public:
37  int idx; // Which point this is.
38  float val; // Stencil value
39 };
40 
41 
43 {
47 };
48 
49 
50 //
51 // GU_BrushStencil abstracts a per point or per vertex stencil.
52 // This stencil has a current value of 0 .. 1 for every point or vertex
53 // in the gdp.
54 //
55 // Stencils are in one of two modes: point or vertex; which determines the
56 // native mode of the stencil.
57 //
59 {
60 public:
62  ~GU_BrushStencil();
63 
64  void clearStencil(bool invalidate_vtx, bool invalidate_pt);
65  bool isEmpty() const;
66 
67  // These will clear out the stencil as well if the mode changes.
68  void setVertexMode();
69  void setPointMode();
70  bool isVertexMode() const;
71  bool isPointMode() const;
72 
73  /// NOTE: If the stencil is in point mode, index is a GA_Index,
74  /// else, (in vertex mode), it is an index into myGeoVtx
75  /// and myIsectVtx.
76  void setVal(exint index, float val, float alpha, const UT_Vector3 *colour = NULL);
77 
78  void startPointIterate();
79  bool iteratePoint(GA_Index &ptind, float &alpha, UT_Vector3 *colour = NULL);
80 
81  void startVertexIterate();
82  bool iterateVertex(int &vtxidx, float &alpha, UT_Vector3 *colour = NULL);
83 
84  GA_Size fillPointData(const GA_Detail &detail, GA_OffsetList &ptoffs, UT_FloatArray &alphas, UT_Vector3Array *colours = NULL);
85  GA_Size fillVertexData(const GA_Detail &detail, const UT_Array<GA_Offset> &geovtx, GA_OffsetList &ptoffs, UT_FloatArray &alphas, UT_Vector3Array *colours = NULL);
86 
87  // These are used to ensure we can convert between vertex & point
88  // iterators
89  void setVtxTables(UT_Array<UT_IntArray *> *pt2vtx,
91  const GU_Detail *gdp);
92 
93  exint entries() const
94  { return myEntries.entries(); }
95 
96 protected:
97  // The actual entries of the stencil
99 
100  // This has for each of our type (whether vertex or point) the stencil
101  // which corresponds to it.
103 
104  // This is any array, one per point, which allows us to avoid
105  // double counting points in a point iterate in vertex mode.
107 
108  // This is the unpremultiplied stencil colour.
110 
113  const GU_Detail *myGdp;
114 
115  // We are either a vertex stencil or point stencil:
117 
118  // Iterator information:
119  int myCurPixel, myCurSubIdx;
122 };
123 
126  const UT_Vector3 &cd, const UT_Vector3 &orig, void *data);
127 
129  const UT_Array<GA_Offset> *ptneighbour,
130  GA_Offset vtx,
131  const UT_Array<GA_Offset> *vtxneighbour,
132  float alpha, GEO_Delta *delta, const GU_Detail *isectgdp,
133  void *data);
134 
135 // This must match the order in the SOP.
137 {
151 };
152 
153 class GU_BrushNib;
154 
156 {
157 public:
158  GU_Brush();
159  ~GU_Brush();
160 
161  // These create and destroy all the cached structures which
162  // describe the topology of the geometry.
163  void buildCaches(GU_Detail *gdp, const GU_Detail *isectgdp,
164  const GA_PrimitiveGroup *group,
165  const GA_PointGroup *ptgroup,
166  bool usevisibility);
167  // This makes the myVtxClass valid.
168  void buildVertexClasses();
169  void clearCaches();
170  // This lets you check to see if the brush has a valid cache built yet.
171  bool hasValidCache() { return myPointTree != NULL; }
172 
173  const GU_Detail *getGdp() const { return myGdp; }
174  const GU_Detail *getIsectGdp() const { return myIsectGdp; }
175 
176  // These allow you to tell it what name to use for custom attributes:
177  // They return true if they created the attribute.
178  bool overrideColour(const char *name, int create_tuple_size=-1);
179  bool overrideAlpha(const char *name, bool create=false);
180  bool overrideNml(const char *name);
181 
182  // This tells it to use a capture region as the colour.
183  void useCaptureRegion(int captureidx, bool normalizeweight,
184  GEO_Detail::CaptureType capturetype
186 
187  // These retrieve the default colour and alpha:
188  // They return non-zero if they added an attribute.
189  bool defaultColour(bool create = false);
190  bool defaultAlpha(bool create = false);
191  bool defaultNormal(bool create = false);
192  bool defaultTexture(const UT_StringHolder &uvattribname, bool create);
193 
194  // This deals with the visualization colour.
195  // Initializes it:
196  void visualizeColor(float low, float high,
198  bool doVisualize() const { return myVisualizeAttrib.isValid(); }
199  void setVisualizeCd(GA_Offset ptoff, const UT_Vector3 &cd);
200  void clearVisualize() { myVisualizeAttrib.clear(); }
201  void applyVisualize(GU_Detail *gdp);
202  void applyVisualizeStencil(GU_Detail *gdp);
203 
204  // Retrieves the colour of a point taking overrides into account.
205  void getPointCd(GA_Offset ptoff, UT_Vector3 &cd) const;
206  void getVertexCd(GA_Offset vtxoff, UT_Vector3 &cd) const;
207 
208  // These update just the GEO_PointTrees that control where
209  // the points are.
210  void addPrimPoints(const GEO_Detail &detail,
211  GA_Offset primoff,
212  UT_BitArray &ptused,
213  UT_Vector3Array &pts, GA_IndexArray &idxlist);
214  void buildTrees(bool usevisibility);
215  void addUVPrimPoints(const GEO_Detail &detail,
216  GA_Offset primoff,
217  const GA_ROHandleV3 &uvattrib,
218  UT_BitArray &ptused,
219  UT_Vector3Array &uvpts, GA_IndexArray &idxlist);
220  void buildUVTrees(const UT_StringHolder &uvattribname, bool usevisibility);
221  void destroyTrees();
222  GEO_PointTree *getPointTree() { return myPointTree; }
223  GEO_PointTree *getUVPointTree() { return myUVPointTree; }
224 
225  // These are the ring zero caches, marking neighbours in point topology.
226  void connectRingVtx(int vtxnum,
227  GA_Offset vtx2,
228  bool doublevalence = false);
229  void buildRingCache(bool usevisibility);
230  void clearRingCache();
231 
232  // Stencil controls:
233 
234  // Determines if we try to blend the alpha or just the colour.
235  void setWriteAlpha(bool val) { myWriteAlpha = val; }
236  bool getWriteAlpha() const { return myWriteAlpha; }
237  // Returns if there is anything in the stencil buffer.
238  int hasStencil() const;
239  // Zeros out the stencil - MUST be done if the geometry changes!
240  void clearStencil(bool invalidate_vtx=true, bool invalidate_pt=true);
241  // Sets the callback for the callback merge mode type.
243  void *data)
244  {
245  myMergeModeCallback = cb;
246  myMergeModeCallbackData = data;
247  }
248  // Applies a merge mode:
249  void applyMergeMode(GA_Offset ptoff, GA_Offset vtxoff,
251  const UT_Vector3 &src, const UT_Vector3 &dst,
252  GU_BrushMergeMode mergemode);
253  // Sets entire stencil to a specific alpha:
254  void setStencil(float val, bool usevisibility);
255  // Colour according to the stencil:
256  void colourStencil(GEO_Delta *delta, const UT_Vector3 &cd,
257  GU_BrushMergeMode mergemode);
258  // Colour according to the stencil & the stencil colours:
259  void stampColourStencil(GEO_Delta *delta,
260  GU_BrushMergeMode mergemode);
261 
262  void callbackStencil(fpreal t, GEO_Delta *delta,
263  GU_BrushCallback cb, void *data);
264  // Comb the normals.
265  // Lift is the amount to raise the comb above or below the tangent
266  // plane.
267  void combNormals(GEO_Delta *delta, const UT_Vector3 &dir,
268  float lift, int preservenmllen);
269 
270  // lift the normals.
271  // Lift is the amount to raise the comb above or below the tangent
272  // plane.
273  void liftNormals(GEO_Delta *delta, float lift,
274  int preservenmllen);
275 
276  // rotate the normals.
277  void rotateNormals(GEO_Delta *delta, const UT_Vector3 &dir,
278  int preservenmllen);
279 
280  void dragTexture(GEO_Delta *delta, const UT_Vector3 &dir);
281  void scaleTexture(GEO_Delta *delta, float scale,
282  const UT_Vector3 &orig);
283 
284  // Displace points along their normals
285  void displaceNormals(GEO_Delta *delta, float amt);
286  // Displace points along a specified vector:
287  void displaceVector(GEO_Delta *delta,
288  const UT_Vector3 &dir, float amt);
289  // Smooths all the points for one iteration...
290  void smoothPoints(GEO_Delta *delta);
291  // Smooths the current point attribute for one iteration.
292  void smoothAttribute(GEO_Delta *delta);
293  // Smooths teh normals keeping them normalized.
294  void smoothNormals(GEO_Delta *delta, int preservenmllen);
295  // Smooths the current texture attribute for one iteration.
296  void smoothTexture(GEO_Delta *delta);
297 
298  // This undoes the specified delta, putting the changes into
299  // the second delta
300  void eraseAttributes(GEO_Delta *old, GEO_Delta *change);
301  void erasePositions(GEO_Delta *old, GEO_Delta *change);
302  void eraseCapture(GEO_Delta *old, GEO_Delta *change);
303 
304  // In UV mode, it will find the closest point to the origin
305  // Returns GA_INVALID_INDEX on failure.
306  GA_Index findUVSeedPtNum(const UT_Vector3 &orig,
307  const UT_StringHolder &uvattribname);
308 
309  // This applies a single dab to the stencil.
310  // The seed primitive is a primitive in the ISECT gdp, as is the seedpt
311  void applyDab(GU_BrushNib *nib, float stencil_val,
312  const UT_Vector3 &orig, const UT_Vector3 &dir,
313  float rad,
314  const GEO_Primitive *seed,
315  GA_Offset seedptoff,
316  bool useconnectivity,
317  bool usenormals,
318  bool inuv,
319  const UT_StringHolder &uvattribname);
320 
321  // Returns cached normal value of a point.
322  void getPtNormal(GA_Index ptidx, UT_Vector3 &nml);
323  // Resets all the normals:
324  void clearNormalCache();
325 
326 private:
327 #ifdef INTEL_COMPILER
328  GU_Brush(const GU_Brush& ) { }
329 #endif
330 
331 protected:
332  bool testPoint(GA_Index ptind,
333  const UT_Vector3 &orig, const UT_Vector3 &dir,
334  float radius2, bool seeddir,
335  bool usenormals);
336  bool isPointEditable(GA_Index ptnum);
337 
338  inline void readColour(GA_Offset offset, UT_Vector3 &dest) const
339  {
340  if (myColourAttribV3.isValid())
341  dest = myColourAttribV3.get(offset);
342  else
343  {
344  for (int j = 0; j < myColourSize; j++)
345  dest(j) = myColourAttrib.get(offset, j);
346  }
347  }
349  {
350  if (myColourAttribV3.isValid())
351  myColourAttribV3.set(offset, src);
352  else
353  {
354  for (int j = 0; j < myColourSize; j++)
355  myColourAttrib.set(offset, j, src(j));
356  }
357  }
358 
363 
366 
373 
374  // Vertex offsets into myIsectGdp
376  // Vertex offsets into myGdp
379 
380  // This assigns each vertex to a unique number depending on
381  // its texture coordinate & point number. Thus, vertices with
382  // matching texture coordinates & point numbers will have
383  // the same class.
385 
386  // First ring of each point...
388  // This is the number of edges attached to each point ring.
389  // If it is less than twice the myRingZero.entries(), we have
390  // a boundary point.
392 
395 
406  float myVisLow, myVisHigh;
414 
417 
418 private:
419  GU_BrushStencil myStencil;
420 };
421 
422 #endif
423 
bool myPtNmlSet
Definition: GU_Brush.h:364
bool myUseCaptureRegion
Definition: GU_Brush.h:409
void readColour(GA_Offset offset, UT_Vector3 &dest) const
Definition: GU_Brush.h:338
void setMergeModeCallback(GU_BrushMergeModeCallback cb, void *data)
Definition: GU_Brush.h:242
void
Definition: png.h:1083
GLboolean * data
Definition: glcorearb.h:131
void writeColour(GA_Offset offset, UT_Vector3 &src) const
Definition: GU_Brush.h:348
GEO_PointTree * myUVPointTree
Definition: GU_Brush.h:368
bool myUseVisibility
Definition: GU_Brush.h:413
const GU_Detail * getIsectGdp() const
Definition: GU_Brush.h:174
const GU_Detail * myGdp
Definition: GU_Brush.h:113
int64 exint
Definition: SYS_Types.h:125
GU_BrushStencilMode
Definition: GU_Brush.h:42
GEO_PointTree * myPointTree
Definition: GU_Brush.h:367
A soup of polygons.
int myCurIteratePass
Definition: GU_Brush.h:120
GU_BrushMergeModeCallback myMergeModeCallback
Definition: GU_Brush.h:415
void setWriteAlpha(bool val)
Definition: GU_Brush.h:235
**But if you need a result
Definition: thread.h:613
UT_Vector3Array myPtNmlCache
Definition: GU_Brush.h:365
UT_Array< GA_Offset > myIsectVtx
Definition: GU_Brush.h:375
exint entries() const
Definition: GU_Brush.h:93
GU_BrushStencilMode myMode
Definition: GU_Brush.h:116
UT_Array< GA_Offset > myGeoVtx
Definition: GU_Brush.h:377
UT_Array< GU_StencilPixel > myEntries
Definition: GU_Brush.h:98
UT_IntArray myStencilRef
Definition: GU_Brush.h:102
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
GU_Detail * myGdp
Definition: GU_Brush.h:361
UT_ColorRamp myVisMode
Definition: GU_Brush.h:407
bool hasValidCache()
Definition: GU_Brush.h:171
UT_Vector3Array myUVPointPos
Definition: GU_Brush.h:371
GA_Size GA_Offset
Definition: GA_Types.h:646
GA_API const UT_StringHolder scale
UT_Array< UT_IntArray * > myPt2Vtx
Definition: GU_Brush.h:378
bool getWriteAlpha() const
Definition: GU_Brush.h:236
CaptureType
Methods for manipulating capture weights (GEO_CaptureWeight.C)
Definition: GEO_Detail.h:996
GLintptr offset
Definition: glcorearb.h:665
UT_IntArray myPointPass
Definition: GU_Brush.h:106
GEO_PointTree * getUVPointTree()
Definition: GU_Brush.h:223
bool myAlphaVertex
Definition: GU_Brush.h:401
UT_IntArray myVtxClass
Definition: GU_Brush.h:384
bool myWriteAlpha
Definition: GU_Brush.h:408
UT_Vector3Array myColours
Definition: GU_Brush.h:109
GA_RWHandleV3 myColourAttribV3
Definition: GU_Brush.h:397
UT_ColorRamp
Definition: UT_Color.h:32
UT_Array< GA_Offset > * myVtx
Definition: GU_Brush.h:112
UT_Array< UT_IntArray * > * myPt2Vtx
Definition: GU_Brush.h:111
void(* GU_BrushMergeModeCallback)(GA_Offset ptoff, GA_Offset vtxoff, UT_Vector3 &result, const UT_Vector3 &cd, const UT_Vector3 &orig, void *data)
Definition: GU_Brush.h:124
float myVisLow
Definition: GU_Brush.h:406
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
UT_Array< GA_OffsetArray > myRingZero
Definition: GU_Brush.h:387
#define GU_API
Definition: GU_API.h:14
GLuint const GLchar * name
Definition: glcorearb.h:786
UT_Array< UT_Array< GA_Offset > * > myVtxRingZero
Definition: GU_Brush.h:393
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:640
GU_BrushMergeMode
Definition: GU_Brush.h:136
GA_RWHandleV3 myVisualizeAttrib
Definition: GU_Brush.h:405
UT_IntArray myRingValence
Definition: GU_Brush.h:391
GLdouble t
Definition: glad.h:2397
GLenum mode
Definition: glcorearb.h:99
const GU_Detail * getGdp() const
Definition: GU_Brush.h:173
void * myMergeModeCallbackData
Definition: GU_Brush.h:416
GLint j
Definition: glad.h:2733
GA_RWHandleF myAlphaAttrib
Definition: GU_Brush.h:400
GLenum GLenum dst
Definition: glcorearb.h:1793
UT_Vector3Array myPointPos
Definition: GU_Brush.h:370
UT_Array< UT_Array< GA_Index > > myFloodConnected
Definition: GU_Brush.h:372
bool myTextureVertex
Definition: GU_Brush.h:403
GA_RWHandleV3 myNormalAttrib
Definition: GU_Brush.h:404
fpreal64 fpreal
Definition: SYS_Types.h:277
GEO_Detail::CaptureType myCaptureType
Definition: GU_Brush.h:412
bool doVisualize() const
Definition: GU_Brush.h:198
GA_RWHandleV3 myTextureAttrib
Definition: GU_Brush.h:402
bool myCurIsVertexIterate
Definition: GU_Brush.h:121
GLuint index
Definition: glcorearb.h:786
int myColourSize
Definition: GU_Brush.h:398
int myCaptureIdx
Definition: GU_Brush.h:410
GLuint GLfloat * val
Definition: glcorearb.h:1608
const GA_PointGroup * myPointGroup
Definition: GU_Brush.h:360
const GU_Detail * myIsectGdp
Definition: GU_Brush.h:362
UT_Array< UT_IntArray * > myVtxRingClass
Definition: GU_Brush.h:394
Container class for all geometry.
Definition: GA_Detail.h:96
void clearVisualize()
Definition: GU_Brush.h:200
const GA_PrimitiveGroup * myGroup
Definition: GU_Brush.h:359
UT_StringHolder myUVTreeAttribName
Definition: GU_Brush.h:369
bool myColourVertex
Definition: GU_Brush.h:399
GA_RWHandleF myColourAttrib
Definition: GU_Brush.h:396
void(* GU_BrushCallback)(fpreal t, GA_Offset pt, const UT_Array< GA_Offset > *ptneighbour, GA_Offset vtx, const UT_Array< GA_Offset > *vtxneighbour, float alpha, GEO_Delta *delta, const GU_Detail *isectgdp, void *data)
Definition: GU_Brush.h:128
Definition: format.h:895
GEO_PointTree * getPointTree()
Definition: GU_Brush.h:222
bool myNormalizeWeight
Definition: GU_Brush.h:411
GLenum src
Definition: glcorearb.h:1793