Browse Source

camera class, render to png extra, yimg external, more material colors (those used in FAST paper),

Former-commit-id: bf715e0e1b612637ea1fc265bae3b9137755e346
jalec 13 years ago
parent
commit
09ef1c952b

+ 10 - 0
.hgignore

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

+ 4 - 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

+ 1 - 0
Makefile.conf

@@ -25,6 +25,7 @@ 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_linux) 

+ 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

+ 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

+ 37 - 0
include/igl/png/Makefile

@@ -0,0 +1,37 @@
+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
+
+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 - 1
include/igl/quat_conjugate.cpp

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

+ 2 - 1
include/igl/quat_to_mat.cpp

@@ -31,6 +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<float>(float const*, float*);
 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 - 1
include/igl/rotate_by_quat.cpp

@@ -42,6 +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<float>(float const*, float const*, float*);
 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 - 1
include/igl/trackball.cpp

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