OpenBeam
C++ library for static analysis of mechanical structures
internals.h
1 /* +---------------------------------------------------------------------------+
2  | OpenBeam - C++ Finite Element Analysis library |
3  | |
4  | Copyright (C) 2010-2021 Jose Luis Blanco Claraco |
5  | University of Malaga |
6  | |
7  | OpenBeam is free software: you can redistribute it and/or modify |
8  | it under the terms of the GNU General Public License as published by |
9  | the Free Software Foundation, either version 3 of the License, or |
10  | (at your option) any later version. |
11  | |
12  | OpenBeam is distributed in the hope that it will be useful, |
13  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15  | GNU General Public License for more details. |
16  | |
17  | You should have received a copy of the GNU General Public License |
18  | along with OpenBeam. If not, see <http://www.gnu.org/licenses/>. |
19  | |
20  +---------------------------------------------------------------------------+
21  */
22 
23 #pragma once
24 
25 #include <openbeam/types.h>
26 
27 #if OPENBEAM_HAS_CAIRO
28 #include <cairomm/context.h>
29 #include <cairomm/surface.h>
30 #include <cairommconfig.h>
31 #endif
32 
33 namespace openbeam
34 {
35 namespace internal
36 {
39 template <class CAIROCR>
40 void drawLocalScaledSegments(
41  CAIROCR& cr, const TRotationTrans3D& node_pose, const double scale,
42  const std::vector<TPoint3D>& seq_points_local)
43 {
44  const Matrix33& node_rot = node_pose.r.getRot();
45 
46  // then rotate to the nodal coordinates (typ. coincides with global coords)
47  const size_t nPts = seq_points_local.size();
48  std::vector<TPoint3D> seq_points_global;
49  if (node_pose.r.isIdentity())
50  {
51  seq_points_global = seq_points_local;
52  for (size_t k = 0; k < nPts; k++)
53  // POINT_GLOBAL = NODE_GLOBAL + MATRIX33 * POINT_LOCAL
54  if (scale == 1)
55  seq_points_global[k] += node_pose.t;
56  else
57  seq_points_global[k] =
58  node_pose.t + scale * seq_points_global[k];
59  }
60  else
61  {
62  seq_points_global.resize(nPts);
63  for (size_t k = 0; k < nPts; k++)
64  {
65  // POINT_GLOBAL = NODE_GLOBAL + MATRIX33 * POINT_LOCAL
66  for (int l = 0; l < 3; l++)
67  seq_points_global[k][l] =
68  node_pose.t[l] +
69  scale * (node_rot.coeff(l, 0) * seq_points_local[k].x +
70  node_rot.coeff(l, 1) * seq_points_local[k].y +
71  node_rot.coeff(l, 2) * seq_points_local[k].z);
72  }
73  }
74 
75  // Draw the lines:
76  for (size_t k = 0; k < nPts; k++)
77  {
78  const double xx = seq_points_global[k].x;
79  const double yy = seq_points_global[k].y;
80  if (k == 0)
81  cr->move_to(xx, yy);
82  else
83  cr->line_to(xx, yy);
84  }
85  cr->stroke();
86 
87 } // end of drawLocalScaledSegments
88 
90 void computeOrientationFromTwoPoints(
91  const TPoint3D& t1, const TPoint3D& t2, const num_t rotation_around_x,
92  TRotation3D& R);
93 
94 } // namespace internal
95 } // namespace openbeam