• Main Page
  • Classes
  • Files
  • File List
  • File Members

chaincon/filtcomplex.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// \file
00004 ///
00005 /// A filtered cell complex.
00006 ///
00007 /////////////////////////////////////////////////////////////////////////////
00008 
00009 // Copyright (C) 2009-2011 by Pawel Pilarczyk.
00010 //
00011 // This file is part of my research software package. This is free software:
00012 // you can redistribute it and/or modify it under the terms of the GNU
00013 // General Public License as published by the Free Software Foundation,
00014 // either version 3 of the License, or (at your option) any later version.
00015 //
00016 // This software is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU General Public License
00022 // along with this software; see the file "license.txt". If not,
00023 // please, see <http://www.gnu.org/licenses/>.
00024 
00025 // Started on March 24, 2009. Last revision: April 4, 2011.
00026 
00027 
00028 #ifndef _CHAINCON_FILTCOMPLEX_H_
00029 #define _CHAINCON_FILTCOMPLEX_H_
00030 
00031 
00032 // include some standard C++ header files
00033 #include <istream>
00034 #include <ostream>
00035 
00036 // include selected header files from the CHomP library
00037 #include "chomp/system/config.h"
00038 #include "chomp/system/textfile.h"
00039 #include "chomp/struct/hashsets.h"
00040 
00041 
00042 // --------------------------------------------------
00043 // ------------- filtered cell complex --------------
00044 // --------------------------------------------------
00045 
00046 /// A filtered complex. Cells must be added to this complex
00047 /// in an order that ensures that any cell that appears in the boundary
00048 /// of another cell is added AFTER that cell.
00049 /// Contains a method for generating the boundaries of all the cells
00050 /// that were previously added to the complex.
00051 /// Then the cells can be accessed in the reversed order using operator [].
00052 template <class CellT>
00053 class tFilteredComplex
00054 {
00055 public:
00056         /// The default constructor.
00057         tFilteredComplex ();
00058 
00059         /// Adds a cell to the complex. Does not add its boundary cells.
00060         /// Returns the number of the added cell in the complex.
00061         int_t add (const CellT &c);
00062 
00063         /// Returns the size of the complex.
00064         int_t size () const;
00065 
00066         /// Returns the information on whether the complex is empty or not.
00067         bool empty () const;
00068 
00069         /// Returns the given cell in the complex in the reversed order.
00070         const CellT &operator [] (int_t n) const;
00071 
00072         /// Swaps the data with another filtered complex.
00073         void swap (tFilteredComplex<CellT> &fc);
00074 
00075 private:
00076         /// The set of all the cells in the complex in the right order.
00077         chomp::homology::hashedset<CellT> cells;
00078 
00079 }; /* class tFilteredComplex */
00080 
00081 // --------------------------------------------------
00082 
00083 template <class CellT>
00084 inline tFilteredComplex<CellT>::tFilteredComplex ():
00085         cells (1024)
00086 {
00087         return;
00088 } /* tFilteredComplex::tFilteredComplex */
00089 
00090 template <class CellT>
00091 inline int_t tFilteredComplex<CellT>::add (const CellT &c)
00092 {
00093         return cells. add (c);
00094 } /* tFilteredComplex::add */
00095 
00096 template <class CellT>
00097 inline int_t tFilteredComplex<CellT>::size () const
00098 {
00099         return cells. size ();
00100 } /* tFilteredComplex::size */
00101 
00102 template <class CellT>
00103 inline bool tFilteredComplex<CellT>::empty () const
00104 {
00105         return cells. empty ();
00106 } /* tFilteredComplex::empty */
00107 
00108 template <class CellT>
00109 inline const CellT &tFilteredComplex<CellT>::operator [] (int_t n) const
00110 {
00111         int_t size = cells. size ();
00112         if (n >= size)
00113                 throw "Wrong number of a cell in a filtered complex.";
00114         return cells [size - n - 1];
00115 } /* tFilteredComplex::operator [] */
00116 
00117 template <class CellT>
00118 inline void tFilteredComplex<CellT>::swap (tFilteredComplex<CellT> &fc)
00119 {
00120         cells. swap (fc. cells);
00121 } /* tFilteredComplex::swap */
00122 
00123 
00124 // --------------------------------------------------
00125 
00126 template <class CellT>
00127 inline void addBoundaries (tFilteredComplex<CellT> &K)
00128 {
00129         for (int_t n = 0; n < K. size (); ++ n)
00130         {
00131                 const CellT &c = K [K. size () - n - 1];
00132                 int len = c. boundaryLength ();
00133                 for (int i = 0; i < len; ++ i)
00134                 {
00135                         CellT bc (c, i);
00136                         int_t cn = K. add (bc);
00137                         if (cn < n)
00138                         {
00139                                 throw "Boundary cell appears too early "
00140                                         "in the filter.";
00141                         }
00142                 }
00143         }
00144         return;
00145 } /* addBoundaries */
00146 
00147 // --------------------------------------------------
00148 
00149 /// Writes a filtered cell complex to an output stream in the text format.
00150 template <class CellT>
00151 std::ostream &operator << (std::ostream &out,
00152         const tFilteredComplex<CellT> &C)
00153 {
00154         int_t size = C. size ();
00155         for (int_t i = 0; i < size; ++ i)
00156         {
00157                 out << C [i] << "\n";
00158         }
00159         return out;
00160 } /* operator << */
00161 
00162 /// Reads a filtered cell complex from an input stream.
00163 /// The cells are supposed to be listed in the input stream
00164 /// in the reverse order, that is, each cell should be followed
00165 /// by its boundary cells, which is not verified in this procedure.
00166 /// Reading the cells is interrupted in case of the empty cell
00167 /// (which is added to the complex if the empty cell is in use)
00168 /// or when the end of the stream is encountered.
00169 template <class CellT>
00170 std::istream &operator >> (std::istream &in, tFilteredComplex<CellT> &K)
00171 {
00172         chomp::homology::ignorecomments (in);
00173         while (!in. eof ())
00174         {
00175                 CellT s;
00176                 in >> s;
00177                 if (s. dim () < 0)
00178                 {
00179 #ifndef NO_EMPTY_CELL
00180                         K. add (s);
00181 #endif
00182                         break;
00183                 }
00184                 K. add (s);
00185         }
00186         return in;
00187 } /* operator >> */
00188 
00189 
00190 #endif // _CHAINCON_FILTCOMPLEX_H_
00191 

Generated on Tue Apr 5 2011 00:06:32 for Chain Contraction Software by  doxygen 1.7.2