当前位置: 首页>>代码示例>>C#>>正文


C# Contour.AddFirst方法代码示例

本文整理汇总了C#中Contour.AddFirst方法的典型用法代码示例。如果您正苦于以下问题:C# Contour.AddFirst方法的具体用法?C# Contour.AddFirst怎么用?C# Contour.AddFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Contour的用法示例。


在下文中一共展示了Contour.AddFirst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TraceContour

	public static Contour TraceContour( int a_iStartingPixelIndex, NeighborDirection a_eStartingDirection, int a_iContourLabel, BinarizedImage a_rBinarizedImage, int[ ] a_rLabelMap )
	{
		int iPixelIndexTrace;
		NeighborDirection eDirectionNext = a_eStartingDirection;
		FindNextPoint( a_iStartingPixelIndex, a_eStartingDirection, a_rBinarizedImage, a_rLabelMap, out iPixelIndexTrace, out eDirectionNext );
		Contour oContour = new Contour( a_iContourLabel );
		oContour.AddFirst( a_rBinarizedImage.PixelIndex2Coords( iPixelIndexTrace ) );
		int iPreviousPixelIndex = a_iStartingPixelIndex;
		int iCurrentPixelIndex = iPixelIndexTrace;
		bool bDone = ( a_iStartingPixelIndex == iPixelIndexTrace );

		// Choose a bias factor
		// The bias factor points to exterior if tracing an outer contour
		// The bias factor points to interior if tracing an inner contour
		float fOrthoBiasFactor;
		if( a_eStartingDirection == NeighborDirection.DirectionUpRight )	// inner contour
		{
			fOrthoBiasFactor = -0.2f;
		}
		else // outer contour
		{
			fOrthoBiasFactor = 0.2f;
		}
		
		while( bDone == false )
		{
			a_rLabelMap[ iCurrentPixelIndex ] = a_iContourLabel;
			NeighborDirection eDirectionSearch = (NeighborDirection) ( ( (int) eDirectionNext + 6 ) % 8 );
			int iNextPixelIndex;
			FindNextPoint( iCurrentPixelIndex, eDirectionSearch, a_rBinarizedImage, a_rLabelMap, out iNextPixelIndex, out eDirectionNext );

			iPreviousPixelIndex = iCurrentPixelIndex;
			iCurrentPixelIndex = iNextPixelIndex;
			bDone = ( iPreviousPixelIndex == a_iStartingPixelIndex && iCurrentPixelIndex == iPixelIndexTrace );

			if( bDone == false )
			{
				// Apply some bias to inner and outer contours to avoid them overlap
				// Use the orthogonal vector to direction
				NeighborDirection eOrthoBiasDirection = (NeighborDirection) ( ( (int) eDirectionNext + 6 ) % 8 ); // == direction - 2 % 8 but easier to compute (always positive)
				Vector2 f2Bias = fOrthoBiasFactor * BinarizedImage.GetDirectionVector( eOrthoBiasDirection );

				// Add bias to pixel pos
				Vector2 f2BiasedPos = f2Bias + a_rBinarizedImage.PixelIndex2Coords( iNextPixelIndex );

				// Add biased pos to contour
				oContour.AddFirst( f2BiasedPos );
			}
		}

		return oContour;	
	}
开发者ID:grifdail,项目名称:GGJ2016,代码行数:52,代码来源:Uni2DEditorContourExtractionUtils.cs


注:本文中的Contour.AddFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。