summaryrefslogtreecommitdiff
path: root/src/Nerve_GIC/test/test_GIC.cpp
blob: cff49372a2c986c4b496a9bd224a5361a0b8a351 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*    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):       Mathieu Carrière
 *
 *    Copyright (C) 2017  INRIA Saclay (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/>.
 */

#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "graph_induced_complex"

#include <boost/test/unit_test.hpp>
#include <cmath>  // float comparison
#include <limits>
#include <string>
#include <vector>
#include <algorithm>    // std::max
#include <gudhi/GIC.h>
#include <gudhi/distance_functions.h>
#include <gudhi/reader_utils.h>

BOOST_AUTO_TEST_CASE(check_nerve) {

  using Point = std::vector<float>;
  Gudhi::graph_induced_complex::Graph_induced_complex<Point> GIC;
  std::string cloud_file_name("data/cloud"); GIC.read_point_cloud(cloud_file_name);
  std::string graph_file_name("data/graph"); GIC.set_graph_from_file(graph_file_name);
  std::string cover_file_name("data/cover"); GIC.set_cover_from_file(cover_file_name);
  GIC.set_color_from_coordinate();
  GIC.find_Nerve_simplices(); Gudhi::graph_induced_complex::Simplex_tree stree; GIC.create_complex(stree);

  BOOST_CHECK(stree.num_vertices() == 3);
  BOOST_CHECK((stree.num_simplices()-stree.num_vertices()) == 0);
  BOOST_CHECK(stree.dimension() == 0);
}

BOOST_AUTO_TEST_CASE(check_GICMAP) {

  using Point = std::vector<float>;
  Gudhi::graph_induced_complex::Graph_induced_complex<Point> GIC;
  std::string cloud_file_name("data/cloud"); GIC.read_point_cloud(cloud_file_name); GIC.set_color_from_coordinate();
  std::string graph_file_name("data/graph"); GIC.set_graph_from_file(graph_file_name);
  std::string cover_file_name("data/cover"); GIC.set_cover_from_file(cover_file_name);
  GIC.find_GICMAP_simplices_with_functional_minimal_cover(); Gudhi::graph_induced_complex::Simplex_tree stree; GIC.create_complex(stree);

  BOOST_CHECK(stree.num_vertices() == 3);
  BOOST_CHECK((stree.num_simplices()-stree.num_vertices()) == 2);
  BOOST_CHECK(stree.dimension() == 1);
}

BOOST_AUTO_TEST_CASE(check_GICcover) {

  using Point = std::vector<float>;
  Gudhi::graph_induced_complex::Graph_induced_complex<Point> GIC;
  std::string cloud_file_name("data/cloud"); GIC.read_point_cloud(cloud_file_name); GIC.set_color_from_coordinate();
  std::string graph_file_name("data/graph"); GIC.set_graph_from_file(graph_file_name);
  std::string cover_file_name("data/cover"); GIC.set_cover_from_file(cover_file_name);
  GIC.find_GIC_simplices(); Gudhi::graph_induced_complex::Simplex_tree stree; GIC.create_complex(stree);

  BOOST_CHECK(stree.num_vertices() == 3);
  BOOST_CHECK((stree.num_simplices()-stree.num_vertices()) == 4);
  BOOST_CHECK(stree.dimension() == 2);
}


BOOST_AUTO_TEST_CASE(check_GICvoronoi) {

  using Point = std::vector<float>;
  Gudhi::graph_induced_complex::Graph_induced_complex<Point> GIC;
  std::string cloud_file_name("data/cloud"); GIC.read_point_cloud(cloud_file_name); GIC.set_color_from_coordinate();
  std::string graph_file_name("data/graph"); GIC.set_graph_from_file(graph_file_name);
  GIC.set_cover_from_Voronoi(Gudhi::Euclidean_distance(),2);
  GIC.find_GIC_simplices(); Gudhi::graph_induced_complex::Simplex_tree stree; GIC.create_complex(stree);

  BOOST_CHECK(stree.num_vertices() == 2);
  BOOST_CHECK((stree.num_simplices()-stree.num_vertices()) == 1);
  BOOST_CHECK(stree.dimension() == 1);
}