Эх сурвалжийг харах

openmp for normals and igl makefile

Former-commit-id: 1e924d48516c2ac3d931dbf23674c28418db8d66
Alec Jacobson (jalec 12 жил өмнө
parent
commit
6bada6d67f

+ 3 - 0
.hgignore

@@ -2,10 +2,13 @@
 syntax: glob
 *.o
 *.a
+*.dylib
 *~
 example
 example_static
 example_header_only
 example1
 external/yimg/.git*
+external/tinyxml2/CMakeFiles*
+external/tinyxml2/CMakeCache.txt
 .DS_Store

+ 2 - 2
Makefile

@@ -13,9 +13,9 @@ $(info Hello, $(IGL_USERNAME)!)
 
 # optimized default settings
 all: LFLAGS +=
-OPTFLAGS=-O3 -DNDEBUG
+OPTFLAGS+=-O3 -DNDEBUG $(OPENMP)
 #debug: OPTFLAGS= -g -Wall -Werror
-debug: OPTFLAGS= -g -Wall
+debug: OPTFLAGS+= -g -Wall
 CFLAGS += $(OPTFLAGS)
 
 EXTRA_DIRS=

+ 3 - 0
Makefile.conf

@@ -28,6 +28,7 @@ ifeq ($(IGL_USERNAME),ajx)
 	IGL_WITH_PNG=1
 	# I don't use llvm
 	AFLAGS=-m64
+	OPENMP=-fopenmp
 endif
 
 ifeq ($(IGL_USERNAME),alecjaco) 
@@ -40,6 +41,7 @@ ifeq ($(IGL_USERNAME),alecjaco)
 	OPENGL_LIB=-lGL -lGLU
 	#GLUT_LIB=-lglut
 	ANTTWEAKBAR_LIB=-lAntTweakBar
+	OPENMP=-fopenmp
 endif
 
 ifeq ($(IGL_USERNAME),sorkineo)
@@ -59,6 +61,7 @@ ifeq ($(IGL_USERNAME),jalec_linux)
 	GLUT_LIB=-lglut
 	ANTTWEAKBAR_LIB=-lAntTweakBar
 	IGL_WITH_PNG=1
+	OPENMP=-fopenmp
 endif
 
 ifeq ($(IGL_USERNAME),daniele)

+ 4 - 1
include/igl/per_face_normals.cpp

@@ -1,5 +1,6 @@
 #include "per_face_normals.h"
 #include <Eigen/Geometry>
+#include <omp.h>
 
 template <typename DerivedV, typename DerivedF>
 IGL_INLINE void igl::per_face_normals(
@@ -9,7 +10,9 @@ IGL_INLINE void igl::per_face_normals(
 {
   N.resize(F.rows(),3);
   // loop over faces
-  for(int i = 0; i < F.rows();i++)
+  int Frows = F.rows();
+#pragma omp parallel for
+  for(int i = 0; i < Frows;i++)
   {
     Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v1 = V.row(F(i,1)) - V.row(F(i,0));
     Eigen::Matrix<typename DerivedV::Scalar, 1, 3> v2 = V.row(F(i,2)) - V.row(F(i,0));

+ 19 - 15
include/igl/per_vertex_normals.cpp

@@ -2,6 +2,7 @@
 
 #include "per_face_normals.h"
 #include "normalize_row_lengths.h"
+#include <omp.h>
 
 template <typename DerivedV, typename DerivedF>
 IGL_INLINE void igl::per_vertex_normals(
@@ -11,21 +12,22 @@ IGL_INLINE void igl::per_vertex_normals(
 {
   Eigen::PlainObjectBase<DerivedV> PFN;
   igl::per_face_normals(V,F,PFN);
+  return igl::per_vertex_normals(V,F,PFN,N);
 
-  // Resize for output
-  N = Eigen::PlainObjectBase<DerivedV>::Zero(V.rows(),3);
+  //// Resize for output
+  //N = Eigen::PlainObjectBase<DerivedV>::Zero(V.rows(),3);
 
-  // loop over faces
-  for(int i = 0; i < F.rows();i++)
-  {
-    // throw normal at each corner
-    for(int j = 0; j < 3;j++)
-    {
-      N.row(F(i,j)) += PFN.row(i);
-    }
-  }
-  // normalize each row
-  igl::normalize_row_lengths(N,N);
+  //// loop over faces
+  //for(int i = 0; i < F.rows();i++)
+  //{
+  //  // throw normal at each corner
+  //  for(int j = 0; j < 3;j++)
+  //  {
+  //    N.row(F(i,j)) += PFN.row(i);
+  //  }
+  //}
+  //// normalize each row
+  //igl::normalize_row_lengths(N,N);
 }
 
 template <typename DerivedV, typename DerivedF>
@@ -36,10 +38,12 @@ IGL_INLINE void igl::per_vertex_normals(
   Eigen::PlainObjectBase<DerivedV> & N)
 {
   // Resize for output
-  N = Eigen::PlainObjectBase<DerivedV>::Zero(V.rows(),3);
+  N.resize(V.rows(),3);
   
   // loop over faces
-  for(int i = 0; i < F.rows();i++)
+  int Frows = F.rows();
+#pragma omp parallel for
+  for(int i = 0; i < Frows;i++)
   {
     // throw normal at each corner
     for(int j = 0; j < 3;j++)