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,
130 if (index < 0 || index >=
int(
_entries.size())) {
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)) {
163 virtual void getValue(
int index,
const char*& value)
165 if (index < 0 || index >=
int(
_entries.size())) { value = 0;
return; }
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; }
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)
249 Entry* e =
newEntry(keysize, key, datatype, datasize, 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)
259 Entry* e =
newEntry(keysize, key, datatype, datasize, metaDataMemUsed);
276 :
_data(new char [size]) {}
297 isLmd(0), lmdData(0), lmdPos(0), lmdZipSize(0) {}
302 if (lmdData) {
delete lmdData; lmdData = 0; }
307 if (data) {
delete []
data; }
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);
414 :
ConstantFace(pixelsize), _deleteOnRelease(deleteOnRelease)
416 memcpy(
_data, errorPixel, pixelsize);
418 virtual void release() {
if (_deleteOnRelease)
delete this; }
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);
631 if (buffer) {
delete []
buffer; buffer = 0; }
634 virtual const char*
lastError() {
return strerror(errno); }
690 : _val( int64_t(faceid)<<32 | uint32_t(16777619*((res.val()<<16) ^ faceid)) ) {}
704 return _val == key.
_val;
709 return uint32_t(_val);
DefaultInputHandler _defaultIo
EdgeFilterMode edgeFilterMode
virtual int numFaces()
Number of faces stored in file.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
std::vector< char > _errorPixel
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
virtual bool hasMipMaps()
True if the file has mipmaps.
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
const ExtHeader & extheader() const
ConstantFace(int pixelsize)
virtual void * getData()
Access the data from this data block.
void ReduceFn(const void *src, int sstride, int ures, int vres, void *dst, int dstride, DataType dt, int nchannels)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
virtual bool hasEdits()
True if the file has edit blocks.
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)
Access resolution and adjacency information about a face.
virtual PtexFaceData * getTile(int)
Access a tile from the data block.
PackedFace(Res resArg, int pixelsize, int size)
virtual int alphaChannel()
Index of alpha channel (if any).
PtexReader(bool premultiply, PtexInputHandler *inputHandler, PtexErrorHandler *errorHandler)
virtual bool isConstant()
True if this data block is constant.
bool readBlock(void *data, int size, bool reportError=true)
std::vector< FilePos > offsets
virtual const char * path()
Path that file was opened with.
virtual int numChannels()
Number of channels stored in file.
void readLevel(int levelid, Level *&level)
std::vector< FilePos > _levelpos
virtual PtexMetaData * getMetaData()
Access meta data.
void readMetaDataBlock(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
EdgeFilterMode
How to handle transformation across edges when filtering.
Get most commonly used info in a single call for convenience / efficiency.
virtual Ptex::Res res()
Resolution of the texture held by this data block.
std::vector< uint32_t > _rfaceids
virtual Ptex::EdgeFilterMode edgeFilterMode()
Mode for filtering textures across edges.
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
Double-precision (32-bit) floating point.
virtual Ptex::DataType dataType()
Type of data stored in file.
virtual void reportError(const char *error)=0
FaceData * errorData(bool deleteOnRelease=false)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
void readFace(int levelid, Level *level, int faceid, Res res)
ErrorFace(void *errorPixel, int pixelsize, bool deleteOnRelease)
Per-face texture data accessor.
void increaseMemUsed(size_t amount)
Custom handler interface redirecting Ptex error messages.
TiledFace(PtexReader *reader, Res resArg, Res tileresArg, int levelid)
virtual Ptex::BorderMode vBorderMode()
Mode for filtering texture access beyond mesh border.
const LevelInfo & levelinfo(int level) const
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
std::vector< FaceData * > _tiles
virtual bool isTiled()
True if this data block is tiled.
virtual Ptex::BorderMode uBorderMode()
Mode for filtering texture access beyond mesh border.
virtual bool isConstant()
True if this data block is constant.
MeshType
Type of base mesh for which the textures are defined.
virtual void * getData()
Access the data from this data block.
virtual bool isConstant()
True if this data block is constant.
void readTile(int tile, FaceData *&data)
void readLargeMetaDataHeaders(MetaData *metadata, FilePos pos, int zipsize, int memsize, size_t &metaDataMemUsed)
std::vector< MetaEdit > _metaedits
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
BorderMode
How to handle mesh border when filtering.
void computeOffsets(FilePos pos, int noffsets, const FaceDataHeader *fdh, FilePos *offsets)
PtexHashMap< ReductionKey, FaceData * > ReductionMap
void setError(const char *error)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
TiledReducedFace(PtexReader *reader, Res resArg, Res tileresArg, TiledFaceBase *parentface, PtexUtils::ReduceFn reducefn)
virtual Ptex::Res res()
Resolution of the texture held by this data block.
bool readZipBlock(void *data, int zipsize, int unzipsize)
std::vector< FaceEdit > _faceedits
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
DataType datatype() const
virtual bool isConstant()
True if this data block is constant.
virtual void getData(int faceid, void *buffer, int stride)
Access texture data for a face at highest-resolution.
virtual void getPixel(int u, int v, void *result)
Read a single texel from the data block.
virtual bool isTiled()
True if this data block is tiled.
std::vector< Level * > _levels
std::vector< FaceDataHeader > fdh
Level * getLevel(int levelid)
virtual bool isTiled()
True if this data block is tiled.
PtexInputHandler::Handle _fp
std::vector< FaceInfo > _faceinfo
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< FaceDataHeader > _fdh
const Header & header() const
FaceData * getFace(int levelid, Level *level, int faceid, Res res)
virtual void getPixel(int, int, void *result)
Read a single texel from the data block.
PtexUtils::ReduceFn * _reducefn
void readFaceData(FilePos pos, FaceDataHeader fdh, Res res, int levelid, FaceData *&face)
ReductionKey(uint32_t faceid, Res res)
virtual void * getData()
Access the data from this data block.
bool matches(const ReductionKey &key) volatile
virtual PtexFaceData * getTile(int tile)
Access a tile from the data block.
TiledFaceBase(PtexReader *reader, Res resArg, Res tileresArg)
Interface for reading data from a ptex file.
std::vector< FilePos > _offsets
Pixel resolution of a given texture.
virtual Ptex::MeshType meshType()
Type of mesh for which texture data is defined.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)
bool pendingPurge() const
Contains PtexHashMap, a lightweight multi-threaded hash table.
ConstDataPtr(void *data, int pixelsize)
void copy(volatile ReductionKey &key) volatile
bool open(const char *path, Ptex::String &error)
Single-precision (32-bit) floating point.
int DataSize(DataType dt)
Look up size of given data type (in bytes).
virtual Ptex::Res tileRes()
Resolution of each tile in this data block.
MetaDataType
Type of meta data entry.
std::vector< LevelInfo > _levelinfo
std::vector< FaceData * > faces
void move(volatile ReductionKey &key) volatile
Information about a face, as stored in the Ptex file header.
size_t baseExtraMemUsed()
DataType
Type of data stored in texture file.
virtual FaceData * reduce(PtexReader *, Res newres, PtexUtils::ReduceFn, size_t &newMemUsed)=0
#define PTEX_NAMESPACE_END
volatile size_t _blockReads
Public API classes for reading, writing, caching, and filtering Ptex files.
TiledFaceBase * _parentface