The ChainCon Software (Release 0.03)
readfcompl.h
Go to the documentation of this file.
1 /////////////////////////////////////////////////////////////////////////////
2 ///
3 /// \file
4 ///
5 /// A generic procedure for reading a filtered cell complex or a pair
6 /// of filtered cell complexes from text files.
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: September 24, 2015.
27 
28 
29 #ifndef _CHAINCON_READFCOMPL_H_
30 #define _CHAINCON_READFCOMPL_H_
31 
32 
33 // include some standard C++ header files
34 #include <istream>
35 #include <ostream>
36 
37 // include selected header files from the CHomP library
38 #include "chomp/system/config.h"
39 #include "chomp/system/textfile.h"
40 #include "chomp/system/timeused.h"
41 
42 // include relevant local header files
43 #include "chaincon/filtcomplex.h"
44 #include "chaincon/boundary.h"
45 #include "chaincon/remordered.h"
46 
47 
48 // --------------------------------------------------
49 // ------------ read filtered complexes -------------
50 // --------------------------------------------------
51 
52 /// Reads a filtered cell complex or a pair of filtered cell complexes
53 /// from text files.
54 /// Shows appropriate messages and throws an error message in case of failure.
55 template <class CellT>
56 inline void readFilteredComplexes (const char *Xname, const char *Aname,
58  bool addBoundariesX, bool addBoundariesA)
59 {
60  using chomp::homology::sout;
61 
62  // read the first filtered cell complex
63  {
64  sout << "Reading '" << Xname << "'... ";
65  std::ifstream in (Xname);
66  if (!in)
67  chomp::homology::fileerror (Xname);
68  in >> K;
69  in. close ();
70  sout << K. size () << " cells read.\n";
71  }
72 // sout << "Cells read from the input:\n" << K << "\n";
73 
74  // read the second filtered cell complex
75  if (Aname && *Aname)
76  {
77  sout << "Reading '" << Aname << "'... ";
78  std::ifstream in (Aname);
79  if (!in)
80  chomp::homology::fileerror (Aname);
81  in >> L;
82  in. close ();
83  sout << L. size () << " cells read.\n";
84  }
85 // sout << "Cells read from the input:\n" << L << "\n";
86 
87  // add boundaries to the second filtered cell complex
88  if (Aname && *Aname)
89  {
90  if (addBoundariesA)
91  {
92  sout << "Adding boundaries to '" << Aname << "'... ";
94  sout << L. size () << " cells total.\n";
95  }
96  else
97  {
98  sout << "NOT adding boundaries to '" << Aname <<
99  "'.\n";
100  sout << "Note: All the relevant boundaries of cells "
101  "are assumed to be present already.\n";
102  }
103  }
104 
105  // remove from K all the cells that appear in L
106  if (Aname && *Aname)
107  {
108  int_t prev_size = K. size ();
109  sout << "Making the filters disjoint... ";
110  removeOrdered (K, L);
111  sout << (K. size () - prev_size) << " cells removed.\n";
112  }
113 
114  // make sure that the filtered cell complex is complete
115  if (addBoundariesX)
116  {
117  sout << "Adding boundaries to '" << Xname << "'... ";
118  if (Aname && *Aname)
119  {
120  addBoundaries (K,
122  }
123  else
124  {
125  addBoundaries (K, Unrestricted ());
126  }
127  sout << K. size () << " cells total.\n";
128  }
129  else
130  {
131  sout << "NOT adding boundaries to '" << Xname << "'.\n";
132  sout << "Note: All the relevant boundaries of cells "
133  "are assumed to be present already.\n";
134  }
135 
136 // sout << "Filtered complex:\n" << K << "==========\n";
137 
138  return;
139 } /* readFilteredComplexes */
140 
141 
142 #endif // _CHAINCON_READFCOMPL_H_
143 
Boundary computation at the level of chains of cells.
void removeOrdered(Vector1T &K, const Vector2T &L)
From the given set of objects, removes another one in such a way that the order of objects in the fir...
Definition: remordered.h:49
A filtered cell complex.
A template of a simple class for negating the cell restriction given by another object for the bounda...
Definition: boundary.h:77
A filtered complex.
Definition: filtcomplex.h:53
void readFilteredComplexes(const char *Xname, const char *Aname, tFilteredComplex< CellT > &K, tFilteredComplex< CellT > &L, bool addBoundariesX, bool addBoundariesA)
Reads a filtered cell complex or a pair of filtered cell complexes from text files.
Definition: readfcompl.h:56
void addBoundaries(tFilteredComplex< CellT > &K, const CellRestrT &restr)
Adds boundaries to all the cells in the given filtered complex.
Definition: boundary.h:459
A template of a simple class for unrestricted cell selection in the boundary computation procedures...
Definition: boundary.h:56
A utility procedure for removing an ordered set from another ordered set.