SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Transform.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 ///////////////////////////
30 // PORTED SCIRUN v4 CODE //
31 ///////////////////////////
32 
33 /// @todo Documentation Core/GeometryPrimitives/Transform.h
34 
35 #ifndef CORE_GEOMETRY_TRANSFORM_H
36 #define CORE_GEOMETRY_TRANSFORM_H 1
37 
39 
41 
42 namespace SCIRun {
43  class TypeDescription;
44 
45 namespace Core {
46 namespace Geometry {
47 
48  class Point;
49  class Vector;
50  class Plane;
51  class Tensor;
52 
54 {
55  private:
56  double mat[4][4];
57  mutable double imat[4][4];
58  mutable bool inverse_valid;
59 
60  void install_mat(double[4][4]);
61  void build_permute(double m[4][4], int, int, int, int pre);
62  void build_rotate(double m[4][4], double, const Vector&);
63  void build_shear(double mat[4][4], const Vector&, const Plane&);
64  void build_scale(double m[4][4], const Vector&);
65  void build_translate(double m[4][4], const Vector&);
66  void pre_mulmat(const double[4][4]);
67  void post_mulmat(const double[4][4]);
68  void invmat(double[4][4]);
69  void switch_rows(double m[4][4], int row1, int row2) const;
70  void sub_rows(double m[4][4], int row1, int row2, double mul) const;
71  void load_identity(double[4][4]);
72  void load_zero(double[4][4]);
73 public:
74  double get_imat_val(int i, int j) const { return imat[i][j]; }
75  void set_imat_val(int i, int j, double val) { imat[i][j] = val; }
76 
77  public:
78  Transform();
79  Transform(const Transform&);
80  Transform& operator=(const Transform&);
81  ~Transform();
82  Transform(const Point&, const Vector&, const Vector&, const Vector&);
83 
84  double get_mat_val(int i, int j) const { return mat[i][j]; }
85  void set_mat_val(int i, int j, double val) { mat[i][j] = val; }
86 
87  void load_basis(const Point&,const Vector&, const Vector&, const Vector&);
88  void load_frame(const Vector&, const Vector&, const Vector&);
89 
90  void change_basis(Transform&);
91  void post_trans(const Transform&);
92  void pre_trans(const Transform&);
93 
94  void print();
95  void printi();
96 
97  void pre_permute(int xmap, int ymap, int zmap);
98  void post_permute(int xmap, int ymap, int zmap);
99  void pre_scale(const Vector&);
100  void post_scale(const Vector&);
101 
102  void load_identity();
103  // Returns true if the rotation happened, false otherwise.
104  bool rotate(const Vector& from, const Vector& to);
105  void pre_translate(const Vector&);
106  void post_translate(const Vector&);
107 
108  void compute_imat() const;
109 
110  Vector project(const Vector& p) const;
111  Point project(const Point& p) const;
112 
113  Point unproject(const Point& p) const;
114  void unproject(const Point& p, Point& res) const;
115  void unproject_inplace(Point& p) const;
116  Vector unproject(const Vector& p) const;
117  void unproject(const Vector& v, Vector& res) const;
118  void unproject_inplace(Vector& v) const;
119 
120  void project(const Point& p, Point& res) const;
121  void project_inplace(Point& p) const;
122 
123  void project(const Vector& p, Vector& res) const;
124  void project_inplace(Vector& p) const;
125  Vector project_normal(const Vector&) const;
126  void project_normal(const Vector&, Vector& res) const;
127  void project_normal_inplace(Vector&) const;
128 
129  void pre_shear(const Vector&, const Plane&);
130  void post_shear(const Vector&, const Plane&);
131 
132  void pre_rotate(double, const Vector& axis);
133  void post_rotate(double, const Vector& axis);
134 
135  void get(double*) const;
136  void get_trans(double*) const;
137  void set(double*);
138  void set_trans(double*);
139 
140  void perspective(const Point& eyep, const Point& lookat,
141  const Vector& up, double fov,
142  double znear, double zfar,
143  int xres, int yres);
144 
145  void invert();
146  bool inv_valid() { return inverse_valid; }
147  void set_inv_valid(bool iv) { inverse_valid = iv; }
148 
149  /// Persistent I/O.
151  virtual void io(Piostream &stream);
152  SCISHARE friend void Pio(Piostream&, Transform*&);
153 };
154 
155 SCISHARE Point operator*(Transform &t, const Point &d);
157 
158 SCISHARE Tensor operator*(const Transform &t, const Tensor &d);
159 SCISHARE Tensor operator*(const Tensor &d, const Transform &t);
160 
161 SCISHARE void Pio(Piostream&, Transform*&);
164 
165 
166 }}}
167 
168 #endif
void set_inv_valid(bool iv)
Definition: Transform.h:147
void set_mat_val(int i, int j, double val)
Definition: Transform.h:85
SCISHARE const TypeDescription * get_type_description(Tensor *)
Definition: Tensor.cc:405
Definition: Persistent.h:89
Definition: Persistent.h:187
Definition: Point.h:49
Definition: TypeDescription.h:45
#define SCISHARE
Definition: share.h:39
double get_imat_val(int i, int j) const
Definition: Transform.h:74
Definition: Vector.h:63
Base class for persistent objects...
void set_imat_val(int i, int j, double val)
Definition: Transform.h:75
Definition: Plane.h:44
Definition: Transform.h:53
Definition: Tensor.h:65
v
Definition: readAllFields.py:42
bool inv_valid()
Definition: Transform.h:146
double get_mat_val(int i, int j) const
Definition: Transform.h:84
SCISHARE void Pio_old(Piostream &, Transform &)
Definition: Transform.cc:940
static PersistentTypeID type_id
Persistent I/O.
Definition: Transform.h:150
Definition: Persistent.h:64
Point operator*(double d, const Point &p)
Definition: Point.h:182
SCISHARE void Pio(Piostream &, BBox &)
Definition: BBox.cc:134