summaryrefslogtreecommitdiff
path: root/src/common/example
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-06-18 14:21:31 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-06-18 14:21:31 +0000
commit56e89b6b7666dec86a70f6a30f08ef8b7960eb21 (patch)
treea43dd7705fcf7435df726e5bc5123662abc8ea4d /src/common/example
parent77b57ae69fa2042b652d91d8015c1d9533176090 (diff)
Moved alphashapedoc.off in data/points
Moved Delaunay triangulation OFF files read and write in src/common Delaunay triangulation OFF files read and write documentation, examples and tests git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/alphashapes@623 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: e03902736a79436e97dbf77a88504f3faa8bd9c6
Diffstat (limited to 'src/common/example')
-rw-r--r--src/common/example/CMakeLists.txt26
-rw-r--r--src/common/example/Delaunay_triangulation_off_rw.cpp55
2 files changed, 81 insertions, 0 deletions
diff --git a/src/common/example/CMakeLists.txt b/src/common/example/CMakeLists.txt
new file mode 100644
index 00000000..ae30da54
--- /dev/null
+++ b/src/common/example/CMakeLists.txt
@@ -0,0 +1,26 @@
+cmake_minimum_required(VERSION 2.6)
+project(GUDHIDelaunayTriangulationOffFileReadWrite)
+
+# need CGAL 4.6
+if(CGAL_FOUND)
+ if (NOT CGAL_VERSION VERSION_LESS 4.6.0)
+ message(STATUS "CGAL version: ${CGAL_VERSION}.")
+
+ include( ${CGAL_USE_FILE} )
+
+ find_package(Eigen3 3.1.0)
+ if (EIGEN3_FOUND)
+ message(STATUS "Eigen3 version: ${EIGEN3_VERSION}.")
+ include( ${EIGEN3_USE_FILE} )
+
+ add_executable ( dtoffrw Delaunay_triangulation_off_rw.cpp )
+ target_link_libraries(dtoffrw ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
+ add_test(dtoffrw ${CMAKE_CURRENT_BINARY_DIR}/dtoffrw ${CMAKE_SOURCE_DIR}/data/points/alphashapedoc.off ${CMAKE_CURRENT_BINARY_DIR}/result.off)
+
+ else()
+ message(WARNING "Eigen3 not found. Version 3.1.0 is required for Alpha shapes feature.")
+ endif()
+ else()
+ message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile Alpha shapes feature. Version 4.6.0 is required.")
+ endif ()
+endif()
diff --git a/src/common/example/Delaunay_triangulation_off_rw.cpp b/src/common/example/Delaunay_triangulation_off_rw.cpp
new file mode 100644
index 00000000..d1aa7988
--- /dev/null
+++ b/src/common/example/Delaunay_triangulation_off_rw.cpp
@@ -0,0 +1,55 @@
+// to construct a Delaunay_triangulation from a OFF file
+#include "gudhi/Delaunay_triangulation_off_io.h"
+
+#include <CGAL/Delaunay_triangulation.h>
+#include <CGAL/Epick_d.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+
+// Use dynamic_dimension_tag for the user to be able to set dimension
+typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > K;
+typedef CGAL::Delaunay_triangulation<K> T;
+// The triangulation uses the default instantiation of the
+// TriangulationDataStructure template parameter
+
+void usage(char * const progName) {
+ std::cerr << "Usage: " << progName << " inputFile.off outputFile.off" << std::endl;
+ exit(-1); // ----- >>
+}
+
+int main(int argc, char **argv) {
+ if (argc != 3) {
+ std::cerr << "Error: Number of arguments (" << argc << ") is not correct" << std::endl;
+ usage(argv[0]);
+ }
+
+ std::string offInputFile(argv[1]);
+ // Read the OFF file (input file name given as parameter) and triangulates points
+ Gudhi::Delaunay_triangulation_off_reader<T> off_reader(offInputFile);
+ // Check the read operation was correct
+ if (!off_reader.is_valid()) {
+ std::cerr << "Unable to read file " << offInputFile << std::endl;
+ exit(-1); // ----- >>
+ }
+
+ // Retrieve the triangulation
+ T* triangulation = off_reader.get_complex();
+ // Operations on triangulation
+ std::cout << "Number of vertices= " << triangulation->number_of_vertices() << std::endl;
+ std::cout << "Number of finite full cells= " << triangulation->number_of_finite_full_cells() << std::endl;
+
+ std::string outFileName(argv[2]);
+ std::string offOutputFile(outFileName);
+ // Write the OFF file (output file name given as parameter) with the points and triangulated cells as faces
+ Gudhi::Delaunay_triangulation_off_writer<T> off_writer(offOutputFile, triangulation);
+
+ // Check the write operation was correct
+ if (!off_writer.is_valid()) {
+ std::cerr << "Unable to write file " << offOutputFile << std::endl;
+ exit(-1); // ----- >>
+ }
+
+ return 0;
+} \ No newline at end of file