Explorar el Código

merge

Former-commit-id: 2ac43d5d72d118aa4c03c5039bf0f7af89ba63c9
Kenshi Takayama (kenshi hace 11 años
padre
commit
78b20d9593

+ 36 - 15
examples/patches/example.cpp

@@ -25,7 +25,6 @@
 #include <igl/jet.h>
 #include <igl/randperm.h>
 #include <igl/normalize_row_lengths.h>
-#include <igl/boost/manifold_patches.h>
 #include <igl/boost/components.h>
 #include <igl/boost/bfs_orient.h>
 #include <igl/orient_outward.h>
@@ -47,20 +46,23 @@
 #define GLUT_ACTIVE_COMMAND 1
 #endif
 
+#include <ctime>
 #include <string>
 #include <vector>
 #include <stack>
 #include <iostream>
 
 
-Eigen::MatrixXd V,C;
+Eigen::MatrixXd V;
 Eigen::VectorXd Vmid,Vmin,Vmax;
 double bbd = 1.0;
 Eigen::MatrixXi F;
+Eigen::VectorXi CC;
 struct State
 {
   igl::Camera camera;
   Eigen::MatrixXd N;
+  Eigen::MatrixXd C;
 } s;
 
 // See README for descriptions
@@ -293,7 +295,7 @@ void display()
       draw_mesh(V,F,s.N);
     }else
     {
-      draw_mesh(V,F,s.N,C);
+      draw_mesh(V,F,s.N,s.C);
     }
   }
   glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
@@ -301,7 +303,7 @@ void display()
   {
     glEnable(GL_POLYGON_OFFSET_FILL); // Avoid Stitching!
     glPolygonOffset(1.0, 0);
-    draw_mesh(V,F,s.N,C);
+    draw_mesh(V,F,s.N,s.C);
   }
 
   pop_object();
@@ -328,7 +330,6 @@ void display()
 void mouse_wheel(int wheel, int direction, int mouse_x, int mouse_y)
 {
   using namespace std;
-  push_undo();
   if(wheel == 0)
   {
     static double mouse_scroll_y = 0;
@@ -496,23 +497,18 @@ void init_relative()
   bbd = (Vmax-Vmin).norm();
 }
 
-void init_patches()
+void randomly_color(
+  const Eigen::VectorXi & CC,
+  Eigen::MatrixXd & C)
 {
   using namespace Eigen;
   using namespace igl;
   using namespace std;
-  VectorXi CC;
-  SparseMatrix<int> A;
-  components(F,CC);
-  cout<<"There are "<<CC.maxCoeff()+1<<" connected components."<<endl;
-  //manifold_patches(F,CC,A);
-  bfs_orient(F,F,CC);
   VectorXi I;
-  orient_outward(V,F,CC,F,I);
-  C.resize(CC.rows(),3);
+  srand ( unsigned ( time(0) ) );
   double num_cc = (double)CC.maxCoeff()+1.0;
-  cout<<"There are "<<num_cc<<" 'manifold/orientable' patches."<<endl;
   randperm(num_cc,I);
+  C.resize(CC.rows(),3);
   for(int f = 0;f<CC.rows();f++)
   {
     jet(
@@ -523,6 +519,30 @@ void init_patches()
   }
 }
 
+void randomize_colors(void * /*clientData*/)
+{
+  push_undo();
+  randomly_color(CC,s.C);
+}
+
+void init_patches()
+{
+  using namespace Eigen;
+  using namespace igl;
+  using namespace std;
+  {
+    VectorXi VCC;
+    components(F,VCC);
+    cout<<"There are "<<VCC.maxCoeff()+1<<" connected components of vertices."<<endl;
+  }
+  bfs_orient(F,F,CC);
+  VectorXi I;
+  orient_outward(V,F,CC,F,I);
+  double num_cc = (double)CC.maxCoeff()+1.0;
+  cout<<"There are "<<num_cc<<" 'manifold/orientable' patches of faces."<<endl;
+  randomly_color(CC,s.C);
+}
+
 void undo()
 {
   using namespace std;
@@ -696,6 +716,7 @@ int main(int argc, char * argv[])
     set_rotation_type,get_rotation_type,NULL,"keyIncr=] keyDecr=[");
   rebar.TwAddVarRW("wireframe_visible",TW_TYPE_BOOLCPP,&wireframe_visible,"key=l");
   rebar.TwAddVarRW("fill_visible",TW_TYPE_BOOLCPP,&fill_visible,"key=f");
+  rebar.TwAddButton("randomize colors",randomize_colors,NULL,"key=c");
   rebar.load(REBAR_NAME);
 
 

+ 2 - 2
examples/patches/temp.rbr

@@ -1,5 +1,5 @@
-wireframe_visible: TW_TYPE_BOOLCPP 1
+wireframe_visible: TW_TYPE_BOOLCPP 0
 fill_visible: TW_TYPE_BOOLCPP 1
-camera_rotation: TW_TYPE_QUAT4D 0.0504783 -0.948499 -0.242586 0.197368
+camera_rotation: TW_TYPE_QUAT4D 0.0952898 0.224325 0.0220463 0.969594
 rotation_type: RotationType two axis fixed up
 

+ 1 - 0
include/igl/boost/bfs_orient.cpp

@@ -29,6 +29,7 @@ void igl::bfs_orient(
     FF = F;
   }
   // loop over patches
+#pragma omp parallel for
   for(int c = 0;c<num_cc;c++)
   {
     queue<int> Q;

+ 5 - 2
include/igl/boost/components.cpp

@@ -1,7 +1,8 @@
 #include "components.h"
 #include <igl/adjacency_matrix.h>
 
-#include <boost/graph/adjacency_matrix.hpp>
+//#include <boost/graph/adjacency_matrix.hpp>
+#include <boost/graph/adjacency_list.hpp>
 #include <boost/graph/connected_components.hpp>
 #include <iostream>
 #include <vector>
@@ -14,7 +15,9 @@ IGL_INLINE void igl::components(
 {
   assert(A.rows() == A.cols());
   using namespace Eigen;
-  boost::adjacency_matrix<boost::undirectedS> bA(A.rows());
+  // THIS IS DENSE:
+  //boost::adjacency_matrix<boost::undirectedS> bA(A.rows());
+  boost::adjacency_list<boost::vecS,boost::vecS,boost::undirectedS> bA(A.rows());
   for(int j=0; j<A.outerSize();j++)
   {
     // Iterate over inside

+ 1 - 1
include/igl/orient_outward.cpp

@@ -46,7 +46,7 @@ IGL_INLINE void igl::orient_outward(
   for(int f = 0;f<m;f++)
   {
     BCmean.row(C(f)) += A(f)*BC.row(f);
-    totA(C(f))++;
+    totA(C(f))+=A(f);
   }
   // take area weighted average
   for(int c = 0;c<num_cc;c++)