Browse Source

Merge branch 'master' of https://github.com/libigl/libigl

Former-commit-id: 2cbf765c97eb892297a370faaae4f2e28292e3f1
Alec Jacobson 10 years ago
parent
commit
75e6360907

+ 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(

+ 0 - 42
include/igl/get_modifiers.cpp

@@ -1,42 +0,0 @@
-#include "get_modifiers.h"
-
-/* glutGetModifiers return mask. */
-#ifndef GLUT_ACTIVE_SHIFT
-#  define GLUT_ACTIVE_SHIFT 1
-#endif
-#ifndef GLUT_ACTIVE_CTRL
-#  define GLUT_ACTIVE_CTRL 2
-#endif
-#ifndef GLUT_ACTIVE_ALT
-#  define GLUT_ACTIVE_ALT 4
-#endif
-#ifndef GLUT_ACTIVE_COMMAND
-#  define GLUT_ACTIVE_COMMAND 8
-#endif
-
-#ifdef __APPLE__
-#include <Carbon/Carbon.h>
-#endif
-
-IGL_INLINE int igl::get_modifiers()
-{
-  int mod = 0;
-#ifdef __APPLE__
-  // http://stackoverflow.com/a/18082326/148668
-  KeyMap keyStates;
-  const auto & carbon_is_keydown = [&keyStates]( uint16_t vKey )->bool
-  {
-    uint8_t index = vKey / 32 ;
-    uint8_t shift = vKey % 32 ;
-    return keyStates[index].bigEndianValue & (1 << shift) ;
-  };
-  GetKeys(keyStates) ;
-  mod |= (carbon_is_keydown(kVK_Command)?GLUT_ACTIVE_COMMAND:0);
-  mod |= (carbon_is_keydown(kVK_Shift)?GLUT_ACTIVE_SHIFT:0);
-  mod |= (carbon_is_keydown(kVK_Option)?GLUT_ACTIVE_ALT:0);
-  mod |= (carbon_is_keydown(kVK_Control)?GLUT_ACTIVE_CTRL:0);
-#else
-#  error "Not supported."
-#endif
-  return mod;
-}

+ 54 - 7
include/igl/get_modifiers.h

@@ -1,22 +1,69 @@
 #ifndef GET_MODIFIERS_H
 #define GET_MODIFIERS_H
-#include "igl_inline.h"
+//#include "igl_inline.h"
 namespace igl
 {
   enum Modifier
   {
     MODIFIER_OPTION = 1,
-    MODIFIER_SHIFT = 3,
-    MODIFIER_CONTROL = 5,
-    MODIFIER_COMMAND = 9,
+    MODIFIER_SHIFT = 2,
+    MODIFIER_CONTROL = 4,
+    MODIFIER_COMMAND = 8,
     NUM_MODIFIERS = 4,
   };
   // 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"
+
+// Implementation 
+
+/* glutGetModifiers return mask. */
+#ifndef GLUT_ACTIVE_SHIFT
+#  define GLUT_ACTIVE_SHIFT 1
+#endif
+#ifndef GLUT_ACTIVE_CTRL
+#  define GLUT_ACTIVE_CTRL 2
+#endif
+#ifndef GLUT_ACTIVE_ALT
+#  define GLUT_ACTIVE_ALT 4
+#endif
+#ifndef GLUT_ACTIVE_COMMAND
+#  define GLUT_ACTIVE_COMMAND 8
+#endif
+
+#ifdef __APPLE__
+//#include <Carbon/HIToolbox/Events.h>
+#include <Carbon/Carbon.h>
 #endif
+
+#warning "igl::get_modifiers is deprecated. If using GLUT, try Alec's glut patch www.alecjacobson.com/weblog/?p=3659 and use glutGetModifiers"
+
+// FORCED INLINE
+inline int igl::get_modifiers()
+{
+  int mod = 0;
+#ifdef __APPLE__
+  // http://stackoverflow.com/a/18082326/148668
+  KeyMap keyStates;
+  const auto & carbon_is_keydown = [&keyStates]( uint16_t vKey )->bool
+  {
+    uint8_t index = vKey / 32 ;
+    uint8_t shift = vKey % 32 ;
+    return keyStates[index].bigEndianValue & (1 << shift) ;
+  };
+  GetKeys(keyStates) ;
+  mod |= (carbon_is_keydown(kVK_Command)?GLUT_ACTIVE_COMMAND:0);
+  mod |= (carbon_is_keydown(kVK_Shift)?GLUT_ACTIVE_SHIFT:0);
+  mod |= (carbon_is_keydown(kVK_Option)?GLUT_ACTIVE_ALT:0);
+  mod |= (carbon_is_keydown(kVK_Control)?GLUT_ACTIVE_CTRL:0);
+#else
+#  warning "igl::get_modifiers not supported on your OS, some demos may not work correctly."
+#endif
+  return mod;
+}
+
 #endif

+ 3 - 9
include/igl/massmatrix.cpp

@@ -8,6 +8,7 @@
 #include "massmatrix.h"
 #include "normalize_row_sums.h"
 #include "sparse.h"
+#include "doublearea.h"
 #include "repmat.h"
 #include <Eigen/Geometry>
 #include <iostream>
@@ -51,15 +52,8 @@ IGL_INLINE void igl::massmatrix(
       l(i,1) = (V.row(F(i,2))-V.row(F(i,0))).norm();
       l(i,2) = (V.row(F(i,0))-V.row(F(i,1))).norm();
     }
-    // semiperimeters
-    Matrix<Scalar,Dynamic,1> s = l.rowwise().sum()*0.5;
-    assert(s.rows() == m);
-    // Heron's forumal for area
-    Matrix<Scalar,Dynamic,1> dblA(m);
-    for(int i = 0;i<m;i++)
-    {
-      dblA(i) = 2.0*sqrt(s(i)*(s(i)-l(i,0))*(s(i)-l(i,1))*(s(i)-l(i,2)));
-    }
+    Matrix<Scalar,Dynamic,1> dblA;
+    doublearea(l,dblA);
 
     switch(eff_type)
     {

+ 1 - 1
tutorial/tutorial.html.REMOVED.git-id

@@ -1 +1 @@
-a30fd5f786682eb951f8170826b3b3212240db31
+b9957737157efb49bcc9a87f4dab957882ed1d66

+ 1 - 1
tutorial/tutorial.md.REMOVED.git-id

@@ -1 +1 @@
-227bf977c70fc9d17fb2b2823c0818e6205893d2
+aaf279644b2b756c9b3ab497804486fa7179564c