Browse Source

mouse controller and quaternion io

Former-commit-id: af1b6b890106b24a8f937d73c71c03c162c62020
Alec Jacobson 11 years ago
parent
commit
3ee6fa10ec

+ 2 - 0
.gitignore

@@ -39,6 +39,8 @@ Release/
 *.vsp
 *.opensdf
 *.psess
+*.swp
+*.swo
 documentation/*.aux
 documentation/*.out
 documentation/*.log

+ 14 - 3
include/igl/MouseController.h

@@ -77,11 +77,11 @@ namespace igl
     public:
       MouseController();
       // Returns const reference to m_selection
-      const inline VectorXb & selection() const{return m_selection;};
+      inline const VectorXb & selection() const{return m_selection;};
       //                          〃 m_is_selecting
-      const inline bool & is_selecting() const{return m_is_selecting;}
+      inline const bool & is_selecting() const{return m_is_selecting;}
       //                          〃 m_rotations
-      const inline RotationList & rotations() const{return m_rotations;}
+      inline const RotationList & rotations() const{return m_rotations;}
       // Returns non-const reference to m_root_enabled
       inline bool & root_enabled(){ return m_root_enabled;}
       inline void reshape(const int w, const int h);
@@ -122,6 +122,7 @@ namespace igl
       inline void set_size(const int n);
       // Resets m_rotation elements to identity
       inline void reset_rotations();
+      inline bool set_rotations(const RotationList & vQ);
       // Sets all entries in m_selection to false
       inline void clear_selection();
       // Returns true iff some element in m_selection is true
@@ -499,6 +500,16 @@ inline void igl::MouseController::reset_rotations()
   // cop out. just clear selection
   clear_selection();
 }
+inline bool igl::MouseController::set_rotations(const RotationList & vQ)
+{
+  if(vQ.size() != m_rotations.size())
+  {
+    return false;
+  }
+  assert(!any_selection());
+  m_rotations = vQ;
+  return true;
+}
 
 inline void igl::MouseController::clear_selection()
 {

+ 21 - 0
include/igl/angular_distance.cpp

@@ -0,0 +1,21 @@
+// 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/.
+#include "angular_distance.h"
+#include <igl/EPS.h>
+#include <igl/PI.h>
+double igl::angular_distance(
+  const Eigen::Quaterniond & A,
+  const Eigen::Quaterniond & B)
+{
+  using namespace igl;
+  assert(fabs(A.norm()-1)<FLOAT_EPS && "A should be unit norm");
+  assert(fabs(B.norm()-1)<FLOAT_EPS && "B should be unit norm");
+  //// acos is always in [0,2*pi)
+  //return acos(fabs(A.dot(B)));
+  return fmod(2.*acos(A.dot(B)),2.*PI);
+}

+ 30 - 0
include/igl/angular_distance.h

@@ -0,0 +1,30 @@
+// 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_ANGULAR_DISTANCE_H
+#define IGL_ANGULAR_DISTANCE_H
+#include "igl_inline.h"
+#include <Eigen/Geometry>
+namespace igl
+{
+  // The "angular distance" between two unit quaternions is the angle of the
+  // smallest rotation (treated as an Axis and Angle) that takes A to B.
+  //
+  // Inputs:
+  //   A  unit quaternion
+  //   B  unit quaternion
+  // Returns angular distance
+  double angular_distance(
+    const Eigen::Quaterniond & A,
+    const Eigen::Quaterniond & B);
+}
+
+#ifdef IGL_HEADER_ONLY
+#include "angular_distance.cpp"
+#endif
+
+#endif

+ 27 - 0
include/igl/column_to_quats.cpp

@@ -0,0 +1,27 @@
+// 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/.
+#include "column_to_quats.h"
+IGL_INLINE bool igl::column_to_quats(
+  const Eigen::VectorXd & Q,
+  std::vector<
+    Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > & vQ)
+{
+  using namespace Eigen;
+  if(Q.size() % 4 != 0)
+  {
+    return false;
+  }
+  const int nQ = Q.size()/4;
+  vQ.resize(nQ);
+  for(int q=0;q<nQ;q++)
+  {
+    // Constructor uses wxyz
+    vQ[q] = Quaterniond( Q(q*4+3), Q(q*4+0), Q(q*4+1), Q(q*4+2));
+  }
+  return true;
+}

+ 36 - 0
include/igl/column_to_quats.h

@@ -0,0 +1,36 @@
+// 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_COLUMN_TO_QUATS_H
+#define IGL_COLUMN_TO_QUATS_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+#include <Eigen/Geometry>
+#include <Eigen/StdVector>
+#include <vector>
+namespace igl
+{
+  // "Columnize" a list of quaternions (q1x,q1y,q1z,q1w,q2x,q2y,q2z,q2w,...)
+  //
+  // Inputs:
+  //   Q  n*4-long list of coefficients
+  // Outputs:
+  //   vQ  n-long list of quaternions
+  // Returns false if n%4!=0
+  IGL_INLINE bool column_to_quats(
+    const Eigen::VectorXd & Q,
+    std::vector<
+      Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > & vQ);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "columns_to_quats.cpp"
+#endif
+
+#endif
+
+

+ 1 - 1
include/igl/forward_kinematics.cpp

@@ -8,7 +8,7 @@
 #include "forward_kinematics.h"
 #include <functional>
 
-void igl::forward_kinematics(
+IGL_INLINE void igl::forward_kinematics(
   const Eigen::MatrixXd & C,
   const Eigen::MatrixXi & BE,
   const Eigen::VectorXi & P,

+ 2 - 1
include/igl/forward_kinematics.h

@@ -7,6 +7,7 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #ifndef IGL_FORWARD_KINEMATICS_H
 #define IGL_FORWARD_KINEMATICS_H
+#include "igl_inline.h"
 #include <Eigen/Core>
 #include <Eigen/Geometry>
 #include <Eigen/StdVector>
@@ -25,7 +26,7 @@ namespace igl
   // Outputs:
   //   vQ  #BE list of absolute rotations
   //   vT  #BE list of absolute translations
-  void forward_kinematics(
+  IGL_INLINE void forward_kinematics(
     const Eigen::MatrixXd & C,
     const Eigen::MatrixXi & BE,
     const Eigen::VectorXi & P,

+ 1 - 1
include/igl/line_segment_in_rectangle.cpp

@@ -7,7 +7,7 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #include "line_segment_in_rectangle.h"
 
-bool igl::line_segment_in_rectangle(
+IGL_INLINE bool igl::line_segment_in_rectangle(
   const Eigen::Vector2d & s,
   const Eigen::Vector2d & d,
   const Eigen::Vector2d & A,

+ 2 - 1
include/igl/line_segment_in_rectangle.h

@@ -7,6 +7,7 @@
 // obtain one at http://mozilla.org/MPL/2.0/.
 #ifndef IGL_LINE_SEGMENT_IN_RECTANGLE_H
 #define IGL_LINE_SEGMENT_IN_RECTANGLE_H
+#include "igl_inline.h"
 #include <Eigen/Core>
 namespace igl
 {
@@ -18,7 +19,7 @@ namespace igl
   //   A  first corner of rectangle
   //   B  opposite corner of rectangle
   // Returns true if line segment is at all inside rectangle
-  bool line_segment_in_rectangle(
+  IGL_INLINE bool line_segment_in_rectangle(
     const Eigen::Vector2d & s,
     const Eigen::Vector2d & d,
     const Eigen::Vector2d & A,

+ 33 - 0
include/igl/quats_to_column.cpp

@@ -0,0 +1,33 @@
+// 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/.
+#include "quats_to_column.h"
+
+IGL_INLINE void igl::quats_to_column(
+  const std::vector<
+    Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > vQ,
+    Eigen::VectorXd & Q)
+{
+  Q.resize(vQ.size()*4);
+  for(int q = 0;q<(int)vQ.size();q++)
+  {
+    auto & xyzw = vQ[q].coeffs();
+    for(int c = 0;c<4;c++)
+    {
+      Q(q*4+c) = xyzw(c);
+    }
+  }
+}
+
+IGL_INLINE Eigen::VectorXd igl::quats_to_column(
+  const std::vector<
+    Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > vQ)
+{
+  Eigen::VectorXd Q;
+  quats_to_column(vQ,Q);
+  return Q;
+}

+ 37 - 0
include/igl/quats_to_column.h

@@ -0,0 +1,37 @@
+// 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_QUATS_TO_COLUMN_H
+#define IGL_QUATS_TO_COLUMN_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+#include <Eigen/Geometry>
+#include <Eigen/StdVector>
+#include <vector>
+namespace igl
+{
+  // "Columnize" a list of quaternions (q1x,q1y,q1z,q1w,q2x,q2y,q2z,q2w,...)
+  //
+  // Inputs:
+  //   vQ  n-long list of quaternions
+  // Outputs:
+  //   Q  n*4-long list of coefficients
+  IGL_INLINE void quats_to_column(
+    const std::vector<
+      Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > vQ,
+      Eigen::VectorXd & Q);
+  IGL_INLINE Eigen::VectorXd quats_to_column(
+    const std::vector<
+      Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > vQ);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "quats_to_column.cpp"
+#endif
+
+#endif
+