Browse Source

randperm, and manifold patches seemingly working

Former-commit-id: 1c1b53568979e64fdeb3db55d320b805e4716abb
Alec Jacobson (jalec 11 years ago
parent
commit
fc8fd874b7

+ 7 - 4
examples/flare-eyes/example.cpp

@@ -72,7 +72,7 @@ std::stack<State> redo_stack;
 bool is_rotating = false;
 bool is_rotating = false;
 int down_x,down_y;
 int down_x,down_y;
 igl::Camera down_camera;
 igl::Camera down_camera;
-bool render_to_png_on_next = false;
+bool render_to_tga_on_next = false;
 int render_count = 0;
 int render_count = 0;
 
 
 int width,height;
 int width,height;
@@ -236,7 +236,7 @@ void draw_eyes()
     LED_METHOD_COLORED_CIRCLE = 0,
     LED_METHOD_COLORED_CIRCLE = 0,
     LED_METHOD_OUTLINED_CIRCLE = 1,
     LED_METHOD_OUTLINED_CIRCLE = 1,
     LED_METHOD_TEXTURE_FLARE = 2
     LED_METHOD_TEXTURE_FLARE = 2
-  } method = LED_METHOD_TEXTURE_FLARE;
+  } method = LED_METHOD_COLORED_CIRCLE;
 
 
   
   
   for(int l = 0;l<NUM_LEDS;l++)
   for(int l = 0;l<NUM_LEDS;l++)
@@ -345,14 +345,14 @@ void display()
 
 
   report_gl_error();
   report_gl_error();
 
 
-  if(render_to_png_on_next)
+  if(render_to_tga_on_next)
   {
   {
     GLint viewport[4];
     GLint viewport[4];
     glGetIntegerv(GL_VIEWPORT,viewport);
     glGetIntegerv(GL_VIEWPORT,viewport);
     render_to_tga(
     render_to_tga(
       STR("./"<< "flare-eyes-" << setw(4) << setfill('0') << render_count++ << ".tga"),
       STR("./"<< "flare-eyes-" << setw(4) << setfill('0') << render_count++ << ".tga"),
       viewport[2],viewport[3],true);
       viewport[2],viewport[3],true);
-    //render_to_png_on_next = false;
+    //render_to_tga_on_next = false;
   }
   }
 
 
   TwDraw();
   TwDraw();
@@ -595,6 +595,9 @@ void key(unsigned char key, int mouse_x, int mouse_y)
           s.camera.rotation);
           s.camera.rotation);
         break;
         break;
       }
       }
+    case ' ':
+      render_to_tga_on_next = !render_to_tga_on_next;
+      break;
     default:
     default:
       if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
       if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
       {
       {

+ 25 - 14
examples/patches/example.cpp

@@ -23,6 +23,7 @@
 #include <igl/ReAntTweakBar.h>
 #include <igl/ReAntTweakBar.h>
 #include <igl/get_seconds.h>
 #include <igl/get_seconds.h>
 #include <igl/jet.h>
 #include <igl/jet.h>
+#include <igl/randperm.h>
 #include <igl/boost/manifold_patches.h>
 #include <igl/boost/manifold_patches.h>
 #include <igl/boost/components.h>
 #include <igl/boost/components.h>
 
 
@@ -37,13 +38,14 @@
 #include <iostream>
 #include <iostream>
 
 
 
 
-Eigen::MatrixXd V,N,C;
+Eigen::MatrixXd V,C;
 Eigen::VectorXd Vmid,Vmin,Vmax;
 Eigen::VectorXd Vmid,Vmin,Vmax;
 double bbd = 1.0;
 double bbd = 1.0;
 Eigen::MatrixXi F;
 Eigen::MatrixXi F;
 struct State
 struct State
 {
 {
   igl::Camera camera;
   igl::Camera camera;
+  Eigen::MatrixXd N;
 } s;
 } s;
 
 
 // See README for descriptions
 // See README for descriptions
@@ -222,14 +224,14 @@ void lights()
   glLightfv(GL_LIGHT0,GL_DIFFUSE,WHITE);
   glLightfv(GL_LIGHT0,GL_DIFFUSE,WHITE);
   glLightfv(GL_LIGHT0,GL_SPECULAR,BLACK);
   glLightfv(GL_LIGHT0,GL_SPECULAR,BLACK);
   glLightfv(GL_LIGHT0,GL_POSITION,pos.data());
   glLightfv(GL_LIGHT0,GL_POSITION,pos.data());
-  glEnable(GL_LIGHT1);
-  pos(0) *= -1;
-  pos(1) *= -1;
-  pos(2) *= -1;
-  glLightfv(GL_LIGHT1,GL_AMBIENT,BLACK);
-  glLightfv(GL_LIGHT1,GL_DIFFUSE,NEAR_BLACK);
-  glLightfv(GL_LIGHT1,GL_SPECULAR,BLACK);
-  glLightfv(GL_LIGHT1,GL_POSITION,pos.data());
+  //glEnable(GL_LIGHT1);
+  //pos(0) *= -1;
+  //pos(1) *= -1;
+  //pos(2) *= -1;
+  //glLightfv(GL_LIGHT1,GL_AMBIENT,BLACK);
+  //glLightfv(GL_LIGHT1,GL_DIFFUSE,NEAR_BLACK);
+  //glLightfv(GL_LIGHT1,GL_SPECULAR,BLACK);
+  //glLightfv(GL_LIGHT1,GL_POSITION,pos.data());
 }
 }
 
 
 void display()
 void display()
@@ -264,7 +266,7 @@ void display()
   // Set material properties
   // Set material properties
   glEnable(GL_COLOR_MATERIAL);
   glEnable(GL_COLOR_MATERIAL);
   glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
   glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
-  draw_mesh(V,F,N,C);
+  draw_mesh(V,F,s.N,C);
   pop_object();
   pop_object();
 
 
   // Draw a nice floor
   // Draw a nice floor
@@ -448,7 +450,7 @@ void init_relative()
 {
 {
   using namespace Eigen;
   using namespace Eigen;
   using namespace igl;
   using namespace igl;
-  per_face_normals(V,F,N);
+  per_face_normals(V,F,s.N);
   Vmax = V.colwise().maxCoeff();
   Vmax = V.colwise().maxCoeff();
   Vmin = V.colwise().minCoeff();
   Vmin = V.colwise().minCoeff();
   Vmid = 0.5*(Vmax + Vmin);
   Vmid = 0.5*(Vmax + Vmin);
@@ -462,14 +464,16 @@ void init_patches()
   using namespace std;
   using namespace std;
   VectorXi CC;
   VectorXi CC;
   SparseMatrix<int> A;
   SparseMatrix<int> A;
-  //manifold_patches(F,CC,A);
-  components(F,CC);
+  manifold_patches(F,CC,A);
+  //components(F,CC);
   C.resize(CC.rows(),3);
   C.resize(CC.rows(),3);
   double num_cc = (double)CC.maxCoeff()+1.0;
   double num_cc = (double)CC.maxCoeff()+1.0;
+  VectorXi I;
+  randperm(num_cc,I);
   for(int f = 0;f<CC.rows();f++)
   for(int f = 0;f<CC.rows();f++)
   {
   {
     jet(
     jet(
-      (double)CC(f)/num_cc,
+      (double)I(CC(f))/num_cc,
       C(f,0),
       C(f,0),
       C(f,1),
       C(f,1),
       C(f,2));
       C(f,2));
@@ -510,6 +514,13 @@ void key(unsigned char key, int mouse_x, int mouse_y)
     // ^C
     // ^C
     case char(3):
     case char(3):
       exit(0);
       exit(0);
+    case 'I':
+    case 'i':
+      {
+        push_undo();
+        s.N *= -1.0;
+        break;
+      }
     case 'z':
     case 'z':
     case 'Z':
     case 'Z':
       if(mod & GLUT_ACTIVE_COMMAND)
       if(mod & GLUT_ACTIVE_COMMAND)

+ 1 - 1
examples/patches/temp.rbr

@@ -1,3 +1,3 @@
-camera_rotation: TW_TYPE_QUAT4D -0.118843 -0.81634 -0.535375 -0.181213
+camera_rotation: TW_TYPE_QUAT4D -0.305599 -0.502294 -0.195568 -0.784897
 rotation_type: RotationType two axis fixed up
 rotation_type: RotationType two axis fixed up
 
 

+ 4 - 3
include/igl/boost/manifold_patches.cpp

@@ -18,12 +18,13 @@ void igl::manifold_patches(
 
 
   // List of all "half"-edges: 3*#F by 2
   // List of all "half"-edges: 3*#F by 2
   Matrix<typename DerivedF::Scalar, Dynamic, 2> allE,sortallE,uE;
   Matrix<typename DerivedF::Scalar, Dynamic, 2> allE,sortallE,uE;
+  allE.resize(F.rows()*3,2);
   VectorXi IC,_;
   VectorXi IC,_;
-  allE.block(0*F.rows(),0,F.rows(),0) = F.col(1);
+  allE.block(0*F.rows(),0,F.rows(),1) = F.col(1);
   allE.block(0*F.rows(),0,F.rows(),1) = F.col(2);
   allE.block(0*F.rows(),0,F.rows(),1) = F.col(2);
-  allE.block(1*F.rows(),0,F.rows(),0) = F.col(2);
+  allE.block(1*F.rows(),0,F.rows(),1) = F.col(2);
   allE.block(1*F.rows(),0,F.rows(),1) = F.col(0);
   allE.block(1*F.rows(),0,F.rows(),1) = F.col(0);
-  allE.block(2*F.rows(),0,F.rows(),0) = F.col(0);
+  allE.block(2*F.rows(),0,F.rows(),1) = F.col(0);
   allE.block(2*F.rows(),0,F.rows(),1) = F.col(1);
   allE.block(2*F.rows(),0,F.rows(),1) = F.col(1);
   // Sort each row
   // Sort each row
   sort(allE,2,true,sortallE,_);
   sort(allE,2,true,sortallE,_);

+ 27 - 0
include/igl/randperm.cpp

@@ -0,0 +1,27 @@
+#include "randperm.h"
+#include "colon.h"
+#include <algorithm> 
+
+template <typename DerivedI>
+IGL_INLINE void igl::randperm(
+  const int n,
+  Eigen::PlainObjectBase<DerivedI> & I)
+{
+  Eigen::VectorXi II;
+  igl::colon(0,1,n-1,II);
+  I = II;
+  std::random_shuffle(I.data(),I.data()+n);
+}
+
+template <typename DerivedI>
+IGL_INLINE Eigen::PlainObjectBase<DerivedI> igl::randperm( const int n)
+{
+  Eigen::PlainObjectBase<DerivedI> I;
+  randperm(n,I);
+  return I;
+}
+
+#ifndef IGL_HEADER_ONLY
+// Explicit template specialization
+template void igl::randperm<Eigen::Matrix<int, -1, 1, 0, -1, 1> >(int, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+#endif

+ 23 - 0
include/igl/randperm.h

@@ -0,0 +1,23 @@
+#ifndef IGL_RANDPERM_H
+#define IGL_RANDPERM_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+namespace igl
+{
+  // Like matlab's randperm(n) but minus 1
+  //
+  // Inputs:
+  //   n  number of elements
+  // Outputs:
+  //   I  n list of rand permutation of 0:n-1
+  template <typename DerivedI>
+  IGL_INLINE void randperm(
+    const int n,
+    Eigen::PlainObjectBase<DerivedI> & I);
+  template <typename DerivedI>
+  IGL_INLINE Eigen::PlainObjectBase<DerivedI> randperm( const int n);
+}
+#ifdef IGL_HEADER_ONLY
+#  include "randperm.cpp"
+#endif
+#endif

+ 1 - 0
include/igl/sort.cpp

@@ -216,4 +216,5 @@ template void igl::sort2<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix
 template void igl::sort_new<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&, int, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::sort_new<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&, int, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::sort<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&, int, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::sort<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&, int, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::sort<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, int, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::sort<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, int, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::sort<Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> > const&, int, bool, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 #endif
 #endif

+ 1 - 0
include/igl/sortrows.cpp

@@ -79,4 +79,5 @@ template void igl::sortrows<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Mat
 template void igl::sortrows<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&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::sortrows<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&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::sortrows<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::sortrows<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::sortrows<Eigen::Matrix<double, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::sortrows<Eigen::Matrix<double, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::sortrows<Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 #endif
 #endif

+ 1 - 0
include/igl/unique.cpp

@@ -194,4 +194,5 @@ template void igl::unique_rows<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Mat
 template void igl::unique_rows<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::unique_rows<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
 template void igl::unique_rows<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::unique_rows<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::unique_rows<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 template void igl::unique_rows<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
+template void igl::unique_rows<Eigen::Matrix<int, -1, 2, 0, -1, 2>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 2, 0, -1, 2> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
 #endif
 #endif