/**		Callback for abcexportctrl.
*/
static void cmd_abcexportctrl( CMD_Args & args )
{
	try
	{
		int argc = args.argc();
		if (argc<2) throw(std::string("not enough arguments"));
		string func(args(1));

#define CHK(n, msg) if (argc<n+2) throw(std::string("not enough arguments--usage: " msg))

		if (func=="oarchive")
		{
			CHK(3, "oarchive <output file> <timestep> <timestart>");
			std::string	abc_file(args(2));
			fpreal		step = atof(args(3)),
					start = atof(args(4));

			DBG << "NEW OARCHIVE"
				<< "\n\tfile=  " << abc_file
				<< "\n\tstep=  " << step
				<< "\n\tstart= " << start
				<< "\n";

			// (re-)init internal structs
			// (do these first as they cannot fail)
			//			
			_objs.clear();
			_objmap.clear();

			// create time sampling + output archive
			//
			AbcGeom::TimeSamplingPtr
				ts( new AbcGeom::TimeSampling(step, start) );

			GeoObject::init(
				new Alembic::AbcGeom::OArchive(
					Alembic::AbcCoreHDF5::WriteArchive(),
					abc_file), ts);
		}
		else if (func=="newobject")
		{
			CHK(4, "newobject <obj full pathname> <obj-src pathname> <parent full pathname> <obj outname> [<sop full pathname>]");
			std::string	objpath(args(2)),
					obj_src(args(3)),
					parentp(args(4)),
					outname(args(5)),
					soppath(args(6));
/*
			DBG << "NEW OBJECT"
				<< " obj= " << objpath
				<< "\n\tobj_src= " << obj_src
				<< "\n\tparent=  " << parentp
				<< " outname= " << outname
				<< " sop= " << soppath
				<< "\n";
*/
			if ( find_obj(objpath, false)==0 )
			{
				// add object
				//
				GeoObject	*parent = find_obj(parentp, false);
				OP_Node		*objnode = OPgetDirector()->findNode(obj_src.c_str());
				SOP_Node	*sopnode = (SOP_Node *)OPgetDirector()->findNode(soppath.c_str());

				if (!objnode)
					throw("couldn't find obj "+obj_src);

				DBG << "objnode=" << objnode << " parent=" << parent << " ";

				boost::shared_ptr<GeoObject> obj(
					new GeoObject(objnode, parent,
					sopnode, &outname) );

				_objs.push_back(obj);
				_objmap[objpath] = obj.get();

				dbg << "\n";
			}
			else throw("object "+objpath+" already added");

		}
		else if (func=="objset")
		{
			CHK(2, "objset <obj_name> <option>");
			std::string	objpath(args(2)),
					opt(args(3));

			GeoObject *obj = find_obj(objpath);

			if (opt=="static") {
				DBG << " -- " << objpath << " set as static\n";
				obj->setStaticGeo(true);
			}
		}
		else if (func=="writesample")
		{
			// write an xform (+geom--optional) sample

			CHK(2, "writesample <time> <obj_name> [<matrix(4x4>]");
			fpreal		now=atof(args(2));
			std::string	objpath(args(3));
/*
			DBG << "WRITE SAMPLE"
				<< " time= " << now
				<< " obj= " << objpath
				<< " ";
*/
			GeoObject *obj = find_obj(objpath);

			if ( argc > (2+2) )
			{
				//DBG << " --- using EXPLICIT matrix\n";
				CHK(2+16, "writesample <time> <obj_name> <matrix4x4>");

				UT_DMatrix4 mtx;
				for( int i=0, p=4;  i<16;  ++i, ++p )
					mtx.data()[i] = atof(args(p));

				obj->setMatrix(mtx);
			}
			else
			{
				//DBG << " --- using its own matrix\n";
				obj->useExplicitMatrix(false);
			}

			// write sample
			//	
			obj->writeSample(now);
		}
		else if (func=="cleanup")
		{
			DBG << "CLEANUP--...\n";

			// TODO: finish this

			_objmap.clear();
			_objs.clear();
			GeoObject::cleanup();
		}
		else
		{
			throw("unsupported function "+func);
		}
#undef CHK


		// TODO: test code, remove
		//
		if ( args.found('e') )
		{
			args.out() << "found -e option with: " << args.argp('e') << "...\n";

			args.err() << "this is an error (?)\n";
			args.showUsage();
		}

		// test: dump all arguments
		//
		if (true) {
			args.out() << "arguments:\n";
			for(int i=0, m=args.argc();  i<m;  ++i)
				args.out() << i << ".: " << args(i) << "\n";
		}
	}

	catch( std::string & e )
	{
		args.err() << "ERROR: " << e << "\n";
		std::cerr << "ERROR: " << e << "\n";
	}

	catch(...)
	{
		std::cerr << "SOME OTHER SHIT HAPPENED :( \n";
	}
}
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
}