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, void *data);
133 
134 // This must match the order in the SOP.
136 {
150 };
151 
152 class GU_BrushNib;
153 
155 {
156 public:
157  GU_Brush();
158  ~GU_Brush();
159 
160  // These create and destroy all the cached structures which
161  // describe the topology of the geometry.
162  void buildCaches(GU_Detail *gdp, const GU_Detail *isectgdp,
163  const GA_PrimitiveGroup *group,
164  const GA_PointGroup *ptgroup,
165  bool usevisibility);
166  // This makes the myVtxClass valid.
167  void buildVertexClasses();
168  void clearCaches();
169  // This lets you check to see if the brush has a valid cache built yet.
170  bool hasValidCache() { return myPointTree != NULL; }
171 
172  const GU_Detail *getGdp() const { return myGdp; }
173  const GU_Detail *getIsectGdp() const { return myIsectGdp; }
174 
175  // These allow you to tell it what name to use for custom attributes:
176  // They return true if they created the attribute.
177  bool overrideColour(const char *name, int create_tuple_size=-1);
178  bool overrideAlpha(const char *name, bool create=false);
179  bool overrideNml(const char *name);
180 
181  // This tells it to use a capture region as the colour.
182  void useCaptureRegion(int captureidx, bool normalizeweight,
183  GEO_Detail::CaptureType capturetype
185 
186  // These retrieve the default colour and alpha:
187  // They return non-zero if they added an attribute.
188  bool defaultColour(bool create = false);
189  bool defaultAlpha(bool create = false);
190  bool defaultNormal(bool create = false);
191  bool defaultTexture(const UT_StringHolder &uvattribname, bool create);
192 
193  // This deals with the visualization colour.
194  // Initializes it:
195  void visualizeColor(float low, float high,
197  bool doVisualize() const { return myVisualizeAttrib.isValid(); }
198  void setVisualizeCd(GA_Offset ptoff, const UT_Vector3 &cd);
199  void clearVisualize() { myVisualizeAttrib.clear(); }
200  void applyVisualize(GU_Detail *gdp);
201  void applyVisualizeStencil(GU_Detail *gdp);
202 
203  // Retrieves the colour of a point taking overrides into account.
204  void getPointCd(GA_Offset ptoff, UT_Vector3 &cd) const;
205  void getVertexCd(GA_Offset vtxoff, UT_Vector3 &cd) const;
206 
207  // These update just the GEO_PointTrees that control where
208  // the points are.
209  void addPrimPoints(const GEO_Detail &detail,
210  GA_Offset primoff,
211  UT_BitArray &ptused,
212  UT_Vector3Array &pts, GA_IndexArray &idxlist);
213  void buildTrees(bool usevisibility);
214  void addUVPrimPoints(const GEO_Detail &detail,
215  GA_Offset primoff,
216  const GA_ROHandleV3 &uvattrib,
217  UT_BitArray &ptused,
218  UT_Vector3Array &uvpts, GA_IndexArray &idxlist);
219  void buildUVTrees(const UT_StringHolder &uvattribname, bool usevisibility);
220  void destroyTrees();
221  GEO_PointTree *getPointTree() { return myPointTree; }
222  GEO_PointTree *getUVPointTree() { return myUVPointTree; }
223 
224  // These are the ring zero caches, marking neighbours in point topology.
225  void connectRingVtx(int vtxnum,
226  GA_Offset vtx2,
227  bool doublevalence = false);
228  void buildRingCache(bool usevisibility);
229  void clearRingCache();
230 
231  // Stencil controls:
232 
233  // Determines if we try to blend the alpha or just the colour.
234  void setWriteAlpha(bool val) { myWriteAlpha = val; }
235  bool getWriteAlpha() const { return myWriteAlpha; }
236  // Returns if there is anything in the stencil buffer.
237  int hasStencil() const;
238  // Zeros out the stencil - MUST be done if the geometry changes!
239  void clearStencil(bool invalidate_vtx=true, bool invalidate_pt=true);
240  // Sets the callback for the callback merge mode type.
242  void *data)
243  {
244  myMergeModeCallback = cb;
245  myMergeModeCallbackData = data;
246  }
247  // Applies a merge mode:
248  void applyMergeMode(GA_Offset ptoff, GA_Offset vtxoff,
250  const UT_Vector3 &src, const UT_Vector3 &dst,
251  GU_BrushMergeMode mergemode);
252  // Sets entire stencil to a specific alpha:
253  void setStencil(float val, bool usevisibility);
254  // Colour according to the stencil:
255  void colourStencil(GEO_Delta *delta, const UT_Vector3 &cd,
256  GU_BrushMergeMode mergemode);
257  // Colour according to the stencil & the stencil colours:
258  void stampColourStencil(GEO_Delta *delta,
259  GU_BrushMergeMode mergemode);
260 
261  void callbackStencil(GEO_Delta *delta,
262  GU_BrushCallback cb, void *data);
263  // Comb the normals.
264  // Lift is the amount to raise the comb above or below the tangent
265  // plane.
266  void combNormals(GEO_Delta *delta, const UT_Vector3 &dir,
267  float lift, int preservenmllen);
268 
269  // lift the normals.
270  // Lift is the amount to raise the comb above or below the tangent
271  // plane.
272  void liftNormals(GEO_Delta *delta, float lift,
273  int preservenmllen);
274 
275  // rotate the normals.
276  void rotateNormals(GEO_Delta *delta, const UT_Vector3 &dir,
277  int preservenmllen);
278 
279  void dragTexture(GEO_Delta *delta, const UT_Vector3 &dir);
280  void scaleTexture(GEO_Delta *delta, float scale,
281  const UT_Vector3 &orig);
282 
283  // Displace points along their normals
284  void displaceNormals(GEO_Delta *delta, float amt);
285  // Displace points along a specified vector:
286  void displaceVector(GEO_Delta *delta,
287  const UT_Vector3 &dir, float amt);
288  // Smooths all the points for one iteration...
289  void smoothPoints(GEO_Delta *delta);
290  // Smooths the current point attribute for one iteration.
291  void smoothAttribute(GEO_Delta *delta);
292  // Smooths teh normals keeping them normalized.
293  void smoothNormals(GEO_Delta *delta, int preservenmllen);
294  // Smooths the current texture attribute for one iteration.
295  void smoothTexture(GEO_Delta *delta);
296 
297  // This undoes the specified delta, putting the changes into
298  // the second delta
299  void eraseAttributes(GEO_Delta *old, GEO_Delta *change);
300  void erasePositions(GEO_Delta *old, GEO_Delta *change);
301  void eraseCapture(GEO_Delta *old, GEO_Delta *change);
302 
303  // In UV mode, it will find the closest point to the origin
304  // Returns GA_INVALID_INDEX on failure.
305  GA_Index findUVSeedPtNum(const UT_Vector3 &orig,
306  const UT_StringHolder &uvattribname);
307 
308  // This applies a single dab to the stencil.
309  // The seed primitive is a primitive in the ISECT gdp, as is the seedpt
310  void applyDab(GU_BrushNib *nib, float stencil_val,
311  const UT_Vector3 &orig, const UT_Vector3 &dir,
312  float rad,
313  const GEO_Primitive *seed,
314  GA_Offset seedptoff,
315  bool useconnectivity,
316  bool usenormals,
317  bool inuv,
318  const UT_StringHolder &uvattribname);
319 
320  // Returns cached normal value of a point.
321  void getPtNormal(GA_Index ptidx, UT_Vector3 &nml);
322  // Resets all the normals:
323  void clearNormalCache();
324 
325 private:
326 #ifdef INTEL_COMPILER
327  GU_Brush(const GU_Brush& ) { }
328 #endif
329 
330 protected:
331  bool testPoint(GA_Index ptind,
332  const UT_Vector3 &orig, const UT_Vector3 &dir,
333  float radius2, bool seeddir,
334  bool usenormals);
335  bool isPointEditable(GA_Index ptnum);
336 
337  inline void readColour(GA_Offset offset, UT_Vector3 &dest) const
338  {
339  if (myColourAttribV3.isValid())
340  dest = myColourAttribV3.get(offset);
341  else
342  {
343  for (int j = 0; j < myColourSize; j++)
344  dest(j) = myColourAttrib.get(offset, j);
345  }
346  }
348  {
349  if (myColourAttribV3.isValid())
350  myColourAttribV3.set(offset, src);
351  else
352  {
353  for (int j = 0; j < myColourSize; j++)
354  myColourAttrib.set(offset, j, src(j));
355  }
356  }
357 
362 
365 
372 
373  // Vertex offsets into myIsectGdp
375  // Vertex offsets into myGdp
378 
379  // This assigns each vertex to a unique number depending on
380  // its texture coordinate & point number. Thus, vertices with
381  // matching texture coordinates & point numbers will have
382  // the same class.
384 
385  // First ring of each point...
387  // This is the number of edges attached to each point ring.
388  // If it is less than twice the myRingZero.entries(), we have
389  // a boundary point.
391 
394 
405  float myVisLow, myVisHigh;
413 
416 
417 private:
418  GU_BrushStencil myStencil;
419 };
420 
421 #endif
422 
bool myPtNmlSet
Definition: GU_Brush.h:363
bool myUseCaptureRegion
Definition: GU_Brush.h:408
void readColour(GA_Offset offset, UT_Vector3 &dest) const
Definition: GU_Brush.h:337
void setMergeModeCallback(GU_BrushMergeModeCallback cb, void *data)
Definition: GU_Brush.h:241
GLenum src
Definition: glew.h:2410
GLuint const GLchar * name
Definition: glew.h:1814
GLclampf GLclampf GLclampf alpha
Definition: glew.h:1520
GLenum mode
Definition: glew.h:2163
GLuint index
Definition: glew.h:1814
void writeColour(GA_Offset offset, UT_Vector3 &src) const
Definition: GU_Brush.h:347
GLuint const GLfloat * val
Definition: glew.h:2794
GEO_PointTree * myUVPointTree
Definition: GU_Brush.h:367
GLenum GLenum GLenum GLenum GLenum scale
Definition: glew.h:13880
bool myUseVisibility
Definition: GU_Brush.h:412
const GU_Detail * getIsectGdp() const
Definition: GU_Brush.h:173
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:366
A soup of polygons.
int myCurIteratePass
Definition: GU_Brush.h:120
GU_BrushMergeModeCallback myMergeModeCallback
Definition: GU_Brush.h:414
void setWriteAlpha(bool val)
Definition: GU_Brush.h:234
UT_Vector3Array myPtNmlCache
Definition: GU_Brush.h:364
UT_Array< GA_Offset > myIsectVtx
Definition: GU_Brush.h:374
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:376
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:233
GU_Detail * myGdp
Definition: GU_Brush.h:360
UT_ColorRamp myVisMode
Definition: GU_Brush.h:406
bool hasValidCache()
Definition: GU_Brush.h:170
UT_Vector3Array myUVPointPos
Definition: GU_Brush.h:370
GA_Size GA_Offset
Definition: GA_Types.h:639
UT_Array< UT_IntArray * > myPt2Vtx
Definition: GU_Brush.h:377
bool getWriteAlpha() const
Definition: GU_Brush.h:235
CaptureType
Methods for manipulating capture weights (GEO_CaptureWeight.C)
Definition: GEO_Detail.h:982
UT_IntArray myPointPass
Definition: GU_Brush.h:106
GEO_PointTree * getUVPointTree()
Definition: GU_Brush.h:222
bool myAlphaVertex
Definition: GU_Brush.h:400
UT_IntArray myVtxClass
Definition: GU_Brush.h:383
bool myWriteAlpha
Definition: GU_Brush.h:407
UT_Vector3Array myColours
Definition: GU_Brush.h:109
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
GA_RWHandleV3 myColourAttribV3
Definition: GU_Brush.h:396
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
Definition: png.h:1083
GLenum GLenum dst
Definition: glew.h:2410
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:405
UT_Array< GA_OffsetArray > myRingZero
Definition: GU_Brush.h:386
#define GU_API
Definition: GU_API.h:14
UT_Array< UT_Array< GA_Offset > * > myVtxRingZero
Definition: GU_Brush.h:392
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:633
GU_BrushMergeMode
Definition: GU_Brush.h:135
GA_RWHandleV3 myVisualizeAttrib
Definition: GU_Brush.h:404
UT_IntArray myRingValence
Definition: GU_Brush.h:390
const GU_Detail * getGdp() const
Definition: GU_Brush.h:172
void * myMergeModeCallbackData
Definition: GU_Brush.h:415
GA_RWHandleF myAlphaAttrib
Definition: GU_Brush.h:399
UT_Vector3Array myPointPos
Definition: GU_Brush.h:369
UT_Array< UT_Array< GA_Index > > myFloodConnected
Definition: GU_Brush.h:371
bool myTextureVertex
Definition: GU_Brush.h:402
GA_RWHandleV3 myNormalAttrib
Definition: GU_Brush.h:403
GEO_Detail::CaptureType myCaptureType
Definition: GU_Brush.h:411
bool doVisualize() const
Definition: GU_Brush.h:197
GA_RWHandleV3 myTextureAttrib
Definition: GU_Brush.h:401
bool myCurIsVertexIterate
Definition: GU_Brush.h:121
int myColourSize
Definition: GU_Brush.h:397
int myCaptureIdx
Definition: GU_Brush.h:409
const GA_PointGroup * myPointGroup
Definition: GU_Brush.h:359
const GU_Detail * myIsectGdp
Definition: GU_Brush.h:361
UT_Array< UT_IntArray * > myVtxRingClass
Definition: GU_Brush.h:393
GLuint64EXT * result
Definition: glew.h:14007
Container class for all geometry.
Definition: GA_Detail.h:95
void clearVisualize()
Definition: GU_Brush.h:199
const GA_PrimitiveGroup * myGroup
Definition: GU_Brush.h:358
UT_StringHolder myUVTreeAttribName
Definition: GU_Brush.h:368
bool myColourVertex
Definition: GU_Brush.h:398
GA_RWHandleF myColourAttrib
Definition: GU_Brush.h:395
GEO_PointTree * getPointTree()
Definition: GU_Brush.h:221
GLboolean GLuint group
Definition: glew.h:2745
bool myNormalizeWeight
Definition: GU_Brush.h:410
void(* GU_BrushCallback)(GA_Offset pt, const UT_Array< GA_Offset > *ptneighbour, GA_Offset vtx, const UT_Array< GA_Offset > *vtxneighbour, float alpha, GEO_Delta *delta, void *data)
Definition: GU_Brush.h:128
GLintptr offset
Definition: glew.h:1682