All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sampler.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_SAMPLER_H
25 #define PXR_IMAGING_PLUGIN_HD_EMBREE_SAMPLER_H
26 
27 #include "pxr/pxr.h"
28 #include <cstddef>
29 
30 #include "pxr/imaging/hd/enums.h"
31 #include "pxr/imaging/hd/vtBufferSource.h"
32 
33 #include "pxr/base/gf/matrix4d.h"
34 #include "pxr/base/gf/matrix4f.h"
35 #include "pxr/base/gf/vec2d.h"
36 #include "pxr/base/gf/vec2f.h"
37 #include "pxr/base/gf/vec2i.h"
38 #include "pxr/base/gf/vec3d.h"
39 #include "pxr/base/gf/vec3f.h"
40 #include "pxr/base/gf/vec3i.h"
41 #include "pxr/base/gf/vec4d.h"
42 #include "pxr/base/gf/vec4f.h"
43 #include "pxr/base/gf/vec4i.h"
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
51 public:
53  template<typename T>
54  static HdTupleType GetTupleType();
55 
57  typedef char PrimvarTypeContainer[sizeof(GfMatrix4d)];
58 };
59 
60 // Define template specializations of HdEmbreeTypeHelper methods for
61 // all our supported types...
62 #define TYPE_HELPER(T,type)\
63 template<> inline HdTupleType \
64 HdEmbreeTypeHelper::GetTupleType<T>() { return HdTupleType{type, 1}; }
65 
66  TYPE_HELPER(bool, HdTypeBool)
67  TYPE_HELPER(char, HdTypeInt8)
68  TYPE_HELPER(short, HdTypeInt16)
69  TYPE_HELPER(unsigned short, HdTypeUInt16)
70  TYPE_HELPER(int, HdTypeInt32)
71  TYPE_HELPER(GfVec2i, HdTypeInt32Vec2)
72  TYPE_HELPER(GfVec3i, HdTypeInt32Vec3)
73  TYPE_HELPER(GfVec4i, HdTypeInt32Vec4)
74  TYPE_HELPER(unsigned int, HdTypeUInt32)
75  TYPE_HELPER(float, HdTypeFloat)
76  TYPE_HELPER(GfVec2f, HdTypeFloatVec2)
77  TYPE_HELPER(GfVec3f, HdTypeFloatVec3)
78  TYPE_HELPER(GfVec4f, HdTypeFloatVec4)
79  TYPE_HELPER(double, HdTypeDouble)
80  TYPE_HELPER(GfVec2d, HdTypeDoubleVec2)
81  TYPE_HELPER(GfVec3d, HdTypeDoubleVec3)
82  TYPE_HELPER(GfVec4d, HdTypeDoubleVec4)
83  TYPE_HELPER(GfMatrix4f, HdTypeFloatMat4)
84  TYPE_HELPER(GfMatrix4d, HdTypeDoubleMat4)
85 #undef TYPE_HELPER
86 
96 public:
102  : _buffer(buffer) {}
103 
117  bool Sample(int index, void* value, HdTupleType dataType) const;
118 
119  // Convenient, templated frontend for Sample().
120  template<typename T> bool Sample(int index, T* value) const {
121  return Sample(index, static_cast<void*>(value),
122  HdEmbreeTypeHelper::GetTupleType<T>());
123  }
124 
125 private:
126  HdVtBufferSource const& _buffer;
127 };
128 
136 public:
138  HdEmbreePrimvarSampler() = default;
140  virtual ~HdEmbreePrimvarSampler() = default;
141 
158  virtual bool Sample(unsigned int element, float u, float v, void* value,
159  HdTupleType dataType) const = 0;
160 
161  // Convenient, templated frontend for Sample().
162  template<typename T> bool Sample(unsigned int element, float u, float v,
163  T* value) const {
164  return Sample(element, u, v, static_cast<void*>(value),
165  HdEmbreeTypeHelper::GetTupleType<T>());
166  }
167 
168 protected:
177  static bool _Interpolate(void* out, void** samples, float* weights,
178  size_t sampleCount, HdTupleType dataType);
179 };
180 
181 PXR_NAMESPACE_CLOSE_SCOPE
182 
183 #endif // PXR_IMAGING_PLUGIN_HD_EMBREE_SAMPLER_H
Basic type for a vector of 4 int components.
Definition: vec4i.h:61
Stores a 4x4 matrix of float elements.
Definition: matrix4f.h:88
static HdTupleType GetTupleType()
Return the HdTupleType corresponding to the given C++ type.
Basic type for a vector of 2 int components.
Definition: vec2i.h:61
virtual bool Sample(unsigned int element, float u, float v, void *value, HdTupleType dataType) const =0
Sample the primvar at element index index and local basis coordinates u and v, writing the sample to ...
A utility class that helps map between C++ types and Hd type tags.
Definition: sampler.h:50
HdEmbreeBufferSampler(HdVtBufferSource const &buffer)
The constructor takes a reference to a buffer source.
Definition: sampler.h:101
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:325
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
An abstract base class that knows how to sample a primvar signal given a ray hit coordinate: an &lt;elem...
Definition: sampler.h:135
Basic type for a vector of 4 double components.
Definition: vec4d.h:63
static bool _Interpolate(void *out, void **samples, float *weights, size_t sampleCount, HdTupleType dataType)
Utility function for derived classes: combine multiple samples with blend weights: out = sum_i { samp...
Basic type for a vector of 2 double components.
Definition: vec2d.h:63
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type for a vector of 3 int components.
Definition: vec3i.h:61
virtual ~HdEmbreePrimvarSampler()=default
Default destructor.
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
bool Sample(int index, void *value, HdTupleType dataType) const
Sample the buffer at element index index, and write the sample to value.
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
Basic type for a vector of 3 double components.
Definition: vec3d.h:63
A utility class that knows how to sample an element from a type-tagged buffer (like HdVtBufferSource)...
Definition: sampler.h:95
HdEmbreePrimvarSampler()=default
Default constructor.
An implementation of HdBufferSource where the source data value is a VtValue.
char PrimvarTypeContainer[sizeof(GfMatrix4d)]
Define a type that can hold one sample of any primvar.
Definition: sampler.h:57