static int visit_child(GtFeatureNode* fn, void *nti, GtError *err) { NodeTraverseInfo* gt_genome_node_info; int had_err = 0; gt_genome_node_info = (NodeTraverseInfo*) nti; gt_error_check(err); if (gt_feature_node_has_children(fn)) { GtFeatureNode *oldparent = gt_genome_node_info->parent; had_err = process_node(gt_genome_node_info->diagram, fn, gt_genome_node_info->parent, err); if (!had_err) { gt_genome_node_info->parent = fn; had_err = gt_feature_node_traverse_direct_children(fn, gt_genome_node_info, visit_child, err); } if (!had_err) { gt_genome_node_info->parent = oldparent; } } else { had_err = process_node(gt_genome_node_info->diagram, fn, gt_genome_node_info->parent, err); } return had_err; }
static memerr process_node(rewrite_sampler_accesses_context *ctx, node *n, essl_bool change_type) { if(_essl_ptrset_has(&ctx->visited, n)) { return MEM_OK; } if(_essl_node_is_texture_operation(n)) { node *sampler; node *swz; assert(change_type == ESSL_FALSE); ESSL_CHECK(sampler = GET_CHILD(n, 0)); ESSL_CHECK(swz = _essl_new_unary_expression(ctx->pool, EXPR_OP_SWIZZLE, sampler)); _essl_ensure_compatible_node(swz, sampler); swz->expr.u.swizzle = _essl_create_scalar_swizzle(0); SET_CHILD(n, 0, swz); ESSL_CHECK(process_node(ctx, sampler, ESSL_TRUE)); } if(change_type == ESSL_TRUE) { if(n->hdr.kind == EXPR_KIND_LOAD && _essl_type_is_or_has_sampler(n->hdr.type)) { ESSL_CHECK(n->hdr.type = _essl_get_type_with_given_vec_size(ctx->typestor_ctx, n->hdr.type, 4)); ESSL_CHECK(_essl_ptrset_insert(&ctx->visited, n)); return MEM_OK; } if (n->hdr.kind == EXPR_KIND_PHI) { phi_source *src; for (src = n->expr.u.phi.sources; src != 0; src = src->next) { ESSL_CHECK(process_node(ctx, src->source, change_type)); } }else { unsigned i; for (i = 0; i < GET_N_CHILDREN(n); ++i) { node *child = GET_CHILD(n, i); ESSL_CHECK(process_node(ctx, child, change_type)); } } ESSL_CHECK(n->hdr.type = _essl_get_type_with_given_vec_size(ctx->typestor_ctx, n->hdr.type, 4)); } ESSL_CHECK(_essl_ptrset_insert(&ctx->visited, n)); return MEM_OK; }
bool gui_color_scheme::load(const string& filename) { // reset old data (this gives the ability to reload the scheme) colors.clear(); // xml::xml_doc ui_doc = x->process_file(oclraster::data_path(filename), false); // TODO: DTD! if(!ui_doc.valid) { oclr_error("couldn't process color scheme file %s!", filename); return false; } const size_t doc_version = ui_doc.get<size_t>("a2e_color_scheme.version"); if(doc_version != A2E_COLOR_SCHEME_VERSION) { oclr_error("invalid color scheme version: %u (should be %u)!", doc_version, A2E_COLOR_SCHEME_VERSION); return false; } // process nodes const auto scheme_node = ui_doc.get_node("a2e_color_scheme"); for(const auto& node : scheme_node->children) { if(node.first[0] != '#') { process_node(node.second, nullptr); } } return true; }
void cpp_from_isl::process_node(isl_ast_node *node) { auto type = isl_ast_node_get_type(node); switch(type) { case isl_ast_node_for: process_for(node); break; case isl_ast_node_if: process_if(node); break; case isl_ast_node_block: process_block(node); break; case isl_ast_node_user: process_user(node); break; case isl_ast_node_mark: { // TODO: label the stmt? auto marked_node = isl_ast_node_mark_get_node(node); process_node(marked_node); isl_ast_node_free(marked_node); break; } default: throw error("Unexpected AST node type."); } }
Model* create_model(char* filename, GLint shader_program) { struct aiScene* scene = aiImportFile(filename, aiProcess_Triangulate); if (!scene) { gl_log(ERROR, "Cannot open scene file: %s", filename); return 0; } gl_log(INFO, "Loading model: %s", filename); gl_log(INFO, "%d animations", scene->mNumAnimations); gl_log(INFO, "%d cameras", scene->mNumCameras); gl_log(INFO, "%d lights", scene->mNumLights); gl_log(INFO, "%d materials", scene->mNumMaterials); gl_log(INFO, "%d meshes", scene->mNumMeshes); gl_log(INFO, "%d textures", scene->mNumTextures); GLint light_position = glGetUniformLocation(shader_program, "light.position"); GLint light_ambient = glGetUniformLocation(shader_program, "light.ambient_color"); GLint light_diffuse = glGetUniformLocation(shader_program, "light.diffuse_color"); GLint light_specular = glGetUniformLocation(shader_program, "light.specular_color"); glUniform3f(light_position, 0.0, 100.0, 10.0); glUniform3f(light_ambient, 1.0f, 1.0f, 1.0f); glUniform3f(light_diffuse, 1.0f, 1.0f, 1.0f); glUniform3f(light_specular, 1.0f, 1.0f, 1.0f); Model* model = malloc(sizeof(Model)); model->num_meshes = scene->mNumMeshes; model->meshes = malloc(sizeof(Mesh*) * scene->mNumMeshes); process_node(model, scene->mRootNode, scene); model->shader_program = shader_program; return model; }
void cpp_from_isl::process_block(isl_ast_node *node) { // The generate AST is weird: // Blocks have at most 2 statements. // If there are more consecutive statements, // all but the last are grouped into a nested block, // and so on recursively. //auto block = make_shared<block_statement>(); //m_ctx->push(&block->statements); auto list = isl_ast_node_block_get_children(node); int n_children = isl_ast_node_list_n_ast_node(list); for(int i = 0; i < n_children; ++i) { auto child = isl_ast_node_list_get_ast_node(list, i); process_node(child); isl_ast_node_free(child); } isl_ast_node_list_free(list); //m_ctx->pop(); //m_ctx->add(block); }
int convert_anim(const char *infname) { int i, bufsz; const struct aiScene *aiscn; struct goat3d *goat; char *outfname; bufsz = output_filename(0, 0, infname, "goatanim"); outfname = alloca(bufsz); output_filename(outfname, bufsz, infname, "goatanim"); printf("converting %s -> %s\n", infname, outfname); if(!(aiscn = aiImportFile(infname, ANM_PPFLAGS))) { fprintf(stderr, "failed to import %s\n", infname); return -1; } goat = goat3d_create(); for(i=0; i<(int)aiscn->mRootNode->mNumChildren; i++) { process_node(goat, 0, aiscn->mRootNode->mChildren[i]); } for(i=0; i<aiscn->mNumAnimations; i++) { if(process_anim(goat, aiscn->mAnimations[i]) == -1) { return -1; } } goat3d_save_anim(goat, outfname); goat3d_free(goat); aiReleaseImport(aiscn); return 0; }
GLboolean convert_model_file(const std::string& source_path, const std::string& target_path){ Assimp::Importer importer; std::unordered_map<std::string, GLuint> bone_id_map; const aiScene* scene = importer.ReadFile(source_path, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs); if(!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) { std::cout << __FILE__ << ":" << __LINE__ << ": " << "ERROR: Assimp failed to load model: " << importer.GetErrorString() << std::endl; errorlogger("ERROR: Assimp failed to load model: ", importer.GetErrorString()); return false; } std::vector<std::string> mesh_names; std::string filename = split(target_path, '/').back(); std::string modelname = split(filename, '.')[0]; process_node(scene->mRootNode, scene, mesh_names, bone_id_map, modelname); if (file_exists(target_path)) { std::cout << __FILE__ << ":" << __LINE__ << ": " << "ERROR: Failed to store binary model, target file exists: " << target_path << std::endl; errorlogger("ERROR: Failed to store binary model, target file exists: ", target_path.c_str()); return false; } std::ofstream contentf (target_path.c_str(), std::ios::binary); if (!contentf.is_open()){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "ERROR: Failed to open content file for storing model data: " << target_path << std::endl; errorlogger("ERROR: Failed to open content file for storing model data: ", target_path.c_str()); return false; } GLuint mesh_count = mesh_names.size(); contentf.write(reinterpret_cast<const char *>(&mesh_count), sizeof(GLuint)); for (const auto &mesh_name : mesh_names) { if (!write_string_to_binary_file(contentf, mesh_name)) { std::cout << __FILE__ << ":" << __LINE__ << ": " << "ERROR: Cannot add empty mesh name as model mesh key for: " << target_path << std::endl; errorlogger("ERROR: Cannot add empty mesh name as model mesh key for: ", target_path.c_str()); return false; } } if (scene->HasAnimations()) { contentf.write(reinterpret_cast<const char *>(&Utility_consts::TRUE_BOOL), sizeof(GLuint)); if (!store_binary_animation_set(scene, modelname, bone_id_map)){ std::cout << __FILE__ << ":" << __LINE__ << ": " << "ERROR: Failed to store animation set for model: " << target_path << std::endl; errorlogger("ERROR: Failed to store animation set for model: ", target_path.c_str()); contentf.close(); return false; } } else{ contentf.write(reinterpret_cast<const char *>(&Utility_consts::FALSE_BOOL), sizeof(GLuint)); } contentf.close(); return true; }
static void process_node(Model* model, struct aiNode* node, struct aiScene* scene) { for (int i = 0; i < node->mNumMeshes; i++) { struct aiMesh* mesh = scene->mMeshes[node->mMeshes[i]]; model->meshes[node->mMeshes[i]] = process_mesh(mesh, scene); } for (int i = 0; i < node->mNumChildren; i++) { process_node(model, node->mChildren[i], scene); } }
void cpp_from_isl::process_if(isl_ast_node *node) { auto cond_expr = isl_ast_node_if_get_cond(node); auto true_node = isl_ast_node_if_get_then(node); auto false_node = isl_ast_node_if_get_else(node); auto if_stmt = make_shared<if_statement>(); if_stmt->condition = process_expr(cond_expr); { vector<statement_ptr> stmts; m_ctx->push(&stmts); process_node(true_node); m_ctx->pop(); if (stmts.size() == 1) if_stmt->true_part = stmts.front(); else if_stmt->true_part = block(stmts); } if (false_node) { vector<statement_ptr> stmts; m_ctx->push(&stmts); process_node(false_node); m_ctx->pop(); if (stmts.size() == 1) if_stmt->false_part = stmts.front(); else if_stmt->false_part = block(stmts); } m_ctx->add(if_stmt); isl_ast_expr_free(cond_expr); isl_ast_node_free(true_node); isl_ast_node_free(false_node); }
static memerr handle_block(rewrite_sampler_accesses_context *ctx, basic_block *b) { control_dependent_operation *c_op; for(c_op = b->control_dependent_ops; c_op != 0; c_op = c_op->next) { ESSL_CHECK(process_node(ctx, c_op->op, ESSL_FALSE)); } return MEM_OK; }
void process_list(struct node* first) { #pragma omp parallel { #pragma omp single for (struct node* n = first; n != NULL; n = n->next) { #pragma omp task firstprivate(n) process_node(n); } } }
static void process_tree(proto_tree *protocol_tree, ph_stats_t* ps, guint pkt_len) { proto_node *ptree_node; ptree_node = ((proto_node *)protocol_tree)->first_child; if (!ptree_node) { return; } process_node(ptree_node, ps->stats_tree, ps, pkt_len); }
int output_multi_t::node_modify(osmid_t id, double lat, double lon, const taglist_t &tags) { if (m_processor->interests(geometry_processor::interest_node)) { // TODO - need to know it's a node? delete_from_output(id); // TODO: need to mark any ways or relations using it - depends on what // type of output this is... delegate to the geometry processor?? return process_node(id, lat, lon, tags); } else { return 0; } }
void process_node(const aiNode* node, const aiScene* scene, std::vector<std::string>& mesh_names, std::unordered_map<std::string, GLuint>& bone_id_map, const std::string& modelname){ for(GLuint i = 0; i < node->mNumMeshes; i++) { aiMesh* mesh = scene->mMeshes[node->mMeshes[i]]; mesh_names.push_back(process_mesh(mesh, scene, bone_id_map, modelname)); } for(GLuint i = 0; i < node->mNumChildren; i++) { process_node(node->mChildren[i], scene, mesh_names, bone_id_map, modelname); } }
void process_node(struct goat3d *goat, struct goat3d_node *parent, struct aiNode *ainode) { int i; struct goat3d_node *node; node = goat3d_create_node(); goat3d_set_node_name(node, ainode->mName.data); for(i=0; i<ainode->mNumChildren; i++) { process_node(goat, node, ainode->mChildren[i]); } goat3d_add_node(goat, node); }
int process_nodes( xmlNode *node) { xmlNode *current; for (current = node; current != NULL; current = current->next) { if (!strcmp((const char *)current->name, node_name)) process_node(current); } return(PBSE_NONE); } /* END process_nodes() */
void cpp_from_isl::process_for(isl_ast_node *node) { auto iter_expr = isl_ast_node_for_get_iterator(node); auto init_expr = isl_ast_node_for_get_init(node); auto cond_expr = isl_ast_node_for_get_cond(node); auto inc_expr = isl_ast_node_for_get_inc(node); auto body_node = isl_ast_node_for_get_body(node); auto iter = process_expr(iter_expr); auto init = process_expr(init_expr); auto cond = process_expr(cond_expr); auto inc = process_expr(inc_expr); auto iter_id = dynamic_pointer_cast<id_expression>(iter); if (!iter_id) throw error("Iterator expression is not an identifier."); auto iter_decl = decl_expr(make_shared<basic_type>("int"), *iter_id, init); auto for_stmt = make_shared<for_statement>(); for_stmt->initialization = iter_decl; for_stmt->condition = cond; for_stmt->update = binop(op::assign_add, iter, inc); { vector<statement_ptr> stmts; m_ctx->push(&stmts); process_node(body_node); m_ctx->pop(); if (stmts.size() == 1) for_stmt->body = stmts.front(); else for_stmt->body = block(stmts); } m_ctx->add(for_stmt); isl_ast_expr_free(iter_expr); isl_ast_expr_free(init_expr); isl_ast_expr_free(cond_expr); isl_ast_expr_free(inc_expr); isl_ast_node_free(body_node); }
//Infix notation: X + Y //An infix expression is produced by the inorder traversal void inorder(BTree* node) { if(node == NULL) { return; } if(node->value->type == IS_OP) { printf("("); } inorder(node->left); process_node(node->value); inorder(node->right); if(node->value->type == IS_OP) { printf(")"); } }
int process_nodes( boost::ptr_vector<std::string>& status, xmlNode *node) { xmlNode *current; for (current = node; current != NULL; current = current->next) { if (!strcmp((const char *)current->name, node_name)) process_node(status, current); } return(PBSE_NONE); } /* END process_nodes() */
void preorder(BTree* node) { if(node == NULL) { return; } if(node->left != NULL || node->right != NULL) { printf("("); } process_node(node->value); preorder(node->left); preorder(node->right); if(node->left != NULL || node->right != NULL) { printf(")"); } }
int convert(const char *infname) { int i, bufsz; const struct aiScene *aiscn; struct goat3d *goat; char *outfname; bufsz = output_filename(0, 0, infname, "goat3d"); outfname = alloca(bufsz); output_filename(outfname, bufsz, infname, "goat3d"); printf("converting %s -> %s\n", infname, outfname); if(!(aiscn = aiImportFile(infname, SCE_PPFLAGS))) { fprintf(stderr, "failed to import %s\n", infname); return -1; } goat = goat3d_create(); for(i=0; i<(int)aiscn->mNumMaterials; i++) { struct aiMaterial *aimat = aiscn->mMaterials[i]; struct goat3d_material *mat = goat3d_create_mtl(); process_material(mat, aimat); goat3d_add_mtl(goat, mat); } for(i=0; i<(int)aiscn->mNumMeshes; i++) { struct aiMesh *aimesh = aiscn->mMeshes[i]; struct goat3d_mesh *mesh = goat3d_create_mesh(); process_mesh(goat, mesh, aimesh); goat3d_add_mesh(goat, mesh); } for(i=0; i<(int)aiscn->mRootNode->mNumChildren; i++) { process_node(goat, 0, aiscn->mRootNode->mChildren[i]); } goat3d_save(goat, outfname); goat3d_free(goat); aiReleaseImport(aiscn); return 0; }
static void process_node(proto_node *ptree_node, GNode *parent_stat_node, ph_stats_t *ps, guint pkt_len) { field_info *finfo; ph_stats_node_t *stats; proto_node *proto_sibling_node; GNode *stat_node; finfo = PNODE_FINFO(ptree_node); /* We don't fake protocol nodes we expect them to have a field_info. * Dissection with faked proto tree? */ g_assert(finfo); /* If the field info isn't related to a protocol but to a field, * don't count them, as they don't belong to any protocol. * (happens e.g. for toplevel tree item of desegmentation "[Reassembled TCP Segments]") */ if (finfo->hfinfo->parent != -1) { /* Skip this element, use parent status node */ stat_node = parent_stat_node; stats = STAT_NODE_STATS(stat_node); } else { stat_node = find_stat_node(parent_stat_node, finfo->hfinfo); stats = STAT_NODE_STATS(stat_node); stats->num_pkts_total++; stats->num_bytes_total += pkt_len; } proto_sibling_node = ptree_node->next; if (proto_sibling_node) { /* If the name does not exist for this proto_sibling_node, then it is * not a normal protocol in the top-level tree. It was instead * added as a normal tree such as IPv6's Hop-by-hop Option Header and * should be skipped when creating the protocol hierarchy display. */ if(strlen(PNODE_FINFO(proto_sibling_node)->hfinfo->name) == 0 && ptree_node->next) proto_sibling_node = proto_sibling_node->next; process_node(proto_sibling_node, stat_node, ps, pkt_len); } else { stats->num_pkts_last++; stats->num_bytes_last += pkt_len; } }
/* Traverse a genome node graph with depth first search. */ static int traverse_genome_nodes(GtFeatureNode *fn, void *nti) { NodeTraverseInfo* gt_genome_node_info; int had_err = 0; gt_assert(nti); gt_genome_node_info = (NodeTraverseInfo*) nti; gt_genome_node_info->parent = fn; /* handle root nodes */ had_err = process_node(gt_genome_node_info->diagram, fn, NULL, gt_genome_node_info->err); if (!had_err && gt_feature_node_has_children(fn)) { had_err = gt_feature_node_traverse_direct_children(fn, gt_genome_node_info, visit_child, gt_genome_node_info ->err); } return had_err; }
static void process_tree(proto_tree *protocol_tree, ph_stats_t* ps) { proto_node *ptree_node; /* * If our first item is a comment, skip over it. This keeps * us from having a top-level "Packet comments" item that * steals items from "Frame". */ ptree_node = ((proto_node *)protocol_tree)->first_child; if (ptree_node && ptree_node->finfo->hfinfo->id == pc_proto_id) { ptree_node = ptree_node->next; } if (!ptree_node) { return; } process_node(ptree_node, ps->stats_tree, ps); }
/// Load the xml file into the node bool UILoaderXML::loadFromFile(const String& filename, Widget* root_view) { pugi::xml_document document; pugi::xml_parse_result result = document.load_file(filename.c_str()); if (result) { pugi::xml_node body_node = document.child("body"); if (body_node) { // Children of the body become children of root_view for (auto it = body_node.children().begin(); it != body_node.children().end(); ++it) { process_node((*it), root_view); } } } else { std::cout << "Load result: " << result.description() << std::endl; } return result; }
static switch_status_t mod_logfile_logger(const switch_log_node_t *node, switch_log_level_t level) { return process_node(node, level); }
int main(int argc, char *argv[]) { struct Map_info In, Out; static struct line_pnts *Points; struct line_cats *Cats; struct GModule *module; /* GRASS module for parsing arguments */ struct Option *map_in, *map_out; struct Option *cat_opt, *field_opt, *where_opt, *abcol, *afcol; struct Option *iter_opt, *error_opt; struct Flag *geo_f, *add_f; int chcat, with_z; int layer, mask_type; struct varray *varray; dglGraph_s *graph; int i, geo, nnodes, nlines, j, max_cat; char buf[2000], *covered; /* initialize GIS environment */ G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */ /* initialize module */ module = G_define_module(); module->keywords = _("vector, network, centrality measures"); module->description = _("Computes degree, centrality, betweeness, closeness and eigenvector " "centrality measures in the network."); /* Define the different options as defined in gis.h */ map_in = G_define_standard_option(G_OPT_V_INPUT); field_opt = G_define_standard_option(G_OPT_V_FIELD); map_out = G_define_standard_option(G_OPT_V_OUTPUT); cat_opt = G_define_standard_option(G_OPT_V_CATS); cat_opt->guisection = _("Selection"); where_opt = G_define_standard_option(G_OPT_WHERE); where_opt->guisection = _("Selection"); afcol = G_define_standard_option(G_OPT_COLUMN); afcol->key = "afcolumn"; afcol->required = NO; afcol->description = _("Name of arc forward/both direction(s) cost column"); afcol->guisection = _("Cost"); abcol = G_define_standard_option(G_OPT_COLUMN); abcol->key = "abcolumn"; abcol->required = NO; abcol->description = _("Name of arc backward direction cost column"); abcol->guisection = _("Cost"); deg_opt = G_define_standard_option(G_OPT_COLUMN); deg_opt->key = "degree"; deg_opt->required = NO; deg_opt->description = _("Name of degree centrality column"); deg_opt->guisection = _("Columns"); close_opt = G_define_standard_option(G_OPT_COLUMN); close_opt->key = "closeness"; close_opt->required = NO; close_opt->description = _("Name of closeness centrality column"); close_opt->guisection = _("Columns"); betw_opt = G_define_standard_option(G_OPT_COLUMN); betw_opt->key = "betweenness"; betw_opt->required = NO; betw_opt->description = _("Name of betweenness centrality column"); betw_opt->guisection = _("Columns"); eigen_opt = G_define_standard_option(G_OPT_COLUMN); eigen_opt->key = "eigenvector"; eigen_opt->required = NO; eigen_opt->description = _("Name of eigenvector centrality column"); eigen_opt->guisection = _("Columns"); iter_opt = G_define_option(); iter_opt->key = "iterations"; iter_opt->answer = "1000"; iter_opt->type = TYPE_INTEGER; iter_opt->required = NO; iter_opt->description = _("Maximum number of iterations to compute eigenvector centrality"); error_opt = G_define_option(); error_opt->key = "error"; error_opt->answer = "0.1"; error_opt->type = TYPE_DOUBLE; error_opt->required = NO; error_opt->description = _("Cummulative error tolerance for eigenvector centrality"); geo_f = G_define_flag(); geo_f->key = 'g'; geo_f->description = _("Use geodesic calculation for longitude-latitude locations"); add_f = G_define_flag(); add_f->key = 'a'; add_f->description = _("Add points on nodes"); /* options and flags parser */ if (G_parser(argc, argv)) exit(EXIT_FAILURE); /* TODO: make an option for this */ mask_type = GV_LINE | GV_BOUNDARY; Points = Vect_new_line_struct(); Cats = Vect_new_cats_struct(); Vect_check_input_output_name(map_in->answer, map_out->answer, GV_FATAL_EXIT); Vect_set_open_level(2); if (1 > Vect_open_old(&In, map_in->answer, "")) G_fatal_error(_("Unable to open vector map <%s>"), map_in->answer); with_z = Vect_is_3d(&In); if (0 > Vect_open_new(&Out, map_out->answer, with_z)) { Vect_close(&In); G_fatal_error(_("Unable to create vector map <%s>"), map_out->answer); } if (geo_f->answer) { geo = 1; if (G_projection() != PROJECTION_LL) G_warning(_("The current projection is not longitude-latitude")); } else geo = 0; /* parse filter option and select appropriate lines */ layer = atoi(field_opt->answer); chcat = (NetA_initialise_varray (&In, layer, mask_type, where_opt->answer, cat_opt->answer, &varray) == 1); /* Create table */ Fi = Vect_default_field_info(&Out, 1, NULL, GV_1TABLE); Vect_map_add_dblink(&Out, 1, NULL, Fi->table, "cat", Fi->database, Fi->driver); db_init_string(&sql); driver = db_start_driver_open_database(Fi->driver, Fi->database); if (driver == NULL) G_fatal_error(_("Unable to open database <%s> by driver <%s>"), Fi->database, Fi->driver); db_init_string(&tmp); if (deg_opt->answer) append_string(&tmp, deg_opt->answer); if (close_opt->answer) append_string(&tmp, close_opt->answer); if (betw_opt->answer) append_string(&tmp, betw_opt->answer); if (eigen_opt->answer) append_string(&tmp, eigen_opt->answer); sprintf(buf, "create table %s(cat integer%s)", Fi->table, db_get_string(&tmp)); db_set_string(&sql, buf); G_debug(2, db_get_string(&sql)); if (db_execute_immediate(driver, &sql) != DB_OK) { db_close_database_shutdown_driver(driver); G_fatal_error(_("Unable to create table: '%s'"), db_get_string(&sql)); } if (db_create_index2(driver, Fi->table, "cat") != DB_OK) G_warning(_("Cannot create index")); if (db_grant_on_table (driver, Fi->table, DB_PRIV_SELECT, DB_GROUP | DB_PUBLIC) != DB_OK) G_fatal_error(_("Cannot grant privileges on table <%s>"), Fi->table); db_begin_transaction(driver); Vect_copy_head_data(&In, &Out); Vect_hist_copy(&In, &Out); Vect_hist_command(&Out); Vect_net_build_graph(&In, mask_type, atoi(field_opt->answer), 0, afcol->answer, abcol->answer, NULL, geo, 0); graph = &(In.graph); nnodes = dglGet_NodeCount(graph); deg = closeness = betw = eigen = NULL; covered = (char *)G_calloc(nnodes + 1, sizeof(char)); if (!covered) G_fatal_error(_("Out of memory")); if (deg_opt->answer) { deg = (double *)G_calloc(nnodes + 1, sizeof(double)); if (!deg) G_fatal_error(_("Out of memory")); } if (close_opt->answer) { closeness = (double *)G_calloc(nnodes + 1, sizeof(double)); if (!closeness) G_fatal_error(_("Out of memory")); } if (betw_opt->answer) { betw = (double *)G_calloc(nnodes + 1, sizeof(double)); if (!betw) G_fatal_error(_("Out of memory")); } if (eigen_opt->answer) { eigen = (double *)G_calloc(nnodes + 1, sizeof(double)); if (!eigen) G_fatal_error(_("Out of memory")); } if (deg_opt->answer) { G_message(_("Computing degree centrality measure")); NetA_degree_centrality(graph, deg); } if (betw_opt->answer || close_opt->answer) { G_message(_("Computing betweenness and/or closeness centrality measure")); NetA_betweenness_closeness(graph, betw, closeness); if (closeness) for (i = 1; i <= nnodes; i++) closeness[i] /= (double)In.cost_multip; } if (eigen_opt->answer) { G_message(_("Computing eigenvector centrality measure")); NetA_eigenvector_centrality(graph, atoi(iter_opt->answer), atof(error_opt->answer), eigen); } nlines = Vect_get_num_lines(&In); G_message(_("Writing data into the table...")); G_percent_reset(); for (i = 1; i <= nlines; i++) { G_percent(i, nlines, 1); int type = Vect_read_line(&In, Points, Cats, i); if (type == GV_POINT && (!chcat || varray->c[i])) { int cat, node; if (!Vect_cat_get(Cats, layer, &cat)) continue; Vect_reset_cats(Cats); Vect_cat_set(Cats, 1, cat); Vect_write_line(&Out, type, Points, Cats); Vect_get_line_nodes(&In, i, &node, NULL); process_node(node, cat); covered[node] = 1; } } if (add_f->answer && !chcat) { max_cat = 0; for (i = 1; i <= nlines; i++) { Vect_read_line(&In, NULL, Cats, i); for (j = 0; j < Cats->n_cats; j++) if (Cats->cat[j] > max_cat) max_cat = Cats->cat[j]; } max_cat++; for (i = 1; i <= nnodes; i++) if (!covered[i]) { Vect_reset_cats(Cats); Vect_cat_set(Cats, 1, max_cat); NetA_add_point_on_node(&In, &Out, i, Cats); process_node(i, max_cat); max_cat++; } } db_commit_transaction(driver); db_close_database_shutdown_driver(driver); G_free(covered); if (deg) G_free(deg); if (closeness) G_free(closeness); if (betw) G_free(betw); if (eigen) G_free(eigen); Vect_build(&Out); Vect_close(&In); Vect_close(&Out); exit(EXIT_SUCCESS); }
int output_multi_t::node_add(osmid_t id, double lat, double lon, const taglist_t &tags) { if (m_processor->interests(geometry_processor::interest_node)) { return process_node(id, lat, lon, tags); } return 0; }
void func_fma_steering::dfs (void (*process_forest) (fma_forest *), void (*process_root) (fma_forest *, fma_root_node *), void (*process_node) (fma_forest *, fma_node *), bool free) { vec<fma_node *> to_process; std::list<fma_forest *>::iterator forest_iter; to_process.create (0); /* For each forest. */ for (forest_iter = this->m_fma_forests.begin (); forest_iter != this->m_fma_forests.end (); forest_iter++) { std::list<fma_root_node *>::iterator root_iter; if (process_forest) process_forest (*forest_iter); /* For each tree root in this forest. */ for (root_iter = (*forest_iter)->get_roots ()->begin (); root_iter != (*forest_iter)->get_roots ()->end (); root_iter++) { if (process_root) process_root (*forest_iter, *root_iter); to_process.safe_push (*root_iter); } /* For each tree node in this forest. */ while (!to_process.is_empty ()) { fma_node *node; std::list<fma_node *>::iterator child_iter; node = to_process.pop (); if (process_node) process_node (*forest_iter, node); /* Absence of children might indicate an alternate root of a *chain*. It's ok to skip it here as the chain will be renamed when processing the canonical root for that chain. */ if (node->get_children ()->empty ()) continue; for (child_iter = node->get_children ()->begin (); child_iter != node->get_children ()->end (); child_iter++) to_process.safe_push (*child_iter); if (free) { if (node->root_p ()) delete static_cast<fma_root_node *> (node); else delete node; } } if (free) delete *forest_iter; } to_process.release (); }