Go to the documentation of this file.
50 #if !defined(PTEX_PLATFORM_WINDOWS)
52 # define PTEX_USE_STDSTRING
131 static const int sizes[] = { 1,2,2,4 };
137 static const float one[] = { 255.f, 65535.f, 1.f, 1.f };
143 static const float one[] = { 1.f/255.f, 1.f/65535.f, 1.f, 1.f };
170 Res(uint16_t value) :
ulog2(int8_t(value&0xff)),
vlog2(int8_t((value>>8)&0xff)) {}
173 int u()
const {
return 1<<(unsigned)
ulog2; }
176 int v()
const {
return 1<<(unsigned)
vlog2; }
248 FaceInfo(
Res res_,
int adjfaces_[4],
int adjedges_[4],
bool isSubface_=
false)
251 setadjfaces(adjfaces_[0], adjfaces_[1], adjfaces_[2], adjfaces_[3]);
252 setadjedges(adjedges_[0], adjedges_[1], adjedges_[2], adjedges_[3]);
279 {
adjedges = (uint8_t)((e0&3) | ((e1&3)<<2) | ((e2&3)<<4) | ((e3&3)<<6)); }
292 #ifdef PTEX_USE_STDSTRING
293 typedef std::string String;
313 #ifndef PTEX_USE_STDSTRING
348 virtual void getValue(
const char* key,
const char*& value) = 0;
352 virtual void getValue(
int index,
const char*& value) = 0;
356 virtual void getValue(
const char* key,
const int8_t*& value,
int& count) = 0;
360 virtual void getValue(
int index,
const int8_t*& value,
int& count) = 0;
364 virtual void getValue(
const char* key,
const int16_t*& value,
int& count) = 0;
368 virtual void getValue(
int index,
const int16_t*& value,
int& count) = 0;
372 virtual void getValue(
const char* key,
const int32_t*& value,
int& count) = 0;
376 virtual void getValue(
int index,
const int32_t*& value,
int& count) = 0;
380 virtual void getValue(
const char* key,
const float*& value,
int& count) = 0;
384 virtual void getValue(
int index,
const float*& value,
int& count) = 0;
388 virtual void getValue(
const char* key,
const double*& value,
int& count) = 0;
392 virtual void getValue(
int index,
const double*& value,
int& count) = 0;
426 virtual void getPixel(
int u,
int v,
void* result) = 0;
483 virtual const char*
path() = 0;
551 virtual void getData(
int faceid,
void* buffer,
int stride) = 0;
593 float* result,
int firstchan,
int nchannels) = 0;
607 float* result,
int firstchan,
int nchannels,
640 virtual size_t read(
void* buffer,
size_t size,
Handle handle) = 0;
713 bool premultiply=
false,
771 virtual void purge(
const char* path) = 0;
829 int nchannels,
int alphachan,
int nfaces,
852 int nchannels,
int alphachan,
int nfaces,
876 virtual void writeMeta(
const char* key,
const char*
string) = 0;
879 virtual void writeMeta(
const char* key,
const int8_t* value,
int count) = 0;
882 virtual void writeMeta(
const char* key,
const int16_t* value,
int count) = 0;
885 virtual void writeMeta(
const char* key,
const int32_t* value,
int count) = 0;
888 virtual void writeMeta(
const char* key,
const float* value,
int count) = 0;
891 virtual void writeMeta(
const char* key,
const double* value,
int count) = 0;
922 virtual bool writeFaceReduction(
int faceid,
const Ptex::Res& res,
const void* data,
int stride=0) = 0;
923 virtual bool writeConstantFaceReduction(
int faceid,
const Ptex::Res& res,
const void* data) = 0;
997 virtual void eval(
float* result,
int firstchan,
int nchannels,
998 int faceid,
float u,
float v,
float uw1,
float vw1,
float uw2,
float vw2,
999 float width=1,
float blur=0) = 0;
1042 operator T* ()
const {
return _ptr; }
1077 using Ptex::PtexMetaData;
1078 using Ptex::PtexFaceData;
1079 using Ptex::PtexTexture;
1080 using Ptex::PtexInputHandler;
1081 using Ptex::PtexErrorHandler;
1082 using Ptex::PtexCache;
1083 using Ptex::PtexWriter;
1084 using Ptex::PtexFilter;
1085 using Ptex::PtexPtr;
@ f_bilinear
Bi-linear interpolation.
FaceInfo(Res res_)
Constructor.
bool operator!=(const Res &r) const
Comparison operator.
virtual Ptex::Res res()=0
Resolution of the texture held by this data block.
~PtexPtr()
Destructor, calls ptr->release().
virtual PtexFaceData * getTile(int tile)=0
Access a tile from the data block.
virtual PtexFaceData * getData(int faceid, Ptex::Res res)=0
Access texture data for a face at a specific resolution as stored on disk.
Pixel resolution of a given texture.
@ efm_none
Don't do anything with the values.
int ntiles(Res tileres) const
Determine the total number of tiles for the given tile res.
virtual bool isTiled()=0
True if this data block is tiled.
@ mdt_int32
Signed 32-bit integer.
virtual void purge(const char *path)=0
Remove a texture file from the cache by pathname.
virtual Ptex::BorderMode vBorderMode()=0
Mode for filtering texture access beyond mesh border.
static PtexCache * create(int maxFiles, size_t maxMem, bool premultiply=false, PtexInputHandler *inputHandler=0, PtexErrorHandler *errorHandler=0)
Create a cache with the specified limits.
virtual int numChannels()=0
Number of channels stored in file.
FilterType filter
Filter type.
virtual ~PtexFilter()
Destructor not for public use. Use release() instead.
@ f_mitchell
Mitchell (equivalent to bi-cubic w/ sharpness=2/3)
@ dt_half
Half-precision (16-bit) floating point.
const char * EdgeIdName(EdgeId eid)
Look up name of given edge ID.
void setadjedges(int e0, int e1, int e2, int e3)
Set the adjedges data.
virtual void setSearchPath(const char *path)=0
Set a search path for finding textures.
@ e_top
Top edge, from UV (1,1) to (0,1)
#define PTEX_NAMESPACE_END
virtual int alphaChannel()=0
Index of alpha channel (if any).
virtual void writeMeta(const char *key, const int16_t *value, int count)=0
Write an array of signed 16-bit integers as meta data.
virtual bool isConstant()=0
True if this data block is constant.
virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo &info, const void *data)=0
Write constant texture data for a face.
virtual void getStats(Stats &stats)=0
Get stats.
T * operator->() const
Access members of pointer.
File-handle and memory cache for reading ptex files.
float OneValueInv(DataType dt)
Lookup up inverse value of given data type that corresponds to the normalized value of 1....
uint16_t val() const
Resolution as a single 16-bit integer value.
Res swappeduv() const
Get value of resolution with u and v swapped.
const char * BorderModeName(BorderMode m)
Look up name of given border mode.
Res()
Default constructor, sets res to 0 (1x1 texel).
Res(int8_t ulog2_, int8_t vlog2_)
Constructor.
@ dt_float
Single-precision (32-bit) floating point.
virtual Ptex::Res tileRes()=0
Resolution of each tile in this data block.
int32_t adjfaces[4]
Adjacent faces (-1 == no adjacent face).
int8_t ulog2
log base 2 of u resolution, in texels
virtual ~PtexErrorHandler()
void swapuv()
Swap the u and v resolution values in place.
@ m_clamp
texel access is clamped to border
virtual ~PtexWriter()
Destructor not for public use. Use release() instead.
int DataSize(DataType dt)
Look up size of given data type (in bytes).
bool isSubface() const
Determine if face is a subface (by checking a flag).
@ f_gaussian
Gaussian filter.
const char * MetaDataTypeName(MetaDataType mdt)
Look up name of given meta data type.
PtexPtr(const PtexPtr &p)
Copying prohibited.
virtual void writeMeta(const char *key, const float *value, int count)=0
Write an array of signed 32-bit floats as meta data.
virtual PtexMetaData * getMetaData()=0
Access meta data.
virtual bool hasEdits()=0
True if the file has edit blocks.
int8_t vlog2
log base 2 of v resolution, in texels
int adjface(int eid) const
Access an adjacent face id. The eid value must be 0..3.
@ mdt_double
Double-precision (32-bit) floating point.
virtual void writeMeta(const char *key, const int8_t *value, int count)=0
Write an array of signed 8-bit integers as meta data.
@ m_black
texel beyond border are assumed to be black
virtual void purge(PtexTexture *texture)=0
Remove a texture file from the cache.
int __structSize
(for internal use only)
DataType
Type of data stored in texture file.
Custom handler interface redirecting Ptex error messages.
virtual Ptex::MeshType meshType()=0
Type of mesh for which texture data is defined.
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
@ mdt_int8
Signed 8-bit integer.
Information about a face, as stored in the Ptex file header.
virtual PtexFaceData * getData(int faceid)=0
Access texture data for a face at highest-resolution as stored on disk.
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
Get most commonly used info in a single call for convenience / efficiency.
const char * MeshTypeName(MeshType mt)
Look up name of given mesh type.
@ f_point
Point-sampled (no filtering)
String & operator=(const char *str)
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels, Ptex::Res res)=0
Access a single texel for a face at a particular resolution.
bool lerp
Interpolate between mipmap levels.
virtual bool close(Ptex::String &error)=0
Close the file.
static bool applyEdits(const char *path, Ptex::String &error)
Apply edits to a file.
@ efm_tanvec
Values are vectors in tangent space; rotate values.
virtual int numFaces()=0
Number of faces stored in file.
virtual void writeMeta(const char *key, const double *value, int count)=0
Write an array of signed 32-bit doubles as meta data.
virtual void release()=0
Release PtexCache. Cache will be immediately destroyed and all resources will be released.
virtual void setEdgeFilterMode(Ptex::EdgeFilterMode edgeFilterMode)=0
Set edge filter mode.
virtual void getData(int faceid, void *buffer, int stride)=0
Access texture data for a face at highest-resolution.
virtual void purgeAll()=0
Remove all texture files from the cache.
@ dt_uint16
Unsigned, 16-bit integer.
EdgeFilterMode edgeFilterMode
Interface for filtered sampling of ptex data files.
bool isConstant() const
Determine if face is constant (by checking a flag).
void ConvertToFloat(float *dst, const void *src, Ptex::DataType dt, int numChannels)
Convert a number of data values from the given data type to float.
virtual bool hasMipMaps()=0
True if the file has mipmaps.
@ dt_uint8
Unsigned, 8-bit integer.
bool operator>=(const Res &r) const
True if res is >= given res in both u and v directions.
virtual void getPixel(int u, int v, void *result)=0
Read a single texel from the data block.
void clamp(const Res &r)
Clamp the resolution value against the given value.
static PtexWriter * edit(const char *path, bool incremental, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, Ptex::String &error, bool genmipmaps=true)
Open an existing texture file for writing.
void reset(T *ptr=0)
Deallocate object pointed to, and optionally set to new value.
float OneValue(DataType dt)
Look up value of given data type that corresponds to the normalized value of 1.0.
Interface for writing data to a ptex file.
@ mt_triangle
Mesh is triangle-based.
MetaDataType
Type of meta data entry.
const char * EdgeFilterModeName(EdgeFilterMode m)
Look up name of given edge filter mode.
Common data structures and enums used throughout the API.
T * get() const
Get pointer value.
Per-face texture data accessor.
void ConvertFromFloat(void *dst, const float *src, Ptex::DataType dt, int numChannels)
Convert a number of data values from float to the given data type.
int ntilesv(Res tileres) const
Determine the number of tiles in the v direction for the given tile res.
static PtexTexture * open(const char *path, Ptex::String &error, bool premultiply=0)
Open a ptex file for reading.
virtual ~PtexTexture()
Destructor not for public use. Use release() instead.
Smart-pointer for acquiring and releasing API objects.
virtual void writeMeta(const char *key, const char *string)=0
Write a string as meta data.
FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
Constructor.
void setadjfaces(int f0, int f1, int f2, int f3)
Set the adjfaces data.
bool operator==(const Res &r) const
Comparison operator.
Interface for reading data from a ptex file.
@ mdt_string
Null-terminated string.
int size() const
Total size of specified texture in texels (u * v).
static PtexFilter * getFilter(PtexTexture *tx, const Options &opts)
virtual Ptex::BorderMode uBorderMode()=0
Mode for filtering texture access beyond mesh border.
Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0, bool noedgeblend_=0)
Constructor - sets defaults.
virtual void eval(float *result, int firstchan, int nchannels, int faceid, float u, float v, float uw1, float vw1, float uw2, float vw2, float width=1, float blur=0)=0
Apply filter to a ptex data file.
EdgeFilterMode
How to handle transformation across edges when filtering.
Definitions related to exported Ptex API symbol visibility.
virtual ~PtexFaceData()
Destructor not for public use. Use release() instead.
@ e_bottom
Bottom edge, from UV (0,0) to (1,0)
const char * DataTypeName(DataType dt)
Look up name of given data type.
@ m_periodic
texel access wraps to other side of face
String(const String &str)
void swap(PtexPtr &p)
Swap pointer values.
int u() const
U resolution in texels.
@ e_right
Right edge, from UV (1,0) to (1,1)
virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode)=0
Set border modes.
virtual void reportError(const char *error)=0
virtual const char * getSearchPath()=0
Query the search path.
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)=0
Access resolution and adjacency information about a face.
@ e_left
Left edge, from UV (0,1) to (0,0)
virtual const char * path()=0
Path that file was opened with.
Res(uint16_t value)
Constructor.
virtual void * getData()=0
Access the data from this data block.
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 Ptex::EdgeFilterMode edgeFilterMode()=0
Mode for filtering textures across edges.
uint8_t adjedges
Adjacent edges, 2 bits per edge.
int v() const
V resolution in texels.
@ f_catmullrom
Catmull-Rom (equivalent to bi-cubic w/ sharpness=1)
EdgeId adjedge(int eid) const
Access an adjacent edge id. The eid value must be 0..3.
virtual void writeMeta(PtexMetaData *data)=0
Copy meta data from an existing meta data block.
bool isNeighborhoodConstant() const
Determine if neighborhood of face is constant (by checking a flag).
virtual ~PtexCache()
Destructor not for public use. Use release() instead.
@ mdt_int16
Signed 16-bit integer.
virtual PtexTexture * get(const char *path, Ptex::String &error)=0
Access a texture.
virtual Ptex::DataType dataType()=0
Type of data stored in file.
virtual bool writeFace(int faceid, const Ptex::FaceInfo &info, const void *data, int stride=0)=0
Write texture data for a face.
@ f_bicubic
General bi-cubic filter (uses sharpness option)
PtexPtr(T *ptr=0)
Constructor.
String & operator=(const std::string &str)
void operator=(PtexPtr &p)
Assignment prohibited.
FaceInfo()
Default constructor.
Res res
Resolution of face.
virtual void writeMeta(const char *key, const int32_t *value, int count)=0
Write an array of signed 32-bit integers as meta data.
String & operator=(const String &str)
@ mdt_float
Single-precision (32-bit) floating point.
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
@ mt_quad
Mesh is quad-based.
BorderMode
How to handle mesh border when filtering.
float sharpness
Filter sharpness, 0..1 (for general bi-cubic filter only).
std::ostream & operator<<(std::ostream &stream, const String &str)
int ntilesu(Res tileres) const
Determine the number of tiles in the u direction for the given tile res.
const char * c_str() const
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
static PtexWriter * open(const char *path, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, Ptex::String &error, bool genmipmaps=true)
Open a new texture file for writing.
MeshType
Type of base mesh for which the textures are defined.
@ f_bspline
BSpline (equivalent to bi-cubic w/ sharpness=0)
bool noedgeblend
Disable cross-face filtering. Useful for debugging or rendering on polys.
virtual void getData(int faceid, void *buffer, int stride, Ptex::Res res)=0
Access texture data for a face at a specific resolution.
Portable fixed-width integer types.
EdgeId
Edge IDs used in adjacency data in the Ptex::FaceInfo struct.
bool hasEdits() const
Determine if face has edits in the file (by checking a flag).