Browse Source

openmp if catch in project_to_line*

Former-commit-id: 27b0ee75b5ace09d89e265dd913978afc41518c4
Alec Jacobson (jalec 11 years ago
parent
commit
865b841fb1

+ 7 - 4
include/igl/draw_skeleton_3d.cpp

@@ -27,7 +27,7 @@ IGL_INLINE void igl::draw_skeleton_3d(
   // parameter. Further, its joint balls are not rotated with the bones.
   using namespace Eigen;
   using namespace std;
-  assert(color.cols() == 4);
+  assert(color.cols() == 4 || color.size() == 4);
   if(T.size() == 0)
   {
     typedef Eigen::Matrix<typename DerivedT::Scalar,Dynamic,Dynamic> Mat;
@@ -40,6 +40,8 @@ IGL_INLINE void igl::draw_skeleton_3d(
     }
     return draw_skeleton_3d(C,BE,T,MAYA_SEA_GREEN);
   }
+  assert(T.rows() == BE.rows()*(C.cols()+1));
+  assert(T.cols() == C.cols());
   // old settings
   int old_lighting=0;
   double old_line_width=1;
@@ -105,12 +107,13 @@ IGL_INLINE void igl::draw_skeleton_3d(
     glPushMatrix();
     glMultMatrixd(Te.data());
     glTranslated(s(0),s(1),s(2));
-    if(color.rows() > 1)
+    if(color.size() == 4)
     {
-      glColor4d( color(e,0), color(e,1), color(e,2), color(e,3));
+      Vector4d d = color.template cast<double>();
+      glColor4dv(d.data());
     }else
     {
-      glColor4d( color(0,0), color(0,1), color(0,2), color(0,3));
+      glColor4d( color(e,0), color(e,1), color(e,2), color(e,3));
     }
     draw_sphere(r);
     const double len = b.norm()-2.*r;

+ 18 - 2
include/igl/list_to_matrix.cpp

@@ -62,11 +62,26 @@ IGL_INLINE bool igl::list_to_matrix(const std::vector<T > & V,Mat & M)
   {
     //fprintf(stderr,"Error: list_to_matrix() list is empty()\n");
     //return false;
-    M.resize(0,0);
+    if(Mat::ColsAtCompileTime == 1)
+    {
+      M.resize(0,1);
+    }else if(Mat::RowsAtCompileTime == 1)
+    {
+      M.resize(1,0);
+    }else
+    {
+      M.resize(0,0);
+    }
     return true;
   }
   // Resize output
-  M.resize(m,1);
+  if(Mat::RowsAtCompileTime == 1)
+  {
+    M.resize(1,m);
+  }else
+  {
+    M.resize(m,1);
+  }
 
   // Loop over rows
   for(int i = 0;i<m;i++)
@@ -105,4 +120,5 @@ template bool igl::list_to_matrix<int, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(std
 template bool igl::list_to_matrix<int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > >(std::vector<int, std::allocator<int> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template bool igl::list_to_matrix<double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > >(std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&);
 template bool igl::list_to_matrix<int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > >(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> >&);
+template bool igl::list_to_matrix<double, Eigen::Matrix<double, 1, -1, 1, 1, -1> >(std::vector<double, std::allocator<double> > const&, Eigen::Matrix<double, 1, -1, 1, 1, -1>&);
 #endif

+ 1 - 1
include/igl/project_to_line.cpp

@@ -39,7 +39,7 @@ IGL_INLINE void igl::project_to_line(
   t.resize(np,1);
   sqrD.resize(np,1);
   // loop over points 
-#pragma omp parallel for
+#pragma omp parallel for if (np>10000)
   for(int i = 0;i<np;i++)
   {
     MatL Pi = P.row(i);

+ 1 - 1
include/igl/project_to_line_segment.cpp

@@ -25,7 +25,7 @@ IGL_INLINE void igl::project_to_line_segment(
   project_to_line(P,S,D,t,sqrD);
   const int np = P.rows();
   // loop over points and fix those that projected beyond endpoints
-#pragma omp parallel for
+#pragma omp parallel for if (np>10000)
   for(int p = 0;p<np;p++)
   {
     if(t(p)<0)

+ 3 - 0
todos.txt

@@ -27,3 +27,6 @@
 - unify include opengl with convenience includes
 - MatrixBase --> PlainObjectBase
 - min_quad_with_fixed should probably be a class
+- everywhere appropriate change:
+  `#pragma omp parallel for` to `#pragma omp parallel for if (n>10000)` where
+  `n` and `1000` are replaced accordingly