Browse Source

scaling in draw skeleton 3d

Former-commit-id: 8b3691faf5c13313db830226c1883635bd0d09e9
Alec Jacobson 10 years ago
parent
commit
c53a2affd6

+ 3 - 2
examples/skeleton-builder/example.cpp

@@ -1,4 +1,3 @@
-#include <igl/draw_skeleton_3d.h>
 #include <igl/draw_skeleton_vector_graphics.h>
 #include <igl/two_axis_valuator_fixed_up.h>
 #include <igl/read_triangle_mesh.h>
@@ -41,6 +40,7 @@
 #include <igl/writeTGF.h>
 #include <igl/file_exists.h>
 #include <igl/centroid.h>
+#include <igl/draw_skeleton_3d.h>
 
 #include <Eigen/Core>
 #include <Eigen/Geometry>
@@ -310,7 +310,7 @@ void display()
             }
           }
         }
-        draw_skeleton_3d(s.C,s.BE,MatrixXd(),colors);
+        draw_skeleton_3d(s.C,s.BE,MatrixXd(),colors,bbd*0.5);
         break;
       }
       case SKEL_STYLE_TYPE_VECTOR_GRAPHICS:
@@ -707,6 +707,7 @@ void init_relative()
   Vmid = 0.5*(Vmax + Vmin);
   centroid(V,F,Vcen);
   bbd = (Vmax-Vmin).norm();
+  cout<<"bbd: "<<bbd<<endl;
   camera.push_away(2);
 }
 

+ 1 - 1
examples/skeleton-posing/example.cpp

@@ -296,7 +296,7 @@ void display()
       default:
       case SKEL_STYLE_TYPE_3D:
       {
-        draw_skeleton_3d(C,BE,T,s.colors);
+        draw_skeleton_3d(C,BE,T,s.colors,bbd*0.5);
         break;
       }
       case SKEL_STYLE_TYPE_VECTOR_GRAPHICS:

+ 1 - 1
examples/skeleton/example.cpp

@@ -293,7 +293,7 @@ void display()
   {
     default:
     case SKEL_STYLE_TYPE_3D:
-      draw_skeleton_3d(C,BE,T);
+      draw_skeleton_3d(C,BE,T,MAYA_VIOLET,bbd*0.5);
       break;
     case SKEL_STYLE_TYPE_VECTOR_GRAPHICS:
       draw_skeleton_vector_graphics(C,BE,T);

+ 12 - 14
include/igl/draw_skeleton_3d.cpp

@@ -21,7 +21,8 @@ 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<Derivedcolor> & color)
+  const Eigen::PlainObjectBase<Derivedcolor> & color,
+  const double half_bbd)
 {
   // Note: Maya's skeleton *does* scale with the mesh suggesting a scale
   // parameter. Further, its joint balls are not rotated with the bones.
@@ -29,7 +30,7 @@ IGL_INLINE void igl::draw_skeleton_3d(
   using namespace std;
   if(color.size() == 0)
   {
-    return draw_skeleton_3d(C,BE,T,MAYA_SEA_GREEN);
+    return draw_skeleton_3d(C,BE,T,MAYA_SEA_GREEN,half_bbd);
   }
   assert(color.cols() == 4 || color.size() == 4);
   if(T.size() == 0)
@@ -42,15 +43,13 @@ IGL_INLINE void igl::draw_skeleton_3d(
     {
       return;
     }
-    return draw_skeleton_3d(C,BE,T,color);
+    return draw_skeleton_3d(C,BE,T,color,half_bbd);
   }
   assert(T.rows() == BE.rows()*(C.cols()+1));
   assert(T.cols() == C.cols());
-  // old settings
-  int old_lighting=0;
-  double old_line_width=1;
-  glGetIntegerv(GL_LIGHTING,&old_lighting);
-  glGetDoublev(GL_LINE_WIDTH,&old_line_width);
+  // push old settings
+  glPushAttrib(GL_LIGHTING_BIT);
+  glPushAttrib(GL_LINE_BIT);
   glDisable(GL_LIGHTING);
   glLineWidth(1.0);
 
@@ -103,7 +102,7 @@ IGL_INLINE void igl::draw_skeleton_3d(
     auto s = C.row(BE(e,0));
     auto d = C.row(BE(e,1));
     auto b = (d-s).transpose().eval();
-    double r = 0.02;
+    double r = 0.02*half_bbd;
     Matrix4d Te = Matrix4d::Identity();
     Te.block(0,0,3,4) = T.block(e*4,0,4,3).transpose();
     Quaterniond q;
@@ -113,8 +112,7 @@ IGL_INLINE void igl::draw_skeleton_3d(
     glTranslated(s(0),s(1),s(2));
     if(color.size() == 4)
     {
-      Vector4d d = color.template cast<double>();
-      glColor4dv(d.data());
+      glColor4d( color(0), color(1), color(2), color(3));
     }else
     {
       glColor4d( color(e,0), color(e,1), color(e,2), color(e,3));
@@ -136,8 +134,8 @@ IGL_INLINE void igl::draw_skeleton_3d(
     glPopMatrix();
   }
   // Reset settings
-  (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING));
-  glLineWidth(old_line_width);
+  glPopAttrib();
+  glPopAttrib();
 }
 
 template <typename DerivedC, typename DerivedBE, typename DerivedT>
@@ -161,5 +159,5 @@ IGL_INLINE void igl::draw_skeleton_3d(
 // 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::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&);
+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, 4, 1, 0, 4, 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, 4, 1, 0, 4, 1> > const&, double);
 #endif

+ 3 - 1
include/igl/draw_skeleton_3d.h

@@ -19,6 +19,7 @@ namespace igl
   //   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
+  //   half_bbd  half bounding box diagonal to determine scaling {1.0}
   template <
     typename DerivedC, 
     typename DerivedBE, 
@@ -28,7 +29,8 @@ namespace igl
     const Eigen::PlainObjectBase<DerivedC> & C,
     const Eigen::PlainObjectBase<DerivedBE> & BE,
     const Eigen::PlainObjectBase<DerivedT> & T,
-    const Eigen::PlainObjectBase<Derivedcolor> & color);
+    const Eigen::PlainObjectBase<Derivedcolor> & color,
+    const double half_bbd=0.5);
   // Default color
   template <typename DerivedC, typename DerivedBE, typename DerivedT>
   IGL_INLINE void draw_skeleton_3d(

+ 4 - 2
include/igl/get_modifiers.cpp

@@ -15,10 +15,12 @@
 #endif
 
 #ifdef __APPLE__
-#include <Carbon/HIToolbox/Events.h>
+//#include <Carbon/HIToolbox/Events.h>
+#include <Carbon/Carbon.h>
 #endif
 
-IGL_INLINE int igl::get_modifiers()
+// FORCED INLINE
+inline int igl::get_modifiers()
 {
   int mod = 0;
 #ifdef __APPLE__

+ 8 - 5
include/igl/get_modifiers.h

@@ -1,6 +1,6 @@
 #ifndef GET_MODIFIERS_H
 #define GET_MODIFIERS_H
-#include "igl_inline.h"
+//#include "igl_inline.h"
 namespace igl
 {
   enum Modifier
@@ -14,9 +14,12 @@ namespace igl
   // Retrieve current modifier constellation. 
   //
   // Returns int that's an "or" of the active modifiers above.
-  IGL_INLINE int get_modifiers();
+  //
+  // FORCED INLINE
+  inline int get_modifiers();
 }
-#ifndef IGL_STATIC_LIBRARY
-#include "get_modifiers.cpp"
-#endif
+// FORCED INLINE
+//#ifndef IGL_STATIC_LIBRARY
+//#include "get_modifiers.cpp"
+//#endif
 #endif