Welcome to mirror list, hosted at ThFree Co, Russian Federation.

canonical_quaternions.h « igl « src « xs - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 86d90112ddd32b757c39e030083775d9df84182f (plain)
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
// This file is part of libigl, a simple c++ geometry processing library.
// 
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
// 
// This Source Code Form is subject to the terms of the Mozilla Public License 
// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
// obtain one at http://mozilla.org/MPL/2.0/.
#ifndef IGL_CANONICAL_QUATERNIONS_H
#define IGL_CANONICAL_QUATERNIONS_H
#include "igl_inline.h"
// Define some canonical quaternions for floats and doubles
// A Quaternion, q, is defined here as an arrays of four scalars (x,y,z,w),
// such that q = x*i + y*j + z*k + w
namespace igl
{
  // Float versions
#define SQRT_2_OVER_2 0.707106781f
  // Identity
  const float IDENTITY_QUAT_F[4] = {0,0,0,1};
  // The following match the Matlab canonical views
  // X point right, Y pointing up and Z point out
  const float XY_PLANE_QUAT_F[4] = {0,0,0,1};
  // X points right, Y points *in* and Z points up
  const float XZ_PLANE_QUAT_F[4] = {-SQRT_2_OVER_2,0,0,SQRT_2_OVER_2};
  // X points out, Y points right, and Z points up
  const float YZ_PLANE_QUAT_F[4] = {-0.5,-0.5,-0.5,0.5};
  const float CANONICAL_VIEW_QUAT_F[][4] = 
    {
      {             0,             0,             0,             1}, // 0
      {             0,             0, SQRT_2_OVER_2, SQRT_2_OVER_2}, // 1
      {             0,             0,             1,             0}, // 2
      {             0,             0, SQRT_2_OVER_2,-SQRT_2_OVER_2}, // 3

      {             0,            -1,             0,             0}, // 4
      {-SQRT_2_OVER_2, SQRT_2_OVER_2,             0,             0}, // 5
      {            -1,             0,             0,             0}, // 6
      {-SQRT_2_OVER_2,-SQRT_2_OVER_2,             0,             0}, // 7

      {          -0.5,          -0.5,          -0.5,           0.5}, // 8
      {             0,-SQRT_2_OVER_2,             0, SQRT_2_OVER_2}, // 9
      {           0.5,          -0.5,           0.5,           0.5}, // 10
      { SQRT_2_OVER_2,             0, SQRT_2_OVER_2,             0}, // 11

      { SQRT_2_OVER_2,             0,-SQRT_2_OVER_2,             0}, // 12
      {           0.5,           0.5,          -0.5,           0.5}, // 13
      {             0, SQRT_2_OVER_2,             0, SQRT_2_OVER_2}, // 14
      {          -0.5,           0.5,           0.5,           0.5}, // 15

      {             0, SQRT_2_OVER_2, SQRT_2_OVER_2,             0}, // 16
      {          -0.5,           0.5,           0.5,          -0.5}, // 17
      {-SQRT_2_OVER_2,             0,             0,-SQRT_2_OVER_2}, // 18
      {          -0.5,          -0.5,          -0.5,          -0.5}, // 19

      {-SQRT_2_OVER_2,             0,             0, SQRT_2_OVER_2}, // 20
      {          -0.5,          -0.5,           0.5,           0.5}, // 21
      {             0,-SQRT_2_OVER_2, SQRT_2_OVER_2,             0}, // 22
      {           0.5,          -0.5,           0.5,          -0.5}  // 23
    };
#undef SQRT_2_OVER_2
  // Double versions
#define SQRT_2_OVER_2 0.70710678118654757
  // Identity
  const double IDENTITY_QUAT_D[4] = {0,0,0,1};
  // The following match the Matlab canonical views
  // X point right, Y pointing up and Z point out
  const double XY_PLANE_QUAT_D[4] = {0,0,0,1};
  // X points right, Y points *in* and Z points up
  const double XZ_PLANE_QUAT_D[4] = {-SQRT_2_OVER_2,0,0,SQRT_2_OVER_2};
  // X points out, Y points right, and Z points up
  const double YZ_PLANE_QUAT_D[4] = {-0.5,-0.5,-0.5,0.5};
  const double CANONICAL_VIEW_QUAT_D[][4] = 
    {
      {             0,             0,             0,             1},
      {             0,             0, SQRT_2_OVER_2, SQRT_2_OVER_2},
      {             0,             0,             1,             0},
      {             0,             0, SQRT_2_OVER_2,-SQRT_2_OVER_2},
  
      {             0,            -1,             0,             0},
      {-SQRT_2_OVER_2, SQRT_2_OVER_2,             0,             0},
      {            -1,             0,             0,             0},
      {-SQRT_2_OVER_2,-SQRT_2_OVER_2,             0,             0},
  
      {          -0.5,          -0.5,          -0.5,           0.5},
      {             0,-SQRT_2_OVER_2,             0, SQRT_2_OVER_2},
      {           0.5,          -0.5,           0.5,           0.5},
      { SQRT_2_OVER_2,             0, SQRT_2_OVER_2,             0},
  
      { SQRT_2_OVER_2,             0,-SQRT_2_OVER_2,             0},
      {           0.5,           0.5,          -0.5,           0.5},
      {             0, SQRT_2_OVER_2,             0, SQRT_2_OVER_2},
      {          -0.5,           0.5,           0.5,           0.5},
  
      {             0, SQRT_2_OVER_2, SQRT_2_OVER_2,             0},
      {          -0.5,           0.5,           0.5,          -0.5},
      {-SQRT_2_OVER_2,             0,             0,-SQRT_2_OVER_2},
      {          -0.5,          -0.5,          -0.5,          -0.5},
  
      {-SQRT_2_OVER_2,             0,             0, SQRT_2_OVER_2},
      {          -0.5,          -0.5,           0.5,           0.5},
      {             0,-SQRT_2_OVER_2, SQRT_2_OVER_2,             0},
      {           0.5,          -0.5,           0.5,          -0.5}
    };
#undef SQRT_2_OVER_2
#define NUM_CANONICAL_VIEW_QUAT 24

  // NOTE: I want to rather be able to return a Q_type[][] but C++ is not
  // making it easy. So instead I've written a per-element accessor
  
  // Return element [i][j] of the corresponding CANONICAL_VIEW_QUAT_* of the
  // given templated type
  // Inputs:
  //   i  index of quaternion
  //   j  index of coordinate in quaternion i
  // Returns values of CANONICAL_VIEW_QUAT_*[i][j]
  template <typename Q_type> 
  IGL_INLINE Q_type CANONICAL_VIEW_QUAT(int i, int j);
  // Template specializations for float and double
  template <> 
  IGL_INLINE float CANONICAL_VIEW_QUAT<float>(int i, int j);
  template <> 
  IGL_INLINE double CANONICAL_VIEW_QUAT<double>(int i, int j);

}

#ifndef IGL_STATIC_LIBRARY
#  include "canonical_quaternions.cpp"
#endif

#endif