Remove slice from the middle of the sequence. !!! TODO !!! Implement more efficient algorithm
| 1669 | // Remove slice from the middle of the sequence. |
| 1670 | // !!! TODO !!! Implement more efficient algorithm |
| 1671 | CV_IMPL void |
| 1672 | cvSeqRemoveSlice( CvSeq* seq, CvSlice slice ) |
| 1673 | { |
| 1674 | int total, length; |
| 1675 | |
| 1676 | if( !CV_IS_SEQ(seq) ) |
| 1677 | CV_Error( CV_StsBadArg, "Invalid sequence header" ); |
| 1678 | |
| 1679 | length = cvSliceLength( slice, seq ); |
| 1680 | total = seq->total; |
| 1681 | |
| 1682 | if( slice.start_index < 0 ) |
| 1683 | slice.start_index += total; |
| 1684 | else if( slice.start_index >= total ) |
| 1685 | slice.start_index -= total; |
| 1686 | |
| 1687 | if( (unsigned)slice.start_index >= (unsigned)total ) |
| 1688 | CV_Error( CV_StsOutOfRange, "start slice index is out of range" ); |
| 1689 | |
| 1690 | slice.end_index = slice.start_index + length; |
| 1691 | |
| 1692 | if ( slice.start_index == slice.end_index ) |
| 1693 | return; |
| 1694 | |
| 1695 | if( slice.end_index < total ) |
| 1696 | { |
| 1697 | CvSeqReader reader_to, reader_from; |
| 1698 | int elem_size = seq->elem_size; |
| 1699 | |
| 1700 | cvStartReadSeq( seq, &reader_to ); |
| 1701 | cvStartReadSeq( seq, &reader_from ); |
| 1702 | |
| 1703 | if( slice.start_index > total - slice.end_index ) |
| 1704 | { |
| 1705 | int i, count = seq->total - slice.end_index; |
| 1706 | cvSetSeqReaderPos( &reader_to, slice.start_index ); |
| 1707 | cvSetSeqReaderPos( &reader_from, slice.end_index ); |
| 1708 | |
| 1709 | for( i = 0; i < count; i++ ) |
| 1710 | { |
| 1711 | memcpy( reader_to.ptr, reader_from.ptr, elem_size ); |
| 1712 | CV_NEXT_SEQ_ELEM( elem_size, reader_to ); |
| 1713 | CV_NEXT_SEQ_ELEM( elem_size, reader_from ); |
| 1714 | } |
| 1715 | |
| 1716 | cvSeqPopMulti( seq, 0, slice.end_index - slice.start_index ); |
| 1717 | } |
| 1718 | else |
| 1719 | { |
| 1720 | int i, count = slice.start_index; |
| 1721 | cvSetSeqReaderPos( &reader_to, slice.end_index ); |
| 1722 | cvSetSeqReaderPos( &reader_from, slice.start_index ); |
| 1723 | |
| 1724 | for( i = 0; i < count; i++ ) |
| 1725 | { |
| 1726 | CV_PREV_SEQ_ELEM( elem_size, reader_to ); |
| 1727 | CV_PREV_SEQ_ELEM( elem_size, reader_from ); |
| 1728 |
no test coverage detected