forked from sonots/opencvx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvsetrow.h
147 lines (140 loc) · 5.21 KB
/
cvsetrow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/** @file */
/* The MIT License
*
* Copyright (c) 2008, Naotoshi Seo <sonots(at)sonots.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CV_SETROW_INCLUDED
#define CV_SETROW_INCLUDED
#include "cv.h"
#include "cvaux.h"
// CVAPI(void) cvSetRows( const CvArr* src, CvArr* dst,
// int start_row, int end_row, int delta_row = 1 );
// CV_INLINE void cvSetRow( const CvArr* src, CvArr* dst, int row );
/**
* Set array row or row span
*
* Following code is faster than using this function because it does not
* require cvCopy()
* @code
* CvMat* submat, submathdr;
* submat = cvGetRows( mat, &submathdr, start_row, end_row, delta_row );
* // Write on submat
* @endcode
*
* @param src Source array
* @param dst Target array. Either of array must be size of setting rows.
* @param start_row Zero-based index of the starting row (inclusive) of the span.
* @param end_row Zero-based index of the ending row (exclusive) of the span.
* @param [delta_row = 1]
* Index step in the row span. That is, the function extracts every
* delta_row-th row from start_row and up to (but not including) end_row.
* @return CVAPI(void)
* @see cvSetRow( src, dst, row ) // cvSetRows( src, dst, row, row + 1 )
*/
CVAPI(void) cvSetRows( const CvArr* src, CvArr* dst,
int start_row, int end_row, int delta_row CV_DEFAULT(1) )
{
int coi;
CvMat *srcmat = (CvMat*)src, srcmatstub;
CvMat *dstmat = (CvMat*)dst, dstmatstub;
CvMat *refmat, refmathdr;
int rows;
CV_FUNCNAME( "cvSetRows" );
__BEGIN__;
if( !CV_IS_MAT(dstmat) )
{
CV_CALL( dstmat = cvGetMat( dstmat, &dstmatstub, &coi ) );
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
}
if( !CV_IS_MAT(srcmat) )
{
CV_CALL( srcmat = cvGetMat( srcmat, &srcmatstub, &coi ) );
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
}
rows = cvFloor( ( end_row - start_row ) / delta_row );
CV_ASSERT( srcmat->rows == rows || dstmat->rows == rows );
if( srcmat->rows == rows )
{
refmat = cvGetRows( dstmat, &refmathdr, start_row, end_row, delta_row );
cvCopy( srcmat, refmat );
}
else
{
refmat = cvGetRows( srcmat, &refmathdr, start_row, end_row, delta_row );
cvCopy( refmat, dstmat );
}
__END__;
}
/*
CVAPI(void) cvSetRows( const CvArr* subarr, CvArr* arr, int start_row, int end_row )
{
CV_FUNCNAME( "cvSetRows" );
__BEGIN__;
int row, col, elem;
int coi = 0;
CvMat* submat = (CvMat*)subarr, submatstub;
CvMat* mat = (CvMat*)arr, matstub;
if( !CV_IS_MAT(submat) )
{
CV_CALL( submat = cvGetMat( submat, &submatstub, &coi ) );
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
}
if( !CV_IS_MAT(mat) )
{
CV_CALL( mat = cvGetMat( mat, &matstub, &coi ) );
if (coi != 0) CV_ERROR_FROM_CODE(CV_BadCOI);
}
CV_ARE_TYPES_EQ( submat, mat ); // cxtypes.h
//CV_ARE_DEPTHS_EQ( submat, mat );
//CV_ARE_CNS_EQ( submat, mat );
//CV_ARE_SIZES_EQ( submat, mat );
CV_ASSERT( 0 <= start_row && end_row <= mat->rows );
CV_ASSERT( end_row - start_row == submat->rows );
CV_ASSERT( mat->cols == submat->cols );
int elem_size = CV_ELEM_SIZE( mat->type );
// FYI: CV_ELEM_SIZE returns not number_of_channels, but number_of_uchar*
// nChannels = CV_MAT_CN( mat->type ); refer cxarray.cpp#cvRawDataToScalar to separate into channel values
for( row = start_row; row < end_row; row++ )
{
for( col = 0; col < mat->cols; col++ )
{
//cvSet2D( mat, row, col, cvGet2D( submat, row - start_row, col ) );
for( elem = 0; elem < elem_size; elem++ )
{
// cvPtr2D( mat, row, col )[elem] = cvPtr2D( submat, row - start_row, col )[elem];
(mat->data.ptr + ((size_t)mat->step * row) + (elem_size * col))[elem] =
(submat->data.ptr + ((size_t)submat->step * (row - start_row)) + (elem_size * col))[elem];
}
}
}
__END__;
}
*/
/**
* Set array row
*
* #define cvSetRow(src, dst, row) (cvSetRows( src, dst, row, row + 1))
*/
CV_INLINE void cvSetRow( const CvArr* src, CvArr* dst, int row )
{
cvSetRows( src, dst, row, row+1 );
}
#endif