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 2014 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 #include "PtexExports.h"
45 #include "PtexInt.h"
46 #include "PtexVersion.h"
47 
48 #include <ostream>
49 
50 #if !defined(PTEX_PLATFORM_WINDOWS)
51 # ifndef DOXYGEN
52 # define PTEX_USE_STDSTRING
53 # endif
54 #endif
55 
56 #ifdef DOXYGEN
58 namespace Ptex {
59 #else
61 #endif
62 
66 enum MeshType {
68  mt_quad
69  };
70 
72 enum DataType {
76  dt_float
77 };
78 
82  efm_tanvec
83 };
84 
86 enum BorderMode {
89  m_periodic
90 };
91 
94 enum EdgeId {
98  e_left
99 };
100 
108  mdt_double
109 };
110 
112 PTEXAPI const char* MeshTypeName(MeshType mt);
113 
115 PTEXAPI const char* DataTypeName(DataType dt);
116 
119 
122 
124 PTEXAPI const char* EdgeIdName(EdgeId eid);
125 
128 
130 inline int DataSize(DataType dt) {
131  static const int sizes[] = { 1,2,2,4 };
132  return sizes[dt];
133 }
134 
136 inline float OneValue(DataType dt) {
137  static const float one[] = { 255.f, 65535.f, 1.f, 1.f };
138  return one[dt];
139 }
140 
142 inline float OneValueInv(DataType dt) {
143  static const float one[] = { 1.f/255.f, 1.f/65535.f, 1.f, 1.f };
144  return one[dt];
145 }
146 
148 PTEXAPI void ConvertToFloat(float* dst, const void* src,
149  Ptex::DataType dt, int numChannels);
150 
152 PTEXAPI void ConvertFromFloat(void* dst, const float* src,
153  Ptex::DataType dt, int numChannels);
154 
159 struct Res {
160  int8_t ulog2;
161  int8_t vlog2;
162 
164  Res() : ulog2(0), vlog2(0) {}
165 
167  Res(int8_t ulog2_, int8_t vlog2_) : ulog2(ulog2_), vlog2(vlog2_) {}
168 
170  Res(uint16_t value) : ulog2(int8_t(value&0xff)), vlog2(int8_t((value>>8)&0xff)) {}
171 
173  int u() const { return 1<<(unsigned)ulog2; }
174 
176  int v() const { return 1<<(unsigned)vlog2; }
177 
179  uint16_t val() const { return uint16_t(ulog2 | (vlog2<<8)); }
180 
182  int size() const { return u() * v(); }
183 
185  size_t size64() const { return size_t(u()) * v(); }
186 
188  bool operator==(const Res& r) const { return r.ulog2 == ulog2 && r.vlog2 == vlog2; }
189 
191  bool operator!=(const Res& r) const { return !(r==*this); }
192 
194  bool operator>=(const Res& r) const { return ulog2 >= r.ulog2 && vlog2 >= r.vlog2; }
195 
197  Res swappeduv() const { return Res(vlog2, ulog2); }
198 
200  void swapuv() { *this = swappeduv(); }
201 
203  void clamp(const Res& r) {
204  if (ulog2 > r.ulog2) ulog2 = r.ulog2;
205  if (vlog2 > r.vlog2) vlog2 = r.vlog2;
206  }
207 
209  int ntilesu(Res tileres) const { return 1<<(ulog2-tileres.ulog2); }
210 
212  int ntilesv(Res tileres) const { return 1<<(vlog2-tileres.vlog2); }
213 
215  int ntiles(Res tileres) const { return ntilesu(tileres) * ntilesv(tileres); }
216 };
217 
232 struct FaceInfo {
234  uint8_t adjedges;
235  uint8_t flags;
236  int32_t adjfaces[4];
237 
239  FaceInfo() : res(), adjedges(0), flags(0)
240  {
241  adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
242  }
243 
245  FaceInfo(Res res_) : res(res_), adjedges(0), flags(0)
246  {
247  adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
248  }
249 
251  FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
252  : res(res_), flags(isSubface_ ? flag_subface : 0)
253  {
254  setadjfaces(adjfaces_[0], adjfaces_[1], adjfaces_[2], adjfaces_[3]);
255  setadjedges(adjedges_[0], adjedges_[1], adjedges_[2], adjedges_[3]);
256  }
257 
259  EdgeId adjedge(int eid) const { return EdgeId((adjedges >> (2*eid)) & 3); }
260 
262  int adjface(int eid) const { return adjfaces[eid]; }
263 
265  bool isConstant() const { return (flags & flag_constant) != 0; }
266 
268  bool isNeighborhoodConstant() const { return (flags & flag_nbconstant) != 0; }
269 
271  bool hasEdits() const { return false; }
272 
274  bool isSubface() const { return (flags & flag_subface) != 0; }
275 
277  void setadjfaces(int f0, int f1, int f2, int f3)
278  { adjfaces[0] = f0, adjfaces[1] = f1, adjfaces[2] = f2; adjfaces[3] = f3; }
279 
281  void setadjedges(int e0, int e1, int e2, int e3)
282  { adjedges = (uint8_t)((e0&3) | ((e1&3)<<2) | ((e2&3)<<4) | ((e3&3)<<6)); }
283 
286 };
287 
288 
295 #ifdef PTEX_USE_STDSTRING
296 typedef std::string String;
297 #else
298 class String
299 {
300 public:
301  String() : _str(0) {}
302  String(const String& str) : _str(0) { *this = str; }
303  PTEXAPI ~String();
304  PTEXAPI String& operator=(const char* str);
305  String& operator=(const String& str) { *this = str._str; return *this; }
306  String& operator=(const std::string& str) { *this = str.c_str(); return *this; }
307  const char* c_str() const { return _str ? _str : ""; }
308  bool empty() const { return _str == 0 || _str[0] == '\0'; }
309 
310 private:
311  char* _str;
312 };
313 #endif
314 
316 #ifndef PTEX_USE_STDSTRING
317 PTEXAPI std::ostream& operator << (std::ostream& stream, const Ptex::String& str);
318 #endif
319 
320 
321 #ifdef DOXYGEN
322 } // end namespace Ptex
323 #endif
324 
332  protected:
334  virtual ~PtexMetaData() {}
335 
336  public:
338  virtual void release() = 0;
339 
341  virtual int numKeys() = 0;
342 
344  virtual void getKey(int index, const char*& key, Ptex::MetaDataType& type) = 0;
345 
347  virtual bool findKey(const char* key, int& index, Ptex::MetaDataType& type) = 0;
348 
351  virtual void getValue(const char* key, const char*& value) = 0;
352 
355  virtual void getValue(int index, const char*& value) = 0;
356 
359  virtual void getValue(const char* key, const int8_t*& value, int& count) = 0;
360 
363  virtual void getValue(int index, const int8_t*& value, int& count) = 0;
364 
367  virtual void getValue(const char* key, const int16_t*& value, int& count) = 0;
368 
371  virtual void getValue(int index, const int16_t*& value, int& count) = 0;
372 
375  virtual void getValue(const char* key, const int32_t*& value, int& count) = 0;
376 
379  virtual void getValue(int index, const int32_t*& value, int& count) = 0;
380 
383  virtual void getValue(const char* key, const float*& value, int& count) = 0;
384 
387  virtual void getValue(int index, const float*& value, int& count) = 0;
388 
391  virtual void getValue(const char* key, const double*& value, int& count) = 0;
392 
395  virtual void getValue(int index, const double*& value, int& count) = 0;
396 };
397 
398 
410  protected:
412  virtual ~PtexFaceData() {}
413 
414  public:
416  virtual void release() = 0;
417 
419  virtual bool isConstant() = 0;
420 
424  virtual Ptex::Res res() = 0;
425 
429  virtual void getPixel(int u, int v, void* result) = 0;
430 
437  virtual void* getData() = 0;
438 
441  virtual bool isTiled() = 0;
442 
444  virtual Ptex::Res tileRes() = 0;
445 
447  virtual PtexFaceData* getTile(int tile) = 0;
448 };
449 
450 
460 class PtexTexture {
461  protected:
463  virtual ~PtexTexture() {}
464 
465  public:
477  PTEXAPI static PtexTexture* open(const char* path, Ptex::String& error, bool premultiply=0);
478 
479 
481  virtual void release() = 0;
482 
486  virtual const char* path() = 0;
487 
489  struct Info {
497  int numFaces;
498  };
499  virtual Info getInfo() = 0;
500 
502  virtual Ptex::MeshType meshType() = 0;
503 
505  virtual Ptex::DataType dataType() = 0;
506 
509 
512 
515 
519  virtual int alphaChannel() = 0;
520 
522  virtual int numChannels() = 0;
523 
525  virtual int numFaces() = 0;
526 
528  virtual bool hasEdits() = 0;
529 
531  virtual bool hasMipMaps() = 0;
532 
534  virtual PtexMetaData* getMetaData() = 0;
535 
537  virtual const Ptex::FaceInfo& getFaceInfo(int faceid) = 0;
538 
554  virtual void getData(int faceid, void* buffer, int stride) = 0;
555 
567  virtual void getData(int faceid, void* buffer, int stride, Ptex::Res res) = 0;
568 
570  virtual PtexFaceData* getData(int faceid) = 0;
571 
581  virtual PtexFaceData* getData(int faceid, Ptex::Res res) = 0;
582 
595  virtual void getPixel(int faceid, int u, int v,
596  float* result, int firstchan, int nchannels) = 0;
597 
609  virtual void getPixel(int faceid, int u, int v,
610  float* result, int firstchan, int nchannels,
611  Ptex::Res res) = 0;
612 
617  virtual void* getConstantData(int faceid) = 0;
618 };
619 
620 
629  protected:
630  virtual ~PtexInputHandler() {}
631 
632  public:
633  typedef void* Handle;
634 
639  virtual Handle open(const char* path) = 0;
640 
642  virtual void seek(Handle handle, int64_t pos) = 0;
643 
649  virtual size_t read(void* buffer, size_t size, Handle handle) = 0;
650 
653  virtual bool close(Handle handle) = 0;
654 
656  virtual const char* lastError() = 0;
657 };
658 
659 
668  protected:
669  virtual ~PtexErrorHandler() {}
670 
671  public:
672  virtual void reportError(const char* error) = 0;
673 };
674 
675 
693 class PtexCache {
694  protected:
696  virtual ~PtexCache() {}
697 
698  public:
720  PTEXAPI static PtexCache* create(int maxFiles,
721  size_t maxMem,
722  bool premultiply=false,
723  PtexInputHandler* inputHandler=0,
724  PtexErrorHandler* errorHandler=0);
725 
727  virtual void release() = 0;
728 
734  virtual void setSearchPath(const char* path) = 0;
735 
737  virtual const char* getSearchPath() = 0;
738 
766  virtual PtexTexture* get(const char* path, Ptex::String& error) = 0;
767 
773  virtual void purge(PtexTexture* texture) = 0;
774 
780  virtual void purge(const char* path) = 0;
781 
786  virtual void purgeAll() = 0;
787 
788  struct Stats {
789  uint64_t memUsed;
790  uint64_t peakMemUsed;
791  uint64_t filesOpen;
792  uint64_t peakFilesOpen;
793  uint64_t filesAccessed;
794  uint64_t fileReopens;
795  uint64_t blockReads;
796  };
797 
799  virtual void getStats(Stats& stats) = 0;
800 };
801 
802 
819 class PtexWriter {
820  protected:
822  virtual ~PtexWriter() {}
823 
824  public:
835  PTEXAPI
836  static PtexWriter* open(const char* path,
838  int nchannels, int alphachan, int nfaces,
839  Ptex::String& error, bool genmipmaps=true);
840 
848  PTEXAPI
849  static PtexWriter* edit(const char* path,
851  int nchannels, int alphachan, int nfaces,
852  Ptex::String& error, bool genmipmaps=true);
853 
861  PTEXAPI
862  static PtexWriter* edit(const char* path, bool incremental,
864  int nchannels, int alphachan, int nfaces,
865  Ptex::String& error, bool genmipmaps=true);
866 
869  PTEXAPI
870  static bool applyEdits(const char* path, Ptex::String& error);
871 
873  virtual void release() = 0;
874 
876  virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode) = 0;
877 
879  virtual void setEdgeFilterMode(Ptex::EdgeFilterMode edgeFilterMode) = 0;
880 
882  virtual void writeMeta(const char* key, const char* string) = 0;
883 
885  virtual void writeMeta(const char* key, const int8_t* value, int count) = 0;
886 
888  virtual void writeMeta(const char* key, const int16_t* value, int count) = 0;
889 
891  virtual void writeMeta(const char* key, const int32_t* value, int count) = 0;
892 
894  virtual void writeMeta(const char* key, const float* value, int count) = 0;
895 
897  virtual void writeMeta(const char* key, const double* value, int count) = 0;
898 
900  virtual void writeMeta(PtexMetaData* data) = 0;
901 
913  virtual bool writeFace(int faceid, const Ptex::FaceInfo& info, const void* data, int stride=0) = 0;
914 
920  virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo& info, const void* data) = 0;
921 
925  virtual bool close(Ptex::String& error) = 0;
926 
927 #if NEW_API
928  virtual bool writeFaceReduction(int faceid, const Ptex::Res& res, const void* data, int stride=0) = 0;
929  virtual bool writeConstantFaceReduction(int faceid, const Ptex::Res& res, const void* data) = 0;
930 #endif
931 };
932 
933 
943 class PtexFilter {
944  protected:
946  virtual ~PtexFilter() {}
947 
948  public:
950  enum FilterType {
958  f_mitchell
959  };
960 
962  struct Options {
965  bool lerp;
966  float sharpness;
967  bool noedgeblend;
968 
970  Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0, bool noedgeblend_=0) :
971  __structSize(sizeof(Options)),
972  filter(filter_), lerp(lerp_), sharpness(sharpness_), noedgeblend(noedgeblend_) {}
973  };
974 
975 
976  /* Evaluate a texture using specified filter options
977 
978  The filter region is a parallelogram centered at the given
979  (u,v) coordinate with sides defined by two vectors [uw1, vw1]
980  and [uw2, vw2]. For an axis-aligned rectangle, the vectors
981  are [uw, 0] and [0, vw]. See \link filterfootprint Filter
982  Footprint \endlink for details.
983 
984  @param tx Texture to evaluate
985  @param opts Filter options
986  @param result Buffer to hold filter result. Must be large enough to hold nchannels worth of data.
987  @param firstchan First channel to evaluate [0..tx->numChannels()-1]
988  @param nchannels Number of channels to evaluate
989  @param faceid Face index [0..tx->numFaces()-1]
990  @param u U coordinate, normalized [0..1]
991  @param v V coordinate, normalized [0..1]
992  @param uw1 U filter width 1, normalized [0..1]
993  @param vw1 V filter width 1, normalized [0..1]
994  @param uw2 U filter width 2, normalized [0..1]
995  @param vw2 V filter width 2, normalized [0..1]
996  @param width scale factor for filter width
997  @param blur amount to add to filter width [0..1]
998  */
999  PTEXAPI static void eval(PtexTexture* tx, const Options& opts,
1000  float* result, int firstchan, int nchannels,
1001  int faceid, float u, float v, float uw1, float vw1, float uw2, float vw2,
1002  float width=1, float blur=0);
1003 
1004  /* Construct a filter for the given texture. Deprecated. (use static eval method)
1005  */
1006  PTEXAPI static PtexFilter* getFilter(PtexTexture* tx, const Options& opts);
1007 
1009  virtual void release() = 0;
1010 
1032  virtual void eval(float* result, int firstchan, int nchannels,
1033  int faceid, float u, float v, float uw1, float vw1, float uw2, float vw2,
1034  float width=1, float blur=0) = 0;
1035 };
1036 
1037 
1067 template <class T> class PtexPtr {
1068  T* _ptr;
1069  public:
1071  PtexPtr(T* ptr=0) : _ptr(ptr) {}
1072 
1074  ~PtexPtr() { if (_ptr) _ptr->release(); }
1075 
1077  operator T* () const { return _ptr; }
1078 
1080  T* operator-> () const { return _ptr; }
1081 
1083  T* get() const { return _ptr; }
1084 
1086  void swap(PtexPtr& p)
1087  {
1088  T* tmp = p._ptr;
1089  p._ptr = _ptr;
1090  _ptr = tmp;
1091  }
1092 
1094  void reset(T* ptr=0) {
1095  if (_ptr) _ptr->release();
1096  _ptr = ptr;
1097  }
1098 
1099  private:
1101  PtexPtr(const PtexPtr& p);
1102 
1105 };
1106 
1107 #ifndef DOXYGEN
1108 namespace PtexUtils {}
1109 
1111 
1112 using Ptex::PtexMetaData;
1113 using Ptex::PtexFaceData;
1114 using Ptex::PtexTexture;
1115 using Ptex::PtexInputHandler;
1116 using Ptex::PtexErrorHandler;
1117 using Ptex::PtexCache;
1118 using Ptex::PtexWriter;
1119 using Ptex::PtexFilter;
1120 using Ptex::PtexPtr;
1121 namespace PtexUtils = Ptex::PtexUtils;
1122 
1123 #endif
1124 #endif
Definitions related to exported Ptex API symbol visibility.
#define PTEXAPI
Definition: PtexExports.h:60
Portable fixed-width integer types.
std::ostream & operator<<(std::ostream &stream, const String &str)
Definition: PtexUtils.cpp:692
#define PTEX_NAMESPACE_END
Definition: PtexVersion.h:62
File-handle and memory cache for reading ptex files.
Definition: Ptexture.h:693
virtual void getStats(Stats &stats)=0
Get stats.
virtual const char * getSearchPath()=0
Query the search path.
virtual void release()=0
Release PtexCache. Cache will be immediately destroyed and all resources will be released.
virtual void purge(PtexTexture *texture)=0
Remove a texture file from the cache.
virtual PtexTexture * get(const char *path, Ptex::String &error)=0
Access a texture.
static PtexCache * create(int maxFiles, size_t maxMem, bool premultiply=false, PtexInputHandler *inputHandler=0, PtexErrorHandler *errorHandler=0)
Create a cache with the specified limits.
Definition: PtexCache.cpp:173
virtual void setSearchPath(const char *path)=0
Set a search path for finding textures.
virtual ~PtexCache()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:696
virtual void purgeAll()=0
Remove all texture files from the cache.
virtual void purge(const char *path)=0
Remove a texture file from the cache by pathname.
Custom handler interface redirecting Ptex error messages.
Definition: Ptexture.h:667
virtual void reportError(const char *error)=0
virtual ~PtexErrorHandler()
Definition: Ptexture.h:669
Per-face texture data accessor.
Definition: Ptexture.h:409
virtual bool isTiled()=0
True if this data block is tiled.
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
virtual void * getData()=0
Access the data from this data block.
virtual void getPixel(int u, int v, void *result)=0
Read a single texel from the data block.
virtual PtexFaceData * getTile(int tile)=0
Access a tile from the data block.
virtual Ptex::Res tileRes()=0
Resolution of each tile in this data block.
virtual bool isConstant()=0
True if this data block is constant.
virtual ~PtexFaceData()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:412
virtual Ptex::Res res()=0
Resolution of the texture held by this data block.
Interface for filtered sampling of ptex data files.
Definition: Ptexture.h:943
static PtexFilter * getFilter(PtexTexture *tx, const Options &opts)
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:946
static void eval(PtexTexture *tx, const Options &opts, 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)
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.
FilterType
Filter types.
Definition: Ptexture.h:950
@ f_bicubic
General bi-cubic filter (uses sharpness option)
Definition: Ptexture.h:955
@ f_bspline
BSpline (equivalent to bi-cubic w/ sharpness=0)
Definition: Ptexture.h:956
@ f_bilinear
Bi-linear interpolation.
Definition: Ptexture.h:952
@ f_catmullrom
Catmull-Rom (equivalent to bi-cubic w/ sharpness=1)
Definition: Ptexture.h:957
@ f_mitchell
Mitchell (equivalent to bi-cubic w/ sharpness=2/3)
Definition: Ptexture.h:958
@ f_box
Box filter.
Definition: Ptexture.h:953
@ f_gaussian
Gaussian filter.
Definition: Ptexture.h:954
@ f_point
Point-sampled (no filtering)
Definition: Ptexture.h:951
Custom handler interface for intercepting and redirecting Ptex input stream calls.
Definition: Ptexture.h:628
virtual void seek(Handle handle, int64_t pos)=0
Seek to an absolute byte position in the input stream.
virtual ~PtexInputHandler()
Definition: Ptexture.h:630
virtual size_t read(void *buffer, size_t size, Handle handle)=0
Read a number of bytes from the file.
virtual const char * lastError()=0
Return the last error message encountered.
virtual Handle open(const char *path)=0
Open a file in read mode.
virtual bool close(Handle handle)=0
Close a file.
Meta data accessor.
Definition: Ptexture.h:331
virtual void getValue(int index, const int8_t *&value, int &count)=0
Query the value of a given meta data entry by index.
virtual void getValue(int index, const int32_t *&value, int &count)=0
Query the value of a given meta data entry by index.
virtual void getValue(const char *key, const double *&value, int &count)=0
Query the value of a given meta data entry.
virtual int numKeys()=0
Query number of meta data entries stored in file.
virtual ~PtexMetaData()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:334
virtual void getValue(const char *key, const int8_t *&value, int &count)=0
Query the value of a given meta data entry.
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
virtual void getValue(int index, const double *&value, int &count)=0
Query the value of a given meta data entry by index.
virtual void getValue(const char *key, const int32_t *&value, int &count)=0
Query the value of a given meta data entry.
virtual bool findKey(const char *key, int &index, Ptex::MetaDataType &type)=0
Query the index and type of a meta data entry by name.
virtual void getValue(int index, const int16_t *&value, int &count)=0
Query the value of a given meta data entry by index.
virtual void getValue(const char *key, const float *&value, int &count)=0
Query the value of a given meta data entry.
virtual void getValue(int index, const float *&value, int &count)=0
Query the value of a given meta data entry by index.
virtual void getValue(const char *key, const char *&value)=0
Query the value of a given meta data entry.
virtual void getValue(int index, const char *&value)=0
Query the value of a given meta data entry by index.
virtual void getKey(int index, const char *&key, Ptex::MetaDataType &type)=0
Query the name and type of a meta data entry.
virtual void getValue(const char *key, const int16_t *&value, int &count)=0
Query the value of a given meta data entry.
Smart-pointer for acquiring and releasing API objects.
Definition: Ptexture.h:1067
T * operator->() const
Access members of pointer.
Definition: Ptexture.h:1080
PtexPtr(const PtexPtr &p)
Copying prohibited.
T * get() const
Get pointer value.
Definition: Ptexture.h:1083
PtexPtr(T *ptr=0)
Constructor.
Definition: Ptexture.h:1071
void reset(T *ptr=0)
Deallocate object pointed to, and optionally set to new value.
Definition: Ptexture.h:1094
void operator=(PtexPtr &p)
Assignment prohibited.
~PtexPtr()
Destructor, calls ptr->release().
Definition: Ptexture.h:1074
void swap(PtexPtr &p)
Swap pointer values.
Definition: Ptexture.h:1086
T * _ptr
Definition: Ptexture.h:1068
Interface for reading data from a ptex file.
Definition: Ptexture.h:460
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)=0
Access resolution and adjacency information about a face.
virtual void getData(int faceid, void *buffer, int stride)=0
Access texture data for a face at highest-resolution.
virtual const char * path()=0
Path that file was opened with.
virtual Ptex::MeshType meshType()=0
Type of mesh for which texture data is defined.
virtual Ptex::BorderMode uBorderMode()=0
Mode for filtering texture access beyond mesh border.
virtual ~PtexTexture()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:463
virtual void * getConstantData(int faceid)=0
Access the constant (or average) data value for a given face.
virtual PtexMetaData * getMetaData()=0
Access meta data.
virtual bool hasMipMaps()=0
True if the file has mipmaps.
virtual Info getInfo()=0
virtual int numFaces()=0
Number of faces stored in file.
virtual Ptex::DataType dataType()=0
Type of data stored in file.
virtual void getData(int faceid, void *buffer, int stride, Ptex::Res res)=0
Access texture data for a face at a specific resolution.
virtual int alphaChannel()=0
Index of alpha channel (if any).
virtual Ptex::EdgeFilterMode edgeFilterMode()=0
Mode for filtering textures across edges.
static PtexTexture * open(const char *path, Ptex::String &error, bool premultiply=0)
Open a ptex file for reading.
Definition: PtexReader.cpp:61
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 .
virtual bool hasEdits()=0
Obsolete (returns false).
virtual Ptex::BorderMode vBorderMode()=0
Mode for filtering texture access beyond mesh border.
virtual PtexFaceData * getData(int faceid, Ptex::Res res)=0
Access texture data for a face at a specific resolution as stored on disk.
virtual int numChannels()=0
Number of channels stored in file.
virtual void getPixel(int faceid, int u, int v, float *result, int firstchan, int nchannels, Ptex::Res res)=0
Access a single texel for a face at a particular resolution.
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
virtual PtexFaceData * getData(int faceid)=0
Access texture data for a face at highest-resolution as stored on disk.
Interface for writing data to a ptex file.
Definition: Ptexture.h:819
virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode)=0
Set border modes.
virtual void writeMeta(const char *key, const float *value, int count)=0
Write an array of signed 32-bit floats as meta data.
virtual void setEdgeFilterMode(Ptex::EdgeFilterMode edgeFilterMode)=0
Set edge filter mode.
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
virtual void writeMeta(const char *key, const int8_t *value, int count)=0
Write an array of signed 8-bit integers as meta data.
static bool applyEdits(const char *path, Ptex::String &error)
Obsolete (returns true).
Definition: PtexWriter.cpp:175
virtual void writeMeta(const char *key, const int32_t *value, int count)=0
Write an array of signed 32-bit integers as meta data.
virtual void writeMeta(const char *key, const int16_t *value, int count)=0
Write an array of signed 16-bit integers as meta data.
virtual void writeMeta(const char *key, const char *string)=0
Write a string as meta data.
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.
Definition: PtexWriter.cpp:119
virtual bool close(Ptex::String &error)=0
Close the file.
virtual void writeMeta(const char *key, const double *value, int count)=0
Write an array of signed 32-bit doubles as meta data.
virtual void writeMeta(PtexMetaData *data)=0
Copy meta data from an existing meta data block.
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:100
virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo &info, const void *data)=0
Write constant texture data for a face.
virtual ~PtexWriter()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:822
virtual bool writeFace(int faceid, const Ptex::FaceInfo &info, const void *data, int stride=0)=0
Write texture data for a face.
Memory-managed string.
Definition: Ptexture.h:299
bool empty() const
Definition: Ptexture.h:308
const char * c_str() const
Definition: Ptexture.h:307
char * _str
Definition: Ptexture.h:311
String & operator=(const String &str)
Definition: Ptexture.h:305
String(const String &str)
Definition: Ptexture.h:302
String & operator=(const std::string &str)
Definition: Ptexture.h:306
String & operator=(const char *str)
Definition: PtexUtils.cpp:685
Common data structures and enums used throughout the API.
Definition: Ptexture.h:58
int DataSize(DataType dt)
Look up size of given data type (in bytes).
Definition: Ptexture.h:130
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.
EdgeId
Edge IDs used in adjacency data in the Ptex::FaceInfo struct.
Definition: Ptexture.h:94
@ e_right
Right edge, from UV (1,0) to (1,1)
Definition: Ptexture.h:96
@ e_top
Top edge, from UV (1,1) to (0,1)
Definition: Ptexture.h:97
@ e_left
Left edge, from UV (0,1) to (0,0)
Definition: Ptexture.h:98
@ e_bottom
Bottom edge, from UV (0,0) to (1,0)
Definition: Ptexture.h:95
const char * EdgeIdName(EdgeId eid)
Look up name of given edge ID.
const char * EdgeFilterModeName(EdgeFilterMode m)
Look up name of given edge filter mode.
DataType
Type of data stored in texture file.
Definition: Ptexture.h:72
@ dt_half
Half-precision (16-bit) floating point.
Definition: Ptexture.h:75
@ dt_float
Single-precision (32-bit) floating point.
Definition: Ptexture.h:76
@ dt_uint16
Unsigned, 16-bit integer.
Definition: Ptexture.h:74
@ dt_uint8
Unsigned, 8-bit integer.
Definition: Ptexture.h:73
float OneValue(DataType dt)
Look up value of given data type that corresponds to the normalized value of 1.0.
Definition: Ptexture.h:136
const char * MeshTypeName(MeshType mt)
Look up name of given mesh type.
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:66
@ mt_triangle
Mesh is triangle-based.
Definition: Ptexture.h:67
@ mt_quad
Mesh is quad-based.
Definition: Ptexture.h:68
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:86
@ m_black
texel beyond border are assumed to be black
Definition: Ptexture.h:88
@ m_clamp
texel access is clamped to border
Definition: Ptexture.h:87
@ m_periodic
texel access wraps to other side of face
Definition: Ptexture.h:89
const char * DataTypeName(DataType dt)
Look up name of given data type.
const char * BorderModeName(BorderMode m)
Look up name of given border mode.
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.
MetaDataType
Type of meta data entry.
Definition: Ptexture.h:102
@ mdt_string
Null-terminated string.
Definition: Ptexture.h:103
@ mdt_float
Single-precision (32-bit) floating point.
Definition: Ptexture.h:107
@ mdt_int32
Signed 32-bit integer.
Definition: Ptexture.h:106
@ mdt_int8
Signed 8-bit integer.
Definition: Ptexture.h:104
@ mdt_double
Double-precision (32-bit) floating point.
Definition: Ptexture.h:108
@ mdt_int16
Signed 16-bit integer.
Definition: Ptexture.h:105
EdgeFilterMode
How to handle transformation across edges when filtering.
Definition: Ptexture.h:80
@ efm_none
Don't do anything with the values.
Definition: Ptexture.h:81
@ efm_tanvec
Values are vectors in tangent space; rotate values.
Definition: Ptexture.h:82
const char * MetaDataTypeName(MetaDataType mdt)
Look up name of given meta data type.
float OneValueInv(DataType dt)
Lookup up inverse value of given data type that corresponds to the normalized value of 1....
Definition: Ptexture.h:142
uint64_t filesAccessed
Definition: Ptexture.h:793
uint64_t filesOpen
Definition: Ptexture.h:791
uint64_t peakFilesOpen
Definition: Ptexture.h:792
uint64_t fileReopens
Definition: Ptexture.h:794
uint64_t memUsed
Definition: Ptexture.h:789
uint64_t blockReads
Definition: Ptexture.h:795
uint64_t peakMemUsed
Definition: Ptexture.h:790
Choose filter options.
Definition: Ptexture.h:962
FilterType filter
Filter type.
Definition: Ptexture.h:964
int __structSize
(for internal use only)
Definition: Ptexture.h:963
float sharpness
Filter sharpness, 0..1 (for general bi-cubic filter only).
Definition: Ptexture.h:966
bool lerp
Interpolate between mipmap levels.
Definition: Ptexture.h:965
bool noedgeblend
Disable cross-face filtering. Useful for debugging or rendering on polys.
Definition: Ptexture.h:967
Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0, bool noedgeblend_=0)
Constructor - sets defaults.
Definition: Ptexture.h:970
Get most commonly used info in a single call for convenience / efficiency.
Definition: Ptexture.h:489
BorderMode uBorderMode
Definition: Ptexture.h:492
BorderMode vBorderMode
Definition: Ptexture.h:493
EdgeFilterMode edgeFilterMode
Definition: Ptexture.h:494
DataType dataType
Definition: Ptexture.h:491
MeshType meshType
Definition: Ptexture.h:490
Information about a face, as stored in the Ptex file header.
Definition: Ptexture.h:232
void setadjedges(int e0, int e1, int e2, int e3)
Set the adjedges data.
Definition: Ptexture.h:281
bool hasEdits() const
Obsolete (returns false).
Definition: Ptexture.h:271
bool isNeighborhoodConstant() const
Determine if neighborhood of face is constant (by checking a flag).
Definition: Ptexture.h:268
FaceInfo(Res res_)
Constructor.
Definition: Ptexture.h:245
bool isSubface() const
Determine if face is a subface (by checking a flag).
Definition: Ptexture.h:274
Res res
Resolution of face.
Definition: Ptexture.h:233
EdgeId adjedge(int eid) const
Access an adjacent edge id. The eid value must be 0..3.
Definition: Ptexture.h:259
bool isConstant() const
Determine if face is constant (by checking a flag).
Definition: Ptexture.h:265
uint8_t adjedges
Adjacent edges, 2 bits per edge.
Definition: Ptexture.h:234
int32_t adjfaces[4]
Adjacent faces (-1 == no adjacent face).
Definition: Ptexture.h:236
uint8_t flags
Flags.
Definition: Ptexture.h:235
FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
Constructor.
Definition: Ptexture.h:251
FaceInfo()
Default constructor.
Definition: Ptexture.h:239
void setadjfaces(int f0, int f1, int f2, int f3)
Set the adjfaces data.
Definition: Ptexture.h:277
int adjface(int eid) const
Access an adjacent face id. The eid value must be 0..3.
Definition: Ptexture.h:262
Pixel resolution of a given texture.
Definition: Ptexture.h:159
bool operator>=(const Res &r) const
True if res is >= given res in both u and v directions.
Definition: Ptexture.h:194
int ntilesu(Res tileres) const
Determine the number of tiles in the u direction for the given tile res.
Definition: Ptexture.h:209
bool operator!=(const Res &r) const
Comparison operator.
Definition: Ptexture.h:191
Res(uint16_t value)
Constructor.
Definition: Ptexture.h:170
int8_t ulog2
log base 2 of u resolution, in texels
Definition: Ptexture.h:160
int ntilesv(Res tileres) const
Determine the number of tiles in the v direction for the given tile res.
Definition: Ptexture.h:212
Res()
Default constructor, sets res to 0 (1x1 texel).
Definition: Ptexture.h:164
uint16_t val() const
Resolution as a single 16-bit integer value.
Definition: Ptexture.h:179
int v() const
V resolution in texels.
Definition: Ptexture.h:176
Res swappeduv() const
Get value of resolution with u and v swapped.
Definition: Ptexture.h:197
int size() const
Total size of specified texture in texels (u * v). (deprecated, use size64)
Definition: Ptexture.h:182
size_t size64() const
Total size of specified texture in texels (u * v), allowing arbitrarily large textures.
Definition: Ptexture.h:185
Res(int8_t ulog2_, int8_t vlog2_)
Constructor.
Definition: Ptexture.h:167
void swapuv()
Swap the u and v resolution values in place.
Definition: Ptexture.h:200
void clamp(const Res &r)
Clamp the resolution value against the given value.
Definition: Ptexture.h:203
int ntiles(Res tileres) const
Determine the total number of tiles for the given tile res.
Definition: Ptexture.h:215
int u() const
U resolution in texels.
Definition: Ptexture.h:173
int8_t vlog2
log base 2 of v resolution, in texels
Definition: Ptexture.h:161
bool operator==(const Res &r) const
Comparison operator.
Definition: Ptexture.h:188