示例#1
0
		///////////////////////////////////////////////////////////////////////////////////////////
		// Construct / Destruct

		// ====================================================================
		//	Description:	Constructor
		//	Return:			void
		public BinaryTree()
		// ====================================================================
		{
			m_pLeft = null;
			m_pRight = null;

			Empty();
		}
示例#2
0
		// ====================================================================
		//	Description:	
		//	Return:	
		public void Empty()
		// ====================================================================
		{
			if ( m_pLeft != null )
			{
				m_pLeft = null;
			}

			if ( m_pRight != null )
			{
				m_pRight = null;
			}

			m_lItem = 0;
			m_lCount = 0;
		}
示例#3
0
		///////////////////////////////////////////////////////////////////////////////////////////
		// Private

		// ====================================================================
		//	Description:	built a histogram
		//	Return:			void
		private void BuiltHist ()
		// ====================================================================
		{
			BinaryTree tree = new BinaryTree();
			Bitmap bmp = (Bitmap)m_Orig.m_Img;
			BitmapData data = bmp.LockBits( new Rectangle( 0 , 0 , bmp.Width , bmp.Height ) , 
				ImageLockMode.ReadWrite  , PixelFormat.Format24bppRgb  );
			
			ulong item = 0;

			MessageBoxButtons buttons = MessageBoxButtons.YesNo;
			string message = "Errored";

			/* built binary tree */
			unsafe
			{ 
				byte* ptr = ( byte* )( data.Scan0 ); 
				for ( int y = 0; y < bmp.Height; y ++ )
				{
					for ( int x = 0; x < bmp.Width; x ++ )
					{
						byte b = *ptr; ptr ++;
						byte g = *ptr; ptr ++;
						byte r = *ptr; ptr ++;

						item = ((ulong)r) << 24;
						item += ((ulong)g) << 16;
						item += ((ulong)b) << 8;

						if ( tree.Insert(item) == false )
						{
							MessageBox.Show (this, message, null, buttons,
								MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 
								MessageBoxOptions.RightAlign);
							break;
						}
					}
					ptr += data.Stride - data.Width * 3;
				}
			}
			bmp.UnlockBits(data);

	
			/* Find size of histogram */
			m_lSize = tree.NumEntries();
			m_RGBVol = new int[m_lSize * 4];
			m_XYZCVol = new double[m_lSize * 4];

			/* Get the histogram */
			tree.Print ( m_RGBVol, 0 ); 
			
			for ( ulong i = 0; i < m_lSize; i ++ )
			{
				for ( ulong j = 0; j < 3; j ++ )
				{
					m_XYZCVol[i*4+j] = m_RGBVol[i*4+j] - 128.0;
				}
			}
		}
示例#4
0
		///////////////////////////////////////////////////////////////////////////////////////////
		// Insert / Remove / Print

		// ====================================================================
		//	Description:	
		//	Return:	
		public bool Insert ( ulong item )
		// ====================================================================
		{
			if ( m_lCount == 0 )
			{
				m_lItem = item;
				m_lCount ++;
				return true;
			}
			else if ( item == m_lItem )
			{
				m_lCount ++;
				return true;
			}
			else if ( item < m_lItem )
			{
				if ( m_pLeft == null )
				{
					m_pLeft = new BinaryTree();

					if ( m_pLeft == null )
						return false;
				}
				return ( m_pLeft.Insert ( item ) );
			}
			else if ( m_lItem < item )
			{
				if ( m_pRight == null )
				{
					m_pRight = new BinaryTree ();

					if ( m_pRight == null )
						return false;
				}
				return ( m_pRight.Insert ( item ) );
			}
			return false;
		}