Browse Source

replaced cin with twaddvarcb

Former-commit-id: 7a24f71dee25c33eb71f2c00b3f6dffc068aa5de
Alec Jacobson (jalec 11 năm trước cách đây
mục cha
commit
3ce7b49bb6
2 tập tin đã thay đổi với 54 bổ sung12 xóa
  1. 52 11
      examples/patches/example.cpp
  2. 2 1
      examples/patches/temp.rbr

+ 52 - 11
examples/patches/example.cpp

@@ -75,6 +75,13 @@ enum RotationType
   NUM_ROTATION_TYPES = 2,
 } rotation_type;
 
+enum OrientMethod
+{
+  ORIENT_METHOD_OUTWARD = 0,
+  ORIENT_METHOD_AO = 1,
+  NUM_ORIENT_METHODS = 2,
+} orient_method = ORIENT_METHOD_AO;
+
 std::stack<State> undo_stack;
 std::stack<State> redo_stack;
 
@@ -97,6 +104,10 @@ Eigen::Vector4f light_pos(-0.1,-0.1,0.9,0);
 #define REBAR_NAME "temp.rbr"
 igl::ReTwBar rebar;
 
+// Forward
+void init_patches();
+void init_relative();
+
 void push_undo()
 {
   undo_stack.push(s);
@@ -112,6 +123,23 @@ void TW_CALL set_camera_rotation(const void * value, void *clientData)
   std::copy(quat,quat+4,s.camera.rotation);
 }
 
+void TW_CALL set_orient_method(const void * value, void * clientData)
+{
+  const OrientMethod old_orient_method = orient_method;
+  orient_method = *(const OrientMethod *)value;
+  if(orient_method != old_orient_method)
+  {
+    init_patches();
+    init_relative();
+  }
+}
+
+void TW_CALL get_orient_method(void * value, void *clientData)
+{
+  OrientMethod * om = (OrientMethod *)(value);
+  *om = orient_method;
+}
+
 void TW_CALL set_rotation_type(const void * value, void * clientData)
 {
   using namespace Eigen;
@@ -539,20 +567,20 @@ void init_patches()
   }
   bfs_orient(F,F,CC);
   VectorXi I;
-  char c;
-  cout << "use ambient occlusion to determine patch orientation? (y/n):";
-  cin >> c;
-  if (c == 'y')
-  {
-    orient_outward_ao(V,F,CC,F.rows() * 100,F,I);
-  }
-  else
+  switch(orient_method)
   {
-    orient_outward(V,F,CC,F,I);
+    case ORIENT_METHOD_AO:
+      cout<<"orient_outward_ao()"<<endl;
+      orient_outward_ao(V,F,CC,F.rows() * 100,F,I);
+      break;
+    case ORIENT_METHOD_OUTWARD:
+    default:
+      cout<<"orient_outward()"<<endl;
+      orient_outward(V,F,CC,F,I);
+      break;
   }
   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()
@@ -703,8 +731,8 @@ int main(int argc, char * argv[])
   F = F_unique;
 
   init_patches();
-
   init_relative();
+  randomly_color(CC,s.C);
 
   // Init glut
   glutInit(&argc,argv);
@@ -729,6 +757,19 @@ int main(int argc, char * argv[])
         NUM_ROTATION_TYPES);
   rebar.TwAddVarCB( "rotation_type", RotationTypeTW,
     set_rotation_type,get_rotation_type,NULL,"keyIncr=] keyDecr=[");
+  TwEnumVal OrientMethodEV[NUM_ORIENT_METHODS] = 
+  {
+    {ORIENT_METHOD_OUTWARD,"outward"},
+    {ORIENT_METHOD_AO,"ambient occlusion"}
+  };
+  TwType OrientMethodTW = 
+    ReTwDefineEnum(
+        "OrientMethod", 
+        OrientMethodEV, 
+        NUM_ROTATION_TYPES);
+  rebar.TwAddVarCB( "orient_method", OrientMethodTW,
+    set_orient_method,get_orient_method,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");

+ 2 - 1
examples/patches/temp.rbr

@@ -1,5 +1,6 @@
 wireframe_visible: TW_TYPE_BOOLCPP 1
 fill_visible: TW_TYPE_BOOLCPP 1
-camera_rotation: TW_TYPE_QUAT4D 0.20801 0.244181 0.0537125 0.945633
+camera_rotation: TW_TYPE_QUAT4D 0.0807446 0.213478 0.0177076 0.973444
 rotation_type: RotationType two axis fixed up
+orient_method: OrientMethod ambient occlusion