Пример #1
0
        /// <summary>
        /// Copy pixels in from a source image, rescaling the values to map into a new value range.
        /// </summary>
        /// <param name="src"></param>
        /// <param name="sx"></param>
        /// <param name="sz"></param>
        /// <param name="srcMinHeight"></param>
        /// <param name="srcMaxHeight"></param>
        /// <param name="size"></param>
        /// <param name="destMinHeight"></param>
        /// <param name="destMaxHeight"></param>
        protected virtual void CopyFromImageRescale(Image src, int sx, int sz, float srcMinHeight, float srcMaxHeight, int size, float destMinHeight, float destMaxHeight)
        {
            // copy source sub-image to destination
            double sourceHeightRange = srcMaxHeight - srcMinHeight;
            double destHeightRange   = destMaxHeight - destMinHeight;

            // Convert height range to inverse so that we can use multiplication rather than
            // division in the inner loop.
            double invHeightRange = 1.0 / destHeightRange;

            // loop over all pixels, converting to the world's height range while
            // copying.
            for (int z = 0; z < size; z++)
            {
                for (int x = 0; x < size; x++)
                {
                    double raw = src.GetNormPixel(x + sx, z + sz);

                    double scaledSourceValue = raw * sourceHeightRange + srcMinHeight;
                    double destNorm          = (scaledSourceValue - destMinHeight) * invHeightRange;

                    if (destNorm > 1.0)
                    {
                        destNorm = 1.0;
                    }
                    if (destNorm < 0.0)
                    {
                        destNorm = 0.0;
                    }
                    SetValue(x, z, (uint)(destNorm * MaxSampleValue));
                }
            }

            dirty = true;
        }
Пример #2
0
        /// <summary>
        /// Copy pixels in from a source image, rescaling the values to map into a new value range.
        /// </summary>
        /// <param name="src"></param>
        /// <param name="sx"></param>
        /// <param name="sz"></param>
        /// <param name="srcMinHeight"></param>
        /// <param name="srcMaxHeight"></param>
        /// <param name="size"></param>
        /// <param name="destMinHeight"></param>
        /// <param name="destMaxHeight"></param>
        protected virtual void CopyFromImageRescale(Image src, int sx, int sz, float srcMinHeight, float srcMaxHeight, int size, float destMinHeight, float destMaxHeight)
        {
            // copy source sub-image to destination
            double sourceHeightRange = srcMaxHeight - srcMinHeight;
            double destHeightRange = destMaxHeight - destMinHeight;

            // Convert height range to inverse so that we can use multiplication rather than
            // division in the inner loop.
            double invHeightRange = 1.0 / destHeightRange;

            // loop over all pixels, converting to the world's height range while
            // copying.
            for (int z = 0; z < size; z++)
            {
                for (int x = 0; x < size; x++)
                {
                    double raw = src.GetNormPixel(x + sx, z + sz);

                    double scaledSourceValue = raw * sourceHeightRange + srcMinHeight;
                    double destNorm = (scaledSourceValue - destMinHeight) * invHeightRange;

                    if (destNorm > 1.0)
                    {
                        destNorm = 1.0;
                    }
                    if (destNorm < 0.0)
                    {
                        destNorm = 0.0;
                    }
                    SetValue(x, z, (uint)(destNorm * MaxSampleValue));
                }
            }

            dirty = true;
        }