The ChainCon Software (Release 0.03)
cubproduct.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A function that converts a cubical cell into a simplicial set
6 /// that corresponds to the cartesian product of intervals.
7 ///
8 /////////////////////////////////////////////////////////////////////////////
9 
10 // Copyright (C) 2009-2016 by Pawel Pilarczyk.
11 //
12 // This file is part of my research software package. This is free software:
13 // you can redistribute it and/or modify it under the terms of the GNU
14 // General Public License as published by the Free Software Foundation,
15 // either version 3 of the License, or (at your option) any later version.
16 //
17 // This software is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this software; see the file "license.txt". If not,
24 // please, see <http://www.gnu.org/licenses/>.
25 
26 // Started on March 24, 2009. Last revision: August 21, 2013.
27 
28 
29 #ifndef _CHAINCON_CUBPRODUCT_H_
30 #define _CHAINCON_CUBPRODUCT_H_
31 
32 
33 // include relevant local header files
34 #include "chaincon/prodcell.h"
35 //#include "chaincon/simplex.h"
36 #include "chaincon/simplset.h"
37 
38 // include selected header files from the CHomP library
39 #include "chomp/system/config.h"
40 #include "chomp/struct/hashsets.h"
41 
42 // include some standard C++ header files
43 #include <istream>
44 #include <ostream>
45 #include <algorithm>
46 #include <vector>
47 
48 
49 // --------------------------------------------------
50 // ---------------- cube to product -----------------
51 // --------------------------------------------------
52 
53 /// Transforms an elementary cube into a simplicial set that represents
54 /// the Cartesian product of the simplicial sets corresponding to the edges
55 /// of the cube.
56 template <class CubCellT, class SetT>
57 inline void cube2product (const CubCellT &q, SetT &cells)
58 {
59  using chomp::homology::sbug;
60 
61  typedef typename SetT::value_type ProdT;
62  typedef typename ProdT::CellType SimCellT;
63  typedef typename CubCellT::CoordType CoordT;
64 
65  // note: SimCellT == tSimplex<CoordT,*,*>
66 
67  // create the simplicial sets corresponding to the edges of the cube
68  int spaceDim (q. spaceDim ());
69  std::vector<tSimplSet<SimCellT> > edgeComplexes (spaceDim);
70  for (int i = 0; i < spaceDim; ++ i)
71  {
72  CoordT coords [2];
73  coords [0] = q. left (i);
74  coords [1] = q. right (i);
75  SimCellT cell (1, coords);
76  edgeComplexes [i]. add (cell);
77  edgeComplexes [i]. addFaces (1);
78  edgeComplexes [i]. addDegenerate (0, spaceDim);
79  }
80 
81  // create product cells and normalize the result
82  std::vector<int_t> counters (spaceDim);
83  std::vector<int_t> maxCounters (spaceDim);
84  for (int i = 0; i < spaceDim; ++ i)
85  maxCounters [i] = edgeComplexes [i]. size ();
86 // for (int i = 0; i < spaceDim; ++ i)
87 // {
88 // sbug << "DEBUG: edgeComplexes [" << i << "]:\n";
89 // sbug << edgeComplexes [i];
90 // }
91  for (int dim = 0; dim <= spaceDim; ++ dim)
92  {
93  // sbug << "DEBUG: --- dimension " << dim << " ---\n";
94  // prepare the initial counters
95  for (int cur = 0; cur < spaceDim; ++ cur)
96  {
97  counters [cur] = 0;
98  while ((counters [cur] < maxCounters [cur]) &&
99  (edgeComplexes [cur] [counters [cur]].
100  dim () != dim))
101  {
102  ++ (counters [cur]);
103  }
104  if (counters [cur] >= maxCounters [cur])
105  throw "Missing cells in cube2product init.";
106  }
107  while (1)
108  {
109  // move to the nearest combination of cells of this dim
110  int cur = 0;
111  while ((counters [cur] < maxCounters [cur]) &&
112  (edgeComplexes [cur] [counters [cur]].
113  dim () != dim))
114  {
115  ++ (counters [cur]);
116  }
117  while (counters [cur] >= maxCounters [cur])
118  {
119  counters [cur] = 0;
120  while ((counters [cur] < maxCounters [cur]) &&
121  (edgeComplexes [cur] [counters [cur]].
122  dim () != dim))
123  {
124  ++ (counters [cur]);
125  }
126  if (counters [cur] >= maxCounters [cur])
127  throw "Missing cells in cube2product.";
128  ++ cur;
129  if (cur >= spaceDim)
130  break;
131  ++ (counters [cur]);
132  while ((counters [cur] < maxCounters [cur]) &&
133  (edgeComplexes [cur] [counters [cur]].
134  dim () != dim))
135  {
136  ++ (counters [cur]);
137  }
138  }
139  if (cur >= spaceDim)
140  break;
141 
142  // create the product cell
143  // sbug << "DEBUG: counters [0] = " << counters [0] << ".\n";
144  // sbug << "DEBUG: cell [0] = " << edgeComplexes [0] [counters [0]] << ".\n";
145  ProdT prodCell (edgeComplexes [0] [counters [0]]);
146  for (int i = 1; i < spaceDim; ++ i)
147  {
148  // sbug << "DEBUG: counters [" << i << "] = " << counters [i] << ".\n";
149  // sbug << "DEBUG: cell [" << i << "] = " << edgeComplexes [i] [counters [i]] << ".\n";
150  ProdT prodNew (prodCell, ProdT
151  (edgeComplexes [i] [counters [i]]));
152  prodCell. swap (prodNew);
153  }
154  cells. add (prodCell);
155 
156  // take the next combination of cells
157  ++ (counters [0]);
158  }
159  }
160 
161  return;
162 } /* cube2product */
163 
164 
165 #endif // _CHAINCON_CUBPRODUCT_H_
166 
A Cartesian product of simplicial cells of arbitrary type.
void cube2product(const CubCellT &q, SetT &cells)
Transforms an elementary cube into a simplicial set that represents the Cartesian product of the simp...
Definition: cubproduct.h:57
A simplicial set.