PtexMainWriter Class Reference

`#include <PtexWriter.h>`

Inheritance diagram for PtexMainWriter:

## Classes

struct | LevelRec

## Public Member Functions

| PtexMainWriter (const char *path, PtexTexture *tex, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, bool genmipmaps)
virtual bool | close (Ptex::String &error)
| Close the file.
virtual bool | writeFace (int faceid, const FaceInfo &f, const void *data, int stride)
virtual bool | writeConstantFace (int faceid, const FaceInfo &f, const void *data)
Public Member Functions inherited from PtexWriterBase
virtual void | setBorderModes (Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode)
| Set border modes.
virtual void | setEdgeFilterMode (Ptex::EdgeFilterMode edgeFilterMode)
| Set edge filter mode.
virtual void | writeMeta (const char *key, const char *value)
| Write a string as meta data.
virtual void | writeMeta (const char *key, const int8_t *value, int count)
| Write an array of signed 8-bit integers as meta data.
virtual void | writeMeta (const char *key, const int16_t *value, int count)
| Write an array of signed 16-bit integers as meta data.
virtual void | writeMeta (const char *key, const int32_t *value, int count)
| Write an array of signed 32-bit integers as meta data.
virtual void | writeMeta (const char *key, const float *value, int count)
| Write an array of signed 32-bit floats as meta data.
virtual void | writeMeta (const char *key, const double *value, int count)
| Write an array of signed 32-bit doubles as meta data.
virtual void | writeMeta (PtexMetaData *data)
| Copy meta data from an existing meta data block.
virtual void | release ()
| Release resources held by this pointer (pointer becomes invalid).
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.
virtual bool | writeConstantFace (int faceid, const Ptex::FaceInfo &info, const void *data)=0
| Write constant texture data for a face.

## Protected Member Functions

virtual | ~PtexMainWriter ()
virtual void | addMetaData (const char *key, MetaDataType t, const void *value, int size)
Protected Member Functions inherited from PtexWriterBase
DataType | datatype () const
| 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)
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.

## Private Member Functions

virtual void | finish ()
void | generateReductions ()
void | flagConstantNeighorhoods ()
void | storeConstValue (int faceid, const void *data, int stride, Res res)
void | writeMetaData (FILE *fp)

## Private Attributes

std::string | _newpath
std::string | _tmppath
FILE * | _tmpfp
bool | _hasNewData
bool | _genmipmaps
std::vector< FaceInfo > | _faceinfo
std::vector< uint8_t > | _constdata
std::vector< uint32_t > | _rfaceids
std::vector< uint32_t > | _faceids_r
std::vector< LevelRec > | _levels
std::vector< FilePos > | _rpos
PtexReader * | _reader

## Static Private Attributes

static const int | MinReductionLog2 =2

## Additional Inherited Members

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.
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.
static bool | applyEdits (const char *path, Ptex::String &error)
| Apply edits to a file.
Protected Attributes inherited from PtexWriterBase
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

## Detailed Description

Definition at line 129 of file PtexWriter.h.

## Constructor & Destructor Documentation

## PtexMainWriter()

PtexMainWriter::PtexMainWriter | ( | const char * | path,
|  | PtexTexture * | tex,
|  | Ptex::MeshType | mt,
|  | Ptex::DataType | dt,
|  | int | nchannels,
|  | int | alphachan,
|  | int | nfaces,
|  | bool | genmipmaps )

Definition at line 723 of file PtexWriter.cpp.

References _constdata, _faceinfo, _hasNewData, _levels, _newpath, PtexWriterBase::_pixelSize, _reader, _rpos, _tmpfp, _tmppath, PtexTexture::edgeFilterMode(), PtexReader::getMetaData(), PtexReader::hasEdits(), PtexWriterBase::setBorderModes(), PtexWriterBase::setEdgeFilterMode(), PtexWriterBase::setError(), PtexTexture::uBorderMode(), PtexTexture::vBorderMode(), and PtexWriterBase::writeMeta().

## ~PtexMainWriter()

PtexMainWriter::~PtexMainWriter | ( |  | ) |

protected virtual

Definition at line 774 of file PtexWriter.cpp.

References _reader, and PtexReader::release().

## Member Function Documentation

## addMetaData()

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

inline protected virtual

Reimplemented from PtexWriterBase.

Definition at line 141 of file PtexWriter.h.

References _hasNewData, and PtexWriterBase::addMetaData().

## close()

bool PtexMainWriter::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.

Reimplemented from PtexWriterBase.

Definition at line 780 of file PtexWriter.cpp.

References _hasNewData, _newpath, PtexWriterBase::_path, _reader, _tmpfp, _tmppath, PtexWriterBase::close(), and PtexReader::release().

## finish()

void PtexMainWriter::finish | ( |  | ) |

private virtual

Implements PtexWriterBase.

Definition at line 890 of file PtexWriter.cpp.

References _constdata, PtexWriterBase::_extheader, _faceinfo, _genmipmaps, _hasNewData, PtexWriterBase::_header, _levels, PtexWriterBase::_metadata, _newpath, PtexWriterBase::_pixelSize, _reader, _tmpfp, Header::constdatasize, PtexWriterBase::copyBlock(), ExtHeader::editdatapos, ExtHeaderSize, Header::faceinfosize, PtexMainWriter::LevelRec::fdh, flagConstantNeighorhoods(), generateReductions(), PtexReader::getData(), PtexReader::getFaceInfo(), HeaderSize, Ptex::FaceInfo::isConstant(), Header::leveldatasize, LevelInfo::leveldatasize, LevelInfo::levelheadersize, LevelInfoSize, Header::levelinfosize, Header::nfaces, LevelInfo::nfaces, Header::nlevels, PtexMainWriter::LevelRec::pos, Ptex::FaceInfo::res, PtexWriterBase::setError(), Ptex::Res::size(), PtexWriterBase::writeBlank(), PtexWriterBase::writeBlock(), writeConstantFace(), writeFace(), writeMetaData(), and PtexWriterBase::writeZipBlock().

## flagConstantNeighorhoods()

void PtexMainWriter::flagConstantNeighorhoods | ( |  | ) |

private

Definition at line 996 of file PtexWriter.cpp.

References _constdata, PtexWriterBase::_extheader, _faceinfo, PtexWriterBase::_header, PtexWriterBase::_pixelSize, Ptex::m_clamp, Header::meshtype, ExtHeader::ubordermode, and ExtHeader::vbordermode.

Referenced by finish().

## generateReductions()

void PtexMainWriter::generateReductions | ( |  | ) |

private

Definition at line 1079 of file PtexWriter.cpp.

References _faceids_r, _faceinfo, PtexWriterBase::_header, _levels, PtexWriterBase::_ok, PtexWriterBase::_pixelSize, _rfaceids, _rpos, _tmpfp, PtexMainWriter::LevelRec::fdh, PtexUtils::genRfaceids(), PtexUtils::max(), PtexUtils::min(), MinReductionLog2, Header::nfaces, PtexMainWriter::LevelRec::pos, PtexWriterBase::readBlock(), storeConstValue(), PtexWriterBase::writeFaceData(), and PtexWriterBase::writeReduction().

Referenced by finish().

## storeConstValue()

void PtexMainWriter::storeConstValue | ( | int | faceid,
|  | const void * | data,
|  | int | stride,
|  | Res | res )

private

Definition at line 878 of file PtexWriter.cpp.

References _constdata, PtexWriterBase::_header, PtexWriterBase::_pixelSize, Header::alphachan, PtexUtils::average(), PtexWriterBase::datatype(), PtexUtils::divalpha(), Header::hasAlpha(), and Header::nchannels.

Referenced by generateReductions(), and writeFace().

## writeConstantFace()

bool PtexMainWriter::writeConstantFace | ( | int | faceid,
|  | const FaceInfo & | f,
|  | const void * | data )

virtual

Definition at line 863 of file PtexWriter.cpp.

References _constdata, _faceinfo, _hasNewData, PtexWriterBase::_ok, PtexWriterBase::_pixelSize, and PtexWriterBase::storeFaceInfo().

Referenced by finish(), and writeFace().

## writeFace()

bool PtexMainWriter::writeFace | ( | int | faceid,
|  | const FaceInfo & | f,
|  | const void * | data,
|  | int | stride )

virtual

Definition at line 806 of file PtexWriter.cpp.

References _faceinfo, _genmipmaps, _hasNewData, PtexWriterBase::_header, _levels, PtexWriterBase::_ok, PtexWriterBase::_pixelSize, _rpos, _tmpfp, Header::alphachan, PtexUtils::copy(), PtexWriterBase::datatype(), Header::hasAlpha(), PtexUtils::isConstant(), MinReductionLog2, PtexUtils::multalpha(), Header::nchannels, storeConstValue(), PtexWriterBase::storeFaceInfo(), writeConstantFace(), PtexWriterBase::writeFaceData(), and PtexWriterBase::writeReduction().

Referenced by finish().

## writeMetaData()

void PtexMainWriter::writeMetaData | ( | FILE * | fp | ) |

private

Definition at line 1150 of file PtexWriter.cpp.

References PtexWriterBase::_extheader, PtexWriterBase::_header, PtexWriterBase::_metadata, _tmpfp, PtexWriterBase::copyBlock(), PtexWriterBase::MetaEntry::data, PtexWriterBase::datatype(), PtexWriterBase::MetaEntry::datatype, PtexWriterBase::MetaEntry::key, ExtHeader::lmddatasize, ExtHeader::lmdheadermemsize, ExtHeader::lmdheaderzipsize, Header::metadatamemsize, MetaDataThreshold, Header::metadatazipsize, PtexWriterBase::writeBlank(), PtexWriterBase::writeMetaDataBlock(), and PtexWriterBase::writeZipBlock().

Referenced by finish().

## Member Data Documentation

## _constdata

std::vector<uint8_t> PtexMainWriter::_constdata

private

Definition at line 160 of file PtexWriter.h.

Referenced by finish(), flagConstantNeighorhoods(), PtexMainWriter(), storeConstValue(), and writeConstantFace().

## _faceids_r

std::vector<uint32_t> PtexMainWriter::_faceids_r

private

Definition at line 162 of file PtexWriter.h.

Referenced by generateReductions().

## _faceinfo

std::vector<FaceInfo> PtexMainWriter::_faceinfo

private

Definition at line 159 of file PtexWriter.h.

Referenced by finish(), flagConstantNeighorhoods(), generateReductions(), PtexMainWriter(), writeConstantFace(), and writeFace().

## _genmipmaps

bool PtexMainWriter::_genmipmaps

private

Definition at line 158 of file PtexWriter.h.

Referenced by finish(), and writeFace().

## _hasNewData

bool PtexMainWriter::_hasNewData

private

Definition at line 157 of file PtexWriter.h.

Referenced by addMetaData(), close(), finish(), PtexMainWriter(), writeConstantFace(), and writeFace().

## _levels

std::vector<LevelRec> PtexMainWriter::_levels

private

Definition at line 174 of file PtexWriter.h.

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

## _newpath

std::string PtexMainWriter::_newpath

private

Definition at line 154 of file PtexWriter.h.

Referenced by close(), finish(), and PtexMainWriter().

## _reader

PtexReader* PtexMainWriter::_reader

private

Definition at line 177 of file PtexWriter.h.

Referenced by close(), finish(), PtexMainWriter(), and ~PtexMainWriter().

## _rfaceids

std::vector<uint32_t> PtexMainWriter::_rfaceids

private

Definition at line 161 of file PtexWriter.h.

Referenced by generateReductions().

## _rpos

std::vector<FilePos> PtexMainWriter::_rpos

private

Definition at line 175 of file PtexWriter.h.

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

## _tmpfp

FILE* PtexMainWriter::_tmpfp

private

Definition at line 156 of file PtexWriter.h.

Referenced by close(), finish(), generateReductions(), PtexMainWriter(), writeFace(), and writeMetaData().

## _tmppath

std::string PtexMainWriter::_tmppath

private

Definition at line 155 of file PtexWriter.h.

Referenced by close(), and PtexMainWriter().

## MinReductionLog2

const int PtexMainWriter::MinReductionLog2 =2

static private

Definition at line 164 of file PtexWriter.h.

Referenced by generateReductions(), and writeFace().

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

- PtexWriter.h
- PtexWriter.cpp