1 //******************************************************************************
2 ///
3 /// @file core/material/warp.h
4 ///
5 /// Declarations related to warps.
6 ///
7 /// @copyright
8 /// @parblock
9 ///
10 /// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11 /// Copyright 1991-2017 Persistence of Vision Raytracer Pty. Ltd.
12 ///
13 /// POV-Ray is free software: you can redistribute it and/or modify
14 /// it under the terms of the GNU Affero General Public License as
15 /// published by the Free Software Foundation, either version 3 of the
16 /// License, or (at your option) any later version.
17 ///
18 /// POV-Ray is distributed in the hope that it will be useful,
19 /// but WITHOUT ANY WARRANTY; without even the implied warranty of
20 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 /// GNU Affero General Public License for more details.
22 ///
23 /// You should have received a copy of the GNU Affero General Public License
24 /// along with this program.  If not, see <http://www.gnu.org/licenses/>.
25 ///
26 /// ----------------------------------------------------------------------------
27 ///
28 /// POV-Ray is based on the popular DKB raytracer version 2.12.
29 /// DKBTrace was originally written by David K. Buck.
30 /// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
31 ///
32 /// @endparblock
33 ///
34 //******************************************************************************
35 
36 #ifndef POVRAY_CORE_WARP_H
37 #define POVRAY_CORE_WARP_H
38 
39 // Module config header file must be the first file included within POV-Ray unit header files
40 #include "core/configcore.h"
41 
42 #include "core/math/matrix.h"
43 #include "core/math/vector.h"
44 
45 namespace pov
46 {
47 
48 //##############################################################################
49 ///
50 /// @defgroup PovCoreMaterialWarp Texture Warps
51 /// @ingroup PovCore
52 ///
53 /// @{
54 
55 /*****************************************************************************
56 * Global typedefs
57 ******************************************************************************/
58 
59 struct GenericWarp
60 {
~GenericWarpGenericWarp61     virtual ~GenericWarp() {}
62     virtual GenericWarp* Clone() const = 0;
63     virtual bool WarpPoint(Vector3d& rP) const = 0;
64     virtual bool WarpNormal(Vector3d& rN) const = 0;
65     virtual bool UnwarpNormal(Vector3d& rN) const = 0;
66 };
67 
68 typedef GenericWarp* WarpPtr;
69 typedef const GenericWarp* ConstWarpPtr;
70 typedef vector<WarpPtr> WarpList;
71 
72 
73 struct BlackHoleWarp : public GenericWarp
74 {
BlackHoleWarpBlackHoleWarp75     BlackHoleWarp() :
76         GenericWarp(), Center(0.0), Repeat_Vector(0.0), Uncertainty_Vector(0.0), Strength(1.0), Radius(1.0),
77         Radius_Squared(1.0), Inverse_Radius(1.0), Power(2.0), Type(0), Inverted(false), Repeat(false), Uncertain(false)
78     {}
BlackHoleWarpBlackHoleWarp79     BlackHoleWarp(const BlackHoleWarp& old) :
80         GenericWarp(old), Center(old.Center), Repeat_Vector(old.Repeat_Vector),
81         Uncertainty_Vector(old.Uncertainty_Vector), Strength(old.Strength), Radius(old.Radius),
82         Radius_Squared(old.Radius_Squared), Inverse_Radius(old.Inverse_Radius), Power(old.Power), Type(old.Type),
83         Inverted(old.Inverted), Repeat(old.Repeat), Uncertain(old.Uncertain)
84     {}
85 
CloneBlackHoleWarp86     virtual GenericWarp* Clone() const { return new BlackHoleWarp(*this); }
87     virtual bool WarpPoint(Vector3d& rP) const;
88     virtual bool WarpNormal(Vector3d& rN) const;
89     virtual bool UnwarpNormal(Vector3d& rN) const;
90 
91     Vector3d    Center;
92     Vector3d    Repeat_Vector;
93     Vector3d    Uncertainty_Vector;
94     DBL         Strength;
95     DBL         Radius;
96     DBL         Radius_Squared;
97     DBL         Inverse_Radius;
98     DBL         Power;
99     short       Type;
100     bool        Inverted;
101     bool        Repeat;
102     bool        Uncertain;
103 };
104 
105 struct CubicWarp : public GenericWarp
106 {
CubicWarpCubicWarp107     CubicWarp() : GenericWarp() {}
CubicWarpCubicWarp108     CubicWarp(const CubicWarp& old) : GenericWarp(old) {}
109 
CloneCubicWarp110     virtual GenericWarp* Clone() const { return new CubicWarp(*this); }
111     virtual bool WarpPoint(Vector3d& rP) const;
112     virtual bool WarpNormal(Vector3d& rN) const;
113     virtual bool UnwarpNormal(Vector3d& rN) const;
114 };
115 
116 struct CylindricalWarp : public GenericWarp
117 {
CylindricalWarpCylindricalWarp118     CylindricalWarp() :
119         GenericWarp(), Orientation_Vector(0.0, 0.0, 1.0), DistExp(0.0)
120     {}
CylindricalWarpCylindricalWarp121     CylindricalWarp(const CylindricalWarp& old) :
122         GenericWarp(old), Orientation_Vector(old.Orientation_Vector), DistExp(old.DistExp)
123     {}
124 
CloneCylindricalWarp125     virtual GenericWarp* Clone() const { return new CylindricalWarp(*this); }
126     virtual bool WarpPoint(Vector3d& rP) const;
127     virtual bool WarpNormal(Vector3d& rN) const;
128     virtual bool UnwarpNormal(Vector3d& rN) const;
129 
130     Vector3d Orientation_Vector;
131     DBL DistExp;
132 };
133 
134 struct IdentityWarp : public GenericWarp
135 {
IdentityWarpIdentityWarp136     IdentityWarp() : GenericWarp() {}
IdentityWarpIdentityWarp137     IdentityWarp(const IdentityWarp& old) : GenericWarp(old) {}
138 
CloneIdentityWarp139     virtual GenericWarp* Clone() const { return new IdentityWarp(*this); }
140     virtual bool WarpPoint(Vector3d& rP) const;
141     virtual bool WarpNormal(Vector3d& rN) const;
142     virtual bool UnwarpNormal(Vector3d& rN) const;
143 };
144 
145 struct PlanarWarp : public GenericWarp
146 {
PlanarWarpPlanarWarp147     PlanarWarp() :
148         GenericWarp(), Orientation_Vector(0.0, 0.0, 1.0), OffSet(0.0)
149     {}
PlanarWarpPlanarWarp150     PlanarWarp(const PlanarWarp& old) :
151         GenericWarp(old), Orientation_Vector(old.Orientation_Vector), OffSet(old.OffSet)
152     {}
153 
ClonePlanarWarp154     virtual GenericWarp* Clone() const { return new PlanarWarp(*this); }
155     virtual bool WarpPoint(Vector3d& rP) const;
156     virtual bool WarpNormal(Vector3d& rN) const;
157     virtual bool UnwarpNormal(Vector3d& rN) const;
158 
159     Vector3d Orientation_Vector;
160     DBL OffSet;
161 };
162 
163 struct RepeatWarp : public GenericWarp
164 {
RepeatWarpRepeatWarp165     RepeatWarp() :
166         GenericWarp(), Axis(-1), Width(0.0), Flip(1.0), Offset(0.0)
167     {}
RepeatWarpRepeatWarp168     RepeatWarp(const RepeatWarp& old) :
169         GenericWarp(old), Axis(old.Axis), Width(old.Width), Flip(old.Flip), Offset(old.Offset)
170     {}
171 
CloneRepeatWarp172     virtual GenericWarp* Clone() const { return new RepeatWarp(*this); }
173     virtual bool WarpPoint(Vector3d& rP) const;
174     virtual bool WarpNormal(Vector3d& rN) const;
175     virtual bool UnwarpNormal(Vector3d& rN) const;
176 
177     int Axis;
178     SNGL Width;
179     Vector3d Flip, Offset;
180 };
181 
182 struct SphericalWarp : public GenericWarp
183 {
SphericalWarpSphericalWarp184     SphericalWarp() :
185         GenericWarp(), Orientation_Vector(0.0, 0.0, 1.0), DistExp(0.0)
186     {}
SphericalWarpSphericalWarp187     SphericalWarp(const SphericalWarp& old) :
188         GenericWarp(old), Orientation_Vector(old.Orientation_Vector), DistExp(old.DistExp)
189      {}
190 
CloneSphericalWarp191     virtual GenericWarp* Clone() const { return new SphericalWarp(*this); }
192     virtual bool WarpPoint(Vector3d& rP) const;
193     virtual bool WarpNormal(Vector3d& rN) const;
194     virtual bool UnwarpNormal(Vector3d& rN) const;
195 
196     Vector3d Orientation_Vector;
197     DBL DistExp;
198 };
199 
200 struct ToroidalWarp : public GenericWarp
201 {
ToroidalWarpToroidalWarp202     ToroidalWarp() :
203         GenericWarp(), Orientation_Vector(0.0, 0.0, 1.0), DistExp(0.0), MajorRadius(1.0)
204     {}
ToroidalWarpToroidalWarp205     ToroidalWarp(const ToroidalWarp& old) :
206         GenericWarp(old), Orientation_Vector(old.Orientation_Vector), DistExp(old.DistExp),
207         MajorRadius(old.MajorRadius)
208     {}
209 
CloneToroidalWarp210     virtual GenericWarp* Clone() const { return new ToroidalWarp(*this); }
211     virtual bool WarpPoint(Vector3d& rP) const;
212     virtual bool WarpNormal(Vector3d& rN) const;
213     virtual bool UnwarpNormal(Vector3d& rN) const;
214 
215     Vector3d Orientation_Vector;
216     DBL DistExp;
217     DBL MajorRadius;
218 };
219 
220 struct TransformWarp : public GenericWarp
221 {
TransformWarpTransformWarp222     TransformWarp() :
223         GenericWarp()
224     {
225         MIdentity(Trans.matrix);
226         MIdentity(Trans.inverse);
227     }
TransformWarpTransformWarp228     TransformWarp(const TransformWarp& old) :
229         GenericWarp(old), Trans(old.Trans)
230     {}
231 
CloneTransformWarp232     virtual GenericWarp* Clone() const { return new TransformWarp(*this); }
233     virtual bool WarpPoint(Vector3d& rP) const;
234     virtual bool WarpNormal(Vector3d& rN) const;
235     virtual bool UnwarpNormal(Vector3d& rN) const;
236 
237     TRANSFORM Trans;
238 };
239 
240 
241 struct GenericTurbulenceWarp : public GenericWarp
242 {
GenericTurbulenceWarpGenericTurbulenceWarp243     GenericTurbulenceWarp() :
244         GenericWarp(), Turbulence(0.0), Octaves(6), Omega(0.5), Lambda(2.0)
245     {}
GenericTurbulenceWarpGenericTurbulenceWarp246     GenericTurbulenceWarp(const GenericTurbulenceWarp& old) :
247         GenericWarp(old), Turbulence(old.Turbulence), Octaves(old.Octaves), Lambda(old.Lambda), Omega(old.Omega)
248     {}
249 
250     virtual GenericWarp* Clone() const = 0;
251     virtual bool WarpPoint(Vector3d& rP) const;
252     virtual bool WarpNormal(Vector3d& rN) const;
253     virtual bool UnwarpNormal(Vector3d& rN) const;
254 
255     Vector3d Turbulence;
256     int Octaves;
257     SNGL Lambda, Omega;
258 };
259 
260 /// Genuine turbulence warp.
261 struct TurbulenceWarp : public GenericTurbulenceWarp
262 {
TurbulenceWarpTurbulenceWarp263     TurbulenceWarp() : GenericTurbulenceWarp() {}
TurbulenceWarpTurbulenceWarp264     TurbulenceWarp(const TurbulenceWarp& old) : GenericTurbulenceWarp(old) {}
265 
CloneTurbulenceWarp266     virtual GenericWarp* Clone() const { return new TurbulenceWarp(*this); }
267 };
268 
269 /// Turbulence tied to a pattern.
270 struct ClassicTurbulence : public GenericTurbulenceWarp
271 {
ClassicTurbulenceClassicTurbulence272     ClassicTurbulence(bool hbp) :
273         GenericTurbulenceWarp(), handledByPattern(hbp)
274     {}
ClassicTurbulenceClassicTurbulence275     ClassicTurbulence(const ClassicTurbulence& old) :
276         GenericTurbulenceWarp(old), handledByPattern(old.handledByPattern)
277     {}
278 
CloneClassicTurbulence279     virtual GenericWarp* Clone() const { return new ClassicTurbulence(*this); }
280 
281     bool handledByPattern;
282 };
283 
284 
285 /*****************************************************************************
286 * Global functions
287 ******************************************************************************/
288 
289 void Warp_EPoint (Vector3d& TPoint, const Vector3d& EPoint, const TPATTERN *TPat);
290 void Destroy_Warps (WarpList& rWarps);
291 void Copy_Warps (WarpList& rNew, const WarpList& old);
292 void Warp_Normal (Vector3d& TNorm, const Vector3d& ENorm, const TPATTERN *TPat, bool DontScaleBumps);
293 void UnWarp_Normal (Vector3d& TNorm, const Vector3d& ENorm, const TPATTERN *TPat, bool DontScaleBumps);
294 
295 /// @}
296 ///
297 //##############################################################################
298 
299 }
300 
301 #endif // POVRAY_CORE_WARP_H
302