Example #1
0
static void dumpOptions(IMG_DeepShadow &fp) {
	const UT_Options * opt;
	UT_WorkBuffer wbuf;
	if (opt = fp.getTBFOptions()) {
		wbuf.strcpy("DSM Options: ");
		opt->appendPyDictionary(wbuf);
		printf("%s\n", wbuf.buffer());
	}
}
Example #2
0
int 
main(int argc, char *argv[])
{
    
    // Init:   
    CMD_Args args;
    args.initialize(argc, argv);
    args.stripOptions("r:v");
    if (args.argc() < 3)
    {
        usage(argv[0]);
        return 1;
    }

    // Options:
    int res     = 256;
    int verbose = 0;
    if(args.found('r')) res     = atoi(args.argp('r'));       
    if(args.found('v')) verbose = 1;
    UT_String dcm_file, gdp_file;
    gdp_file.harden(argv[argc-2]);
    dcm_file.harden(argv[argc-1]);
    
    #if 1
    // Open GDP with samples:
    GU_Detail gdp;
    UT_BoundingBox bbox;
    if (!gdp.load(gdp_file, 0).success())
    {
        cerr << "Cant open " << gdp_file << endl;
        return 1;
    }
   
    // Points arrays and bbox details: 
    gdp.getBBox(&bbox);
    int range = gdp.getNumPoints();  
    UT_Vector3Array         positions(range);
    UT_ValArray<int>        indices(range);
    
    const GEO_Point *ppt;
    const GEO_PointList plist = gdp.points();
    for (int i = 0; i < gdp.getNumPoints(); i++)
    {
        ppt = plist(i);
        UT_Vector3 pos = ppt->getPos3();
        positions.append(pos);
        indices.append(i);
    }

    if (verbose)
        cout << "Points in gdp      : " <<  positions.entries() << endl;

    // Point Grid structures/objects:
    UT_Vector3Point accessor(positions, indices);
    UT_PointGrid<UT_Vector3Point> pointgrid(accessor);

    // Can we build it?
    if (!pointgrid.canBuild(res, res, res))
    {
        cout << "Can't build the grid!" << endl; 
        return 1;
    }
    // Build it:
    pointgrid.build(bbox.minvec(), bbox.size(), res, res, res);

    if (verbose)
    {
        cout << "Point grid res     : " << res << "x" << res << "x" << res << endl;
        cout << "Bounding box size  : " << bbox.size().x() << ", " << bbox.size().y() << ", " << bbox.size().z() << endl;
        cout << "Bounding box center: " << bbox.center().x() << ", " << bbox.center().y() << ", " << bbox.center().z() << endl;
        cout << "Pointgrid mem size : " << pointgrid.getMemoryUsage() << endl;
        cout << "Voxel size is      : " << pointgrid.getVoxelSize() << endl;
        cout << "Total grid points  : " << pointgrid.entries() << endl;
    }
    #endif

    // Open rat (our random access, variable array length storage):
    IMG_DeepShadow dsm;
    dsm.setOption("compression", "0");
    dsm.setOption("zbias", "0.05");
    dsm.setOption("depth_mode", "nearest");
    dsm.setOption("depth_interp", "discrete");
    dsm.open(dcm_file, res*res, res);
    dsm.getTBFOptions()->setOptionV3("bbox:min" , bbox.minvec());
    dsm.getTBFOptions()->setOptionV3("bbox:max" , bbox.maxvec()); 
    
    if (verbose)
        cout << "DCM created res    : " << res*res << "x" << res << endl;
      
    #if 1
    // db_* debug variables...
    int db_index = 0;
    int db_uindex = 0;
    int db_av_iter = 0;

    // Put point into deep pixels:
    Locker locker;
    Timer timer;
    timer.start();
    parallel_fillDCM(res, &dsm, &pointgrid, &positions, &locker);
    cout <<     "Creation time      : " << timer.current() << endl;
    if (verbose)
    {
        cout << "Total voxels       : " << db_index  << endl;
        cout << "Written voxel      : " << db_uindex << endl;
        cout << "Points per voxel   : " << (float)db_av_iter / db_uindex << endl;
    }
    timer.start();
    dsm.close();
    cout <<     "Saving time        : " << timer.current() << endl;
    if (verbose)
        cout << "Deep map closed." << endl;
    return 0;
    #endif
}
Example #3
0
int main(int argc, char *argv[]) {
    IMG_DeepShadow fp;
    int xres, yres;

    if (argc < 3 || !fp.open(argv[1])) {
    	usage(argv[0]);
    }

    char * sdfFileName = argv[2];
    std::vector<std::string> channelNames;

    // Read the texture options in the file
    dumpOptions(fp);

    // Query the resolution
    fp.resolution(xres, yres);
    printf("%s[%d,%d] (%d channels)\n", argv[1], xres, yres, fp.getChannelCount());

    for (int i = 0; i < fp.getChannelCount(); i++) {
    	const IMG_DeepShadowChannel * chp = fp.getChannel(i);
    	printf("%s ", chp->getName());
    	if (strcmp(chp->getName(), "C") == 0) {
    		channelNames.push_back("R");
    		channelNames.push_back("G");
    		channelNames.push_back("B");
    		channelNames.push_back("A");
    	}
    }
    channelNames.push_back("Z");
    channelNames.push_back("ZBack");
    std::cout << std::endl;

    DeepImage * deepImage = new DeepImage(xres, yres, channelNames);
    std::cout << "Pre load" << std::endl;
    printDeepImageStats(*deepImage);

    IMG_DeepPixelReader pixel(fp);

    const IMG_DeepShadowChannel * pzp = nullptr;
    const IMG_DeepShadowChannel * ofp = nullptr;
    const IMG_DeepShadowChannel * cp = nullptr;

    for (int i = 0; i < fp.getChannelCount(); i++) {
		if (strcmp(fp.getChannel(i)->getName(), "Pz") == 0)
			pzp = fp.getChannel(i);
		else if (strcmp(fp.getChannel(i)->getName(), "Of") == 0) {
			ofp = fp.getChannel(i);
		} else if (strcmp(fp.getChannel(i)->getName(), "C") == 0) {
			cp = fp.getChannel(i);
		}
	}

//    const IMG_DeepShadowChannel * chp;
    const UT_Options * opt = fp.getTBFOptions();
    std::string interp = opt->getOptionS("texture:depth_interp");
    bool linearInterp = (interp.compare("continuous") == 0);
    int numChannels = channelNames.size();

    for (int y = 0; y < yres; ++y) {
        for (int x = 0; x < xres; ++x) {
        	if (!pixel.open(x, y)) {
				printf("\tUnable to open pixel [%d,%d]!\n", x, y);
				return 0;
			}
        	pixel.uncomposite(*pzp, *ofp, true);
        	// Get the number of z-records for the pixel
			int numSamples = pixel.getDepth();
			if (numSamples > 0) {
				for (int d = 0; d < numSamples; ++d) {
					std::vector<DeepDataType> values(numChannels);
					// Get color:
					const float * c = pixel.getData(*cp, d);
					const float * pz = pixel.getData(*pzp, d);
					const float * pzBack = pz;
					if (linearInterp) {
						if (d + 1 < numSamples) {
							pzBack = pixel.getData(*pzp, d + 1);
						} else {
							continue;
						}
					}
					for (int i = 0; i < cp->getTupleSize(); ++i) {
						values[i] = c[i];
						if (i < 3 && c[3] > 0.0) {
							// Unpremult.
							values[i] /= c[3];
						}
					}
					values[4] = pz[0];
					values[5] = pzBack[0];
//					for (int i = 0; i < fp.getChannelCount(); i++) {
//						chp = fp.getChannel(i);
//						int offset = -1;
//						if (strcmp(chp->getName(), "C") == 0) {
//							offset = 0;
//						} else if (strcmp(chp->getName(), "Pz") == 0) {
//							offset = 4;
//						}
//						if (offset >= 0) {
//							const float * p = pixel.getData(*chp, d);
//							for (int t = 0; t < chp->getTupleSize(); ++t) {
//								values[offset+t] = p[t];
//							}
//						}
//					}
//					values[5] = values[4];
//					values[0] /= values[3]; values[1] /= values[3]; values[2] /= values[3];
					deepImage->addSample(yres-y-1, x, values);
				}
			}
        }
    }

    std::cout << "Post load" << std::endl;
    printDeepImageStats(*deepImage);
    DeepImageWriter writer(sdfFileName, *deepImage);
    if (writer.open()) {
    	writer.write();
    	writer.close();
    }
    delete deepImage;

    // Print the raw pixel data
//	printPixel(fp, 0, 0);
//	printPixel(fp, xres >> 1, 0);
//	printPixel(fp, xres - 1, 0);
	printPixel(fp, 0, yres >> 1);
	printPixel(fp, xres >> 1, yres >> 1);
//	printPixel(fp, xres - 1, yres >> 1);
//	printPixel(fp, 0, yres - 1);
	printPixel(fp, xres >> 1, yres - 1);
//	printPixel(fp, xres - 1, yres - 1);

    return 0;
}