Ptex
Ptexture.h
Go to the documentation of this file.
1 #ifndef Ptexture_h
2 #define Ptexture_h
3 
4 /*
5 PTEX SOFTWARE
6 Copyright 2009 Disney Enterprises, Inc. All rights reserved
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are
10 met:
11 
12  * Redistributions of source code must retain the above copyright
13  notice, this list of conditions and the following disclaimer.
14 
15  * Redistributions in binary form must reproduce the above copyright
16  notice, this list of conditions and the following disclaimer in
17  the documentation and/or other materials provided with the
18  distribution.
19 
20  * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
21  Studios" or the names of its contributors may NOT be used to
22  endorse or promote products derived from this software without
23  specific prior written permission from Walt Disney Pictures.
24 
25 Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
26 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
27 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
28 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
29 IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
30 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37 */
38 
44 #if defined(_WIN32) || defined(_WINDOWS) || defined(_MSC_VER)
45 # ifndef PTEXAPI
46 # ifndef PTEX_STATIC
47 # ifdef PTEX_EXPORTS
48 # define PTEXAPI __declspec(dllexport)
49 # else
50 # define PTEXAPI __declspec(dllimport)
51 # endif
52 # else
53 # define PTEXAPI
54 # endif
55 # endif
56 #else
57 # ifndef PTEXAPI
58 # define PTEXAPI
59 # endif
60 # ifndef DOXYGEN
61 # define PTEX_USE_STDSTRING
62 # endif
63 #endif
64 
65 #include "PtexInt.h"
66 #include <ostream>
67 
68 #define PtexAPIVersion 2
69 #define PtexFileMajorVersion 1
70 #define PtexFileMinorVersion 3
71 
73 struct Ptex {
77  enum MeshType {
80  };
81 
83  enum DataType {
88  };
89 
91  enum BorderMode {
95  };
96 
99  enum EdgeId {
104  };
105 
114  };
115 
117  PTEXAPI static const char* MeshTypeName(MeshType mt);
118 
120  PTEXAPI static const char* DataTypeName(DataType dt);
121 
123  PTEXAPI static const char* BorderModeName(BorderMode m);
124 
126  PTEXAPI static const char* EdgeIdName(EdgeId eid);
127 
129  PTEXAPI static const char* MetaDataTypeName(MetaDataType mdt);
130 
132  static int DataSize(DataType dt) {
133  static const int sizes[] = { 1,2,2,4 };
134  return sizes[dt];
135  }
136 
138  static float OneValue(DataType dt) {
139  static const float one[] = { 255.f, 65535.f, 1.f, 1.f };
140  return one[dt];
141  }
142 
144  static float OneValueInv(DataType dt) {
145  static const float one[] = { 1.f/255.f, 1.f/65535.f, 1.f, 1.f };
146  return one[dt];
147  }
148 
150  PTEXAPI static void ConvertToFloat(float* dst, const void* src,
151  Ptex::DataType dt, int numChannels);
152 
154  PTEXAPI static void ConvertFromFloat(void* dst, const float* src,
155  Ptex::DataType dt, int numChannels);
156 
161  struct Res {
162  int8_t ulog2;
163  int8_t vlog2;
164 
166  Res() : ulog2(0), vlog2(0) {}
167 
169  Res(int8_t ulog2_, int8_t vlog2_) : ulog2(ulog2_), vlog2(vlog2_) {}
170 
172  Res(uint16_t value) {
173  ulog2 = *(uint8_t *)&value;
174  vlog2 = *((uint8_t *)&value + 1);
175  }
176 
178  int u() const { return 1<<(unsigned)ulog2; }
179 
181  int v() const { return 1<<(unsigned)vlog2; }
182 
184  uint16_t& val() { return *(uint16_t*)this; }
185 
187  const uint16_t& val() const { return *(const uint16_t*)this; }
188 
190  int size() const { return u() * v(); }
193  bool operator==(const Res& r) const { return val() == r.val(); }
194 
196  bool operator!=(const Res& r) const { return val() != r.val(); }
199  bool operator>=(const Res& r) const { return ulog2 >= r.ulog2 && vlog2 >= r.vlog2; }
202  Res swappeduv() const { return Res(vlog2, ulog2); }
203 
205  void swapuv() { *this = swappeduv(); }
208  void clamp(const Res& r) {
209  if (ulog2 > r.ulog2) ulog2 = r.ulog2;
210  if (vlog2 > r.vlog2) vlog2 = r.vlog2;
211  }
214  int ntilesu(Res tileres) const { return 1<<(ulog2-tileres.ulog2); }
217  int ntilesv(Res tileres) const { return 1<<(vlog2-tileres.vlog2); }
218 
220  int ntiles(Res tileres) const { return ntilesu(tileres) * ntilesv(tileres); }
221  };
237  struct FaceInfo {
239  uint8_t adjedges;
240  uint8_t flags;
241  int32_t adjfaces[4];
242 
244  FaceInfo() : res(), adjedges(0), flags(0)
245  {
246  adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
247  }
248 
250  FaceInfo(Res res_) : res(res_), adjedges(0), flags(0)
251  {
252  adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
253  }
254 
256  FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
257  : res(res_), flags(isSubface_ ? flag_subface : 0)
258  {
259  setadjfaces(adjfaces_[0], adjfaces_[1], adjfaces_[2], adjfaces_[3]);
260  setadjedges(adjedges_[0], adjedges_[1], adjedges_[2], adjedges_[3]);
261  }
262 
264  EdgeId adjedge(int eid) const { return EdgeId((adjedges >> (2*eid)) & 3); }
265 
267  int adjface(int eid) const { return adjfaces[eid]; }
268 
270  bool isConstant() const { return (flags & flag_constant) != 0; }
271 
273  bool isNeighborhoodConstant() const { return (flags & flag_nbconstant) != 0; }
276  bool hasEdits() const { return (flags & flag_hasedits) != 0; }
277 
279  bool isSubface() const { return (flags & flag_subface) != 0; }
280 
282  void setadjfaces(int f0, int f1, int f2, int f3)
283  { adjfaces[0] = f0, adjfaces[1] = f1, adjfaces[2] = f2; adjfaces[3] = f3; }
284 
286  void setadjedges(int e0, int e1, int e2, int e3)
287  { adjedges = (uint8_t)((e0&3) | ((e1&3)<<2) | ((e2&3)<<4) | ((e3&3)<<6)); }
288 
291  };
292 
293 
300 #ifdef PTEX_USE_STDSTRING
301  typedef std::string String;
302 #else
303  class String
304  {
305  public:
306  String() : _str(0) {}
307  String(const String& str) : _str(0) { *this = str; }
308  PTEXAPI ~String();
309  PTEXAPI String& operator=(const char* str);
310  String& operator=(const String& str) { *this = str._str; return *this; }
311  String& operator=(const std::string& str) { *this = str.c_str(); return *this; }
312  const char* c_str() const { return _str ? _str : ""; }
313  bool empty() const { return _str == 0; }
314 
315  private:
316  char* _str;
317  };
318 #endif
319 
320 }
321 #ifndef DOXYGEN
322 ;
323 #endif
324 
326 #ifndef PTEX_USE_STDSTRING
327 std::ostream& operator << (std::ostream& stream, const Ptex::String& str);
328 #endif
329 
338  protected:
340  virtual ~PtexMetaData() {}
341 
342  public:
344  virtual void release() = 0;
345 
347  virtual int numKeys() = 0;
348 
350  virtual void getKey(int n, const char*& key, Ptex::MetaDataType& type) = 0;
354  virtual void getValue(const char* key, const char*& value) = 0;
355 
358  virtual void getValue(const char* key, const int8_t*& value, int& count) = 0;
359 
362  virtual void getValue(const char* key, const int16_t*& value, int& count) = 0;
366  virtual void getValue(const char* key, const int32_t*& value, int& count) = 0;
367 
370  virtual void getValue(const char* key, const float*& value, int& count) = 0;
371 
374  virtual void getValue(const char* key, const double*& value, int& count) = 0;
375 };
376 
389  protected:
391  virtual ~PtexFaceData() {}
393  public:
395  virtual void release() = 0;
396 
398  virtual bool isConstant() = 0;
403  virtual Ptex::Res res() = 0;
404 
408  virtual void getPixel(int u, int v, void* result) = 0;
409 
416  virtual void* getData() = 0;
417 
420  virtual bool isTiled() = 0;
421 
423  virtual Ptex::Res tileRes() = 0;
426  virtual PtexFaceData* getTile(int tile) = 0;
427 };
428 
439 class PtexTexture {
440  protected:
442  virtual ~PtexTexture() {}
443 
444  public:
456  PTEXAPI static PtexTexture* open(const char* path, Ptex::String& error, bool premultiply=0);
457 
458 
460  virtual void release() = 0;
461 
465  virtual const char* path() = 0;
466 
468  virtual Ptex::MeshType meshType() = 0;
469 
471  virtual Ptex::DataType dataType() = 0;
472 
474  virtual Ptex::BorderMode uBorderMode() = 0;
475 
477  virtual Ptex::BorderMode vBorderMode() = 0;
478 
482  virtual int alphaChannel() = 0;
483 
485  virtual int numChannels() = 0;
486 
488  virtual int numFaces() = 0;
489 
491  virtual bool hasEdits() = 0;
492 
494  virtual bool hasMipMaps() = 0;
495 
497  virtual PtexMetaData* getMetaData() = 0;
498 
500  virtual const Ptex::FaceInfo& getFaceInfo(int faceid) = 0;
501 
517  virtual void getData(int faceid, void* buffer, int stride) = 0;
518 
530  virtual void getData(int faceid, void* buffer, int stride, Ptex::Res res) = 0;
531 
533  virtual PtexFaceData* getData(int faceid) = 0;
534 
544  virtual PtexFaceData* getData(int faceid, Ptex::Res res) = 0;
545 
558  virtual void getPixel(int faceid, int u, int v,
559  float* result, int firstchan, int nchannels) = 0;
560 
572  virtual void getPixel(int faceid, int u, int v,
573  float* result, int firstchan, int nchannels,
574  Ptex::Res res) = 0;
575 };
576 
577 
586  protected:
587  virtual ~PtexInputHandler() {}
588 
589  public:
590  typedef void* Handle;
591 
596  virtual Handle open(const char* path) = 0;
597 
599  virtual void seek(Handle handle, int64_t pos) = 0;
600 
606  virtual size_t read(void* buffer, size_t size, Handle handle) = 0;
607 
610  virtual bool close(Handle handle) = 0;
611 
613  virtual const char* lastError() = 0;
614 };
615 
616 
634 class PtexCache {
635  protected:
637  virtual ~PtexCache() {}
638 
639  public:
655  PTEXAPI static PtexCache* create(int maxFiles=0,
656  int maxMem=0,
657  bool premultiply=false,
658  PtexInputHandler* handler=0);
659 
661  virtual void release() = 0;
662 
668  virtual void setSearchPath(const char* path) = 0;
669 
671  virtual const char* getSearchPath() = 0;
672 
699  virtual PtexTexture* get(const char* path, Ptex::String& error) = 0;
700 
705  virtual void purge(PtexTexture* texture) = 0;
706 
712  virtual void purge(const char* path) = 0;
713 
717  virtual void purgeAll() = 0;
718 };
719 
720 
737 class PtexWriter {
738  protected:
740  virtual ~PtexWriter() {}
741 
742  public:
753  PTEXAPI
754  static PtexWriter* open(const char* path,
756  int nchannels, int alphachan, int nfaces,
757  Ptex::String& error, bool genmipmaps=true);
758 
776  PTEXAPI
777  static PtexWriter* edit(const char* path, bool incremental,
779  int nchannels, int alphachan, int nfaces,
780  Ptex::String& error, bool genmipmaps=true);
781 
790  PTEXAPI
791  static bool applyEdits(const char* path, Ptex::String& error);
792 
794  virtual void release() = 0;
795 
797  virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode) = 0;
798 
800  virtual void writeMeta(const char* key, const char* string) = 0;
801 
803  virtual void writeMeta(const char* key, const int8_t* value, int count) = 0;
804 
806  virtual void writeMeta(const char* key, const int16_t* value, int count) = 0;
807 
809  virtual void writeMeta(const char* key, const int32_t* value, int count) = 0;
810 
812  virtual void writeMeta(const char* key, const float* value, int count) = 0;
813 
815  virtual void writeMeta(const char* key, const double* value, int count) = 0;
816 
818  virtual void writeMeta(PtexMetaData* data) = 0;
819 
831  virtual bool writeFace(int faceid, const Ptex::FaceInfo& info, const void* data, int stride=0) = 0;
832 
838  virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo& info, const void* data) = 0;
839 
843  virtual bool close(Ptex::String& error) = 0;
844 
845 #if NEW_API
846  virtual bool writeFaceReduction(int faceid, const Ptex::Res& res, const void* data, int stride=0) = 0;
847  virtual bool writeConstantFaceReduction(int faceid, const Ptex::Res& res, const void* data) = 0;
848 #endif
849 };
850 
851 
861 class PtexFilter {
862  protected:
864  virtual ~PtexFilter() {}
865 
866  public:
868  enum FilterType {
877  };
878 
880  struct Options {
883  bool lerp;
884  float sharpness;
885 
887  Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0) :
888  __structSize(sizeof(Options)),
889  filter(filter_), lerp(lerp_), sharpness(sharpness_) {}
890  };
891 
892  /* Construct a filter for the given texture.
893  */
894  PTEXAPI static PtexFilter* getFilter(PtexTexture* tx, const Options& opts);
895 
897  virtual void release() = 0;
898 
920  virtual void eval(float* result, int firstchan, int nchannels,
921  int faceid, float u, float v, float uw1, float vw1, float uw2, float vw2,
922  float width=1, float blur=0) = 0;
923 };
924 
925 
955 template <class T> class PtexPtr {
956  T* _ptr;
957  public:
959  PtexPtr(T* ptr=0) : _ptr(ptr) {}
960 
962  ~PtexPtr() { if (_ptr) _ptr->release(); }
963 
965  operator T* () { return _ptr; }
966 
968  T* operator-> () { return _ptr; }
969 
971  T* get() { return _ptr; }
972 
974  void swap(PtexPtr& p)
975  {
976  T* tmp = p._ptr;
977  p._ptr = _ptr;
978  _ptr = tmp;
979  }
980 
982  void reset(T* ptr=0) {
983  if (_ptr) _ptr->release();
984  _ptr = ptr;
985  }
986 
987  private:
989  PtexPtr(const PtexPtr& p);
990 
992  void operator= (PtexPtr& p);
993 };
994 
995 #endif
Single-precision (32-bit) floating point.
Definition: Ptexture.h:112
PtexPtr(T *ptr=0)
Constructor.
Definition: Ptexture.h:959
Mesh is quad-based.
Definition: Ptexture.h:79
T * operator->()
Access members of pointer.
Definition: Ptexture.h:968
Left edge, from UV (0,1) to (0,0)
Definition: Ptexture.h:103
virtual Ptex::BorderMode vBorderMode()=0
Mode for filtering texture access beyond mesh border.
virtual void getKey(int n, const char *&key, Ptex::MetaDataType &type)=0
Query the name and type of a meta data entry.
Signed 8-bit integer.
Definition: Ptexture.h:109
static float OneValueInv(DataType dt)
Lookup up inverse value of given data type that corresponds to the normalized value of 1...
Definition: Ptexture.h:144
int ntiles(Res tileres) const
Determine the total number of tiles for the given tile res.
Definition: Ptexture.h:220
int ntilesv(Res tileres) const
Determine the number of tiles in the v direction for the given tile res.
Definition: Ptexture.h:217
FaceInfo()
Default constructor, sets all members to zero.
Definition: Ptexture.h:244
int adjface(int eid) const
Access an adjacent face id. The eid value must be 0..3.
Definition: Ptexture.h:267
virtual int numChannels()=0
Number of channels stored in file.
Interface for writing data to a ptex file.
Definition: Ptexture.h:737
Unsigned, 8-bit integer.
Definition: Ptexture.h:84
void setadjedges(int e0, int e1, int e2, int e3)
Set the adjedges data.
Definition: Ptexture.h:286
Common data structures and enums used throughout the API.
Definition: Ptexture.h:73
Box filter.
Definition: Ptexture.h:871
virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode)=0
Set border modes.
bool isConstant() const
Determine if face is constant (by checking a flag).
Definition: Ptexture.h:270
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:190
bool operator>=(const Res &r) const
True if res is >= given res in both u and v directions.
Definition: Ptexture.h:199
Unsigned, 16-bit integer.
Definition: Ptexture.h:85
static int DataSize(DataType dt)
Look up size of given data type (in bytes).
Definition: Ptexture.h:132
Memory-managed string.
Definition: Ptexture.h:303
virtual bool hasEdits()=0
True if the file has edit blocks.
Top edge, from UV (1,1) to (0,1)
Definition: Ptexture.h:102
Half-precision (16-bit) floating point.
Definition: Ptexture.h:86
DataType
Type of data stored in texture file.
Definition: Ptexture.h:83
void reset(T *ptr=0)
Deallocate object pointed to, and optionally set to new value.
Definition: Ptexture.h:982
FaceInfo(Res res_)
Constructor.
Definition: Ptexture.h:250
Meta data accessor.
Definition: Ptexture.h:337
T * _ptr
Definition: Ptexture.h:956
uint8_t flags
Flags.
Definition: Ptexture.h:240
Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0)
Constructor - sets defaults.
Definition: Ptexture.h:887
static PtexFilter * getFilter(PtexTexture *tx, const Options &opts)
Mesh is triangle-based.
Definition: Ptexture.h:78
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
Res swappeduv() const
Get value of resolution with u and v swapped.
Definition: Ptexture.h:202
File-handle and memory cache for reading ptex files.
Definition: Ptexture.h:634
virtual void eval(float *result, int firstchan, int nchannels, int faceid, float u, float v, float uw1, float vw1, float uw2, float vw2, float width=1, float blur=0)=0
Apply filter to a ptex data file.
bool isNeighborhoodConstant() const
Determine if neighborhood of face is constant (by checking a flag).
Definition: Ptexture.h:273
String & operator=(const char *str)
Definition: PtexUtils.cpp:666
Pixel resolution of a given texture.
Definition: Ptexture.h:274
void operator=(PtexPtr &p)
Assignment prohibited.
Bi-linear interpolation.
Definition: Ptexture.h:870
Null-terminated string.
Definition: Ptexture.h:108
static PtexCache * create(int maxFiles=0, int maxMem=0, bool premultiply=false, PtexInputHandler *handler=0)
Create a cache with the specified limits.
Definition: PtexCache.cpp:410
Memory-managed string.
Definition: Ptexture.h:416
MetaDataType
Type of meta data entry.
Definition: Ptexture.h:107
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
int v() const
V resolution in texels.
Definition: Ptexture.h:181
virtual Handle open(const char *path)=0
Open a file in read mode.
EdgeId
Edge IDs used in adjacency data in the Ptex::FaceInfo struct.
Definition: Ptexture.h:212
virtual int alphaChannel()=0
Index of alpha channel (if any).
virtual PtexMetaData * getMetaData()=0
Access meta data.
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.
Definition: PtexWriter.cpp:166
static float OneValue(DataType dt)
Look up value of given data type that corresponds to the normalized value of 1.0. ...
Definition: Ptexture.h:138
int8_t vlog2
log base 2 of v resolution, in texels
Definition: Ptexture.h:276
Bottom edge, from UV (0,0) to (1,0)
Definition: Ptexture.h:100
static const char * MeshTypeName(MeshType mt)
Look up name of given mesh type.
Definition: PtexUtils.cpp:45
virtual ~PtexFaceData()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:391
virtual size_t read(void *buffer, size_t size, Handle handle)=0
Read a number of bytes from the file.
int32_t adjfaces[4]
Adjacent faces (-1 == no adjacent face).
Definition: Ptexture.h:241
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:91
virtual Ptex::MeshType meshType()=0
Type of mesh for which texture data is defined.
virtual Ptex::Res res()=0
Resolution of the texture held by this data block.
virtual ~PtexWriter()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:740
char * _str
Definition: Ptexture.h:316
Per-face texture data accessor.
Definition: Ptexture.h:388
bool operator!=(const Res &r) const
Comparison operator.
Definition: Ptexture.h:196
virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo &info, const void *data)=0
Write constant texture data for a face.
int u() const
U resolution in texels.
Definition: Ptexture.h:178
virtual void * getData()=0
Access the data from this data block.
int8_t vlog2
log base 2 of v resolution, in texels
Definition: Ptexture.h:163
uint16_t & val()
Resolution as a single 16-bit integer value.
Definition: Ptexture.h:297
virtual void writeMeta(const char *key, const char *string)=0
Write a string as meta data.
int ntilesu(Res tileres) const
Determine the number of tiles in the u direction for the given tile res.
Definition: Ptexture.h:214
virtual PtexFaceData * getTile(int tile)=0
Access a tile from the data block.
virtual ~PtexInputHandler()
Definition: Ptexture.h:587
int8_t ulog2
log base 2 of u resolution, in texels
Definition: Ptexture.h:275
Single-precision (32-bit) floating point.
Definition: Ptexture.h:87
virtual void getData(int faceid, void *buffer, int stride)=0
Access texture data for a face at highest-resolution.
DataType
Type of data stored in texture file.
Definition: Ptexture.h:196
std::ostream & operator<<(std::ostream &stream, const Ptex::String &str)
Definition: PtexUtils.cpp:673
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:204
bool isSubface() const
Determine if face is a subface (by checking a flag).
Definition: Ptexture.h:279
virtual bool hasMipMaps()=0
True if the file has mipmaps.
bool hasEdits() const
Determine if face has edits in the file (by checking a flag).
Definition: Ptexture.h:276
String & operator=(const String &str)
Definition: Ptexture.h:310
virtual void purgeAll()=0
Remove all texture files from the cache.
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
virtual ~PtexFilter()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:864
virtual int numFaces()=0
Number of faces stored in file.
static const char * DataTypeName(DataType dt)
Look up name of given data type.
Definition: PtexUtils.cpp:54
~PtexPtr()
Destructor, calls ptr->release().
Definition: Ptexture.h:962
bool empty() const
Definition: Ptexture.h:313
Signed 32-bit integer.
Definition: Ptexture.h:111
virtual bool writeFace(int faceid, const Ptex::FaceInfo &info, const void *data, int stride=0)=0
Write texture data for a face.
const uint16_t & val() const
Resolution as a single 16-bit integer value.
Definition: Ptexture.h:187
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
virtual const char * lastError()=0
Return the last error message encountered.
Mitchell (equivalent to bi-cubic w/ sharpness=2/3)
Definition: Ptexture.h:876
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:77
Point-sampled (no filtering)
Definition: Ptexture.h:869
EdgeId adjedge(int eid) const
Access an adjacent edge id. The eid value must be 0..3.
Definition: Ptexture.h:264
MetaDataType
Type of meta data entry.
Definition: Ptexture.h:220
virtual ~PtexTexture()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:442
String(const String &str)
Definition: Ptexture.h:307
FilterType filter
Filter type.
Definition: Ptexture.h:882
FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
Constructor.
Definition: Ptexture.h:256
int size() const
Total size of specified texture in texels (u * v).
Definition: Ptexture.h:190
void setadjfaces(int f0, int f1, int f2, int f3)
Set the adjfaces data.
Definition: Ptexture.h:282
String & operator=(const std::string &str)
Definition: Ptexture.h:311
texel beyond border are assumed to be black
Definition: Ptexture.h:93
Catmull-Rom (equivalent to bi-cubic w/ sharpness=1)
Definition: Ptexture.h:875
virtual Ptex::DataType dataType()=0
Type of data stored in file.
Res()
Default constructor, sets res to 0 (1x1 texel).
Definition: Ptexture.h:166
static PtexTexture * open(const char *path, Ptex::String &error, bool premultiply=0)
Open a ptex file for reading.
Definition: PtexReader.cpp:46
virtual const char * path()=0
Path that file was opened with.
void swapuv()
Swap the u and v resolution values in place.
Definition: Ptexture.h:205
BSpline (equivalent to bi-cubic w/ sharpness=0)
Definition: Ptexture.h:874
virtual void seek(Handle handle, int64_t pos)=0
Seek to an absolute byte position in the input stream.
Res(int8_t ulog2_, int8_t vlog2_)
Constructor.
Definition: Ptexture.h:169
virtual ~PtexMetaData()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:340
Smart-pointer for acquiring and releasing API objects.
Definition: Ptexture.h:955
virtual bool isTiled()=0
True if this data block is tiled.
static const char * MetaDataTypeName(MetaDataType mdt)
Look up name of given meta data type.
Definition: PtexUtils.cpp:81
Signed 16-bit integer.
Definition: Ptexture.h:110
virtual bool isConstant()=0
True if this data block is constant.
int8_t ulog2
log base 2 of u resolution, in texels
Definition: Ptexture.h:162
#define PTEXAPI
Definition: Ptexture.h:58
virtual void getPixel(int u, int v, void *result)=0
Read a single texel from the data block.
static const char * BorderModeName(BorderMode m)
Look up name of given border mode.
Definition: PtexUtils.cpp:63
float sharpness
Filter sharpness, 0..1 (for general bi-cubic filter only).
Definition: Ptexture.h:884
uint16_t & val()
Resolution as a single 16-bit integer value.
Definition: Ptexture.h:184
Right edge, from UV (1,0) to (1,1)
Definition: Ptexture.h:101
Interface for reading data from a ptex file.
Definition: Ptexture.h:439
virtual int numKeys()=0
Query number of meta data entries stored in file.
static bool applyEdits(const char *path, Ptex::String &error)
Apply edits to a file.
Definition: PtexWriter.cpp:242
Pixel resolution of a given texture.
Definition: Ptexture.h:161
Gaussian filter.
Definition: Ptexture.h:872
virtual void setSearchPath(const char *path)=0
Set a search path for finding textures.
virtual Ptex::BorderMode uBorderMode()=0
Mode for filtering texture access beyond mesh border.
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels)=0
Access a single texel from the highest resolution texture .
Res res
Resolution of face.
Definition: Ptexture.h:238
uint8_t adjedges
Adjacent edges, 2 bits per edge.
Definition: Ptexture.h:239
virtual const char * getSearchPath()=0
Query the search path.
Information about a face, as stored in the Ptex file header.
Definition: Ptexture.h:237
virtual bool close(Ptex::String &error)=0
Close the file.
Choose filter options.
Definition: Ptexture.h:880
texel access wraps to other side of face
Definition: Ptexture.h:94
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
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.
Definition: PtexUtils.cpp:107
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)=0
Access resolution and adjacency information about a face.
Double-precision (32-bit) floating point.
Definition: Ptexture.h:113
FilterType
Filter types.
Definition: Ptexture.h:868
Res(uint16_t value)
Constructor from 16-bit integer.
Definition: Ptexture.h:172
bool operator==(const Res &r) const
Comparison operator.
Definition: Ptexture.h:193
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.
Definition: PtexUtils.cpp:118
texel access is clamped to border
Definition: Ptexture.h:92
const char * c_str() const
Definition: Ptexture.h:312
Portable fixed-width integer types.
virtual bool close(Handle handle)=0
Close a file.
virtual void getValue(const char *key, const char *&value)=0
Query the value of a given meta data entry.
void swap(PtexPtr &p)
Swap pointer values.
Definition: Ptexture.h:974
static const char * EdgeIdName(EdgeId eid)
Look up name of given edge ID.
Definition: PtexUtils.cpp:72
void clamp(const Res &r)
Clamp the resolution value against the given value.
Definition: Ptexture.h:208
virtual ~PtexCache()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:637
int __structSize
(for internal use only)
Definition: Ptexture.h:881
bool lerp
Interpolate between mipmap levels.
Definition: Ptexture.h:883
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
EdgeId
Edge IDs used in adjacency data in the Ptex::FaceInfo struct.
Definition: Ptexture.h:99
Custom handler interface for intercepting and redirecting Ptex input stream calls.
Definition: Ptexture.h:585
General bi-cubic filter (uses sharpness option)
Definition: Ptexture.h:873
Interface for filtered sampling of ptex data files.
Definition: Ptexture.h:861
virtual Ptex::Res tileRes()=0
Resolution of each tile in this data block.
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.
Definition: PtexWriter.cpp:186
virtual void purge(PtexTexture *texture)=0
Remove a texture file from the cache.