diff --git a/build/Makefile_triangle b/build/Makefile_triangle new file mode 100644 index 000000000..19085bc7c --- /dev/null +++ b/build/Makefile_triangle @@ -0,0 +1,44 @@ + +.PHONY: all +all: libigltriangle +debug: libigltriangle + +include Makefile.conf +all: CFLAGS += -O3 -DNDEBUG +debug: CFLAGS += -g -Wall -Werror + +.PHONY: libtriangle +libigltriangle: obj ../lib/libigltriangle.a + +SRC_DIR=../include/igl/triangle/ +CPP_FILES=$(wildcard $(SRC_DIR)*.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$(DEFAULT_PREFIX)/include/eigen3 -I$(DEFAULT_PREFIX)/include/eigen3/unsupported +INC+=$(EIGEN3_INC) + +# triangle dependency +TRIANGLE=../external/triangle +TRIANGLE_INC=-I$(TRIANGLE) +INC+=$(TRIANGLE_INC) +TRIANGLE_STATIC_LIB=$(TRIANGLE)/libtriangle.a + +obj: + mkdir -p obj + +../lib/libigltriangle.a: $(OBJ_FILES) + rm -f $@ + ar cqs $@ $(OBJ_FILES) + +obj/%.o: $(SRC_DIR)/%.cpp $(SRC_DIR)/%.h + g++ $(AFLAGS) $(CFLAGS) -c -o $@ $< $(INC) + +clean: + rm -f obj/*.o + rm -f ../lib/libigltriangle.a diff --git a/include/igl/triangle/triangulate.cpp b/include/igl/triangle/triangulate.cpp index 90f82483b..b3418bb40 100644 --- a/include/igl/triangle/triangulate.cpp +++ b/include/igl/triangle/triangulate.cpp @@ -6,6 +6,16 @@ // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "triangulate.h" +#ifdef ANSI_DECLARATORS +# define IGL_PREVIOUSLY_DEFINED_ANSI_DECLARATORS ANSI_DECLARATORS +#endif +#ifdef REAL +# define IGL_PREVIOUSLY_DEFINED_REAL REAL +#endif +#ifdef VOID +# define IGL_PREVIOUSLY_DEFINED_VOID VOID +#endif +#define ANSI_DECLARATORS #define REAL double #define VOID int @@ -14,13 +24,31 @@ extern "C" #include } +#ifdef IGL_PREVIOUSLY_DEFINED_ANSI_DECLARATORS +# define ANSI_DECLARATORS IGL_PREVIOUSLY_DEFINED_ANSI_DECLARATORS +#else +# undef ANSI_DECLARATORS +#endif + +#ifdef IGL_PREVIOUSLY_DEFINED_REAL +# define REAL IGL_PREVIOUSLY_DEFINED_REAL +#else +# undef REAL +#endif + +#ifdef IGL_PREVIOUSLY_DEFINED_VOID +# define VOID IGL_PREVIOUSLY_DEFINED_VOID +#else +# undef VOID +#endif + IGL_INLINE void igl::triangulate( const Eigen::MatrixXd& V, const Eigen::MatrixXi& E, const Eigen::MatrixXd& H, + const std::string flags, Eigen::MatrixXd& V2, - Eigen::MatrixXi& F2, - const std::string flags) + Eigen::MatrixXi& F2) { using namespace std; using namespace Eigen; @@ -74,7 +102,7 @@ IGL_INLINE void igl::triangulate( out.segmentlist = NULL; // Call triangle - triangulate(const_cast(full_flags.c_str()), &in, &out, 0); + ::triangulate(const_cast(full_flags.c_str()), &in, &out, 0); // Cleanup in free(in.pointlist); diff --git a/include/igl/triangle/triangulate.h b/include/igl/triangle/triangulate.h index 88c028dca..f73016fd4 100644 --- a/include/igl/triangle/triangulate.h +++ b/include/igl/triangle/triangulate.h @@ -19,6 +19,7 @@ namespace igl // V #V by 2 list of 2D vertex positions // E #E by 2 list of vertex ids forming unoriented edges of the boundary of the polygon // H #H by 2 coordinates of points contained inside holes of the polygon + // flags string of options pass to triangle (see triangle documentation) // Outputs: // V2 #V2 by 2 coordinates of the vertives of the generated triangulation // F2 #F2 by 3 list of indices forming the faces of the generated triangulation @@ -29,9 +30,9 @@ namespace igl const Eigen::MatrixXd& V, const Eigen::MatrixXi& E, const Eigen::MatrixXd& H, + const std::string flags, Eigen::MatrixXd& V2, - Eigen::MatrixXi& F2, - const std::string flags = std::string("q")); + Eigen::MatrixXi& F2); } diff --git a/tutorial/604_Triangle/main.cpp b/tutorial/604_Triangle/main.cpp index 557e90b5f..c839aa24b 100755 --- a/tutorial/604_Triangle/main.cpp +++ b/tutorial/604_Triangle/main.cpp @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) H << 0,0; // Triangulate the interior - igl::triangulate(V,E,H,V2,F2,"a0.005q"); + igl::triangulate(V,E,H,"a0.005q",V2,F2); // Plot the generated mesh igl::Viewer viewer;