Browse Source

quicklook for point clouds

Former-commit-id: 65a9cf6c1df884a85eb801bbdd7466a5a6a01f87
Alec Jacobson 10 years ago
parent
commit
f328a0e42c
2 changed files with 34 additions and 6 deletions
  1. 28 3
      examples/quicklook-mesh/src/render_to_buffer.cpp
  2. 6 3
      include/igl/readOFF.cpp

+ 28 - 3
examples/quicklook-mesh/src/render_to_buffer.cpp

@@ -280,7 +280,24 @@ void display()
       glMaterialfv(GL_BACK, GL_SPECULAR, SILVER_SPECULAR);
       glMaterialf (GL_BACK, GL_SHININESS, 128);
     //}
-    draw_mesh(V,F,N);
+    if(F.rows() == 0)
+    {
+      glPointSize(1.+ 20./log10(V.rows()));
+      const bool has_normals = N.rows() == V.rows();
+      glBegin(GL_POINTS);
+      for(int v = 0;v<V.rows();v++)
+      {
+        if(has_normals)
+        {
+          glNormal3d(N(v,0),N(v,1),N(v,2));
+        }
+        glVertex3d(V(v,0),V(v,1),V(v,2));
+      }
+      glEnd();
+    }else
+    {
+      draw_mesh(V,F,N);
+    }
     //if(invert)
     //{
     //  glFrontFace(GL_CCW);
@@ -411,13 +428,21 @@ bool render_to_buffer(
       red(width,height,buffer);
       return false;
     }
+    if(!list_to_matrix(vN,N))
+    {
+      // silently continue
+      N.resize(0,0);
+    }
     polygon_mesh_to_triangle_mesh(vF,F);
   }
   cout<<"IO: "<<(get_seconds()-ts)<<"s"<<endl;
   ts = get_seconds();
 
-  // Computer already normalized per triangle normals
-  per_face_normals(V,F,N);
+  // Compute already normalized per triangle normals
+  if(N.rows() != V.rows() && N.rows() != F.rows())
+  {
+    per_face_normals(V,F,N);
+  }
   //Vmean = 0.5*(V.colwise().maxCoeff()+V.colwise().minCoeff());
   Vmax = V.colwise().maxCoeff();
   Vmin = V.colwise().minCoeff();

+ 6 - 3
include/igl/readOFF.cpp

@@ -16,6 +16,7 @@ IGL_INLINE bool igl::readOFF(
   std::vector<std::vector<Index > > & F,
   std::vector<std::vector<Scalar > > & N)
 {
+  using namespace std;
   FILE * off_file = fopen(off_file_name.c_str(),"r");                                       
   if(NULL==off_file)
   {
@@ -30,13 +31,15 @@ IGL_INLINE bool igl::readOFF(
   const std::string OFF("OFF");
   const std::string NOFF("NOFF");
   if(fscanf(off_file,"%s\n",header)!=1
-     || !(OFF == header || NOFF == header))
+     || !(
+       string(header).compare(0,NOFF.length(),NOFF)==0 || 
+       string(header).compare(0,NOFF.length(),NOFF)==0))
   {
     printf("Error: %s's first line should be OFF or NOFF not %s...",off_file_name.c_str(),header);
     fclose(off_file);
     return false; 
   }
-  bool has_normals = NOFF==header;
+  bool has_normals = string(header).compare(0,NOFF.length(),NOFF)==0;
   // Second line is #vertices #faces #edges
   int number_of_vertices;
   int number_of_faces;
@@ -80,7 +83,7 @@ IGL_INLINE bool igl::readOFF(
       }
       i++;
     }else if(
-             fscanf(off_file,"%[#]",&tic_tac_toe)==1)
+        fscanf(off_file,"%[#]",&tic_tac_toe)==1)
     {
       char comment[1000];
       fscanf(off_file,"%[^\n]",comment);