HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual exint numPrimitives() const;
115 
116  virtual void getBBox(exint prim,
117  UT_BoundingBox &bbox) const;
118 
119  virtual bool canValidate(exint prim) const;
120  virtual bool validateBBox(exint prim, const UT_BoundingBox &bbox) const;
121 
122  /// Initialize a block binding information. This is responsible
123  /// for passing to the rasterizer information about the primitives.
124  /// It takes a worldspace location in P which is present as one
125  /// of the bindings that is already filled out.
126  virtual void fillBindings(const UT_ExintArray &primnum,
127  UT_Array<GU_VolumeRasterizeBinding> &bindings) const;
128  /// Returns a list of bindings that we know how to write to.
129  virtual void proposeBindings(UT_Array<GU_VolumeRasterizeBinding> &bindings) const;
130 
131  /// Computes the transform world position to texture coordinates.
132  void getInverseXform(exint prim, UT_Matrix4 &xform) const;
133  /// Computes the tranform from texture to world
134  void getXform(exint prim, UT_Matrix4 &xform) const;
135 private:
136  const GU_Detail *myGdp;
137  GA_OffsetList myPointList;
138  GA_ROHandleF myPscaleH;
139  GA_ROHandleF myPaddingAbsH;
140  GA_ROHandleF myPaddingRelH;
141  GA_AttributeInstanceMatrix myInstanceMatrix;
142  float myScaleAbs, myScaleRel;
143 };
144 
146 {
147 public:
151  MIX_MIN
152  };
153  GU_VolumeRasterizeOutput( const char *name,
154  CompositeType comp,
155  CVEX_Type type);
156 
157  GU_PrimVDB *vdb(int i, int j) const { return myVDB[i][j]; }
158  GU_PrimVolume *vol(int i, int j) const { return myVol[i][j]; }
159  void setField(int i, int j, GU_PrimVolume *vol, GU_PrimVDB *vdb)
160  {
161  myVDB[i][j] = vdb;
162  myVol[i][j] = vol;
163  if (!i && !j)
164  {
165  if (vdb)
166  myIdxXform = vdb->getIndexSpaceTransform();
167  if (vol)
168  myIdxXform = vol->getIndexSpaceTransform();
169  }
170  }
171  const char *name() const { return (const char *) myName; }
172  CompositeType comptype() const { return myComp; }
173  CVEX_Type type() const { return myType; }
174 
175  inline UT_Vector3 posToIndex(UT_Vector3 pos) const
176  { return myIdxXform.toVoxelSpace(pos); }
178  { return myIdxXform.fromVoxelSpace(index); }
179 
180  inline void posToIndex(UT_BoundingBox &box) const
181  { return myIdxXform.toVoxelSpace(box); }
182  inline void indexToPos(UT_BoundingBox &box) const
183  { return myIdxXform.fromVoxelSpace(box); }
184 
185 private:
186  UT_String myName;
187  GU_PrimVDB *myVDB[3][3];
188  GU_PrimVolume *myVol[3][3];
189  CompositeType myComp;
190  CVEX_Type myType;
191 public:
193 };
194 
196 {
197 public:
199  virtual ~GU_VolumeRasterize();
200 
201  class BlockData;
202  class WorkUnit;
203  class WorkJob;
204 
205  void bindOutput(const char *name,
207  GU_PrimVolume *vol,
208  GU_PrimVDB *vdb);
209 
210  void setRasterizer(const char *vexscript,
211  int vexcwdopid);
212 
213  void rasterize(const GU_VolumeRasterizePrimList &primlist);
214 
215  const char *getVexErrors() const;
216  const char *getVexWarnings() const;
217 
218  void setOpCaller(UT_OpCaller *opcaller) { myOpCaller = opcaller; }
219  void setTime(fpreal time, fpreal frame, fpreal timeinc)
220  { myTime = time; myFrame = frame; myTimeInc = timeinc; }
221  void setSampling(int samples, float seed)
222  { mySamples = samples; mySeed = seed; }
223  void setPreMult(bool premult, bool unpremult)
224  { myDoPreMult = premult; myDoUnPreMult = unpremult; }
225 
226  bool isTimeDependent() const { return myTimeDependent; }
227 
228 private:
229  void processBlock(const GU_VolumeRasterizePrimList &primlist, BlockData &data);
230  void rasterizeBlock(BlockData &data);
231 
232  THREADED_METHOD3(GU_VolumeRasterize, vox->numTiles() > 1,
233  compositeVoxels,
234  UT_VoxelArrayF *, vox,
235  const UT_VoxelArrayF *, src,
237  void compositeVoxelsPartial(UT_VoxelArrayF *dst,
238  const UT_VoxelArrayF *src,
240  const UT_JobInfo &info);
241 
242  THREADED_METHOD2(GU_VolumeRasterize, vox->numTiles() > 1,
243  unpremultiplyVoxels,
244  UT_VoxelArrayF *, vox,
245  const UT_VoxelArrayF *, densvox)
246  void unpremultiplyVoxelsPartial(UT_VoxelArrayF *dst,
247  const UT_VoxelArrayF *densvox,
248  const UT_JobInfo &info);
249 
251  doRasterize,
252  const GU_VolumeRasterizePrimList &, primlist,
253  const BlockData &, refblock,
254  UT_Array<BlockData *> &, blocks);
255  void doRasterizePartial(
256  const GU_VolumeRasterizePrimList &primlist,
257  const BlockData &refblock,
258  UT_Array<BlockData *> &blocks,
259  const UT_JobInfo &info);
260 
261  UT_String myVexScript;
262  int myVexCWDNodeId;
263  UT_OpCaller *myOpCaller;
264  UT_WorkArgs *myVexArgs;
265  UT_StringArray myVexErrorList, myVexWarningList;
266  mutable UT_String myVexErrors, myVexWarnings;
267  fpreal myTime, myTimeInc;
268  fpreal myFrame;
269  bool myTimeDependent;
270 
271  int mySamples;
272  float mySeed;
273  bool myDoPreMult;
274  bool myDoUnPreMult;;
275 
277 };
278 
279 #endif
280 
virtual bool canValidate(exint prim) const
virtual void fillBindings(const UT_ExintArray &primnum, UT_Array< GU_VolumeRasterizeBinding > &bindings) const =0
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)
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
png_uint_32 i
Definition: png.h:2877
#define THREADED_METHOD3(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2, PARMTYPE3, PARMNAME3)
virtual bool validateBBox(exint prim, const UT_BoundingBox &bbox) const
UT_Vector3 indexToPos(UT_Vector3 index) const
int64 exint
Definition: SYS_Types.h:109
UT_Matrix4 * m4data() const
#define THREADED_METHOD2(CLASSNAME, DOMULTI, METHOD, PARMTYPE1, PARMNAME1, PARMTYPE2, PARMNAME2)
GU_PrimVolume * vol(int i, int j) const
virtual void endThread(const UT_JobInfo &info, void *threaddata) const
void indexToPos(UT_BoundingBox &box) const
#define GU_API
Definition: GU_API.h:11
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
CVEX_Type
The CVEX_Type enum defines the VEX types available to CVEX.
Definition: CVEX_Value.h:23
GLsizei samples
Definition: glcorearb.h:1297
GLenum GLenum dst
Definition: glcorearb.h:1792
double fpreal
Definition: SYS_Types.h:263
virtual exint numPrimitives() const =0
png_infop png_sPLT_tpp entries
Definition: png.h:2481
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
GLuint index
Definition: glcorearb.h:785
Compute an instance transform given a set of attributes.
UT_Matrix3 * m3data() const
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
GU_PrimVDB * vdb(int i, int j) const
UT_Vector3 posToIndex(UT_Vector3 pos) const
GEO_PrimVolumeXform myIdxXform
GLenum src
Definition: glcorearb.h:1792