-
Notifications
You must be signed in to change notification settings - Fork 140
/
ptxinfo.cpp
378 lines (331 loc) · 12.9 KB
/
ptxinfo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
PTEX SOFTWARE
Copyright 2014 Disney Enterprises, Inc. All rights reserved
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
Studios" or the names of its contributors may NOT be used to
endorse or promote products derived from this software without
specific prior written permission from Walt Disney Pictures.
Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#include <string>
#include <iostream>
#include "Ptexture.h"
#include "PtexReader.h"
using namespace Ptex;
namespace PtexIO = Ptex;
void DumpFaceInfo(const Ptex::FaceInfo& f)
{
Ptex::Res res = f.res;
std::cout << " res: " << int(res.ulog2) << ' ' << int(res.vlog2)
<< " (" << res.u() << " x " << res.v() << ")"
<< " adjface: "
<< f.adjfaces[0] << ' '
<< f.adjfaces[1] << ' '
<< f.adjfaces[2] << ' '
<< f.adjfaces[3]
<< " adjedge: "
<< f.adjedge(0) << ' '
<< f.adjedge(1) << ' '
<< f.adjedge(2) << ' '
<< f.adjedge(3)
<< " flags:";
// output flag names
if (f.flags == 0) std::cout << " (none)";
else {
if (f.isSubface()) std::cout << " subface";
if (f.isConstant()) std::cout << " constant";
if (f.isNeighborhoodConstant()) std::cout << " nbconstant";
if (f.hasEdits()) std::cout << " hasedits";
}
std::cout << std::endl;
}
void DumpTiling(PtexFaceData* dh)
{
std::cout << " tiling: ";
if (dh->isTiled()) {
Ptex::Res res = dh->tileRes();
std::cout << "ntiles = " << dh->res().ntiles(res)
<< ", res = "
<< int(res.ulog2) << ' ' << int(res.vlog2)
<< " (" << res.u() << " x " << res.v() << ")\n";
}
else if (dh->isConstant()) {
std::cout << " (constant)" << std::endl;
}
else {
std::cout << " (untiled)" << std::endl;
}
}
void DumpData(PtexTexture* r, int faceid, bool dumpall)
{
int levels = 1;
if (dumpall) {
PtexReader* R = static_cast<PtexReader*> (r);
if (R) levels = R->header().nlevels;
}
const Ptex::FaceInfo& f = r->getFaceInfo(faceid);
int nchan = r->numChannels();
float* pixel = (float*) malloc(sizeof(float)*nchan);
Ptex::Res res = f.res;
while (levels && res.ulog2 >= 1 && res.vlog2 >= 1) {
int ures = res.u(), vres = res.v();
std::cout << " data (" << ures << " x " << vres << ")";
if (f.isConstant()) { ures = vres = 1; }
bool isconst = (ures == 1 && vres == 1);
if (isconst) std::cout << ", const: ";
else std::cout << ":";
for (int vi = 0; vi < vres; vi++) {
for (int ui = 0; ui < ures; ui++) {
if (!isconst) std::cout << "\n (" << ui << ", " << vi << "): ";
r->getPixel(faceid, ui, vi, pixel, 0, nchan, res);
for (int c=0; c < nchan; c++) {
printf(" %.3f", pixel[c]);
}
}
}
std::cout << std::endl;
res.ulog2--;
res.vlog2--;
levels--;
}
free(pixel);
}
template <typename T>
class DumpMetaArrayVal
{
public:
void operator()(PtexMetaData* meta, const char* key)
{
const T* val=0;
int count=0;
meta->getValue(key, val, count);
for (int i = 0; i < count; i++) {
if (i%10==0 && (i || count > 10)) std::cout << "\n ";
std::cout << " " << val[i];
}
}
};
void DumpMetaData(PtexMetaData* meta)
{
std::cout << "meta:" << std::endl;
for (int i = 0; i < meta->numKeys(); i++) {
const char* key;
Ptex::MetaDataType type;
meta->getKey(i, key, type);
std::cout << " " << key << " type=" << Ptex::MetaDataTypeName(type);
switch (type) {
case Ptex::mdt_string:
{
const char* val=0;
meta->getValue(key, val);
std::cout << " \"" << val << "\"";
}
break;
case Ptex::mdt_int8: DumpMetaArrayVal<int8_t>()(meta, key); break;
case Ptex::mdt_int16: DumpMetaArrayVal<int16_t>()(meta, key); break;
case Ptex::mdt_int32: DumpMetaArrayVal<int32_t>()(meta, key); break;
case Ptex::mdt_float: DumpMetaArrayVal<float>()(meta, key); break;
case Ptex::mdt_double: DumpMetaArrayVal<double>()(meta, key); break;
}
std::cout << std::endl;
}
}
void DumpInternal(PtexTexture* tx)
{
PtexReader* r = static_cast<PtexReader*> (tx);
const PtexIO::Header& h = r->header();
const PtexIO::ExtHeader& eh = r->extheader();
std::cout << "Header:\n"
<< " magic: ";
if (h.magic == PtexIO::Magic)
std::cout << "'Ptex'" << std::endl;
else
std::cout << h.magic << std::endl;
std::cout << " version: " << h.version << '.' << h.minorversion << std::endl
<< " meshtype: " << h.meshtype << std::endl
<< " datatype: " << h.datatype << std::endl
<< " alphachan: " << int(h.alphachan) << std::endl
<< " nchannels: " << h.nchannels << std::endl
<< " nlevels: " << h.nlevels << std::endl
<< " nfaces: " << h.nfaces << std::endl
<< " extheadersize: " << h.extheadersize << std::endl
<< " faceinfosize: " << h.faceinfosize << std::endl
<< " constdatasize: " << h.constdatasize << std::endl
<< " levelinfosize: " << h.levelinfosize << std::endl
<< " leveldatasize: " << h.leveldatasize << std::endl
<< " metadatazipsize: " << h.metadatazipsize << std::endl
<< " metadatamemsize: " << h.metadatamemsize << std::endl
<< " ubordermode: " << eh.ubordermode << std::endl
<< " vbordermode: " << eh.vbordermode << std::endl
<< " lmdheaderzipsize: " << eh.lmdheaderzipsize << std::endl
<< " lmdheadermemsize: " << eh.lmdheadermemsize << std::endl
<< " lmddatasize: " << eh.lmddatasize << std::endl
<< " editdatasize: " << eh.editdatasize << std::endl
<< " editdatapos: " << eh.editdatapos << std::endl;
std::cout << "Level info:\n";
for (int i = 0; i < h.nlevels; i++) {
const PtexIO::LevelInfo& l = r->levelinfo(i);
std::cout << " Level " << i << std::endl
<< " leveldatasize: " << l.leveldatasize << std::endl
<< " levelheadersize: " << l.levelheadersize << std::endl
<< " nfaces: " << l.nfaces << std::endl;
}
}
int CheckAdjacency(PtexTexture* tx)
{
int result=0;
bool noinfo=true;
for (int fid = 0; fid < tx->numFaces(); fid++) {
const Ptex::FaceInfo& finfo = tx->getFaceInfo(fid);
for (int e=0; e<4; ++e) {
if (finfo.adjface(e)>=0) {
noinfo=false;
const Ptex::FaceInfo & adjf = tx->getFaceInfo(finfo.adjface(e));
int oppfid = adjf.adjface( finfo.adjedge(e));
// trivial match
if (oppfid==fid)
continue;
// subface case
if (finfo.isSubface() && !adjf.isSubface()) {
// neighbor face might be pointing to "other" subface
if (oppfid == finfo.adjface((e+1)%4))
continue;
}
std::cerr << "face " << fid << " edge " << e
<< " has incorrect adjacency\n";
++result;
}
}
}
if (noinfo) {
std::cerr << "\"" << tx->path() << "\" does not appear to have"
"any adjacency information.\n";
++result;
}
if (result==0) {
std::cout << "Adjacency information appears consistent.\n";
}
return result;
}
void usage()
{
std::cerr << "Usage: ptxinfo [options] file\n"
<< " -v Show ptex software version\n"
<< " -m Dump meta data\n"
<< " -f Dump face info\n"
<< " -d Dump data\n"
<< " -D Dump data for all mipmap levels\n"
<< " -t Dump tiling info\n"
<< " -i Dump internal info\n"
<< " -c Check validity of adjacency data\n";
exit(1);
}
int main(int argc, char** argv)
{
bool showver = 0;
bool dumpmeta = 0;
bool dumpfaceinfo = 0;
bool dumpdata = 0;
bool dumpalldata = 0;
bool dumpinternal = 0;
bool dumptiling = 0;
bool checkadjacency = 0;
const char* fname = 0;
while (--argc) {
if (**++argv == '-') {
char* cp = *argv + 1;
if (!*cp) usage(); // handle bare '-'
while (*cp) {
switch (*cp++) {
case 'v': showver = 1; break;
case 'm': dumpmeta = 1; break;
case 'd': dumpdata = 1; break;
case 'D': dumpdata = 1; dumpalldata = 1; break;
case 'f': dumpfaceinfo = 1; break;
case 't': dumptiling = 1; break;
case 'i': dumpinternal = 1; break;
case 'c': checkadjacency = 1; break;
default: usage();
}
}
}
else if (fname) usage();
else fname = *argv;
}
if (showver) {
#ifdef PTEX_VENDOR
# define str(s) #s
# define xstr(s) str(s)
std::cout << "Ptex v" << PtexLibraryMajorVersion << "." << PtexLibraryMinorVersion << "-" << xstr(PTEX_VENDOR) << std::endl;
#else
std::cout << "Ptex v" << PtexLibraryMajorVersion << "." << PtexLibraryMinorVersion << std::endl;
#endif
}
if (!fname) {
if (!showver) usage();
return 0;
}
Ptex::String error;
PtexPtr<PtexTexture> r ( PtexTexture::open(fname, error) );
if (!r) {
std::cerr << error.c_str() << std::endl;
return 1;
}
if (checkadjacency) {
return CheckAdjacency(r);
}
std::cout << "meshType: " << Ptex::MeshTypeName(r->meshType()) << std::endl;
std::cout << "dataType: " << Ptex::DataTypeName(r->dataType()) << std::endl;
std::cout << "numChannels: " << r->numChannels() << std::endl;
std::cout << "alphaChannel: ";
if (r->alphaChannel() == -1) std::cout << "(none)" << std::endl;
else std::cout << r->alphaChannel() << std::endl;
std::cout << "uBorderMode: " << Ptex::BorderModeName(r->uBorderMode()) << std::endl;
std::cout << "vBorderMode: " << Ptex::BorderModeName(r->vBorderMode()) << std::endl;
std::cout << "edgeFilterMode: " << Ptex::EdgeFilterModeName(r->edgeFilterMode()) << std::endl;
std::cout << "numFaces: " << r->numFaces() << std::endl;
std::cout << "hasEdits: " << (r->hasEdits() ? "yes" : "no") << std::endl;
std::cout << "hasMipMaps: " << (r->hasMipMaps() ? "yes" : "no") << std::endl;
PtexPtr<PtexMetaData> meta ( r->getMetaData() );
if (meta) {
std::cout << "numMetaKeys: " << meta->numKeys() << std::endl;
if (dumpmeta && meta->numKeys()) DumpMetaData(meta);
}
if (dumpfaceinfo || dumpdata || dumptiling) {
uint64_t texels = 0;
for (int i = 0; i < r->numFaces(); i++) {
std::cout << "face " << i << ":";
const Ptex::FaceInfo& f = r->getFaceInfo(i);
DumpFaceInfo(f);
texels += f.res.size();
if (dumptiling) {
PtexPtr<PtexFaceData> dh ( r->getData(i, f.res) );
DumpTiling(dh);
}
if (dumpdata) DumpData(r, i, dumpalldata);
}
std::cout << "texels: " << texels << std::endl;
}
if (dumpinternal) DumpInternal(r);
return 0;
}