File: transform.h

package info (click to toggle)
evolvotron 0.7.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,336 kB
  • sloc: cpp: 10,425; python: 162; sh: 138; makefile: 8
file content (216 lines) | stat: -rw-r--r-- 5,363 bytes parent folder | download | duplicates (3)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**************************************************************************/
/*  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 Transform.
*/

#ifndef _transform_h_
#define _transform_h_

#include "common.h"

#include "xyz.h"

//! Class representing 3d linear transforms.
/*! Not much functionality currently because is used mainly to pass info around for warp functionality
 */
class Transform 
{
 public:
  //! Default constructor.  NB Doesn't set up identity or anything.
  Transform();

  //! Copy constructor.
  Transform(const Transform&);

  //! Constructor specifying column vectors.
  Transform(const XYZ& t,const XYZ& x,const XYZ& y,const XYZ& z);

  //! Constructor specifying column-wise elements.
  Transform(const std::vector<real>& v,uint starting_element=0);

  //! virtual destructor in case of extension
  virtual ~Transform();

  //@{
  //! Accessor
  const XYZ& translate() const
    {
      return _translate;
    }
  const XYZ& basis_x() const
    {
      return _basis_x;
    }
  const XYZ& basis_y() const    
    {
      return _basis_y;
    }
  const XYZ& basis_z() const    
    {
      return _basis_z;
    }

  void translate(const XYZ &t)
     {
       _translate=t;
     }
  void basis_x(const XYZ &x)
     {
       _basis_x=x;
     }
  void basis_y(const XYZ &y)
     {
       _basis_y=y;
     }
  void basis_z(const XYZ &z)
     {
       _basis_z=z;
     }
  //@}

  //! Get column-wise element values as a vector
  const std::vector<real> get_columns() const;

  //! Transform a point
  const XYZ transformed(const XYZ& p) const;

  //! Transform a point with no translation
  const XYZ transformed_no_translate(const XYZ& p) const;

  //! Concatenate transforms
  Transform& concatenate_on_right(const Transform& t);

  //! Concatenate transforms
  Transform& concatenate_on_left(const Transform& t);

 protected:
  //@{
  //! Translation component (column vector in matrix).
  XYZ _translate;
  XYZ _basis_x;
  XYZ _basis_y;
  XYZ _basis_z;
};

inline const XYZ operator*(const Transform& t,const XYZ& p)
{
  return 
     t.basis_x()*p.x()
    +t.basis_y()*p.y()
    +t.basis_z()*p.z()
    +t.translate();
}

inline std::ostream& operator<<(std::ostream& out,const Transform& t)
{
  return out << t.translate() << ";" << t.basis_x() << "," << t.basis_y() << "," << t.basis_z();
}

class TransformIdentity : public Transform
{
 public:
  TransformIdentity()
    {
      translate(XYZ(0.0,0.0,0.0));
      basis_x(XYZ(1.0,0.0,0.0));
      basis_y(XYZ(0.0,1.0,0.0));
      basis_z(XYZ(0.0,0.0,1.0));
    }
};

class TransformTranslate : public Transform
{
 public:
  TransformTranslate(const XYZ& t)
    {
      translate(t);
      basis_x(XYZ(1.0,0.0,0.0));
      basis_y(XYZ(0.0,1.0,0.0));
      basis_z(XYZ(0.0,0.0,1.0));
    }
};

class TransformScale : public Transform
{
 public:
  TransformScale(const XYZ& s)
    {
      translate(XYZ(0.0,0.0,0.0));
      basis_x(XYZ(s.x(),0.0,0.0));
      basis_y(XYZ(0.0,s.y(),0.0));
      basis_z(XYZ(0.0,0.0,s.z()));
    }
  TransformScale(real s)
    {
      translate(XYZ(0.0,0.0,0.0));
      basis_x(XYZ(s,0.0,0.0));
      basis_y(XYZ(0.0,s,0.0));
      basis_z(XYZ(0.0,0.0,s));
    }
};


class TransformRotateX : public Transform
{
 public:
  TransformRotateX(real a)
    {
      const real sa=sin(a);
      const real ca=cos(a);

      translate(XYZ(0.0,0.0,0.0));
      basis_x(XYZ(1.0,0.0,0.0));
      basis_y(XYZ(0.0, ca , sa ));
      basis_z(XYZ(0.0,-sa , ca ));
    }
};

class TransformRotateY : public Transform
{
 public:
  TransformRotateY(real a)
    {
      const real sa=sin(a);
      const real ca=cos(a);
      
      translate(XYZ(0.0,0.0,0.0));
      basis_x(XYZ( ca ,0.0,-sa ));
      basis_y(XYZ(0.0,1.0,0.0));
      basis_z(XYZ( sa ,0.0, ca ));
    }
};

class TransformRotateZ : public Transform
{
 public:
  TransformRotateZ(real a)
    {
      const real sa=sin(a);
      const real ca=cos(a);
      
      translate(XYZ(0.0,0.0,0.0));
      basis_x(XYZ( ca , sa ,0.0));
      basis_y(XYZ(-sa , ca ,0.0));
      basis_z(XYZ(0.0,0.0,1.0));
    }
};

#endif