소스 검색

project/unproject wrappers, 2d point in circle test and eigen affine matrix example

Former-commit-id: df6ec07d10150d281476bb5c91b13799678b38ae
jalec 13 년 전
부모
커밋
b7e523aec7
7개의 변경된 파일193개의 추가작업 그리고 2개의 파일을 삭제
  1. 23 0
      examples/affine/Makefile
  2. 8 0
      examples/affine/README
  3. 33 0
      examples/affine/example.cpp
  4. 33 0
      point_in_circle.h
  5. 48 0
      project.h
  6. 0 2
      readDMAT.h
  7. 48 0
      unproject.h

+ 23 - 0
examples/affine/Makefile

@@ -0,0 +1,23 @@
+
+.PHONY: all
+
+all: example
+
+.PHONY: example
+
+igl_lib=../../
+eigen=/usr/local/include/eigen3
+
+CFLAGS=-g
+inc=-I$(igl_lib) -I$(eigen)
+lib=
+
+example: example.o
+	g++ $(CFLAGS) -o example example.o $(lib)
+	rm example.o
+
+example.o: example.cpp
+	g++ $(CFLAGS) -c example.cpp -o example.o $(inc)
+clean:
+	rm -f example.o
+	rm -f example

+ 8 - 0
examples/affine/README

@@ -0,0 +1,8 @@
+A small program showing how .translate and .rotate affect eigen's Affine matrix class
+
+
+Compile with:
+  make
+
+Run with:
+  ./example

+ 33 - 0
examples/affine/example.cpp

@@ -0,0 +1,33 @@
+#include <Eigen/Geometry>
+#include <iostream>
+using namespace std;
+
+typedef Eigen::Transform<double,3,Eigen::Affine> Tform3;
+typedef Eigen::Vector3d Vec3;
+typedef Eigen::Quaterniond Quat;
+
+int main(int argc, char * argv[])
+{
+  Tform3 T;
+  T =Tform3::Identity();
+  cout<<"T =Tform3::Identity();"<<endl;
+  cout<<"T=["<<endl<<T.affine().matrix()<<endl<<"];"<<endl;
+  cout<<"T.translate(Vec3(1,2,3));"<<endl;
+  T.translate(Vec3(1,2,3));
+  cout<<"T=["<<endl<<T.affine().matrix()<<endl<<"];"<<endl;
+  cout<<"T.rotate(Quat(0,1,0,0));"<<endl;
+  T.rotate(Quat(0,1,0,0));
+  cout<<"T=["<<endl<<T.affine().matrix()<<endl<<"];"<<endl;
+  cout<<endl;
+
+  T =Tform3::Identity();
+  cout<<"T =Tform3::Identity();"<<endl;
+  cout<<"T=["<<endl<<T.affine().matrix()<<endl<<"];"<<endl;
+  cout<<"T.rotate(Quat(0,1,0,0));"<<endl;
+  T.rotate(Quat(0,1,0,0));
+  cout<<"T=["<<endl<<T.affine().matrix()<<endl<<"];"<<endl;
+  cout<<"T.translate(Vec3(1,2,3));"<<endl;
+  T.translate(Vec3(1,2,3));
+  cout<<"T=["<<endl<<T.affine().matrix()<<endl<<"];"<<endl;
+  cout<<endl;
+}

+ 33 - 0
point_in_circle.h

@@ -0,0 +1,33 @@
+#ifndef IGL_POINT_IN_CIRCLE
+#define IGL_POINT_IN_CIRCLE
+
+namespace igl
+{
+  // Determine if 2d point is in a circle
+  // Inputs:
+  //   qx  x-coordinate of query point
+  //   qy  y-coordinate of query point
+  //   cx  x-coordinate of circle center
+  //   cy  y-coordinate of circle center
+  //   r  radius of circle
+  // Returns true if query point is in circle, false otherwise
+  inline bool point_in_circle(
+    const double qx, 
+    const double qy,
+    const double cx, 
+    const double cy,
+    const double r);
+}
+
+// Implementation
+
+inline bool igl::point_in_circle(
+  const double qx, 
+  const double qy,
+  const double cx, 
+  const double cy,
+  const double r)
+{
+  return (qx-cx)*(qx-cx) + (qy-cy)*(qy-cy) - r*r < 0;
+}
+#endif

+ 48 - 0
project.h

@@ -0,0 +1,48 @@
+#ifndef IGL_PROJECT_H
+#define IGL_PROJECT_H
+namespace igl
+{
+  // Wrapper for gluProject that uses the current GL_MODELVIEW_MATRIX,
+  // GL_PROJECTION_MATRIX, and GL_VIEWPORT
+  // Inputs:
+  //   obj*  3D objects' x, y, and z coordinates respectively
+  // Outputs:
+  //   win*  pointers to screen space x, y, and z coordinates respectively
+  // Returns return value of gluProject call
+  inline int project(
+    const double objX,
+    const double objY,
+    const double objZ,
+    double* winX,
+    double* winY,
+    double* winZ);
+}
+
+// Implementation
+
+#ifdef __APPLE__
+# include <OpenGL/gl.h>
+# include <OpenGL/glu.h>
+#else
+# include <GL/gl.h>
+# include <GL/glu.h>
+#endif
+
+inline int igl::project(
+  const double objX,
+  const double objY,
+  const double objZ,
+  double* winX,
+  double* winY,
+  double* winZ)
+{
+  // Put model, projection, and viewport matrices into double arrays
+  double MV[16];
+  double P[16];
+  int VP[4];
+  glGetDoublev(GL_MODELVIEW_MATRIX,  MV);
+  glGetDoublev(GL_PROJECTION_MATRIX, P);
+  glGetIntegerv(GL_VIEWPORT, VP);
+  return gluProject(objX,objY,objZ,MV,P,VP,winX,winY,winZ);
+}
+#endif

+ 0 - 2
readDMAT.h

@@ -47,8 +47,6 @@ inline bool igl::readDMAT(const std::string file_name, Eigen::MatrixXd & W)
     fprintf(stderr,"IOError: readDMAT() first row should be [num cols] [num rows]...\n");
     return false;
   }
-  verbose("Number of rows: %d\n",num_rows);
-  verbose("Number of cols: %d\n",num_cols);
 
   // check that number of columns and rows are sane
   if(num_cols < 0)

+ 48 - 0
unproject.h

@@ -0,0 +1,48 @@
+#ifndef IGL_UNPROJECT_H
+#define IGL_UNPROJECT_H
+namespace igl
+{
+  // Wrapper for gluProject that uses the current GL_MODELVIEW_MATRIX,
+  // GL_PROJECTION_MATRIX, and GL_VIEWPORT
+  // Inputs:
+  //   win*  screen space x, y, and z coordinates respectively
+  // Outputs:
+  //   obj*  pointers to 3D objects' x, y, and z coordinates respectively
+  // Returns return value of gluUnProject call
+  inline int unproject(
+    const double winX,
+    const double winY,
+    const double winZ,
+    double* objX,
+    double* objY,
+    double* objZ);
+}
+
+// Implementation
+
+#ifdef __APPLE__
+# include <OpenGL/gl.h>
+# include <OpenGL/glu.h>
+#else
+# include <GL/gl.h>
+# include <GL/glu.h>
+#endif
+
+inline int igl::unproject(
+  const double winX,
+  const double winY,
+  const double winZ,
+  double* objX,
+  double* objY,
+  double* objZ)
+{
+  // Put model, projection, and viewport matrices into double arrays
+  double MV[16];
+  double P[16];
+  int VP[4];
+  glGetDoublev(GL_MODELVIEW_MATRIX,  MV);
+  glGetDoublev(GL_PROJECTION_MATRIX, P);
+  glGetIntegerv(GL_VIEWPORT, VP);
+  return gluUnProject(winX,winY,winZ,MV,P,VP,objX,objY,objZ);
+}
+#endif