void add_circle(struct dxf_file *dxf, struct Map_info *Map) { int code; char handle[DXF_BUF_SIZE]; /* entity handle, 16 hexadecimal digits */ char layer[DXF_BUF_SIZE]; /* layer name */ int layer_flag = 0; /* indicates if a layer name has been found */ int xflag = 0; /* indicates if a x value has been found */ int yflag = 0; /* indicates if a y value has been found */ int rflag = 0; /* indicates if a radius has been found */ double centerx = 0; /* read in from dxf file */ double centery = 0; /* read in from dxf file */ double radius = 0; /* read in from dxf file */ double zcoor = 0; /* read in from dxf file */ int arr_size = 0; handle[0] = 0; strcpy(layer, UNIDENTIFIED_LAYER); /* read in lines and process information until a 0 is read in */ while ((code = dxf_get_code(dxf)) != 0) { if (code == -2) return; switch (code) { case 5: /* entity handle */ strcpy(handle, dxf_buf); break; case 8: /* layer name */ if (!layer_flag && *dxf_buf) { if (flag_list) { if (!is_layer_in_list(dxf_buf)) add_layer_to_list(dxf_buf, 1); return; } /* skip if (opt_layers != NULL && ( * (flag_invert == 0 && is_layer_in_list == 0) || * (flag_invert == 1 && is_layer_in_list == 1) * ) */ if (opt_layers && flag_invert == is_layer_in_list(dxf_buf)) return; strcpy(layer, dxf_buf); layer_flag = 1; } break; case 10: /* x coordinate */ centerx = atof(dxf_buf); xflag = 1; break; case 20: /* y coordinate */ centery = atof(dxf_buf); yflag = 1; break; case 30: /* z coordinate */ zcoor = atof(dxf_buf); break; case 40: /* radius */ radius = atof(dxf_buf); rflag = 1; break; } } if (xflag && yflag && rflag) { arr_size = make_arc(0, centerx, centery, radius, 0.0, 360.0, zcoor); write_vect(Map, layer, "CIRCLE", handle, "", arr_size, GV_LINE); } return; }
void Arpa2OpenFST::generateFST ( ) { if( arpa_lm_fp.is_open() ){ make_arc( start, //Input state label sb, //Output state label sb, //Input label sb, //Output label 0.0 //Weight ); while( arpa_lm_fp.good() ){ getline( arpa_lm_fp, line ); if( current_order > 0 && line.compare("") != 0 && line.compare(0,1,"\\") != 0 ){ //Process data based on N-gram order vector<string> tokens; istringstream iss(line); copy( istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens) ); //Handle the unigrams if( current_order == 1 ){ if( tokens[1].compare(se) == 0 ){ make_arc( eps, se, se, se, atof(tokens[0].c_str()) ); }else if( tokens[1].compare(sb) == 0 ){ double weight = tokens.size()==3 ? atof(tokens[2].c_str()) : 0.0; make_arc( sb, eps, eps, eps, weight ); }else{ double weight = tokens.size()==3 ? atof(tokens[2].c_str()) : 0.0; make_arc( tokens[1], eps, eps, eps, weight ); make_arc( eps, tokens[1], tokens[current_order], tokens[current_order], atof(tokens[0].c_str()) ); } //Handle the middle-order N-grams }else if( current_order < max_order ){ if( tokens[current_order].compare(se) == 0 ){ make_arc( join(tokens, ",", 1, current_order), tokens[current_order], tokens[current_order], tokens[current_order], atof(tokens[0].c_str()) ); }else{ double weight = tokens.size()==current_order+2 ? atof(tokens[tokens.size()-1].c_str()) : 0.0; make_arc( join(tokens, ",", 1, current_order+1), join(tokens, ",", 2, current_order+1), eps, eps, weight ); make_arc( join(tokens, ",", 1, current_order), join(tokens, ",", 1, current_order+1), tokens[current_order], tokens[current_order], atof(tokens[0].c_str()) ); } //Handle the N-order N-grams }else if( current_order==max_order ){ if( tokens[current_order].compare(se) == 0 ){ make_arc( join(tokens, ",", 1, current_order), tokens[current_order], tokens[current_order], tokens[current_order], atof(tokens[0].c_str()) ); }else{ make_arc( join(tokens, ",", 1, current_order), join(tokens, ",", 2, current_order+1), tokens[current_order], tokens[current_order], atof(tokens[0].c_str()) ); } } } //Parse the header/footer/meta-data. This is not foolproof. //Random header info starting with '\' or 'ngram', etc. may cause problems. if( line.size() > 4 && line.compare( 0, 5, "ngram" ) == 0 ) max_order = (size_t)atoi(&line[6])>max_order ? atoi(&line[6]) : max_order; else if( line.compare( "\\data\\" ) == 0 ) continue; else if( line.compare( "\\end\\" ) == 0 ) break; else if( line.size() > 0 && line.compare( 0, 1, "\\" ) == 0 ){ line.replace(0, 1, ""); if( line.compare( 1, 1, "-" ) == 0 ) line.replace(1, 7, ""); else //Will work up to N=99. line.replace(2, 7, ""); current_order = atoi(&line[0]); } } arpa_lm_fp.close(); }else{ cout << "Unable to open file: " << arpa_lm_file << endl; } }