Browse Source

add line seg inside and draw rect, use aligned alloc for quat in vector, better ignore

Former-commit-id: 7920964c88d7484fade82c30b5db08d9a5f4821a
Alec Jacobson 11 years ago
parent
commit
e57d75c473

+ 6 - 0
.gitignore

@@ -49,3 +49,9 @@ examples/bbw/examples/*-volume.dmat
 examples/bbw/examples/*-volume.mesh
 examples/upright/upright
 examples/principal_curvature/curvature
+external/MeshFix/meshfix
+external/embree/build/*
+external/tetgen/tetgen
+external/tinyxml2/test
+external/tinyxml2/tinyxml2.pc
+external/yimg/showpng

+ 3 - 2
include/igl/dqs.cpp

@@ -4,12 +4,13 @@ template <
   typename DerivedV,
   typename DerivedW,
   typename Q,
+  typename QAlloc,
   typename T,
   typename DerivedU>
 IGL_INLINE void igl::dqs(
   const Eigen::PlainObjectBase<DerivedV> & V,
   const Eigen::PlainObjectBase<DerivedW> & W,
-  const std::vector<Q> & vQ,
+  const std::vector<Q,QAlloc> & vQ,
   const std::vector<T> & vT,
   Eigen::PlainObjectBase<DerivedU> & U)
 {
@@ -63,5 +64,5 @@ IGL_INLINE void igl::dqs(
 
 #ifndef IGL_HEADER_ONLY
 // Explicit template instanciation
-template void igl::dqs<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Quaternion<double, 0>, Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, -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> > const&, std::vector<Eigen::Quaternion<double, 0>, std::allocator<Eigen::Quaternion<double, 0> > > const&, std::vector<Eigen::Matrix<double, 3, 1, 0, 3, 1>, std::allocator<Eigen::Matrix<double, 3, 1, 0, 3, 1> > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
+template void igl::dqs<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Quaternion<double, 0>, Eigen::aligned_allocator<Eigen::Quaternion<double, 0> >, Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, -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> > const&, std::vector<Eigen::Quaternion<double, 0>, Eigen::aligned_allocator<Eigen::Quaternion<double, 0> > > const&, std::vector<Eigen::Matrix<double, 3, 1, 0, 3, 1>, std::allocator<Eigen::Matrix<double, 3, 1, 0, 3, 1> > > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
 #endif

+ 2 - 1
include/igl/dqs.h

@@ -18,12 +18,13 @@ namespace igl
     typename DerivedV,
     typename DerivedW,
     typename Q,
+    typename QAlloc,
     typename T,
     typename DerivedU>
   IGL_INLINE void dqs(
     const Eigen::PlainObjectBase<DerivedV> & V,
     const Eigen::PlainObjectBase<DerivedW> & W,
-    const std::vector<Q> & vQ,
+    const std::vector<Q,QAlloc> & vQ,
     const std::vector<T> & vT,
     Eigen::PlainObjectBase<DerivedU> & U);
 };

+ 52 - 0
include/igl/draw_rectangular_marquee.cpp

@@ -0,0 +1,52 @@
+#include "draw_rectangular_marquee.h"
+#include "OpenGL_convenience.h"
+#include "material_colors.h"
+
+void igl::draw_rectangular_marquee(
+  const int from_x,
+  const int from_y,
+  const int to_x,
+  const int to_y)
+{
+  using namespace igl;
+  using namespace std;
+  int l;
+  glGetIntegerv(GL_LIGHTING,&l);
+  int s;
+  glGetIntegerv(GL_LINE_STIPPLE,&s);
+  double lw;
+  glGetDoublev(GL_LINE_WIDTH,&lw);
+  glDisable(GL_LIGHTING);
+  // Screen space for this viewport
+  GLint viewport[4];
+  glGetIntegerv(GL_VIEWPORT,viewport);
+  const int width = viewport[2];
+  const int height = viewport[3];
+  glMatrixMode(GL_PROJECTION);
+  glPushMatrix();
+  glLoadIdentity();
+  gluOrtho2D(0,width,0,height);
+  glMatrixMode(GL_MODELVIEW);
+  glPushMatrix();
+  glLoadIdentity();
+
+  glEnable(GL_LINE_STIPPLE);
+  glLineStipple(3,0xAAAA);
+  glLineWidth(1);
+  glColor4f(0.2,0.2,0.2,1);
+  glBegin(GL_LINE_STRIP);
+  glVertex2d(from_x,from_y);
+  glVertex2d(to_x,from_y);
+  glVertex2d(to_x,to_y);
+  glVertex2d(from_x,to_y);
+  glVertex2d(from_x,from_y);
+  glEnd();
+
+  glPopMatrix();
+  glMatrixMode(GL_PROJECTION);
+  glPopMatrix();
+  glMatrixMode(GL_MODELVIEW);
+  glLineWidth(lw);
+  (s ? glEnable(GL_LINE_STIPPLE):glDisable(GL_LINE_STIPPLE));
+  (l ? glEnable(GL_LIGHTING):glDisable(GL_LIGHTING));
+}

+ 24 - 0
include/igl/draw_rectangular_marquee.h

@@ -0,0 +1,24 @@
+#ifndef IGL_DRAW_RECTANGULAR_MARQUEE_H
+#define IGL_DRAW_RECTANGULAR_MARQUEE_H
+namespace igl
+{
+  // Draw a rectangular marquee (selection box) in screen space. This sets up
+  // screen space using current viewport.
+  //
+  // Inputs:
+  //   from_x  x coordinate of from point
+  //   from_y  y coordinate of from point
+  //   to_x  x coordinate of to point
+  //   to_y  y coordinate of to point
+  void draw_rectangular_marquee(
+    const int from_x,
+    const int from_y,
+    const int to_x,
+    const int to_y);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "draw_rectangular_marquee.cpp"
+#endif
+
+#endif

+ 4 - 2
include/igl/forward_kinematics.cpp

@@ -12,8 +12,10 @@ void igl::forward_kinematics(
   const Eigen::MatrixXd & C,
   const Eigen::MatrixXi & BE,
   const Eigen::VectorXi & P,
-  const std::vector<Eigen::Quaterniond> & dQ,
-  std::vector<Eigen::Quaterniond> & vQ,
+  const std::vector<
+    Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > & dQ,
+  std::vector<
+    Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > & vQ,
   std::vector<Eigen::Vector3d> & vT)
 {
   using namespace std;

+ 5 - 2
include/igl/forward_kinematics.h

@@ -9,6 +9,7 @@
 #define IGL_FORWARD_KINEMATICS_H
 #include <Eigen/Core>
 #include <Eigen/Geometry>
+#include <Eigen/StdVector>
 #include <vector>
 
 namespace igl
@@ -28,8 +29,10 @@ namespace igl
     const Eigen::MatrixXd & C,
     const Eigen::MatrixXi & BE,
     const Eigen::VectorXi & P,
-    const std::vector<Eigen::Quaterniond> & dQ,
-    std::vector<Eigen::Quaterniond> & vQ,
+    const std::vector<
+      Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > & dQ,
+    std::vector<
+      Eigen::Quaterniond,Eigen::aligned_allocator<Eigen::Quaterniond> > & vQ,
     std::vector<Eigen::Vector3d> & vT);
 };
 

+ 97 - 0
include/igl/line_segment_in_rectangle.cpp

@@ -0,0 +1,97 @@
+#include "line_segment_in_rectangle.h"
+
+bool igl::line_segment_in_rectangle(
+  const Eigen::Vector2d & s,
+  const Eigen::Vector2d & d,
+  const Eigen::Vector2d & A,
+  const Eigen::Vector2d & B)
+{
+  using namespace std;
+  using namespace Eigen;
+  using namespace igl;
+  // http://stackoverflow.com/a/100165/148668
+  const auto SegmentIntersectRectangle = [](double a_rectangleMinX,
+                                 double a_rectangleMinY,
+                                 double a_rectangleMaxX,
+                                 double a_rectangleMaxY,
+                                 double a_p1x,
+                                 double a_p1y,
+                                 double a_p2x,
+                                 double a_p2y)->bool
+  {
+    // Find min and max X for the segment
+
+    double minX = a_p1x;
+    double maxX = a_p2x;
+
+    if(a_p1x > a_p2x)
+    {
+      minX = a_p2x;
+      maxX = a_p1x;
+    }
+
+    // Find the intersection of the segment's and rectangle's x-projections
+
+    if(maxX > a_rectangleMaxX)
+    {
+      maxX = a_rectangleMaxX;
+    }
+
+    if(minX < a_rectangleMinX)
+    {
+      minX = a_rectangleMinX;
+    }
+
+    if(minX > maxX) // If their projections do not intersect return false
+    {
+      return false;
+    }
+
+    // Find corresponding min and max Y for min and max X we found before
+
+    double minY = a_p1y;
+    double maxY = a_p2y;
+
+    double dx = a_p2x - a_p1x;
+
+    if(fabs(dx) > 0.0000001)
+    {
+      double a = (a_p2y - a_p1y) / dx;
+      double b = a_p1y - a * a_p1x;
+      minY = a * minX + b;
+      maxY = a * maxX + b;
+    }
+
+    if(minY > maxY)
+    {
+      double tmp = maxY;
+      maxY = minY;
+      minY = tmp;
+    }
+
+    // Find the intersection of the segment's and rectangle's y-projections
+
+    if(maxY > a_rectangleMaxY)
+    {
+      maxY = a_rectangleMaxY;
+    }
+
+    if(minY < a_rectangleMinY)
+    {
+      minY = a_rectangleMinY;
+    }
+
+    if(minY > maxY) // If Y-projections do not intersect return false
+    {
+      return false;
+    }
+
+    return true;
+  };
+  const double minX = min(A(0),B(0));
+  const double minY = min(A(1),B(1));
+  const double maxX = max(A(0),B(0));
+  const double maxY = max(A(1),B(1));
+  bool ret = SegmentIntersectRectangle(minX,minY,maxX,maxY,s(0),s(1),d(0),d(1));
+  return ret;
+}

+ 25 - 0
include/igl/line_segment_in_rectangle.h

@@ -0,0 +1,25 @@
+#ifndef IGL_LINE_SEGMENT_IN_RECTANGLE_H
+#define IGL_LINE_SEGMENT_IN_RECTANGLE_H
+#include <Eigen/Core>
+namespace igl
+{
+  // Determine whether a line segment overlaps with a rectangle.
+  //
+  // Inputs:
+  //   s  source point of line segment
+  //   d  dest point of line segment
+  //   A  first corner of rectangle
+  //   B  opposite corner of rectangle
+  // Returns true if line segment is at all inside rectangle
+  bool line_segment_in_rectangle(
+    const Eigen::Vector2d & s,
+    const Eigen::Vector2d & d,
+    const Eigen::Vector2d & A,
+    const Eigen::Vector2d & B);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "line_segment_in_rectangle.cpp"
+#endif
+
+#endif