Explorar o código

better select example in matlab2eigen, better const in RotateWidget

Former-commit-id: c49da4a8e5fd3b93e6ea419b2d367806a24e1283
Alec Jacobson (jalec %!s(int64=11) %!d(string=hai) anos
pai
achega
85fd62a94b

+ 2 - 1
examples/rotate-widget/example.cpp

@@ -614,7 +614,8 @@ int main(int argc, char * argv[])
   glutMouseFunc(mouse);
   glutMotionFunc(mouse_drag);
   glutPassiveMotionFunc(
-    [](int x, int y){
+    [](int x, int y)
+    {
       TwEventMouseMotionGLUT(x,y);
       glutPostRedisplay();
     });

+ 9 - 0
include/igl/ReAntTweakBar.h

@@ -44,6 +44,15 @@
 #else
 #  include <AntTweakBar.h>
 #endif
+// Instead of including AntTweakBar.h, just define the necessary types
+// Types used:
+//   - TwType
+//   - TwEnumVal
+//   - TwSetVarCallback
+//   - TwGetVarCallback
+//   - TwBar
+//   - TwButtonCallback
+
 
 #include <vector>
 #include <string>

+ 44 - 38
include/igl/RotateWidget.h

@@ -47,7 +47,7 @@ namespace igl
       //   x  mouse x position
       //   y  mouse y position
       // Returns vector
-      inline Eigen::Vector3d unproject_onto(const int x, const int y);
+      inline Eigen::Vector3d unproject_onto(const int x, const int y) const;
       // Shoot ray from mouse click to sphere
       //
       // Inputs:
@@ -56,14 +56,17 @@ namespace igl
       // Outputs:
       //   hit  position of hit
       // Returns true only if there was a hit
-      inline bool intersect(const int x, const int y, Eigen::Vector3d & hit);
-      inline double unprojected_inner_radius();
+      inline bool intersect(
+        const int x, 
+        const int y, 
+        Eigen::Vector3d & hit) const;
+      inline double unprojected_inner_radius() const;
       inline bool down(const int x, const int y);
       inline bool drag(const int x, const int y);
       inline bool up(const int x, const int y);
-      inline bool is_down();
-      inline void draw();
-      inline void draw_guide();
+      inline bool is_down() const;
+      inline void draw() const;
+      inline void draw_guide() const;
   };
 }
 
@@ -119,37 +122,9 @@ inline igl::RotateWidget::RotateWidget():
 {
 }
 
-inline bool igl::RotateWidget::intersect(const int x, const int y, Eigen::Vector3d & hit)
-{
-  using namespace Eigen;
-  using namespace igl;
-  Vector3d view = view_direction(x,y);
-  const Vector3d ppos = project(pos);
-  Vector3d uxy = unproject(Vector3d(x,y,ppos(2)));
-  double t0,t1;
-  if(!ray_sphere_intersect(uxy,view,pos,unprojected_inner_radius(),t0,t1))
-  {
-    return false;
-  }
-  hit = uxy+t0*view;
-  return true;
-}
-
-inline double igl::RotateWidget::unprojected_inner_radius()
-{
-  using namespace Eigen;
-  using namespace igl;
-  Vector3d off,ppos,ppos_off,pos_off;
-  project(pos,ppos);
-  ppos_off = ppos;
-  ppos_off(0) += outer_radius_on_screen/outer_over_inner;
-  unproject(ppos_off,pos_off);
-  return (pos-pos_off).norm();
-}
-
 inline Eigen::Vector3d igl::RotateWidget::unproject_onto(
   const int x, 
-  const int y)
+  const int y) const
 {
   using namespace Eigen;
   using namespace igl;
@@ -174,6 +149,37 @@ inline Eigen::Vector3d igl::RotateWidget::unproject_onto(
   return (uxy-pos)/unprojected_inner_radius()*outer_over_inner*outer_over_inner;
 }
 
+inline bool igl::RotateWidget::intersect(
+  const int x, 
+  const int y,
+  Eigen::Vector3d & hit) const
+{
+  using namespace Eigen;
+  using namespace igl;
+  Vector3d view = view_direction(x,y);
+  const Vector3d ppos = project(pos);
+  Vector3d uxy = unproject(Vector3d(x,y,ppos(2)));
+  double t0,t1;
+  if(!ray_sphere_intersect(uxy,view,pos,unprojected_inner_radius(),t0,t1))
+  {
+    return false;
+  }
+  hit = uxy+t0*view;
+  return true;
+}
+
+
+inline double igl::RotateWidget::unprojected_inner_radius() const
+{
+  using namespace Eigen;
+  using namespace igl;
+  Vector3d off,ppos,ppos_off,pos_off;
+  project(pos,ppos);
+  ppos_off = ppos;
+  ppos_off(0) += outer_radius_on_screen/outer_over_inner;
+  unproject(ppos_off,pos_off);
+  return (pos-pos_off).norm();
+}
 inline bool igl::RotateWidget::down(const int x, const int y)
 {
   using namespace Eigen;
@@ -330,12 +336,12 @@ inline bool igl::RotateWidget::up(const int /*x*/, const int /*y*/)
   return false;
 }
 
-inline bool igl::RotateWidget::is_down()
+inline bool igl::RotateWidget::is_down() const
 {
   return down_type != DOWN_TYPE_NONE;
 }
 
-inline void igl::RotateWidget::draw()
+inline void igl::RotateWidget::draw() const
 {
   using namespace Eigen;
   using namespace std;
@@ -436,7 +442,7 @@ inline void igl::RotateWidget::draw()
   (dt ? glEnable(GL_DEPTH_TEST):glDisable(GL_DEPTH_TEST));
 };
 
-inline void igl::RotateWidget::draw_guide()
+inline void igl::RotateWidget::draw_guide() const
 {
   using namespace Eigen;
   using namespace std;

+ 1 - 1
matlab-to-eigen.html

@@ -111,7 +111,7 @@
 
       <tr class=d1>
         <td><pre><code>A(B == 0) = C(B==0)</code></pre></td>
-        <td><pre><code>A = (B == 0).select(C,A)</code></pre></td>
+        <td><pre><code>A = (B.array() == 0).select(C,A)</code></pre></td>
         <td></td>
       </tr>