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 #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 #include "PtexVersion.h"
69 #ifdef DOXYGEN
70
71 namespace Ptex {
72 #else
73 PTEX_NAMESPACE_BEGIN
74 #endif
75
79 enum MeshType {
80 mt_triangle,
81 mt_quad
82 };
83
85 enum DataType {
86 dt_uint8,
87 dt_uint16,
88 dt_half,
89 dt_float
90 };
91
93 enum EdgeFilterMode {
94 efm_none,
95 efm_tanvec
96 };
97
99 enum BorderMode {
100 m_clamp,
101 m_black,
102 m_periodic
103 };
104
107 enum EdgeId {
108 e_bottom,
109 e_right,
110 e_top,
111 e_left
112 };
113
115 enum MetaDataType {
116 mdt_string,
117 mdt_int8,
118 mdt_int16,
119 mdt_int32,
120 mdt_float,
121 mdt_double
122 };
123
125 PTEXAPI const char* MeshTypeName(MeshType mt);
126
128 PTEXAPI const char* DataTypeName(DataType dt);
129
131 PTEXAPI const char* BorderModeName(BorderMode m);
132
134 PTEXAPI const char* EdgeFilterModeName(EdgeFilterMode m);
135
137 PTEXAPI const char* EdgeIdName(EdgeId eid);
138
140 PTEXAPI const char* MetaDataTypeName(MetaDataType mdt);
141
143 inline int DataSize(DataType dt) {
144 static const int sizes[] = { 1,2,2,4 };
145 return sizes[dt];
146 }
147
149 inline float OneValue(DataType dt) {
150 static const float one[] = { 255.f, 65535.f, 1.f, 1.f };
151 return one[dt];
152 }
153
155 inline float OneValueInv(DataType dt) {
156 static const float one[] = { 1.f/255.f, 1.f/65535.f, 1.f, 1.f };
157 return one[dt];
158 }
159
161 PTEXAPI void ConvertToFloat(float* dst, const void* src,
162 Ptex::DataType dt, int numChannels);
163
165 PTEXAPI void ConvertFromFloat(void* dst, const float* src,
166 Ptex::DataType dt, int numChannels);
167
172 struct Res {
173 int8_t ulog2;
174 int8_t vlog2;
175
177 Res() : ulog2(0), vlog2(0) {}
178
180 Res(int8_t ulog2_, int8_t vlog2_) : ulog2(ulog2_), vlog2(vlog2_) {}
181
183 Res(uint16_t value) : ulog2(int8_t(value&0xff)), vlog2(int8_t((value>>8)&0xff)) {}
184
186 int u() const { return 1<<(unsigned)ulog2; }
187
189 int v() const { return 1<<(unsigned)vlog2; }
190
192 uint16_t val() const { return uint16_t(ulog2 | (vlog2<<8)); }
193
195 int size() const { return u() * v(); }
196
198 bool operator==(const Res& r) const { return r.ulog2 == ulog2 && r.vlog2 == vlog2; }
199
201 bool operator!=(const Res& r) const { return !(r==*this); }
202
204 bool operator>=(const Res& r) const { return ulog2 >= r.ulog2 && vlog2 >= r.vlog2; }
205
207 Res swappeduv() const { return Res(vlog2, ulog2); }
208
210 void swapuv() { *this = swappeduv(); }
211
213 void clamp(const Res& r) {
214 if (ulog2 > r.ulog2) ulog2 = r.ulog2;
215 if (vlog2 > r.vlog2) vlog2 = r.vlog2;
216 }
217
219 int ntilesu(Res tileres) const { return 1<<(ulog2-tileres.ulog2); }
220
222 int ntilesv(Res tileres) const { return 1<<(vlog2-tileres.vlog2); }
223
225 int ntiles(Res tileres) const { return ntilesu(tileres) * ntilesv(tileres); }
226 };
227
242 struct FaceInfo {
243 Res res;
244 uint8_t adjedges;
245 uint8_t flags;
246 int32_t adjfaces[4];
247
249 FaceInfo() : res(), adjedges(0), flags(0)
250 {
251 adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
252 }
253
255 FaceInfo(Res res_) : res(res_), adjedges(0), flags(0)
256 {
257 adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
258 }
259
261 FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
262 : res(res_), flags(isSubface_ ? flag_subface : 0)
263 {
264 setadjfaces(adjfaces_[0], adjfaces_[1], adjfaces_[2], adjfaces_[3]);
265 setadjedges(adjedges_[0], adjedges_[1], adjedges_[2], adjedges_[3]);
266 }
267
269 EdgeId adjedge(int eid) const { return EdgeId((adjedges >> (2*eid)) & 3); }
270
272 int adjface(int eid) const { return adjfaces[eid]; }
273
275 bool isConstant() const { return (flags & flag_constant) != 0; }
276
278 bool isNeighborhoodConstant() const { return (flags & flag_nbconstant) != 0; }
279
281 bool hasEdits() const { return (flags & flag_hasedits) != 0; }
282
284 bool isSubface() const { return (flags & flag_subface) != 0; }
285
287 void setadjfaces(int f0, int f1, int f2, int f3)
288 { adjfaces[0] = f0, adjfaces[1] = f1, adjfaces[2] = f2; adjfaces[3] = f3; }
289
291 void setadjedges(int e0, int e1, int e2, int e3)
292 { adjedges = (uint8_t)((e0&3) | ((e1&3)<<2) | ((e2&3)<<4) | ((e3&3)<<6)); }
293
295 enum { flag_constant = 1, flag_hasedits = 2, flag_nbconstant = 4, flag_subface = 8 };
296 };
297
298
305 #ifdef PTEX_USE_STDSTRING
306 typedef std::string String;
307 #else
308 class String
309 {
310 public:
311 String() : _str(0) {}
312 String(const String& str) : _str(0) { *this = str; }
313 PTEXAPI ~String();
314 PTEXAPI String& operator=(const char* str);
315 String& operator=(const String& str) { *this = str._str; return *this; }
316 String& operator=(const std::string& str) { *this = str.c_str(); return *this; }
317 const char* c_str() const { return _str ? _str : ""; }
318 bool empty() const { return _str == 0 || _str[0] == '\0'; }
319
320 private:
321 char* _str;
322 };
323 #endif
324
326 #ifndef PTEX_USE_STDSTRING
327 std::ostream& operator << (std::ostream& stream, const Ptex::String& str);
328 #endif
329
330
331 #ifdef DOXYGEN
332 } // end namespace Ptex
333 #endif
334
341 class PtexMetaData {
342 protected:
344 virtual ~PtexMetaData() {}
345
346 public:
348 virtual void release() = 0;
349
351 virtual int numKeys() = 0;
352
354 virtual void getKey(int index, const char*& key, Ptex::MetaDataType& type) = 0;
355
357 virtual bool findKey(const char* key, int& index, Ptex::MetaDataType& type) = 0;
358
361 virtual void getValue(const char* key, const char*& value) = 0;
362
365 virtual void getValue(int index, const char*& value) = 0;
366
369 virtual void getValue(const char* key, const int8_t*& value, int& count) = 0;
370
373 virtual void getValue(int index, const int8_t*& value, int& count) = 0;
374
377 virtual void getValue(const char* key, const int16_t*& value, int& count) = 0;
378
381 virtual void getValue(int index, const int16_t*& value, int& count) = 0;
382
385 virtual void getValue(const char* key, const int32_t*& value, int& count) = 0;
386
389 virtual void getValue(int index, const int32_t*& value, int& count) = 0;
390
393 virtual void getValue(const char* key, const float*& value, int& count) = 0;
394
397 virtual void getValue(int index, const float*& value, int& count) = 0;
398
401 virtual void getValue(const char* key, const double*& value, int& count) = 0;
402
405 virtual void getValue(int index, const double*& value, int& count) = 0;
406 };
407
408
419 class PtexFaceData {
420 protected:
422 virtual ~PtexFaceData() {}
423
424 public:
426 virtual void release() = 0;
427
429 virtual bool isConstant() = 0;
430
434 virtual Ptex::Res res() = 0;
435
439 virtual void getPixel(int u, int v, void* result) = 0;
440
447 virtual void* getData() = 0;
448
451 virtual bool isTiled() = 0;
452
454 virtual Ptex::Res tileRes() = 0;
455
457 virtual PtexFaceData* getTile(int tile) = 0;
458 };
459
460
470 class PtexTexture {
471 protected:
473 virtual ~PtexTexture() {}
474
475 public:
487 PTEXAPI static PtexTexture* open(const char* path, Ptex::String& error, bool premultiply=0);
488
489
491 virtual void release() = 0;
492
496 virtual const char* path() = 0;
497
499 struct Info {
500 MeshType meshType;
501 DataType dataType;
502 BorderMode uBorderMode;
503 BorderMode vBorderMode;
504 EdgeFilterMode edgeFilterMode;
505 int alphaChannel;
506 int numChannels;
507 int numFaces;
508 };
509 virtual Info getInfo() = 0;
510
512 virtual Ptex::MeshType meshType() = 0;
513
515 virtual Ptex::DataType dataType() = 0;
516
518 virtual Ptex::BorderMode uBorderMode() = 0;
519
521 virtual Ptex::BorderMode vBorderMode() = 0;
522
524 virtual Ptex::EdgeFilterMode edgeFilterMode() = 0;
525
529 virtual int alphaChannel() = 0;
530
532 virtual int numChannels() = 0;
533
535 virtual int numFaces() = 0;
536
538 virtual bool hasEdits() = 0;
539
541 virtual bool hasMipMaps() = 0;
542
544 virtual PtexMetaData* getMetaData() = 0;
545
547 virtual const Ptex::FaceInfo& getFaceInfo(int faceid) = 0;
548
564 virtual void getData(int faceid, void* buffer, int stride) = 0;
565
577 virtual void getData(int faceid, void* buffer, int stride, Ptex::Res res) = 0;
578
580 virtual PtexFaceData* getData(int faceid) = 0;
581
591 virtual PtexFaceData* getData(int faceid, Ptex::Res res) = 0;
592
605 virtual void getPixel(int faceid, int u, int v,
606 float* result, int firstchan, int nchannels) = 0;
607
619 virtual void getPixel(int faceid, int u, int v,
620 float* result, int firstchan, int nchannels,
621 Ptex::Res res) = 0;
622 };
623
624
632 class PtexInputHandler {
633 protected:
634 virtual ~PtexInputHandler() {}
635
636 public:
637 typedef void* Handle;
638
643 virtual Handle open(const char* path) = 0;
644
646 virtual void seek(Handle handle, int64_t pos) = 0;
647
653 virtual size_t read(void* buffer, size_t size, Handle handle) = 0;
654
657 virtual bool close(Handle handle) = 0;
658
660 virtual const char* lastError() = 0;
661 };
662
663
671 class PtexErrorHandler {
672 protected:
673 virtual ~PtexErrorHandler() {}
674
675 public:
676 virtual void reportError(const char* error) = 0;
677 };
678
679
697 class PtexCache {
698 protected:
700 virtual ~PtexCache() {}
701
702 public:
724 PTEXAPI static PtexCache* create(int maxFiles,
725 size_t maxMem,
726 bool premultiply=false,
727 PtexInputHandler* inputHandler=0,
728 PtexErrorHandler* errorHandler=0);
729
731 virtual void release() = 0;
732
738 virtual void setSearchPath(const char* path) = 0;
739
741 virtual const char* getSearchPath() = 0;
742
770 virtual PtexTexture* get(const char* path, Ptex::String& error) = 0;
771
777 virtual void purge(PtexTexture* texture) = 0;
778
784 virtual void purge(const char* path) = 0;
785
790 virtual void purgeAll() = 0;
791
792 struct Stats {
793 uint64_t memUsed;
794 uint64_t peakMemUsed;
795 uint64_t filesOpen;
796 uint64_t peakFilesOpen;
797 uint64_t filesAccessed;
798 uint64_t fileReopens;
799 uint64_t blockReads;
800 };
801
803 virtual void getStats(Stats& stats) = 0;
804 };
805
806
823 class PtexWriter {
824 protected:
826 virtual ~PtexWriter() {}
827
828 public:
839 PTEXAPI
840 static PtexWriter* open(const char* path,
841 Ptex::MeshType mt, Ptex::DataType dt,
842 int nchannels, int alphachan, int nfaces,
843 Ptex::String& error, bool genmipmaps=true);
844
862 PTEXAPI
863 static PtexWriter* edit(const char* path, bool incremental,
864 Ptex::MeshType mt, Ptex::DataType dt,
865 int nchannels, int alphachan, int nfaces,
866 Ptex::String& error, bool genmipmaps=true);
867
876 PTEXAPI
877 static bool applyEdits(const char* path, Ptex::String& error);
878
880 virtual void release() = 0;
881
883 virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode) = 0;
884
886 virtual void setEdgeFilterMode(Ptex::EdgeFilterMode edgeFilterMode) = 0;
887
889 virtual void writeMeta(const char* key, const char* string) = 0;
890
892 virtual void writeMeta(const char* key, const int8_t* value, int count) = 0;
893
895 virtual void writeMeta(const char* key, const int16_t* value, int count) = 0;
896
898 virtual void writeMeta(const char* key, const int32_t* value, int count) = 0;
899
901 virtual void writeMeta(const char* key, const float* value, int count) = 0;
902
904 virtual void writeMeta(const char* key, const double* value, int count) = 0;
905
907 virtual void writeMeta(PtexMetaData* data) = 0;
908
920 virtual bool writeFace(int faceid, const Ptex::FaceInfo& info, const void* data, int stride=0) = 0;
921
927 virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo& info, const void* data) = 0;
928
932 virtual bool close(Ptex::String& error) = 0;
933
934 #if NEW_API
935 virtual bool writeFaceReduction(int faceid, const Ptex::Res& res, const void* data, int stride=0) = 0;
936 virtual bool writeConstantFaceReduction(int faceid, const Ptex::Res& res, const void* data) = 0;
937 #endif
938 };
939
940
950 class PtexFilter {
951 protected:
953 virtual ~PtexFilter() {}
954
955 public:
957 enum FilterType {
958 f_point,
959 f_bilinear,
960 f_box,
961 f_gaussian,
962 f_bicubic,
963 f_bspline,
964 f_catmullrom,
965 f_mitchell
966 };
967
969 struct Options {
970 int __structSize;
971 FilterType filter;
972 bool lerp;
973 float sharpness;
974 bool noedgeblend;
975
977 Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0, bool noedgeblend_=0) :
978 __structSize(sizeof(Options)),
979 filter(filter_), lerp(lerp_), sharpness(sharpness_), noedgeblend(noedgeblend_) {}
980 };
981
982 /* Construct a filter for the given texture.
983 */
984 PTEXAPI static PtexFilter* getFilter(PtexTexture* tx, const Options& opts);
985
987 virtual void release() = 0;
988
1010 virtual void eval(float* result, int firstchan, int nchannels,
1011 int faceid, float u, float v, float uw1, float vw1, float uw2, float vw2,
1012 float width=1, float blur=0) = 0;
1013 };
1014
1015
1045 template <class T> class PtexPtr {
1046 T* _ptr;
1047 public:
1049 PtexPtr(T* ptr=0) : _ptr(ptr) {}
1050
1052 ~PtexPtr() { if (_ptr) _ptr->release(); }
1053
1055 operator T* () const { return _ptr; }
1056
1058 T* operator-> () const { return _ptr; }
1059
1061 T* get() const { return _ptr; }
1062
1064 void swap(PtexPtr& p)
1065 {
1066 T* tmp = p._ptr;
1067 p._ptr = _ptr;
1068 _ptr = tmp;
1069 }
1070
1072 void reset(T* ptr=0) {
1073 if (_ptr) _ptr->release();
1074 _ptr = ptr;
1075 }
1076
1077 private:
1079 PtexPtr(const PtexPtr& p);
1080
1082 void operator= (PtexPtr& p);
1083 };
1084
1085 #ifndef DOXYGEN
1086 namespace PtexUtils {}
1087
1088 PTEX_NAMESPACE_END
1089
1090 using Ptex::PtexMetaData;
1091 using Ptex::PtexFaceData;
1092 using Ptex::PtexTexture;
1093 using Ptex::PtexInputHandler;
1094 using Ptex::PtexErrorHandler;
1095 using Ptex::PtexCache;
1096 using Ptex::PtexWriter;
1097 using Ptex::PtexFilter;
1098 using Ptex::PtexPtr;
1099 namespace PtexUtils = Ptex::PtexUtils;
1100
1101 #endif
1102 #endif
Ptex::Res::v
int v() const
V resolution in texels.
Definition: Ptexture.h:189
PtexTexture::Info::edgeFilterMode
EdgeFilterMode edgeFilterMode
Definition: Ptexture.h:504
PtexPtr::PtexPtr
PtexPtr(T *ptr=0)
Constructor.
Definition: Ptexture.h:1049
PtexTexture::vBorderMode
virtual Ptex::BorderMode vBorderMode()=0
Mode for filtering texture access beyond mesh border.
Ptex::mdt_int32
Signed 32-bit integer.
Definition: Ptexture.h:119
PtexTexture::Info::dataType
DataType dataType
Definition: Ptexture.h:501
Ptex::FaceInfo::FaceInfo
FaceInfo()
Default constructor.
Definition: Ptexture.h:249
PtexTexture::numChannels
virtual int numChannels()=0
Number of channels stored in file.
PtexWriter
Interface for writing data to a ptex file.
Definition: Ptexture.h:823
Ptex::Res::operator==
bool operator==(const Res &r) const
Comparison operator.
Definition: Ptexture.h:198
Ptex::FaceInfo::setadjedges
void setadjedges(int e0, int e1, int e2, int e3)
Set the adjedges data.
Definition: Ptexture.h:291
Ptex::dt_half
Half-precision (16-bit) floating point.
Definition: Ptexture.h:88
Ptex::efm_none
Don&#39;t do anything with the values.
Definition: Ptexture.h:94
PtexFilter::f_box
Box filter.
Definition: Ptexture.h:960
PtexWriter::setBorderModes
virtual void setBorderModes(Ptex::BorderMode uBorderMode, Ptex::BorderMode vBorderMode)=0
Set border modes.
Ptex::String::operator=
String & operator=(const char *str)
Definition: PtexUtils.cpp:679
Ptex::Res::ntilesv
int ntilesv(Res tileres) const
Determine the number of tiles in the v direction for the given tile res.
Definition: Ptexture.h:222
PtexCache::Stats::peakMemUsed
uint64_t peakMemUsed
Definition: Ptexture.h:794
Ptex::String
Memory-managed string.
Definition: Ptexture.h:308
PtexTexture::hasEdits
virtual bool hasEdits()=0
True if the file has edit blocks.
PtexFilter::Options::noedgeblend
bool noedgeblend
Disable cross-face filtering. Useful for debugging or rendering on polys.
Definition: Ptexture.h:974
Ptex::Res::size
int size() const
Total size of specified texture in texels (u * v).
Definition: Ptexture.h:195
PtexTexture::Info::vBorderMode
BorderMode vBorderMode
Definition: Ptexture.h:503
PtexPtr::reset
void reset(T *ptr=0)
Deallocate object pointed to, and optionally set to new value.
Definition: Ptexture.h:1072
Ptex::ConvertFromFloat
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.
Ptex::FaceInfo::FaceInfo
FaceInfo(Res res_)
Constructor.
Definition: Ptexture.h:255
Ptex::m_clamp
texel access is clamped to border
Definition: Ptexture.h:100
Ptex::e_top
Top edge, from UV (1,1) to (0,1)
Definition: Ptexture.h:110
PtexMetaData
Meta data accessor.
Definition: Ptexture.h:341
PtexPtr::_ptr
T * _ptr
Definition: Ptexture.h:1046
Ptex::FaceInfo::flags
uint8_t flags
Flags.
Definition: Ptexture.h:245
PtexFilter::getFilter
static PtexFilter * getFilter(PtexTexture *tx, const Options &opts)
Definition: PtexFilters.cpp:419
Ptex::FaceInfo::isSubface
bool isSubface() const
Determine if face is a subface (by checking a flag).
Definition: Ptexture.h:284
PtexTexture::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexCache
File-handle and memory cache for reading ptex files.
Definition: Ptexture.h:697
PtexFilter::eval
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.
Ptex::dt_float
Single-precision (32-bit) floating point.
Definition: Ptexture.h:89
Ptex::mdt_int8
Signed 8-bit integer.
Definition: Ptexture.h:117
Ptex::DataTypeName
const char * DataTypeName(DataType dt)
Look up name of given data type.
PtexPtr::operator=
void operator=(PtexPtr &p)
Assignment prohibited.
PtexPtr::operator->
T * operator->() const
Access members of pointer.
Definition: Ptexture.h:1058
PtexCache::getStats
virtual void getStats(Stats &stats)=0
Get stats.
PtexFilter::f_bilinear
Bi-linear interpolation.
Definition: Ptexture.h:959
PtexCache::Stats::memUsed
uint64_t memUsed
Definition: Ptexture.h:793
Ptex::EdgeFilterMode
EdgeFilterMode
How to handle transformation across edges when filtering.
Definition: Ptexture.h:93
PtexTexture::Info
Get most commonly used info in a single call for convenience / efficiency.
Definition: Ptexture.h:499
PtexCache::release
virtual void release()=0
Release PtexCache. Cache will be immediately destroyed and all resources will be released.
PtexInputHandler::open
virtual Handle open(const char *path)=0
Open a file in read mode.
PtexTexture::alphaChannel
virtual int alphaChannel()=0
Index of alpha channel (if any).
PtexTexture::getMetaData
virtual PtexMetaData * getMetaData()=0
Access meta data.
PtexWriter::open
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:167
Ptex::Res::val
uint16_t val() const
Resolution as a single 16-bit integer value.
Definition: Ptexture.h:192
PtexMetaData::findKey
virtual bool findKey(const char *key, int &index, Ptex::MetaDataType &type)=0
Query the index and type of a meta data entry by name.
Ptex::FaceInfo::flag_hasedits
Definition: Ptexture.h:295
Ptex::m_black
texel beyond border are assumed to be black
Definition: Ptexture.h:101
Ptex::FaceInfo::flag_nbconstant
Definition: Ptexture.h:295
Ptex::String::c_str
const char * c_str() const
Definition: Ptexture.h:317
PtexFaceData::~PtexFaceData
virtual ~PtexFaceData()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:422
Ptex::mdt_double
Double-precision (32-bit) floating point.
Definition: Ptexture.h:121
Ptex::EdgeId
EdgeId
Edge IDs used in adjacency data in the Ptex::FaceInfo struct.
Definition: Ptexture.h:107
Ptex::efm_tanvec
Values are vectors in tangent space; rotate values.
Definition: Ptexture.h:95
PtexInputHandler::read
virtual size_t read(void *buffer, size_t size, Handle handle)=0
Read a number of bytes from the file.
Ptex::String::String
String()
Definition: Ptexture.h:311
PtexErrorHandler::reportError
virtual void reportError(const char *error)=0
Ptex::FaceInfo::adjfaces
int32_t adjfaces[4]
Adjacent faces (-1 == no adjacent face).
Definition: Ptexture.h:246
PtexTexture::meshType
virtual Ptex::MeshType meshType()=0
Type of mesh for which texture data is defined.
PtexFaceData::res
virtual Ptex::Res res()=0
Resolution of the texture held by this data block.
PtexWriter::~PtexWriter
virtual ~PtexWriter()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:826
Ptex::String::_str
char * _str
Definition: Ptexture.h:321
PtexFaceData
Per-face texture data accessor.
Definition: Ptexture.h:419
PtexWriter::writeConstantFace
virtual bool writeConstantFace(int faceid, const Ptex::FaceInfo &info, const void *data)=0
Write constant texture data for a face.
PtexErrorHandler
Custom handler interface redirecting Ptex error messages.
Definition: Ptexture.h:671
PtexFaceData::getData
virtual void * getData()=0
Access the data from this data block.
Ptex::Res::vlog2
int8_t vlog2
log base 2 of v resolution, in texels
Definition: Ptexture.h:174
PtexTexture::open
static PtexTexture * open(const char *path, Ptex::String &error, bool premultiply=0)
Open a ptex file for reading.
Definition: PtexReader.cpp:59
Ptex::FaceInfo::adjface
int adjface(int eid) const
Access an adjacent face id. The eid value must be 0..3.
Definition: Ptexture.h:272
Ptex::dt_uint8
Unsigned, 8-bit integer.
Definition: Ptexture.h:86
PtexWriter::writeMeta
virtual void writeMeta(const char *key, const char *string)=0
Write a string as meta data.
PtexFaceData::getTile
virtual PtexFaceData * getTile(int tile)=0
Access a tile from the data block.
PtexUtils
Definition: PtexUtils.cpp:139
PtexCache::Stats::filesOpen
uint64_t filesOpen
Definition: Ptexture.h:795
PtexInputHandler::~PtexInputHandler
virtual ~PtexInputHandler()
Definition: Ptexture.h:634
Ptex::MeshType
MeshType
Type of base mesh for which the textures are defined.
Definition: Ptexture.h:79
PtexTexture::getData
virtual void getData(int faceid, void *buffer, int stride)=0
Access texture data for a face at highest-resolution.
Ptex::dt_uint16
Unsigned, 16-bit integer.
Definition: Ptexture.h:87
Ptex::Res::u
int u() const
U resolution in texels.
Definition: Ptexture.h:186
Ptex::Res::ntilesu
int ntilesu(Res tileres) const
Determine the number of tiles in the u direction for the given tile res.
Definition: Ptexture.h:219
PtexTexture::Info::numChannels
int numChannels
Definition: Ptexture.h:506
Ptex::FaceInfo::isConstant
bool isConstant() const
Determine if face is constant (by checking a flag).
Definition: Ptexture.h:275
PtexTexture::hasMipMaps
virtual bool hasMipMaps()=0
True if the file has mipmaps.
Ptex::EdgeIdName
const char * EdgeIdName(EdgeId eid)
Look up name of given edge ID.
Ptex::BorderMode
BorderMode
How to handle mesh border when filtering.
Definition: Ptexture.h:99
Ptex::String::operator=
String & operator=(const String &str)
Definition: Ptexture.h:315
PtexFilter::Options::Options
Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0, bool noedgeblend_=0)
Constructor - sets defaults.
Definition: Ptexture.h:977
PtexCache::purgeAll
virtual void purgeAll()=0
Remove all texture files from the cache.
PtexFaceData::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexFilter::~PtexFilter
virtual ~PtexFilter()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:953
PtexTexture::numFaces
virtual int numFaces()=0
Number of faces stored in file.
Ptex
Common data structures and enums used throughout the API.
Definition: Ptexture.h:71
PtexPtr::~PtexPtr
~PtexPtr()
Destructor, calls ptr->release().
Definition: Ptexture.h:1052
PtexWriter::setEdgeFilterMode
virtual void setEdgeFilterMode(Ptex::EdgeFilterMode edgeFilterMode)=0
Set edge filter mode.
Ptex::mt_triangle
Mesh is triangle-based.
Definition: Ptexture.h:80
PtexWriter::writeFace
virtual bool writeFace(int faceid, const Ptex::FaceInfo &info, const void *data, int stride=0)=0
Write texture data for a face.
PtexFilter::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexInputHandler::lastError
virtual const char * lastError()=0
Return the last error message encountered.
PtexInputHandler::Handle
void * Handle
Definition: Ptexture.h:637
PtexCache::Stats::blockReads
uint64_t blockReads
Definition: Ptexture.h:799
PtexTexture::Info::meshType
MeshType meshType
Definition: Ptexture.h:500
Ptex::Res::operator>=
bool operator>=(const Res &r) const
True if res is >= given res in both u and v directions.
Definition: Ptexture.h:204
PtexFilter::f_mitchell
Mitchell (equivalent to bi-cubic w/ sharpness=2/3)
Definition: Ptexture.h:965
PtexFilter::f_point
Point-sampled (no filtering)
Definition: Ptexture.h:958
PtexCache::Stats
Definition: Ptexture.h:792
PtexTexture::~PtexTexture
virtual ~PtexTexture()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:473
PtexTexture::Info::alphaChannel
int alphaChannel
Definition: Ptexture.h:505
PtexVersion.h
Ptex::String::String
String(const String &str)
Definition: Ptexture.h:312
PtexCache::Stats::filesAccessed
uint64_t filesAccessed
Definition: Ptexture.h:797
Ptex::e_right
Right edge, from UV (1,0) to (1,1)
Definition: Ptexture.h:109
Ptex::e_bottom
Bottom edge, from UV (0,0) to (1,0)
Definition: Ptexture.h:108
PtexFilter::Options::filter
FilterType filter
Filter type.
Definition: Ptexture.h:971
Ptex::FaceInfo::FaceInfo
FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
Constructor.
Definition: Ptexture.h:261
PtexMetaData::getKey
virtual void getKey(int index, const char *&key, Ptex::MetaDataType &type)=0
Query the name and type of a meta data entry.
Ptex::FaceInfo::setadjfaces
void setadjfaces(int f0, int f1, int f2, int f3)
Set the adjfaces data.
Definition: Ptexture.h:287
Ptex::String::operator=
String & operator=(const std::string &str)
Definition: Ptexture.h:316
Ptex::OneValueInv
float OneValueInv(DataType dt)
Lookup up inverse value of given data type that corresponds to the normalized value of 1...
Definition: Ptexture.h:155
Ptex::Res::swappeduv
Res swappeduv() const
Get value of resolution with u and v swapped.
Definition: Ptexture.h:207
PtexFilter::f_catmullrom
Catmull-Rom (equivalent to bi-cubic w/ sharpness=1)
Definition: Ptexture.h:964
PtexTexture::dataType
virtual Ptex::DataType dataType()=0
Type of data stored in file.
Ptex::Res::Res
Res()
Default constructor, sets res to 0 (1x1 texel).
Definition: Ptexture.h:177
PtexTexture::path
virtual const char * path()=0
Path that file was opened with.
Ptex::Res::swapuv
void swapuv()
Swap the u and v resolution values in place.
Definition: Ptexture.h:210
PtexFilter::f_bspline
BSpline (equivalent to bi-cubic w/ sharpness=0)
Definition: Ptexture.h:963
PtexInputHandler::seek
virtual void seek(Handle handle, int64_t pos)=0
Seek to an absolute byte position in the input stream.
Ptex::Res::Res
Res(int8_t ulog2_, int8_t vlog2_)
Constructor.
Definition: Ptexture.h:180
PtexMetaData::~PtexMetaData
virtual ~PtexMetaData()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:344
PtexPtr
Smart-pointer for acquiring and releasing API objects.
Definition: Ptexture.h:1045
PtexFaceData::isTiled
virtual bool isTiled()=0
True if this data block is tiled.
Ptex::mdt_string
Null-terminated string.
Definition: Ptexture.h:116
PtexFaceData::isConstant
virtual bool isConstant()=0
True if this data block is constant.
PtexTexture::edgeFilterMode
virtual Ptex::EdgeFilterMode edgeFilterMode()=0
Mode for filtering textures across edges.
Ptex::Res::ulog2
int8_t ulog2
log base 2 of u resolution, in texels
Definition: Ptexture.h:173
PTEXAPI
#define PTEXAPI
Definition: Ptexture.h:58
PtexFaceData::getPixel
virtual void getPixel(int u, int v, void *result)=0
Read a single texel from the data block.
Ptex::MeshTypeName
const char * MeshTypeName(MeshType mt)
Look up name of given mesh type.
Ptex::FaceInfo::flag_constant
Definition: Ptexture.h:295
PtexFilter::Options::sharpness
float sharpness
Filter sharpness, 0..1 (for general bi-cubic filter only).
Definition: Ptexture.h:973
PtexTexture
Interface for reading data from a ptex file.
Definition: Ptexture.h:470
PtexCache::create
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:177
Ptex::m_periodic
texel access wraps to other side of face
Definition: Ptexture.h:102
PtexMetaData::numKeys
virtual int numKeys()=0
Query number of meta data entries stored in file.
PtexTexture::getInfo
virtual Info getInfo()=0
PtexWriter::applyEdits
static bool applyEdits(const char *path, Ptex::String &error)
Apply edits to a file.
Definition: PtexWriter.cpp:242
Ptex::FaceInfo::isNeighborhoodConstant
bool isNeighborhoodConstant() const
Determine if neighborhood of face is constant (by checking a flag).
Definition: Ptexture.h:278
PtexErrorHandler::~PtexErrorHandler
virtual ~PtexErrorHandler()
Definition: Ptexture.h:673
Ptex::Res
Pixel resolution of a given texture.
Definition: Ptexture.h:172
PtexFilter::f_gaussian
Gaussian filter.
Definition: Ptexture.h:961
Ptex::String::~String
~String()
Definition: PtexUtils.cpp:673
Ptex::e_left
Left edge, from UV (0,1) to (0,0)
Definition: Ptexture.h:111
Ptex::String::empty
bool empty() const
Definition: Ptexture.h:318
Ptex::Res::operator!=
bool operator!=(const Res &r) const
Comparison operator.
Definition: Ptexture.h:201
Ptex::FaceInfo::flag_subface
Definition: Ptexture.h:295
PtexCache::setSearchPath
virtual void setSearchPath(const char *path)=0
Set a search path for finding textures.
PtexCache::Stats::fileReopens
uint64_t fileReopens
Definition: Ptexture.h:798
PtexCache::Stats::peakFilesOpen
uint64_t peakFilesOpen
Definition: Ptexture.h:796
PtexTexture::uBorderMode
virtual Ptex::BorderMode uBorderMode()=0
Mode for filtering texture access beyond mesh border.
PtexTexture::getPixel
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 .
Ptex::mdt_float
Single-precision (32-bit) floating point.
Definition: Ptexture.h:120
Ptex::DataSize
int DataSize(DataType dt)
Look up size of given data type (in bytes).
Definition: Ptexture.h:143
Ptex::FaceInfo::res
Res res
Resolution of face.
Definition: Ptexture.h:243
Ptex::FaceInfo::adjedges
uint8_t adjedges
Adjacent edges, 2 bits per edge.
Definition: Ptexture.h:244
Ptex::MetaDataType
MetaDataType
Type of meta data entry.
Definition: Ptexture.h:115
PtexCache::getSearchPath
virtual const char * getSearchPath()=0
Query the search path.
Ptex::FaceInfo
Information about a face, as stored in the Ptex file header.
Definition: Ptexture.h:242
PtexWriter::close
virtual bool close(Ptex::String &error)=0
Close the file.
PtexFilter::Options
Choose filter options.
Definition: Ptexture.h:969
Ptex::Res::ntiles
int ntiles(Res tileres) const
Determine the total number of tiles for the given tile res.
Definition: Ptexture.h:225
PtexWriter::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexTexture::getFaceInfo
virtual const Ptex::FaceInfo & getFaceInfo(int faceid)=0
Access resolution and adjacency information about a face.
Ptex::mdt_int16
Signed 16-bit integer.
Definition: Ptexture.h:118
Ptex::BorderModeName
const char * BorderModeName(BorderMode m)
Look up name of given border mode.
Ptex::DataType
DataType
Type of data stored in texture file.
Definition: Ptexture.h:85
PTEX_NAMESPACE_BEGIN
Definition: PtexSeparableKernel.cpp:42
PtexFilter::FilterType
FilterType
Filter types.
Definition: Ptexture.h:957
Ptex::Res::Res
Res(uint16_t value)
Constructor.
Definition: Ptexture.h:183
Ptex::OneValue
float OneValue(DataType dt)
Look up value of given data type that corresponds to the normalized value of 1.0. ...
Definition: Ptexture.h:149
PtexInt.h
Portable fixed-width integer types.
PTEX_NAMESPACE_END
#define PTEX_NAMESPACE_END
Definition: PtexVersion.h:62
PtexInputHandler::close
virtual bool close(Handle handle)=0
Close a file.
Ptex::EdgeFilterModeName
const char * EdgeFilterModeName(EdgeFilterMode m)
Look up name of given edge filter mode.
Ptex::FaceInfo::hasEdits
bool hasEdits() const
Determine if face has edits in the file (by checking a flag).
Definition: Ptexture.h:281
PtexMetaData::getValue
virtual void getValue(const char *key, const char *&value)=0
Query the value of a given meta data entry.
Ptex::mt_quad
Mesh is quad-based.
Definition: Ptexture.h:81
PtexPtr::swap
void swap(PtexPtr &p)
Swap pointer values.
Definition: Ptexture.h:1064
operator<<
std::ostream & operator<<(std::ostream &stream, const String &str)
Definition: PtexUtils.cpp:686
Ptex::Res::clamp
void clamp(const Res &r)
Clamp the resolution value against the given value.
Definition: Ptexture.h:213
PtexCache::~PtexCache
virtual ~PtexCache()
Destructor not for public use. Use release() instead.
Definition: Ptexture.h:700
PtexFilter::Options::__structSize
int __structSize
(for internal use only)
Definition: Ptexture.h:970
PtexFilter::Options::lerp
bool lerp
Interpolate between mipmap levels.
Definition: Ptexture.h:972
Ptex::ConvertToFloat
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.
Ptex::FaceInfo::adjedge
EdgeId adjedge(int eid) const
Access an adjacent edge id. The eid value must be 0..3.
Definition: Ptexture.h:269
PtexMetaData::release
virtual void release()=0
Release resources held by this pointer (pointer becomes invalid).
PtexTexture::Info::uBorderMode
BorderMode uBorderMode
Definition: Ptexture.h:502
PtexInputHandler
Custom handler interface for intercepting and redirecting Ptex input stream calls.
Definition: Ptexture.h:632
Ptex::MetaDataTypeName
const char * MetaDataTypeName(MetaDataType mdt)
Look up name of given meta data type.
PtexFilter::f_bicubic
General bi-cubic filter (uses sharpness option)
Definition: Ptexture.h:962
PtexFilter
Interface for filtered sampling of ptex data files.
Definition: Ptexture.h:950
PtexFaceData::tileRes
virtual Ptex::Res tileRes()=0
Resolution of each tile in this data block.
PtexTexture::Info::numFaces
int numFaces
Definition: Ptexture.h:507
PtexWriter::edit
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
PtexCache::purge
virtual void purge(PtexTexture *texture)=0
Remove a texture file from the cache.