Browse Source

dqs example

Former-commit-id: aa16acc78b9c2253ecda43dfcd6ab3b8b07e8a58
Alec Jacobson 11 years ago
parent
commit
319a2c40f5

+ 11 - 0
tutorial/404_DualQuaternionSkinning/CMakeLists.txt

@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 2.6)
+project(404_DualQuaternionSkinning)
+
+include("../CMakeLists.shared")
+
+set(SOURCES
+${PROJECT_SOURCE_DIR}/main.cpp
+)
+
+add_executable(${PROJECT_NAME}_bin ${SOURCES} ${SHARED_SOURCES})
+target_link_libraries(${PROJECT_NAME}_bin ${SHARED_LIBRARIES})

+ 119 - 0
tutorial/404_DualQuaternionSkinning/main.cpp

@@ -0,0 +1,119 @@
+// Don't use static library for this example because of Mosek complications
+//#define IGL_NO_MOSEK
+#ifdef IGL_NO_MOSEK
+#undef IGL_STATIC_LIBRARY
+#endif
+#include <igl/boundary_conditions.h>
+#include <igl/colon.h>
+#include <igl/column_to_quats.h>
+#include <igl/directed_edge_parents.h>
+#include <igl/forward_kinematics.h>
+#include <igl/jet.h>
+#include <igl/lbs_matrix.h>
+#include <igl/deform_skeleton.h>
+#include <igl/normalize_row_sums.h>
+#include <igl/readDMAT.h>
+#include <igl/readMESH.h>
+#include <igl/readTGF.h>
+#include <igl/viewer/Viewer.h>
+#include <igl/bbw/bbw.h>
+
+#include <Eigen/Geometry>
+#include <Eigen/StdVector>
+#include <vector>
+#include <algorithm>
+#include <iostream>
+
+typedef 
+  std::vector<Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> >
+  RotationList;
+
+const Eigen::RowVector3d sea_green(70./255.,252./255.,167./255.);
+Eigen::MatrixXd V,W;
+Eigen::MatrixXi F,BE;
+Eigen::VectorXi P;
+RotationList pose;
+double anim_t = 1.0;
+double anim_t_dir = -0.03;
+
+bool pre_draw(igl::Viewer & viewer)
+{
+  using namespace Eigen;
+  using namespace std;
+  if(viewer.options.is_animating)
+  {
+    // Interpolate pose and identity
+    RotationList anim_pose(pose.size());
+    for(int e = 0;e<pose.size();e++)
+    {
+      anim_pose[e] = pose[e].slerp(anim_t,Quaterniond::Identity());
+    }
+    // Propogate relative rotations via FK to retrieve absolute transformations
+    RotationList vQ;
+    vector<Vector3d> vT;
+    igl::forward_kinematics(C,BE,P,anim_pose,vQ,vT);
+    const int dim = C.cols();
+    MatrixXd T(BE.rows()*(dim+1),dim);
+    for(int e = 0;e<BE.rows();e++)
+    {
+      Affine3d a = Affine3d::Identity();
+      a.translate(vT[e]);
+      a.rotate(vQ[e]);
+      T.block(e*(dim+1),0,dim+1,dim) =
+        a.matrix().transpose().block(0,0,dim+1,dim);
+    }
+    // Compute deformation via LBS as matrix multiplication
+    U = M*T;
+
+    // Also deform skeleton edges
+    MatrixXd CT;
+    MatrixXi BET;
+    igl::deform_skeleton(C,BE,T,CT,BET);
+    
+    viewer.set_vertices(U);
+    viewer.set_edges(CT,BET,sea_green);
+    viewer.compute_normals();
+    anim_t += anim_t_dir;
+    anim_t_dir *= (anim_t>=1.0 || anim_t<=0.0?-1.0:1.0);
+  }
+  return false;
+}
+
+bool key_down(igl::Viewer &viewer, unsigned char key, int mods)
+{
+  switch(key)
+  {
+    case ' ':
+      viewer.options.is_animating = !viewer.options.is_animating;
+      break;
+  }
+}
+
+int main(int argc, char *argv[])
+{
+  using namespace Eigen;
+  using namespace std;
+  igl::readOBJ("../shared/arm.obj",V,F);
+  U=V;
+  igl::readTGF("../shared/arm.tgf",C,BE);
+  // retrieve parents for forward kinematics
+  directed_edge_parents(BE,P);
+  igl::readDMAT("../shared/arm-weights.dmat",W);
+  pose_0 identity
+  pose_1 twist
+  pose_2 bend
+
+  // Plot the mesh with pseudocolors
+  igl::Viewer viewer;
+  viewer.set_mesh(U, F);
+  viewer.set_edges(C,BE,sea_green);
+  viewer.options.show_lines = false;
+  viewer.options.show_overlay_depth = false;
+  viewer.options.line_width = 1;
+  viewer.options.trackball_angle.normalize();
+  viewer.callback_pre_draw = &pre_draw;
+  viewer.callback_key_down = &key_down;
+  viewer.options.is_animating = false;
+  viewer.options.animation_max_fps = 30.;
+  viewer.launch();
+}

+ 31 - 0
tutorial/cmake/FindMOSEK.cmake

@@ -0,0 +1,31 @@
+#
+# Try to find MOSEK
+# Once done this will define
+#
+# MOSEK_FOUND           - system has MOSEK
+# MOSEK_INCLUDE_DIRS    - the MOSEK include directories
+# MOSEK_LIBRARIES       - Link these to use MOSEK
+#
+
+FIND_PATH(MOSEK_INCLUDE_DIR mosek.h
+  PATHS /usr/local/mosek/7/tools/platform/osx64x86/h/
+    )
+
+SET(SEARCH_PATHS "${MOSEK_INCLUDE_DIR}" "${MOSEK_INCLUDE_DIR}/../bin" "${MOSEK_INCLUDE_DIR}/lib")
+
+set(MOSEK_LIBRARIES)
+FIND_LIBRARY(MOSEK_LIBRARIES  NAMES mosek64 PATHS ${SEARCH_PATHS} NO_DEFAULT_PATH DPATH_SUFFIXES a lib dylib)
+
+if(MOSEK_LIBRARIES AND MOSEK_INCLUDE_DIR)
+message(STATUS "Found mosek: ${MOSEK_LIBRARIES}")
+set(MOSEK_FOUND TRUE)
+endif(MOSEK_LIBRARIES AND MOSEK_INCLUDE_DIR)
+
+IF (MOSEK_FOUND)
+   message(STATUS "Found MOSEK: ${MOSEK_INCLUDE_DIR}")
+   SET(MOSEK_INCLUDE_DIRS ${MOSEK_INCLUDE_DIR} )
+ELSE (MOSEK_FOUND)
+    #add_definitions(-DIGL_NO_MOSEK)
+    message(WARNING "could NOT find MOSEK")
+ENDIF (MOSEK_FOUND)
+

+ 1 - 0
tutorial/shared/arm-weights.dmat.REMOVED.git-id

@@ -0,0 +1 @@
+2c590c9778cd6d08706d0f04522456ac5c3227e3

+ 1 - 0
tutorial/shared/arm.obj.REMOVED.git-id

@@ -0,0 +1 @@
+72e27526420c96ae057efda818e9b63aafcc604b

+ 11 - 0
tutorial/shared/arm.tgf

@@ -0,0 +1,11 @@
+   1 -0.72962893 0.011729617 -0.1327604          0 3.9525252e-323 4.9406565e-324          1          1          1          0          0          0          1 0.94587917  1.0551426  0.8672396          0    1 
+   2 -0.78317295 0.21661256 -0.0075451165 2.1219958e-314 2.1219958e-314 1.527837e-312          1          1          1          0          0          0          1 0.89233515  1.2574551 0.99245488          0    2 
+   3 0.081400687 0.18519857 -0.042544638          0 3.9525252e-323 9.8813129e-324          1          1          1          0          0          0          1   1.857155 0.98442204 0.95745536          0    4 
+   4  0.5987815 -0.077609889 0.065252126 4.441723e+291 4.441723e+291 4.441723e+291          1          1          1          0          0          0          1  1.5751366 0.73446566  1.0652521          0    6 
+   5 0.73572894 -0.17523362 0.090210152 2.7982368e+199 3.7150555e-27 6.0174446e+175          1          1          1          0          0          0          1  1.1543039 0.88360183  1.0902102          0    8 
+#
+   3    4 1 0 1 0 7
+   1    2 1 0 1 0 3
+   4    5 1 0 1 0 9
+   2    3 1 0 1 0 5
+#