face_from_indices.h
1 /* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2  * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3  * Author(s): Siargey Kachanovich
4  *
5  * Copyright (C) 2019 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef PERMUTAHEDRAL_REPRESENTATION_FACE_FROM_INDICES_H_
12 #define PERMUTAHEDRAL_REPRESENTATION_FACE_FROM_INDICES_H_
13 
14 #include <cstdlib> // for std::size_t
15 #include <algorithm>
16 
17 namespace Gudhi {
18 
19 namespace coxeter_triangulation {
20 
31 template <class Permutahedral_representation, class Index_range>
32 Permutahedral_representation face_from_indices(const Permutahedral_representation& simplex,
33  const Index_range& indices) {
34  using range_index = typename Index_range::value_type;
35  using Ordered_set_partition = typename Permutahedral_representation::OrderedSetPartition;
36  using Part = typename Ordered_set_partition::value_type;
37  using part_index = typename Part::value_type;
38  Permutahedral_representation value;
39  std::size_t d = simplex.vertex().size();
40  value.vertex() = simplex.vertex();
41  std::size_t k = indices.size() - 1;
42  value.partition().resize(k + 1);
43  std::size_t l = simplex.partition().size() - 1;
44  for (std::size_t h = 1; h < k + 1; h++)
45  for (range_index i = indices[h - 1]; i < indices[h]; i++)
46  for (part_index j : simplex.partition()[i]) value.partition()[h - 1].push_back(j);
47  for (range_index i = indices[k]; i < l + 1; i++)
48  for (part_index j : simplex.partition()[i]) value.partition()[k].push_back(j);
49  for (range_index i = 0; i < indices[0]; i++)
50  for (part_index j : simplex.partition()[i]) {
51  if (j != d)
52  value.vertex()[j]++;
53  else
54  for (std::size_t l = 0; l < d; l++) value.vertex()[l]--;
55  value.partition()[k].push_back(j);
56  }
57  // sort the values in each part (probably not needed)
58  for (auto& part : value.partition()) std::sort(part.begin(), part.end());
59  return value;
60 }
61 
62 } // namespace coxeter_triangulation
63 
64 } // namespace Gudhi
65 
66 #endif
Ordered_set_partition_ OrderedSetPartition
Type of the ordered partition.
Definition: Permutahedral_representation.h:46
GUDHIdev  Version 3.5.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Wed Apr 6 2022 19:26:28 for GUDHIdev by Doxygen 1.9.1