All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
sampler.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_PLUGIN_HD_EMBREE_SAMPLER_H
8#define PXR_IMAGING_PLUGIN_HD_EMBREE_SAMPLER_H
9
10#include "pxr/pxr.h"
11#include <cstddef>
12
13#include "pxr/imaging/hd/enums.h"
14#include "pxr/imaging/hd/vtBufferSource.h"
15
18#include "pxr/base/gf/vec2d.h"
19#include "pxr/base/gf/vec2f.h"
20#include "pxr/base/gf/vec2i.h"
21#include "pxr/base/gf/vec3d.h"
22#include "pxr/base/gf/vec3f.h"
23#include "pxr/base/gf/vec3i.h"
24#include "pxr/base/gf/vec4d.h"
25#include "pxr/base/gf/vec4f.h"
26#include "pxr/base/gf/vec4i.h"
27
28PXR_NAMESPACE_OPEN_SCOPE
29
34public:
36 template<typename T>
38
40 typedef char PrimvarTypeContainer[sizeof(GfMatrix4d)];
41};
42
43// Define template specializations of HdEmbreeTypeHelper methods for
44// all our supported types...
45#define TYPE_HELPER(T,type)\
46template<> inline HdTupleType \
47HdEmbreeTypeHelper::GetTupleType<T>() { return HdTupleType{type, 1}; }
48
49 TYPE_HELPER(bool, HdTypeBool)
50 TYPE_HELPER(char, HdTypeInt8)
51 TYPE_HELPER(short, HdTypeInt16)
52 TYPE_HELPER(unsigned short, HdTypeUInt16)
53 TYPE_HELPER(int, HdTypeInt32)
54 TYPE_HELPER(GfVec2i, HdTypeInt32Vec2)
55 TYPE_HELPER(GfVec3i, HdTypeInt32Vec3)
56 TYPE_HELPER(GfVec4i, HdTypeInt32Vec4)
57 TYPE_HELPER(unsigned int, HdTypeUInt32)
58 TYPE_HELPER(float, HdTypeFloat)
59 TYPE_HELPER(GfVec2f, HdTypeFloatVec2)
60 TYPE_HELPER(GfVec3f, HdTypeFloatVec3)
61 TYPE_HELPER(GfVec4f, HdTypeFloatVec4)
62 TYPE_HELPER(double, HdTypeDouble)
63 TYPE_HELPER(GfVec2d, HdTypeDoubleVec2)
64 TYPE_HELPER(GfVec3d, HdTypeDoubleVec3)
65 TYPE_HELPER(GfVec4d, HdTypeDoubleVec4)
66 TYPE_HELPER(GfMatrix4f, HdTypeFloatMat4)
67 TYPE_HELPER(GfMatrix4d, HdTypeDoubleMat4)
68 TYPE_HELPER(GfQuath, HdTypeHalfFloatVec4)
69#undef TYPE_HELPER
70
80public:
86 : _buffer(buffer) {}
87
101 bool Sample(int index, void* value, HdTupleType dataType) const;
102
103 // Convenient, templated frontend for Sample().
104 template<typename T> bool Sample(int index, T* value) const {
105 return Sample(index, static_cast<void*>(value),
106 HdEmbreeTypeHelper::GetTupleType<T>());
107 }
108
109private:
110 HdVtBufferSource const& _buffer;
111};
112
120public:
124 virtual ~HdEmbreePrimvarSampler() = default;
125
142 virtual bool Sample(unsigned int element, float u, float v, void* value,
143 HdTupleType dataType) const = 0;
144
145 // Convenient, templated frontend for Sample().
146 template<typename T> bool Sample(unsigned int element, float u, float v,
147 T* value) const {
148 return Sample(element, u, v, static_cast<void*>(value),
149 HdEmbreeTypeHelper::GetTupleType<T>());
150 }
151
152protected:
161 static bool _Interpolate(void* out, void** samples, float* weights,
162 size_t sampleCount, HdTupleType dataType);
163};
164
165PXR_NAMESPACE_CLOSE_SCOPE
166
167#endif // PXR_IMAGING_PLUGIN_HD_EMBREE_SAMPLER_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Stores a 4x4 matrix of float elements.
Definition: matrix4f.h:71
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Definition: quath.h:44
Basic type for a vector of 2 double components.
Definition: vec2d.h:46
Basic type for a vector of 2 float components.
Definition: vec2f.h:46
Basic type for a vector of 2 int components.
Definition: vec2i.h:44
Basic type for a vector of 3 double components.
Definition: vec3d.h:46
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
Basic type for a vector of 3 int components.
Definition: vec3i.h:44
Basic type for a vector of 4 double components.
Definition: vec4d.h:46
Basic type for a vector of 4 float components.
Definition: vec4f.h:46
Basic type for a vector of 4 int components.
Definition: vec4i.h:44
A utility class that knows how to sample an element from a type-tagged buffer (like HdVtBufferSource)...
Definition: sampler.h:79
bool Sample(int index, void *value, HdTupleType dataType) const
Sample the buffer at element index index, and write the sample to value.
HdEmbreeBufferSampler(HdVtBufferSource const &buffer)
The constructor takes a reference to a buffer source.
Definition: sampler.h:85
An abstract base class that knows how to sample a primvar signal given a ray hit coordinate: an <elem...
Definition: sampler.h:119
virtual ~HdEmbreePrimvarSampler()=default
Default destructor.
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 ...
HdEmbreePrimvarSampler()=default
Default constructor.
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...
A utility class that helps map between C++ types and Hd type tags.
Definition: sampler.h:33
static HdTupleType GetTupleType()
Return the HdTupleType corresponding to the given C++ type.
char PrimvarTypeContainer[sizeof(GfMatrix4d)]
Define a type that can hold one sample of any primvar.
Definition: sampler.h:40
An implementation of HdBufferSource where the source data value is a VtValue.
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:343