Browse Source

fixed bug in per_corner_normals, separated draw_Floor_outline from draw_floor

Former-commit-id: d97e7ca8cb9ee30ae93381ba9ea0dd5071d4ddf5
Alec Jacobson (jalec 11 years ago
parent
commit
440670b2ac

+ 44 - 11
include/igl/draw_floor.cpp

@@ -3,14 +3,16 @@
 
 #include "OpenGL_convenience.h"
 
+static const int GridSizeX = 100;
+static const int GridSizeY = 100;
+static const float SizeX = 0.5f;
+static const float SizeY = 0.5f;
 IGL_INLINE void igl::draw_floor(const float * colorA, const float * colorB)
 {
   // old settings
   int old_lighting=0,old_color_material=0;
-  float old_line_width =0;
   glGetIntegerv(GL_LIGHTING,&old_lighting);
   glGetIntegerv(GL_COLOR_MATERIAL,&old_color_material);
-  glGetFloatv(GL_LINE_WIDTH,&old_line_width);
   glDisable(GL_LIGHTING);
   glColorMaterial( GL_FRONT, GL_EMISSION);
   glEnable(GL_COLOR_MATERIAL);
@@ -31,12 +33,6 @@ IGL_INLINE void igl::draw_floor(const float * colorA, const float * colorB)
     glDisable(GL_LIGHTING);
   }
 
-  int GridSizeX = 100;
-  int GridSizeY = 100;
-  //int GridSizeX = 5;
-  //int GridSizeY = 5;
-  float SizeX = 0.5f;
-  float SizeY = 0.5f;
 
   glBegin(GL_QUADS);
   glNormal3f(0,1,0);
@@ -59,6 +55,42 @@ IGL_INLINE void igl::draw_floor(const float * colorA, const float * colorB)
   }
   glEnd();
 
+  (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING));
+  (old_color_material? glEnable(GL_COLOR_MATERIAL) : glDisable(GL_COLOR_MATERIAL));
+}
+
+IGL_INLINE void igl::draw_floor()
+{
+  const float grey[] = {0.80,0.80,0.80,1.};
+  const float white[] = {0.95,0.95,0.95,1.};
+  igl::draw_floor(grey,white);
+}
+
+IGL_INLINE void igl::draw_floor_outline(const float * colorA, const float * colorB)
+{
+  float old_line_width =0;
+  // old settings
+  int old_lighting=0,old_color_material=0;
+  glGetIntegerv(GL_LIGHTING,&old_lighting);
+  glGetIntegerv(GL_COLOR_MATERIAL,&old_color_material);
+  glDisable(GL_LIGHTING);
+
+  // Set material
+  const float black[] = {0.,0.,0.,1.};
+  glMaterialfv(GL_FRONT, GL_AMBIENT, black);
+  glMaterialfv(GL_FRONT, GL_DIFFUSE, black);
+  glMaterialfv(GL_FRONT, GL_SPECULAR, black);
+  glMaterialfv(GL_FRONT, GL_EMISSION, black);
+  glMaterialf(GL_FRONT, GL_SHININESS,0);
+  const bool use_lighting = false;
+  if(use_lighting)
+  {
+    glEnable(GL_LIGHTING);
+  }else
+  {
+    glDisable(GL_LIGHTING);
+  }
+
   glLineWidth(2.0f);
   glBegin(GL_LINES);
   for (int x =-GridSizeX/2;x<=GridSizeX/2;++x)
@@ -103,15 +135,16 @@ IGL_INLINE void igl::draw_floor(const float * colorA, const float * colorB)
   }
   glEnd();
 
+  glGetFloatv(GL_LINE_WIDTH,&old_line_width);
+  glLineWidth(old_line_width);
   (old_lighting ? glEnable(GL_LIGHTING) : glDisable(GL_LIGHTING));
   (old_color_material? glEnable(GL_COLOR_MATERIAL) : glDisable(GL_COLOR_MATERIAL));
-  glLineWidth(old_line_width);
 }
 
-IGL_INLINE void igl::draw_floor()
+IGL_INLINE void igl::draw_floor_outline()
 {
   const float grey[] = {0.80,0.80,0.80,1.};
   const float white[] = {0.95,0.95,0.95,1.};
-  igl::draw_floor(grey,white);
+  igl::draw_floor_outline(grey,white);
 }
 #endif

+ 19 - 0
include/igl/draw_floor.h

@@ -12,9 +12,28 @@ namespace igl
   // Inputs:
   //   colorA  float4 color
   //   colorB  float4 color
+  //
+  // Example:
+  //   // Draw a nice floor
+  //   glPushMatrix();
+  //   glCullFace(GL_BACK);
+  //   glEnable(GL_CULL_FACE);
+  //   glEnable(GL_LIGHTING);
+  //   glTranslated(0,-1,0);
+  //   if(project(Vector3d(0,0,0))(2) - project(Vector3d(0,1,0))(2) > -FLOAT_EPS)
+  //   {
+  //     draw_floor_outline();
+  //   }
+  //   draw_floor();
+  //   glPopMatrix();
+  //   glDisable(GL_CULL_FACE);
+  //
   IGL_INLINE void draw_floor(const float * colorA, const float * colorB);
   // Wrapper with default colors
   IGL_INLINE void draw_floor();
+  IGL_INLINE void draw_floor_outline(const float * colorA, const float * colorB);
+  // Wrapper with default colors
+  IGL_INLINE void draw_floor_outline();
 }
 #ifdef IGL_HEADER_ONLY
 #  include "draw_floor.cpp"

+ 2 - 2
include/igl/per_corner_normals.cpp

@@ -55,8 +55,8 @@ IGL_INLINE void igl::per_corner_normals(
   // valence of faces
   const int n = F.cols();
 
-  // initialize output to zero
-  CN.resize(m*n,3);
+  // initialize output to ***zero***
+  CN.setZero(m*n,3);
 
   // loop over faces
   for(size_t i = 0;int(i)<m;i++)

+ 10 - 0
include/igl/project.cpp

@@ -72,9 +72,19 @@ IGL_INLINE int igl::project(
       &win(0),&win(1),&win(2));
 }
 
+template <typename Derivedobj>
+IGL_INLINE Eigen::PlainObjectBase<Derivedobj> igl::project(
+  const Eigen::PlainObjectBase<Derivedobj> & obj)
+{
+  Eigen::PlainObjectBase<Derivedobj> win;
+  project(obj,win);
+  return win;
+}
+
 #ifndef IGL_HEADER_ONLY
 // Explicit template instanciations
 template int igl::project<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
+template Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > igl::project<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
 #endif
 
 #endif

+ 4 - 0
include/igl/project.h

@@ -23,6 +23,10 @@ namespace igl
   IGL_INLINE int project(
     const Eigen::PlainObjectBase<Derivedobj> & obj,
     Eigen::PlainObjectBase<Derivedwin> & win);
+  // Eigen wrapper  with return
+  template <typename Derivedobj>
+  IGL_INLINE Eigen::PlainObjectBase<Derivedobj> project(
+    const Eigen::PlainObjectBase<Derivedobj> & obj);
 }
 
 #ifdef IGL_HEADER_ONLY

+ 2 - 2
scripts/header_cluster_demo.m

@@ -41,7 +41,7 @@ P = rand(numel(H),2);
 E = [EJ EI];
 L = (A-diag(sum(A,2)));
 I = 0*speye(size(L));
-[EV,ED] = eigs(L+I,ceil(sqrt(size(A,1))),'sm');
+[EV,ED] = eigs(L+I,size(A,1),'sm');
 EV = EV(:,2:end);
 ED = ED(2:end, 2:end);
 p = 1;
@@ -53,7 +53,7 @@ B = EV * (inv(abs(ED))^(p/2));
 %subplot(1,nsp,2);
 plot_edges(B(:,1:3),E);
 
-C = kmeans(B,size(B,2));
+C = kmeans(B,20);
 
 for c = 1:max(C)
   fprintf('%s\n',H{C==c});