1 /**************************************************************************/
2 /* Copyright 2012 Tim Day */
3 /* */
4 /* This file is part of Evolvotron */
5 /* */
6 /* Evolvotron is free software: you can redistribute it and/or modify */
7 /* it under the terms of the GNU General Public License as published by */
8 /* the Free Software Foundation, either version 3 of the License, or */
9 /* (at your option) any later version. */
10 /* */
11 /* Evolvotron is distributed in the hope that it will be useful, */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
14 /* GNU General Public License for more details. */
15 /* */
16 /* You should have received a copy of the GNU General Public License */
17 /* along with Evolvotron. If not, see <http://www.gnu.org/licenses/>. */
18 /**************************************************************************/
19
20 /*! \file
21 \brief Implementation for class TransformFactory.
22 */
23
24
25
26 #include "transform_factory.h"
27
28 #include "random.h"
29 #include "transform.h"
30
operator ()(Random01 & r01) const31 const Transform TransformFactoryRandomWarpXY::operator()(Random01& r01) const
32 {
33 // Gives a scale between 0.5 and 2, average 1.
34 const real r=pow(2.0,2.0*r01()-1.0);
35
36 // Random rotation
37 const real a=(2.0*M_PI)*r01();
38
39 const XYZ basis_x( r*cos(a), r*sin(a),0.0);
40 const XYZ basis_y(-r*sin(a), r*cos(a),0.0);
41 const XYZ basis_z(0.0,0.0,1.0);
42
43 // Random translation
44 const real tx=2.0*r01()-1.0;
45 const real ty=2.0*r01()-1.0;
46 const XYZ translate(tx,ty,0.0);
47
48 return Transform(translate,basis_x,basis_y,basis_z);
49 }
50
operator ()(Random01 & rng) const51 const Transform TransformFactoryRandomScaleXY::operator()(Random01& rng) const
52 {
53 const XYZ translate(0.0,0.0,0.0);
54
55 const real p=rng();
56 const real s=pow(2.0,_lopow2+p*(_hipow2-_lopow2));
57 const XYZ basis_x( s,0.0,0.0);
58 const XYZ basis_y(0.0, s,0.0);
59 const XYZ basis_z(0.0,0.0,1.0);
60
61 return Transform(translate,basis_x,basis_y,basis_z);
62 }
63
operator ()(Random01 & r01) const64 const Transform TransformFactoryRandomRotateZ::operator()(Random01& r01) const
65 {
66 // Random rotation
67 const real a=(2.0*M_PI)*r01();
68 const real ca=cos(a);
69 const real sa=sin(a);
70
71 const XYZ basis_x( ca, sa,0.0);
72 const XYZ basis_y( -sa, ca,0.0);
73 const XYZ basis_z(0.0,0.0,1.0);
74 const XYZ translate(0.0,0.0,0.0);
75
76 return Transform(translate,basis_x,basis_y,basis_z);
77 }
78
operator ()(Random01 & r01) const79 const Transform TransformFactoryRandomTranslateXYZ::operator()(Random01& r01) const
80 {
81 const XYZ translate(_origin+RandomXYZInBox(r01,_range));
82 const XYZ basis_x(1.0,0.0,0.0);
83 const XYZ basis_y(0.0,1.0,0.0);
84 const XYZ basis_z(1.0,0.0,1.0);
85
86 return Transform(translate,basis_x,basis_y,basis_z);
87 }
88