Ptex

Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
PtexMainWriter Class Reference

`#include <PtexWriter.h>`

Inheritance diagram for PtexMainWriter:

## Classes
struct | MetaEntry
struct | FaceRec

## Public Member Functions
| PtexMainWriter (const char *path, PtexTexture *tex, Ptex::MeshType mt, Ptex::DataType dt, int nchannels, int alphachan, int nfaces, bool genmipmaps)
virtual void | release ()
| Release resources held by this pointer (pointer becomes invalid).
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)
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.
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.

## Private Member Functions
virtual | ~PtexMainWriter ()
DataType | datatype () const
size_t | writeBlock (FILE *fp, const void *data, size_t size)
size_t | writeBlock (FILE *fp, const std::vector< std::byte > &dataBlock)
void | addToDataBlock (std::vector< std::byte > &dataBlock, const void *data, size_t size)
libdeflate_compressor * | getCompressor ()
void | releaseCompressor (libdeflate_compressor *compressor)
void | compressDataBlock (libdeflate_compressor *compressor, std::vector< std::byte > &compressedData, const void *data, size_t size)
Res | calcTileRes (Res faceres)
void | addMetaData (const char *key, MetaDataType t, const void *value, int size)
void | compressFaceDataBlock (libdeflate_compressor *compressor, std::vector< std::byte > &compressedData, FaceDataHeader &fdh, Res res, const void *uncompressedData, int stride)
void | compressFaceData (libdeflate_compressor *compressor, std::vector< std::byte > &compressedData, FaceDataHeader &fdh, Res res, const void *uncompressedData)
void | addToMetaDataBlock (std::vector< std::byte > &dataBlock, const MetaEntry &val)
void | setError (const std::string &error)
bool | storeFaceInfo (int faceid, FaceInfo &dest, const FaceInfo &src, int flags=0)
void | finish ()
void | flagConstantNeighorhoods ()
void | storeConstValue (int faceid, const void *data, int stride, Res res)

## Private Attributes
bool | _ok
std::string | _error
std::string | _path
Header | _header
ExtHeader | _extheader
int | _pixelSize
std::vector< MetaEntry > | _metadata
std::map< std::string, int > | _metamap
std::vector< libdeflate_compressor * > | _compressors
Mutex | _compressorMutex
PtexUtils::ReduceFn * | _reduceFn
std::string | _newpath
bool | _genmipmaps
std::vector< FaceInfo > | _faceinfo
std::vector< std::byte > | _constdata
std::vector< uint32_t > | _rfaceids
std::vector< uint32_t > | _faceids_r
std::vector< FaceRec > | _faces
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, 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 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)
| Obsolete (returns true).
Protected Member Functions inherited from PtexWriter
virtual | ~PtexWriter ()
| Destructor not for public use. Use release() instead.

## Detailed Description

Definition at line 51 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 528 of file PtexWriter.cpp.

References _constdata, _extheader, _faceinfo, _faces, _genmipmaps, _header, _newpath, _ok, _path, _pixelSize, _reader, _reduceFn, PtexTexture::edgeFilterMode(), Magic, PtexFileMajorVersion, PtexFileMinorVersion, PtexUtils::reduce(), PtexUtils::reduceTri(), setBorderModes(), setEdgeFilterMode(), PtexTexture::uBorderMode(), PtexTexture::vBorderMode(), and writeMeta().

## ◆ ~PtexMainWriter()

PtexMainWriter::~PtexMainWriter | ( |  | ) |
| private virtual

Definition at line 582 of file PtexWriter.cpp.

References _compressors, and _reader.

## Member Function Documentation

## ◆ addMetaData()

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

Definition at line 316 of file PtexWriter.cpp.

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

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

## ◆ addToDataBlock()

void PtexMainWriter::addToDataBlock | ( | std::vector< std::byte > & | dataBlock,
|  | const void * | data,
|  | size_t | size )
| private

Definition at line 361 of file PtexWriter.cpp.

Referenced by addToMetaDataBlock(), compressFaceData(), and finish().

## ◆ addToMetaDataBlock()

void PtexMainWriter::addToMetaDataBlock | ( | std::vector< std::byte > & | dataBlock,
|  | const MetaEntry & | val )
| private

Definition at line 515 of file PtexWriter.cpp.

References addToDataBlock(), PtexMainWriter::MetaEntry::data, datatype(), PtexMainWriter::MetaEntry::datatype, and PtexMainWriter::MetaEntry::key.

Referenced by finish().

## ◆ calcTileRes()

Ptex::Res PtexMainWriter::calcTileRes | ( | Res | faceres | ) |
| private

Definition at line 402 of file PtexWriter.cpp.

References _pixelSize, PtexUtils::floor_log2(), Ptex::Res::size64(), and TileSize.

Referenced by compressFaceData().

## ◆ close()

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

Close the file.

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

Implements PtexWriter.

Definition at line 591 of file PtexWriter.cpp.

References _newpath, _ok, _path, _reader, finish(), getError(), and setError().

Referenced by release().

## ◆ compressDataBlock()

void PtexMainWriter::compressDataBlock | ( | libdeflate_compressor * | compressor,
|  | std::vector< std::byte > & | compressedData,
|  | const void * | data,
|  | size_t | size )
| private

Definition at line 391 of file PtexWriter.cpp.

References setError().

Referenced by compressFaceData(), compressFaceDataBlock(), and finish().

## ◆ compressFaceData()

void PtexMainWriter::compressFaceData | ( | libdeflate_compressor * | compressor,
|  | std::vector< std::byte > & | compressedData,
|  | FaceDataHeader & | fdh,
|  | Res | res,
|  | const void * | uncompressedData )
| private

Definition at line 450 of file PtexWriter.cpp.

References _pixelSize, addToDataBlock(), calcTileRes(), compressDataBlock(), compressFaceDataBlock(), enc_constant, enc_tiled, PtexUtils::isConstant(), and FaceDataHeader::set().

Referenced by writeFace().

## ◆ compressFaceDataBlock()

void PtexMainWriter::compressFaceDataBlock | ( | libdeflate_compressor * | compressor,
|  | std::vector< std::byte > & | compressedData,
|  | FaceDataHeader & | fdh,
|  | Res | res,
|  | const void * | uncompressedData,
|  | int | stride )
| private

Definition at line 424 of file PtexWriter.cpp.

References _header, _pixelSize, compressDataBlock(), datatype(), PtexUtils::deinterleave(), enc_diffzipped, enc_zipped, PtexUtils::encodeDifference(), and FaceDataHeader::set().

Referenced by compressFaceData().

## ◆ datatype()

DataType PtexMainWriter::datatype | ( |  | ) | const
| inline private

Definition at line 90 of file PtexWriter.h.

References _header.

Referenced by addToMetaDataBlock(), compressFaceDataBlock(), finish(), storeConstValue(), and writeFace().

## ◆ finish()

void PtexMainWriter::finish | ( |  | ) |
| private

Definition at line 721 of file PtexWriter.cpp.

References _constdata, _extheader, _faceids_r, _faceinfo, _faces, _genmipmaps, _header, _metadata, _newpath, _pixelSize, _reader, _rfaceids, addToDataBlock(), addToMetaDataBlock(), compressDataBlock(), PtexMainWriter::MetaEntry::data, datatype(), PtexMainWriter::MetaEntry::datatype, ExtHeaderSize, PtexMainWriter::FaceRec::faceData, PtexMainWriter::FaceRec::fdh, flagConstantNeighorhoods(), PtexUtils::genRfaceids(), getCompressor(), HeaderSize, Ptex::FaceInfo::isConstant(), PtexMainWriter::MetaEntry::key, LevelInfoSize, MetaDataThreshold, MinReductionLog2, releaseCompressor(), Ptex::FaceInfo::res, setError(), Ptex::Res::size64(), storeFaceInfo(), Ptex::Res::ulog2, Ptex::Res::vlog2, writeBlock(), and writeFace().

Referenced by close().

## ◆ flagConstantNeighorhoods()

void PtexMainWriter::flagConstantNeighorhoods | ( |  | ) |
| private

Definition at line 939 of file PtexWriter.cpp.

References _constdata, _extheader, _faceinfo, _header, _pixelSize, and Ptex::m_clamp.

Referenced by finish().

## ◆ getCompressor()

libdeflate_compressor * PtexMainWriter::getCompressor | ( |  | ) |
| private

Definition at line 369 of file PtexWriter.cpp.

References _compressorMutex, and _compressors.

Referenced by finish(), and writeFace().

## ◆ getError()

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

Definition at line 83 of file PtexWriter.h.

References _error, and _path.

Referenced by close(), and ok().

## ◆ ok()

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

Definition at line 79 of file PtexWriter.h.

References _ok, and getError().

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

## ◆ release()

void PtexMainWriter::release | ( |  | ) |
| virtual

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

Implements PtexWriter.

Definition at line 182 of file PtexWriter.cpp.

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

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

## ◆ releaseCompressor()

void PtexMainWriter::releaseCompressor | ( | libdeflate_compressor * | compressor | ) |
| private

Definition at line 384 of file PtexWriter.cpp.

References _compressorMutex, and _compressors.

Referenced by finish(), and writeFace().

## ◆ setBorderModes()

virtual void PtexMainWriter::setBorderModes | ( | Ptex::BorderMode | uBorderMode,
|  | Ptex::BorderMode | vBorderMode )
| inline virtual

Set border modes.

Implements PtexWriter.

Definition at line 62 of file PtexWriter.h.

References _extheader.

Referenced by PtexMainWriter().

## ◆ setEdgeFilterMode()

virtual void PtexMainWriter::setEdgeFilterMode | ( | Ptex::EdgeFilterMode | edgeFilterMode | ) |
| inline virtual

Set edge filter mode.

Implements PtexWriter.

Definition at line 67 of file PtexWriter.h.

References _extheader.

Referenced by PtexMainWriter().

## ◆ setError()

void PtexMainWriter::setError | ( | const std::string & | error | ) |
| inline private

Definition at line 112 of file PtexWriter.h.

References _error, and _ok.

Referenced by addMetaData(), close(), compressDataBlock(), finish(), storeFaceInfo(), and writeBlock().

## ◆ storeConstValue()

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

Definition at line 709 of file PtexWriter.cpp.

References _constdata, _header, _pixelSize, PtexUtils::average(), datatype(), and PtexUtils::divalpha().

Referenced by writeFace().

## ◆ storeFaceInfo()

bool PtexMainWriter::storeFaceInfo | ( | int | faceid,
|  | FaceInfo & | dest,
|  | const FaceInfo & | src,
|  | int | flags = 0 )
| private

Definition at line 192 of file PtexWriter.cpp.

References _header, and setError().

Referenced by finish(), writeConstantFace(), and writeFace().

## ◆ writeBlock() [1/2]

size_t PtexMainWriter::writeBlock | ( | FILE * | fp,
|  | const std::vector< std::byte > & | dataBlock )
| inline private

Definition at line 100 of file PtexWriter.h.

References writeBlock().

Referenced by writeBlock().

## ◆ writeBlock() [2/2]

size_t PtexMainWriter::writeBlock | ( | FILE * | fp,
|  | const void * | data,
|  | size_t | size )
| private

Definition at line 350 of file PtexWriter.cpp.

References _ok, and setError().

Referenced by finish().

## ◆ writeConstantFace()

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

Definition at line 695 of file PtexWriter.cpp.

References _constdata, _faceinfo, _ok, _pixelSize, and storeFaceInfo().

Referenced by writeFace().

## ◆ writeFace()

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

Definition at line 613 of file PtexWriter.cpp.

References _faceinfo, _faces, _genmipmaps, _header, _ok, _pixelSize, _reduceFn, compressFaceData(), PtexUtils::copy(), datatype(), PtexMainWriter::FaceRec::faceData, PtexMainWriter::FaceRec::fdh, getCompressor(), PtexUtils::isConstant(), MinReductionLog2, PtexUtils::multalpha(), PtexMainWriter::FaceRec::mutex, releaseCompressor(), Ptex::Res::size64(), storeConstValue(), storeFaceInfo(), Ptex::Res::u(), Ptex::Res::ulog2, Ptex::Res::v(), Ptex::Res::vlog2, and writeConstantFace().

Referenced by finish().

## ◆ writeMeta() [1/7]

void PtexMainWriter::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 224 of file PtexWriter.cpp.

References addMetaData().

Referenced by PtexMainWriter(), and writeMeta().

## ◆ writeMeta() [2/7]

void PtexMainWriter::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 254 of file PtexWriter.cpp.

References addMetaData().

## ◆ writeMeta() [3/7]

void PtexMainWriter::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 248 of file PtexWriter.cpp.

References addMetaData().

## ◆ writeMeta() [4/7]

void PtexMainWriter::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 236 of file PtexWriter.cpp.

References addMetaData().

## ◆ writeMeta() [5/7]

void PtexMainWriter::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 242 of file PtexWriter.cpp.

References addMetaData().

## ◆ writeMeta() [6/7]

void PtexMainWriter::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 230 of file PtexWriter.cpp.

References addMetaData().

## ◆ writeMeta() [7/7]

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

Copy meta data from an existing meta data block.

Implements PtexWriter.

Definition at line 260 of file PtexWriter.cpp.

References PtexMetaData::getKey(), PtexMetaData::getValue(), PtexMetaData::numKeys(), and writeMeta().

## Member Data Documentation

## ◆ _compressorMutex

Mutex PtexMainWriter::_compressorMutex
| private

Definition at line 128 of file PtexWriter.h.

Referenced by getCompressor(), and releaseCompressor().

## ◆ _compressors

std::vector<libdeflate_compressor*> PtexMainWriter::_compressors
| private

Definition at line 127 of file PtexWriter.h.

Referenced by getCompressor(), releaseCompressor(), and ~PtexMainWriter().

## ◆ _constdata

std::vector<std::byte> PtexMainWriter::_constdata
| private

Definition at line 135 of file PtexWriter.h.

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

## ◆ _error

std::string PtexMainWriter::_error
| private

Definition at line 119 of file PtexWriter.h.

Referenced by getError(), and setError().

## ◆ _extheader

ExtHeader PtexMainWriter::_extheader
| private

Definition at line 122 of file PtexWriter.h.

Referenced by finish(), flagConstantNeighorhoods(), PtexMainWriter(), setBorderModes(), and setEdgeFilterMode().

## ◆ _faceids_r

std::vector<uint32_t> PtexMainWriter::_faceids_r
| private

Definition at line 137 of file PtexWriter.h.

Referenced by finish().

## ◆ _faceinfo

std::vector<FaceInfo> PtexMainWriter::_faceinfo
| private

Definition at line 134 of file PtexWriter.h.

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

## ◆ _faces

std::vector<FaceRec> PtexMainWriter::_faces
| private

Definition at line 145 of file PtexWriter.h.

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

## ◆ _genmipmaps

bool PtexMainWriter::_genmipmaps
| private

Definition at line 133 of file PtexWriter.h.

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

## ◆ _header

Header PtexMainWriter::_header
| private

Definition at line 121 of file PtexWriter.h.

Referenced by compressFaceDataBlock(), datatype(), finish(), flagConstantNeighorhoods(), PtexMainWriter(), storeConstValue(), storeFaceInfo(), and writeFace().

## ◆ _metadata

std::vector<MetaEntry> PtexMainWriter::_metadata
| private

Definition at line 124 of file PtexWriter.h.

Referenced by addMetaData(), and finish().

## ◆ _metamap

std::map<std::string,int> PtexMainWriter::_metamap
| private

Definition at line 125 of file PtexWriter.h.

Referenced by addMetaData().

## ◆ _newpath

std::string PtexMainWriter::_newpath
| private

Definition at line 132 of file PtexWriter.h.

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

## ◆ _ok

bool PtexMainWriter::_ok
| private

Definition at line 118 of file PtexWriter.h.

Referenced by close(), ok(), PtexMainWriter(), setError(), writeBlock(), writeConstantFace(), and writeFace().

## ◆ _path

std::string PtexMainWriter::_path
| private

Definition at line 120 of file PtexWriter.h.

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

## ◆ _pixelSize

int PtexMainWriter::_pixelSize
| private

Definition at line 123 of file PtexWriter.h.

Referenced by calcTileRes(), compressFaceData(), compressFaceDataBlock(), finish(), flagConstantNeighorhoods(), PtexMainWriter(), storeConstValue(), writeConstantFace(), and writeFace().

## ◆ _reader

PtexReader* PtexMainWriter::_reader
| private

Definition at line 147 of file PtexWriter.h.

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

## ◆ _reduceFn

PtexUtils::ReduceFn* PtexMainWriter::_reduceFn
| private

Definition at line 130 of file PtexWriter.h.

Referenced by PtexMainWriter(), and writeFace().

## ◆ _rfaceids

std::vector<uint32_t> PtexMainWriter::_rfaceids
| private

Definition at line 136 of file PtexWriter.h.

Referenced by finish().

## ◆ MinReductionLog2

const int PtexMainWriter::MinReductionLog2 =2
| static private

Definition at line 139 of file PtexWriter.h.

Referenced by finish(), and writeFace().

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

- PtexWriter.h
- PtexWriter.cpp