Given two vertices, return the edge * connecting them, creating it if it * did not already exist: */
| 2742 | * did not already exist: |
| 2743 | */ |
| 2744 | CV_IMPL int |
| 2745 | cvGraphAddEdgeByPtr( CvGraph* graph, |
| 2746 | CvGraphVtx* start_vtx, CvGraphVtx* end_vtx, |
| 2747 | const CvGraphEdge* _edge, |
| 2748 | CvGraphEdge ** _inserted_edge ) |
| 2749 | { |
| 2750 | CvGraphEdge *edge = 0; |
| 2751 | int result = -1; |
| 2752 | int delta; |
| 2753 | |
| 2754 | if( !graph ) |
| 2755 | CV_Error( CV_StsNullPtr, "graph pointer is NULL" ); |
| 2756 | |
| 2757 | if( !CV_IS_GRAPH_ORIENTED( graph ) && |
| 2758 | (start_vtx->flags & CV_SET_ELEM_IDX_MASK) > (end_vtx->flags & CV_SET_ELEM_IDX_MASK) ) |
| 2759 | { |
| 2760 | CvGraphVtx* t; |
| 2761 | CV_SWAP( start_vtx, end_vtx, t ); |
| 2762 | } |
| 2763 | |
| 2764 | edge = cvFindGraphEdgeByPtr( graph, start_vtx, end_vtx ); |
| 2765 | if( edge ) |
| 2766 | { |
| 2767 | result = 0; |
| 2768 | if( _inserted_edge ) |
| 2769 | *_inserted_edge = edge; |
| 2770 | return result; |
| 2771 | } |
| 2772 | |
| 2773 | if( start_vtx == end_vtx ) |
| 2774 | CV_Error( start_vtx ? CV_StsBadArg : CV_StsNullPtr, |
| 2775 | "vertex pointers coinside (or set to NULL)" ); |
| 2776 | |
| 2777 | edge = (CvGraphEdge*)cvSetNew( (CvSet*)(graph->edges) ); |
| 2778 | assert( edge->flags >= 0 ); |
| 2779 | |
| 2780 | edge->vtx[0] = start_vtx; |
| 2781 | edge->vtx[1] = end_vtx; |
| 2782 | edge->next[0] = start_vtx->first; |
| 2783 | edge->next[1] = end_vtx->first; |
| 2784 | start_vtx->first = end_vtx->first = edge; |
| 2785 | |
| 2786 | delta = graph->edges->elem_size - sizeof(*edge); |
| 2787 | if( _edge ) |
| 2788 | { |
| 2789 | if( delta > 0 ) |
| 2790 | memcpy( edge + 1, _edge + 1, delta ); |
| 2791 | edge->weight = _edge->weight; |
| 2792 | } |
| 2793 | else |
| 2794 | { |
| 2795 | if( delta > 0 ) |
| 2796 | memset( edge + 1, 0, delta ); |
| 2797 | edge->weight = 1.f; |
| 2798 | } |
| 2799 | |
| 2800 | result = 1; |
| 2801 |
no test coverage detected