HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_VolumeRasterize.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_VolumeRasterize.h ( GU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GU_VolumeRasterize__
12 #define __GU_VolumeRasterize__
13 
14 #include "GU_API.h"
15 
16 #include <UT/UT_Array.h>
17 #include <UT/UT_BoundingBox.h>
18 #include <UT/UT_VoxelArray.h>
20 #include <CVEX/CVEX_Context.h>
21 
22 #include <GA/GA_Handle.h>
23 #include <GA/GA_OffsetList.h>
25 #include "GU_PrimVolume.h"
26 #include "GU_PrimVDB.h"
27 
28 class GU_Detail;
29 class GA_PointGroup;
30 
32 {
33 public:
35  : myName(UT_String::ALWAYS_DEEP, name)
36  , myType(type)
37  , myData(0)
38  , myIsFilled(0)
39  {
40  }
42  {
43  free(myData);
44  }
45 
46  const char *name() const { return myName; }
47  CVEX_Type type() const { return myType; }
48 
49  void alloc(exint entries);
50 
51  void *data() const { return myData; }
52  float *fdata() const { return (float *) myData; }
53  int *idata() const { return (int *) myData; }
54  UT_Vector3 *v3data() const { return (UT_Vector3 *) myData; }
55  UT_Vector4 *v4data() const { return (UT_Vector4 *) myData; }
56  UT_Matrix3 *m3data() const { return (UT_Matrix3 *) myData; }
57  UT_Matrix4 *m4data() const { return (UT_Matrix4 *) myData; }
58 
59  bool myIsFilled;
60 
61 private:
62  UT_String myName;
63  CVEX_Type myType;
64  void *myData;
65 };
66 
68 {
69 public:
72 
73 
74  // All of the following functions must be threadsafe.
75  virtual exint numPrimitives() const = 0;
76 
77  virtual void getBBox(exint prim,
78  UT_BoundingBox &bbox) const = 0;
79 
80  // Do we support validating bounding boxes?
81  virtual bool canValidate(exint prim) const { return false; }
82 
83  // Query if this world space box has any voxels worth looking at.
84  virtual bool validateBBox(exint prim, const UT_BoundingBox &bbox) const { return true; }
85 
86  // threaddata is a pointer to a void * that you can initialize to
87  // point to your allocated thread local data
88  virtual void initThread(const UT_JobInfo &info, void **threaddata) const {}
89  // This is the value of the threaddata that you set on initThread.
90  virtual void endThread(const UT_JobInfo &info, void *threaddata) const {}
91 
92  /// Initialize a block binding information. This is responsible
93  /// for passing to the rasterizer information about the primitives.
94  /// It takes a worldspace location in P which is present as one
95  /// of the bindings that is already filled out.
96  virtual void fillBindings(const UT_ExintArray &primnum,
97  UT_Array<GU_VolumeRasterizeBinding> &bindings) const = 0;
98 
99  /// Returns a list of bindings that we know how to write to.
100  virtual void proposeBindings(UT_Array<GU_VolumeRasterizeBinding> &bindings) const = 0;
101 };
102 
105 {
106 public:
107  GU_VolumeRasterizePointAsPrimList(const GU_Detail *gdp, const GA_OffsetList &ptlist, bool scaletexturespace);
109 
110  // Rasterizes pscale sized spheres, will expand them by *= relative
111  // and += absolute.
112  void setDisplaceBounds(fpreal relative, fpreal absolute);
113 
114  exint numPrimitives() const override;
115 
116  void getBBox(exint prim,
117  UT_BoundingBox &bbox) const override;
118 
119  bool canValidate(exint prim) const override;
120  bool validateBBox(
121  exint prim,
122  const UT_BoundingBox &bbox
123  ) const override;
124 
125  /// Initialize a block binding information. This is responsible
126  /// for passing to the rasterizer information about the primitives.
127  /// It takes a worldspace location in P which is present as one
128  /// of the bindings that is already filled out.
129  void fillBindings(
130  const UT_ExintArray &primnum,
132  ) const override;
133  /// Returns a list of bindings that we know how to write to.
134  void proposeBindings(
136  ) const override;
137 
138  /// Computes the transform world position to texture coordinates.
139  void getInverseXform(exint prim, UT_Matrix4 &xform) const;
140  /// Computes the tranform from texture to world
141  void getXform(exint prim, UT_Matrix4 &xform) const;
142 private:
143  const GU_Detail *myGdp;
144  GA_OffsetList myPointList;
145  GA_ROHandleF myPscaleH;
146  GA_ROHandleF myPaddingAbsH;
147  GA_ROHandleF myPaddingRelH;
148  GA_AttributeInstanceMatrix myInstanceMatrix;
149  float myScaleAbs, myScaleRel;
150 };
151 
153 {
154 public:
158  MIX_MIN
159  };
160  GU_VolumeRasterizeOutput( const char *name,
161  CompositeType comp,
162  CVEX_Type type);
163 
164  GU_PrimVDB *vdb(int i, int j) const { return myVDB[i][j]; }
165  GU_PrimVolume *vol(int i, int j) const { return myVol[i][j]; }
166  void setField(int i, int j, GU_PrimVolume *vol, GU_PrimVDB *vdb)
167  {
168  myVDB[i][j] = vdb;
169  myVol[i][j] = vol;
170  if (!i && !j)
171  {
172  if (vdb)
173  myIdxXform = vdb->getIndexSpaceTransform();
174  if (vol)
175  myIdxXform = vol->getIndexSpaceTransform();
176  }
177  }
178  const char *name() const { return (const char *) myName; }
179  CompositeType comptype() const { return myComp; }
180  CVEX_Type type() const { return myType; }
181 
182  inline UT_Vector3 posToIndex(UT_Vector3 pos) const
183  { return myIdxXform.toVoxelSpace(pos); }
185  { return myIdxXform.fromVoxelSpace(index); }
186 
187  inline void posToIndex(UT_BoundingBox &box) const
188  { return myIdxXform.toVoxelSpace(box); }
189  inline void indexToPos(UT_BoundingBox &box) const
190  { return myIdxXform.fromVoxelSpace(box); }
191 
192 private:
193  UT_String myName;
194  GU_PrimVDB *myVDB[3][3];
195  GU_PrimVolume *myVol[3][3];
196  CompositeType myComp;
197  CVEX_Type myType;
198 public:
200 };
201 
203 {
204 public:
206  virtual ~GU_VolumeRasterize();
207 
208  class BlockData;
209  class WorkUnit;
210  class WorkJob;
211 
212  void bindOutput(const char *name,
214  GU_PrimVolume *vol,
215  GU_PrimVDB *vdb);
216 
217  void setRasterizer(const char *vexscript,
218  int vexcwdopid);
219 
220  void rasterize(const GU_VolumeRasterizePrimList &primlist);
221 
222  const char *getVexErrors() const;
223  const char *getVexWarnings() const;
224 
225  void setOpCaller(UT_OpCaller *opcaller) { myOpCaller = opcaller; }
226  void setTime(fpreal time, fpreal frame, fpreal timeinc)
227  { myTime = time; myFrame = frame; myTimeInc = timeinc; }
228  void setSampling(int samples, float seed)
229  { mySamples = samples; mySeed = seed; }
230  void setPreMult(bool premult, bool unpremult)
231  { myDoPreMult = premult; myDoUnPreMult = unpremult; }
232 
233  bool isTimeDependent() const { return myTimeDependent; }
234 
235 private:
236  void processBlock(const GU_VolumeRasterizePrimList &primlist, BlockData &data);
237  void rasterizeBlock(BlockData &data);
238 
239  THREADED_METHOD3(GU_VolumeRasterize, vox->numTiles() > 1,
240  compositeVoxels,
241  UT_VoxelArrayF *, vox,
242  const UT_VoxelArrayF *, src,
244  void compositeVoxelsPartial(UT_VoxelArrayF *dst,
245  const UT_VoxelArrayF *src,
247  const UT_JobInfo &info);
248 
249  THREADED_METHOD2(GU_VolumeRasterize, vox->numTiles() > 1,
250  unpremultiplyVoxels,
251  UT_VoxelArrayF *, vox,
252  const UT_VoxelArrayF *, densvox)
253  void unpremultiplyVoxelsPartial(UT_VoxelArrayF *dst,
254  const UT_VoxelArrayF *densvox,
255  const UT_JobInfo &info);
256 
258  doRasterize,
259  const GU_VolumeRasterizePrimList &, primlist,
260  const BlockData &, refblock,
261  UT_Array<BlockData *> &, blocks);
262  void doRasterizePartial(
263  const GU_VolumeRasterizePrimList &primlist,
264  const BlockData &refblock,
265  UT_Array<BlockData *> &blocks,
266  const UT_JobInfo &info);
267 
268  UT_String myVexScript;
269  int myVexCWDNodeId;
270  UT_OpCaller *myOpCaller;
271  UT_WorkArgs *myVexArgs;
272  UT_StringArray myVexErrorList, myVexWarningList;
273  mutable UT_String myVexErrors, myVexWarnings;
274  fpreal myTime, myTimeInc;
275  fpreal myFrame;
276  bool myTimeDependent;
277 
278  int mySamples;
279  float mySeed;
280  bool myDoPreMult;
281  bool myDoUnPreMult;
282 
284 };
285 
286 #endif
287 
GLenum src
Definition: glew.h:2410
GLuint const GLchar * name
Definition: glew.h:1814
virtual bool canValidate(exint prim) const
virtual void fillBindings(const UT_ExintArray &primnum, UT_Array< GU_VolumeRasterizeBinding > &bindings) const =0
GT_API const UT_StringHolder time
GLuint index
Definition: glew.h:1814
UT_Vector4 * v4data() const
const char * name() const
virtual void getBBox(exint prim, UT_BoundingBox &bbox) const =0
virtual void proposeBindings(UT_Array< GU_VolumeRasterizeBinding > &bindings) const =0
Returns a list of bindings that we know how to write to.
GU_VolumeRasterizeBinding(const char *name, CVEX_Type type)
void setTime(fpreal time, fpreal frame, fpreal timeinc)
int64 exint
Definition: SYS_Types.h:125
CompositeType comptype() const
void setSampling(int samples, float seed)
void setField(int i, int j, GU_PrimVolume *vol, GU_PrimVDB *vdb)
GEO_PrimVolumeXform getIndexSpaceTransform() const
void setOpCaller(UT_OpCaller *opcaller)
UT_Vector3 * v3data() const
#define THREADED_METHOD3(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3)
OIIO_API void premult(int nchannels, int width, int height, int depth, int chbegin, int chend, TypeDesc datatype, void *data, stride_t xstride, stride_t ystride, stride_t zstride, int alpha_channel=-1, int z_channel=-1)
virtual bool validateBBox(exint prim, const UT_BoundingBox &bbox) const
UT_Vector3 indexToPos(UT_Vector3 index) const
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
UT_Matrix4 * m4data() const
#define THREADED_METHOD2(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2)
GU_PrimVolume * vol(int i, int j) const
GLenum GLenum dst
Definition: glew.h:2410
virtual void endThread(const UT_JobInfo &info, void *threaddata) const
void indexToPos(UT_BoundingBox &box) const
#define GU_API
Definition: GU_API.h:14
CVEX_Type
The CVEX_Type enum defines the VEX types available to CVEX.
Definition: CVEX_Value.h:27
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
virtual exint numPrimitives() const =0
virtual void initThread(const UT_JobInfo &info, void **threaddata) const
void posToIndex(UT_BoundingBox &box) const
void setPreMult(bool premult, bool unpremult)
const char * name() const
bool isTimeDependent() const
GEO_PrimVolumeXform getIndexSpaceTransform() const
fpreal64 fpreal
Definition: SYS_Types.h:277
Compute an instance transform given a set of attributes.
UT_Matrix3 * m3data() const
GU_PrimVDB * vdb(int i, int j) const
UT_Vector3 posToIndex(UT_Vector3 pos) const
GLsizei samples
Definition: glew.h:2998
GEO_PrimVolumeXform myIdxXform
ImageBuf OIIO_API unpremult(const ImageBuf &src, ROI roi={}, int nthreads=0)