Просмотр исходного кода

clean up and make triangle wrapper compile

Former-commit-id: 4a0fb1f166d9060d41c1224c44da2ed76dea5ec0
Alec Jacobson 11 лет назад
Родитель
Сommit
5ccd74445e

+ 44 - 0
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

+ 31 - 3
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 <triangle.h>
 }
 
+#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<char*>(full_flags.c_str()), &in, &out, 0);
+  ::triangulate(const_cast<char*>(full_flags.c_str()), &in, &out, 0);
 
   // Cleanup in
   free(in.pointlist);

+ 3 - 2
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);
 
 }
 

+ 1 - 1
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;