Example #1
0
 /// <summary>
 /// Converts the stream of image camera views to a different pixel format.
 /// </summary>
 /// <param name="source">The source stream of image camera views.</param>
 /// <param name="scaleX">Scale factor for X.</param>
 /// <param name="scaleY">Scale factor for Y.</param>
 /// <param name="samplingMode">Method for sampling pixels when rescaling.</param>
 /// <param name="deliveryPolicy">An optional delivery policy.</param>
 /// <param name="sharedImageAllocator">Optional image allocator for creating new shared images.</param>
 /// <param name="name">An optional name for the stream operator.</param>
 /// <returns>The resulting stream.</returns>
 public static IProducer <ImageCameraView> Scale(
     this IProducer <ImageCameraView> source,
     float scaleX,
     float scaleY,
     SamplingMode samplingMode = SamplingMode.Bilinear,
     DeliveryPolicy <ImageCameraView> deliveryPolicy = null,
     Func <int, int, PixelFormat, Shared <Image> > sharedImageAllocator = null,
     string name = nameof(Scale))
 {
     sharedImageAllocator ??= (width, height, pixelFormat) => ImagePool.GetOrCreate(width, height, pixelFormat);
     return(source.Process <ImageCameraView, ImageCameraView>(
                (imageCameraView, envelope, emitter) =>
     {
         // if the image is null, post null
         if (imageCameraView == null)
         {
             emitter.Post(null, envelope.OriginatingTime);
         }
         else
         {
             int finalWidth = (int)(imageCameraView.ViewedObject.Resource.Width * scaleX);
             int finalHeight = (int)(imageCameraView.ViewedObject.Resource.Height * scaleY);
             using var scaledSharedImage = sharedImageAllocator(finalWidth, finalHeight, imageCameraView.ViewedObject.Resource.PixelFormat);
             imageCameraView.ViewedObject.Resource.Scale(scaledSharedImage.Resource, scaleX, scaleY, samplingMode);
             using var outputImageCameraView = new ImageCameraView(scaledSharedImage, imageCameraView.CameraIntrinsics, imageCameraView.CameraPose);
             emitter.Post(outputImageCameraView, envelope.OriginatingTime);
         }
     },
                deliveryPolicy,
                name));
 }
Example #2
0
 protected static DependencyProperty RegisterPixelShaderSamplerProperty(string dpName,
                                                                        Type ownerType,
                                                                        int samplerRegisterIndex,
                                                                        SamplingMode samplingMode)
 {
     return(DependencyProperty.Register(dpName, typeof(Brush), ownerType, new PropertyMetadata(null, PixelShaderSamplerCallback(samplerRegisterIndex, samplingMode))));
 }
Example #3
0
 public BabylonTexture(BabylonTexture original)
 {
     name             = original.name;
     level            = original.level;
     hasAlpha         = original.hasAlpha;
     getAlphaFromRGB  = original.getAlphaFromRGB;
     coordinatesMode  = original.coordinatesMode;
     isCube           = original.isCube;
     uOffset          = original.uOffset;
     vOffset          = original.vOffset;
     uScale           = original.uScale;
     vScale           = original.vScale;
     uRotationCenter  = original.uRotationCenter;
     vRotationCenter  = original.vRotationCenter;
     wRotationCenter  = original.wRotationCenter;
     invertY          = original.invertY;
     uAng             = original.uAng;
     vAng             = original.vAng;
     wAng             = original.wAng;
     wrapU            = original.wrapU;
     wrapV            = original.wrapV;
     coordinatesIndex = original.coordinatesIndex;
     isRenderTarget   = original.isRenderTarget;
     renderTargetSize = original.renderTargetSize;
     mirrorPlane      = original.mirrorPlane;
     renderList       = original.renderList;
     animations       = original.animations;
     extensions       = original.extensions;
     samplingMode     = original.samplingMode;
     originalPath     = original.originalPath;
     bitmap           = original.bitmap;
 }
Example #4
0
        void bProcess_Click(object sender, EventArgs e)
        {
            // cancel whatever task is in progress
            if (currentTask != null)
            {
                runAfterCancel = true;
                worker.CancelAsync();
                currentTask.CancelAsync();
                return;
            }

            SortAlgorithm algo          = (SortAlgorithm)cAlgorithm.SelectedIndex;
            SortOrder     order         = (SortOrder)cOrder.SelectedIndex;
            SortMetric    metric        = (SortMetric)cMetric.SelectedIndex;
            SamplingMode  sampling      = (SamplingMode)cSampling.SelectedIndex;
            int           segmentWidth  = (int)nSegmentWidth.Value;
            int           segmentHeight = (int)nSegmentHeight.Value;
            double        threshold     = tbThreshold.Value / 100d;

            pbProgress.Value = 0;
            SetProgressVisible(true);

            currentTask = new SortingTask(algo,
                                          order,
                                          metric,
                                          sampling,
                                          segmentWidth,
                                          segmentHeight,
                                          (Bitmap)originalImage.Clone(),
                                          threshold);
            currentTask.ProgressChanged += (o, args) => worker.ReportProgress(args.ProgressPercentage);

            worker.RunWorkerAsync();
        }
Example #5
0
 internal ReflectImageTraits(SpirvReflectNative.SpvReflectImageTraits image)
 {
     Arrayed      = image.arrayed;
     Depth        = image.depth;
     Sampled      = image.sampled;
     MultiSampled = (SamplingMode)image.ms;
     Dim          = (Dim)image.dim;
     ImageFormat  = (ImageFormat)image.image_format;
 }
Example #6
0
        protected static PropertyChangedCallback PixelShaderSamplerCallback(int register,
                                                                            SamplingMode samplingMode)
        {
            return(delegate(DependencyObject sender, DependencyPropertyChangedEventArgs e)
            {
                Brush brush = (Brush)e.NewValue;
                IntPtr input = brush == null ? IntPtr.Zero : brush.native;

                UpdateShaderSampler(sender.native, register, (int)samplingMode, input);
            });
        }
Example #7
0
		protected static PropertyChangedCallback PixelShaderSamplerCallback (int register,
										     SamplingMode samplingMode)
		{
			return delegate (DependencyObject sender, DependencyPropertyChangedEventArgs e)
			       {
					Brush brush = (Brush) e.NewValue;
					IntPtr input = brush == null ? IntPtr.Zero : brush.native;

					UpdateShaderSampler (sender.native, register, (int) samplingMode, input);
				};
		}
 /// <summary>
 /// Writes our settings to an XML writer
 /// </summary>
 /// <param name="writer">an XML writer</param>
 public void WriteXml(System.Xml.XmlWriter writer)
 {
     writer.WriteAttributeString("BaudRate", BaudRate.ToString());
     writer.WriteAttributeString("ControllerType", ControllerType.ToString());
     writer.WriteAttributeString("SamplingChannels", SamplingChannels.ToString());
     writer.WriteAttributeString("SamplingCompression", SamplingCompression.ToString());
     writer.WriteAttributeString("SamplingMode", SamplingMode.ToString());
     writer.WriteAttributeString("SamplingRate", SamplingRate.ToString());
     writer.WriteAttributeString("SamplingTime", SamplingTime.ToString());
     writer.WriteAttributeString("SerialPortName", SerialPortName);
 }
Example #9
0
        public SortingTask(SortAlgorithm algorithm, SortOrder order, SortMetric metric, SamplingMode sampling,
                           int segmentWidth, int segmentHeight, Bitmap originalImage, double threshold)
        {
            Algorithm      = algorithm;
            Order          = order;
            Metric         = metric;
            Sampling       = sampling;
            SegmentWidth   = segmentWidth;
            SegmentHeight  = segmentHeight;
            OriginalImage  = originalImage;
            Threshold      = threshold;
            segmentRows    = OriginalImage.Height / SegmentHeight;
            segmentColumns = OriginalImage.Width / SegmentWidth;

            switch (Algorithm)
            {
            case SortAlgorithm.WholeImage:
                segments    = new Segment[1][];
                segments[0] = new Segment[segmentRows * segmentColumns];
                break;

            case SortAlgorithm.Column:
                segments = new Segment[segmentColumns][];
                for (int col = 0; col < segmentColumns; ++col)
                {
                    segments[col] = new Segment[segmentRows];
                }
                break;

            case SortAlgorithm.Row:
                segments = new Segment[segmentRows][];
                for (int row = 0; row < segmentRows; ++row)
                {
                    segments[row] = new Segment[segmentColumns];
                }
                break;

            case SortAlgorithm.Segment:
                segments = new Segment[segmentRows * segmentColumns][];
                for (int i = 0; i < segments.Length; ++i)
                {
                    segments[i] = new Segment[segmentWidth * segmentHeight];
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #10
0
 public BabylonTexture()
 {
     level            = 1.0f;
     uOffset          = 0;
     vOffset          = 0;
     uScale           = 1.0f;
     vScale           = 1.0f;
     uAng             = 0;
     vAng             = 0;
     wAng             = 0;
     wrapU            = AddressMode.WRAP_ADDRESSMODE;
     wrapV            = AddressMode.WRAP_ADDRESSMODE;
     hasAlpha         = false;
     coordinatesIndex = 0;
     samplingMode     = SamplingMode.LINEAR_LINEAR_MIPLINEAR;
 }
Example #11
0
        /// <summary>
        /// Parsing Resampling Mode.
        /// </summary>
        /// <param name="data">Resampling Text</param>
        /// <param name="errMsg">Error Message</param>
        /// <param name="mode">SamplingMode</param>
        /// <returns></returns>
        public bool ParseResamplingMode(string data, ref string errMsg, ref SamplingMode mode)
        {
            bool ret = true;

            try
            {
                mode = (SamplingMode)Enum.Parse(typeof(SamplingMode), data);
            }
            catch
            {
                ret    = false;
                errMsg = ERROR_RESAMPLING_MODE;
                mode   = SamplingMode.FIRST;
            }
            return(ret);
        }
Example #12
0
        private void InitChannelValues(SamplingMode eSampleMode)
        {
            switch (eSampleMode)
            {
            case SamplingMode.SingleRate:

                Values  = new List <double>();
                Samples = null;
                break;

            case SamplingMode.MultipleRates:

                Values  = null;
                Samples = new List <SerieSample>();
                break;
            }
        }
Example #13
0
        /// <summary>
        /// Constructor including name and  sampling mode of the data channel to create
        /// </summary>
        /// <param name="ChannelName">Channel name</param>
        /// <param name="SampleMode">Sampling mode of the data channel</param>
        public GW_DataChannel(string ChannelName, SamplingMode SampleMode)
        {
            Name = ChannelName;
            Min  = 0;
            Max  = 0;
            Avg  = 0;
            ChannelStepTimeMin = 0;
            ChannelStepTimeMax = 0;
            KeyId = -1;

            InitChannelValues(SampleMode);

            //XML Data file channel properties default values
            Description           = "";
            Unit                  = "";
            GraphicFormat         = new GraphSerieValueFormat();
            ChannelReferenceLines = new List <GraphReferenceLine>();
        }
        public SamplerState GetSamplerState(SamplingMode samplingMode)
        {
            switch (samplingMode)
            {
            case SamplingMode.AnisotropicClamp: return(SamplerState.AnisotropicClamp);

            case SamplingMode.AnisotropicWrap: return(SamplerState.AnisotropicWrap);

            case SamplingMode.LinearClamp: return(SamplerState.LinearClamp);

            case SamplingMode.LinearWrap: return(SamplerState.LinearWrap);

            case SamplingMode.PointClamp: return(SamplerState.PointClamp);

            case SamplingMode.PointWrap: return(SamplerState.PointWrap);

            default:
                return(SamplerState.LinearWrap);
            }
        }
Example #15
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public GW_DataFile()
        {
            DataSamplingMode = SamplingMode.SingleRate;

            Time = new GW_DataChannel("Time");
            Time.ParentDataFile = this;

            Channels       = new GW_DataChannelList(this);
            TimeBufferSize = -1;

            StepTimeMin = 0;
            StepTimeMax = 0;

            CoordConversionUpdateRequested = false;

            //XML Data file default properties
            DataStartTime = DateTime.Now;
            UserComment   = "";
            XmlDataFileCustomProperties = new List <GW_XmlDataFileCustomProperty>();
        }
        /// <summary>
        /// Запуск процесса
        /// </summary>
        public bool Start()
        {
            Started?.Invoke(this, new EventArgs());
            m_Started = 1;
            //No preffered serial number, trying to opne any device
            string PrefferedSerialNumber = null;
            //PrefferedSerialNumber = "3005";
            bool result = MitsarDeviceOperation.Launch(device,
                                                       ProtocolClass,
                                                       PrefferedSerialNumber,
                                                       DataType,
                                                       InputTask,
                                                       ref ErrorMessage);

            m_Sampling = SamplingMode.Frequency250;
            updateBatteryPercent();
            if (ErrorMessage != null)
            {
                MessageBox.Show(ErrorMessage);
                return(false);
            }
            return(true);
        }
Example #17
0
        public virtual void Draw(GameTime time, SpriteBatch spriteBatch)
        {
            lock (Manager.SyncRoot)
            {
                bool         isBatching   = false;
                SamplingMode lastSampling = SamplingMode.LinearClamp;

                var transforms = Manager.GetSortedTransformList();
                for (int i = 0, count = transforms.Count; i < count; i++)
                {
                    UITransform transform = transforms[i];
                    if (transform.IsActive == false || !transform.IsDrawable)
                    {
                        continue;
                    }

                    if (lastSampling != transform.PreferredSampling)
                    {
                        if (isBatching)
                        {
                            spriteBatch.End();
                            isBatching = false;
                        }
                        lastSampling = transform.PreferredSampling;
                    }

                    if (!isBatching)
                    {
                        spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, GetSamplerState(lastSampling));
                        isBatching = true;
                    }

                    transform.Draw(time, spriteBatch);
                }
                spriteBatch.End();
            }
        }
        public virtual void Draw(GameTime time, SpriteBatch spriteBatch)
        {
            bool         isBatching   = false;
            SamplingMode lastSampling = SamplingMode.LinearClamp;

            var transforms = Manager.SortAndGetTransforms();

            for (int i = 0; i < transforms.Count; i++)
            {
                var transform = transforms[i];
                if (!transform.IsActive || !transform.IsDrawable)
                {
                    continue;
                }

                if (lastSampling != transform.PreferredSampling)
                {
                    if (isBatching)
                    {
                        spriteBatch.End();
                        isBatching = false;
                    }
                    lastSampling = transform.PreferredSampling;
                }

                if (!isBatching)
                {
                    spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, GetSamplerState(lastSampling));
                    isBatching = true;
                }

                transform.Purify();
                transform.Draw(time, spriteBatch);
            }
            spriteBatch.End();
        }
Example #19
0
        /// <summary>
        /// Rotates an image
        /// </summary>
        /// <param name="image">Image to rotate</param>
        /// <param name="angleInDegrees">Number of degrees to rotate in counter clockwise direction</param>
        /// <param name="mode">Pixel resampling method</param>
        /// <returns>Rotated image</returns>
        public static Shared <Image> Rotate(this Image image, float angleInDegrees, SamplingMode mode)
        {
            float ca   = (float)System.Math.Cos(angleInDegrees * System.Math.PI / 180.0f);
            float sa   = (float)System.Math.Sin(angleInDegrees * System.Math.PI / 180.0f);
            float minx = 0.0f;
            float miny = 0.0f;
            float maxx = 0.0f;
            float maxy = 0.0f;
            float x    = image.Width - 1;
            float y    = 0.0f;
            float nx   = (x * ca) - (y * sa);
            float ny   = (x * sa) + (y * ca);

            if (nx < minx)
            {
                minx = nx;
            }

            if (nx > maxx)
            {
                maxx = nx;
            }

            if (ny < miny)
            {
                miny = ny;
            }

            if (ny > maxy)
            {
                maxy = ny;
            }

            x  = image.Width - 1;
            y  = image.Height - 1;
            nx = (x * ca) - (y * sa);
            ny = (x * sa) + (y * ca);
            if (nx < minx)
            {
                minx = nx;
            }

            if (nx > maxx)
            {
                maxx = nx;
            }

            if (ny < miny)
            {
                miny = ny;
            }

            if (ny > maxy)
            {
                maxy = ny;
            }

            x  = 0.0f;
            y  = image.Height - 1;
            nx = (x * ca) - (y * sa);
            ny = (x * sa) + (y * ca);
            if (nx < minx)
            {
                minx = nx;
            }

            if (nx > maxx)
            {
                maxx = nx;
            }

            if (ny < miny)
            {
                miny = ny;
            }

            if (ny > maxy)
            {
                maxy = ny;
            }

            int dstWidth  = (int)(maxx - minx + 1);
            int dstHeight = (int)(maxy - miny + 1);
            var bitmap    = new Bitmap(dstWidth, dstHeight);
            var graphics  = Graphics.FromImage(bitmap);

            graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            switch (mode)
            {
            case SamplingMode.Point:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
                break;

            case SamplingMode.Bilinear:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                break;

            case SamplingMode.Bicubic:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                break;
            }

            graphics.TranslateTransform(-minx, -miny);
            graphics.RotateTransform(angleInDegrees);
            graphics.DrawImage(image.ToManagedImage(), new Point(0, 0));
            return(ImagePool.GetOrCreate(bitmap));
        }
Example #20
0
 protected static DependencyProperty RegisterPixelShaderSamplerProperty(string @dpName, Type @ownerType, int @samplerRegisterIndex, SamplingMode @samplingMode)
 {
     return(null);
 }
Example #21
0
        /// <summary>
        /// Resizes an image by the specified scale factors using the specified sampling mode
        /// </summary>
        /// <param name="image">Image to resize</param>
        /// <param name="xScale">Scale factor to apply in X direction</param>
        /// <param name="yScale">Scale factor to apply in Y direction</param>
        /// <param name="mode">Sampling mode for sampling of pixels</param>
        /// <returns>Returns a new image scaled by the specified scale factors</returns>
        public static Shared <Image> Scale(this Image image, float xScale, float yScale, SamplingMode mode)
        {
            if (xScale == 0.0 || yScale == 0.0)
            {
                throw new System.Exception("Unexpected scale factors");
            }

            int dstWidth  = (int)(image.Width * xScale);
            int dstHeight = (int)(image.Height * yScale);
            var bitmap    = new Bitmap(dstWidth, dstHeight);
            var graphics  = Graphics.FromImage(bitmap);

            graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
            switch (mode)
            {
            case SamplingMode.Point:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
                break;

            case SamplingMode.Bilinear:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                break;

            case SamplingMode.Bicubic:
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                break;
            }

            graphics.ScaleTransform(xScale, yScale);
            graphics.DrawImage(image.ToManagedImage(), new Point(0, 0));
            return(ImagePool.GetOrCreate(bitmap));
        }
Example #22
0
 /// <summary>
 /// Checking SpecifiedIntervalRange
 /// </summary>
 /// <param name="min">min</param>
 /// <param name="max">max</param>
 /// <param name="interval">interval</param>
 /// <param name="mode">mode</param>
 /// <returns></returns>
 public bool IsValidSpecifiedIntervalRange(double min, double max, double?interval, SamplingMode mode)
 {
     if (mode == SamplingMode.SPECIFIED)
     {
         if ((min > max) ||
             (interval == null) ||
             (min > interval) ||
             (interval > max))
         {
             return(false);
         }
     }
     return(true);
 }
Example #23
0
        /// <summary>
        /// Parsing SpecifiedInterval
        /// </summary>
        /// <param name="data">SpecifiedInterval</param>
        /// <param name="errMsg">Error Message</param>
        /// <param name="Interval">Interval</param>
        /// <param name="mode">Mode</param>
        /// <returns></returns>
        public bool ParseSpecifiedInterval(string data, ref string errMsg, ref double?Interval, SamplingMode mode)
        {
            bool ret = true;

            try
            {
                Interval = double.Parse(data);
            }
            catch
            {
                if (mode == SamplingMode.SPECIFIED)
                {
                    ret      = false;
                    errMsg   = ERROR_SPECIFIED_INTERVAL;
                    Interval = 0.5;
                }
                else
                {
                    Interval = null;
                }
            }
            return(ret);
        }
Example #24
0
        /// <summary>
        /// Read a XML data file
        /// </summary>
        /// <param name="fPath">Path of the XML file to read</param>
        /// <param name="HeaderOnly">Read only data file header flag</param>
        /// <returns>Reading error flag: True = No Error / False = Error</returns>
        public bool Load_XmlDataFile(string fPath, bool HeaderOnly)
        {
            XmlNode xDataFile, xHeader, xChannels, xSamples;
            XmlNode xElemParent, xElemChild;

            this.DataSamplingMode = SamplingMode.MultipleRates;

            try
            {
                XmlDocument oXDoc = new XmlDocument();
                oXDoc.Load(fPath);

                xDataFile = oXDoc.SelectSingleNode("XmlGraphDataFile");

                #region XML Data file header

                //Header reading
                xHeader = xDataFile.SelectSingleNode("DataFileHeader");

                //Data file start time
                xElemChild         = xHeader.SelectSingleNode("DataStartTime");
                this.DataStartTime = DateTime.FromBinary(long.Parse(xElemChild.InnerText));

                //User comment
                xElemChild       = xHeader.SelectSingleNode("DataUserComment");
                this.UserComment = xElemChild.InnerText;

                //Data file user properties
                xElemParent = xHeader.SelectSingleNode("DataCustomProperties");

                foreach (XmlNode xProp in xElemParent.ChildNodes)
                {
                    GW_XmlDataFileCustomProperty oProp = new GW_XmlDataFileCustomProperty();

                    oProp.Name = xProp.Attributes["CustomPropertyName"].Value;

                    string PropType = xProp.Attributes["CustomPropertyType"].Value;
                    oProp.ParsePropertyStringValue(xProp.InnerText, PropType);

                    this.XmlDataFileCustomProperties.Add(oProp);
                }

                #endregion

                #region XML Data files channels

                //Data reading
                if (!HeaderOnly)
                {
                    xChannels = xDataFile.SelectSingleNode("DataFileChannels");

                    foreach (XmlNode xChan in xChannels.ChildNodes)
                    {
                        GW_DataChannel oChan = new GW_DataChannel(SamplingMode.MultipleRates);

                        //Read channel properties
                        oChan.KeyId = int.Parse(xChan.Attributes["ChanId"].Value);

                        xElemChild = xChan.SelectSingleNode("ChannelName");
                        oChan.Name = xElemChild.InnerText;

                        xElemChild        = xChan.SelectSingleNode("ChannelDescription");
                        oChan.Description = xElemChild.InnerText;

                        xElemChild = xChan.SelectSingleNode("ChannelUnit");
                        oChan.Unit = xElemChild.InnerText;

                        xElemChild = xChan.SelectSingleNode("ValueFormat");
                        oChan.GraphicFormat.SetSerieValueFormatFromXmlNode(xElemChild);

                        xElemParent = xChan.SelectSingleNode("ChannelReferenceLines");

                        if (!(xElemParent == null))
                        {
                            foreach (XmlNode xRefLine in xElemParent.ChildNodes)
                            {
                                GraphReferenceLine oLine = new GraphReferenceLine();

                                if (oLine.Read_GraphLineXmlNode(xRefLine))
                                {
                                    oChan.ChannelReferenceLines.Add(oLine);
                                }
                            }
                        }

                        //Read channel samples
                        xSamples = xChan.SelectSingleNode("ChannelSamples");

                        foreach (XmlNode xSerieSample in xSamples.ChildNodes)
                        {
                            SerieSample sSample = new SerieSample();

                            sSample.SampleTime  = double.Parse(xSerieSample.Attributes["ST"].Value);
                            sSample.SampleValue = double.Parse(xSerieSample.InnerText);

                            oChan.Samples.Add(sSample);

                            if (oChan.Samples.Count == 1)
                            {
                                oChan.Min = sSample.SampleValue;
                                oChan.Max = sSample.SampleValue;
                            }
                            else
                            {
                                if (sSample.SampleValue < oChan.Min)
                                {
                                    oChan.Min = sSample.SampleValue;
                                }
                                if (sSample.SampleValue > oChan.Max)
                                {
                                    oChan.Max = sSample.SampleValue;
                                }
                            }
                        }

                        this.Channels.Add(oChan);
                    }
                }

                #endregion
            }
            catch
            {
                return(false);
            }

            return(true);
        }
 protected static System.Windows.DependencyProperty RegisterPixelShaderSamplerProperty(string dpName, Type ownerType, int samplerRegisterIndex, SamplingMode samplingMode)
 {
   return default(System.Windows.DependencyProperty);
 }
 protected static System.Windows.PropertyChangedCallback PixelShaderSamplerCallback(int samplerRegisterIndex, SamplingMode samplingMode)
 {
   return default(System.Windows.PropertyChangedCallback);
 }
Example #27
0
        /// <summary>
        /// Resizes an image by the specified scale factors using the specified sampling mode.
        /// </summary>
        /// <param name="image">Image to resize.</param>
        /// <param name="scaleX">Scale factor to apply in X direction.</param>
        /// <param name="scaleY">Scale factor to apply in Y direction.</param>
        /// <param name="mode">Sampling mode for sampling of pixels.</param>
        /// <returns>Returns a new image scaled by the specified scale factors.</returns>
        public static Shared <Image> Scale(this Image image, float scaleX, float scaleY, SamplingMode mode)
        {
            if (scaleX == 0.0 || scaleY == 0.0)
            {
                throw new System.Exception("Unexpected scale factors");
            }

            if (image.PixelFormat == PixelFormat.Gray_16bpp)
            {
                throw new System.NotSupportedException(
                          "Scaling 16bpp images is not currently supported. " +
                          "Convert to a supported format such as color or 8bpp grayscale first.");
            }

            int dstWidth  = (int)(image.Width * scaleX);
            int dstHeight = (int)(image.Height * scaleY);

            using (var bitmap = new Bitmap(dstWidth, dstHeight))
            {
                using (var graphics = Graphics.FromImage(bitmap))
                {
                    graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    switch (mode)
                    {
                    case SamplingMode.Point:
                        graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                        graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                        graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                        graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed;
                        break;

                    case SamplingMode.Bilinear:
                        graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
                        graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                        break;

                    case SamplingMode.Bicubic:
                        graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        graphics.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                        break;
                    }

                    graphics.ScaleTransform(scaleX, scaleY);

                    using (var managedimg = image.ToManagedImage())
                    {
                        graphics.DrawImage(managedimg, new Point(0, 0));
                    }

                    return(ImagePool.GetOrCreate(bitmap));
                }
            }
        }
Example #28
0
        public static CrossSectionGraph GenerateFromSampler(Device device, Rectangle area,
                                                            Vector3 start, Vector3 end,
                                                            int density, Bitmap bitmap,
                                                            SamplingMode sampling)
        {
            CrossSectionGraph graph = new CrossSectionGraph(device, area, start, end, density);

            // determine real start and end positions in the data set (if out of bounds)
            // (basicaly rectangle intersection)
            Vector2             intersectHP = new Vector2(graph.worldStart.X, graph.worldStart.Z);
            Vector2             intersectLP = new Vector2(graph.worldEnd.X, graph.worldEnd.Z);
            LiangBarskyClipping clipping    = new LiangBarskyClipping(area);

            if (clipping.ClipLine(ref intersectLP, ref intersectHP))
            {
                graph.sampleStart = intersectHP;
                graph.sampleEnd   = intersectLP;
                // determine sample points
                Vector2 intersectionV = new Vector2(intersectLP.X - intersectHP.X, intersectLP.Y - intersectHP.Y);

                // determine x-axis sample points
                // round start up and end down
                int startX     = intersectHP.X != 0 ? (int)Math.Ceiling(intersectHP.X / density) : 0;
                int endX       = intersectLP.X != 0 ? (int)Math.Floor(intersectLP.X / density) : 0;
                int xAxisCount = endX - startX;
                startX *= density;
                endX   *= density;

                int startY     = intersectHP.Y != 0 ? (int)Math.Ceiling(intersectHP.Y / density) : 0;
                int endY       = intersectLP.Y != 0 ? (int)Math.Floor(intersectLP.Y / density) : 0;
                int yAxisCount = endY - startY;
                startY *= density;
                endY   *= density;

                // add extra points for start and end if not exactly on boundaries
                int extra = 0;
                if (intersectHP.X != startX && intersectHP.Y != startY)
                {
                    extra++;
                }
                if (intersectLP.X != endX && intersectLP.Y != endY)
                {
                    extra++;
                }

                // write x values into array
                int pIdx = 0;
                graph.points = new Point3D[xAxisCount + yAxisCount + extra];
                if (intersectHP.X != startX && intersectHP.Y != startY)
                {
                    graph.points[pIdx]            = new Point3D();
                    graph.points[pIdx++].Position = new Vector3(intersectHP.X, float.NaN, intersectHP.Y);
                }

                Vector2 v  = new Vector2(0, 1);
                Vector2 s  = new Vector2(0, area.Top);
                Vector2 hp = new Vector2(intersectHP.X, intersectHP.Y);
                for (int i = startX; i < endX; i += density)
                {
                    // get y intersection point
                    s.X = i;
                    Vector2 p;
                    IntersectLineAABB.LineIntersection(hp, intersectionV, s, v, out p);

                    graph.points[pIdx]            = new Point3D();
                    graph.points[pIdx++].Position = new Vector3(i, float.NaN, p.Y);
                }

                v = new Vector2(1, 0);
                s = new Vector2(area.Left, 0);
                for (int i = startY; i < endY; i += density)
                {
                    Vector2 p;
                    s.Y = i;
                    IntersectLineAABB.LineIntersection(hp, intersectionV, s, v, out p);

                    graph.points[pIdx]            = new Point3D();
                    graph.points[pIdx++].Position = new Vector3(p.X, float.NaN, i);
                }

                if (intersectLP.X != endX && intersectLP.Y != endY)
                {
                    graph.points[pIdx]            = new Point3D();
                    graph.points[pIdx++].Position = new Vector3(intersectLP.X, float.NaN, intersectLP.Y);
                }

                // measure & sort by distance from HP
                float[] distances = new float[graph.points.Length];
                for (int i = 0; i < distances.Length; i++)
                {
                    //if (distances[i] != -1)
                    //{
                    float x = graph.points[i].Position.X - intersectHP.X;
                    float y = graph.points[i].Position.Z - intersectHP.Y;
                    distances[i] = (float)Math.Sqrt((x * x) + (y * y));
                    // check for duplicates

                    /*for (int d = i + 1; d < distances.Length; d++)
                     * {
                     *  if (graph.points[d].Position == graph.points[i].Position)
                     *  {
                     *      distances[d] = -1;
                     *  }
                     * }*/
                    //}
                }

                int[] order = new int[distances.Length];
                for (int i = 0; i < distances.Length; i++)
                {
                    order[i] = i;
                }
                for (int o = 0; o < order.Length; o++)
                {
                    for (int d = o + 1; d < order.Length; d++)
                    {
                        if (distances[order[d]] < distances[order[o]])
                        {
                            int temp = order[o];
                            order[o] = order[d];
                            order[d] = temp;
                        }
                    }
                }

                // re-arange array for new order
                Point3D[] newPoints = new Point3D[graph.points.Length];
                for (int i = 0; i < graph.points.Length; i++)
                {
                    newPoints[i] = graph.points[order[i]];
                }
                graph.points = newPoints;

                // Take the actual height samples
                for (int i = 0; i < graph.points.Length; i++)
                {
                    graph.points[i].Position.Y = bitmap.GetPixel((int)graph.points[i].Position.X,
                                                                 (int)graph.points[i].Position.Z).R;
                }

                return(graph);
            }
            return(null);
        }
Example #29
0
 /// <summary>
 /// Construct a PropertyChangedCallback which, when invoked, will result
 /// in the DP being associated with the specified shader sampler
 /// register index. Expected to be called on a Brush-valued
 /// DependencyProperty.
 /// </summary>
 protected static PropertyChangedCallback PixelShaderSamplerCallback(int samplerRegisterIndex, SamplingMode samplingMode)
 {
     return
         ((obj, args) =>
     {
         ShaderEffect eff = obj as ShaderEffect;
         if (eff != null)
         {
             if (args.IsAValueChange)
             {
                 eff.UpdateShaderSampler(args.Property, args.NewValue, samplerRegisterIndex, samplingMode);
             }
         }
     });
 }
 protected static System.Windows.PropertyChangedCallback PixelShaderSamplerCallback(int samplerRegisterIndex, SamplingMode samplingMode)
 {
     return(default(System.Windows.PropertyChangedCallback));
 }
 protected static System.Windows.DependencyProperty RegisterPixelShaderSamplerProperty(string dpName, Type ownerType, int samplerRegisterIndex, SamplingMode samplingMode)
 {
     return(default(System.Windows.DependencyProperty));
 }
Example #32
0
		protected static DependencyProperty RegisterPixelShaderSamplerProperty (string dpName,
											Type ownerType,
											int samplerRegisterIndex,
											SamplingMode samplingMode)
		{
			return DependencyProperty.Register (dpName, typeof(Brush), ownerType, new PropertyMetadata (null, PixelShaderSamplerCallback (samplerRegisterIndex, samplingMode)));
		}
Example #33
0
        // Updates the shader sampler referred to by the DP.  Converts to the
        // form that the HLSL shaders want, and stores that value, since it will
        // be sent on every update.
        // We WritePreamble/Postscript here since this method is called by the user with the callback
        // created in PixelShaderSamplerCallback.
        private void UpdateShaderSampler(DependencyProperty dp, object newValue, int registerIndex, SamplingMode samplingMode)
        {
            WritePreamble();

            if (newValue != null)
            {
                if (!(typeof(VisualBrush).IsInstanceOfType(newValue) ||
                      typeof(BitmapCacheBrush).IsInstanceOfType(newValue) ||
                      typeof(ImplicitInputBrush).IsInstanceOfType(newValue) ||
                      typeof(ImageBrush).IsInstanceOfType(newValue))
                    )
                {
                    // Note that if the type of the brush is ImplicitInputBrush and the value is non null, the value is actually
                    // Effect.ImplicitInput. This is because ImplicitInputBrush is internal and the user can only get to the singleton
                    // Effect.ImplicitInput.
                    throw new ArgumentException(SR.Get(SRID.Effect_ShaderSamplerType), "dp");
                }
            }

            //
            // Treat as ps_2_0 by default
            //
            int    registerMax = PS_2_0_SAMPLER_LIMIT;
            string srid        = SRID.Effect_Shader20SamplerRegisterLimit;

            if (PixelShader != null && PixelShader.ShaderMajorVersion >= 3)
            {
                registerMax = PS_3_0_SAMPLER_LIMIT;
                srid        = SRID.Effect_Shader30SamplerRegisterLimit;
            }

            if (registerIndex >= registerMax || registerIndex < 0)
            {
                throw new ArgumentException(SR.Get(srid));
            }

            SamplerData sd = new SamplerData()
            {
                _brush        = (Brush)newValue,
                _samplingMode = samplingMode
            };

            StashSamplerDataInPosition(registerIndex, sd, registerMax);

            // Propagate dirty
            this.PropertyChanged(dp);
            WritePostscript();
        }
Example #34
0
        /// <summary>
        /// Read ini file.
        /// </summary>
        /// <returns>result</returns>
        public bool ReadParameterIni()
        {
            ClrMsppManager msObj = ClrMsppManager.getInstance();
            ClrIniFile     ini   = msObj.getParameters();

            uint   sectionNum = ini.getNumberOfSections();
            uint   parameterNum;
            string parameterName;
            bool   flgSectionFound = default(bool);
            string errMsg          = "";

            for (uint i = 0; i < sectionNum; i++)
            {
                if (ini.getSection(i) == PARAMETERS_INI_SECTION_NAME)
                {
                    parameterNum    = ini.getNumberOfParameters(ini.getSection(i));
                    flgSectionFound = true;

                    for (uint j = 0; j < parameterNum; j++)
                    {
                        parameterName = ini.getParameterName(ini.getSection(i), j);
                        string parseResult = ini.getParameterValue(ini.getSection(i), j);
                        switch (parameterName)
                        {
                        //Sampling Points
                        case PARAMETERS_INI_SAMPLINGPOINTS:
                            SamplingMode mode = SamplingMode.FIRST;
                            if (ParseResamplingMode(parseResult, ref errMsg, ref mode) == false)
                            {
                                ErrorMessage += (errMsg + "\n");
                            }
                            else
                            {
                                ResamplingMode = mode;
                            }

                            break;

                        //Interpolation
                        case PARAMETERS_INI_INTERPOLATION:
                            InterpolationAlgorithm pol = InterpolationAlgorithm.LINEAR;
                            if (ParseInterpolation(parseResult, ref errMsg, ref pol) == false)
                            {
                                ErrorMessage += (errMsg + "\n");
                            }
                            Interpolation = pol;

                            break;

                        //Output range MIN
                        case PARAMETERS_INI_OUTPUTRANGEMIN:
                            double?min = null;
                            if (ParseOutputRangeMin(parseResult, ref errMsg, ref min) == false)
                            {
                                ErrorMessage += (errMsg + "\n");
                            }
                            OutputLowerRange = min;

                            break;

                        //Output range MAX
                        case PARAMETERS_INI_OUTPUTRANGEMAX:
                            double?max = null;
                            if (ParseOutputRangeMax(parseResult, ref errMsg, ref max) == false)
                            {
                                ErrorMessage += (errMsg + "\n");
                            }
                            OutputHigherRange = max;

                            break;

                        //Specified Interval
                        case PARAMETERS_INI_SPECIFIED_INTERVAL:
                            double?Interval = null;
                            if (ParseSpecifiedInterval(parseResult, ref errMsg, ref Interval, ResamplingMode) == false)
                            {
                                ErrorMessage = ErrorMessage + errMsg + "\n";
                            }
                            SpecifiedInterval = Interval;

                            break;

                        default:
                            break;
                        }
                    }
                }
            }


            //Debug.WriteLine(ini.getSection(0));

            return(flgSectionFound);
        }