Ejemplo n.º 1
0
int main(int argc, char** argv)
{
    int maxmem = argc >= 2 ? atoi(argv[1]) : 1024*1024;
    PtexCache* c = PtexCache::create(0, maxmem);

    Ptex::String error;
    PtexPtr<PtexTexture> r ( c->get("test.ptx", error) );

    if (!r) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }

    PtexFilter::Options opts(PtexFilter::f_bicubic, 0, 1.0);
    PtexPtr<PtexFilter> f ( PtexFilter::getFilter(r, opts) );
    float result[4];
    int faceid = 0;
    float u=0, v=0, uw=.125, vw=.125;
    for (v = 0; v <= 1; v += .125) {
	for (u = 0; u <= 1; u += .125) {
	    f->eval(result, 0, 1, faceid, u, v, uw, 0, 0, vw);
	    printf("%8f %8f -> %8f\n", u, v, result[0]);
	}
    }

    return 0;
}
Ejemplo n.º 2
0
int main(int /*argc*/, char** /*argv*/)
{
    Ptex::String error;
    PtexPtr<PtexCache> c(PtexCache::create());
    c->setSearchPath("foo/bar:.");
    PtexPtr<PtexTexture> r(c->get("test.ptx", error));

    if (!r) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    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 << "numFaces: " << r->numFaces() << std::endl;

    PtexMetaData* meta = r->getMetaData();
    std::cout << "numMetaKeys: " << meta->numKeys() << std::endl;
    if (meta->numKeys()) DumpMetaData(meta);
    meta->release();

    int nfaces = r->numFaces();
    for (int i = 0; i < nfaces; i++) {
	const Ptex::FaceInfo& f = r->getFaceInfo(i);
	std::cout << "face " << i << ":\n"
		  << "  res: " << int(f.res.ulog2) << ' ' << int(f.res.vlog2) << "\n"
		  << "  adjface: " 
		  << f.adjfaces[0] << ' '
		  << f.adjfaces[1] << ' '
		  << f.adjfaces[2] << ' '
		  << f.adjfaces[3] << "\n"
		  << "  adjedge: " 
		  << f.adjedge(0) << ' '
		  << f.adjedge(1) << ' '
		  << f.adjedge(2) << ' '
		  << f.adjedge(3) << "\n"
		  << "  flags: " << int(f.flags) << "\n";

	Ptex::Res res = f.res;
	while (res.ulog2 > 0 || res.vlog2 > 0) {
	    PtexFaceData* dh = r->getData(i, res);
	    if (!dh) break;
	    DumpData(r->dataType(), r->numChannels(), dh, "  ");
	    bool isconst = dh->isConstant();
	    dh->release();
	    if (isconst) break;
	    if (res.ulog2) res.ulog2--;
	    if (res.vlog2) res.vlog2--;
	}
	PtexFaceData* dh = r->getData(i, Ptex::Res(0,0));
	DumpData(r->dataType(), r->numChannels(), dh, "  ");
	dh->release();
    }

    return 0;
}
Ejemplo n.º 3
0
void PtexWriterBase::release()
{
    Ptex::String error;
    // close writer if app didn't, and report error if any
    if (_tilefp && !close(error))
	std::cerr << error.c_str() << std::endl;
    delete this;
}
Ejemplo n.º 4
0
bool PtexViewer::loadFile(std::string filename, int face)
{
    Ptex::String ptexError;
    PtexPtr<PtexTexture> r(PtexTexture::open(filename.c_str(), ptexError, true));
    
    _quads = true;
    
    if (!r)
    {
        fprintf(stderr,"%s\n",ptexError.c_str());
        return false;
    }
    
    if (face>=r->numFaces())
    {
        std::cerr << "Invalid face ID requested" << std::endl;
        return false;
    }
    
    removeSceneData();
    
    _numFaces = r->numFaces();
    _typeStr = Ptex::DataTypeName(r->dataType());
    _quads = r->meshType()==Ptex::mt_quad;
    _mode3d = false;
    _envCube = false;
    
    if (_enable3D && r->numFaces()==6 && face<0)
    {
        // Test for environment cube case
        
        _envCube = true;
        
        int adjfaces[6][4] = {
            { 3, 5, 2, 4 }, // px
            { 3, 4, 2, 5 }, // nx
            { 4, 0, 5, 1 }, // py
            { 5, 0, 4, 1 }, // ny
            { 3, 0, 2, 1 }, // pz
            { 3, 1, 2, 0 }  // nz
        };
        
        int fi = 0;
        while (fi<6 && _envCube)
        {
            const Ptex::FaceInfo& f = r->getFaceInfo(fi);
            
            for (int v=0; v<4; v++)
                if (f.adjfaces[v]!=adjfaces[fi][v]) _envCube = false;
            
            fi++;
        }
    }
    
    if (_envCube)
    {
        // Construct environment cube geometry
        
        float cubeVerts[8][3] = { 
            {-1,-1,-1}, {1,-1,-1}, {1,-1, 1}, {-1,-1, 1},  
            {-1, 1,-1}, {1, 1,-1}, {1, 1, 1}, {-1, 1, 1} };

        int cubeInds[6][4] = {
            {2,1,5,6}, {0,3,7,4},
            {7,6,5,4}, {0,1,2,3},
            {3,2,6,7}, {1,0,4,5} };
        
        for (int i=0; i<8; i++) _geometry.addVertex(cubeVerts[i]);
        
        for (int fi=0; fi<6; fi++)
        {
            const Ptex::FaceInfo& f = r->getFaceInfo(fi);

            polygon q;
            for (int v=0; v<4; v++) q.indices[v] = cubeInds[fi][v];
            q.ures = f.res.u();
            q.vres = f.res.v();
            _geometry.addFace(q);
        }
        
        _mode3d = true;
    }
    else
    {
        if (_enable3D) _mode3d = _geometry.loadFromMetaData(r);
        if (_geometry.empty()) _geometry.makeFlatGeom(r);

        for (int fi=0; fi<r->numFaces(); fi++)
        {
            polygon* q = _geometry.getFace(fi);
            if (!q) continue;
            const Ptex::FaceInfo& f = r->getFaceInfo(fi);
            q->ures = f.res.u();
            q->vres = f.res.v();
        }
    }
    _geometry.makePages(r);
    
    computeBounds();
    
    return true;
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
int main(int /*argc*/, char** /*argv*/)
{
    static Ptex::Res res[] = { Ptex::Res(8,7),
			       Ptex::Res(1,2),
			       Ptex::Res(3,1),
			       Ptex::Res(5,4),
			       Ptex::Res(9,8),
			       Ptex::Res(2,4),
			       Ptex::Res(6,2),
			       Ptex::Res(7,4),
			       Ptex::Res(2,1)};
    static int adjedges[][4] = {{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 },
				{ 2, 3, 0, 1 }};
    static int adjfaces[][4] ={{ 3, 1, -1, -1 },
			       { 4, 2, -1, 0 },
			       { 5, -1, -1, 1 },
			       { 6, 4, 0, -1 },
			       { 7, 5, 1, 3 },
			       { 8, -1, 2, 4 },
			       { -1, 7, 3, -1 },
			       { -1, 8, 4, 6 },
			       { -1, -1, 5, 7 }};

    int nfaces = sizeof(res)/sizeof(res[0]);
    Ptex::DataType dt = Ptex::dt_half;
#define DTYPE PtexHalf
    int alpha = -1;
    int nchan = 3;

    Ptex::String error;
    PtexWriter* w =
	PtexWriter::open("test.ptx", Ptex::mt_quad, dt, nchan, alpha, nfaces, error);
    if (!w) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    int size = 0;
    for (int i = 0; i < nfaces; i++)
	size = std::max(size, res[i].size());
    size *= Ptex::DataSize(dt) * nchan;

    void* buff = malloc(size);
    for (int i = 0; i < nfaces; i++)
    {
	memset(buff, 0, size);
	DTYPE* fbuff = (DTYPE*)buff;
	int ures = res[i].u(), vres = res[i].v();
	for (int v = 0; v < vres; v++) {
	    for (int u = 0; u < ures; u++) {
		float c = (u ^ v) & 1;
		fbuff[(v*ures+u)*nchan] = u/float(ures-1);
		fbuff[(v*ures+u)*nchan+1] = v/float(vres-1);
		fbuff[(v*ures+u)*nchan+2] = c;
	    }
	}

	w->writeFace(i, Ptex::FaceInfo(res[i], adjfaces[i], adjedges[i]), buff);
    }
    free(buff);

    char* sval = "a str val";
    int ndvals = 3;
    double dvals_buff[3] = { 1.1,2.2,3.3 };
    double* dvals = dvals_buff;
    int nivals = 4;
    int16_t ivals[4] = { 2, 4, 6, 8 };
    char* xval = 0;

    writeMeta(w, sval, dvals, ndvals, ivals, nivals, xval);
    if (!w->close(error)) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    w->release();
    if (!checkMeta("test.ptx", sval, dvals, ndvals, ivals, nivals, xval))
	return 1;

    // add some incremental edits
    w = PtexWriter::edit("test.ptx", true, Ptex::mt_quad, dt, nchan, alpha, nfaces, error);
    sval = "a string value";
    dvals[2] = 0;
    writeMeta(w, sval, dvals, ndvals, 0, 0, 0);

    if (!w->close(error)) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    w->release();
    if (!checkMeta("test.ptx", sval, dvals, ndvals, ivals, nivals, xval))
	return 1;

    // add some non-incremental edits, including some large meta data
    ndvals = 500;
    dvals = (double*)malloc(ndvals * sizeof(dvals[0]));
    for (int i = 0; i < ndvals; i++) dvals[i] = i;

    w = PtexWriter::edit("test.ptx", false, Ptex::mt_quad, dt, nchan, alpha, nfaces, error);
    xval = "another string value";
    writeMeta(w, 0, dvals, ndvals, 0, 0, xval);
    if (!w->close(error)) {
	std::cerr << error.c_str() << std::endl;
	return 1;
    }
    w->release();
    if (!checkMeta("test.ptx", sval, dvals, ndvals, ivals, nivals, xval))
	return 1;

    return 0;
}