1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
45 icvSubdiv2DCheck( CvSubdiv2D* subdiv )
47 int i, j, total = subdiv->edges->total;
50 CV_FUNCNAME("icvSubdiv2DCheck");
55 CV_ERROR_FROM_STATUS( CV_NULLPTR_ERR );
57 for( i = 0; i < total; i++ )
59 CvQuadEdge2D* edge = (CvQuadEdge2D*)cvGetSetElem(subdiv->edges,i);
61 if( edge && CV_IS_SET_ELEM( edge ))
63 for( j = 0; j < 4; j++ )
65 CvSubdiv2DEdge e = (CvSubdiv2DEdge)edge + j;
66 CvSubdiv2DEdge o_next = cvSubdiv2DNextEdge(e);
67 CvSubdiv2DEdge o_prev = cvSubdiv2DGetEdge(e, CV_PREV_AROUND_ORG );
68 CvSubdiv2DEdge d_prev = cvSubdiv2DGetEdge(e, CV_PREV_AROUND_DST );
69 CvSubdiv2DEdge d_next = cvSubdiv2DGetEdge(e, CV_NEXT_AROUND_DST );
72 if( cvSubdiv2DEdgeOrg(e) != cvSubdiv2DEdgeOrg(o_next))
74 if( cvSubdiv2DEdgeOrg(e) != cvSubdiv2DEdgeOrg(o_prev))
76 if( cvSubdiv2DEdgeDst(e) != cvSubdiv2DEdgeDst(d_next))
78 if( cvSubdiv2DEdgeDst(e) != cvSubdiv2DEdgeDst(d_prev))
82 if( cvSubdiv2DEdgeDst(o_next) != cvSubdiv2DEdgeOrg(d_prev))
84 if( cvSubdiv2DEdgeDst(o_prev) != cvSubdiv2DEdgeOrg(d_next))
86 if( cvSubdiv2DGetEdge(cvSubdiv2DGetEdge(cvSubdiv2DGetEdge(
87 e,CV_NEXT_AROUND_LEFT),CV_NEXT_AROUND_LEFT),CV_NEXT_AROUND_LEFT) != e )
89 if( cvSubdiv2DGetEdge(cvSubdiv2DGetEdge(cvSubdiv2DGetEdge(
90 e,CV_NEXT_AROUND_RIGHT),CV_NEXT_AROUND_RIGHT),CV_NEXT_AROUND_RIGHT) != e)
107 draw_subdiv_facet( CvSubdiv2D * subdiv, IplImage * dst, IplImage * src, CvSubdiv2DEdge edge )
109 CvSubdiv2DEdge t = edge;
111 CvPoint local_buf[100];
112 CvPoint *buf = local_buf;
114 // count number of edges in facet
118 t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
120 while( t != edge && count < subdiv->quad_edges * 4 );
122 if( count * sizeof( buf[0] ) > sizeof( local_buf ))
124 buf = (CvPoint *) malloc( count * sizeof( buf[0] ));
129 for( i = 0; i < count; i++ )
131 CvSubdiv2DPoint *pt = cvSubdiv2DEdgeOrg( t );
135 assert( fabs( pt->pt.x ) < 10000 && fabs( pt->pt.y ) < 10000 );
136 buf[i] = cvPoint( cvRound( pt->pt.x ), cvRound( pt->pt.y ));
137 t = cvSubdiv2DGetEdge( t, CV_NEXT_AROUND_LEFT );
142 CvSubdiv2DPoint *pt = cvSubdiv2DEdgeDst( cvSubdiv2DRotateEdge( edge, 1 ));
143 CvPoint ip = cvPoint( cvRound( pt->pt.x ), cvRound( pt->pt.y ));
144 CvScalar color = {{0,0,0,0}};
146 //printf("count = %d, (%d,%d)\n", ip.x, ip.y );
148 if( 0 <= ip.x && ip.x < src->width && 0 <= ip.y && ip.y < src->height )
150 uchar *ptr = (uchar*)(src->imageData + ip.y * src->widthStep + ip.x * 3);
151 color = CV_RGB( ptr[2], ptr[1], ptr[0] );
154 cvFillConvexPoly( dst, buf, count, color );
155 //draw_subdiv_point( dst, pt->pt, CV_RGB(0,0,0));
158 if( buf != local_buf )
164 icvDrawMosaic( CvSubdiv2D * subdiv, IplImage * src, IplImage * dst )
166 int i, total = subdiv->edges->total;
168 cvCalcSubdivVoronoi2D( subdiv );
170 //icvSet( dst, 255 );
171 for( i = 0; i < total; i++ )
173 CvQuadEdge2D *edge = (CvQuadEdge2D *) cvGetSetElem( subdiv->edges, i );
175 if( edge && CV_IS_SET_ELEM( edge ))
177 CvSubdiv2DEdge e = (CvSubdiv2DEdge) edge;
180 draw_subdiv_facet( subdiv, dst, src, cvSubdiv2DRotateEdge( e, 1 ));
182 draw_subdiv_facet( subdiv, dst, src, cvSubdiv2DRotateEdge( e, 3 ));