Ptexture.h
Go to the documentation of this file.
#ifndef Ptexture_h
#define Ptexture_h
/*
PTEX SOFTWARE
Copyright 2014 Disney Enterprises, Inc. All rights reserved
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
Studios" or the names of its contributors may NOT be used to
endorse or promote products derived from this software without
specific prior written permission from Walt Disney Pictures.
Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include "PtexExports.h"
#include "PtexInt.h"
#include "PtexVersion.h"
#include <ostream>
#if !defined(PTEX_PLATFORM_WINDOWS)
# ifndef DOXYGEN
# define PTEX_USE_STDSTRING
# endif
#endif
#ifdef DOXYGEN
namespace Ptex {
#else
PTEX_NAMESPACE_BEGIN
#endif
enum MeshType {
mt_triangle,
mt_quad
};
enum DataType {
dt_uint8,
dt_uint16,
dt_half,
dt_float
};
enum EdgeFilterMode {
efm_none,
efm_tanvec
};
enum BorderMode {
m_clamp,
m_black,
m_periodic
};
enum EdgeId {
e_bottom,
e_right,
e_top,
e_left
};
enum MetaDataType {
mdt_string,
mdt_int8,
mdt_int16,
mdt_int32,
mdt_float,
mdt_double
};
PTEXAPI const char* MeshTypeName(MeshType mt);
PTEXAPI const char* DataTypeName(DataType dt);
PTEXAPI const char* BorderModeName(BorderMode m);
PTEXAPI const char* EdgeFilterModeName(EdgeFilterMode m);
PTEXAPI const char* EdgeIdName(EdgeId eid);
PTEXAPI const char* MetaDataTypeName(MetaDataType mdt);
inline int DataSize(DataType dt) {
static const int sizes[] = { 1,2,2,4 };
return sizes[dt];
}
inline float OneValue(DataType dt) {
static const float one[] = { 255.f, 65535.f, 1.f, 1.f };
return one[dt];
}
inline float OneValueInv(DataType dt) {
static const float one[] = { 1.f/255.f, 1.f/65535.f, 1.f, 1.f };
return one[dt];
}
PTEXAPI void ConvertToFloat(float* dst, const void* src,
Ptex::DataType dt, int numChannels);
PTEXAPI void ConvertFromFloat(void* dst, const float* src,
Ptex::DataType dt, int numChannels);
struct Res {
int8_t ulog2;
int8_t vlog2;
Res() : ulog2(0), vlog2(0) {}
Res(int8_t ulog2_, int8_t vlog2_) : ulog2(ulog2_), vlog2(vlog2_) {}
Res(uint16_t value) : ulog2(int8_t(value&0xff)), vlog2(int8_t((value>>8)&0xff)) {}
int u() const { return 1<<(unsigned)ulog2; }
int v() const { return 1<<(unsigned)vlog2; }
uint16_t val() const { return uint16_t(ulog2 | (vlog2<<8)); }
int size() const { return u() * v(); }
bool operator==(const Res& r) const { return r.ulog2 == ulog2 && r.vlog2 == vlog2; }
bool operator!=(const Res& r) const { return !(r==*this); }
bool operator>=(const Res& r) const { return ulog2 >= r.ulog2 && vlog2 >= r.vlog2; }
Res swappeduv() const { return Res(vlog2, ulog2); }
void swapuv() { *this = swappeduv(); }
void clamp(const Res& r) {
if (ulog2 > r.ulog2) ulog2 = r.ulog2;
if (vlog2 > r.vlog2) vlog2 = r.vlog2;
}
int ntilesu(Res tileres) const { return 1<<(ulog2-tileres.ulog2); }
int ntilesv(Res tileres) const { return 1<<(vlog2-tileres.vlog2); }
int ntiles(Res tileres) const { return ntilesu(tileres) * ntilesv(tileres); }
};
struct FaceInfo {
Res res;
uint8_t adjedges;
uint8_t flags;
int32_t adjfaces[4];
FaceInfo() : res(), adjedges(0), flags(0)
{
adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
}
FaceInfo(Res res_) : res(res_), adjedges(0), flags(0)
{
adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
}
FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
: res(res_), flags(isSubface_ ? flag_subface : 0)
{
setadjfaces(adjfaces_[0], adjfaces_[1], adjfaces_[2], adjfaces_[3]);
setadjedges(adjedges_[0], adjedges_[1], adjedges_[2], adjedges_[3]);
}
EdgeId adjedge(int eid) const { return EdgeId((adjedges >> (2*eid)) & 3); }
int adjface(int eid) const { return adjfaces[eid]; }
bool isConstant() const { return (flags & flag_constant) != 0; }
bool isNeighborhoodConstant() const { return (flags & flag_nbconstant) != 0; }
bool hasEdits() const { return (flags & flag_hasedits) != 0; }
bool isSubface() const { return (flags & flag_subface) != 0; }
void setadjfaces(int f0, int f1, int f2, int f3)
{ adjfaces[0] = f0, adjfaces[1] = f1, adjfaces[2] = f2; adjfaces[3] = f3; }
void setadjedges(int e0, int e1, int e2, int e3)
{ adjedges = (uint8_t)((e0&3) | ((e1&3)<<2) | ((e2&3)<<4) | ((e3&3)<<6)); }
enum { flag_constant = 1, flag_hasedits = 2, flag_nbconstant = 4, flag_subface = 8 };
};
#ifdef PTEX_USE_STDSTRING
typedef std::string String;
#else
class String
{
public:
String() : _str(0) {}
String(const String& str) : _str(0) { *this = str; }
PTEXAPI ~String();
PTEXAPI String& operator=(const char* str);
String& operator=(const String& str) { *this = str._str; return *this; }
String& operator=(const std::string& str) { *this = str.c_str(); return *this; }
const char* c_str() const { return _str ? _str : ""; }
bool empty() const { return _str == 0 || _str[0] == '\0'; }
private:
char* _str;
};
#endif
#ifndef PTEX_USE_STDSTRING
PTEXAPI std::ostream& operator << (std::ostream& stream, const Ptex::String& str);
#endif
#ifdef DOXYGEN
} // end namespace Ptex
#endif
class PtexMetaData {
protected:
virtual ~PtexMetaData() {}
public:
virtual void release() = 0;
virtual int numKeys() = 0;
virtual void getKey(int index, const char*& key, Ptex::MetaDataType& type) = 0;
virtual bool findKey(const char* key, int& index, Ptex::MetaDataType& type) = 0;
virtual void getValue(const char* key, const char*& value) = 0;
virtual void getValue(int index, const char*& value) = 0;
virtual void getValue(const char* key, const int8_t*& value, int& count) = 0;
virtual void getValue(int index, const int8_t*& value, int& count) = 0;
virtual void getValue(const char* key, const int16_t*& value, int& count) = 0;
virtual void getValue(int index, const int16_t*& value, int& count) = 0;
virtual void getValue(const char* key, const int32_t*& value, int& count) = 0;
virtual void getValue(int index, const int32_t*& value, int& count) = 0;
virtual void getValue(const char* key, const float*& value, int& count) = 0;
virtual void getValue(int index, const float*& value, int& count) = 0;
virtual void getValue(const char* key, const double*& value, int& count) = 0;
virtual void getValue(int index, const double*& value, int& count) = 0;
};
class PtexFaceData {
protected:
virtual ~PtexFaceData() {}
public:
virtual void release() = 0;
virtual bool isConstant() = 0;
virtual Ptex::Res res() = 0;
virtual void getPixel(int u, int v, void* result) = 0;
virtual void* getData() = 0;
virtual bool isTiled() = 0;
virtual Ptex::Res tileRes() = 0;
virtual PtexFaceData* getTile(int tile) = 0;
};
class PtexTexture {
protected:
virtual ~PtexTexture() {}
public:
PTEXAPI static PtexTexture* open(const char* path, Ptex::String& error, bool premultiply=0);
virtual void release() = 0;
virtual const char* path() = 0;
struct Info {
MeshType meshType;
DataType dataType;
BorderMode uBorderMode;
BorderMode vBorderMode;
EdgeFilterMode edgeFilterMode;
int alphaChannel;
int numChannels;
int numFaces;
};
virtual Info getInfo() = 0;
virtual Ptex::MeshType meshType() = 0;
virtual Ptex::DataType dataType() = 0;
virtual Ptex::BorderMode uBorderMode() = 0;
virtual Ptex::BorderMode vBorderMode() = 0;
virtual Ptex::EdgeFilterMode edgeFilterMode() = 0;
virtual int alphaChannel() = 0;
virtual int numChannels() = 0;
virtual int numFaces() = 0;
virtual bool hasEdits() = 0;
virtual bool hasMipMaps() = 0;
virtual PtexMetaData* getMetaData() = 0;
virtual const Ptex::FaceInfo& getFaceInfo(int faceid) = 0;
virtual void getData(int faceid, void* buffer, int stride) = 0;
virtual void getData(int faceid, void* buffer, int stride, Ptex::Res res) = 0;
virtual PtexFaceData* getData(int faceid) = 0;
virtual PtexFaceData* getData(int faceid, Ptex::Res res) = 0;
virtual void getPixel(int faceid, int u, int v,
float* result, int firstchan, int nchannels) = 0;
virtual void getPixel(int faceid, int u, int v,
float* result, int firstchan, int nchannels,
Ptex::Res res) = 0;
};
class PtexInputHandler {
protected:
virtual ~PtexInputHandler() {}
public:
typedef void* Handle;
virtual Handle open(const char* path) = 0;
virtual void seek(Handle handle, int64_t pos) = 0;
virtual size_t read(void* buffer, size_t size, Handle handle) = 0;
virtual bool close(Handle handle) = 0;
virtual const char* lastError() = 0;
};
class PtexErrorHandler {
protected:
virtual ~PtexErrorHandler() {}
public:
virtual void reportError(const char* error) = 0;
};
class PtexCache {
protected:
virtual ~PtexCache() {}
public:
PTEXAPI static PtexCache* create(int maxFiles,
size_t maxMem,
bool premultiply=false,
PtexInputHandler* inputHandler=0,
PtexErrorHandler* errorHandler=0);
virtual void release() = 0;
virtual void setSearchPath(const char* path) = 0;
virtual const char* getSearchPath() = 0;
virtual PtexTexture* get(const char* path, Ptex::String& error) = 0;
virtual void purge(PtexTexture* texture) = 0;
virtual void purge(const char* path) = 0;
virtual void purgeAll() = 0;
struct Stats {
uint64_t memUsed;
uint64_t peakMemUsed;
uint64_t filesOpen;
uint64_t peakFilesOpen;
uint64_t filesAccessed;
uint64_t fileReopens;
uint64_t blockReads;
};
virtual void getStats(Stats& stats) = 0;
};
class PtexWriter {
protected:
virtual ~PtexWriter() {}
public:
PTEXAPI
static PtexWriter* open(const char* path,
Ptex::MeshType mt, Ptex::DataType dt,
int nchannels, int alphachan, int nfaces,
Ptex::String& error, bool genmipmaps=true);
PTEXAPI
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);
PTEXAPI
static bool applyEdits(const char* path, Ptex::String& error);
virtual void release() = 0;
virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode) = 0;
virtual void setEdgeFilterMode(Ptex::EdgeFilterMode edgeFilterMode) = 0;
virtual void writeMeta(const char* key, const char* string) = 0;
virtual void writeMeta(const char* key, const int8_t* value, int count) = 0;
virtual void writeMeta(const char* key, const int16_t* value, int count) = 0;
virtual void writeMeta(const char* key, const int32_t* value, int count) = 0;
virtual void writeMeta(const char* key, const float* value, int count) = 0;
virtual void writeMeta(const char* key, const double* value, int count) = 0;
virtual void writeMeta(PtexMetaData* data) = 0;
virtual bool writeFace(int faceid, const Ptex::FaceInfo& info, const void* data, int stride=0) = 0;
virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo& info, const void* data) = 0;
virtual bool close(Ptex::String& error) = 0;
#if NEW_API
virtual bool writeFaceReduction(int faceid, const Ptex::Res& res, const void* data, int stride=0) = 0;
virtual bool writeConstantFaceReduction(int faceid, const Ptex::Res& res, const void* data) = 0;
#endif
};
class PtexFilter {
protected:
virtual ~PtexFilter() {}
public:
enum FilterType {
f_point,
f_bilinear,
f_box,
f_gaussian,
f_bicubic,
f_bspline,
f_catmullrom,
f_mitchell
};
struct Options {
int __structSize;
FilterType filter;
bool lerp;
float sharpness;
bool noedgeblend;
Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0, bool noedgeblend_=0) :
__structSize(sizeof(Options)),
filter(filter_), lerp(lerp_), sharpness(sharpness_), noedgeblend(noedgeblend_) {}
};
/* Construct a filter for the given texture.
*/
PTEXAPI static PtexFilter* getFilter(PtexTexture* tx, const Options& opts);
virtual void release() = 0;
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;
};
template <class T> class PtexPtr {
T* _ptr;
public:
PtexPtr(T* ptr=0) : _ptr(ptr) {}
~PtexPtr() { if (_ptr) _ptr->release(); }
operator T* () const { return _ptr; }
T* operator-> () const { return _ptr; }
T* get() const { return _ptr; }
void swap(PtexPtr& p)
{
T* tmp = p._ptr;
p._ptr = _ptr;
_ptr = tmp;
}
void reset(T* ptr=0) {
if (_ptr) _ptr->release();
_ptr = ptr;
}
private:
PtexPtr(const PtexPtr& p);
void operator= (PtexPtr& p);
};
#ifndef DOXYGEN
namespace PtexUtils {}
PTEX_NAMESPACE_END
using Ptex::PtexMetaData;
using Ptex::PtexFaceData;
using Ptex::PtexTexture;
using Ptex::PtexInputHandler;
using Ptex::PtexErrorHandler;
using Ptex::PtexCache;
using Ptex::PtexWriter;
using Ptex::PtexFilter;
using Ptex::PtexPtr;
namespace PtexUtils = Ptex::PtexUtils;
#endif
#endif
PtexExports.h
Definitions related to exported Ptex API symbol visibility.
PTEXAPI
#define PTEXAPI
Definition PtexExports.h:60
PtexInt.h
Portable fixed-width integer types.
operator<<
std::ostream & operator<<(std::ostream &stream, const String &str)
Definition PtexUtils.cpp:692
PtexVersion.h
PTEX_NAMESPACE_END
#define PTEX_NAMESPACE_END
Definition PtexVersion.h:62
PtexCache
File-handle and memory cache for reading ptex files.
Definition Ptexture.h:684
PtexCache::getStats
virtual void getStats(Stats &stats)=0
Get stats.
PtexCache::release
virtual void release()=0
Release PtexCache. Cache will be immediately destroyed and all resources will be released.
PtexCache::get
virtual PtexTexture * get(const char *path, Ptex::String &error)=0
Access a texture.
PtexCache::purge
virtual void purge(PtexTexture *texture)=0
Remove a texture file from the cache.
PtexCache::create
static PtexCache * create(int maxFiles, size_t maxMem, bool premultiply=false, PtexInputHandler *inputHandler=0, PtexErrorHandler *errorHandler=0)
Create a cache with the specified limits.
Definition PtexCache.cpp:177
PtexCache::setSearchPath
virtual void setSearchPath(const char *path)=0
Set a search path for finding textures.
PtexCache::~PtexCache
virtual ~PtexCache()
Destructor not for public use. Use release() instead.
Definition Ptexture.h:687
PtexCache::getSearchPath
virtual const char * getSearchPath()=0
Query the search path.
PtexCache::purgeAll
virtual void purgeAll()=0
Remove all texture files from the cache.
PtexCache::purge
virtual void purge(const char *path)=0
Remove a texture file from the cache by pathname.
PtexErrorHandler
Custom handler interface redirecting Ptex error messages.
Definition Ptexture.h:658
PtexErrorHandler::reportError
virtual void reportError(const char *error)=0
PtexErrorHandler::~PtexErrorHandler
virtual ~PtexErrorHandler()
Definition Ptexture.h:660
PtexFaceData
Per-face texture data accessor.
Definition Ptexture.h:406
PtexFaceData::getTile
virtual PtexFaceData * getTile(int tile)=0
Access a tile from the data block.
PtexFaceData::isTiled
virtual bool isTiled()=0
True if this data block is tiled.
PtexFaceData::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexFaceData::getPixel
virtual void getPixel(int u, int v, void *result)=0
Read a single texel from the data block.
PtexFaceData::tileRes
virtual Ptex::Res tileRes()=0
Resolution of each tile in this data block.
PtexFaceData::isConstant
virtual bool isConstant()=0
True if this data block is constant.
PtexFaceData::~PtexFaceData
virtual ~PtexFaceData()
Destructor not for public use. Use release() instead.
Definition Ptexture.h:409
PtexFaceData::getData
virtual void * getData()=0
Access the data from this data block.
PtexFaceData::res
virtual Ptex::Res res()=0
Resolution of the texture held by this data block.
PtexFilter
Interface for filtered sampling of ptex data files.
Definition Ptexture.h:937
PtexFilter::getFilter
static PtexFilter * getFilter(PtexTexture *tx, const Options &opts)
Definition PtexFilters.cpp:419
PtexFilter::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexFilter::~PtexFilter
virtual ~PtexFilter()
Destructor not for public use. Use release() instead.
Definition Ptexture.h:940
PtexFilter::eval
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.
PtexFilter::FilterType
FilterType
Filter types.
Definition Ptexture.h:944
PtexFilter::f_bicubic
@ f_bicubic
General bi-cubic filter (uses sharpness option)
Definition Ptexture.h:949
PtexFilter::f_bspline
@ f_bspline
BSpline (equivalent to bi-cubic w/ sharpness=0)
Definition Ptexture.h:950
PtexFilter::f_bilinear
@ f_bilinear
Bi-linear interpolation.
Definition Ptexture.h:946
PtexFilter::f_catmullrom
@ f_catmullrom
Catmull-Rom (equivalent to bi-cubic w/ sharpness=1)
Definition Ptexture.h:951
PtexFilter::f_mitchell
@ f_mitchell
Mitchell (equivalent to bi-cubic w/ sharpness=2/3)
Definition Ptexture.h:952
PtexFilter::f_box
@ f_box
Box filter.
Definition Ptexture.h:947
PtexFilter::f_gaussian
@ f_gaussian
Gaussian filter.
Definition Ptexture.h:948
PtexFilter::f_point
@ f_point
Point-sampled (no filtering)
Definition Ptexture.h:945
PtexInputHandler
Custom handler interface for intercepting and redirecting Ptex input stream calls.
Definition Ptexture.h:619
PtexInputHandler::seek
virtual void seek(Handle handle, int64_t pos)=0
Seek to an absolute byte position in the input stream.
PtexInputHandler::~PtexInputHandler
virtual ~PtexInputHandler()
Definition Ptexture.h:621
PtexInputHandler::read
virtual size_t read(void *buffer, size_t size, Handle handle)=0
Read a number of bytes from the file.
PtexInputHandler::lastError
virtual const char * lastError()=0
Return the last error message encountered.
PtexInputHandler::open
virtual Handle open(const char *path)=0
Open a file in read mode.
PtexInputHandler::Handle
void * Handle
Definition Ptexture.h:624
PtexInputHandler::close
virtual bool close(Handle handle)=0
Close a file.
PtexMetaData
Meta data accessor.
Definition Ptexture.h:328
PtexMetaData::getValue
virtual void getValue(int index, const int8_t *&value, int &count)=0
Query the value of a given meta data entry by index.
PtexMetaData::getValue
virtual void getValue(int index, const int32_t *&value, int &count)=0
Query the value of a given meta data entry by index.
PtexMetaData::getValue
virtual void getValue(const char *key, const double *&value, int &count)=0
Query the value of a given meta data entry.
PtexMetaData::numKeys
virtual int numKeys()=0
Query number of meta data entries stored in file.
PtexMetaData::~PtexMetaData
virtual ~PtexMetaData()
Destructor not for public use. Use release() instead.
Definition Ptexture.h:331
PtexMetaData::getValue
virtual void getValue(const char *key, const int8_t *&value, int &count)=0
Query the value of a given meta data entry.
PtexMetaData::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexMetaData::getValue
virtual void getValue(int index, const double *&value, int &count)=0
Query the value of a given meta data entry by index.
PtexMetaData::getValue
virtual void getValue(const char *key, const int32_t *&value, int &count)=0
Query the value of a given meta data entry.
PtexMetaData::findKey
virtual bool findKey(const char *key, int &index, Ptex::MetaDataType &type)=0
Query the index and type of a meta data entry by name.
PtexMetaData::getValue
virtual void getValue(int index, const int16_t *&value, int &count)=0
Query the value of a given meta data entry by index.
PtexMetaData::getValue
virtual void getValue(const char *key, const float *&value, int &count)=0
Query the value of a given meta data entry.
PtexMetaData::getValue
virtual void getValue(int index, const float *&value, int &count)=0
Query the value of a given meta data entry by index.
PtexMetaData::getValue
virtual void getValue(const char *key, const char *&value)=0
Query the value of a given meta data entry.
PtexMetaData::getValue
virtual void getValue(int index, const char *&value)=0
Query the value of a given meta data entry by index.
PtexMetaData::getKey
virtual void getKey(int index, const char *&key, Ptex::MetaDataType &type)=0
Query the name and type of a meta data entry.
PtexMetaData::getValue
virtual void getValue(const char *key, const int16_t *&value, int &count)=0
Query the value of a given meta data entry.
PtexPtr
Smart-pointer for acquiring and releasing API objects.
Definition Ptexture.h:1032
PtexPtr::PtexPtr
PtexPtr(const PtexPtr &p)
Copying prohibited.
PtexPtr::PtexPtr
PtexPtr(T *ptr=0)
Constructor.
Definition Ptexture.h:1036
PtexPtr::reset
void reset(T *ptr=0)
Deallocate object pointed to, and optionally set to new value.
Definition Ptexture.h:1059
PtexPtr::get
T * get() const
Get pointer value.
Definition Ptexture.h:1048
PtexPtr::operator=
void operator=(PtexPtr &p)
Assignment prohibited.
PtexPtr::~PtexPtr
~PtexPtr()
Destructor, calls ptr->release().
Definition Ptexture.h:1039
PtexPtr::operator->
T * operator->() const
Access members of pointer.
Definition Ptexture.h:1045
PtexPtr::swap
void swap(PtexPtr &p)
Swap pointer values.
Definition Ptexture.h:1051
PtexPtr::_ptr
T * _ptr
Definition Ptexture.h:1033
PtexTexture
Interface for reading data from a ptex file.
Definition Ptexture.h:457
PtexTexture::getData
virtual void getData(int faceid, void *buffer, int stride)=0
Access texture data for a face at highest-resolution.
PtexTexture::meshType
virtual Ptex::MeshType meshType()=0
Type of mesh for which texture data is defined.
PtexTexture::uBorderMode
virtual Ptex::BorderMode uBorderMode()=0
Mode for filtering texture access beyond mesh border.
PtexTexture::~PtexTexture
virtual ~PtexTexture()
Destructor not for public use. Use release() instead.
Definition Ptexture.h:460
PtexTexture::getMetaData
virtual PtexMetaData * getMetaData()=0
Access meta data.
PtexTexture::hasMipMaps
virtual bool hasMipMaps()=0
True if the file has mipmaps.
PtexTexture::getInfo
virtual Info getInfo()=0
PtexTexture::numFaces
virtual int numFaces()=0
Number of faces stored in file.
PtexTexture::dataType
virtual Ptex::DataType dataType()=0
Type of data stored in file.
PtexTexture::getData
virtual void getData(int faceid, void *buffer, int stride, Ptex::Res res)=0
Access texture data for a face at a specific resolution.
PtexTexture::getData
virtual PtexFaceData * getData(int faceid, Ptex::Res res)=0
Access texture data for a face at a specific resolution as stored on disk.
PtexTexture::path
virtual const char * path()=0
Path that file was opened with.
PtexTexture::alphaChannel
virtual int alphaChannel()=0
Index of alpha channel (if any).
PtexTexture::edgeFilterMode
virtual Ptex::EdgeFilterMode edgeFilterMode()=0
Mode for filtering textures across edges.
PtexTexture::open
static PtexTexture * open(const char *path, Ptex::String &error, bool premultiply=0)
Open a ptex file for reading.
Definition PtexReader.cpp:59
PtexTexture::getPixel
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 .
PtexTexture::getData
virtual PtexFaceData * getData(int faceid)=0
Access texture data for a face at highest-resolution as stored on disk.
PtexTexture::hasEdits
virtual bool hasEdits()=0
True if the file has edit blocks.
PtexTexture::vBorderMode
virtual Ptex::BorderMode vBorderMode()=0
Mode for filtering texture access beyond mesh border.
PtexTexture::numChannels
virtual int numChannels()=0
Number of channels stored in file.
PtexTexture::getFaceInfo
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)=0
Access resolution and adjacency information about a face.
PtexTexture::getPixel
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.
PtexTexture::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexWriter
Interface for writing data to a ptex file.
Definition Ptexture.h:810
PtexWriter::setBorderModes
virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode)=0
Set border modes.
PtexWriter::writeMeta
virtual void writeMeta(const char *key, const float *value, int count)=0
Write an array of signed 32-bit floats as meta data.
PtexWriter::setEdgeFilterMode
virtual void setEdgeFilterMode(Ptex::EdgeFilterMode edgeFilterMode)=0
Set edge filter mode.
PtexWriter::edit
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.
Definition PtexWriter.cpp:186
PtexWriter::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexWriter::writeMeta
virtual void writeMeta(const char *key, const int8_t *value, int count)=0
Write an array of signed 8-bit integers as meta data.
PtexWriter::applyEdits
static bool applyEdits(const char *path, Ptex::String &error)
Apply edits to a file.
Definition PtexWriter.cpp:242
PtexWriter::writeMeta
virtual void writeMeta(const char *key, const int32_t *value, int count)=0
Write an array of signed 32-bit integers as meta data.
PtexWriter::writeMeta
virtual void writeMeta(const char *key, const int16_t *value, int count)=0
Write an array of signed 16-bit integers as meta data.
PtexWriter::writeMeta
virtual void writeMeta(const char *key, const char *string)=0
Write a string as meta data.
PtexWriter::close
virtual bool close(Ptex::String &error)=0
Close the file.
PtexWriter::writeMeta
virtual void writeMeta(const char *key, const double *value, int count)=0
Write an array of signed 32-bit doubles as meta data.
PtexWriter::writeMeta
virtual void writeMeta(PtexMetaData *data)=0
Copy meta data from an existing meta data block.
PtexWriter::open
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.
Definition PtexWriter.cpp:167
PtexWriter::writeConstantFace
virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo &info, const void *data)=0
Write constant texture data for a face.
PtexWriter::~PtexWriter
virtual ~PtexWriter()
Destructor not for public use. Use release() instead.
Definition Ptexture.h:813
PtexWriter::writeFace
virtual bool writeFace(int faceid, const Ptex::FaceInfo &info, const void *data, int stride=0)=0
Write texture data for a face.
Ptex::String
Memory-managed string.
Definition Ptexture.h:296
Ptex::String::c_str
const char * c_str() const
Definition Ptexture.h:304
Ptex::String::operator=
String & operator=(const std::string &str)
Definition Ptexture.h:303
Ptex::String::empty
bool empty() const
Definition Ptexture.h:305
Ptex::String::String
String()
Definition Ptexture.h:298
Ptex::String::_str
char * _str
Definition Ptexture.h:308
Ptex::String::operator=
String & operator=(const String &str)
Definition Ptexture.h:302
Ptex::String::String
String(const String &str)
Definition Ptexture.h:299
Ptex::String::~String
~String()
Definition PtexUtils.cpp:679
Ptex::String::operator=
String & operator=(const char *str)
Definition PtexUtils.cpp:685
PTEX_NAMESPACE_BEGIN
Definition PtexSeparableKernel.cpp:42
PtexUtils
Definition PtexUtils.cpp:145
Ptex
Common data structures and enums used throughout the API.
Definition Ptexture.h:58
Ptex::DataTypeName
const char * DataTypeName(DataType dt)
Look up name of given data type.
Ptex::DataSize
int DataSize(DataType dt)
Look up size of given data type (in bytes).
Definition Ptexture.h:130
Ptex::MeshTypeName
const char * MeshTypeName(MeshType mt)
Look up name of given mesh type.
Ptex::ConvertFromFloat
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.
Ptex::EdgeId
EdgeId
Edge IDs used in adjacency data in the Ptex::FaceInfo struct.
Definition Ptexture.h:94
Ptex::e_right
@ e_right
Right edge, from UV (1,0) to (1,1)
Definition Ptexture.h:96
Ptex::e_top
@ e_top
Top edge, from UV (1,1) to (0,1)
Definition Ptexture.h:97
Ptex::e_left
@ e_left
Left edge, from UV (0,1) to (0,0)
Definition Ptexture.h:98
Ptex::e_bottom
@ e_bottom
Bottom edge, from UV (0,0) to (1,0)
Definition Ptexture.h:95
Ptex::EdgeFilterModeName
const char * EdgeFilterModeName(EdgeFilterMode m)
Look up name of given edge filter mode.
Ptex::DataType
DataType
Type of data stored in texture file.
Definition Ptexture.h:72
Ptex::dt_half
@ dt_half
Half-precision (16-bit) floating point.
Definition Ptexture.h:75
Ptex::dt_float
@ dt_float
Single-precision (32-bit) floating point.
Definition Ptexture.h:76
Ptex::dt_uint16
@ dt_uint16
Unsigned, 16-bit integer.
Definition Ptexture.h:74
Ptex::dt_uint8
@ dt_uint8
Unsigned, 8-bit integer.
Definition Ptexture.h:73
Ptex::OneValue
float OneValue(DataType dt)
Look up value of given data type that corresponds to the normalized value of 1.0.
Definition Ptexture.h:136
Ptex::MetaDataTypeName
const char * MetaDataTypeName(MetaDataType mdt)
Look up name of given meta data type.
Ptex::EdgeIdName
const char * EdgeIdName(EdgeId eid)
Look up name of given edge ID.
Ptex::MeshType
MeshType
Type of base mesh for which the textures are defined.
Definition Ptexture.h:66
Ptex::mt_triangle
@ mt_triangle
Mesh is triangle-based.
Definition Ptexture.h:67
Ptex::mt_quad
@ mt_quad
Mesh is quad-based.
Definition Ptexture.h:68
Ptex::BorderMode
BorderMode
How to handle mesh border when filtering.
Definition Ptexture.h:86
Ptex::m_black
@ m_black
texel beyond border are assumed to be black
Definition Ptexture.h:88
Ptex::m_clamp
@ m_clamp
texel access is clamped to border
Definition Ptexture.h:87
Ptex::m_periodic
@ m_periodic
texel access wraps to other side of face
Definition Ptexture.h:89
Ptex::ConvertToFloat
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.
Ptex::MetaDataType
MetaDataType
Type of meta data entry.
Definition Ptexture.h:102
Ptex::mdt_string
@ mdt_string
Null-terminated string.
Definition Ptexture.h:103
Ptex::mdt_float
@ mdt_float
Single-precision (32-bit) floating point.
Definition Ptexture.h:107
Ptex::mdt_int32
@ mdt_int32
Signed 32-bit integer.
Definition Ptexture.h:106
Ptex::mdt_int8
@ mdt_int8
Signed 8-bit integer.
Definition Ptexture.h:104
Ptex::mdt_double
@ mdt_double
Double-precision (32-bit) floating point.
Definition Ptexture.h:108
Ptex::mdt_int16
@ mdt_int16
Signed 16-bit integer.
Definition Ptexture.h:105
Ptex::EdgeFilterMode
EdgeFilterMode
How to handle transformation across edges when filtering.
Definition Ptexture.h:80
Ptex::efm_none
@ efm_none
Don't do anything with the values.
Definition Ptexture.h:81
Ptex::efm_tanvec
@ efm_tanvec
Values are vectors in tangent space; rotate values.
Definition Ptexture.h:82
Ptex::BorderModeName
const char * BorderModeName(BorderMode m)
Look up name of given border mode.
Ptex::OneValueInv
float OneValueInv(DataType dt)
Lookup up inverse value of given data type that corresponds to the normalized value of 1....
Definition Ptexture.h:142
PtexCache::Stats
Definition Ptexture.h:779
PtexCache::Stats::filesAccessed
uint64_t filesAccessed
Definition Ptexture.h:784
PtexCache::Stats::filesOpen
uint64_t filesOpen
Definition Ptexture.h:782
PtexCache::Stats::peakFilesOpen
uint64_t peakFilesOpen
Definition Ptexture.h:783
PtexCache::Stats::fileReopens
uint64_t fileReopens
Definition Ptexture.h:785
PtexCache::Stats::memUsed
uint64_t memUsed
Definition Ptexture.h:780
PtexCache::Stats::blockReads
uint64_t blockReads
Definition Ptexture.h:786
PtexCache::Stats::peakMemUsed
uint64_t peakMemUsed
Definition Ptexture.h:781
PtexFilter::Options
Choose filter options.
Definition Ptexture.h:956
PtexFilter::Options::filter
FilterType filter
Filter type.
Definition Ptexture.h:958
PtexFilter::Options::__structSize
int __structSize
(for internal use only)
Definition Ptexture.h:957
PtexFilter::Options::sharpness
float sharpness
Filter sharpness, 0..1 (for general bi-cubic filter only).
Definition Ptexture.h:960
PtexFilter::Options::lerp
bool lerp
Interpolate between mipmap levels.
Definition Ptexture.h:959
PtexFilter::Options::noedgeblend
bool noedgeblend
Disable cross-face filtering. Useful for debugging or rendering on polys.
Definition Ptexture.h:961
PtexFilter::Options::Options
Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0, bool noedgeblend_=0)
Constructor - sets defaults.
Definition Ptexture.h:964
PtexTexture::Info
Get most commonly used info in a single call for convenience / efficiency.
Definition Ptexture.h:486
PtexTexture::Info::numChannels
int numChannels
Definition Ptexture.h:493
PtexTexture::Info::uBorderMode
BorderMode uBorderMode
Definition Ptexture.h:489
PtexTexture::Info::vBorderMode
BorderMode vBorderMode
Definition Ptexture.h:490
PtexTexture::Info::edgeFilterMode
EdgeFilterMode edgeFilterMode
Definition Ptexture.h:491
PtexTexture::Info::alphaChannel
int alphaChannel
Definition Ptexture.h:492
PtexTexture::Info::dataType
DataType dataType
Definition Ptexture.h:488
PtexTexture::Info::numFaces
int numFaces
Definition Ptexture.h:494
PtexTexture::Info::meshType
MeshType meshType
Definition Ptexture.h:487
Ptex::FaceInfo
Information about a face, as stored in the Ptex file header.
Definition Ptexture.h:229
Ptex::FaceInfo::setadjedges
void setadjedges(int e0, int e1, int e2, int e3)
Set the adjedges data.
Definition Ptexture.h:278
Ptex::FaceInfo::hasEdits
bool hasEdits() const
Determine if face has edits in the file (by checking a flag).
Definition Ptexture.h:268
Ptex::FaceInfo::isNeighborhoodConstant
bool isNeighborhoodConstant() const
Determine if neighborhood of face is constant (by checking a flag).
Definition Ptexture.h:265
Ptex::FaceInfo::FaceInfo
FaceInfo(Res res_)
Constructor.
Definition Ptexture.h:242
Ptex::FaceInfo::isSubface
bool isSubface() const
Determine if face is a subface (by checking a flag).
Definition Ptexture.h:271
Ptex::FaceInfo::res
Res res
Resolution of face.
Definition Ptexture.h:230
Ptex::FaceInfo::adjedge
EdgeId adjedge(int eid) const
Access an adjacent edge id. The eid value must be 0..3.
Definition Ptexture.h:256
Ptex::FaceInfo::isConstant
bool isConstant() const
Determine if face is constant (by checking a flag).
Definition Ptexture.h:262
Ptex::FaceInfo::flag_hasedits
@ flag_hasedits
Definition Ptexture.h:282
Ptex::FaceInfo::flag_constant
@ flag_constant
Definition Ptexture.h:282
Ptex::FaceInfo::flag_nbconstant
@ flag_nbconstant
Definition Ptexture.h:282
Ptex::FaceInfo::flag_subface
@ flag_subface
Definition Ptexture.h:282
Ptex::FaceInfo::adjedges
uint8_t adjedges
Adjacent edges, 2 bits per edge.
Definition Ptexture.h:231
Ptex::FaceInfo::adjfaces
int32_t adjfaces[4]
Adjacent faces (-1 == no adjacent face).
Definition Ptexture.h:233
Ptex::FaceInfo::flags
uint8_t flags
Flags.
Definition Ptexture.h:232
Ptex::FaceInfo::FaceInfo
FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
Constructor.
Definition Ptexture.h:248
Ptex::FaceInfo::FaceInfo
FaceInfo()
Default constructor.
Definition Ptexture.h:236
Ptex::FaceInfo::setadjfaces
void setadjfaces(int f0, int f1, int f2, int f3)
Set the adjfaces data.
Definition Ptexture.h:274
Ptex::FaceInfo::adjface
int adjface(int eid) const
Access an adjacent face id. The eid value must be 0..3.
Definition Ptexture.h:259
Ptex::Res
Pixel resolution of a given texture.
Definition Ptexture.h:159
Ptex::Res::operator>=
bool operator>=(const Res &r) const
True if res is >= given res in both u and v directions.
Definition Ptexture.h:191
Ptex::Res::ntilesu
int ntilesu(Res tileres) const
Determine the number of tiles in the u direction for the given tile res.
Definition Ptexture.h:206
Ptex::Res::operator!=
bool operator!=(const Res &r) const
Comparison operator.
Definition Ptexture.h:188
Ptex::Res::Res
Res(uint16_t value)
Constructor.
Definition Ptexture.h:170
Ptex::Res::ulog2
int8_t ulog2
log base 2 of u resolution, in texels
Definition Ptexture.h:160
Ptex::Res::ntilesv
int ntilesv(Res tileres) const
Determine the number of tiles in the v direction for the given tile res.
Definition Ptexture.h:209
Ptex::Res::Res
Res()
Default constructor, sets res to 0 (1x1 texel).
Definition Ptexture.h:164
Ptex::Res::val
uint16_t val() const
Resolution as a single 16-bit integer value.
Definition Ptexture.h:179
Ptex::Res::v
int v() const
V resolution in texels.
Definition Ptexture.h:176
Ptex::Res::swappeduv
Res swappeduv() const
Get value of resolution with u and v swapped.
Definition Ptexture.h:194
Ptex::Res::size
int size() const
Total size of specified texture in texels (u * v).
Definition Ptexture.h:182
Ptex::Res::Res
Res(int8_t ulog2_, int8_t vlog2_)
Constructor.
Definition Ptexture.h:167
Ptex::Res::swapuv
void swapuv()
Swap the u and v resolution values in place.
Definition Ptexture.h:197
Ptex::Res::clamp
void clamp(const Res &r)
Clamp the resolution value against the given value.
Definition Ptexture.h:200
Ptex::Res::ntiles
int ntiles(Res tileres) const
Determine the total number of tiles for the given tile res.
Definition Ptexture.h:212
Ptex::Res::u
int u() const
U resolution in texels.
Definition Ptexture.h:173
Ptex::Res::vlog2
int8_t vlog2
log base 2 of v resolution, in texels
Definition Ptexture.h:161
Ptex::Res::operator==
bool operator==(const Res &r) const
Comparison operator.
Definition Ptexture.h:185