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 
107  void clearOCL();
108 
110  const UT_Array<UT_Array<float>> &cpu_deltas,
111  const UT_Array<UT_Array<int>> &page_offsets,
112  const UT_Array<UT_Array<std::pair<GA_PageNum, exint>>> &page_starts,
113  int num_shapes,
114  int tuple_size);
115 
117  const UT_Array<UT_Array<float>> &cpu_deltas,
118  const UT_Array<UT_Array<int>> &page_offsets,
119  const UT_Array<UT_Array<std::pair<GA_PageNum, exint>>> &page_starts,
120  int num_shapes,
121  int tuple_size);
122 
123  void prepareWeightsOCL(const float *cpu_weights, int num_shapes);
124 
125  void setCopyKernelArgOCL(GA_Attribute *data_attrib, int num_tuples);
126  void setSparseKernelArgOCL(GA_Attribute *data_attrib, int num_tuple);
128  GA_Attribute *data_attrib,
129  int num_tuples,
130  int num_shapes);
131 
132  void applyCopyKernelOCL(GA_Attribute *data_attrib, int num_tuples);
133  void applySparseDeltaOCL(
134  GA_Attribute *data_attrib,
135  int num_shape,
136  int num_tuple);
137  void applyDenseDeltaOCL(
138  GA_Attribute *data_attrib,
139  int num_shapes,
140  int num_tuples);
141 
142  void setRedoDeltaOCL(bool redo_delta) { myRedoDelta = redo_delta; }
143 
144  bool useOCL() { return myUseOCL; }
145  bool switchOCL() { return mySwitchOCL; }
146  DeltaModeOCL deltaModeOCL() { return myDeltaModeOCL; }
147  bool switchDeltaModeOCL() { return mySwitchDeltaModeOCL; }
148  bool redoDelta() { return myRedoDelta; }
149  bool isDeltaBufferEmpty() { return myIsDeltaEmpty; }
150 
151 private:
152  bool myUseOCL;
153  bool mySwitchOCL;
154  DeltaModeOCL myDeltaModeOCL;
155  bool mySwitchDeltaModeOCL;
156  bool myRedoDelta;
157  bool myIsDeltaEmpty;
158 
159  GA_DataId mySrcDataID;
160  exint myNpts;
161  exint myNumHeaders;
162 
163  const GA_IndexMap *myPtMap;
164 
165  cl::Program myOCLProgram;
166  cl::Kernel myApplyDeltaKernel;
167 
168  UT_UniquePtr<GA_CEAttribute> mySrcCEAttrib;
169 
170  CE_BufferDevice<float> myDeltasBuffer;
171  CE_BufferDevice<SparseHeader> myCSHeadersBufffer;
172  CE_BufferDevice<int> myPointIndicesBuffer;
173  CE_BufferDevice<float> myWeightsBuffer;
174 };
175 
176 /// This cache can be used to accelerate successive blends. However,
177 /// it is all references to *external* data.
178 /// It also does *NOT* detect if the id attribute names change, so the
179 /// caller is expected to clear the cache in that case.
181 {
182 public:
193 };
194 template <typename T>
196 {
197 public:
207 };
208 }
209 
210 /// If deleteUnmatched is true, points that don't have a match to interpolate with are deleted.
211 /// If deleteUnmatched is false but unmatchedGroupName is given (non-NULL), then these points
212 /// are instead put into a point group of the specified name.
213 /// Note that points of volume and VDB primitives are neither deleted nor put into the group.
214 GU_API void GUblend(
215  GU_Detail *dest, const GU_Detail *source, fpreal weight,
216  const char *pattern = "*", const UT_StringRef &ptidattr = GA_Names::id, const UT_StringRef &primidattr = GA_Names::name,
217  bool doslerp = true, bool usevforpinterp = false, float timestep = (1/24.0),
218  GU_VoxelBlend dovoxel = GU_VoxelBlend::None, GU_Blend::CachedItems *cached_items = NULL, const char *velname = "vel",
219  float advdt = 1, bool deleteUnmatched = false, const char *unmatchedGroupName = NULL);
220 
221 /// If deleteUnmatched is non-zero, points that have fewer than that many interpolation sources
222 /// are deleted from the output (or put into the specified group if unmatchedGroupName is not
223 /// NULL).
224 /// NOTE: Advected volume interpolation is necessarily linear; in that case, volweight is needed to determine
225 /// which detail to blend with and by how much.
226 GU_API void GUblend(
227  GU_Detail *dest, const GU_Detail *gdps[], const float *weights, int size, const GA_Group *group,
228  const char *pattern = "*", const UT_StringRef &ptidattr = GA_Names::id, const UT_StringRef &primidattr = GA_Names::name,
229  bool doslerp = true, GU_VoxelBlend dovoxel = GU_VoxelBlend::None, GU_Blend::CachedItems *cached_items = NULL,
230  bool is_differencing = true, bool dosparse = false,
231  float timestep = (1/24.0), const char *velname = "vel", float advdt = 1, fpreal volweight = 0,
232  int deleteUnmatched = 0, const char *unmatchedGroupName = NULL,
233  const GU_Blend::MaskData * mask_data = NULL,
234  float total = 1);
235 
236 /// Blend the attribute values for the given range, with an optional mapping to
237 /// different offsets in the second detail.
238 /// If set, the weights and mapping arrays should be at least as long as attrib0's offset
239 /// map (attrib0.getIndexMap().offsetSize()).
240 /// @{
241 GU_API void GUblendRange(
242  GA_Attribute &attrib0,
243  const GA_Attribute &attrib1,
244  const GA_Range &range0,
245  float weight,
246  const UT_Array<GA_Offset> *mapping);
247 
248 GU_API void GUblendRange(
249  GA_Attribute &attrib0,
250  const GA_Attribute &attrib1,
251  const GA_Range &range0,
252  const UT_Array<float> &weights,
253  const UT_Array<GA_Offset> *mapping);
254 /// @}
255 
256 /// Calculate the blend weight for an in-between shape given the channel weight
257 /// and a list of all in-between weights
259  float channel_weight,
260  const UT_Array<float> &inbetween_weights,
261  int inbetween_idx);
262 #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:185
UT_Array< PerMappingData > * myPtArrayOfPerMappingData
Definition: GU_Blend.h:186
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:198
UT_Array< PerAttribData > * myPtArrayOfPerAttribData
Definition: GU_Blend.h:183
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:204
void setRedoDeltaOCL(bool redo_delta)
Definition: GU_Blend.h:142
UT_Array< PerAttribDataT< T > > * myVertexArrayOfPerAttribData
Definition: GU_Blend.h:200
A range of elements in an index-map.
Definition: GA_Range.h:42
CachedItemsOCL * myCachedItemsOCL
Definition: GU_Blend.h:192
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:189
GU_API float GUgetInbetweenWeight(float channel_weight, const UT_Array< float > &inbetween_weights, int inbetween_idx)
DeltaModeOCL deltaModeOCL()
Definition: GU_Blend.h:146
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:184
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:188
void applyCopyKernelOCL(GA_Attribute *data_attrib, int num_tuples)
UT_Array< PerMappingData > * myPtArrayOfPerMappingData
Definition: GU_Blend.h:201
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:191
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:199
UT_Array< UT_Array< T > > myArrayOfDeltas
Definition: GU_Blend.h:61
UT_Array< int64 > * myPtTopoDataIds
Definition: GU_Blend.h:203
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:187
UT_Array< PerMappingData > * myPrimArrayOfPerMappingData
Definition: GU_Blend.h:202