/// <summary>
        /// Builds the noise map.
        ///
        /// @pre SetBounds() was previously called.
        /// @pre NoiseMap was previously defined.
        /// @pre a SourceModule was previously defined.
        /// @pre The width and height values specified by SetSize() are
        /// positive.
        /// @pre The width and height values specified by SetSize() do not
        /// exceed the maximum possible width and height for the noise map.
        ///
        /// @post The original contents of the destination noise map is
        /// destroyed.
        ///
        /// @throw noise::ArgumentException See the preconditions.
        ///
        /// If this method is successful, the destination noise map contains
        /// the coherent-noise values from the noise module specified by
        /// the SourceModule.
        /// </summary>
        public override void Build()
        {
            if (_lowerXBound >= _upperXBound || _lowerZBound >= _upperZBound)
            {
                throw new ArgumentException(
                          "Incoherent bounds : lowerXBound >= upperXBound or lowerZBound >= upperZBound");
            }

            if (PWidth < 0 || PHeight < 0)
            {
                throw new ArgumentException("Dimension must be greater or equal 0");
            }

            if (PSourceModule == null)
            {
                throw new ArgumentException("A source module must be provided");
            }

            if (PNoiseMap == null)
            {
                throw new ArgumentException("A noise map must be provided");
            }

            // Resize the destination noise map so that it can store the new output
            // values from the source model.
            PNoiseMap.SetSize(PWidth, PHeight);

            // Create the plane model.
            var model = new Plane(PSourceModule);

            float xExtent = _upperXBound - _lowerXBound;
            float zExtent = _upperZBound - _lowerZBound;
            float xDelta  = xExtent / PWidth;
            float zDelta  = zExtent / PHeight;
            float xCur    = _lowerXBound;
            float zCur    = _lowerZBound;

            // Fill every point in the noise map with the output values from the model.
            for (int z = 0; z < PHeight; z++)
            {
                xCur = _lowerXBound;

                for (int x = 0; x < PWidth; x++)
                {
                    float finalValue;
                    var   level = FilterLevel.Source;

                    if (PFilter != null)
                    {
                        level = PFilter.IsFiltered(x, z);
                    }

                    if (level == FilterLevel.Constant)
                    {
                        finalValue = PFilter.ConstantValue;
                    }
                    else
                    {
                        if (_seamless)
                        {
                            float swValue = model.GetValue(xCur, zCur);
                            float seValue = model.GetValue(xCur + xExtent, zCur);
                            float nwValue = model.GetValue(xCur, zCur + zExtent);
                            float neValue = model.GetValue(xCur + xExtent, zCur + zExtent);

                            float xBlend = 1.0f - ((xCur - _lowerXBound) / xExtent);
                            float zBlend = 1.0f - ((zCur - _lowerZBound) / zExtent);

                            float z0 = Libnoise.Lerp(swValue, seValue, xBlend);
                            float z1 = Libnoise.Lerp(nwValue, neValue, xBlend);

                            finalValue = Libnoise.Lerp(z0, z1, zBlend);
                        }
                        else
                        {
                            finalValue = model.GetValue(xCur, zCur);
                        }

                        if (level == FilterLevel.Filter && PFilter != null)
                        {
                            finalValue = PFilter.FilterValue(x, z, finalValue);
                        }
                    }

                    PNoiseMap.SetValue(x, z, finalValue);

                    xCur += xDelta;
                }

                zCur += zDelta;

                if (PCallBack != null)
                {
                    PCallBack(z);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Builds the noise map.
        ///
        /// @pre SetBounds() was previously called.
        /// @pre NoiseMap was previously defined.
        /// @pre a SourceModule was previously defined.
        /// @pre The width and height values specified by SetSize() are
        /// positive.
        /// @pre The width and height values specified by SetSize() do not
        /// exceed the maximum possible width and height for the noise map.
        ///
        /// @post The original contents of the destination noise map is
        /// destroyed.
        ///
        /// @throw noise::ArgumentException See the preconditions.
        ///
        /// If this method is successful, the destination noise map contains
        /// the coherent-noise values from the noise module specified by
        /// the SourceModule.
        /// </summary>
        public override void Build()
        {
            if (_lowerAngleBound >= _upperAngleBound || _lowerHeightBound >= _upperHeightBound)
            {
                throw new ArgumentException(
                          "Incoherent bounds : lowerAngleBound >= upperAngleBound or lowerZBound >= upperHeightBound");
            }

            if (PWidth < 0 || PHeight < 0)
            {
                throw new ArgumentException("Dimension must be greater or equal 0");
            }

            if (PSourceModule == null)
            {
                throw new ArgumentException("A source module must be provided");
            }

            if (PNoiseMap == null)
            {
                throw new ArgumentException("A noise map must be provided");
            }

            // Resize the destination noise map so that it can store the new output
            // values from the source model.
            PNoiseMap.SetSize(PWidth, PHeight);

            // Create the plane model.
            var model = new Cylinder((IModule3D)PSourceModule);

            double angleExtent  = _upperAngleBound - _lowerAngleBound;
            double heightExtent = _upperHeightBound - _lowerHeightBound;

            double xDelta = angleExtent / PWidth;
            double yDelta = heightExtent / PHeight;

            double curAngle  = _lowerAngleBound;
            double curHeight = _lowerHeightBound;

            // Fill every point in the noise map with the output values from the model.
            for (int y = 0; y < PHeight; y++)
            {
                curAngle = _lowerAngleBound;

                for (int x = 0; x < PWidth; x++)
                {
                    double finalValue;
                    var    level = FilterLevel.Source;

                    if (PFilter != null)
                    {
                        level = PFilter.IsFiltered(x, y);
                    }

                    if (level == FilterLevel.Constant && PFilter != null)
                    {
                        finalValue = PFilter.ConstantValue;
                    }
                    else
                    {
                        finalValue = model.GetValue(curAngle, curHeight);

                        if (level == FilterLevel.Filter && PFilter != null)
                        {
                            finalValue = PFilter.FilterValue(x, y, finalValue);
                        }
                    }

                    PNoiseMap.SetValue(x, y, finalValue);

                    curAngle += xDelta;
                }

                curHeight += yDelta;

                if (PCallBack != null)
                {
                    PCallBack(y);
                }
            }
        }
        /// <summary>
        /// Builds the noise map.
        ///
        /// @pre SetBounds() was previously called.
        /// @pre NoiseMap was previously defined.
        /// @pre a SourceModule was previously defined.
        /// @pre The width and height values specified by SetSize() are
        /// positive.
        /// @pre The width and height values specified by SetSize() do not
        /// exceed the maximum possible width and height for the noise map.
        ///
        /// @post The original contents of the destination noise map is
        /// destroyed.
        ///
        /// @throw noise::ArgumentException See the preconditions.
        ///
        /// If this method is successful, the destination noise map contains
        /// the coherent-noise values from the noise module specified by
        /// the SourceModule.
        /// </summary>
        public override void Build()
        {
            if (_southLatBound >= _northLatBound || _westLonBound >= _eastLonBound)
            {
                throw new ArgumentException(
                          "Incoherent bounds : southLatBound >= northLatBound or westLonBound >= eastLonBound");
            }

            if (PWidth < 0 || PHeight < 0)
            {
                throw new ArgumentException("Dimension must be greater or equal 0");
            }

            if (PSourceModule == null)
            {
                throw new ArgumentException("A source module must be provided");
            }

            if (PNoiseMap == null)
            {
                throw new ArgumentException("A noise map must be provided");
            }

            // Resize the destination noise map so that it can store the new output
            // values from the source model.
            PNoiseMap.SetSize(PWidth, PHeight);

            // Create the plane model.
            var model = new Sphere((IModule3D)PSourceModule);

            float lonExtent = _eastLonBound - _westLonBound;
            float latExtent = _northLatBound - _southLatBound;

            float xDelta = lonExtent / PWidth;
            float yDelta = latExtent / PHeight;

            float curLon = _westLonBound;
            float curLat = _southLatBound;

            // Fill every point in the noise map with the output values from the model.
            for (int y = 0; y < PHeight; y++)
            {
                curLon = _westLonBound;

                for (int x = 0; x < PWidth; x++)
                {
                    float finalValue;
                    var   level = FilterLevel.Source;

                    if (PFilter != null)
                    {
                        level = PFilter.IsFiltered(x, y);
                    }

                    if (level == FilterLevel.Constant)
                    {
                        finalValue = PFilter.ConstantValue;
                    }
                    else
                    {
                        finalValue = model.GetValue(curLat, curLon);

                        if (level == FilterLevel.Filter)
                        {
                            finalValue = PFilter.FilterValue(x, y, finalValue);
                        }
                    }

                    PNoiseMap.SetValue(x, y, finalValue);

                    curLon += xDelta;
                }

                curLat += yDelta;

                if (PCallBack != null)
                {
                    PCallBack(y);
                }
            }
        }