Browse Source

support for double quats in reanttweakbar and some templates

Former-commit-id: 94c2f40e49fc1b4e457656335967688b0a5a38ba
ajx 13 năm trước cách đây
mục cha
commit
5f7bb2d694

+ 34 - 0
include/igl/ReAntTweakBar.cpp

@@ -266,6 +266,15 @@ std::string igl::ReTwBar::get_value_as_string(
         sstr << *(static_cast<bool*>(var));
         break;
       }
+    case TW_TYPE_QUAT4D:
+      {
+        sstr << "TW_TYPE_QUAT4D" << " ";
+        // Q: Why does casting to double* work? shouldn't I have to cast to
+        // double**?
+        double * q = static_cast<double*>(var);
+        sstr << q[0] << " " << q[1] << " " << q[2] << " " << q[3];
+        break;
+      }
     case TW_TYPE_QUAT4F:
       {
         sstr << "TW_TYPE_QUAT4F" << " ";
@@ -453,6 +462,7 @@ bool igl::ReTwBar::set_value_from_string(
   float v;
   double dv;
   float f[4];
+  double d[4];
   bool b;
 
   // First try to get value from default types
@@ -472,6 +482,19 @@ bool igl::ReTwBar::set_value_from_string(
         }
         break;
       }
+    case TW_TYPE_QUAT4D:
+    //case TW_TYPE_COLOR4D:
+      {
+        if(sscanf(value_str," %lf %lf %lf %lf",&d[0],&d[1],&d[2],&d[3]) == 4)
+        {
+          value = &d;
+        }else
+        {
+          printf("ERROR: Bad value format...\n");
+          return false;
+        }
+        break;
+      }
     case TW_TYPE_QUAT4F:
     case TW_TYPE_COLOR4F:
       {
@@ -586,6 +609,17 @@ bool igl::ReTwBar::set_value_from_string(
             *bvar = *bvalue;
             break;
           }
+        case TW_TYPE_QUAT4D:
+        //case TW_TYPE_COLOR4D:
+          {
+            double * dvar = static_cast<double*>(var);
+            double * dvalue = static_cast<double*>(value);
+            dvar[0] = dvalue[0];
+            dvar[1] = dvalue[1];
+            dvar[2] = dvalue[2];
+            dvar[3] = dvalue[3];
+            break;
+          }
         case TW_TYPE_QUAT4F:
         case TW_TYPE_COLOR4F:
           {

+ 2 - 2
include/igl/canonical_quaternions.cpp

@@ -1,10 +1,10 @@
 #include "canonical_quaternions.h"
 
-template <> IGL_INLINE const float igl::CANONICAL_VIEW_QUAT<float>(int i, int j)
+template <> IGL_INLINE float igl::CANONICAL_VIEW_QUAT<float>(int i, int j)
 {
   return (float)igl::CANONICAL_VIEW_QUAT_F[i][j];
 }
-template <> IGL_INLINE const double igl::CANONICAL_VIEW_QUAT<double>(int i, int j)
+template <> IGL_INLINE double igl::CANONICAL_VIEW_QUAT<double>(int i, int j)
 {
   return (double)igl::CANONICAL_VIEW_QUAT_D[i][j];
 }

+ 3 - 3
include/igl/canonical_quaternions.h

@@ -107,12 +107,12 @@ namespace igl
   //   j  index of coordinate in quaternion i
   // Returns values of CANONICAL_VIEW_QUAT_*[i][j]
   template <typename Q_type> 
-  IGL_INLINE const Q_type CANONICAL_VIEW_QUAT(int i, int j);
+  IGL_INLINE Q_type CANONICAL_VIEW_QUAT(int i, int j);
   // Template specializations for float and double
   template <> 
-  IGL_INLINE const float CANONICAL_VIEW_QUAT<float>(int i, int j);
+  IGL_INLINE float CANONICAL_VIEW_QUAT<float>(int i, int j);
   template <> 
-  IGL_INLINE const double CANONICAL_VIEW_QUAT<double>(int i, int j);
+  IGL_INLINE double CANONICAL_VIEW_QUAT<double>(int i, int j);
 
 #  undef SQRT_2_OVER_2
 }

+ 1 - 0
include/igl/quat_conjugate.cpp

@@ -15,4 +15,5 @@ IGL_INLINE void igl::quat_conjugate(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::quat_conjugate<float>(float const*, float*);
+template void igl::quat_conjugate<double>(double const*, double*);
 #endif

+ 1 - 0
include/igl/quat_to_mat.cpp

@@ -32,4 +32,5 @@ IGL_INLINE void igl::quat_to_mat(const Q_type * quat, Q_type * mat)
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::quat_to_mat<float>(float const*, float*);
+template void igl::quat_to_mat<double>(double const*, double*);
 #endif

+ 1 - 0
include/igl/rotate_by_quat.cpp

@@ -43,4 +43,5 @@ IGL_INLINE void igl::rotate_by_quat(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::rotate_by_quat<float>(float const*, float const*, float*);
+template void igl::rotate_by_quat<double>(double const*, double const*, double*);
 #endif

+ 1 - 0
include/igl/trackball.cpp

@@ -103,4 +103,5 @@ IGL_INLINE void igl::trackball(
 // Explicit template specialization
 // generated by autoexplicit.sh
 template void igl::trackball<float>(int, int, float, float const*, int, int, int, int, float*);
+template void igl::trackball<double>(int, int, double, double const*, int, int, int, int, double*);
 #endif