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