/* * Reads a token from a given preprocessing context, expands it if macro, and * returns it. */ static Token *expand_one(CppContext *ctx) { Token *tok = read_cpp_token(ctx); if (!tok) return NULL; if (tok->toktype != TOKTYPE_IDENT) return tok; String *name = tok->val.str; Macro *macro = dict_get(ctx->defs, name); if (!macro) return tok; if (list_in(tok->hideset, name)) return tok; switch (macro->type) { case MACRO_OBJ: { List *ts = subst(ctx, macro, make_list(), list_union1(tok->hideset, name)); pushback(ctx, ts); return expand_one(ctx); } case MACRO_FUNC: { List *args = read_args(ctx, macro); Token *rparen = read_cpp_token(ctx); List *hideset = list_union1(list_intersect(tok->hideset, rparen->hideset), name); List *ts = subst(ctx, macro, args, hideset); pushback(ctx, ts); return expand_one(ctx); } case MACRO_SPECIAL: macro->fn(ctx, tok); return expand_one(ctx); } panic("should not reach here"); }
LIST *property_set_create( PARSE *parse, FRAME *frame ) { LIST* properties = lol_get( frame->args, 0 ); LIST* sorted = 0; LIST* order_sensitive = 0; LIST* unique; LIST* tmp; LIST* val; string var[1]; #if 0 /* Sort all properties which are not order sensitive */ for(tmp = properties; tmp; tmp = tmp->next) { LIST* g = get_grist(tmp->string); LIST* att = call_rule("feature.attributes", frame, g, 0); if (list_in(att, "order-sensitive")) { order_sensitive = list_new( order_sensitive, tmp->string); } else { sorted = list_new( sorted, tmp->string); } list_free(att); } sorted = list_sort(sorted); sorted = list_append(sorted, order_sensitive); unique = list_unique(sorted); #endif sorted = list_sort(properties); unique = list_unique(sorted); string_new(var); string_append(var, ".ps."); for(tmp = unique; tmp; tmp = tmp->next) { string_append(var, tmp->string); string_push_back(var, '-'); } val = var_get(var->value); if (val == 0) { val = call_rule("new", frame, list_append(list_new(0, "property-set"), unique), 0); var_set(newstr(var->value), list_copy(0, val), VAR_SET); } else { val = list_copy(0, val); } string_free(var); /* The 'unique' variable is freed in 'call_rule'. */ list_free(sorted); return val; }
int list_is_sublist( LIST * sub, LIST * l ) { LISTITER iter = list_begin( sub ); LISTITER const end = list_end( sub ); for ( ; iter != end; iter = list_next( iter ) ) if ( !list_in( l, list_item( iter ) ) ) return 0; return 1; }
/* local result = ; local element ; for element in $(B) { if ! ( $(element) in $(A) ) { result += $(element) ; } } return $(result) ; */ LIST *set_difference( PARSE *parse, FRAME *frame ) { LIST* b = lol_get( frame->args, 0 ); LIST* a = lol_get( frame->args, 1 ); LIST* result = 0; for(; b; b = b->next) { if (!list_in(a, b->string)) result = list_new(result, b->string); } return result; }
/* local result = ; local element ; for element in $(B) { if ! ( $(element) in $(A) ) { result += $(element) ; } } return $(result) ; */ LIST *set_difference( FRAME *frame, int flags ) { LIST* b = lol_get( frame->args, 0 ); LIST* a = lol_get( frame->args, 1 ); LIST* result = 0; for(; b; b = b->next) { if (!list_in(a, b->value)) result = list_new(result, object_copy(b->value)); } return result; }
LIST * compile_eval( PARSE *parse, LOL *args, int *jmp ) { LIST *ll, *lr, *t; int status = 0; /* Short circuit lr eval for &&, ||, and 'in' */ ll = (*parse->left->func)( parse->left, args, jmp ); lr = 0; switch( parse->num ) { case EXPR_AND: case EXPR_IN: if( ll ) goto eval; break; case EXPR_OR: if( !ll ) goto eval; break; default: eval: lr = (*parse->right->func)( parse->right, args, jmp ); } /* Now eval */ switch( parse->num ) { case EXPR_NOT: if( !ll ) status = 1; break; case EXPR_AND: if( ll && lr ) status = 1; break; case EXPR_OR: if( ll || lr ) status = 1; break; case EXPR_IN: /* "a in b": make sure each of */ /* ll is equal to something in lr. */ status = list_in(ll, lr); break; case EXPR_EXISTS: if( lcmp( ll, L0 ) != 0 ) status = 1; break; case EXPR_EQUALS: if( lcmp( ll, lr ) == 0 ) status = 1; break; case EXPR_NOTEQ: if( lcmp( ll, lr ) != 0 ) status = 1; break; case EXPR_LESS: if( lcmp( ll, lr ) < 0 ) status = 1; break; case EXPR_LESSEQ: if( lcmp( ll, lr ) <= 0 ) status = 1; break; case EXPR_MORE: if( lcmp( ll, lr ) > 0 ) status = 1; break; case EXPR_MOREEQ: if( lcmp( ll, lr ) >= 0 ) status = 1; break; } if( DEBUG_IF ) { debug_compile( 0, "if" ); list_print( ll ); printf( "(%d) ", status ); list_print( lr ); printf( "\n" ); } /* Find something to return. */ /* In odd circumstances (like "" = "") */ /* we'll have to return a new string. */ if( !status ) t = 0; else if( ll ) t = ll, ll = 0; else if( lr ) t = lr, lr = 0; else t = list_append( L0, "1", 0 ); if( ll ) list_free( ll ); if( lr ) list_free( lr ); return t; }
void LoadBundlerMap(const string& structure_file, const string& image_list_file, Map& map) { CHECK_PRED1(fs::exists, structure_file); CHECK_PRED1(fs::exists, image_list_file); // Get the base path to help find images fs::path basedir = fs::path(image_list_file).parent_path(); // Read list of images sifstream list_in(image_list_file); vector<fs::path> image_paths; int nonexistent = 0; while (true) { string image_file; getline(list_in, image_file); if (list_in.eof()) break; fs::path path = basedir / image_file; if (!fs::exists(path)) { DLOG << "WARNING: image file not found: " << path; } image_paths.push_back(path); } // Load structure sifstream in(structure_file); // Ignore comment string comment; getline(in, comment); // Load number of cameras and points int num_cameras, num_points; in >> num_cameras >> num_points; CHECK(num_cameras > 0); CHECK_EQ(image_paths.size(), num_cameras) << "Number of cameras should equal number of image files in " << image_list_file; // Load poses bool warned_focal = false; bool warned_distortion = false; double focal_length; double f; Mat3 R; Vec3 t; Vec2 distortion; for (int i = 0; i < num_cameras; i++) { in >> f >> distortion >> R >> t; if (distortion != makeVector(0,0) && !warned_distortion) { DLOG << "WARNING: Distorted cameras not supported yet, " << "loading map anyway"; warned_distortion = true; } if (i == 0) { focal_length = f; // Construct a linear camera Mat3 cam = Identity; cam[0][0] = cam[1][1] = focal_length; map.camera.reset(new LinearCamera(cam, *gvDefaultImageSize)); } else { if (f != focal_length && !warned_focal) { DLOG << "WARNING: Multiple focal lengths not supported yet, " "loading map anyway"; warned_focal = true; } } // Bundler considers cameras looking down the negative Z axis so // invert (this only really matters for visualizations and // visibility testing). SE3<> pose(SO3<>(-R), -t); string image_file = i < image_paths.size() ? image_paths[i].string() : ""; map.AddFrame(new Frame(i, image_file, pose)); } // Load points // TODO: store observations Vec3 v, color; Vec2 obs_pt; int num_obs, obs_camera, obs_key; for (int i = 0; i < num_points; i++) { in >> v >> color >> num_obs; for (int j = 0; j < num_obs; j++) { in >> obs_camera >> obs_key >> obs_pt; } map.points.push_back(v); } }
//============================================================================ // add_to_set //============================================================================ int set_add(set_t *set, uint64_t val) { int index = list_in(set, val); if (index >= 0) return index; return list_append(set, val); }
//============================================================================ // set_in //============================================================================ int set_in(set_t *set, uint64_t val) { return list_in(set, val); }