void write_png(const string& dst) { auto status = cairo_surface_write_to_png(m_s, dst.c_str()); if (status != CAIRO_STATUS_SUCCESS) { throw application_error(sstream() << "cairo_surface_write_to_png(): " << cairo_status_to_string(status)); } }
void runner::run_single_filter(const std::string& filter) { std::istringstream sstream(filter); std::string testcase_name; std::string benchmark_name; std::getline(sstream, testcase_name, '.'); if (!sstream) throw std::runtime_error("Error malformed gauge_filter" " (example MyTest.*)"); std::getline(sstream, benchmark_name); if (!sstream) { throw std::runtime_error("Error malformed gauge_filter" " (example MyTest.*)"); } // Evaluate all possible filter combinations if (testcase_name == "*" && benchmark_name == "*") { run_all(); } else if (testcase_name == "*") { // The benchmark must be run for each of the testcases for which // it belongs. If the requested benchmark is not found, throw an // error bool benchmark_found = false; for (const auto& testcase : m_impl->m_testcases) { for (const auto& b : testcase.second) { if (benchmark_name == b.first) { uint32_t id = b.second; assert(m_impl->m_benchmarks.find(id) != m_impl->m_benchmarks.end()); auto& make = m_impl->m_benchmarks[id]; auto benchmark = make(); run_benchmark_configurations(benchmark); benchmark_found = true; } } } if (!benchmark_found) { throw std::runtime_error("Error benchmark not found"); } } else if (benchmark_name == "*") { // All the benchmarks from a testcase must be run. If the requested // testcase is not found, throw an error if (m_impl->m_testcases.find(testcase_name) == m_impl->m_testcases.end()) { throw std::runtime_error("Error testcase not found"); } auto& benchmarks = m_impl->m_testcases[testcase_name]; for (auto& b : benchmarks) { uint32_t id = b.second; assert(m_impl->m_benchmarks.find(id) != m_impl->m_benchmarks.end()); auto& make = m_impl->m_benchmarks[id]; auto benchmark = make(); run_benchmark_configurations(benchmark); } } else { // Run the specific testcase_name.benchmark_name pair if (m_impl->m_testcases.find(testcase_name) == m_impl->m_testcases.end()) { throw std::runtime_error("Error testcase not found"); } auto& benchmarks = m_impl->m_testcases[testcase_name]; if (benchmarks.find(benchmark_name) == benchmarks.end()) { throw std::runtime_error("Error benchmark not found"); } uint32_t id = benchmarks.find(benchmark_name)->second; assert(m_impl->m_benchmarks.find(id) != m_impl->m_benchmarks.end()); auto& make = m_impl->m_benchmarks[id]; auto benchmark = make(); run_benchmark_configurations(benchmark); } }
static void throw_corrupted(name const & n) { throw exception(sstream() << "error in 'no_confusion' generation, '" << n << "' inductive datatype declaration is corrupted"); }
optional<environment> mk_no_confusion_type(environment const & env, name const & n) { optional<inductive::inductive_decls> decls = inductive::is_inductive_decl(env, n); if (!decls) throw exception(sstream() << "error in 'no_confusion' generation, '" << n << "' is not an inductive datatype"); if (is_inductive_predicate(env, n)) return optional<environment>(); // type is a proposition name_generator ngen; unsigned nparams = std::get<1>(*decls); declaration ind_decl = env.get(n); declaration cases_decl = env.get(name(n, "cases_on")); level_param_names lps = cases_decl.get_univ_params(); level rlvl = mk_param_univ(head(lps)); levels ilvls = param_names_to_levels(tail(lps)); if (length(ilvls) != length(ind_decl.get_univ_params())) return optional<environment>(); // type does not have only a restricted eliminator expr ind_type = instantiate_type_univ_params(ind_decl, ilvls); name eq_name("eq"); name heq_name("heq"); // All inductive datatype parameters and indices are arguments buffer<expr> args; ind_type = to_telescope(ngen, ind_type, args, some(mk_implicit_binder_info())); if (!is_sort(ind_type) || args.size() < nparams) throw_corrupted(n); lean_assert(!(env.impredicative() && is_zero(sort_level(ind_type)))); unsigned nindices = args.size() - nparams; // Create inductive datatype expr I = mk_app(mk_constant(n, ilvls), args); // Add (P : Type) expr P = mk_local(ngen.next(), "P", mk_sort(rlvl), binder_info()); args.push_back(P); // add v1 and v2 elements of the inductive type expr v1 = mk_local(ngen.next(), "v1", I, binder_info()); expr v2 = mk_local(ngen.next(), "v2", I, binder_info()); args.push_back(v1); args.push_back(v2); expr R = mk_sort(rlvl); name no_confusion_type_name{n, "no_confusion_type"}; expr no_confusion_type_type = Pi(args, R); // Create type former buffer<expr> type_former_args; for (unsigned i = nparams; i < nparams + nindices; i++) type_former_args.push_back(args[i]); type_former_args.push_back(v1); expr type_former = Fun(type_former_args, R); // Create cases_on levels clvls = levels(mk_succ(rlvl), ilvls); expr cases_on = mk_app(mk_app(mk_constant(cases_decl.get_name(), clvls), nparams, args.data()), type_former); cases_on = mk_app(cases_on, nindices, args.data() + nparams); expr cases_on1 = mk_app(cases_on, v1); expr cases_on2 = mk_app(cases_on, v2); type_checker tc(env); expr t1 = tc.infer(cases_on1).first; expr t2 = tc.infer(cases_on2).first; buffer<expr> outer_cases_on_args; unsigned idx1 = 0; while (is_pi(t1)) { buffer<expr> minor1_args; expr minor1 = to_telescope(tc, binding_domain(t1), minor1_args); expr curr_t2 = t2; buffer<expr> inner_cases_on_args; unsigned idx2 = 0; while (is_pi(curr_t2)) { buffer<expr> minor2_args; expr minor2 = to_telescope(tc, binding_domain(curr_t2), minor2_args); if (idx1 != idx2) { // infeasible case, constructors do not match inner_cases_on_args.push_back(Fun(minor2_args, P)); } else { if (minor1_args.size() != minor2_args.size()) throw_corrupted(n); buffer<expr> rtype_hyp; // add equalities for (unsigned i = 0; i < minor1_args.size(); i++) { expr lhs = minor1_args[i]; expr rhs = minor2_args[i]; expr lhs_type = mlocal_type(lhs); expr rhs_type = mlocal_type(rhs); level l = sort_level(tc.ensure_type(lhs_type).first); expr h_type; if (tc.is_def_eq(lhs_type, rhs_type).first) { h_type = mk_app(mk_constant(eq_name, to_list(l)), lhs_type, lhs, rhs); } else { h_type = mk_app(mk_constant(heq_name, to_list(l)), lhs_type, lhs, rhs_type, rhs); } rtype_hyp.push_back(mk_local(ngen.next(), local_pp_name(lhs).append_after("_eq"), h_type, binder_info())); } inner_cases_on_args.push_back(Fun(minor2_args, mk_arrow(Pi(rtype_hyp, P), P))); } idx2++; curr_t2 = binding_body(curr_t2); } outer_cases_on_args.push_back(Fun(minor1_args, mk_app(cases_on2, inner_cases_on_args))); idx1++; t1 = binding_body(t1); } expr no_confusion_type_value = Fun(args, mk_app(cases_on1, outer_cases_on_args)); bool opaque = false; bool use_conv_opt = true; declaration new_d = mk_definition(env, no_confusion_type_name, lps, no_confusion_type_type, no_confusion_type_value, opaque, ind_decl.get_module_idx(), use_conv_opt); environment new_env = module::add(env, check(env, new_d)); return some(add_protected(new_env, no_confusion_type_name)); }
void LLFacebookPhotoPanel::updateResolution(BOOL do_update) { LLComboBox* combobox = static_cast<LLComboBox *>(mResolutionComboBox); LLComboBox* filterbox = static_cast<LLComboBox *>(mFilterComboBox); std::string sdstring = combobox->getSelectedValue(); LLSD sdres; std::stringstream sstream(sdstring); LLSDSerialize::fromNotation(sdres, sstream, sdstring.size()); S32 width = sdres[0]; S32 height = sdres[1]; // Note : index 0 of the filter drop down is assumed to be "No filter" in whichever locale std::string filter_name = (filterbox->getCurrentIndex() ? filterbox->getSimple() : ""); LLSnapshotLivePreview * previewp = static_cast<LLSnapshotLivePreview *>(mPreviewHandle.get()); if (previewp && combobox->getCurrentIndex() >= 0) { // <FS:Ansariel> FIRE-15112: Allow custom resolution for SLShare; moved up checkAspectRatio(width); S32 original_width = 0 , original_height = 0 ; previewp->getSize(original_width, original_height) ; if (width == 0 || height == 0) { // take resolution from current window size LL_DEBUGS() << "Setting preview res from window: " << gViewerWindow->getWindowWidthRaw() << "x" << gViewerWindow->getWindowHeightRaw() << LL_ENDL; previewp->setSize(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw()); } // <FS:Ansariel> FIRE-15112: Allow custom resolution for SLShare else if (width == -1 || height == -1) { // take resolution from custom size LLSpinCtrl* width_spinner = getChild<LLSpinCtrl>("custom_snapshot_width"); LLSpinCtrl* height_spinner = getChild<LLSpinCtrl>("custom_snapshot_height"); S32 custom_width = width_spinner->getValue().asInteger(); S32 custom_height = height_spinner->getValue().asInteger(); if (checkImageSize(previewp, custom_width, custom_height, TRUE, previewp->getMaxImageSize())) { width_spinner->set(custom_width); height_spinner->set(custom_height); } LL_DEBUGS() << "Setting preview res from custom: " << custom_width << "x" << custom_height << LL_ENDL; previewp->setSize(custom_width, custom_height); } // </FS:Ansariel> else { // use the resolution from the selected pre-canned drop-down choice LL_DEBUGS() << "Setting preview res selected from combo: " << width << "x" << height << LL_ENDL; previewp->setSize(width, height); } // <FS:Ansariel> FIRE-15112: Allow custom resolution for SLShare; moved up //checkAspectRatio(width); previewp->getSize(width, height); // Recompute quality setting mQuality = compute_jpeg_quality(width, height); previewp->setSnapshotQuality(mQuality, false); if (original_width != width || original_height != height) { previewp->setSize(width, height); if (do_update) { previewp->updateSnapshot(TRUE); updateControls(); } } // Get the old filter, compare to the current one "filter_name" and set if changed std::string original_filter = previewp->getFilter(); if (original_filter != filter_name) { previewp->setFilter(filter_name); if (do_update) { previewp->updateSnapshot(FALSE, TRUE); updateControls(); } } } // <FS:Ansariel> FIRE-15112: Allow custom resolution for SLShare BOOL custom_resolution = static_cast<LLComboBox *>(mResolutionComboBox)->getSelectedValue().asString() == "[i-1,i-1]"; getChild<LLSpinCtrl>("custom_snapshot_width")->setEnabled(custom_resolution); getChild<LLSpinCtrl>("custom_snapshot_height")->setEnabled(custom_resolution); getChild<LLCheckBoxCtrl>("keep_aspect_ratio")->setEnabled(custom_resolution); // </FS:Ansariel> }
void add_congr_core(environment const & env, simp_rule_sets & s, name const & n) { declaration const & d = env.get(n); type_checker tc(env); buffer<level> us; unsigned num_univs = d.get_num_univ_params(); for (unsigned i = 0; i < num_univs; i++) { us.push_back(mk_meta_univ(name(*g_prefix, i))); } levels ls = to_list(us); expr pr = mk_constant(n, ls); expr e = instantiate_type_univ_params(d, ls); buffer<bool> explicit_args; buffer<expr> metas; unsigned idx = 0; while (is_pi(e)) { expr mvar = mk_metavar(name(*g_prefix, idx), binding_domain(e)); idx++; explicit_args.push_back(is_explicit(binding_info(e))); metas.push_back(mvar); e = instantiate(binding_body(e), mvar); pr = mk_app(pr, mvar); } expr rel, lhs, rhs; if (!is_simp_relation(env, e, rel, lhs, rhs) || !is_constant(rel)) { throw exception(sstream() << "invalid congruence rule, '" << n << "' resulting type is not of the form t ~ s, where '~' is a transitive and reflexive relation"); } name_set found_mvars; buffer<expr> lhs_args, rhs_args; expr const & lhs_fn = get_app_args(lhs, lhs_args); expr const & rhs_fn = get_app_args(rhs, rhs_args); if (is_constant(lhs_fn)) { if (!is_constant(rhs_fn) || const_name(lhs_fn) != const_name(rhs_fn) || lhs_args.size() != rhs_args.size()) { throw exception(sstream() << "invalid congruence rule, '" << n << "' resulting type is not of the form (" << const_name(lhs_fn) << " ...) " << "~ (" << const_name(lhs_fn) << " ...), where ~ is '" << const_name(rel) << "'"); } for (expr const & lhs_arg : lhs_args) { if (is_sort(lhs_arg)) continue; if (!is_metavar(lhs_arg) || found_mvars.contains(mlocal_name(lhs_arg))) { throw exception(sstream() << "invalid congruence rule, '" << n << "' the left-hand-side of the congruence resulting type must be of the form (" << const_name(lhs_fn) << " x_1 ... x_n), where each x_i is a distinct variable or a sort"); } found_mvars.insert(mlocal_name(lhs_arg)); } } else if (is_binding(lhs)) { if (lhs.kind() != rhs.kind()) { throw exception(sstream() << "invalid congruence rule, '" << n << "' kinds of the left-hand-side and right-hand-side of " << "the congruence resulting type do not match"); } if (!is_valid_congr_rule_binding_lhs(lhs, found_mvars)) { throw exception(sstream() << "invalid congruence rule, '" << n << "' left-hand-side of the congruence resulting type must " << "be of the form (fun/Pi (x : A), B x)"); } } else { throw exception(sstream() << "invalid congruence rule, '" << n << "' left-hand-side is not an application nor a binding"); } buffer<expr> congr_hyps; lean_assert(metas.size() == explicit_args.size()); for (unsigned i = 0; i < metas.size(); i++) { expr const & mvar = metas[i]; if (explicit_args[i] && !found_mvars.contains(mlocal_name(mvar))) { buffer<expr> locals; expr type = mlocal_type(mvar); while (is_pi(type)) { expr local = mk_local(tc.mk_fresh_name(), binding_domain(type)); locals.push_back(local); type = instantiate(binding_body(type), local); } expr h_rel, h_lhs, h_rhs; if (!is_simp_relation(env, type, h_rel, h_lhs, h_rhs) || !is_constant(h_rel)) continue; unsigned j = 0; for (expr const & local : locals) { j++; if (!only_found_mvars(mlocal_type(local), found_mvars)) { throw exception(sstream() << "invalid congruence rule, '" << n << "' argument #" << j << " of parameter #" << (i+1) << " contains " << "unresolved parameters"); } } if (!only_found_mvars(h_lhs, found_mvars)) { throw exception(sstream() << "invalid congruence rule, '" << n << "' argument #" << (i+1) << " is not a valid hypothesis, the left-hand-side contains " << "unresolved parameters"); } if (!is_valid_congr_hyp_rhs(h_rhs, found_mvars)) { throw exception(sstream() << "invalid congruence rule, '" << n << "' argument #" << (i+1) << " is not a valid hypothesis, the right-hand-side must be " << "of the form (m l_1 ... l_n) where m is parameter that was not " << "'assigned/resolved' yet and l_i's are locals"); } found_mvars.insert(mlocal_name(mvar)); congr_hyps.push_back(mvar); } } congr_rule rule(n, ls, to_list(metas), lhs, rhs, pr, to_list(congr_hyps)); s.insert(const_name(rel), rule); }
void decl_attributes::parse(parser & p) { buffer<char const *> attr_tokens; get_attribute_tokens(attr_tokens); while (true) { auto pos = p.pos(); if (auto it = parse_priority(p)) { m_prio = *it; bool has_prio_attr = false; for (auto const & entry : m_entries) { if (get_attribute_kind(entry.m_attr.c_str()) == attribute_kind::Prioritized) { has_prio_attr = true; break; } } if (!has_prio_attr) { throw parser_error("invalid '[priority]' attribute, declaration has not been marked with a prioritized attribute", pos); } } else if (p.curr_is_token(get_parsing_only_tk())) { if (!m_is_abbrev) throw parser_error("invalid '[parsing_only]' attribute, only abbreviations can be " "marked as '[parsing_only]'", pos); m_parsing_only = true; p.next(); } else { bool found = false; for (char const * tk : attr_tokens) { if (p.curr_is_token(tk)) { p.next(); char const * attr = get_attribute_from_token(tk); for (auto const & entry : m_entries) { if (are_incompatible(entry.m_attr.c_str(), attr)) { throw parser_error(sstream() << "invalid attribute [" << attr << "], declaration was already marked with [" << entry.m_attr << "]", pos); } } switch (get_attribute_kind(attr)) { case attribute_kind::Default: case attribute_kind::Prioritized: m_entries = cons(entry(attr), m_entries); break; case attribute_kind::Parametric: { unsigned v = p.parse_small_nat(); if (v == 0) throw parser_error("invalid attribute parameter, value must be positive", pos); p.check_token_next(get_rbracket_tk(), "invalid attribute, ']' expected"); m_entries = cons(entry(attr, v-1), m_entries); break; } case attribute_kind::OptParametric: if (!p.curr_is_token(get_rbracket_tk())) { unsigned v = p.parse_small_nat(); if (v == 0) throw parser_error("invalid attribute parameter, value must be positive", pos); p.check_token_next(get_rbracket_tk(), "invalid attribute, ']' expected"); m_entries = cons(entry(attr, v-1), m_entries); } else { p.check_token_next(get_rbracket_tk(), "invalid attribute, ']' expected"); m_entries = cons(entry(attr), m_entries); } break; case attribute_kind::MultiParametric: { buffer<unsigned> vs; while (true) { unsigned v = p.parse_small_nat(); if (v == 0) throw parser_error("invalid attribute parameter, value must be positive", pos); vs.push_back(v-1); if (p.curr_is_token(get_rbracket_tk())) break; } p.next(); m_entries = cons(entry(attr, to_list(vs)), m_entries); break; } } found = true; break; } } if (!found) break; } } }
environment mk_projections(environment const & env, name const & n, buffer<name> const & proj_names, implicit_infer_kind infer_k, bool inst_implicit) { // Given an inductive datatype C A (where A represent parameters) // intro : Pi A (x_1 : B_1[A]) (x_2 : B_2[A, x_1]) ..., C A // // we generate projections of the form // proj_i A (c : C A) : B_i[A, (proj_1 A n), ..., (proj_{i-1} A n)] // C.rec A (fun (x : C A), B_i[A, ...]) (fun (x_1 ... x_n), x_i) c auto p = get_nparam_intro_rule(env, n); name_generator ngen; unsigned nparams = p.first; inductive::intro_rule intro = p.second; expr intro_type = inductive::intro_rule_type(intro); name rec_name = inductive::get_elim_name(n); declaration ind_decl = env.get(n); if (env.impredicative() && is_prop(ind_decl.get_type())) throw exception(sstream() << "projection generation, '" << n << "' is a proposition"); declaration rec_decl = env.get(rec_name); level_param_names lvl_params = ind_decl.get_univ_params(); levels lvls = param_names_to_levels(lvl_params); buffer<expr> params; // datatype parameters for (unsigned i = 0; i < nparams; i++) { if (!is_pi(intro_type)) throw_ill_formed(n); expr param = mk_local(ngen.next(), binding_name(intro_type), binding_domain(intro_type), binder_info()); intro_type = instantiate(binding_body(intro_type), param); params.push_back(param); } expr C_A = mk_app(mk_constant(n, lvls), params); binder_info c_bi = inst_implicit ? mk_inst_implicit_binder_info() : binder_info(); expr c = mk_local(ngen.next(), name("c"), C_A, c_bi); buffer<expr> intro_type_args; // arguments that are not parameters expr it = intro_type; while (is_pi(it)) { expr local = mk_local(ngen.next(), binding_name(it), binding_domain(it), binding_info(it)); intro_type_args.push_back(local); it = instantiate(binding_body(it), local); } buffer<expr> projs; // projections generated so far unsigned i = 0; environment new_env = env; for (name const & proj_name : proj_names) { if (!is_pi(intro_type)) throw exception(sstream() << "generating projection '" << proj_name << "', '" << n << "' does not have sufficient data"); expr result_type = binding_domain(intro_type); buffer<expr> proj_args; proj_args.append(params); proj_args.push_back(c); expr type_former = Fun(c, result_type); expr minor_premise = Fun(intro_type_args, mk_var(intro_type_args.size() - i - 1)); expr major_premise = c; type_checker tc(new_env); level l = sort_level(tc.ensure_sort(tc.infer(result_type).first).first); levels rec_lvls = append(to_list(l), lvls); expr rec = mk_constant(rec_name, rec_lvls); buffer<expr> rec_args; rec_args.append(params); rec_args.push_back(type_former); rec_args.push_back(minor_premise); rec_args.push_back(major_premise); expr rec_app = mk_app(rec, rec_args); expr proj_type = Pi(proj_args, result_type); proj_type = infer_implicit_params(proj_type, nparams, infer_k); expr proj_val = Fun(proj_args, rec_app); bool opaque = false; bool use_conv_opt = false; declaration new_d = mk_definition(env, proj_name, lvl_params, proj_type, proj_val, opaque, rec_decl.get_module_idx(), use_conv_opt); new_env = module::add(new_env, check(new_env, new_d)); new_env = set_reducible(new_env, proj_name, reducible_status::Reducible); new_env = add_unfold_c_hint(new_env, proj_name, nparams); new_env = save_projection_info(new_env, proj_name, inductive::intro_rule_name(intro), nparams, i, inst_implicit); expr proj = mk_app(mk_app(mk_constant(proj_name, lvls), params), c); intro_type = instantiate(binding_body(intro_type), proj); i++; } return new_env; }
static void check_action(lua_State * L, int idx, std::initializer_list<action_kind> const & ks) { action_kind k = to_notation_action(L, idx).kind(); if (std::find(ks.begin(), ks.end(), k) == ks.end()) throw exception(sstream() << "arg #" << idx << " is a notation action, but it has an unexpected kind"); }
void HandleLinkLine(const char* str, const char* what) { /// Tokenize the input string and load/unload the libraries /// from the list. /// \param str The string output from Geant4 liblist /// \param what The option specifying whether we want to load ('l') or /// unload ('u') libraries // Fill the libs names in the vector std::vector<std::string> libs; std::stringstream sstream(str); unsigned int w = 0; while ( ! sstream.eof() ) { // Read one string std::string token; std::getline(sstream, token, ' '); // Check stream status if ( sstream.bad() ) break; // Check that we got a meaningful tokenonent if ( token.empty() || std::isspace(token[0]) ) continue; if ( token[0] != '-' ) { Warning("LoadLibraryList", "Unknown element %s", token.c_str()); continue; } std::string dir_or_file = token.substr(2,token.size()-2); if ( token[1] == 'L' ) { std::stringstream path; path << gSystem->GetDynamicPath() << ":" << dir_or_file; gSystem->SetDynamicPath(path.str().c_str()); } else if ( token[1] == 'l' ) { std::stringstream ln; ln << "lib" << NoSpaces(dir_or_file) << '.' << gSystem->GetSoExt(); std::string lib(ln.str()); libs.push_back(lib); if ( lib.length() > w ) w = lib.length(); } else { Warning("LoadLibraryList", "Unknown option %s in", token.c_str(), str); continue; } } // Process the vector with libs names and load libraries size_t n = libs.size(); TString sWhat(what); Bool_t load = sWhat.Contains("l"); if (!load && !sWhat.Contains("u")) { std::cerr << " Unknown load action " << what << std::endl; return; } for ( size_t i = 0; i < n; ++i ) { size_t idx = n - i - 1; // Uncomment to debug // size_t m = TMath::Log10(n)+1; // string say=" Loading "; // if ( TString(what).Contains("u") ) say = " Unloading "; // std::cout << say << std::setw(m) << (i+1) // << "/" << std::setw(m) << n // << ": " << std::setw(w) << libs[idx] // << std::endl; // << std::flush; int result = 0; if ( libs[idx].c_str() ) { if (load) result = gSystem->Load(libs[idx].c_str()); else gSystem->Unload(libs[idx].c_str()); } // Uncomment to debug // if ( TString(what).Contains("l") ) // std::cout << ( result < 0 ? " failed" : " ok" ) << "\r"; } // std::cout << "\n Done" << std::endl; }
int main(int argc, char **argv) { namespace po = boost::program_options; // Variables set by program options std::string basename; std::string opengmFileName; std::string unaryFilename; std::string proposalFilename; std::string outfilename; // Setup and parse options po::options_description options("Stereo arguments"); options.add_options() ("help", "Display this help message") ("image", po::value<std::string>(&basename)->required(), "Name of image (without extension)") ("kappa", po::value<float>(&StereoClique::kappa)->default_value(0.001), "Truncation for stereo prior") ("alpha", po::value<float>(&StereoClique::alpha)->default_value(10), "Max gradient for stereo prior") ("lambda", po::value<float>(&StereoClique::scale)->default_value(20000), "Scale for stereo prior") ("output", po::value<std::string>(&outfilename)->required(), "Output file name") ("ogmFile", po::value<std::string>(&opengmFileName)->required(), "Opengm file name") ; po::positional_options_description positionalOpts; positionalOpts.add("image", 1); positionalOpts.add("ogmFile", 2); positionalOpts.add("output", 3); po::variables_map vm; try { po::store(po::command_line_parser(argc, argv). options(options).positional(positionalOpts).run(), vm); if (vm.count("help")) { std::cout << options; exit(0); } po::notify(vm); } catch (std::exception& e) { std::cout << "Parsing error: " << e.what() << "\n"; std::cout << "Usage: denoise [options] basename\n"; std::cout << options; exit(-1); } unaryFilename = basename + ".unary"; proposalFilename = basename + ".proposals"; // Read stored unaries and proposed moves std::cout << "Reading proposals...\n"; std::vector<cv::Mat> proposals = ReadProposals(proposalFilename); std::cout << "Reading unaries...\n"; std::vector<cv::Mat> unaries = ReadUnaries(unaryFilename); cv::Mat image(height, width, CV_32FC1); std::vector<Label> current(width*height, 0); std::cout << "Setting up energy...\n"; MultilabelEnergy energyFunction = SetupEnergy(proposals, unaries); { // Read image from opengm output file std::ifstream ogmFile(opengmFileName); std::string line = "foo"; while (line != "%states" && line != "") std::getline(ogmFile, line); if (line == "") { std::cout << "Didn't find states\n"; exit(-1); } std::getline(ogmFile, line); std::stringstream sstream(line); for (int i = 0; i < width*height; ++i) { int label; sstream >> label; sstream.ignore(2); current[i] = label; } } for (int i = 0; i < height; ++i) for (int j = 0; j < width; ++j) image.at<float>(i, j) = proposals[current[i*width+j]].at<float>(i, j); // Write out results image.convertTo(image, CV_8U, 1.0, 0); cv::imwrite(outfilename.c_str(), image); REAL energy = energyFunction.computeEnergy(current); std::cout << "Final Energy: " << energy << std::endl; return 0; }
void Compiler::Parse(const String& filename, const String& scriptText) { std::stringstream sstream(scriptText); Compiler::Parse(filename, sstream); }
static void check_choice(lua_State * L, int idx) { if (!is_choice(to_expr(L, idx))) throw exception(sstream() << "arg #" << idx << " is not a choice-expression"); }
void Settings::Load() { { std::string path = "../data/"; std::ifstream stream(path + "Guards.txt"); std::string row; std::string split; std::vector<sf::Vector2f> waypoints; sf::Vector2f vect; if(stream.is_open()) { while(!stream.eof()) { std::getline(stream, row); if(row.find("§") != std::string::npos) { if(ms_guards.size() > 0) { m_allGuardWaypoints.insert(std::pair<int, std::vector<sf::Vector2f>>(ms_guards.size() - 1, waypoints)); } waypoints.clear(); std::getline(stream, row); std::istringstream sstream(row); std::vector<std::string> tokens; copy(std::istream_iterator<std::string>(sstream), std::istream_iterator<std::string>(), std::back_inserter<std::vector<std::string> >(tokens)); ms_guards.push_back(sf::Vector2f((float)atof(tokens.at(0).c_str()), (float)atof(tokens.at(1).c_str()))); } else if(row.length() > 0) { std::istringstream sstream(row); std::vector<std::string> tokens; copy(std::istream_iterator<std::string>(sstream), std::istream_iterator<std::string>(), std::back_inserter<std::vector<std::string> >(tokens)); vect.x = atof(tokens.at(1).c_str()); vect.y = atof(tokens.at(2).c_str()); waypoints.push_back(vect); } } } m_allGuardWaypoints.insert(std::pair<int, std::vector<sf::Vector2f>>(ms_guards.size() - 1, waypoints)); } { std::string path = "../data/"; std::ifstream stream(path + "EnterExit.txt"); std::string row; std::string split; std::vector<sf::Vector2f> waypoints; sf::Vector2f vect; if(stream.is_open()) { while(!stream.eof()) { std::getline(stream, row); if(row.length() > 0) { std::istringstream sstream(row); std::vector<std::string> tokens; copy(std::istream_iterator<std::string>(sstream), std::istream_iterator<std::string>(), std::back_inserter<std::vector<std::string> >(tokens)); vect.x = atof(tokens.at(0).c_str()); vect.y = atof(tokens.at(1).c_str()); ms_enter = vect; } std::getline(stream, row); if(row.length() > 0) { std::istringstream sstream(row); std::vector<std::string> tokens; copy(std::istream_iterator<std::string>(sstream), std::istream_iterator<std::string>(), std::back_inserter<std::vector<std::string> >(tokens)); vect.x = atof(tokens.at(0).c_str()); vect.y = atof(tokens.at(1).c_str()); ms_exit = vect; } } } } }
void check_macro(expr const & m) const { if (!is_macro(m) || macro_num_args(m) != 1) throw exception(sstream() << "invalid '" << m_proj_name << "' projection macro, incorrect number of arguments"); }
[[ noreturn ]] static void throw_ill_formed(name const & n) { throw exception(sstream() << "projection generation, '" << n << "' is an ill-formed inductive datatype"); }
static void check_identifier(parser & p, environment const & env, name const & ns, name const & id) { name full_id = ns + id; if (!env.find(full_id)) throw parser_error(sstream() << "invalid 'using' command, unknown declaration '" << full_id << "'", p.pos()); }
int pcl::MTLReader::read (const std::string& mtl_file_path) { if (mtl_file_path == "" || !boost::filesystem::exists (mtl_file_path)) { PCL_ERROR ("[pcl::MTLReader::read] Could not find file '%s'.\n", mtl_file_path.c_str ()); return (-1); } std::ifstream mtl_file; mtl_file.open (mtl_file_path.c_str (), std::ios::binary); if (!mtl_file.is_open () || mtl_file.fail ()) { PCL_ERROR ("[pcl::MTLReader::read] Could not open file '%s'! Error : %s\n", mtl_file_path.c_str (), strerror(errno)); mtl_file.close (); return (-1); } std::string line; std::vector<std::string> st; boost::filesystem::path parent_path = mtl_file_path.c_str (); parent_path = parent_path.parent_path (); try { while (!mtl_file.eof ()) { getline (mtl_file, line); // Ignore empty lines if (line == "") continue; // Tokenize the line std::stringstream sstream (line); sstream.imbue (std::locale::classic ()); line = sstream.str (); boost::trim (line); boost::split (st, line, boost::is_any_of ("\t\r "), boost::token_compress_on); // Ignore comments if (st[0] == "#") continue; if (st[0] == "newmtl") { materials_.push_back (pcl::TexMaterial ()); materials_.back ().tex_name = st[1]; continue; } if (st[0] == "Ka" || st[0] == "Kd" || st[0] == "Ks") { if (st[1] == "spectral") { PCL_ERROR ("[pcl::MTLReader::read] Can't handle spectral files!\n"); mtl_file.close (); materials_.clear (); return (-1); } else { pcl::TexMaterial::RGB &rgb = materials_.back ().tex_Ka; if (st[0] == "Kd") rgb = materials_.back ().tex_Kd; else if (st[0] == "Ks") rgb = materials_.back ().tex_Ks; if (st[1] == "xyz") { if (fillRGBfromXYZ (st, rgb)) { PCL_ERROR ("[pcl::MTLReader::read] Could not convert %s to RGB values", line.c_str ()); mtl_file.close (); materials_.clear (); return (-1); } } else { if (fillRGBfromRGB (st, rgb)) { PCL_ERROR ("[pcl::MTLReader::read] Could not convert %s to RGB values", line.c_str ()); mtl_file.close (); materials_.clear (); return (-1); } } } continue; } if (st[0] == "illum") { try { materials_.back ().tex_illum = boost::lexical_cast<int> (st[1]); } catch (boost::bad_lexical_cast &) { PCL_ERROR ("[pcl::MTLReader::read] Could not convert %s to illumination model", line.c_str ()); mtl_file.close (); materials_.clear (); return (-1); } continue; } if (st[0] == "d") { if (st.size () > 2) { try { materials_.back ().tex_d = boost::lexical_cast<float> (st[2]); } catch (boost::bad_lexical_cast &) { PCL_ERROR ("[pcl::MTLReader::read] Could not convert %s to transparency value", line.c_str ()); mtl_file.close (); materials_.clear (); return (-1); } } else { try { materials_.back ().tex_d = boost::lexical_cast<float> (st[1]); } catch (boost::bad_lexical_cast &) { PCL_ERROR ("[pcl::MTLReader::read] Could not convert %s to transparency value", line.c_str ()); mtl_file.close (); materials_.clear (); return (-1); } } continue; } if (st[0] == "Ns") { try { materials_.back ().tex_d = boost::lexical_cast<float> (st[1]); } catch (boost::bad_lexical_cast &) { PCL_ERROR ("[pcl::MTLReader::read] Could not convert %s to shininess value", line.c_str ()); mtl_file.close (); materials_.clear (); return (-1); } continue; } if (st[0] == "map_Kd") { boost::filesystem::path full_path = parent_path; full_path/= st.back ().c_str (); materials_.back ().tex_file = full_path.string (); continue; } // other elements? we don't care for now } } catch (const char *exception) { PCL_ERROR ("[pcl::MTLReader::read] %s\n", exception); mtl_file.close (); materials_.clear (); return (-1); } return (0); }
int main(int argc, char **argv) { if (argc == 1) PrintHelpInfo(); else { if (!ReadParameter(argc, argv)) { std::cerr << "Bad Parameters.\n"; return 1; } ReadConfig(configFileName); if (compress) { // Compress db_compress::Compressor compressor(outputFileName, schema, config); int iter_cnt = 0; while (1) { std::cout << "Iteration " << ++iter_cnt << " Starts\n"; std::ifstream inFile(inputFileName); std::string str; int tuple_cnt = 0; while (std::getline(inFile,str)) { std::stringstream sstream(str); std::string item; db_compress::Tuple tuple(schema.attr_type.size()); size_t count = 0; while (std::getline(sstream, item, ',')) { AppendAttr(&tuple, item, attr_type[count], count); ++ count; } // The last item might be empty string if (str[str.length() - 1] == ',') { AppendAttr(&tuple, "", attr_type[count], count); ++ count; } if (count != attr_type.size()) { std::cerr << "File Format Error!\n"; } compressor.ReadTuple(tuple); if (!compressor.RequireFullPass() && ++ tuple_cnt >= NonFullPassStopPoint) { break; } } compressor.EndOfData(); if (!compressor.RequireMoreIterations()) break; } } else { // Decompress db_compress::Decompressor decompressor(inputFileName, schema); std::ofstream outFile(outputFileName); decompressor.Init(); while (decompressor.HasNext()) { db_compress::Tuple tuple(attr_type.size()); decompressor.ReadNextTuple(&tuple); for (size_t i = 0; i < attr_type.size(); ++i) { std::string str = ExtractAttr(tuple, attr_type[i], i); outFile << str << (i == attr_type.size() - 1 ? '\n' : ','); } } } } return 0; }