LOOS  v2.3.2
XForm.hpp
1 /*
2  This file is part of LOOS.
3 
4  LOOS (Lightweight Object-Oriented Structure library)
5  Copyright (c) 2008, Tod D. Romo, Alan Grossfield
6  Department of Biochemistry and Biophysics
7  School of Medicine & Dentistry, University of Rochester
8 
9  This package (LOOS) is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation under version 3 of the License.
12 
13  This package is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 
24 
25 
26 #if !defined(LOOS_XFORM_HPP)
27 #define LOOS_XFORM_HPP
28 
29 
30 #include <iostream>
31 #include <stdexcept>
32 #include <string>
33 #include <vector>
34 
35 #include <cmath>
36 
37 #include <loos_defs.hpp>
38 #include <Coord.hpp>
39 #include <Matrix44.hpp>
40 
41 namespace loos {
42 
43  typedef Matrix44<greal> GMatrix;
44 
45  // This was formerly global, but now restricted to this unit...
46  namespace {
47 
48  const double PI = 4.0*atan(1.0);
49  const double very_small = 1e-15;
50  }
51 
52 
53 
55 
91  class XForm {
92  std::vector<GMatrix> stack;
93  bool _unset;
94 
95  public:
96  XForm() : _unset(true) { GMatrix m; stack.push_back(m); }
97 
99  explicit XForm(const GMatrix& m) { stack.push_back(m); }
100 
101  XForm(const XForm& x) : stack(x.stack), _unset(x._unset) { }
102 
104  void push(void);
106  void pop(void);
108  void load(const GMatrix&);
110  void concat(const GMatrix&);
111 
113  void premult(const GMatrix&);
114 
116  void identity(void);
117 
118  bool unset(void) const;
119 
121  void translate(const greal, const greal, const greal);
122 
124  void translate(const GCoord&);
125 
127  void scale(const greal, const greal, const greal);
128 
130  void scale(const GCoord&);
131 
132  // Angles are in degrees.
133 
136  void rotate(const GCoord&, const greal);
137 
141  void rotate(const char, const greal);
142 
144  GCoord transform(const GCoord&);
145 
147  // Should we copy or return a ref?
148  GMatrix current(void) const;
149 
150  };
151 
152 
153 }
154 
155 #endif
void rotate(const GCoord &, const greal)
Definition: XForm.cpp:64
void identity(void)
Set the current transform to the identity.
Definition: XForm.cpp:33
void concat(const GMatrix &)
Concatenate (post-multiply) a matrix with the current transform.
Definition: XForm.cpp:29
Matrix class for handling coordinate transforms...
Definition: XForm.hpp:91
GCoord transform(const GCoord &)
Transform a GCoord() with the current transformation.
Definition: XForm.cpp:106
void pop(void)
Pop the top matrix off the stack.
Definition: XForm.cpp:27
void translate(const greal, const greal, const greal)
Translation matrix.
Definition: XForm.cpp:37
XForm(const GMatrix &m)
Initialize an XForm with an existing matrix.
Definition: XForm.hpp:99
GMatrix current(void) const
Get the current trasnformation.
Definition: XForm.cpp:110
void premult(const GMatrix &)
Premultiply the current transform.
Definition: XForm.cpp:31
void push(void)
Push the current matrix onto the stack.
Definition: XForm.cpp:26
void scale(const greal, const greal, const greal)
Scaling.
Definition: XForm.cpp:50
Namespace for most things not already encapsulated within a class.
void load(const GMatrix &)
Load a matrix onto the current transform.
Definition: XForm.cpp:28