Kaynağa Gözat

files that depends on matlab are now compiled on a separated lib. Fixed example for the matlab interface

Former-commit-id: b98a55cac3a827b8aed1e40dbf38cd50cc88f232
dpanozzo 13 yıl önce
ebeveyn
işleme
cbef21e99f

+ 5 - 1
Makefile

@@ -1,5 +1,5 @@
 .PHONY: all
-all: lib examples extras
+all: lib extras examples
 
 # Shared flags etc.
 include Makefile.conf
@@ -14,6 +14,10 @@ ifeq ($(IGL_WITH_TETGEN),1)
 	# append tetgen extra dir
 	EXTRA_DIRS+=include/igl/tetgen
 endif
+ifeq ($(IGL_WITH_MATLAB),1)
+	# append matlab extra dir
+	EXTRA_DIRS+=include/igl/matlab
+endif
 
 .PHONY: examples
 .PHONY: extras

+ 1 - 0
Makefile.conf

@@ -1,4 +1,5 @@
 IGL_WITH_TETGEN=1
+IGL_WITH_MATLAB=1
 
 #############################################################################
 # FLAGS 

+ 0 - 8
examples/Core/Makefile

@@ -18,16 +18,8 @@ example1: example1.o
 example1.o: example1.cpp
 	g++ $(CFLAGS) -c example1.cpp -o example1.o $(inc)
 
-example2: example2.o
-	g++ $(CFLAGS) $(matlab_lib) -o example2 example2.o -framework OpenGL -framework GLUT $(lib)
-	rm example2.o
-
-example2.o: example2.cpp
-	g++ $(CFLAGS) $(matlab_inc) -c example2.cpp -o example2.o $(inc)
 
 clean:
 	rm -f example1.o
 	rm -f example1
-	rm -f example2.o
-	rm -f example2
 	rm -f bunny_out.off

+ 0 - 6
examples/Core/README

@@ -5,9 +5,3 @@ Example1.cpp:
 - Compute face and edge topology
 - Compute the cotan matrix of the loaded mesh
 
-Example2.cpp:
-- Shows how it is possible to send/receive matrices to/from matlab
-in order to use the matlab functions in the igl_toolbox
-
-To run example2 you need matlab and to properly configure your PATH and DYLD_PATH.
-See runexample2.sh for an example.

+ 0 - 56
examples/Core/example2.cpp

@@ -1,56 +0,0 @@
-//
-//  IGL Lib - Simple C++ mesh library 
-//
-//  Copyright 2011, Daniele Panozzo. All rights reserved.
-//
-//
-//  Example that shows the integration with matlab
-//
-
-// IMPORTANT DO NOT REMOVE OR MOVE
-#define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET 
-
-#include <iostream>
-#include <string>
-#include <igl/read.h>
-
-#include <igl/matlabinterface.h>
-
-using namespace std;
-
-int main (int argc, const char * argv[])
-{
-  // This is broken
-    //// read the header of matlabinterface.h for compilation instructions
-    //
-    //Eigen::MatrixXd V,V2;
-    //Eigen::MatrixXi F,F2;
-    //
-    //// Read mesh from file
-    //igl::read("bunny.off",V,F);
-    //
-    //// Send mesh to matlab
-    //igl::mlsetmatrix("V",V);
-    //igl::mlsetmatrix("F",F);
-
-    //// Plot the mesh from matlab
-    //igl::mleval("trimesh(F,V(:,1),V(:,2),V(:,3))");
-
-    //// Receive mesh from matlab
-    //igl::mlgetmatrix("V",V2);
-    //igl::mlgetmatrix("F",F2);
-
-    //// Plot the received mesh
-    //cerr << "V " << endl << V2  << endl;
-    //cerr << "F " << endl << F2  << endl;
-    //
-    //// It is also possible to send scalars
-    //igl::mlsetscalar("s", 3);
-    //cerr << "s = " << igl::mlgetscalar("s") << endl;
-
-    //// If the program closes the matlab session is killed too..
-    //getchar();
-    
-    return 0;
-}
-

+ 1 - 1
examples/MatlabWorkspace/example.cpp

@@ -7,7 +7,7 @@
 #  define IGL_HEADER_ONLY
 #  define IGL_HEADER_ONLY_WAS_NOT_DEFINED
 #endif
-#include <igl/MatlabWorkspace.h>
+#include <igl/matlab/MatlabWorkspace.h>
 #include <igl/on_boundary.h>
 #ifdef IGL_HEADER_ONLY_WAS_NOT_DEFINED
 #  undef IGL_HEADER_ONLY

+ 0 - 1
examples/marching_cubes/example.REMOVED.git-id

@@ -1 +0,0 @@
-b3f3382514052ba833b3b5e749a8b16ee2281c1e

+ 38 - 0
include/igl/matlab/Makefile

@@ -0,0 +1,38 @@
+include ../../../Makefile.conf
+
+.PHONY: all
+all: libmatlab
+
+.PHONY: libmatlab
+libmatlab: obj ../../../lib/libiglmatlab.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 
+
+# Eigen dependency
+EIGEN3_INC=-I/opt/local/include/eigen3 -I/opt/local/include/eigen3/unsupported
+INC+=$(EIGEN3_INC)
+
+# Matlab dependency
+MATLAB_INC=-I$(MATLAB)/extern/include/
+MATLAB_LIB=-L$(MATLAB)/bin/maci64 -lmx -leng
+INC+=$(MATLAB_INC)
+
+obj: 
+	mkdir -p obj
+
+../../../lib/libiglmatlab.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/libiglmatlab.a

+ 2 - 7
include/igl/MatlabWorkspace.cpp → include/igl/matlab/MatlabWorkspace.cpp

@@ -1,10 +1,7 @@
-// Don't let libigl.a compile anything here
-#ifdef IGL_HEADER_ONLY
-
-#include "MatlabWorkspace.h"
+#include "igl/matlab/MatlabWorkspace.h"
 
 // IGL
-#include "list_to_matrix.h"
+#include "igl/list_to_matrix.h"
 
 // MATLAB
 #include "mat.h"
@@ -132,5 +129,3 @@ IGL_INLINE igl::MatlabWorkspace::MatlabWorkspace& igl::MatlabWorkspace::save_ind
 //    name<<" not saved."<<endl;
 //  return false;
 //}
-
-#endif

+ 1 - 1
include/igl/MatlabWorkspace.h → include/igl/matlab/MatlabWorkspace.h

@@ -1,6 +1,6 @@
 #ifndef IGL_WRITE_MATLAB_WORKSPACE
 #define IGL_WRITE_MATLAB_WORKSPACE
-#include "igl_inline.h"
+#include "igl/igl_inline.h"
 
 #include <string>
 #include <vector>

+ 14 - 90
include/igl/matlabinterface.h → include/igl/matlab/matlabinterface.cpp

@@ -1,96 +1,23 @@
-//
-//  IGL Lib - Simple C++ mesh library 
-//
-//  Copyright 2011, Daniele Panozzo. All rights reserved.
-
-// WARNING: These functions require matlab installed
-// Additional header folder required:
-//   /Applications/MATLAB_R2011a.app/extern/include
-// Additional binary lib to be linked with:
-// /Applications/MATLAB_R2011a.app/bin/maci64/libeng.dylib
-// /Applications/MATLAB_R2011a.app/bin/maci64/libmx.dylib
-
-// MAC ONLY:
-// Add to the environment variables:
-// DYLD_LIBRARY_PATH = /Applications/MATLAB_R2011a.app/bin/maci64/
-// PATH = /opt/local/bin:/opt/local/sbin:/Applications/MATLAB_R2011a.app/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin
-
-#ifndef IGL_MATLAB_INTERFACE_H
-#define IGL_MATLAB_INTERFACE_H
-
-#include <Eigen/Core>
-#include <string>
-
-#include <complex>
-#include <cassert>
-#include <map>
-#include <string>
-#include <vector>
-
-#include "engine.h"  // Matlab engine header
-
-namespace igl 
-{
-  // Init the MATLAB engine 
-  // (no need to call it directly since it is automatically invoked by any other command)
-  inline void mlinit(Engine** engine);
-  
-  // Closes the MATLAB engine
-  inline void mlclose(Engine** engine);
-  
-  // Send a matrix to MATLAB
-  inline void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXd& M);
-  
-  // Send a matrix to MATLAB
-  inline void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXf& M);
-
-  // Send a matrix to MATLAB
-  inline void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXi& M);
-  
-  // Send a matrix to MATLAB
-  inline void mlsetmatrix(Engine** mlengine, std::string name, const Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
-  
-  // Receive a matrix from MATLAB
-  inline void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXd& M);
-  
-  // Receive a matrix from MATLAB
-  inline void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXf& M);
-
-  // Receive a matrix from MATLAB
-  inline void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXi& M);
-  
-  // Receive a matrix from MATLAB
-  inline void mlgetmatrix(Engine** mlengine, std::string name, Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
-
-  // Send a single scalar to MATLAB
-  inline void mlsetscalar(Engine** engine, std::string name, double s);
-  
-  // Receive a single scalar from MATLAB
-  inline double mlgetscalar(Engine** engine, std::string name);
-  
-  // Execute arbitrary MATLAB code and return the MATLAB output
-  inline std::string mleval(Engine** engine, std::string code);
-  
-}
+#include <igl/matlab/matlabinterface.h>
 
 // Implementation
 
 // Init the MATLAB engine 
 // (no need to call it directly since it is automatically invoked by any other command)
-inline void igl::mlinit(Engine** mlengine)
+IGL_INLINE void igl::mlinit(Engine** mlengine)
 {
   *mlengine = engOpen("\0");
 }
 
 // Closes the MATLAB engine
-inline void igl::mlclose(Engine** mlengine)
+IGL_INLINE void igl::mlclose(Engine** mlengine)
 {
   engClose(*mlengine);
   *mlengine = 0;
 }
 
 // Send a matrix to MATLAB
-inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::MatrixXd& M)
+IGL_INLINE void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::MatrixXd& M)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -108,7 +35,7 @@ inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::M
 }
 
 // Send a matrix to MATLAB
-inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::MatrixXf& M)
+IGL_INLINE void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::MatrixXf& M)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -126,7 +53,7 @@ inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::M
 }
 
 // Send a matrix to MATLAB
-inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::MatrixXi& M)
+IGL_INLINE void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::MatrixXi& M)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -144,7 +71,7 @@ inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::M
 }
 
 // Send a matrix to MATLAB
-inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M)
+IGL_INLINE void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -162,7 +89,7 @@ inline void igl::mlsetmatrix(Engine** mlengine, std::string name, const Eigen::M
 }
 
 // Receive a matrix from MATLAB
-inline void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixXd& M)
+IGL_INLINE void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixXd& M)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -195,7 +122,7 @@ inline void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixX
   mxDestroyArray(ary);
 }
 
-inline void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixXf& M)
+IGL_INLINE void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixXf& M)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -229,7 +156,7 @@ inline void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixX
 }
 
 // Receive a matrix from MATLAB
-inline void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixXi& M)
+IGL_INLINE void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixXi& M)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -263,7 +190,7 @@ inline void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::MatrixX
 }
 
 // Receive a matrix from MATLAB
-inline void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M)
+IGL_INLINE void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -298,7 +225,7 @@ inline void igl::mlgetmatrix(Engine** mlengine, std::string name, Eigen::Matrix<
 
 
 // Send a single scalar to MATLAB
-inline void igl::mlsetscalar(Engine** mlengine, std::string name, double s)
+IGL_INLINE void igl::mlsetscalar(Engine** mlengine, std::string name, double s)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -309,7 +236,7 @@ inline void igl::mlsetscalar(Engine** mlengine, std::string name, double s)
 }
 
 // Receive a single scalar from MATLAB
-inline double igl::mlgetscalar(Engine** mlengine, std::string name)
+IGL_INLINE double igl::mlgetscalar(Engine** mlengine, std::string name)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -320,7 +247,7 @@ inline double igl::mlgetscalar(Engine** mlengine, std::string name)
 }
 
 // Execute arbitrary MATLAB code and return the MATLAB output
-inline std::string igl::mleval(Engine** mlengine, std::string code)
+IGL_INLINE std::string igl::mleval(Engine** mlengine, std::string code)
 {
   if (*mlengine == 0)
     mlinit(mlengine);
@@ -359,6 +286,3 @@ inline std::string igl::mleval(Engine** mlengine, std::string code)
   
   return std::string(buf);
 }
-
-
-#endif

+ 82 - 0
include/igl/matlab/matlabinterface.h

@@ -0,0 +1,82 @@
+#ifndef IGL_MATLAB_INTERFACE_H
+#define IGL_MATLAB_INTERFACE_H
+#include "../igl_inline.h"
+
+//
+//  IGL Lib - Simple C++ mesh library 
+//
+//  Copyright 2011, Daniele Panozzo. All rights reserved.
+
+// WARNING: These functions require matlab installed
+// Additional header folder required:
+//   /Applications/MATLAB_R2011a.app/extern/include
+// Additional binary lib to be linked with:
+// /Applications/MATLAB_R2011a.app/bin/maci64/libeng.dylib
+// /Applications/MATLAB_R2011a.app/bin/maci64/libmx.dylib
+
+// MAC ONLY:
+// Add to the environment variables:
+// DYLD_LIBRARY_PATH = /Applications/MATLAB_R2011a.app/bin/maci64/
+// PATH = /opt/local/bin:/opt/local/sbin:/Applications/MATLAB_R2011a.app/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin
+
+#include <Eigen/Core>
+#include <string>
+
+#include <complex>
+#include <cassert>
+#include <map>
+#include <string>
+#include <vector>
+
+#include "engine.h"  // Matlab engine header
+
+namespace igl 
+{
+  // Init the MATLAB engine 
+  // (no need to call it directly since it is automatically invoked by any other command)
+  IGL_INLINE void mlinit(Engine** engine);
+  
+  // Closes the MATLAB engine
+  IGL_INLINE void mlclose(Engine** engine);
+  
+  // Send a matrix to MATLAB
+  IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXd& M);
+  
+  // Send a matrix to MATLAB
+  IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXf& M);
+
+  // Send a matrix to MATLAB
+  IGL_INLINE void mlsetmatrix(Engine** engine, std::string name, const Eigen::MatrixXi& M);
+  
+  // Send a matrix to MATLAB
+  IGL_INLINE void mlsetmatrix(Engine** mlengine, std::string name, const Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
+  
+  // Receive a matrix from MATLAB
+  IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXd& M);
+  
+  // Receive a matrix from MATLAB
+  IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXf& M);
+
+  // Receive a matrix from MATLAB
+  IGL_INLINE void mlgetmatrix(Engine** engine, std::string name, Eigen::MatrixXi& M);
+  
+  // Receive a matrix from MATLAB
+  IGL_INLINE void mlgetmatrix(Engine** mlengine, std::string name, Eigen::Matrix<unsigned int, Eigen::Dynamic, Eigen::Dynamic >& M);
+
+  // Send a single scalar to MATLAB
+  IGL_INLINE void mlsetscalar(Engine** engine, std::string name, double s);
+  
+  // Receive a single scalar from MATLAB
+  IGL_INLINE double mlgetscalar(Engine** engine, std::string name);
+  
+  // Execute arbitrary MATLAB code and return the MATLAB output
+  IGL_INLINE std::string mleval(Engine** engine, std::string code);
+  
+}
+
+// Be sure that this is not compiled into libigl.a
+#ifdef IGL_HEADER_ONLY
+#  include "matlabinterface.cpp"
+#endif
+
+#endif