summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-02-13 16:55:41 +0000
committervrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2018-02-13 16:55:41 +0000
commit753ab8e366bb7d44b6cbe5e26d95c13317fc48c9 (patch)
treecf338c25d4efa278e3eebd9fd97a03a6d051a49e
parent739d683b3000b5b69686cf49ecad2c8f49f11295 (diff)
Add documentation tests for example_vector_double_points_off_reader
Fix Marc's comments about reader git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/offreaderfix_vincent@3243 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 7dfb928c064c1286c1903cb91600ebace7a8fd47
-rw-r--r--src/common/example/CMakeLists.txt11
-rw-r--r--src/common/example/example_CGAL_3D_points_off_reader.cpp6
-rw-r--r--src/common/example/example_CGAL_points_off_reader.cpp6
-rw-r--r--src/common/example/example_vector_double_points_off_reader.cpp14
-rw-r--r--src/common/example/vectordoubleoffreader_result.txt (renamed from src/common/example/cgaloffreader_result.txt)0
-rw-r--r--src/common/include/gudhi/Off_reader.h29
-rw-r--r--src/common/include/gudhi/Points_off_io.h4
7 files changed, 42 insertions, 28 deletions
diff --git a/src/common/example/CMakeLists.txt b/src/common/example/CMakeLists.txt
index afe865d4..1273c699 100644
--- a/src/common/example/CMakeLists.txt
+++ b/src/common/example/CMakeLists.txt
@@ -3,11 +3,20 @@ project(Common_examples)
add_executable ( vector_double_off_reader example_vector_double_points_off_reader.cpp )
target_link_libraries(vector_double_off_reader ${CGAL_LIBRARY})
+file(COPY "${CMAKE_SOURCE_DIR}/data/points/alphacomplexdoc.off" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
add_test(NAME Common_example_vector_double_off_reader COMMAND $<TARGET_FILE:vector_double_off_reader>
- "${CMAKE_SOURCE_DIR}/data/points/SO3_10000.off")
+ "alphacomplexdoc.off")
install(TARGETS vector_double_off_reader DESTINATION bin)
+if (DIFF_PATH)
+ # Do not forget to copy test results files in current binary dir
+ file(COPY "vectordoubleoffreader_result.txt" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
+
+ add_test(Common_example_vector_double_off_reader_diff_files ${DIFF_PATH}
+ ${CMAKE_CURRENT_BINARY_DIR}/vectordoubleoffreader_result.txt ${CMAKE_CURRENT_BINARY_DIR}/alphacomplexdoc.off.txt)
+endif()
+
if(CGAL_FOUND)
add_executable ( cgal_3D_off_reader example_CGAL_3D_points_off_reader.cpp )
target_link_libraries(cgal_3D_off_reader ${CGAL_LIBRARY})
diff --git a/src/common/example/example_CGAL_3D_points_off_reader.cpp b/src/common/example/example_CGAL_3D_points_off_reader.cpp
index 665b7a29..4658d8d5 100644
--- a/src/common/example/example_CGAL_3D_points_off_reader.cpp
+++ b/src/common/example/example_CGAL_3D_points_off_reader.cpp
@@ -20,12 +20,12 @@ int main(int argc, char **argv) {
usage(argv[0]);
}
- std::string offInputFile(argv[1]);
+ std::string off_input_file(argv[1]);
// Read the OFF file (input file name given as parameter) and triangulate points
- Gudhi::Points_3D_off_reader<Point_3> off_reader(offInputFile);
+ Gudhi::Points_3D_off_reader<Point_3> off_reader(off_input_file);
// Check the read operation was correct
if (!off_reader.is_valid()) {
- std::cerr << "Unable to read file " << offInputFile << std::endl;
+ std::cerr << "Unable to read file " << off_input_file << std::endl;
usage(argv[0]);
}
diff --git a/src/common/example/example_CGAL_points_off_reader.cpp b/src/common/example/example_CGAL_points_off_reader.cpp
index 8c6a6b54..f45683a5 100644
--- a/src/common/example/example_CGAL_points_off_reader.cpp
+++ b/src/common/example/example_CGAL_points_off_reader.cpp
@@ -22,12 +22,12 @@ int main(int argc, char **argv) {
usage(argv[0]);
}
- std::string offInputFile(argv[1]);
+ std::string off_input_file(argv[1]);
// Read the OFF file (input file name given as parameter) and triangulate points
- Gudhi::Points_off_reader<Point_d> off_reader(offInputFile);
+ Gudhi::Points_off_reader<Point_d> off_reader(off_input_file);
// Check the read operation was correct
if (!off_reader.is_valid()) {
- std::cerr << "Unable to read file " << offInputFile << std::endl;
+ std::cerr << "Unable to read file " << off_input_file << std::endl;
usage(argv[0]);
}
diff --git a/src/common/example/example_vector_double_points_off_reader.cpp b/src/common/example/example_vector_double_points_off_reader.cpp
index 8aecb26e..5093da85 100644
--- a/src/common/example/example_vector_double_points_off_reader.cpp
+++ b/src/common/example/example_vector_double_points_off_reader.cpp
@@ -17,25 +17,27 @@ int main(int argc, char **argv) {
usage(argv[0]);
}
- std::string offInputFile(argv[1]);
+ std::string off_input_file(argv[1]);
// Read the OFF file (input file name given as parameter) and triangulate points
- Gudhi::Points_off_reader<Point_d> off_reader(offInputFile);
+ Gudhi::Points_off_reader<Point_d> off_reader(off_input_file);
// Check the read operation was correct
if (!off_reader.is_valid()) {
- std::cerr << "Unable to read file " << offInputFile << std::endl;
+ std::cerr << "Unable to read file " << off_input_file << std::endl;
usage(argv[0]);
}
// Retrieve the triangulation
std::vector<Point_d> point_cloud = off_reader.get_point_cloud();
+ std::ofstream output_file(off_input_file + ".txt");
int n {0};
for (auto point : point_cloud) {
- std::cout << "Point[" << n << "] = ";
+ output_file << "Point[" << n << "] = ";
for (std::size_t i {0}; i < point.size(); i++)
- std::cout << point[i] << " ";
- std::cout << "\n";
+ output_file << point[i] << " ";
+ output_file << "\n";
++n;
}
+ output_file.close();
return 0;
}
diff --git a/src/common/example/cgaloffreader_result.txt b/src/common/example/vectordoubleoffreader_result.txt
index 1deb8dbd..1deb8dbd 100644
--- a/src/common/example/cgaloffreader_result.txt
+++ b/src/common/example/vectordoubleoffreader_result.txt
diff --git a/src/common/include/gudhi/Off_reader.h b/src/common/include/gudhi/Off_reader.h
index 4fcd2af2..32320e4d 100644
--- a/src/common/include/gudhi/Off_reader.h
+++ b/src/common/include/gudhi/Off_reader.h
@@ -105,25 +105,26 @@ class Off_reader {
bool is_off_file = (line.find("OFF") != std::string::npos);
bool is_noff_file = (line.find("nOFF") != std::string::npos);
+
+
if (!is_off_file && !is_noff_file) {
std::cerr << line << std::endl;
std::cerr << "missing off header\n";
return false;
}
+ if (is_noff_file) {
+ // Should be on a separate line, but we accept it on the same line as the number of vertices
+ stream_ >> off_info_.dim;
+ } else {
+ off_info_.dim = 3;
+ }
+
if (!goto_next_uncomment_line(line)) return false;
std::istringstream iss(line);
- if ((is_off_file) && (!is_noff_file)) {
- off_info_.dim = 3;
- if (!(iss >> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)) {
- std::cerr << "incorrect number of vertices/faces/edges\n";
- return false;
- }
- } else {
- if (!(iss >> off_info_.dim >> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)) {
+ if (!(iss >> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)) {
std::cerr << "incorrect number of vertices/faces/edges\n";
return false;
- }
}
off_visitor.init(off_info_.dim, off_info_.num_vertices, off_info_.num_faces, off_info_.num_edges);
@@ -131,10 +132,12 @@ class Off_reader {
}
bool goto_next_uncomment_line(std::string& uncomment_line) {
- uncomment_line.clear();
- do
- std::getline(stream_, uncomment_line); while (uncomment_line[0] == '%');
- return (uncomment_line.size() > 0 && uncomment_line[0] != '%');
+ do {
+ // skip whitespace, including empty lines
+ if (!std::ifstream::sentry(stream_)) return false;
+ std::getline(stream_, uncomment_line);
+ } while (uncomment_line[0] == '#');
+ return (bool)stream_;
}
template<typename OffVisitor>
diff --git a/src/common/include/gudhi/Points_off_io.h b/src/common/include/gudhi/Points_off_io.h
index 29af8a8a..08f324c6 100644
--- a/src/common/include/gudhi/Points_off_io.h
+++ b/src/common/include/gudhi/Points_off_io.h
@@ -126,9 +126,9 @@ class Points_off_visitor_reader {
* \code $> ./vector_double_off_reader ../../data/points/alphacomplexdoc.off
* \endcode
*
- * the program output is:
+ * the program outputs a file ../../data/points/alphacomplexdoc.off.txt:
*
- * \include common/cgaloffreader_result.txt
+ * \include common/vectordoubleoffreader_result.txt
*/
template<typename Point_d>
class Points_off_reader {