## "Fossies" - the Fresh Open Source Software Archive

### Member "gmsh-4.3.0-source/Geo/affineTransformation.cpp" (11 Feb 2019, 2628 Bytes) of package /linux/privat/gmsh-4.3.0-source.tgz:

As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "affineTransformation.cpp" see the Fossies "Dox" file reference documentation.

```    1 // Gmsh - Copyright (C) 1997-2019 C. Geuzaine, J.-F. Remacle
2 //
4 // issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 //
6 // Contributed by K. Hillewaert
7
8 #include <vector>
9
10 #include "fullMatrix.h"
11
12 template <class FLOAT>
13 bool computeAffineTransformationTemplate(const FLOAT *rc, const FLOAT *ra,
14                                          const FLOAT *tr,
15                                          std::vector<double> &tfo)
16 hlOpen(16,1);{
17   tfo.clear();
18   tfo.reserve(16);
19
20   fullMatrix<double> compoundRotation(3, 3);
21   for(int i = 0; i < 3; i++) compoundRotation(i, i) = 1;
22
23   for(int i = 0; i < 3; i++) hlOpen(23,2);{
24     if(ra[i] != 0) hlOpen(24,3);{
25       fullMatrix<double> tmp(compoundRotation);
26
27       fullMatrix<double> rotation(3, 3);
28       rotation(i, i) = 1;
29
30       int ii = (i + 1) % 3;
31       int jj = (i + 2) % 3;
32
33       double ca = cos(ra[i]);
34       double sa = sin(ra[i]);
35
36       // rotation with alpha
37
38       rotation(ii, ii) = ca;
39       rotation(ii, jj) = sa;
40       rotation(jj, ii) = -sa;
41       rotation(jj, jj) = ca;
42
43       compoundRotation.gemm(rotation, tmp, 1, 0);
44     hlClose(3, 44);}
45   hlClose(2, 45);}
46
47   // compute displacement from rotation center
48
49   fullVector<double> disp(3);
50
51   fullVector<double> center(3);
52   for(int i = 0; i < 3; i++) center(i) = rc[i];
53   compoundRotation.mult(center, disp);
54
56
57   for(int i = 0; i < 3; i++) disp(i) = -tr[i];
58
59   // copy to tfo
60
61   tfo.clear();
62
63   for(int i = 0; i < 3; i++) hlOpen(63,2);{
64     for(int j = 0; j < 3; j++) tfo.push_back(compoundRotation(i, j));
65     tfo.push_back(disp(i));
66   hlClose(4, 66);}
67   for(int i = 0; i < 3; i++) tfo.push_back(0);
68   tfo.push_back(1);
69
70   return true;
71 hlClose(1, 71);}
72
73 bool computeAffineTransformation(const float *rc, const float *ra,
74                                  const float *tr, std::vector<double> &tfo)
75 hlOpen(75,1);{
76   return computeAffineTransformationTemplate(rc, ra, tr, tfo);
77 hlClose(5, 77);}
78
79 bool computeAffineTransformation(const double *rc, const double *ra,
80                                  const double *tr, std::vector<double> &tfo)
81 hlOpen(81,1);{
82   return computeAffineTransformationTemplate(rc, ra, tr, tfo);
83 hlClose(6, 83);}
84
85 bool invertAffineTransformation(const std::vector<double> &tfo,
86                                 std::vector<double> &newTfo)
87 hlOpen(87,1);{
88   fullMatrix<double> inv(4, 4);
89   for(int i = 0; i < 4; i++)
90     for(int j = 0; j < 4; j++) inv(i, j) = tfo[i * 4 + j];
91   inv.invertInPlace();
92   newTfo.clear();
93   for(int i = 0; i < 4; i++)
94     for(int j = 0; j < 4; j++) newTfo.push_back(inv(i, j));
95   return true;
96 hlClose(7, 96);}
97
98 bool setUnitAffineTransformation(std::vector<double> &tfo)
99 hlOpen(99,1);{
100   tfo.resize(16, 0);
101   for(int i = 0; i < 16; i += 5) tfo[i] = 1;
102   return true;
103 hlClose(8, 103);}
```