예제 #1
0
파일: Octree.cs 프로젝트: hanistory/hasuite
		/// <summary>
		/// Keep track of the previous node that was quantized
		/// </summary>
		/// <param name="node">The node last quantized</param>
		public void TrackPrevious( OctreeNode node )
		{
			_previousNode = node;
		}
예제 #2
0
파일: Octree.cs 프로젝트: hanistory/hasuite
		/// <summary>
		/// Construct the octree
		/// </summary>
		/// <param name="maxColourBits">
		/// The maximum number of significant bits in the image
		/// </param>
		public Octree( int maxColourBits )
		{
			_maxColorBits = maxColourBits;
			_reducibleNodes = new OctreeNode[9];
			_root = new OctreeNode( 0, _maxColorBits, this ); 
		}
예제 #3
0
파일: Octree.cs 프로젝트: hanistory/hasuite
		/// <summary>
		/// Reduce the depth of the tree
		/// </summary>
		private void Reduce()
		{
			int	index;

			// Find the deepest level containing at least one reducible node
			for( 
			    index = _maxColorBits - 1;
			    ( index > 0 ) && ( null == _reducibleNodes[index] ); 
			    index-- 
			   );

			// Reduce the node most recently added to the list at level 'index'
			OctreeNode	node = _reducibleNodes[index];
			_reducibleNodes[index] = node.NextReducible;

			// Decrement the leaf count after reducing the node
			_leafCount -= node.Reduce();

			// And just in case I've reduced the last color to be added, 
			// and the next color to be added is the same, invalidate the 
			// previousNode...
			_previousNode = null;
		}
예제 #4
0
		public void AddColour( Colour32* pixel, 
		                       int colourBits, 
		                       int level, 
		                       Octree octree )
		{
			// Update the color information if this is a leaf
			if( _leaf )
			{
				Increment( pixel );
				// Setup the previous node
				octree.TrackPrevious( this );
			}
			else
			{
				// Go to the next level down in the tree
				// FXCOP: Correct the potential overflow in the operation '7-level' in 'OctreeNode.AddColour(Colour32*, Int32, Int32, Octree):Void'. (CA2233)
				int	shift = 7 - level;
				int index = ( ( pixel->Red & mask[level] ) >> ( shift - 2 ) ) |
							( ( pixel->Green & mask[level] ) >> ( shift - 1 ) ) |
							( ( pixel->Blue & mask[level] ) >> ( shift ) );

				OctreeNode	child = _children[index];

				if( null == child )
				{
					// Create a new child node & store in the array
					// FXCOP: Correct the potential overflow in the operation 'level+1' in 'OctreeNode.AddColour(Colour32*, Int32, Int32, Octree):Void'. (CA2233) 
					child = new OctreeNode( level + 1, colourBits, octree ); 
					_children[index] = child;
				}

				// Add the color to the child node
				// FXCOP: Correct the potential overflow in the operation 'level+1' in 'OctreeNode.AddColour(Colour32*, Int32, Int32, Octree):Void'. (CA2233) 
				child.AddColour( pixel, colourBits, level + 1, octree );
			}

		}
예제 #5
0
		public OctreeNode( int level, int colourBits, Octree octree )
		{
			if( octree == null )
			{
				// TESTME: constructor null argument
				throw new ArgumentNullException( "octree" );
			}
			
			// Construct the new node
			_leaf = ( level == colourBits );

			_red = _green = _blue = 0;

			// If a leaf, increment the leaf count
			if( _leaf )
			{
				octree.Leaves++;
			}
			else
			{
				// Otherwise add this to the reducible nodes
				_nextReducible = octree.ReducibleNodes[level];
				octree.ReducibleNodes[level] = this;
				_children = new OctreeNode[8];
			}
		}
예제 #6
0
 /// <summary>
 /// Construct the octree
 /// </summary>
 /// <param name="maxColourBits">
 /// The maximum number of significant bits in the image
 /// </param>
 public Octree(int maxColourBits)
 {
     _maxColorBits   = maxColourBits;
     _reducibleNodes = new OctreeNode[9];
     _root           = new OctreeNode(0, _maxColorBits, this);
 }
예제 #7
0
 /// <summary>
 /// Keep track of the previous node that was quantized
 /// </summary>
 /// <param name="node">The node last quantized</param>
 public void TrackPrevious(OctreeNode node)
 {
     _previousNode = node;
 }