File: transform_factory.h

package info (click to toggle)
evolvotron 0.6.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,420 kB
  • ctags: 1,367
  • sloc: cpp: 10,462; python: 162; sh: 147; makefile: 9
file content (151 lines) | stat: -rw-r--r-- 4,690 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**************************************************************************/
/*  Copyright 2012 Tim Day                                                */
/*                                                                        */
/*  This file is part of Evolvotron                                       */
/*                                                                        */
/*  Evolvotron is free software: you can redistribute it and/or modify    */
/*  it under the terms of the GNU General Public License as published by  */
/*  the Free Software Foundation, either version 3 of the License, or     */
/*  (at your option) any later version.                                   */
/*                                                                        */
/*  Evolvotron is distributed in the hope that it will be useful,         */
/*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
/*  GNU General Public License for more details.                          */
/*                                                                        */
/*  You should have received a copy of the GNU General Public License     */
/*  along with Evolvotron.  If not, see <http://www.gnu.org/licenses/>.   */
/**************************************************************************/

/*! \file 
  \brief Interface for class TransformFactory.
*/

#ifndef _transform_factory_h_
#define _transform_factory_h_

class Random01;
class Transform;

//! Abstract base class for classes creating Transforms
class TransformFactory 
{
 public:
  TransformFactory()
    {}
  virtual ~TransformFactory()
    {}

  //! Clone functionality needed to retain typed copies of factories.
  virtual std::auto_ptr<TransformFactory> clone() const
    =0;

  //! Method to build a Transform.
  virtual const Transform operator()(Random01&) const
    =0;
 protected:
};

//! Factory for creating random warps
/*! These are the mixed scale/rotate/translate ones used by the combo warp.
*/
class TransformFactoryRandomWarpXY : public TransformFactory
{
 public:
  //! Constructor accepts power-of-2 specifiers, so -1 & 1 would generate scalings between 0.5 and 2, half zooming in and half zooming out.
  // Constructor.
  /*! \todo Should be parameterised with parameters specified at point of usage in MutatableImageDisplay
   */
  TransformFactoryRandomWarpXY()
    {}

  //! Clone.
  virtual std::auto_ptr<TransformFactory> clone() const
    {
      return std::auto_ptr<TransformFactory>(new TransformFactoryRandomWarpXY());
    }

  //! Return a random transform.
  virtual const Transform operator()(Random01& rng) const;

 protected:
};

//! Factory for creating random scaling transforms
class TransformFactoryRandomScaleXY : public TransformFactory
{
 public:
  //! Constructor accepts power-of-2 specifiers, so -1 & 1 would generate scalings between 0.5 and 2, half zooming in and half zooming out.
  TransformFactoryRandomScaleXY(real lopow2,real hipow2)
    :_lopow2(lopow2),_hipow2(hipow2)
    {}

  //! Clone method.
  virtual std::auto_ptr<TransformFactory> clone() const
    {
      return std::auto_ptr<TransformFactory>(new TransformFactoryRandomScaleXY(_lopow2,_hipow2));
    }

  //! Return a random scaling transform.
  virtual const Transform operator()(Random01& rng) const;
 protected:
  //! The low end of the scaling as a power of 2
  real _lopow2;

  //! The high end of the scaling as a power of 2
  real _hipow2;
};

//! Factory for creating random z-axis rotation transforms
class TransformFactoryRandomRotateZ : public TransformFactory
{
 public:
  //! Constructor
  TransformFactoryRandomRotateZ()
    {}

  //! Clone method.
  virtual std::auto_ptr<TransformFactory> clone() const
    {
      return std::auto_ptr<TransformFactory>(new TransformFactoryRandomRotateZ());
    }

  //! Create a transform.
  virtual const Transform operator()(Random01& rng) const;
 protected:
};

//! Factory for creating random translation transforms
class TransformFactoryRandomTranslateXYZ : public TransformFactory
{
 public:
  //! Constructor accepts XYZ origin (centre) and range (+/-)
  TransformFactoryRandomTranslateXYZ(const XYZ& o,const XYZ& r)
    :_origin(o)
    ,_range(r)
    {}

  //! Clone method.
  virtual std::auto_ptr<TransformFactory> clone() const
    {
      return std::auto_ptr<TransformFactory>(new TransformFactoryRandomTranslateXYZ(_origin,_range));
    }

  //! Return a random Transform
  virtual const Transform operator()(Random01& rng) const;

 protected:
  //! Base value for translations
  XYZ _origin;

  //! Range for translations
  XYZ _range;
};


#endif