1 // scalebias.h
2 //
3 // Copyright (C) 2003, 2004 Jason Bevins
4 //
5 // This library is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 2.1 of the License, or (at
8 // your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
13 // License (COPYING.txt) for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 //
19 // The developer's email is jlbezigvins@gmzigail.com (for great email, take
20 // off every 'zig'.)
21 //
22 module noise.mod.scalebias;
23 
24 private {
25     import noise.mod.modulebase;
26 }
27 
28 /// @addtogroup libnoise
29 /// @{
30 
31 /// @addtogroup modules
32 /// @{
33 
34 /// @addtogroup modifiermodules
35 /// @{
36 
37 /// Default bias for the module::ScaleBias noise module.
38 const double DEFAULT_BIAS = 0.0;
39 
40 /// Default scale for the module::ScaleBias noise module.
41 const double DEFAULT_SCALE = 1.0;
42 
43 /// Noise module that applies a scaling factor and a bias to the output
44 /// value from a source module.
45 ///
46 /// @image html modulescalebias.png
47 ///
48 /// The GetValue() method retrieves the output value from the source
49 /// module, multiplies it with a scaling factor, adds a bias to it, then
50 /// outputs the value.
51 ///
52 /// This noise module requires one source module.
53 class ScaleBias : Mod
54 {
55 
56   public:
57 
58     /// Constructor.
59     ///
60     /// The default bias is set to module::DEFAULT_BIAS.
61     ///
62     /// The default scaling factor is set to module::DEFAULT_SCALE.
63     this()
64     {
65         super(this.GetSourceModCount ());
66         m_bias = DEFAULT_BIAS;
67         m_scale = DEFAULT_SCALE;
68     }
69 
70     /// Returns the bias to apply to the scaled output value from the
71     /// source module.
72     ///
73     /// @returns The bias to apply.
74     ///
75     /// The GetValue() method retrieves the output value from the source
76     /// module, multiplies it with the scaling factor, adds the bias to
77     /// it, then outputs the value.
78     double GetBias () const
79     {
80       return m_bias;
81     }
82 
83     /// Returns the scaling factor to apply to the output value from the
84     /// source module.
85     ///
86     /// @returns The scaling factor to apply.
87     ///
88     /// The GetValue() method retrieves the output value from the source
89     /// module, multiplies it with the scaling factor, adds the bias to
90     /// it, then outputs the value.
91     double GetScale () const
92     {
93       return m_scale;
94     }
95 
96     override int GetSourceModCount () const
97     {
98       return 1;
99     }
100 
101     override double GetValue (double x, double y, double z) const
102     {
103       assert (m_pSourceMod[0] !is null);
104 
105       return m_pSourceMod[0].GetValue (x, y, z) * m_scale + m_bias;
106     }
107 
108     /// Sets the bias to apply to the scaled output value from the source
109     /// module.
110     ///
111     /// @param bias The bias to apply.
112     ///
113     /// The GetValue() method retrieves the output value from the source
114     /// module, multiplies it with the scaling factor, adds the bias to
115     /// it, then outputs the value.
116     void SetBias (double bias)
117     {
118       m_bias = bias;
119     }
120 
121     /// Sets the scaling factor to apply to the output value from the
122     /// source module.
123     ///
124     /// @param scale The scaling factor to apply.
125     ///
126     /// The GetValue() method retrieves the output value from the source
127     /// module, multiplies it with the scaling factor, adds the bias to
128     /// it, then outputs the value.
129     void SetScale (double scale)
130     {
131       m_scale = scale;
132     }
133 
134   protected:
135 
136     /// Bias to apply to the scaled output value from the source module.
137     double m_bias;
138 
139     /// Scaling factor to apply to the output value from the source
140     /// module.
141     double m_scale;
142 
143 };
144 
145 /// @}
146 
147 /// @}
148 
149 /// @}