Pg_points_graph::Pg_points_graph( std::vector<Point_on_edge_t> p_points, std::vector<pgr_edge_t> p_edges_of_points, bool p_normal, char p_driving_side, bool p_directed) : m_points(p_points), m_o_points(p_points), m_edges_of_points(p_edges_of_points), m_normal(p_normal), m_driving_side(p_driving_side), m_directed(p_directed) { if (!p_normal) { reverse_sides(); } if (!m_directed) { m_driving_side = 'b'; } check_points(); create_new_edges(); log << "constructor"; }
bool test_no_deduction_points_off(const char* file_name) { boost::vector_property_map<Point_3> points_1; std::vector<std::size_t> indices; std::vector<Point_3> points_2; // read with custom output iterator type dummy_counter::counter = 0; std::ifstream input(file_name); CGAL::read_off_points<dummy_counter>( input, back_inserter(indices), points_1, Kernel()); // read with ordinary pmaps input.clear(); input.close(); input.open(file_name); CGAL::read_off_points( input, back_inserter(points_2), CGAL::Identity_property_map<Point_3>(), Kernel()); return check_points(points_1, points_2, indices); }
t1_decoder_parse_charstrings( T1_Decoder decoder, FT_Byte* charstring_base, FT_UInt charstring_len ) { FT_Error error; T1_Decoder_Zone zone; FT_Byte* ip; FT_Byte* limit; T1_Builder builder = &decoder->builder; FT_Pos x, y, orig_x, orig_y; T1_Hints_Funcs hinter; /* we don't want to touch the source code -- use macro trick */ #define start_point t1_builder_start_point #define check_points t1_builder_check_points #define add_point t1_builder_add_point #define add_point1 t1_builder_add_point1 #define add_contour t1_builder_add_contour #define close_contour t1_builder_close_contour /* First of all, initialize the decoder */ decoder->top = decoder->stack; decoder->zone = decoder->zones; zone = decoder->zones; builder->parse_state = T1_Parse_Start; hinter = (T1_Hints_Funcs)builder->hints_funcs; zone->base = charstring_base; limit = zone->limit = charstring_base + charstring_len; ip = zone->cursor = zone->base; error = PSaux_Err_Ok; x = orig_x = builder->pos_x; y = orig_y = builder->pos_y; /* begin hints recording session, if any */ if ( hinter ) hinter->open( hinter->hints ); /* now, execute loop */ while ( ip < limit ) { FT_Long* top = decoder->top; T1_Operator op = op_none; FT_Long value = 0; /*********************************************************************/ /* */ /* Decode operator or operand */ /* */ /* */ /* first of all, decompress operator or value */ switch ( *ip++ ) { case 1: op = op_hstem; break; case 3: op = op_vstem; break; case 4: op = op_vmoveto; break; case 5: op = op_rlineto; break; case 6: op = op_hlineto; break; case 7: op = op_vlineto; break; case 8: op = op_rrcurveto; break; case 9: op = op_closepath; break; case 10: op = op_callsubr; break; case 11: op = op_return; break; case 13: op = op_hsbw; break; case 14: op = op_endchar; break; case 15: /* undocumented, obsolete operator */ op = op_none; break; case 21: op = op_rmoveto; break; case 22: op = op_hmoveto; break; case 30: op = op_vhcurveto; break; case 31: op = op_hvcurveto; break; case 12: if ( ip > limit ) { FT_ERROR(( "t1_decoder_parse_charstrings: " "invalid escape (12+EOF)\n" )); goto Syntax_Error; } switch ( *ip++ ) { case 0: op = op_dotsection; break; case 1: op = op_vstem3; break; case 2: op = op_hstem3; break; case 6: op = op_seac; break; case 7: op = op_sbw; break; case 12: op = op_div; break; case 16: op = op_callothersubr; break; case 17: op = op_pop; break; case 33: op = op_setcurrentpoint; break; default: FT_ERROR(( "t1_decoder_parse_charstrings: " "invalid escape (12+%d)\n", ip[-1] )); goto Syntax_Error; } break; case 255: /* four bytes integer */ if ( ip + 4 > limit ) { FT_ERROR(( "t1_decoder_parse_charstrings: " "unexpected EOF in integer\n" )); goto Syntax_Error; } value = (FT_Int32)( ((FT_Long)ip[0] << 24) | ((FT_Long)ip[1] << 16) | ((FT_Long)ip[2] << 8 ) | ip[3] ); ip += 4; break; default: if ( ip[-1] >= 32 ) { if ( ip[-1] < 247 ) value = (FT_Long)ip[-1] - 139; else { if ( ++ip > limit ) { FT_ERROR(( "t1_decoder_parse_charstrings: " )); FT_ERROR(( "unexpected EOF in integer\n" )); goto Syntax_Error; } if ( ip[-2] < 251 ) value = ( ( (FT_Long)ip[-2] - 247 ) << 8 ) + ip[-1] + 108; else value = -( ( ( (FT_Long)ip[-2] - 251 ) << 8 ) + ip[-1] + 108 ); } } else { FT_ERROR(( "t1_decoder_parse_charstrings: " "invalid byte (%d)\n", ip[-1] )); goto Syntax_Error; } } /*********************************************************************/ /* */ /* Push value on stack, or process operator */ /* */ /* */ if ( op == op_none ) { if ( top - decoder->stack >= T1_MAX_CHARSTRINGS_OPERANDS ) { FT_ERROR(( "t1_decoder_parse_charstrings: stack overflow!\n" )); goto Syntax_Error; } FT_TRACE4(( " %ld", value )); *top++ = value; decoder->top = top; } else if ( op == op_callothersubr ) /* callothersubr */ { FT_TRACE4(( " callothersubr" )); if ( top - decoder->stack < 2 ) goto Stack_Underflow; top -= 2; switch ( (FT_Int)top[1] ) { case 1: /* start flex feature */ if ( top[0] != 0 ) goto Unexpected_OtherSubr; decoder->flex_state = 1; decoder->num_flex_vectors = 0; if ( start_point( builder, x, y ) || check_points( builder, 6 ) ) goto Fail; break; case 2: /* add flex vectors */ { FT_Int idx; if ( top[0] != 0 ) goto Unexpected_OtherSubr; /* note that we should not add a point for index 0; */ /* this will move our current position to the flex */ /* point without adding any point to the outline */ idx = decoder->num_flex_vectors++; if ( idx > 0 && idx < 7 ) add_point( builder, x, y, (FT_Byte)( idx == 3 || idx == 6 ) ); } break; case 0: /* end flex feature */ if ( top[0] != 3 ) goto Unexpected_OtherSubr; if ( decoder->flex_state == 0 || decoder->num_flex_vectors != 7 ) { FT_ERROR(( "t1_decoder_parse_charstrings: " "unexpected flex end\n" )); goto Syntax_Error; } /* now consume the remaining `pop pop setcurpoint' */ if ( ip + 6 > limit || ip[0] != 12 || ip[1] != 17 || /* pop */ ip[2] != 12 || ip[3] != 17 || /* pop */ ip[4] != 12 || ip[5] != 33 ) /* setcurpoint */ { FT_ERROR(( "t1_decoder_parse_charstrings: " "invalid flex charstring\n" )); goto Syntax_Error; } ip += 6; decoder->flex_state = 0; break; case 3: /* change hints */ if ( top[0] != 1 ) goto Unexpected_OtherSubr; /* eat the following `pop' */ if ( ip + 2 > limit ) { FT_ERROR(( "t1_decoder_parse_charstrings: " "invalid escape (12+%d)\n", ip[-1] )); goto Syntax_Error; } if ( ip[0] != 12 || ip[1] != 17 ) { FT_ERROR(( "t1_decoder_parse_charstrings: " )); FT_ERROR(( "`pop' expected, found (%d %d)\n", ip[0], ip[1] )); goto Syntax_Error; } ip += 2; if ( hinter ) hinter->reset( hinter->hints, builder->current->n_points ); break; case 12: case 13: /* counter control hints, clear stack */ top = decoder->stack; break; case 14: case 15: case 16: case 17: case 18: /* multiple masters */ { PS_Blend blend = decoder->blend; FT_UInt num_points, nn, mm; FT_Long* delta; FT_Long* values; if ( !blend ) { FT_ERROR(( "t1_decoder_parse_charstrings: " )); FT_ERROR(( "unexpected multiple masters operator!\n" )); goto Syntax_Error; } num_points = (FT_UInt)top[1] - 13 + ( top[1] == 18 ); if ( top[0] != (FT_Int)( num_points * blend->num_designs ) ) { FT_ERROR(( "t1_decoder_parse_charstrings: " )); FT_ERROR(( "incorrect number of mm arguments\n" )); goto Syntax_Error; } top -= blend->num_designs * num_points; if ( top < decoder->stack ) goto Stack_Underflow; /* we want to compute: */ /* */ /* a0*w0 + a1*w1 + ... + ak*wk */ /* */ /* but we only have the a0, a1-a0, a2-a0, .. ak-a0 */ /* however, given that w0 + w1 + ... + wk == 1, we can */ /* rewrite it easily as: */ /* */ /* a0 + (a1-a0)*w1 + (a2-a0)*w2 + .. + (ak-a0)*wk */ /* */ /* where k == num_designs-1 */ /* */ /* I guess that's why it's written in this `compact' */ /* form. */ /* */ delta = top + num_points; values = top; for ( nn = 0; nn < num_points; nn++ ) { FT_Long tmp = values[0]; for ( mm = 1; mm < blend->num_designs; mm++ ) tmp += FT_MulFix( *delta++, blend->weight_vector[mm] ); *values++ = tmp; } /* note that `top' will be incremented later by calls to `pop' */ break; } default: Unexpected_OtherSubr: FT_ERROR(( "t1_decoder_parse_charstrings: " "invalid othersubr [%d %d]!\n", top[0], top[1] )); goto Syntax_Error; } decoder->top = top; } else /* general operator */ { FT_Int num_args = t1_args_count[op]; if ( top - decoder->stack < num_args ) goto Stack_Underflow; top -= num_args; switch ( op ) { case op_endchar: FT_TRACE4(( " endchar" )); close_contour( builder ); /* close hints recording session */ if ( hinter ) { if (hinter->close( hinter->hints, builder->current->n_points )) goto Syntax_Error; /* apply hints to the loaded glyph outline now */ hinter->apply( hinter->hints, builder->current, (PSH_Globals) builder->hints_globals, decoder->hint_mode ); } /* add current outline to the glyph slot */ FT_GlyphLoader_Add( builder->loader ); /* return now! */ FT_TRACE4(( "\n\n" )); return PSaux_Err_Ok; case op_hsbw: FT_TRACE4(( " hsbw" )); builder->parse_state = T1_Parse_Have_Width; builder->left_bearing.x += top[0]; builder->advance.x = top[1]; builder->advance.y = 0; orig_x = builder->last.x = x = builder->pos_x + top[0]; orig_y = builder->last.y = y = builder->pos_y; FT_UNUSED( orig_y ); /* the `metrics_only' indicates that we only want to compute */ /* the glyph's metrics (lsb + advance width), not load the */ /* rest of it; so exit immediately */ if ( builder->metrics_only ) return PSaux_Err_Ok; break; case op_seac: /* return immediately after the processing */ return t1operator_seac( decoder, top[0], top[1], top[2], (FT_Int)top[3], (FT_Int)top[4] ); case op_sbw: FT_TRACE4(( " sbw" )); builder->parse_state = T1_Parse_Have_Width; builder->left_bearing.x += top[0]; builder->left_bearing.y += top[1]; builder->advance.x = top[2]; builder->advance.y = top[3]; builder->last.x = x = builder->pos_x + top[0]; builder->last.y = y = builder->pos_y + top[1]; /* the `metrics_only' indicates that we only want to compute */ /* the glyph's metrics (lsb + advance width), not load the */ /* rest of it; so exit immediately */ if ( builder->metrics_only ) return PSaux_Err_Ok; break; case op_closepath: FT_TRACE4(( " closepath" )); close_contour( builder ); if ( !( builder->parse_state == T1_Parse_Have_Path || builder->parse_state == T1_Parse_Have_Moveto ) ) goto Syntax_Error; builder->parse_state = T1_Parse_Have_Width; break; case op_hlineto: FT_TRACE4(( " hlineto" )); if ( start_point( builder, x, y ) ) goto Fail; x += top[0]; goto Add_Line; case op_hmoveto: FT_TRACE4(( " hmoveto" )); x += top[0]; if ( !decoder->flex_state ) { if ( builder->parse_state == T1_Parse_Start ) goto Syntax_Error; builder->parse_state = T1_Parse_Have_Moveto; } break; case op_hvcurveto: FT_TRACE4(( " hvcurveto" )); if ( start_point( builder, x, y ) || check_points( builder, 3 ) ) goto Fail; x += top[0]; add_point( builder, x, y, 0 ); x += top[1]; y += top[2]; add_point( builder, x, y, 0 ); y += top[3]; add_point( builder, x, y, 1 ); break; case op_rlineto: FT_TRACE4(( " rlineto" )); if ( start_point( builder, x, y ) ) goto Fail; x += top[0]; y += top[1]; Add_Line: if ( add_point1( builder, x, y ) ) goto Fail; break; case op_rmoveto: FT_TRACE4(( " rmoveto" )); x += top[0]; y += top[1]; if ( !decoder->flex_state ) { if ( builder->parse_state == T1_Parse_Start ) goto Syntax_Error; builder->parse_state = T1_Parse_Have_Moveto; } break; case op_rrcurveto: FT_TRACE4(( " rcurveto" )); if ( start_point( builder, x, y ) || check_points( builder, 3 ) ) goto Fail; x += top[0]; y += top[1]; add_point( builder, x, y, 0 ); x += top[2]; y += top[3]; add_point( builder, x, y, 0 ); x += top[4]; y += top[5]; add_point( builder, x, y, 1 ); break; case op_vhcurveto: FT_TRACE4(( " vhcurveto" )); if ( start_point( builder, x, y ) || check_points( builder, 3 ) ) goto Fail; y += top[0]; add_point( builder, x, y, 0 ); x += top[1]; y += top[2]; add_point( builder, x, y, 0 ); x += top[3]; add_point( builder, x, y, 1 ); break; case op_vlineto: FT_TRACE4(( " vlineto" )); if ( start_point( builder, x, y ) ) goto Fail; y += top[0]; goto Add_Line; case op_vmoveto: FT_TRACE4(( " vmoveto" )); y += top[0]; if ( !decoder->flex_state ) { if ( builder->parse_state == T1_Parse_Start ) goto Syntax_Error; builder->parse_state = T1_Parse_Have_Moveto; } break; case op_div: FT_TRACE4(( " div" )); if ( top[1] ) { *top = top[0] / top[1]; ++top; } else { FT_ERROR(( "t1_decoder_parse_charstrings: division by 0\n" )); goto Syntax_Error; } break; case op_callsubr: { FT_Int idx; FT_TRACE4(( " callsubr" )); idx = (FT_Int)top[0]; if ( idx < 0 || idx >= (FT_Int)decoder->num_subrs ) { FT_ERROR(( "t1_decoder_parse_charstrings: " "invalid subrs index\n" )); goto Syntax_Error; } if ( zone - decoder->zones >= T1_MAX_SUBRS_CALLS ) { FT_ERROR(( "t1_decoder_parse_charstrings: " "too many nested subrs\n" )); goto Syntax_Error; } zone->cursor = ip; /* save current instruction pointer */ zone++; /* The Type 1 driver stores subroutines without the seed bytes. */ /* The CID driver stores subroutines with seed bytes. This */ /* case is taken care of when decoder->subrs_len == 0. */ zone->base = decoder->subrs[idx]; if ( decoder->subrs_len ) zone->limit = zone->base + decoder->subrs_len[idx]; else { /* We are using subroutines from a CID font. We must adjust */ /* for the seed bytes. */ zone->base += ( decoder->lenIV >= 0 ? decoder->lenIV : 0 ); zone->limit = decoder->subrs[idx + 1]; } zone->cursor = zone->base; if ( !zone->base ) { FT_ERROR(( "t1_decoder_parse_charstrings: " "invoking empty subrs!\n" )); goto Syntax_Error; } decoder->zone = zone; ip = zone->base; limit = zone->limit; break; } case op_pop: FT_TRACE4(( " pop" )); /* theoretically, the arguments are already on the stack */ top++; break; case op_return: FT_TRACE4(( " return" )); if ( zone <= decoder->zones ) { FT_ERROR(( "t1_decoder_parse_charstrings: unexpected return\n" )); goto Syntax_Error; } zone--; ip = zone->cursor; limit = zone->limit; decoder->zone = zone; break; case op_dotsection: FT_TRACE4(( " dotsection" )); break; case op_hstem: FT_TRACE4(( " hstem" )); /* record horizontal hint */ if ( hinter ) { /* top[0] += builder->left_bearing.y; */ hinter->stem( hinter->hints, 1, top ); } break; case op_hstem3: FT_TRACE4(( " hstem3" )); /* record horizontal counter-controlled hints */ if ( hinter ) hinter->stem3( hinter->hints, 1, top ); break; case op_vstem: FT_TRACE4(( " vstem" )); /* record vertical hint */ if ( hinter ) { top[0] += orig_x; hinter->stem( hinter->hints, 0, top ); } break; case op_vstem3: FT_TRACE4(( " vstem3" )); /* record vertical counter-controlled hints */ if ( hinter ) { FT_Pos dx = orig_x; top[0] += dx; top[2] += dx; top[4] += dx; hinter->stem3( hinter->hints, 0, top ); } break; case op_setcurrentpoint: FT_TRACE4(( " setcurrentpoint" )); FT_ERROR(( "t1_decoder_parse_charstrings: " )); FT_ERROR(( "unexpected `setcurrentpoint'\n" )); goto Syntax_Error; default: FT_ERROR(( "t1_decoder_parse_charstrings: " "unhandled opcode %d\n", op )); goto Syntax_Error; } decoder->top = top; } /* general operator processing */ } /* while ip < limit */ FT_TRACE4(( "..end..\n\n" )); Fail: return error; Syntax_Error: return PSaux_Err_Syntax_Error; Stack_Underflow: return PSaux_Err_Stack_Underflow; }
void do_pgr_one_to_many_withPoints( pgr_edge_t *edges, size_t total_edges, Point_on_edge_t *points_p, size_t total_points, pgr_edge_t *edges_of_points, size_t total_edges_of_points, int64_t start_vid, int64_t *end_pidsArr, size_t size_end_pidsArr, char driving_side, bool details, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char ** log_msg, char ** err_msg) { std::ostringstream log; std::ostringstream err; try { pgassert(!(*return_tuples)); pgassert((*return_count) == 0); pgassert(!(*log_msg)); pgassert(!(*err_msg)); /* * DOCUMENT: * - Points are treated as the same point when the pid is the same * therefore when two points have the same pid, but different edge/fraction * an error is generated. */ std::vector< Point_on_edge_t > points(points_p, points_p + total_points); int errcode = check_points(points, log); if (errcode) { *log_msg = strdup(log.str().c_str()); err << "Unexpected point(s) with same pid but different edge/fraction/side combination found."; *err_msg = strdup(err.str().c_str()); return; } std::vector< pgr_edge_t > edges_to_modify(edges_of_points, edges_of_points + total_edges_of_points); std::vector< pgr_edge_t > new_edges; log << "driving_side" << driving_side << "\n"; create_new_edges( points, edges_to_modify, driving_side, new_edges); log << "Inserting points into a c++ vector structure\n"; /* * Eliminating duplicates * & ordering the points */ std::set< int64_t > s_end_vertices(end_pidsArr, end_pidsArr + size_end_pidsArr); std::vector< int64_t > end_vertices(s_end_vertices.begin(), s_end_vertices.end()); log << "start_vid" << start_vid << "\n"; log << "end_vertices"; for (const auto &vid : end_vertices) { log << vid << "\n"; } graphType gType = directed? DIRECTED: UNDIRECTED; std::deque< Path > paths; if (directed) { log << "Working with directed Graph\n"; pgrouting::DirectedGraph digraph( pgrouting::extract_vertices( pgrouting::extract_vertices(edges, total_edges), new_edges), gType); digraph.graph_insert_data(edges, total_edges); digraph.graph_insert_data(new_edges); pgr_dijkstra(digraph, paths, start_vid, end_vertices, only_cost); } else { log << "Working with Undirected Graph\n"; auto vertices(pgrouting::extract_vertices(edges, total_edges)); vertices = pgrouting::extract_vertices(vertices, new_edges); pgrouting::UndirectedGraph undigraph(vertices, gType); vertices.clear(); undigraph.graph_insert_data(edges, total_edges); undigraph.graph_insert_data(new_edges); pgr_dijkstra(undigraph, paths, start_vid, end_vertices, only_cost); } if (!details) { for (auto &path : paths) { eliminate_details(path, edges_to_modify); } } /* * order paths based on the end_pid */ std::sort(paths.begin(), paths.end(), [](const Path &a, const Path &b) { return a.end_id() < b.end_id(); }); size_t count(0); count = count_tuples(paths); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; log << "No paths found between Starting and any of the Ending vertices\n"; *log_msg = strdup(log.str().c_str()); return; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); log << "Converting a set of paths into the tuples\n"; (*return_count) = (collapse_paths(return_tuples, paths)); *log_msg = strdup(log.str().c_str()); pgassert(!(*err_msg)); return; } catch (AssertFailedException &except) { if (*return_tuples) free(*return_tuples); (*return_count) = 0; *log_msg = strdup(log.str().c_str()); err << except.what() << "\n"; *err_msg = strdup(err.str().c_str()); } catch (std::exception& except) { if (*return_tuples) free(*return_tuples); (*return_count) = 0; *log_msg = strdup(log.str().c_str()); err << except.what() << "\n"; *err_msg = strdup(err.str().c_str()); } catch(...) { if (*return_tuples) free(*return_tuples); (*return_count) = 0; *log_msg = strdup(log.str().c_str()); err << "Caught unknown exception!\n"; *err_msg = strdup(err.str().c_str()); } }
int do_pgr_many_to_one_withPoints( pgr_edge_t *edges, size_t total_edges, Point_on_edge_t *points_p, size_t total_points, pgr_edge_t *edges_of_points, size_t total_edges_of_points, int64_t *start_pidsArr, size_t size_start_pidsArr, int64_t end_vid, char driving_side, bool details, bool directed, bool only_cost, General_path_element_t **return_tuples, size_t *return_count, char ** err_msg) { std::ostringstream log; try { std::vector< Point_on_edge_t > points(points_p, points_p + total_points); int errcode = check_points(points, log); if (errcode) { /* Point(s) with same pid but different edge/fraction/side combination found */ *err_msg = strdup(log.str().c_str()); return errcode; } std::vector< pgr_edge_t > edges_to_modify(edges_of_points, edges_of_points + total_edges_of_points); std::vector< pgr_edge_t > new_edges; create_new_edges( points, edges_to_modify, driving_side, new_edges); std::set< int64_t > s_start_vertices(start_pidsArr, start_pidsArr + size_start_pidsArr); std::vector< int64_t > start_vertices(s_start_vertices.begin(), s_start_vertices.end()); graphType gType = directed? DIRECTED: UNDIRECTED; std::deque< Path > paths; if (directed) { log << "Working with directed Graph\n"; pgrouting::DirectedGraph digraph(gType); digraph.graph_insert_data(edges, total_edges); digraph.graph_insert_data(new_edges); pgr_dijkstra(digraph, paths, start_vertices, end_vid, only_cost); } else { log << "Working with Undirected Graph\n"; pgrouting::UndirectedGraph undigraph(gType); undigraph.graph_insert_data(edges, total_edges); undigraph.graph_insert_data(new_edges); pgr_dijkstra(undigraph, paths, start_vertices, end_vid, only_cost); } #if 0 for (auto &path : paths) { adjust_pids(points, path); } #endif if (!details) { for (auto &path : paths) { eliminate_details(path, edges_to_modify); } } /* * order paths based on the start_pid */ std::sort(paths.begin(), paths.end(), [](const Path &a, const Path &b) { return a.start_id() < b.start_id(); }); size_t count(0); count = count_tuples(paths); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; log << "No paths found between Starting and any of the Ending vertices\n"; *err_msg = strdup(log.str().c_str()); return 0; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); log << "Converting a set of paths into the tuples\n"; (*return_count) = (collapse_paths(return_tuples, paths)); #ifndef NDEBUG { std::ostringstream log; log << "OK"; *err_msg = strdup(log.str().c_str()); } #else *err_msg = strdup(log.str().c_str()); #endif return 0; } catch ( ... ) { log << "Caught unknown exception!\n"; *err_msg = strdup(log.str().c_str()); return 1000; } return 0; }
void do_pgr_withPoints( pgr_edge_t *edges, size_t total_edges, Point_on_edge_t *points_p, size_t total_points, pgr_edge_t *edges_of_points, size_t total_edges_of_points, int64_t *start_pidsArr, size_t size_start_pidsArr, int64_t *end_pidsArr, size_t size_end_pidsArr, char driving_side, bool details, bool directed, bool only_cost, bool normal, General_path_element_t **return_tuples, size_t *return_count, char** log_msg, char** notice_msg, char** err_msg) { std::ostringstream log; std::ostringstream notice; std::ostringstream err; try { pgassert(!(*log_msg)); pgassert(!(*notice_msg)); pgassert(!(*err_msg)); pgassert(!(*return_tuples)); pgassert((*return_count) == 0); pgassert(edges || edges_of_points); pgassert(points_p); pgassert(start_pidsArr); pgassert(end_pidsArr); std::vector< Point_on_edge_t > points(points_p, points_p + total_points); if (!normal) { for (auto &point : points) { if (point.side == 'r') { point.side = 'l'; } else if (point.side == 'l') { point.side = 'r'; } point.fraction = 1 - point.fraction; } if (driving_side == 'r') { driving_side = 'l'; } else if (driving_side == 'l') { driving_side = 'r'; } } int errcode = check_points(points, log); if (errcode) { *log_msg = strdup(log.str().c_str()); err << "Unexpected point(s) with same pid" << " but different edge/fraction/side combination found."; *err_msg = pgr_msg(err.str().c_str()); return; } std::vector< pgr_edge_t > edges_to_modify( edges_of_points, edges_of_points + total_edges_of_points); std::vector< pgr_edge_t > new_edges; create_new_edges( points, edges_to_modify, driving_side, new_edges, log); std::vector<int64_t> start_vertices(start_pidsArr, start_pidsArr + size_start_pidsArr); std::vector< int64_t > end_vertices(end_pidsArr, end_pidsArr + size_end_pidsArr); auto vertices(pgrouting::extract_vertices(edges, total_edges)); vertices = pgrouting::extract_vertices(vertices, new_edges); graphType gType = directed? DIRECTED: UNDIRECTED; std::deque< Path > paths; if (directed) { log << "Working with directed Graph\n"; pgrouting::DirectedGraph digraph(vertices, gType); digraph.insert_edges(edges, total_edges); digraph.insert_edges(new_edges); paths = pgr_dijkstra( digraph, start_vertices, end_vertices, only_cost, normal); } else { log << "Working with Undirected Graph\n"; pgrouting::UndirectedGraph undigraph(vertices, gType); undigraph.insert_edges(edges, total_edges); undigraph.insert_edges(new_edges); paths = pgr_dijkstra( undigraph, start_vertices, end_vertices, only_cost, normal); } if (!details) { for (auto &path : paths) { eliminate_details(path, edges_to_modify); } } /* * order paths based on the start_pid, end_pid */ std::sort(paths.begin(), paths.end(), [](const Path &a, const Path &b) -> bool { if (b.start_id() != a.start_id()) { return a.start_id() < b.start_id(); } return a.end_id() < b.end_id(); }); size_t count(0); count = count_tuples(paths); if (count == 0) { (*return_tuples) = NULL; (*return_count) = 0; #if 0 log << "No paths found"; *err_msg = pgr_msg(log.str().c_str()); #endif return; } (*return_tuples) = pgr_alloc(count, (*return_tuples)); log << "Converting a set of paths into the tuples\n"; (*return_count) = (collapse_paths(return_tuples, paths)); *log_msg = log.str().empty()? *log_msg : pgr_msg(log.str().c_str()); *notice_msg = notice.str().empty()? *notice_msg : pgr_msg(notice.str().c_str()); } catch (AssertFailedException &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); } catch (std::exception &except) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; err << except.what(); *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); } catch(...) { (*return_tuples) = pgr_free(*return_tuples); (*return_count) = 0; err << "Caught unknown exception!"; *err_msg = pgr_msg(err.str().c_str()); *log_msg = pgr_msg(log.str().c_str()); } }