Axiom.Media.PixelBox.GetSubVolume C# (CSharp) Method

GetSubVolume() public method

Return a subvolume of this PixelBox.
This function does not copy any data, it just returns a PixelBox object with a data pointer pointing somewhere inside the data of object. Throws an Exception if def is not fully contained.
public GetSubVolume ( BasicBox def ) : PixelBox
def BasicBox Defines the bounds of the subregion to return
return PixelBox
		public PixelBox GetSubVolume( BasicBox def )
		{
			if ( Compressed( format ) )
			{
				if ( def.Left == left && def.Top == top && def.Front == front &&
				   def.Right == right && def.Bottom == bottom && def.Back == back )
					// Entire buffer is being queried
					return this;
				throw new Exception( "Cannot return subvolume of compressed PixelBuffer, in PixelBox.GetSubVolume" );
			}
			if ( !Contains( def ) )
				throw new Exception( "Bounds out of range, in PixelBox.GetSubVolume" );

			int elemSize = PixelUtil.GetNumElemBytes( format );
			// Calculate new data origin
			PixelBox rval = new PixelBox( def, format, data );
			rval.offset = ( ( ( def.Left - left ) * elemSize ) +
							( ( def.Top - top ) * rowPitch * elemSize ) +
							( ( def.Front - front ) * slicePitch * elemSize ) );
			rval.rowPitch = rowPitch;
			rval.slicePitch = slicePitch;
			rval.format = format;
			return rval;
		}