summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/doc/main_page.h4
-rw-r--r--src/common/example/CMakeLists.txt18
-rw-r--r--src/common/example/example_CGAL_3D_points_off_reader.cpp (renamed from src/common/example/CGAL_3D_points_off_reader.cpp)0
-rw-r--r--src/common/example/example_CGAL_points_off_reader.cpp (renamed from src/common/example/CGAL_points_off_reader.cpp)2
-rw-r--r--src/common/example/example_vector_double_points_off_reader.cpp41
-rw-r--r--src/common/include/gudhi/Points_3D_off_io.h4
-rw-r--r--src/common/include/gudhi/Points_off_io.h13
-rw-r--r--src/common/include/gudhi/Test.h105
-rw-r--r--src/common/test/CMakeLists.txt27
-rw-r--r--src/common/test/test_points_off_reader.cpp (renamed from src/common/test/points_off_reader_unit_test.cpp)21
10 files changed, 79 insertions, 156 deletions
diff --git a/src/common/doc/main_page.h b/src/common/doc/main_page.h
index 0983051d..21cf6925 100644
--- a/src/common/doc/main_page.h
+++ b/src/common/doc/main_page.h
@@ -315,8 +315,8 @@ make \endverbatim
* @example Bitmap_cubical_complex/Bitmap_cubical_complex.cpp
* @example Bitmap_cubical_complex/Bitmap_cubical_complex_periodic_boundary_conditions.cpp
* @example Bitmap_cubical_complex/Random_bitmap_cubical_complex.cpp
- * @example common/CGAL_3D_points_off_reader.cpp
- * @example common/CGAL_points_off_reader.cpp
+ * @example common/example_CGAL_3D_points_off_reader.cpp
+ * @example common/example_CGAL_points_off_reader.cpp
* @example Contraction/Garland_heckbert.cpp
* @example Contraction/Rips_contraction.cpp
* @example Persistent_cohomology/alpha_complex_3d_persistence.cpp
diff --git a/src/common/example/CMakeLists.txt b/src/common/example/CMakeLists.txt
index 0da3dcc0..b0c6d69a 100644
--- a/src/common/example/CMakeLists.txt
+++ b/src/common/example/CMakeLists.txt
@@ -1,17 +1,21 @@
cmake_minimum_required(VERSION 2.6)
project(Common_examples)
-# need CGAL 4.7
+add_executable ( vector_double_off_reader example_vector_double_points_off_reader.cpp )
+target_link_libraries(vector_double_off_reader ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
+add_test(vector_double_off_reader ${CMAKE_CURRENT_BINARY_DIR}/vector_double_off_reader ${CMAKE_SOURCE_DIR}/data/points/SO3_10000.off)
+
if(CGAL_FOUND)
- add_executable ( cgal3Doffreader CGAL_3D_points_off_reader.cpp )
- target_link_libraries(cgal3Doffreader ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
- add_test(cgal3Doffreader ${CMAKE_CURRENT_BINARY_DIR}/cgal3Doffreader ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off)
+ add_executable ( cgal_3D_off_reader example_CGAL_3D_points_off_reader.cpp )
+ target_link_libraries(cgal_3D_off_reader ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
+ add_test(cgal_3D_off_reader ${CMAKE_CURRENT_BINARY_DIR}/cgal_3D_off_reader ${CMAKE_SOURCE_DIR}/data/points/tore3D_300.off)
+ # need CGAL 4.7
if (NOT CGAL_VERSION VERSION_LESS 4.7.0)
if (EIGEN3_FOUND)
- add_executable ( cgaloffreader CGAL_points_off_reader.cpp )
- target_link_libraries(cgaloffreader ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
- add_test(cgaloffreader ${CMAKE_CURRENT_BINARY_DIR}/cgaloffreader ${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off)
+ add_executable ( cgal_off_reader example_CGAL_points_off_reader.cpp )
+ target_link_libraries(cgal_off_reader ${Boost_SYSTEM_LIBRARY} ${CGAL_LIBRARY})
+ add_test(cgal_off_reader ${CMAKE_CURRENT_BINARY_DIR}/cgal_off_reader ${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off)
endif(EIGEN3_FOUND)
endif (NOT CGAL_VERSION VERSION_LESS 4.7.0)
endif()
diff --git a/src/common/example/CGAL_3D_points_off_reader.cpp b/src/common/example/example_CGAL_3D_points_off_reader.cpp
index d48bb17d..d48bb17d 100644
--- a/src/common/example/CGAL_3D_points_off_reader.cpp
+++ b/src/common/example/example_CGAL_3D_points_off_reader.cpp
diff --git a/src/common/example/CGAL_points_off_reader.cpp b/src/common/example/example_CGAL_points_off_reader.cpp
index d1ca166d..4522174a 100644
--- a/src/common/example/CGAL_points_off_reader.cpp
+++ b/src/common/example/example_CGAL_points_off_reader.cpp
@@ -37,7 +37,7 @@ int main(int argc, char **argv) {
int n {0};
for (auto point : point_cloud) {
std::cout << "Point[" << n << "] = ";
- for (int i {0}; i < point.dimension(); i++)
+ for (std::size_t i {0}; i < point.size(); i++)
std::cout << point[i] << " ";
std::cout << "\n";
++n;
diff --git a/src/common/example/example_vector_double_points_off_reader.cpp b/src/common/example/example_vector_double_points_off_reader.cpp
new file mode 100644
index 00000000..8aecb26e
--- /dev/null
+++ b/src/common/example/example_vector_double_points_off_reader.cpp
@@ -0,0 +1,41 @@
+#include <gudhi/Points_off_io.h>
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+using Point_d = std::vector<double>;
+
+void usage(char * const progName) {
+ std::cerr << "Usage: " << progName << " inputFile.off" << std::endl;
+ exit(-1);
+}
+
+int main(int argc, char **argv) {
+ if (argc != 2) {
+ 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 triangulate points
+ Gudhi::Points_off_reader<Point_d> off_reader(offInputFile);
+ // Check the read operation was correct
+ if (!off_reader.is_valid()) {
+ std::cerr << "Unable to read file " << offInputFile << std::endl;
+ usage(argv[0]);
+ }
+
+ // Retrieve the triangulation
+ std::vector<Point_d> point_cloud = off_reader.get_point_cloud();
+
+ int n {0};
+ for (auto point : point_cloud) {
+ std::cout << "Point[" << n << "] = ";
+ for (std::size_t i {0}; i < point.size(); i++)
+ std::cout << point[i] << " ";
+ std::cout << "\n";
+ ++n;
+ }
+ return 0;
+}
diff --git a/src/common/include/gudhi/Points_3D_off_io.h b/src/common/include/gudhi/Points_3D_off_io.h
index 2647f11e..b0d24998 100644
--- a/src/common/include/gudhi/Points_3D_off_io.h
+++ b/src/common/include/gudhi/Points_3D_off_io.h
@@ -132,12 +132,12 @@ class Points_3D_off_visitor_reader {
*
* @code template<class InputIterator > Point_3::Point_3(double x, double y, double z) @endcode
*
- * @section Example
+ * @section point3doffioexample Example
*
* This example loads points from an OFF file and builds a vector of CGAL points in dimension 3.
* Then, it is asked to display the points.
*
- * @include common/CGAL_3D_points_off_reader.cpp
+ * @include common/example_CGAL_3D_points_off_reader.cpp
*
* When launching:
*
diff --git a/src/common/include/gudhi/Points_off_io.h b/src/common/include/gudhi/Points_off_io.h
index 74b49386..29af8a8a 100644
--- a/src/common/include/gudhi/Points_off_io.h
+++ b/src/common/include/gudhi/Points_off_io.h
@@ -73,9 +73,8 @@ class Points_off_visitor_reader {
* @details
* Point_d must have a constructor with the following form:
*
- * @code template<class InputIterator > Point_d::Point_d(int d, InputIterator first, InputIterator last) @endcode
+ * @code template<class InputIterator > Point_d::Point_d(InputIterator first, InputIterator last) @endcode
*
- * where d is the point dimension.
*/
void point(const std::vector<double>& point) {
#ifdef DEBUG_TRACES
@@ -86,7 +85,7 @@ class Points_off_visitor_reader {
std::cout << std::endl;
#endif // DEBUG_TRACES
// Fill the point cloud
- point_cloud.push_back(Point_d(point.size(), point.begin(), point.end()));
+ point_cloud.push_back(Point_d(point.begin(), point.end()));
}
// Off_reader visitor maximal_face implementation - Only points are read
@@ -115,16 +114,16 @@ class Points_off_visitor_reader {
*
* where d is the point dimension.
*
- * \section Example
+ * \section pointoffioexample Example
*
- * This example loads points from an OFF file and builds a vector of CGAL points in dimension d.
+ * This example loads points from an OFF file and builds a vector of points (vector of double).
* Then, it is asked to display the points.
*
- * \include common/CGAL_points_off_reader.cpp
+ * \include common/example_vector_double_points_off_reader.cpp
*
* When launching:
*
- * \code $> ./cgaloffreader ../../data/points/alphacomplexdoc.off
+ * \code $> ./vector_double_off_reader ../../data/points/alphacomplexdoc.off
* \endcode
*
* the program output is:
diff --git a/src/common/include/gudhi/Test.h b/src/common/include/gudhi/Test.h
deleted file mode 100644
index 6024c822..00000000
--- a/src/common/include/gudhi/Test.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/* This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
- * library for computational topology.
- *
- * Author(s): David Salinas
- *
- * Copyright (C) 2014 INRIA Sophia Antipolis-Mediterranee (France)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef TEST_H_
-#define TEST_H_
-
-#include <list>
-#include <string>
-#include <vector>
-#include <sstream>
-#include <iostream>
-
-
-#define TEST(a) std::cout << "TEST: " << (a) << std::endl
-#define TESTMSG(a, b) std::cout << "TEST: " << a << b << std::endl
-#define TESTVALUE(a) std::cout << "TEST: " << #a << ": " << a << std::endl
-
-/**
- * Class to perform test
- */
-
-class Test {
- private:
- std::string name;
- bool (*test)();
-
- std::string separation() const {
- return "+++++++++++++++++++++++++++++++++++++++++++++++++\n";
- }
-
- std::string print_between_plus(std::string& s) const {
- std::stringstream res;
- res << "+++++++++++++++++" << s << "+++++++++++++++++\n";
- return res.str();
- }
-
- public:
- Test(std::string name_, bool (*test_)()) {
- name = name_;
- test = test_;
- }
-
- bool run() {
- std::cout << print_between_plus(name);
- return test();
- }
-
- std::string getName() {
- return name;
- }
-};
-
-class Tests {
- private:
- std::list<Test> tests;
-
- public:
- void add(std::string name_, bool (*test_)()) {
- Test test(name_, test_);
- tests.push_back(test);
- }
-
- bool run() {
- bool tests_succesful(true);
- std::vector<bool> res;
- for (Test test : tests) {
- res.push_back(test.run());
- }
- std::cout << "\n\n results of tests : " << std::endl;
- int i = 0;
- for (Test t : tests) {
- std::cout << "Test " << i << " \"" << t.getName() << "\" --> ";
- if (res[i++]) {
- std::cout << "OK" << std::endl;
- } else {
- std::cout << "Fail" << std::endl;
- tests_succesful = false;
- break;
- }
- }
- return tests_succesful;
- }
-};
-
-#endif // TEST_H_
diff --git a/src/common/test/CMakeLists.txt b/src/common/test/CMakeLists.txt
index 0a88cf8e..7ccdb752 100644
--- a/src/common/test/CMakeLists.txt
+++ b/src/common/test/CMakeLists.txt
@@ -10,26 +10,15 @@ if (GPROF_PATH)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
endif()
-# need CGAL 4.7
-if(CGAL_FOUND)
- if (NOT CGAL_VERSION VERSION_LESS 4.7.0)
- if (EIGEN3_FOUND)
- add_executable ( poffreader_UT points_off_reader_unit_test.cpp )
- target_link_libraries(poffreader_UT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
+add_executable ( poffreader_UT test_points_off_reader.cpp )
+target_link_libraries(poffreader_UT ${Boost_SYSTEM_LIBRARY} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
- # Do not forget to copy test files in current binary dir
- file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
+# Do not forget to copy test files in current binary dir
+file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
- # Unitary tests
- add_test(poffreader_UT ${CMAKE_CURRENT_BINARY_DIR}/poffreader_UT
- # XML format for Jenkins xUnit plugin
- --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/poffreader_UT.xml --log_level=test_suite --report_level=no)
+# Unitary tests
+add_test(poffreader_UT ${CMAKE_CURRENT_BINARY_DIR}/poffreader_UT
+ # XML format for Jenkins xUnit plugin
+ --log_format=XML --log_sink=${CMAKE_SOURCE_DIR}/poffreader_UT.xml --log_level=test_suite --report_level=no)
- else()
- message(WARNING "Eigen3 not found. Version 3.1.0 is required for points_off_reader unitary tests.")
- endif()
- else()
- message(WARNING "CGAL version: ${CGAL_VERSION} is too old to compile points_off_reader unitary tests. Version 4.7.0 is required.")
- endif ()
-endif()
diff --git a/src/common/test/points_off_reader_unit_test.cpp b/src/common/test/test_points_off_reader.cpp
index dbcc0434..b4f71182 100644
--- a/src/common/test/points_off_reader_unit_test.cpp
+++ b/src/common/test/test_points_off_reader.cpp
@@ -22,10 +22,6 @@
#include <gudhi/Points_off_io.h>
-// For CGAL points type in dimension d
-// cf. http://doc.cgal.org/latest/Kernel_d/classCGAL_1_1Point__d.html
-#include <CGAL/Epick_d.h>
-
#include <iostream>
#include <string>
#include <vector>
@@ -34,8 +30,7 @@
#define BOOST_TEST_MODULE "points_off_read_write"
#include <boost/test/unit_test.hpp>
-typedef CGAL::Epick_d< CGAL::Dynamic_dimension_tag > Kernel;
-typedef Kernel::Point_d Point_d;
+using Point_d = std::vector<double>;
BOOST_AUTO_TEST_CASE( points_doc_test )
{
@@ -50,19 +45,19 @@ BOOST_AUTO_TEST_CASE( points_doc_test )
std::vector<Point_d> expected_points;
std::vector<double> point = {1.0, 1.0};
- expected_points.push_back(Point_d(2, point.begin(), point.end()));
+ expected_points.push_back(Point_d(point.begin(), point.end()));
point = {7.0, 0.0};
- expected_points.push_back(Point_d(2, point.begin(), point.end()));
+ expected_points.push_back(Point_d(point.begin(), point.end()));
point = {4.0, 6.0};
- expected_points.push_back(Point_d(2, point.begin(), point.end()));
+ expected_points.push_back(Point_d(point.begin(), point.end()));
point = {9.0, 6.0};
- expected_points.push_back(Point_d(2, point.begin(), point.end()));
+ expected_points.push_back(Point_d(point.begin(), point.end()));
point = {0.0, 14.0};
- expected_points.push_back(Point_d(2, point.begin(), point.end()));
+ expected_points.push_back(Point_d(point.begin(), point.end()));
point = {2.0, 19.0};
- expected_points.push_back(Point_d(2, point.begin(), point.end()));
+ expected_points.push_back(Point_d(point.begin(), point.end()));
point = {9.0, 17.0};
- expected_points.push_back(Point_d(2, point.begin(), point.end()));
+ expected_points.push_back(Point_d(point.begin(), point.end()));
BOOST_CHECK(point_cloud == expected_points);
}