/// <summary> /// Initializes a new instance of the <see cref="HSLFiltering"/> class. /// </summary> /// /// <param name="hue">Range of hue component.</param> /// <param name="saturation">Range of saturation component.</param> /// <param name="luminance">Range of luminance component.</param> /// public HSLFiltering( IntRange hue, Range saturation, Range luminance ) : this( ) { this.hue = hue; this.saturation = saturation; this.luminance = luminance; }
/// <summary> /// Set bounds for specified servos. /// </summary> /// /// <param name="mask">Mask array specifying which servos need to be set.</param> /// <param name="bounds">Array of servos' bounds. Each bound may be in [0, 255] range.</param> /// /// <remarks><para>The method sets servos' physical bounds in which they may move. /// See documentation to <see cref="Qwerk.Servos"/> for clarification.</para></remarks> /// /// <exception cref="ArgumentException">Incorrect length of <paramref name="mask"/>, /// or <paramref name="bounds"/> array.</exception> /// <exception cref="NotConnectedException">No connection to Qwerk or its service.</exception> /// <exception cref="ConnectionLostException">Connestion to Qwerk is lost.</exception> /// public void SetBounds( bool[] mask, IntRange[] bounds ) { if ( ( mask.Length != Count ) || ( bounds.Length != Count ) ) { throw new ArgumentException( "Incorrect length of mask or positions array." ); } // check controller if ( servoController == null ) { throw new NotConnectedException( "Qwerk's service is not connected." ); } try { TeRKIceLib.Bounds[] nativeBounds = new TeRKIceLib.Bounds[Count]; for ( int i = 0; i < Count; i++ ) { if ( mask[i] ) { nativeBounds[i].min = bounds[i].Min; nativeBounds[i].max = bounds[i].Max; } } // set servos' bounds servoController.setBounds( mask, nativeBounds ); } catch { throw new ConnectionLostException( "Connection is lost." ); } }
/// <summary> /// Get bounds of all servos. /// </summary> /// /// <returns>Returns array of configured servos' bounds.</returns> /// /// <exception cref="NotConnectedException">No connection to Qwerk or its service.</exception> /// <exception cref="ConnectionLostException">Connestion to Qwerk is lost.</exception> /// public IntRange[] GetBounds( ) { // check controller if ( servoController == null ) { throw new NotConnectedException( "Qwerk's service is not connected." ); } try { // get servos' bounds TeRKIceLib.Bounds[] nativeBounds = servoController.getBounds( ); IntRange[] bounds = new IntRange[Count]; for ( int i = 0; i < Count; i++ ) { bounds[i] = new IntRange( nativeBounds[i].min, nativeBounds[i].max ); } return bounds; } catch { throw new ConnectionLostException( "Connection is lost." ); } }
/// <summary> /// Calculate filtering map. /// </summary> /// /// <param name="range">Filtering range.</param> /// <param name="fill">Fillter value.</param> /// <param name="fillOutsideRange">Fill outside or inside the range.</param> /// <param name="map">Filtering map.</param> /// private void CalculateMap( IntRange range, byte fill, bool fillOutsideRange, byte[] map ) { for ( int i = 0; i < 256; i++ ) { if ( ( i >= range.Min ) && ( i <= range.Max ) ) { map[i] = ( fillOutsideRange ) ? (byte) i : fill; } else { map[i] = ( fillOutsideRange ) ? fill : (byte) i; } } }
/// <summary> /// Set bounds for the specified servo. /// </summary> /// /// <param name="servo">Servo to set bounds for, [0, <see cref="Servos.Count"/>).</param> /// <param name="bound">Bounds to set for the specified servo.</param> /// /// <remarks><para>The method sets servo's physical bounds in which it may move. /// See documentation to <see cref="Qwerk.Servos"/> for clarification.</para></remarks> /// /// <exception cref="ArgumentOutOfRangeException">Invalid servo is specified.</exception> /// <exception cref="NotConnectedException">No connection to Qwerk or its service.</exception> /// <exception cref="ConnectionLostException">Connestion to Qwerk is lost.</exception> /// public void SetBound( int servo, IntRange bound ) { if ( ( servo < 0 ) || ( servo >= Count ) ) { throw new ArgumentOutOfRangeException( "Invalid servo is specified." ); } bool[] mask = new bool[Count]; IntRange[] bounds = new IntRange[Count]; mask[servo] = true; bounds[servo] = bound; SetBounds( mask, bounds ); }
/// <summary> /// Check if the specified range overlaps with the range. /// </summary> /// /// <param name="range">Range to check for overlapping.</param> /// /// <returns><b>True</b> if the specified range overlaps with the range or /// <b>false</b> otherwise.</returns> /// public bool IsOverlapping( IntRange range ) { return ( ( IsInside( range.min ) ) || ( IsInside( range.max ) ) || ( range.IsInside( min ) ) || ( range.IsInside( max ) ) ); }
/// <summary> /// Initializes a new instance of the <see cref="ChannelFiltering"/> class. /// </summary> /// /// <param name="red">Red channel's filtering range.</param> /// <param name="green">Green channel's filtering range.</param> /// <param name="blue">Blue channel's filtering range.</param> /// public ChannelFiltering( IntRange red, IntRange green, IntRange blue ) { Red = red; Green = green; Blue = blue; formatTranslations[PixelFormat.Format24bppRgb] = PixelFormat.Format24bppRgb; formatTranslations[PixelFormat.Format32bppRgb] = PixelFormat.Format32bppRgb; formatTranslations[PixelFormat.Format32bppArgb] = PixelFormat.Format32bppArgb; }
/// <summary> /// Check if the specified range is inside of the range. /// </summary> /// /// <param name="range">Range to check.</param> /// /// <returns><b>True</b> if the specified range is inside of the range or /// <b>false</b> otherwise.</returns> /// public bool IsInside( IntRange range ) { return ( ( IsInside( range.min ) ) && ( IsInside( range.max ) ) ); }
/// <summary> /// Calculate conversion map. /// </summary> /// /// <param name="inRange">Input range.</param> /// <param name="outRange">Output range.</param> /// <param name="map">Conversion map.</param> /// private void CalculateMap( IntRange inRange, IntRange outRange, ushort[] map ) { double k = 0, b = 0; if ( inRange.Max != inRange.Min ) { k = (double) ( outRange.Max - outRange.Min ) / (double) ( inRange.Max - inRange.Min ); b = (double) ( outRange.Min ) - k * inRange.Min; } for ( int i = 0; i < 65536; i++ ) { ushort v = (ushort) i; if ( v >= inRange.Max ) v = (ushort) outRange.Max; else if ( v <= inRange.Min ) v = (ushort) outRange.Min; else v = (ushort) ( k * v + b ); map[i] = v; } }
/// <summary> /// Check if the specified range overlaps with the range. /// </summary> /// /// <param name="range">Range to check for overlapping.</param> /// /// <returns><b>True</b> if the specified range overlaps with the range or /// <b>false</b> otherwise.</returns> /// public bool IsOverlapping(IntRange range) { return((IsInside(range.min)) || (IsInside(range.max)) || (range.IsInside(min)) || (range.IsInside(max))); }
/// <summary> /// Check if the specified range is inside of the range. /// </summary> /// /// <param name="range">Range to check.</param> /// /// <returns><b>True</b> if the specified range is inside of the range or /// <b>false</b> otherwise.</returns> /// public bool IsInside(IntRange range) { return((IsInside(range.min)) && (IsInside(range.max))); }
/// <summary> /// Initializes a new instance of the <see cref="FrequencyFilter"/> class. /// </summary> /// /// <param name="frequencyRange">Range of frequencies to keep.</param> /// public FrequencyFilter( IntRange frequencyRange ) { this.frequencyRange = frequencyRange; }