Browse Source

draw skeleton with colors

Former-commit-id: b0a2de2df414115f2776a28acbbfd5cc35f162d8
Alec Jacobson (jalec 11 years ago
parent
commit
ae29184e91

+ 48 - 16
include/igl/draw_skeleton_3d.cpp

@@ -12,26 +12,34 @@
 #include <Eigen/Geometry>
 #include <iostream>
 
-template <typename DerivedC, typename DerivedBE>
-IGL_INLINE void igl::draw_skeleton_3d(
-  const Eigen::PlainObjectBase<DerivedC> & C,
-  const Eigen::PlainObjectBase<DerivedBE> & BE)
-{
-  using namespace Eigen;
-  typedef Eigen::Matrix<typename DerivedC::Scalar,Dynamic,Dynamic> Mat;
-  Mat I = Mat::Identity(C.cols()+1,C.cols());
-  Mat T = I.replicate(BE.rows(),1);
-  return draw_skeleton_3d(C,BE,T);
-}
-
-template <typename DerivedC, typename DerivedBE, typename DerivedT>
+template <
+  typename DerivedC, 
+  typename DerivedBE, 
+  typename DerivedT, 
+  typename Derivedcolor>
 IGL_INLINE void igl::draw_skeleton_3d(
   const Eigen::PlainObjectBase<DerivedC> & C,
   const Eigen::PlainObjectBase<DerivedBE> & BE,
-  const Eigen::PlainObjectBase<DerivedT> & T)
+  const Eigen::PlainObjectBase<DerivedT> & T,
+  const Eigen::PlainObjectBase<Derivedcolor> & color)
 {
+  // Note: Maya's skeleton *does* scale with the mesh suggesting a scale
+  // parameter. Further, its joint balls are not rotated with the bones.
   using namespace Eigen;
   using namespace std;
+  assert(color.cols() == 4);
+  if(T.size() == 0)
+  {
+    typedef Eigen::Matrix<typename DerivedT::Scalar,Dynamic,Dynamic> Mat;
+    Mat I = Mat::Identity(C.cols()+1,C.cols());
+    Mat T = I.replicate(BE.rows(),1);
+    // insane base case
+    if(T.size() == 0)
+    {
+      return;
+    }
+    return draw_skeleton_3d(C,BE,T,MAYA_SEA_GREEN);
+  }
   // old settings
   int old_lighting=0;
   double old_line_width=1;
@@ -39,7 +47,6 @@ IGL_INLINE void igl::draw_skeleton_3d(
   glGetDoublev(GL_LINE_WIDTH,&old_line_width);
   glDisable(GL_LIGHTING);
   glLineWidth(1.0);
-  glColor4fv(MAYA_SEA_GREEN.data());
 
   auto draw_sphere = [](const double r)
   {
@@ -98,6 +105,13 @@ IGL_INLINE void igl::draw_skeleton_3d(
     glPushMatrix();
     glMultMatrixd(Te.data());
     glTranslated(s(0),s(1),s(2));
+    if(color.rows() > 1)
+    {
+      glColor4d( color(e,0), color(e,1), color(e,2), color(e,3));
+    }else
+    {
+      glColor4d( color(0,0), color(0,1), color(0,2), color(0,3));
+    }
     draw_sphere(r);
     const double len = b.norm()-2.*r;
     if(len>=0)
@@ -119,8 +133,26 @@ IGL_INLINE void igl::draw_skeleton_3d(
   glLineWidth(old_line_width);
 }
 
+template <typename DerivedC, typename DerivedBE, typename DerivedT>
+IGL_INLINE void igl::draw_skeleton_3d(
+  const Eigen::PlainObjectBase<DerivedC> & C,
+  const Eigen::PlainObjectBase<DerivedBE> & BE,
+  const Eigen::PlainObjectBase<DerivedT> & T)
+{
+  return draw_skeleton_3d(C,BE,T,MAYA_SEA_GREEN);
+}
+
+template <typename DerivedC, typename DerivedBE>
+IGL_INLINE void igl::draw_skeleton_3d(
+  const Eigen::PlainObjectBase<DerivedC> & C,
+  const Eigen::PlainObjectBase<DerivedBE> & BE)
+{
+  return draw_skeleton_3d(C,BE,Eigen::MatrixXd(),MAYA_SEA_GREEN);
+}
+
 #ifndef IGL_HEADER_ONLY
 // Explicit template instanciation
-template void igl::draw_skeleton_3d<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&);
 template void igl::draw_skeleton_3d<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
+template void igl::draw_skeleton_3d<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&);
+template void igl::draw_skeleton_3d<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&);
 #endif

+ 14 - 1
include/igl/draw_skeleton_3d.h

@@ -8,6 +8,7 @@
 #ifndef IGL_DRAW_SKELETON_3D_H
 #define IGL_DRAW_SKELETON_3D_H
 #include "igl_inline.h"
+#include "material_colors.h"
 #include <Eigen/Core>
 namespace igl
 {
@@ -17,12 +18,24 @@ namespace igl
   //   C  #C by dim List of joint rest positions
   //   BE  #BE by 2 list of bone edge indices into C
   //   T  #BE*(dim+1) by dim  matrix of stacked transposed bone transformations
+  //   color  #BE|1 by 4 list of color
+  template <
+    typename DerivedC, 
+    typename DerivedBE, 
+    typename DerivedT, 
+    typename Derivedcolor>
+  IGL_INLINE void draw_skeleton_3d(
+    const Eigen::PlainObjectBase<DerivedC> & C,
+    const Eigen::PlainObjectBase<DerivedBE> & BE,
+    const Eigen::PlainObjectBase<DerivedT> & T,
+    const Eigen::PlainObjectBase<Derivedcolor> & color);
+  // Wrapper with each T = Identity
   template <typename DerivedC, typename DerivedBE, typename DerivedT>
   IGL_INLINE void draw_skeleton_3d(
     const Eigen::PlainObjectBase<DerivedC> & C,
     const Eigen::PlainObjectBase<DerivedBE> & BE,
     const Eigen::PlainObjectBase<DerivedT> & T);
-  // Wrapper with each T = Identity
+  // Default color
   template <typename DerivedC, typename DerivedBE>
   IGL_INLINE void draw_skeleton_3d(
     const Eigen::PlainObjectBase<DerivedC> & C,

+ 1 - 0
include/igl/material_colors.h

@@ -49,6 +49,7 @@ namespace igl
     MAYA_RED(234./255.,63./255.,52./255.,1.),
     MAYA_BLUE(0./255.,73./255.,252./255.,1.),
     MAYA_PURPLE(180./255.,73./255.,200./255.,1.),
+    MAYA_VIOLET(31./255.,15./255.,66./255.,1.),
     MAYA_GREY(0.5,0.5,0.5,1.0),
     MAYA_CYAN(131./255.,219./255.,252./255.,1.),
     MAYA_SEA_GREEN(70./255.,252./255.,167./255.,1.);

+ 7 - 0
matlab-to-eigen.html

@@ -237,6 +237,13 @@ IP.conservativeResize(stable_partition(
         </code></pre></td>
         <td>Where I and P are vectors. <i>Requires C++11 and <code>#include &lt;algorithm&gt;</code></i></td>
       </tr>
+
+      <tr class=d0>
+        <td><pre><code>a = any(A(:))</code></pre></td>
+        <td><pre><code>bool a = any_of(A.data(),A.data()+A.size(),[](bool a){ return a;});</code></pre></td>
+        <td>Casts <code>Matrix::Scalar<code> to <code>bool</code>.</td>
+      </tr>
+
       <!-- Insert rows for each command pair -->
 
       <!-- Leave this here for copy and pasting