Ptex: PtexWriterBase Class Reference

Ptex

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
PtexWriterBase Class Referenceabstract

`#include <PtexWriter.h>`

Inheritance diagram for PtexWriterBase:

## Classes
struct | MetaEntry

## Public Member Functions
virtual void | setBorderModes (Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode)
| Set border modes. More...
virtual void | writeMeta (const char *key, const char *value)
| Write a string as meta data. More...
virtual void | writeMeta (const char *key, const int8_t *value, int count)
| Write an array of signed 8-bit integers as meta data. More...
virtual void | writeMeta (const char *key, const int16_t *value, int count)
| Write an array of signed 16-bit integers as meta data. More...
virtual void | writeMeta (const char *key, const int32_t *value, int count)
| Write an array of signed 32-bit integers as meta data. More...
virtual void | writeMeta (const char *key, const float *value, int count)
| Write an array of signed 32-bit floats as meta data. More...
virtual void | writeMeta (const char *key, const double *value, int count)
| Write an array of signed 32-bit doubles as meta data. More...
virtual void | writeMeta (PtexMetaData *data)
| Copy meta data from an existing meta data block. More...
virtual bool | close (Ptex::String &error)
| Close the file. More...
virtual void | release ()
| Release resources held by this pointer (pointer becomes invalid). More...
bool | ok (Ptex::String &error)
void | getError (Ptex::String &error)
Public Member Functions inherited from PtexWriter
virtual bool | writeFace (int faceid, const Ptex::FaceInfo &info, const void *data, int stride=0)=0
| Write texture data for a face. More...
virtual bool | writeConstantFace (int faceid, const Ptex::FaceInfo &info, const void *data)=0
| Write constant texture data for a face. More...

## Protected Member Functions
virtual void | finish ()=0
| PtexWriterBase (const char *path, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, bool compress)
virtual | ~PtexWriterBase ()
int | writeBlank (FILE *fp, int size)
int | writeBlock (FILE *fp, const void *data, int size)
int | writeZipBlock (FILE *fp, const void *data, int size, bool finish=true)
int | readBlock (FILE *fp, void *data, int size)
int | copyBlock (FILE *dst, FILE *src, FilePos pos, int size)
Res | calcTileRes (Res faceres)
virtual void | addMetaData (const char *key, MetaDataType t, const void *value, int size)
void | writeConstFaceBlock (FILE *fp, const void *data, FaceDataHeader &fdh)
void | writeFaceBlock (FILE *fp, const void *data, int stride, Res res, FaceDataHeader &fdh)
void | writeFaceData (FILE *fp, const void *data, int stride, Res res, FaceDataHeader &fdh)
void | writeReduction (FILE *fp, const void *data, int stride, Res res)
int | writeMetaDataBlock (FILE *fp, MetaEntry &val)
void | setError (const std::string &error)
bool | storeFaceInfo (int faceid, FaceInfo &dest, const FaceInfo &src, int flags=0)
Protected Member Functions inherited from PtexWriter
virtual | ~PtexWriter ()
| Destructor not for public use. Use release() instead. More...

## Protected Attributes
bool | _ok
std::string | _error
std::string | _path
std::string | _tilepath
FILE * | _tilefp
Header | _header
ExtHeader | _extheader
int | _pixelSize
std::vector< MetaEntry > | _metadata
std::map< std::string, int > | _metamap
z_stream_s | _zstream
PtexUtils::ReduceFn * | _reduceFn

## Additional Inherited Members
Public Types inherited from PtexIO
enum | Encoding { enc_constant, enc_zipped, enc_diffzipped, enc_tiled }
enum | EditType { et_editfacedata, et_editmetadata }
Public Types inherited from Ptex
enum | MeshType { mt_triangle, mt_quad }
| Type of base mesh for which the textures are defined. More...
enum | DataType { dt_uint8, dt_uint16, dt_half, dt_float }
| Type of data stored in texture file. More...
enum | BorderMode { m_clamp, m_black, m_periodic }
| How to handle mesh border when filtering. More...
enum | EdgeId { e_bottom, e_right, e_top, e_left }
| Edge IDs used in adjacency data in the Ptex::FaceInfo struct. More...
enum | MetaDataType { mdt_string, mdt_int8, mdt_int16, mdt_int32, mdt_float, mdt_double }
| Type of meta data entry. More...
Static Public Member Functions inherited from PtexWriter
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. More...
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. More...
static bool | applyEdits (const char *path, Ptex::String &error)
| Apply edits to a file. More...
Static Public Member Functions inherited from PtexIO
static bool | LittleEndian ()
Static Public Member Functions inherited from Ptex
static const char * | MeshTypeName (MeshType mt)
| Look up name of given mesh type. More...
static const char * | DataTypeName (DataType dt)
| Look up name of given data type. More...
static const char * | BorderModeName (BorderMode m)
| Look up name of given border mode. More...
static const char * | EdgeIdName (EdgeId eid)
| Look up name of given edge ID. More...
static const char * | MetaDataTypeName (MetaDataType mdt)
| Look up name of given meta data type. More...
static int | DataSize (DataType dt)
| Look up size of given data type (in bytes). More...
static float | OneValue (DataType dt)
| Look up value of given data type that corresponds to the normalized value of 1.0. More...
static float | OneValueInv (DataType dt)
| Lookup up inverse value of given data type that corresponds to the normalized value of 1.0. More...
static 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. More...
static 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. More...
Static Public Attributes inherited from PtexIO
static const uint32_t | Magic = 'P' | ('t'<<8) | ('e'<<16) | ('x'<<24)
static const int | HeaderSize = sizeof(Header)
static const int | ExtHeaderSize = sizeof(ExtHeader)
static const int | LevelInfoSize = sizeof(LevelInfo)
static const int | FaceDataHeaderSize = sizeof(FaceDataHeader)
static const int | EditFaceDataHeaderSize = sizeof(EditFaceDataHeader)
static const int | EditMetaDataHeaderSize = sizeof(EditMetaDataHeader)
static const int | IBuffSize = 8192
static const int | BlockSize = 16384
static const int | TileSize = 65536
static const int | AllocaMax = 16384
static const int | MetaDataThreshold = 1024

## Detailed Description

Definition at line 49 of file PtexWriter.h.

## Constructor & Destructor Documentation

PtexWriterBase::PtexWriterBase | ( | const char * | path,
|  | Ptex::MeshType | mt,
|  | Ptex::DataType | dt,
|  | int | nchannels,
|  | int | alphachan,
|  | int | nfaces,
|  | bool | compress
| ) |  |
| protected

Definition at line 262 of file PtexWriter.cpp.

References _extheader, _header, _pixelSize, _reduceFn, _tilefp, _tilepath, _zstream, PtexIO::Header::alphachan, PtexIO::Header::datatype, PtexIO::Header::extheadersize, PtexIO::Header::magic, PtexIO::Magic, PtexIO::Header::meshtype, PtexIO::Header::minorversion, Ptex::mt_triangle, PtexIO::Header::nchannels, PtexIO::Header::nfaces, PtexIO::Header::nlevels, PtexIO::Header::pixelSize(), PtexFileMajorVersion, PtexFileMinorVersion, PtexUtils::reduce(), PtexUtils::reduceTri(), setError(), and PtexIO::Header::version.

PtexWriterBase::~PtexWriterBase | ( |  | ) |
| protectedvirtual

Definition at line 312 of file PtexWriter.cpp.

References _zstream.

## Member Function Documentation

void PtexWriterBase::addMetaData | ( | const char * | key,
|  | MetaDataType | t,
|  | const void * | value,
|  | int | size
| ) |  |
| protectedvirtual

Reimplemented in PtexMainWriter.

Definition at line 455 of file PtexWriter.cpp.

References _metadata, _metamap, PtexWriterBase::MetaEntry::data, PtexWriterBase::MetaEntry::datatype, PtexWriterBase::MetaEntry::key, and setError().

Referenced by PtexMainWriter::addMetaData(), and writeMeta().

Ptex::Res PtexWriterBase::calcTileRes | ( | Res | faceres | ) |
| protected

Definition at line 572 of file PtexWriter.cpp.

References _pixelSize, PtexUtils::floor_log2(), PtexUtils::min(), Ptex::Res::size(), PtexIO::TileSize, Ptex::Res::ulog2, and Ptex::Res::vlog2.

Referenced by writeFaceData().

bool PtexWriterBase::close | ( | Ptex::String & | error | ) |
| virtual

Close the file.

This operation can take some time if mipmaps are being generated or if there are many edit blocks. If an error occurs while writing, false is returned and an error string is written into the error parameter.

Implements PtexWriter.

Reimplemented in PtexIncrWriter, and PtexMainWriter.

Definition at line 318 of file PtexWriter.cpp.

References _ok, _tilefp, _tilepath, finish(), and getError().

Referenced by PtexMainWriter::close(), PtexIncrWriter::close(), and release().

int PtexWriterBase::copyBlock | ( | FILE * | dst,
|  | FILE * | src,
|  | FilePos | pos,
|  | int | size
| ) |  |
| protected

Definition at line 553 of file PtexWriter.cpp.

References PtexIO::BlockSize, setError(), and writeBlock().

Referenced by PtexMainWriter::finish(), writeFaceData(), and PtexMainWriter::writeMetaData().

virtual void PtexWriterBase::finish | ( |  | ) |
| protectedpure virtual

Implemented in PtexIncrWriter, and PtexMainWriter.

Referenced by close().

void PtexWriterBase::getError | ( | Ptex::String & | error | ) |
| inline

Definition at line 70 of file PtexWriter.h.

References _error, and _path.

Referenced by close(), and ok().

bool PtexWriterBase::ok | ( | Ptex::String & | error | ) |
| inline

Definition at line 66 of file PtexWriter.h.

References _ok, and getError().

Referenced by PtexWriter::edit(), and PtexWriter::open().

int PtexWriterBase::readBlock | ( | FILE * | fp,
|  | void * | data,
|  | int | size
| ) |  |
| protected

Definition at line 543 of file PtexWriter.cpp.

References setError().

Referenced by PtexMainWriter::generateReductions().

void PtexWriterBase::release | ( |  | ) |
| virtual

Release resources held by this pointer (pointer becomes invalid).

Implements PtexWriter.

Definition at line 303 of file PtexWriter.cpp.

References _tilefp, Ptex::String::c_str(), and close().

Referenced by PtexWriter::edit(), and PtexWriter::open().

virtual void PtexWriterBase::setBorderModes | ( | Ptex::BorderMode | uBorderMode,
|  | Ptex::BorderMode | vBorderMode
| ) |  |
| inlinevirtual

Set border modes.

Implements PtexWriter.

Definition at line 51 of file PtexWriter.h.

References _extheader, PtexIO::ExtHeader::ubordermode, and PtexIO::ExtHeader::vbordermode.

Referenced by PtexMainWriter::PtexMainWriter().

void PtexWriterBase::setError | ( | const std::string & | error | ) |
| inlineprotected

Definition at line 103 of file PtexWriter.h.

References _error, and _ok.

Referenced by addMetaData(), copyBlock(), PtexMainWriter::finish(), PtexIncrWriter::PtexIncrWriter(), PtexMainWriter::PtexMainWriter(), PtexWriterBase(), readBlock(), storeFaceInfo(), writeBlock(), and writeZipBlock().

bool PtexWriterBase::storeFaceInfo | ( | int | faceid,
|  | FaceInfo & | dest,
|  | const FaceInfo & | src,
|  | int | flags = `0`
| ) |  |
| protected

Definition at line 331 of file PtexWriter.cpp.

References _header, Ptex::FaceInfo::adjedges, Ptex::FaceInfo::adjfaces, Ptex::FaceInfo::flag_subface, Ptex::FaceInfo::flags, PtexIO::Header::meshtype, Ptex::mt_triangle, PtexIO::Header::nfaces, Ptex::FaceInfo::res, setError(), Ptex::Res::ulog2, and Ptex::Res::vlog2.

Referenced by PtexMainWriter::writeConstantFace(), PtexIncrWriter::writeConstantFace(), PtexMainWriter::writeFace(), and PtexIncrWriter::writeFace().

int PtexWriterBase::writeBlank | ( | FILE * | fp,
|  | int | size
| ) |  |
| protected

Definition at line 489 of file PtexWriter.cpp.

References _ok, PtexIO::BlockSize, and writeBlock().

Referenced by PtexMainWriter::finish(), PtexIncrWriter::writeFace(), PtexMainWriter::writeMetaData(), and PtexIncrWriter::writeMetaDataEdit().

int PtexWriterBase::writeBlock | ( | FILE * | fp,
|  | const void * | data,
|  | int | size
| ) |  |
| protected

Definition at line 501 of file PtexWriter.cpp.

References _ok, and setError().

Referenced by copyBlock(), PtexMainWriter::finish(), writeBlank(), PtexIncrWriter::writeConstantFace(), writeConstFaceBlock(), PtexIncrWriter::writeFace(), writeFaceData(), PtexIncrWriter::writeMetaDataEdit(), writeReduction(), and writeZipBlock().

void PtexWriterBase::writeConstFaceBlock | ( | FILE * | fp,
|  | const void * | data,
|  | FaceDataHeader & | fdh
| ) |  |
| protected

Definition at line 594 of file PtexWriter.cpp.

References _pixelSize, PtexIO::enc_constant, PtexIO::FaceDataHeader::set(), and writeBlock().

Referenced by writeFaceData().

void PtexWriterBase::writeFaceBlock | ( | FILE * | fp,
|  | const void * | data,
|  | int | stride,
|  | Res | res,
|  | FaceDataHeader & | fdh
| ) |  |
| protected

Definition at line 604 of file PtexWriter.cpp.

References _header, _pixelSize, PtexIO::AllocaMax, Ptex::DataSize(), PtexIO::Header::datatype, PtexUtils::deinterleave(), Ptex::dt_uint16, Ptex::dt_uint8, PtexIO::enc_diffzipped, PtexIO::enc_zipped, PtexUtils::encodeDifference(), PtexIO::Header::nchannels, PtexIO::FaceDataHeader::set(), Ptex::Res::u(), Ptex::Res::v(), and writeZipBlock().

Referenced by writeFaceData().

void PtexWriterBase::writeFaceData | ( | FILE * | fp,
|  | const void * | data,
|  | int | stride,
|  | Res | res,
|  | FaceDataHeader & | fdh
| ) |  |
| protected

Definition at line 631 of file PtexWriter.cpp.

References _pixelSize, _tilefp, PtexIO::FaceDataHeader::blocksize(), calcTileRes(), copyBlock(), PtexIO::enc_tiled, PtexUtils::isConstant(), Ptex::Res::ntilesu(), Ptex::Res::ntilesv(), PtexIO::FaceDataHeader::set(), Ptex::Res::u(), Ptex::Res::v(), writeBlock(), writeConstFaceBlock(), writeFaceBlock(), and writeZipBlock().

Referenced by PtexMainWriter::generateReductions(), PtexMainWriter::writeFace(), and PtexIncrWriter::writeFace().

void PtexWriterBase::writeMeta | ( | const char * | key,
|  | const char * | string
| ) |  |
| virtual

Write a string as meta data.

Both the key and string params must be null-terminated strings.

Implements PtexWriter.

Definition at line 363 of file PtexWriter.cpp.

References addMetaData(), and Ptex::mdt_string.

Referenced by PtexMainWriter::PtexMainWriter(), and writeMeta().

void PtexWriterBase::writeMeta | ( | const char * | key,
|  | const int8_t * | value,
|  | int | count
| ) |  |
| virtual

Write an array of signed 8-bit integers as meta data.

The key must be a null-terminated string.

Implements PtexWriter.

Definition at line 369 of file PtexWriter.cpp.

References addMetaData(), and Ptex::mdt_int8.

void PtexWriterBase::writeMeta | ( | const char * | key,
|  | const int16_t * | value,
|  | int | count
| ) |  |
| virtual

Write an array of signed 16-bit integers as meta data.

The key must be a null-terminated string.

Implements PtexWriter.

Definition at line 375 of file PtexWriter.cpp.

References addMetaData(), and Ptex::mdt_int16.

void PtexWriterBase::writeMeta | ( | const char * | key,
|  | const int32_t * | value,
|  | int | count
| ) |  |
| virtual

Write an array of signed 32-bit integers as meta data.

The key must be a null-terminated string.

Implements PtexWriter.

Definition at line 381 of file PtexWriter.cpp.

References addMetaData(), and Ptex::mdt_int32.

void PtexWriterBase::writeMeta | ( | const char * | key,
|  | const float * | value,
|  | int | count
| ) |  |
| virtual

Write an array of signed 32-bit floats as meta data.

The key must be a null-terminated string.

Implements PtexWriter.

Definition at line 387 of file PtexWriter.cpp.

References addMetaData(), and Ptex::mdt_float.

void PtexWriterBase::writeMeta | ( | const char * | key,
|  | const double * | value,
|  | int | count
| ) |  |
| virtual

Write an array of signed 32-bit doubles as meta data.

The key must be a null-terminated string.

Implements PtexWriter.

Definition at line 393 of file PtexWriter.cpp.

References addMetaData(), and Ptex::mdt_double.

void PtexWriterBase::writeMeta | ( | PtexMetaData * | data | ) |
| virtual

Copy meta data from an existing meta data block.

Implements PtexWriter.

Definition at line 399 of file PtexWriter.cpp.

References PtexMetaData::getKey(), PtexMetaData::getValue(), Ptex::mdt_double, Ptex::mdt_float, Ptex::mdt_int16, Ptex::mdt_int32, Ptex::mdt_int8, Ptex::mdt_string, PtexMetaData::numKeys(), and writeMeta().

int PtexWriterBase::writeMetaDataBlock | ( | FILE * | fp,
|  | MetaEntry & | val
| ) |  |
| protected

Definition at line 709 of file PtexWriter.cpp.

References PtexWriterBase::MetaEntry::data, PtexWriterBase::MetaEntry::datatype, PtexWriterBase::MetaEntry::key, and writeZipBlock().

Referenced by PtexMainWriter::writeMetaData(), and PtexIncrWriter::writeMetaDataEdit().

void PtexWriterBase::writeReduction | ( | FILE * | fp,
|  | const void * | data,
|  | int | stride,
|  | Res | res
| ) |  |
| protected

Definition at line 692 of file PtexWriter.cpp.

References _header, _pixelSize, _reduceFn, PtexIO::AllocaMax, PtexIO::Header::datatype, PtexIO::Header::nchannels, Ptex::Res::size(), Ptex::Res::u(), Ptex::Res::ulog2, Ptex::Res::v(), Ptex::Res::vlog2, and writeBlock().

Referenced by PtexMainWriter::generateReductions(), and PtexMainWriter::writeFace().

int PtexWriterBase::writeZipBlock | ( | FILE * | fp,
|  | const void * | data,
|  | int | size,
|  | bool | finish = `true`
| ) |  |
| protected

Definition at line 512 of file PtexWriter.cpp.

References _ok, _zstream, PtexIO::BlockSize, setError(), and writeBlock().

Referenced by PtexMainWriter::finish(), writeFaceBlock(), writeFaceData(), PtexMainWriter::writeMetaData(), writeMetaDataBlock(), and PtexIncrWriter::writeMetaDataEdit().

## Member Data Documentation

std::string PtexWriterBase::_error
| protected

Definition at line 107 of file PtexWriter.h.

Referenced by getError(), and setError().

ExtHeader PtexWriterBase::_extheader
| protected

Definition at line 112 of file PtexWriter.h.

Referenced by PtexMainWriter::finish(), PtexIncrWriter::finish(), PtexIncrWriter::PtexIncrWriter(), PtexWriterBase(), setBorderModes(), and PtexMainWriter::writeMetaData().

Header PtexWriterBase::_header
| protected

Definition at line 111 of file PtexWriter.h.

Referenced by PtexMainWriter::finish(), PtexIncrWriter::finish(), PtexMainWriter::flagConstantNeighorhoods(), PtexMainWriter::generateReductions(), PtexIncrWriter::PtexIncrWriter(), PtexWriterBase(), PtexMainWriter::storeConstValue(), storeFaceInfo(), PtexMainWriter::writeFace(), PtexIncrWriter::writeFace(), writeFaceBlock(), PtexMainWriter::writeMetaData(), and writeReduction().

std::vector<MetaEntry> PtexWriterBase::_metadata
| protected

Definition at line 114 of file PtexWriter.h.

Referenced by addMetaData(), PtexMainWriter::finish(), PtexIncrWriter::finish(), PtexMainWriter::writeMetaData(), and PtexIncrWriter::writeMetaDataEdit().

std::map<std::string,int> PtexWriterBase::_metamap
| protected

Definition at line 115 of file PtexWriter.h.

Referenced by addMetaData().

bool PtexWriterBase::_ok
| protected

Definition at line 106 of file PtexWriter.h.

Referenced by close(), PtexMainWriter::generateReductions(), ok(), setError(), writeBlank(), writeBlock(), PtexMainWriter::writeConstantFace(), PtexMainWriter::writeFace(), and writeZipBlock().

std::string PtexWriterBase::_path
| protected

Definition at line 108 of file PtexWriter.h.

Referenced by PtexMainWriter::close(), and getError().

int PtexWriterBase::_pixelSize
| protected

Definition at line 113 of file PtexWriter.h.

Referenced by calcTileRes(), PtexMainWriter::finish(), PtexMainWriter::flagConstantNeighorhoods(), PtexMainWriter::generateReductions(), PtexMainWriter::PtexMainWriter(), PtexWriterBase(), PtexMainWriter::storeConstValue(), PtexMainWriter::writeConstantFace(), PtexIncrWriter::writeConstantFace(), writeConstFaceBlock(), PtexMainWriter::writeFace(), PtexIncrWriter::writeFace(), writeFaceBlock(), writeFaceData(), and writeReduction().

PtexUtils::ReduceFn* PtexWriterBase::_reduceFn
| protected

Definition at line 118 of file PtexWriter.h.

Referenced by PtexWriterBase(), and writeReduction().

FILE* PtexWriterBase::_tilefp
| protected

Definition at line 110 of file PtexWriter.h.

Referenced by close(), PtexWriterBase(), release(), and writeFaceData().

std::string PtexWriterBase::_tilepath
| protected

Definition at line 109 of file PtexWriter.h.

Referenced by close(), and PtexWriterBase().

z_stream_s PtexWriterBase::_zstream
| protected

Definition at line 116 of file PtexWriter.h.

Referenced by PtexWriterBase(), writeZipBlock(), and ~PtexWriterBase().

The documentation for this class was generated from the following files:

- PtexWriter.h
- PtexWriter.cpp