50 virtual void eval(
float* result,
int firstchan,
int nchannels,
51 int faceid,
float u,
float v,
52 float ,
float ,
float ,
float ,
55 if (!
_tx || nchannels <= 0)
return;
56 if (faceid < 0 || faceid >=
_tx->
numFaces())
return;
58 int resu = f.
res.
u(), resv = f.res.v();
61 _tx->
getPixel(faceid, ui, vi, result, firstchan, nchannels);
75 virtual void eval(
float* result,
int firstchan,
int nchannels,
76 int faceid,
float u,
float v,
77 float ,
float ,
float ,
float ,
80 if (!
_tx || nchannels <= 0)
return;
81 if (faceid < 0 || faceid >=
_tx->
numFaces())
return;
85 float ut = u * (float)res, vt = v * (
float)res;
88 float uf = ut - (float)ui, vf = vt - (
float)vi;
90 if (uf + vf <= 1.0f) {
92 _tx->
getPixel(faceid, ui, vi, result, firstchan, nchannels);
96 _tx->
getPixel(faceid, resm1-vi, resm1-ui, result, firstchan, nchannels);
138 return x < 1.0f ? (2.0f*x-3.0f)*x*x+1.0f : 0.0f;
142 float u,
float uw,
int f_ureslog2)
151 int resu = 1 << k_ureslog2;
152 float uwlo = 1.0f/(float)resu;
156 float lerp1 = 1.0f-lerp2;
162 float upix = u * 4.0f - 0.5f;
163 int u1 = int(PtexUtils::ceil(upix - 2)), u2 = int(PtexUtils::ceil(upix + 2));
168 float x1 = (float)u1-upix;
169 for (
int i = 0; i < k_uw; i+=2) {
170 float xa = x1 + (float)i, xb = xa + 1.0f, xc = (xa+xb)*0.25f;
173 float s = 1.0f/(uw + .75f);
174 float ka =
_k(xa,
_c), kb =
_k(xb,
_c), kc =
blur(xc*s);
175 ku[i] = ka * lerp1 + kc * lerp2;
176 ku[i+1] = kb * lerp1 + kc * lerp2;
182 float upix = u * 2.0f - 0.5f;
183 k_u = int(PtexUtils::floor(u - .5f))*2;
185 float x1 = (float)k_u-upix;
186 for (
int i = 0; i < k_uw; i+=2) {
187 float xa = x1 + (float)i, xb = xa + 1.0f, xc = (xa+xb)*0.5f;
190 float s = 1.0f/(uw*1.5f + .5f);
191 float ka =
blur(xa*s), kb =
blur(xb*s), kc =
blur(xc*s);
192 ku[i] = ka * lerp1 + kc * lerp2;
193 ku[i+1] = kb * lerp1 + kc * lerp2;
201 float upix = u - .5f;
203 float ui = PtexUtils::floor(upix);
205 ku[0] =
blur(upix-ui);
212 float upix = u * (float)resu - 0.5f;
213 float uwpix = uw * (float)resu;
217 float dupix = 2.0f*uwpix;
218 int u1 = int(PtexUtils::ceil(upix - dupix)), u2 = int(PtexUtils::ceil(upix + dupix));
229 float step = 1.0f/uwpix, x1 = ((float)u1-upix)*(float)step;
230 for (
int i = 0; i < k_uw; i+=2) {
231 float xa = x1 + (float)i*step, xb = xa + step, xc = (xa+xb)*0.5f;
232 float ka =
_k(xa,
_c), kb =
_k(xb,
_c), kc =
_k(xc,
_c);
233 ku[i] = ka * lerp1 + kc * lerp2;
234 ku[i+1] = kb * lerp1 + kc * lerp2;
241 float x1 = ((float)u1-upix)/uwpix, step = 1.0f/uwpix;
242 for (
int i = 0; i < k_uw; i++) ku[i] =
_k(x1 + (
float)i*step,
_c);
267 float B = 1.0f - sharpness;
270 _coeffs[2] = 1.0f - float(1.0/3.0) * B;
271 _coeffs[3] = float(1.0/3.0) * B - 0.5f;
274 _coeffs[6] = 2.0f - float(2.0/3.0) * B;
281 if (x < 1.0f)
return (c[0]*x + c[1])*x*x + c[2];
282 else if (x < 2.0f)
return ((c[3]*x + c[4])*x + c[5])*x + c[6];
301 return (
float)exp(-2.0f*x*x);
332 Res res(ureslog2, vreslog2);
336 u = u * (float)k.
res.u();
337 v = v * (float)k.
res.v();
338 uw *= (float)k.
res.u();
339 vw *= (float)k.
res.v();
343 float u1 = u - 0.5f*uw, u2 = u + 0.5f*uw;
344 float v1 = v - 0.5f*vw, v2 = v + 0.5f*vw;
345 float u1floor = PtexUtils::floor(u1), u2ceil = PtexUtils::ceil(u2);
346 float v1floor = PtexUtils::floor(v1), v2ceil = PtexUtils::ceil(v2);
349 k.
uw = int(u2ceil)-k.
u;
350 k.
vw = int(v2ceil)-k.
v;
360 assert(size >= 1 && size <= 3);
363 kernel[0] = f1 + f2 - 1.0f;
367 for (
int i = 1; i < size-1; i++) kernel[i] = 1.0f;
395 Res res(ureslog2, vreslog2);
399 float upix = u * (float)k.
res.u() - 0.5f;
400 float vpix = v * (float)k.
res.v() - 0.5f;
402 float ufloor = PtexUtils::floor(upix);
403 float vfloor = PtexUtils::floor(vpix);
410 float ufrac = upix-ufloor, vfrac = vpix-vfloor;
411 k.
ku[0] = 1.0f - ufrac;
413 k.
kv[0] = 1.0f - vfrac;
#define PTEX_NAMESPACE_END
Public API classes for reading, writing, caching, and filtering Ptex files.
Separable bicubic filter.
static float kernelFn(float x, const float *c)
PtexBicubicFilter(PtexTexture *tx, const PtexFilter::Options &opts, float sharpness)
Bilinear filter (for rectangular textures)
PtexBilinearFilter(PtexTexture *tx, const PtexFilter::Options &opts)
virtual void buildKernel(PtexSeparableKernel &k, float u, float v, float uw, float vw, Res faceRes)
PtexBoxFilter(PtexTexture *tx, const PtexFilter::Options &opts)
void computeWeights(float *kernel, int size, float f1, float f2)
virtual void buildKernel(PtexSeparableKernel &k, float u, float v, float uw, float vw, Res faceRes)
Interface for filtered sampling of ptex data files.
static PtexFilter * getFilter(PtexTexture *tx, const Options &opts)
@ f_bicubic
General bi-cubic filter (uses sharpness option)
@ f_bspline
BSpline (equivalent to bi-cubic w/ sharpness=0)
@ f_bilinear
Bi-linear interpolation.
@ f_catmullrom
Catmull-Rom (equivalent to bi-cubic w/ sharpness=1)
@ f_mitchell
Mitchell (equivalent to bi-cubic w/ sharpness=2/3)
@ f_gaussian
Gaussian filter.
@ f_point
Point-sampled (no filtering)
Separable gaussian filter.
PtexGaussianFilter(PtexTexture *tx, const PtexFilter::Options &opts)
static float kernelFn(float x, const float *)
Point-sampling filter for triangular textures.
virtual void eval(float *result, int firstchan, int nchannels, int faceid, float u, float v, float, float, float, float, float, float)
Apply filter to a ptex data file.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
PtexPointFilterTri(PtexTexture *tx)
Point-sampling filter for rectangular textures.
virtual void eval(float *result, int firstchan, int nchannels, int faceid, float u, float v, float, float, float, float, float, float)
Apply filter to a ptex data file.
PtexPointFilter(PtexTexture *tx)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
Interface for reading data from a ptex file.
virtual Ptex::MeshType meshType()=0
Type of mesh for which texture data is defined.
virtual int numFaces()=0
Number of faces stored in file.
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels)=0
Access a single texel from the highest resolution texture .
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)=0
Access resolution and adjacency information about a face.
Separable filter with width=4 support.
PtexWidth4Filter(PtexTexture *tx, const PtexFilter::Options &opts, KernelFn k, const float *c=0)
void buildKernelAxis(int8_t &k_ureslog2, int &k_u, int &k_uw, float *ku, float u, float uw, int f_ureslog2)
float KernelFn(float x, const float *c)
virtual void buildKernel(PtexSeparableKernel &k, float u, float v, float uw, float vw, Res faceRes)
float reciprocalPow2(int power)
int calcResFromWidth(float w)
@ mt_triangle
Mesh is triangle-based.
@ mt_quad
Mesh is quad-based.
FilterType filter
Filter type.
float sharpness
Filter sharpness, 0..1 (for general bi-cubic filter only).
bool lerp
Interpolate between mipmap levels.
Res res
Resolution of face.
int u() const
U resolution in texels.