示例#1
0
Object * Database::load_obj(const wstring & name)
{

    int ret = 0;
    Object * obj = global->obj_mgr->find(name, ret);
    if (obj != NULL)
        return obj;
    if (!is_existent_in_json(name))
        return NULL;
    obj = new Object();
    
    obj->name = name;
    string key = wstring_to_string(name);
    ObjMapMap::iterator it = obj->attr_maps.begin();
    for (; it != obj->attr_maps.end(); it++){
        ObjMap * map = it->second;
        string map_name = it->first;
        Json::Value attr = root[key][map_name];
        int size = attr.size();
        for (int i = 0; i < size; i++){
            Object * other = find(attr[i].asString(), ret);
            if (other == NULL){
                ERR("find object error\n");
                continue;
            }
            map->insert(ObjMap::value_type(other->name, other));
        }
    }
    
    return obj;
}
PyObject *PyAtom::Retrieve(size_t id)
{
    ObjMap::iterator it = objmap.find(id);
    PyObject *ret = it == objmap.end()?NULL:it->second;
    Collect();
    return ret;
}
	void InfiGLDestroyContextObjects( SDL_GLContext ctx ) {
		ObjMap::iterator vai = vertexarrays.find( ctx );
		if ( vai != vertexarrays.end() ) {
			ObjSet* va = vai->second;
			
			uint32* bufferva = new uint32[va->size()];
			
			ObjSet::iterator vaiter = va->begin();
			for ( uint32 i=0;vaiter!=va->end();++vaiter,++i )
				bufferva[i] = *vaiter;
			
			InfiGLDeleteVertexArrays( va->size(), bufferva );
			delete[] bufferva;
			delete va;
		}
		
		ObjMap::iterator fbi = framebuffers.find( ctx );
		if ( fbi != framebuffers.end() ) {
			ObjSet* fb = fbi->second;
			
			uint32* bufferfb = new uint32[fb->size()];
			
			ObjSet::iterator fbiter = fb->begin();
			for ( uint32 i=0;fbiter!=fb->end();++fbiter,++i )
				bufferfb[i] = *fbiter;
			
			InfiGLDeleteFramebuffers( fb->size(), bufferfb );
			delete[] bufferfb;
			delete fb;
		}
	}
	static ObjSet* get_framebuffer() {
		SDL_GLContext ctx = InfiCurrentContext();
		ObjMap::iterator f = framebuffers.find( ctx );
		if ( f == framebuffers.end() ) {
			ObjSet* narr = new ObjSet;
			framebuffers.insert( f, std::make_pair( ctx, narr ) );
			return narr;
		} else {
			return f->second;
		}
	}
GeoObject * find_obj( std::string & objname, bool do_throw=true )
{
	//DBG << "( find_obj() " << objname << " )\n";
	ObjMap::iterator p = _objmap.find(objname);

	if (p==_objmap.end()) {
		//DBG << " -- (not found)\n";
		if (do_throw) throw("couldn't look up "+objname);
		else return 0;
	}
	//DBG << "( find_obj() " << objname << "==" << (p->second) << " )\n";
	return p->second;
}
示例#6
0
int Database::save_obj(Object * & obj)
{
    
    string key = wstring_to_string(obj->name);
    Json::Value attrs;
    ObjMapMap::iterator it = obj->attr_maps.begin();
    for (; it != obj->attr_maps.end(); it++){
        ObjMap * map = it->second;
        string map_name = it->first;
        ObjMap::iterator i = map->begin();
        attrs[map_name] = Json::nullValue;
        for (; i != map->end(); i++){
            attrs[map_name].append(wstring_to_string(i->first));
        }
        
    }
    root[key] = attrs;
    return 0;
}
void PyAtom::Collect()
{
    for(;;) {
        ObjMap::iterator it = objmap.begin();
        if(it == objmap.end() || it->first > collix) break;
        
        PyObject *obj = it->second;
        Py_DECREF(obj);
        objmap.erase(it);

#ifdef _DEBUG
//        post("DEL %p\n",obj);
#endif
    }

    // schedule next collect time
    double tm = flext::GetTime();
    if(tm > last+INTV) last = tm,collix = curix;
}
/**		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";
	}
}
示例#9
0
 double getObjCoef(IloNumVar x) const {
    ObjMap::const_iterator const it = objMap.find(x);
    return (it == objMap.end()) ? 0.0 : it->second;
 }
示例#10
0
namespace render {
	
	typedef std::set<uint32> ObjSet;
	typedef core::map_t<SDL_GLContext,ObjSet*> ObjMap;
	ObjMap vertexarrays, framebuffers;
	
	static ObjSet* get_vertex_array() {
		SDL_GLContext ctx = InfiCurrentContext();
		ObjMap::iterator f = vertexarrays.find( ctx );
		if ( f == vertexarrays.end() ) {
			ObjSet* narr = new ObjSet;
			vertexarrays.insert( f, std::make_pair( ctx, narr ) );
			return narr;
		} else {
			return f->second;
		}
	}
	static ObjSet* get_framebuffer() {
		SDL_GLContext ctx = InfiCurrentContext();
		ObjMap::iterator f = framebuffers.find( ctx );
		if ( f == framebuffers.end() ) {
			ObjSet* narr = new ObjSet;
			framebuffers.insert( f, std::make_pair( ctx, narr ) );
			return narr;
		} else {
			return f->second;
		}
	}
	
	void InfiGLDestroyContextObjects( SDL_GLContext ctx ) {
		ObjMap::iterator vai = vertexarrays.find( ctx );
		if ( vai != vertexarrays.end() ) {
			ObjSet* va = vai->second;
			
			uint32* bufferva = new uint32[va->size()];
			
			ObjSet::iterator vaiter = va->begin();
			for ( uint32 i=0;vaiter!=va->end();++vaiter,++i )
				bufferva[i] = *vaiter;
			
			InfiGLDeleteVertexArrays( va->size(), bufferva );
			delete[] bufferva;
			delete va;
		}
		
		ObjMap::iterator fbi = framebuffers.find( ctx );
		if ( fbi != framebuffers.end() ) {
			ObjSet* fb = fbi->second;
			
			uint32* bufferfb = new uint32[fb->size()];
			
			ObjSet::iterator fbiter = fb->begin();
			for ( uint32 i=0;fbiter!=fb->end();++fbiter,++i )
				bufferfb[i] = *fbiter;
			
			InfiGLDeleteFramebuffers( fb->size(), bufferfb );
			delete[] bufferfb;
			delete fb;
		}
	}
	
	uint32 InfiGLCreateFramebuffer() {
		ObjSet* arr = get_framebuffer();
		uint32 hnd;
		InfiGLGenFramebuffers( 1, &hnd );
		arr->insert( hnd );
		return hnd;
	}
	uint32 InfiGLCreateVertexArray() {
		ObjSet* arr = get_vertex_array();
		uint32 hnd;
		InfiGLGenVertexArrays( 1, &hnd );
		arr->insert( hnd );
		return hnd;
	}
	
	void InfiGLDestroyFramebuffer( uint32 obj ) {
		ObjSet* arr = get_framebuffer();
		ObjSet::iterator iter = arr->find( obj );
		
		InfiGLDeleteVertexArrays( 1, &(*iter) );
		if ( iter != arr->end() )
			arr->erase( iter );
	}
	void InfiGLDestroyVertexArray( uint32 obj ) {
		ObjSet* arr = get_framebuffer();
		ObjSet::iterator iter = arr->find( obj );
		InfiGLDeleteFramebuffers( 1, &(*iter) );
		if ( iter != arr->end() )
			arr->erase( iter );
	}
	
} }