75 virtual const char*
path() {
return _path.c_str(); }
103 virtual void getData(
int faceid,
void* buffer,
int stride);
104 virtual void getData(
int faceid,
void* buffer,
int stride, Res res);
107 virtual void getPixel(
int faceid,
int u,
int v,
108 float* result,
int firstchan,
int nchannels);
109 virtual void getPixel(
int faceid,
int u,
int v,
110 float* result,
int firstchan,
int nchannels,
128 virtual void getKey(
int index,
const char*& key, MetaDataType& type)
130 if (index < 0 || index >=
int(
_entries.size())) {
138 virtual bool findKey(
const char* key,
int& index, MetaDataType& type)
140 MetaMap::iterator iter =
_map.find(key);
141 if (iter==
_map.end()) {
145 index = iter->second.index;
146 type = iter->second.type;
150 virtual void getValue(
const char* key,
const char*& value)
154 if (!
findKey(key, index, type)) {
159 if (e && e->
type == mdt_string) value = (
const char*) e->
data;
163 virtual void getValue(
int index,
const char*& value)
165 if (index < 0 || index >=
int(
_entries.size())) { value = 0;
return; }
167 if (e && e->
type == mdt_string) value = (
const char*) e->
data;
172 void getValue(
int index, MetaDataType requestedType,
const T*& value,
int& count)
174 if (index < 0 || index >=
int(
_entries.size())) {
180 if (e && e->
type == requestedType) {
181 value = (
const T*) e->
data;
184 else { value = 0; count = 0; }
188 void getValue(
const char* key, MetaDataType requestedType,
const T*& value,
int& count)
193 getValue<T>(index, requestedType, value, count);
196 virtual void getValue(
const char* key,
const int8_t*& value,
int& count)
198 getValue<int8_t>(key, mdt_int8, value, count);
201 virtual void getValue(
int index,
const int8_t*& value,
int& count)
203 getValue<int8_t>(index, mdt_int8, value, count);
206 virtual void getValue(
const char* key,
const int16_t*& value,
int& count)
208 getValue<int16_t>(key, mdt_int16, value, count);
211 virtual void getValue(
int index,
const int16_t*& value,
int& count)
213 getValue<int16_t>(index, mdt_int16, value, count);
216 virtual void getValue(
const char* key,
const int32_t*& value,
int& count)
218 getValue<int32_t>(key, mdt_int32, value, count);
221 virtual void getValue(
int index,
const int32_t*& value,
int& count)
223 getValue<int32_t>(index, mdt_int32, value, count);
226 virtual void getValue(
const char* key,
const float*& value,
int& count)
228 getValue<float>(key, mdt_float, value, count);
231 virtual void getValue(
int index,
const float*& value,
int& count)
233 getValue<float>(index, mdt_float, value, count);
236 virtual void getValue(
const char* key,
const double*& value,
int& count)
238 getValue<double>(key, mdt_double, value, count);
241 virtual void getValue(
int index,
const double*& value,
int& count)
243 getValue<double>(index, mdt_double, value, count);
247 uint32_t datasize,
const void* data,
size_t& metaDataMemUsed)
250 e->
data =
new char[datasize];
251 memcpy(e->
data, data, datasize);
252 metaDataMemUsed += datasize;
256 uint32_t datasize,
FilePos filepos, uint32_t zipsize,
257 size_t& metaDataMemUsed)
276 :
_data(new char [size]) {}
315 std::pair<MetaMap::iterator,bool> result =
316 _map.insert(std::make_pair(std::string(key, keysize),
Entry()));
317 Entry* e = &result.first->second;
318 bool newentry = result.second;
328 e->
key = result.first->first.c_str();
332 metaDataMemUsed +=
sizeof(std::string) + keysize + 1 +
sizeof(
Entry);
439 virtual void getPixel(
int u,
int v,
void* result);
453 for (std::vector<FaceData*>::iterator i =
_tiles.begin(); i !=
_tiles.end(); ++i) {
493 std::vector<FaceDataHeader>
_fdh;
522 std::vector<FaceDataHeader>
fdh;
532 for (std::vector<FaceData*>::iterator i =
faces.begin(); i !=
faces.end(); ++i) {
538 return sizeof(*this) +
fdh.size() * (
sizeof(
fdh[0]) +
548 std::string msg = error;
549 msg +=
" PtexFile: ";
553 else std::cerr << msg;
570 bool readBlock(
void* data,
int size,
bool reportError=
true);
571 bool readZipBlock(
void* data,
int zipsize,
int unzipsize);
583 if (!face)
readFace(levelid, level, faceid, res);
590 void readLevel(
int levelid, Level*& level);
591 void readFace(
int levelid, Level* level,
int faceid, Res res);
607 FilePos* end = offsets + noffsets;
608 while (offsets != end) { *offsets++ = pos; pos += fdh->
blocksize(); fdh++; }
617 FILE* fp = fopen(
path,
"rb");
625 virtual void seek(
Handle handle, int64_t pos) { fseeko((FILE*)handle, pos, SEEK_SET); }
626 virtual size_t read(
void* bufferArg,
size_t size,
Handle handle) {
627 return fread(bufferArg, size, 1, (FILE*)handle) == 1 ? size : 0;
630 bool ok = handle && (fclose((FILE*)handle) == 0);
634 virtual const char*
lastError() {
return strerror(errno); }
690 :
_val( int64_t(faceid)<<32 | uint32_t(16777619*((res.val()<<16) ^ faceid)) ) {}
709 return uint32_t(
_val);
Contains PtexHashMap, a lightweight multi-threaded hash table.
#define PTEX_NAMESPACE_END
Public API classes for reading, writing, caching, and filtering Ptex files.
Custom handler interface redirecting Ptex error messages.
virtual void reportError(const char *error)=0
Per-face texture data accessor.
virtual bool isConstant()
True if this data block is constant.
virtual Ptex::Res res()
Resolution of the texture held by this data block.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
virtual bool isTiled()
True if this data block is tiled.
virtual void * getData()
Access the data from this data block.
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
ConstDataPtr(void *data, int pixelsize)
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
ConstantFace(int pixelsize)
virtual bool isConstant()
True if this data block is constant.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
ErrorFace(void *errorPixel, int pixelsize, bool deleteOnRelease)
virtual Ptex::Res res()
Resolution of the texture held by this data block.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)=0
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
std::vector< FilePos > offsets
std::vector< FaceDataHeader > fdh
std::vector< FaceData * > faces
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
PackedFace(Res resArg, int pixelsize, int size)
virtual bool isTiled()
True if this data block is tiled.
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual bool isConstant()
True if this data block is constant.
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
virtual void * getData()
Access the data from this data block.
ReductionKey(uint32_t faceid, Res res)
void move(volatile ReductionKey &key) volatile
bool matches(const ReductionKey &key) volatile
void copy(volatile ReductionKey &key) volatile
TiledFaceBase(PtexReader *reader, Res resArg, Res tileresArg)
size_t baseExtraMemUsed()
std::vector< FaceData * > _tiles
virtual bool isTiled()
True if this data block is tiled.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual void * getData()
Access the data from this data block.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
virtual bool isConstant()
True if this data block is constant.
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
std::vector< FaceDataHeader > _fdh
TiledFace(PtexReader *reader, Res resArg, Res tileresArg, int levelid)
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
void readTile(int tile, FaceData *&data)
std::vector< FilePos > _offsets
TiledFaceBase * _parentface
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
PtexUtils::ReduceFn * _reducefn
TiledReducedFace(PtexReader *reader, Res resArg, Res tileresArg, TiledFaceBase *parentface, PtexUtils::ReduceFn reducefn)
DataType datatype() const
void readMetaDataBlock(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
const ExtHeader & extheader() const
virtual int numFaces()
Number of faces stored in file.
virtual Ptex::BorderMode vBorderMode()
Mode for filtering texture access beyond mesh border.
std::vector< FilePos > _levelpos
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels)
Access a single texel from the highest resolution texture .
std::vector< FaceEdit > _faceedits
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
void increaseMemUsed(size_t amount)
virtual const char * path()
Path that file was opened with.
FaceData * getFace(int levelid, Level *level, int faceid, Res res)
Level * getLevel(int levelid)
FaceData * errorData(bool deleteOnRelease=false)
virtual Ptex::BorderMode uBorderMode()
Mode for filtering texture access beyond mesh border.
void computeOffsets(FilePos pos, int noffsets, const FaceDataHeader *fdh, FilePos *offsets)
virtual PtexMetaData * getMetaData()
Access meta data.
virtual int alphaChannel()
Index of alpha channel (if any).
virtual void getData(int faceid, void *buffer, int stride)
Access texture data for a face at highest-resolution.
const Header & header() const
std::vector< LevelInfo > _levelinfo
PtexHashMap< ReductionKey, FaceData * > ReductionMap
virtual bool hasMipMaps()
True if the file has mipmaps.
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)
Access resolution and adjacency information about a face.
void readLargeMetaDataHeaders(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
bool pendingPurge() const
void readFace(int levelid, Level *level, int faceid, Res res)
virtual bool hasEdits()
True if the file has edit blocks.
std::vector< uint32_t > _rfaceids
std::vector< MetaEdit > _metaedits
DefaultInputHandler _defaultIo
volatile size_t _blockReads
void readFaceData(FilePos pos, FaceDataHeader fdh, Res res, int levelid, FaceData *&face)
bool readBlock(void *data, int size, bool reportError=true)
std::vector< Level * > _levels
std::vector< FaceInfo > _faceinfo
virtual Ptex::MeshType meshType()
Type of mesh for which texture data is defined.
virtual Ptex::EdgeFilterMode edgeFilterMode()
Mode for filtering textures across edges.
PtexInputHandler::Handle _fp
bool readZipBlock(void *data, int zipsize, int unzipsize)
void readLevel(int levelid, Level *&level)
virtual Ptex::DataType dataType()
Type of data stored in file.
std::vector< char > _errorPixel
virtual int numChannels()
Number of channels stored in file.
bool open(const char *path, Ptex::String &error)
const LevelInfo & levelinfo(int level) const
void setError(const char *error)
Interface for reading data from a ptex file.
void ReduceFn(const void *src, int sstride, int ures, int vres, void *dst, int dstride, DataType dt, int nchannels)
DataType
Type of data stored in texture file.
MeshType
Type of base mesh for which the textures are defined.
BorderMode
How to handle mesh border when filtering.
EdgeFilterMode
How to handle transformation across edges when filtering.
Get most commonly used info in a single call for convenience / efficiency.
EdgeFilterMode edgeFilterMode
Information about a face, as stored in the Ptex file header.
Pixel resolution of a given texture.