Quellcode durchsuchen

merge

Former-commit-id: a58f1c53335db2cff806a266f9e9f71421e20415
Daniele Panozzo vor 13 Jahren
Ursprung
Commit
239d7e9456

+ 11 - 0
.hgignore

@@ -0,0 +1,11 @@
+# use glob syntax.
+syntax: glob
+*.o
+*.a
+*~
+example
+example_static
+example_header_only
+example1
+external/yimg/.git*
+.DS_Store

+ 5 - 0
Makefile

@@ -23,6 +23,10 @@ ifeq ($(IGL_WITH_MOSEK),1)
 	# append mosek extra dir
 	EXTRA_DIRS+=include/igl/mosek
 endif
+ifeq ($(IGL_WITH_PNG),1)
+	# append mosek extra dir
+	EXTRA_DIRS+=include/igl/png
+endif
 
 .PHONY: examples
 .PHONY: extras
@@ -68,6 +72,7 @@ obj:
 	mkdir -p obj
 
 lib/libigl.a: $(OBJ_FILES)
+	mkdir -p lib
 	rm -f $@
 	ar cqs $@ $(OBJ_FILES)
 

+ 2 - 1
Makefile.conf

@@ -25,9 +25,10 @@ ifeq ($(IGL_USERNAME),ajx)
 	IGL_WITH_TETGEN=1
 	IGL_WITH_MATLAB=1
 	IGL_WITH_MOSEK=1
+	IGL_WITH_PNG=1
 endif
 
-ifeq ($(IGL_USERNAME),jalec)
+ifeq ($(IGL_USERNAME),jalec_linux) 
 	MOSEKPLATFORM=linux64x86
 	IGL_WITH_TETGEN=1
 	IGL_WITH_MATLAB=0

+ 30 - 0
include/igl/Camera.cpp

@@ -0,0 +1,30 @@
+#include "Camera.h"
+#include <igl/canonical_quaternions.h>
+#include <algorithm>
+
+igl::Camera::Camera()
+{
+  using namespace igl;
+  using namespace std;
+  // Defaults
+  // canonical (X,Y) view
+  copy(XY_PLANE_QUAT_D,XY_PLANE_QUAT_D+4,rotation);
+  zoom = 1.0;
+  angle = 45;
+  pan[0] = 0.0;
+  pan[1] = 0.0;
+  pan[2] = 0.0;
+}
+
+igl::Camera::Camera(const Camera & that)
+{
+  pan[0] = that.pan[0];
+  pan[1] = that.pan[1];
+  pan[2] = that.pan[2];
+  for(int i = 0; i<4; i++)
+  {
+    rotation[i] = that.rotation[i];
+  }
+  zoom = that.zoom;
+  angle = that.angle;
+}

+ 36 - 0
include/igl/Camera.h

@@ -0,0 +1,36 @@
+#ifndef IGL_CAMERA_H
+#define IGL_CAMERA_H
+#include "igl_inline.h"
+
+// Simple Camera class
+namespace igl
+{
+  class Camera
+  {
+    // Public Fields
+    public:
+      // Rotation as quaternion (0,0,0,1) is identity
+      double rotation[4];
+      // Translation of origin
+      double pan[3];
+      // Zoom scale
+      double zoom;
+      // Perspective angle
+      double angle;
+    // Public functions
+    public:
+      Camera();
+      // Copy constructor
+      // 
+      // Inputs:
+      //   that  other Camera to be copied
+      Camera(const Camera & that);
+      ~Camera(){}
+  };
+};
+
+#ifdef IGL_HEADER_ONLY
+#  include "Camera.cpp"
+#endif
+
+#endif

+ 34 - 0
include/igl/ReAntTweakBar.cpp

@@ -266,6 +266,15 @@ std::string igl::ReTwBar::get_value_as_string(
         sstr << *(static_cast<bool*>(var));
         break;
       }
+    case TW_TYPE_QUAT4D:
+      {
+        sstr << "TW_TYPE_QUAT4D" << " ";
+        // Q: Why does casting to double* work? shouldn't I have to cast to
+        // double**?
+        double * q = static_cast<double*>(var);
+        sstr << q[0] << " " << q[1] << " " << q[2] << " " << q[3];
+        break;
+      }
     case TW_TYPE_QUAT4F:
       {
         sstr << "TW_TYPE_QUAT4F" << " ";
@@ -453,6 +462,7 @@ bool igl::ReTwBar::set_value_from_string(
   float v;
   double dv;
   float f[4];
+  double d[4];
   bool b;
 
   // First try to get value from default types
@@ -472,6 +482,19 @@ bool igl::ReTwBar::set_value_from_string(
         }
         break;
       }
+    case TW_TYPE_QUAT4D:
+    //case TW_TYPE_COLOR4D:
+      {
+        if(sscanf(value_str," %lf %lf %lf %lf",&d[0],&d[1],&d[2],&d[3]) == 4)
+        {
+          value = &d;
+        }else
+        {
+          printf("ERROR: Bad value format...\n");
+          return false;
+        }
+        break;
+      }
     case TW_TYPE_QUAT4F:
     case TW_TYPE_COLOR4F:
       {
@@ -586,6 +609,17 @@ bool igl::ReTwBar::set_value_from_string(
             *bvar = *bvalue;
             break;
           }
+        case TW_TYPE_QUAT4D:
+        //case TW_TYPE_COLOR4D:
+          {
+            double * dvar = static_cast<double*>(var);
+            double * dvalue = static_cast<double*>(value);
+            dvar[0] = dvalue[0];
+            dvar[1] = dvalue[1];
+            dvar[2] = dvalue[2];
+            dvar[3] = dvalue[3];
+            break;
+          }
         case TW_TYPE_QUAT4F:
         case TW_TYPE_COLOR4F:
           {

+ 2 - 2
include/igl/canonical_quaternions.cpp

@@ -1,10 +1,10 @@
 #include "canonical_quaternions.h"
 
-template <> IGL_INLINE const float igl::CANONICAL_VIEW_QUAT<float>(int i, int j)
+template <> IGL_INLINE float igl::CANONICAL_VIEW_QUAT<float>(int i, int j)
 {
   return (float)igl::CANONICAL_VIEW_QUAT_F[i][j];
 }
-template <> IGL_INLINE const double igl::CANONICAL_VIEW_QUAT<double>(int i, int j)
+template <> IGL_INLINE double igl::CANONICAL_VIEW_QUAT<double>(int i, int j)
 {
   return (double)igl::CANONICAL_VIEW_QUAT_D[i][j];
 }

+ 3 - 3
include/igl/canonical_quaternions.h

@@ -107,12 +107,12 @@ namespace igl
   //   j  index of coordinate in quaternion i
   // Returns values of CANONICAL_VIEW_QUAT_*[i][j]
   template <typename Q_type> 
-  IGL_INLINE const Q_type CANONICAL_VIEW_QUAT(int i, int j);
+  IGL_INLINE Q_type CANONICAL_VIEW_QUAT(int i, int j);
   // Template specializations for float and double
   template <> 
-  IGL_INLINE const float CANONICAL_VIEW_QUAT<float>(int i, int j);
+  IGL_INLINE float CANONICAL_VIEW_QUAT<float>(int i, int j);
   template <> 
-  IGL_INLINE const double CANONICAL_VIEW_QUAT<double>(int i, int j);
+  IGL_INLINE double CANONICAL_VIEW_QUAT<double>(int i, int j);
 
 #  undef SQRT_2_OVER_2
 }

+ 8 - 0
include/igl/material_colors.h

@@ -15,5 +15,13 @@ namespace igl
   const float CYAN_SPECULAR[4] =   { 163.0/255.0,221.0/255.0,255.0/255.0,1.0f };
   const float DENIS_PURPLE_DIFFUSE[4] =   { 80.0/255.0,64.0/255.0,255.0/255.0,1.0f };
   const float LADISLAV_ORANGE_DIFFUSE[4] = {1.0f, 125.0f / 255.0f, 19.0f / 255.0f, 0.0f};
+  // FAST armadillos colors
+  const float FAST_GREEN_DIFFUSE[4] = { 113.0f/255.0f, 239.0f/255.0f,  46.0f/255.0f, 1.0f};
+  const float FAST_RED_DIFFUSE[4]   = { 255.0f/255.0f,  65.0f/255.0f,  46.0f/255.0f, 1.0f};
+  const float FAST_BLUE_DIFFUSE[4]  = { 106.0f/255.0f, 106.0f/255.0f, 255.0f/255.0f, 1.0f};
+  const float FAST_GRAY_DIFFUSE[4]  = { 150.0f/255.0f, 150.0f/255.0f, 150.0f/255.0f, 1.0f};
+  const float WHITE_AMBIENT[4] =   { 255.0/255.0,255.0/255.0,255.0/255.0,1.0f };
+  const float WHITE_DIFFUSE[4] =   { 255.0/255.0,255.0/255.0,255.0/255.0,1.0f };
+  const float WHITE_SPECULAR[4] =  { 255.0/255.0,255.0/255.0,255.0/255.0,1.0f };
 }
 #endif

+ 2 - 0
include/igl/mosek/mosek_quadprog.cpp

@@ -247,7 +247,9 @@ IGL_INLINE bool igl::mosek_quadprog(
   // Q should be square
   assert(Q.rows() == Q.cols());
   // Q should be symmetric
+#ifdef EIGEN_HAS_A_BUG_AND_FAILS_TO_LET_ME_COMPUTE_Q_MINUS_Q_TRANSPOSE
   assert( (Q-Q.transpose()).sum() < FLOAT_EPS);
+#endif
   // Only keep lower triangular part of Q
   SparseMatrix<double> QL;
   //QL = Q.template triangularView<Lower>();

+ 23 - 0
include/igl/per_vertex_attribute_smoothing.cpp

@@ -0,0 +1,23 @@
+#include "per_vertex_attribute_smoothing.h"
+#include <vector>
+
+template <typename DerivedV, typename DerivedF>
+IGL_INLINE void igl::per_vertex_attribute_smoothing(
+    const Eigen::PlainObjectBase<DerivedV>& Ain,
+    const Eigen::PlainObjectBase<DerivedF>& F,
+    Eigen::PlainObjectBase<DerivedV> & Aout)
+{
+    std::vector<double> denominator(Ain.rows(), 0);
+    Aout = Eigen::PlainObjectBase<DerivedV>::Zero(Ain.rows(), Ain.cols());
+    for (int i = 0; i < F.rows(); ++i) {
+        for (int j = 0; j < 3; ++j) {
+            int j1 = (j + 1) % 3;
+            int j2 = (j + 2) % 3;
+            Aout.row(F(i, j)) += Ain.row(F(i, j1)) + Ain.row(F(i, j2));
+            denominator[F(i, j)] += 2;
+        }
+    }
+    for (int i = 0; i < Ain.rows(); ++i)
+        Aout.row(i) /= denominator[i];
+}
+

+ 25 - 0
include/igl/per_vertex_attribute_smoothing.h

@@ -0,0 +1,25 @@
+#ifndef IGL_PER_VERTEX_ATTRIBUTE_SMOOTHING_H
+#define IGL_PER_VERTEX_ATTRIBUTE_SMOOTHING_H
+#include "igl_inline.h"
+#include <Eigen/Core>
+
+namespace igl
+{
+  // Smooth vertex attributes using uniform Laplacian
+  // Inputs:
+  //   Ain  #V by #A eigen Matrix of mesh vertex attributes (each vertex has #A attributes)
+  //   F    #F by 3 eigne Matrix of face (triangle) indices
+  // Output:
+  //   Aout #V by #A eigen Matrix of mesh vertex attributes
+  template <typename DerivedV, typename DerivedF>
+  IGL_INLINE void per_vertex_attribute_smoothing(
+    const Eigen::PlainObjectBase<DerivedV>& Ain,
+    const Eigen::PlainObjectBase<DerivedF>& F,
+    Eigen::PlainObjectBase<DerivedV> & Aout);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "per_vertex_attribute_smoothing.cpp"
+#endif
+
+#endif

+ 40 - 0
include/igl/png/Makefile

@@ -0,0 +1,40 @@
+include ../../../Makefile.conf
+all: CFLAGS += -O3 -DNDEBUG -j 
+debug: CFLAGS += -g -Wall -Werror
+
+.PHONY: all
+all: libiglpng
+
+.PHONY: libpng
+libiglpng: obj ../../../lib/libiglpng.a
+
+CPP_FILES=$(wildcard *.cpp)
+OBJ_FILES=$(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o)))
+
+# include igl headers
+INC+=-I../../../include/
+
+# EXPECTS THAT CFLAGS IS ALREADY SET APPROPRIATELY 
+
+# YIMG dependency
+YIMG=../../../external/yimg
+YIMG_INC=-I$(YIMG)
+INC+=$(YIMG_INC)
+YIMG_STATIC_LIB=$(YIMG)/libyimg.a
+
+# BOOST dependency
+INC+=-I/opt/local/include/
+
+obj: 
+	mkdir -p obj
+
+../../../lib/libiglpng.a: $(OBJ_FILES)
+	rm -f $@
+	ar cqs $@ $(OBJ_FILES)
+
+obj/%.o: %.cpp %.h
+	g++ $(AFLAGS) $(CFLAGS) -c -o $@ $< $(INC)
+
+clean:
+	rm -f obj/*.o
+	rm -f ../../../lib/libiglpng.a

+ 42 - 0
include/igl/png/render_to_png.cpp

@@ -0,0 +1,42 @@
+#include "render_to_png.h"
+#include <YImage.hpp>
+
+#ifdef __APPLE__
+#  include <OpenGL/gl.h>
+#else
+#  ifdef _WIN32
+#    define NOMINMAX
+#    include <Windows.h>
+#    undef NOMINMAX
+#  endif
+#  include <GL/gl.h>
+#endif
+
+IGL_INLINE bool igl::render_to_png(
+  const std::string png_file,
+  const int width,
+  const int height,
+  const bool alpha,
+  const bool fast)
+{
+  YImage img;
+  img.resize(width,height);
+  glReadPixels(
+    0,
+    0,
+    width,
+    height,
+    GL_RGBA,
+    GL_UNSIGNED_BYTE,
+    img.data());
+  img.flip();
+  if(!alpha)
+  {
+    for(int i = 0;i<width;i++)
+    for(int j = 0;j<height;j++)
+    {
+      img.at(i,j).a = 255;
+    }
+  }
+  return img.save(png_file.c_str(),fast);
+}

+ 31 - 0
include/igl/png/render_to_png.h

@@ -0,0 +1,31 @@
+#ifndef IGL_RENDER_TO_PNG_H
+#define IGL_RENDER_TO_PNG_H
+#include <igl/igl_inline.h>
+
+#include <string>
+namespace igl
+{
+  //
+  // Render current open GL image to .png file
+  // Inputs:
+  //   png_file  path to output .png file
+  //   width  width of scene and resulting image
+  //   height height of scene and resulting image
+  //   alpha  whether to include alpha channel
+  //   fast  sacrifice compression ratio for speed
+  // Returns true only if no errors occured
+  //
+  // See also: igl/render_to_tga which is faster but writes .tga files
+  IGL_INLINE bool render_to_png(
+    const std::string png_file,
+    const int width,
+    const int height,
+    const bool alpha = true,
+    const bool fast = false);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "render_to_png.cpp"
+#endif
+
+#endif

+ 60 - 0
include/igl/png/render_to_png_async.cpp

@@ -0,0 +1,60 @@
+#ifndef IGL_NO_BOOST
+#include "render_to_png_async.h"
+#include <YImage.hpp>
+
+#ifdef __APPLE__
+#  include <OpenGL/gl.h>
+#else
+#  ifdef _WIN32
+#    define NOMINMAX
+#    include <Windows.h>
+#    undef NOMINMAX
+#  endif
+#  include <GL/gl.h>
+#endif
+
+  
+static IGL_INLINE bool render_to_png_async_helper(
+  YImage * img,
+  const std::string png_file,
+  const bool alpha,
+  const bool fast)
+{
+
+  img->flip();
+  const int width = img->width();
+  const int height = img->height();
+  if(!alpha)
+  {
+    for(int i = 0;i<width;i++)
+    for(int j = 0;j<height;j++)
+    {
+      img->at(i,j).a = 255;
+    }
+  }
+
+  return img->save(png_file.c_str(),fast);
+}
+
+IGL_INLINE boost::thread igl::render_to_png_async(
+  const std::string png_file,
+  const int width,
+  const int height,
+  const bool alpha,
+  const bool fast)
+{
+  // Part that should serial
+  YImage * img = new YImage();
+  img->resize(width,height);
+  glReadPixels(
+    0,
+    0,
+    width,
+    height,
+    GL_RGBA,
+    GL_UNSIGNED_BYTE,
+    img->data());
+  // Part that should be asynchronous  
+  return boost::thread(render_to_png_async_helper,img,png_file,alpha,fast);
+}
+#endif

+ 37 - 0
include/igl/png/render_to_png_async.h

@@ -0,0 +1,37 @@
+#ifndef IGL_NO_BOOST
+#ifndef IGL_RENDER_TO_PNG_ASYNC_H
+#define IGL_RENDER_TO_PNG_ASYNC_H
+#include <igl/igl_inline.h>
+#include <boost/thread/thread.hpp>
+
+#include <string>
+namespace igl
+{
+  // History:
+  //  added multithreaded parameter and support, Alec Sept 3, 2012
+  //
+  // Render current open GL image to .png file
+  // Inputs:
+  //   png_file  path to output .png file
+  //   width  width of scene and resulting image
+  //   height height of scene and resulting image
+  //   alpha  whether to include alpha channel
+  //   fast  sacrifice compression ratio for speed
+  // Returns true only if no errors occured
+  //
+  // See also: igl/render_to_tga which is faster but writes .tga files
+  IGL_INLINE boost::thread render_to_png_async(
+    const std::string png_file,
+    const int width,
+    const int height,
+    const bool alpha = true,
+    const bool fast = false);
+}
+
+#ifdef IGL_HEADER_ONLY
+#  include "render_to_png_async.cpp"
+#endif
+
+#endif
+
+#endif

+ 2 - 0
include/igl/quat_conjugate.cpp

@@ -14,5 +14,7 @@ IGL_INLINE void igl::quat_conjugate(
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
+template void igl::quat_conjugate<double>(double const*, double*);
+// generated by autoexplicit.sh
 template void igl::quat_conjugate<float>(float const*, float*);
 #endif

+ 2 - 0
include/igl/quat_to_mat.cpp

@@ -31,5 +31,7 @@ IGL_INLINE void igl::quat_to_mat(const Q_type * quat, Q_type * mat)
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
+template void igl::quat_to_mat<double>(double const*, double*);
+// generated by autoexplicit.sh
 template void igl::quat_to_mat<float>(float const*, float*);
 #endif

+ 3 - 0
include/igl/readOBJ.h

@@ -60,6 +60,9 @@ namespace igl
   //
   // KNOWN BUG: This only knows how to face lines without normal or texture
   // indices. It will probably crash or give garbage on anything else.
+  //
+  // KNOWN BUG: The order of the attributes is different than the vector
+  // version above
   template <typename DerivedV, typename DerivedF, typename DerivedT>
   IGL_INLINE bool readOBJ(
     const std::string str,

+ 2 - 0
include/igl/render_to_tga.h

@@ -12,6 +12,8 @@ namespace igl
   //   height height of scene and resulting image
   ///  alpha  whether to include alpha channel
   // Returns true only if no errors occured
+  //
+  // See also: png/render_to_png which is slower but writes .png files
   IGL_INLINE bool render_to_tga(
     const std::string tga_file,
     const int width,

+ 2 - 0
include/igl/rotate_by_quat.cpp

@@ -42,5 +42,7 @@ IGL_INLINE void igl::rotate_by_quat(
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
+template void igl::rotate_by_quat<double>(double const*, double const*, double*);
+// generated by autoexplicit.sh
 template void igl::rotate_by_quat<float>(float const*, float const*, float*);
 #endif

+ 3 - 2
include/igl/snap_to_canonical_view_quat.cpp

@@ -41,9 +41,9 @@ IGL_INLINE bool igl::snap_to_canonical_view_quat(
   const Q_type MAX_DISTANCE = 0.4;
   Q_type min_distance = 2*MAX_DISTANCE;
   int min_index = -1;
-  int min_sign = 0;
+  double min_sign = 0;
   // loop over canonical view quaternions
-  for(int sign = -1;sign<=1;sign+=2)
+  for(double sign = -1;sign<=1;sign+=2)
   {
     for(int i = 0; i<NUM_CANONICAL_VIEW_QUAT; i++)
     {
@@ -51,6 +51,7 @@ IGL_INLINE bool igl::snap_to_canonical_view_quat(
       // loop over coordinates
       for(int j = 0;j<4;j++)
       {
+        // Double cast because of bug in llvm version 4.2 with -O3
         distance += 
           (qn[j]-sign*igl::CANONICAL_VIEW_QUAT<Q_type>(i,j))*
           (qn[j]-sign*igl::CANONICAL_VIEW_QUAT<Q_type>(i,j));

+ 2 - 0
include/igl/trackball.cpp

@@ -102,5 +102,7 @@ IGL_INLINE void igl::trackball(
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
+template void igl::trackball<double>(int, int, double, double const*, int, int, int, int, double*);
+// generated by autoexplicit.sh
 template void igl::trackball<float>(int, int, float, float const*, int, int, int, int, float*);
 #endif