HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_Blend.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_Blend.h (C++)
7  *
8  * COMMENTS: Functions for blending between details.
9  *
10  */
11 
12 
13  #ifndef __GU_BLEND_H__
14 #define __GU_BLEND_H__
15 
16 #include "GU_API.h"
17 
18 #include <CE/CE_BufferDevice.h>
19 #include <CE/CE_Context.h>
20 #include <GA/GA_CEAttribute.h>
21 #include <GA/GA_IndexMap.h>
22 #include <GA/GA_Names.h>
23 #include <GA/GA_Types.h>
24 #include <UT/UT_Array.h>
25 #include <UT/UT_UniquePtr.h>
26 #include <SYS/SYS_Types.h>
27 
28 class UT_StringRef;
29 class GU_Detail;
30 class GA_Attribute;
31 class GA_Group;
32 class GA_Range;
33 
34 enum class GU_VoxelBlend
35 {
36  None,
38  ByVoxelPos,
39  Advected
40 };
41 
42 enum class GU_MaskMode
43 {
44  None,
47 };
48 
49 namespace GU_Blend
50 {
52 {
57 };
58 template <typename T>
60 {
65 };
66 
68 {
70  bool myHasIdAttribMapping = false;
71  bool myIdAttribDataIdIsSame = false;
72 };
73 
74 struct MaskData
75 {
78  int mySource;
79 };
80 
81 // OpenCL delta mode
82 enum DeltaModeOCL : uint8_t
83 {
86 };
87 
88 // Compressed Sparse
90 {
95 };
96 
98 {
99 public:
101 
102  GU_API void initPerFrameOCL(
103  bool use_opencl,
104  const GA_IndexMap *index_map,
105  DeltaModeOCL dense_mode = DENSE_MODE);
106 
108  const UT_Array<UT_Array<float>> &cpu_deltas,
109  const UT_Array<UT_Array<int>> &page_offsets,
110  const UT_Array<UT_Array<std::pair<GA_PageNum, exint>>> &page_starts,
111  int num_shapes,
112  int tuple_size);
113 
115  const UT_Array<UT_Array<float>> &cpu_deltas,
116  const UT_Array<UT_Array<int>> &page_offsets,
117  const UT_Array<UT_Array<std::pair<GA_PageNum, exint>>> &page_starts,
118  int num_shapes,
119  int tuple_size);
120 
121  void prepareWeightsOCL(const float *cpu_weights, int num_shapes);
122 
123  void setCopyKernelArgOCL(GA_Attribute *data_attrib, int num_tuples);
124  void setSparseKernelArgOCL(GA_Attribute *data_attrib, int num_tuple);
126  GA_Attribute *data_attrib,
127  int num_tuples,
128  int num_shapes);
129 
130  void applyCopyKernelOCL(GA_Attribute *data_attrib, int num_tuples);
131  void applySparseDeltaOCL(
132  GA_Attribute *data_attrib,
133  int num_shape,
134  int num_tuple);
135  void applyDenseDeltaOCL(
136  GA_Attribute *data_attrib,
137  int num_shapes,
138  int num_tuples);
139 
140  void setRedoDeltaOCL(bool redo_delta) { myRedoDelta = redo_delta; }
141 
142  bool useOCL() { return myUseOCL; }
143  bool switchOCL() { return mySwitchOCL; }
144  DeltaModeOCL deltaModeOCL() { return myDeltaModeOCL; }
145  bool switchDeltaModeOCL() { return mySwitchDeltaModeOCL; }
146  bool redoDelta() { return myRedoDelta; }
147  bool isDeltaBufferEmpty() { return myIsDeltaEmpty; }
148 
149 private:
150  bool myUseOCL;
151  bool mySwitchOCL;
152  DeltaModeOCL myDeltaModeOCL;
153  bool mySwitchDeltaModeOCL;
154  bool myRedoDelta;
155  bool myIsDeltaEmpty;
156 
157  GA_DataId mySrcDataID;
158  exint myNpts;
159  exint myNumHeaders;
160 
161  const GA_IndexMap *myPtMap;
162 
163  cl::Program myOCLProgram;
164  cl::Kernel myApplyDeltaKernel;
165 
166  UT_UniquePtr<GA_CEAttribute> mySrcCeAttrib;
167 
168  CE_BufferDevice<float> myDeltasBuffer;
169  CE_BufferDevice<SparseHeader> myCSHeadersBufffer;
170  CE_BufferDevice<int> myPointIndicesBuffer;
171  CE_BufferDevice<float> myWeightsBuffer;
172 };
173 
174 /// This cache can be used to accelerate successive blends. However,
175 /// it is all references to *external* data.
176 /// It also does *NOT* detect if the id attribute names change, so the
177 /// caller is expected to clear the cache in that case.
179 {
180 public:
191 };
192 template <typename T>
194 {
195 public:
205 };
206 }
207 
208 /// If deleteUnmatched is true, points that don't have a match to interpolate with are deleted.
209 /// If deleteUnmatched is false but unmatchedGroupName is given (non-NULL), then these points
210 /// are instead put into a point group of the specified name.
211 /// Note that points of volume and VDB primitives are neither deleted nor put into the group.
212 GU_API void GUblend(
213  GU_Detail *dest, const GU_Detail *source, fpreal weight,
214  const char *pattern = "*", const UT_StringRef &ptidattr = GA_Names::id, const UT_StringRef &primidattr = GA_Names::name,
215  bool doslerp = true, bool usevforpinterp = false, float timestep = (1/24.0),
216  GU_VoxelBlend dovoxel = GU_VoxelBlend::None, GU_Blend::CachedItems *cached_items = NULL, const char *velname = "vel",
217  float advdt = 1, bool deleteUnmatched = false, const char *unmatchedGroupName = NULL);
218 
219 /// If deleteUnmatched is non-zero, points that have fewer than that many interpolation sources
220 /// are deleted from the output (or put into the specified group if unmatchedGroupName is not
221 /// NULL).
222 /// NOTE: Advected volume interpolation is necessarily linear; in that case, volweight is needed to determine
223 /// which detail to blend with and by how much.
224 GU_API void GUblend(
225  GU_Detail *dest, const GU_Detail *gdps[], const float *weights, int size, const GA_Group *group,
226  const char *pattern = "*", const UT_StringRef &ptidattr = GA_Names::id, const UT_StringRef &primidattr = GA_Names::name,
227  bool doslerp = true, GU_VoxelBlend dovoxel = GU_VoxelBlend::None, GU_Blend::CachedItems *cached_items = NULL,
228  bool is_differencing = true, bool dosparse = false,
229  float timestep = (1/24.0), const char *velname = "vel", float advdt = 1, fpreal volweight = 0,
230  int deleteUnmatched = 0, const char *unmatchedGroupName = NULL,
231  const GU_Blend::MaskData * mask_data = NULL,
232  float total = 1);
233 
234 /// Blend the attribute values for the given range, with an optional mapping to
235 /// different offsets in the second detail.
236 /// If set, the weights and mapping arrays should be at least as long as attrib0's offset
237 /// map (attrib0.getIndexMap().offsetSize()).
238 /// @{
239 GU_API void GUblendRange(
240  GA_Attribute &attrib0,
241  const GA_Attribute &attrib1,
242  const GA_Range &range0,
243  float weight,
244  const UT_Array<GA_Offset> *mapping);
245 
246 GU_API void GUblendRange(
247  GA_Attribute &attrib0,
248  const GA_Attribute &attrib1,
249  const GA_Range &range0,
250  const UT_Array<float> &weights,
251  const UT_Array<GA_Offset> *mapping);
252 /// @}
253 
254 /// Calculate the blend weight for an in-between shape given the channel weight
255 /// and a list of all in-between weights
257  float channel_weight,
258  const UT_Array<float> &inbetween_weights,
259  int inbetween_idx);
260 #endif
UT_Array< GA_Offset > myArrayOfOffsets
Definition: GU_Blend.h:69
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
void prepareDenseDeltasOCL(const UT_Array< UT_Array< float >> &cpu_deltas, const UT_Array< UT_Array< int >> &page_offsets, const UT_Array< UT_Array< std::pair< GA_PageNum, exint >>> &page_starts, int num_shapes, int tuple_size)
void prepareWeightsOCL(const float *cpu_weights, int num_shapes)
UT_Array< PerAttribData > * myVertexArrayOfPerAttribData
Definition: GU_Blend.h:183
UT_Array< PerMappingData > * myPtArrayOfPerMappingData
Definition: GU_Blend.h:184
UT_Array< UT_Array< int > > myArrayOfPageOffsets
Definition: GU_Blend.h:62
int64 GA_DataId
Definition: GA_Types.h:696
UT_Array< PerAttribDataT< T > > * myPtArrayOfPerAttribData
Definition: GU_Blend.h:196
UT_Array< PerAttribData > * myPtArrayOfPerAttribData
Definition: GU_Blend.h:181
int64 exint
Definition: SYS_Types.h:125
UT_Array< UT_Array< std::pair< GA_PageNum, exint > > > myArrayOfPageStarts
Definition: GU_Blend.h:63
UT_Array< int64 > * myPrimListDataIds
Definition: GU_Blend.h:202
void setRedoDeltaOCL(bool redo_delta)
Definition: GU_Blend.h:140
UT_Array< PerAttribDataT< T > > * myVertexArrayOfPerAttribData
Definition: GU_Blend.h:198
A range of elements in an index-map.
Definition: GA_Range.h:42
CachedItemsOCL * myCachedItemsOCL
Definition: GU_Blend.h:190
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GA_API const UT_StringHolder name
UT_Array< UT_Array< int > > myArrayOfPageOffsets
Definition: GU_Blend.h:54
UT_Array< int64 > * myPrimListDataIds
Definition: GU_Blend.h:187
GU_API float GUgetInbetweenWeight(float channel_weight, const UT_Array< float > &inbetween_weights, int inbetween_idx)
DeltaModeOCL deltaModeOCL()
Definition: GU_Blend.h:144
GA_PageNum pageNum
Definition: GU_Blend.h:92
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
UT_Array< UT_Array< std::pair< GA_PageNum, exint > > > myArrayOfPageStarts
Definition: GU_Blend.h:55
UT_Array< PerAttribData > * myPrimArrayOfPerAttribData
Definition: GU_Blend.h:182
GU_MaskMode myMode
Definition: GU_Blend.h:76
long long int64
Definition: SYS_Types.h:116
GU_MaskMode
Definition: GU_Blend.h:42
#define GU_API
Definition: GU_API.h:14
GLushort pattern
Definition: glad.h:2583
GA_API const UT_StringHolder id
GU_VoxelBlend
Definition: GU_Blend.h:34
UT_Array< int64 > * myPtTopoDataIds
Definition: GU_Blend.h:186
void applyCopyKernelOCL(GA_Attribute *data_attrib, int num_tuples)
UT_Array< PerMappingData > * myPtArrayOfPerMappingData
Definition: GU_Blend.h:199
GU_API void GUblendRange(GA_Attribute &attrib0, const GA_Attribute &attrib1, const GA_Range &range0, float weight, const UT_Array< GA_Offset > *mapping)
void setCopyKernelArgOCL(GA_Attribute *data_attrib, int num_tuples)
GLsizeiptr size
Definition: glcorearb.h:664
void setSparseKernelArgOCL(GA_Attribute *data_attrib, int num_tuple)
UT_Array< int64 > myArrayOfDataId
Definition: GU_Blend.h:56
fpreal64 fpreal
Definition: SYS_Types.h:278
UT_Array< int64 > myArrayOfDataId
Definition: GU_Blend.h:64
GA_Size GA_PageNum
Definition: GA_Types.h:649
UT_StringRef myAttribName
Definition: GU_Blend.h:77
void applyDenseDeltaOCL(GA_Attribute *data_attrib, int num_shapes, int num_tuples)
void setDenseKernelArgOCL(GA_Attribute *data_attrib, int num_tuples, int num_shapes)
DeltaModeOCL
Definition: GU_Blend.h:82
int64 * myPrimIdDataId
Definition: GU_Blend.h:189
Kernel interface that implements cl_kernel.
Definition: cl.hpp:2544
void prepareSparseDeltasOCL(const UT_Array< UT_Array< float >> &cpu_deltas, const UT_Array< UT_Array< int >> &page_offsets, const UT_Array< UT_Array< std::pair< GA_PageNum, exint >>> &page_starts, int num_shapes, int tuple_size)
UT_Array< PerAttribDataT< T > > * myPrimArrayOfPerAttribData
Definition: GU_Blend.h:197
UT_Array< UT_Array< T > > myArrayOfDeltas
Definition: GU_Blend.h:61
UT_Array< int64 > * myPtTopoDataIds
Definition: GU_Blend.h:201
GU_API void initPerFrameOCL(bool use_opencl, const GA_IndexMap *index_map, DeltaModeOCL dense_mode=DENSE_MODE)
void applySparseDeltaOCL(GA_Attribute *data_attrib, int num_shape, int num_tuple)
Program interface that implements cl_program.
Definition: cl.hpp:2649
UT_Array< UT_Array< float > > myArrayOfDeltas
Definition: GU_Blend.h:53
GU_API void GUblend(GU_Detail *dest, const GU_Detail *source, fpreal weight, const char *pattern="*", const UT_StringRef &ptidattr=GA_Names::id, const UT_StringRef &primidattr=GA_Names::name, bool doslerp=true, bool usevforpinterp=false, float timestep=(1/24.0), GU_VoxelBlend dovoxel=GU_VoxelBlend::None, GU_Blend::CachedItems *cached_items=NULL, const char *velname="vel", float advdt=1, bool deleteUnmatched=false, const char *unmatchedGroupName=NULL)
UT_Array< PerMappingData > * myPrimArrayOfPerMappingData
Definition: GU_Blend.h:185
UT_Array< PerMappingData > * myPrimArrayOfPerMappingData
Definition: GU_Blend.h:200