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

chaincon/homgvf2.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 ///
00003 /// \file
00004 ///
00005 /// Homology gradient vector field computation: Algorithm 2, new version,
00006 /// with computing the transpose of the projection (faster).
00007 ///
00008 /////////////////////////////////////////////////////////////////////////////
00009 
00010 // Copyright (C) 2009-2011 by Pawel Pilarczyk.
00011 //
00012 // This file is part of my research software package. This is free software:
00013 // you can redistribute it and/or modify it under the terms of the GNU
00014 // General Public License as published by the Free Software Foundation,
00015 // either version 3 of the License, or (at your option) any later version.
00016 //
00017 // This software is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this software; see the file "license.txt". If not,
00024 // please, see <http://www.gnu.org/licenses/>.
00025 
00026 // Started on March 24, 2009. Last revision: March 24, 2011.
00027 
00028 
00029 #ifndef _CHAINCON_HOMGVF2_H_
00030 #define _CHAINCON_HOMGVF2_H_
00031 
00032 
00033 // include some standard C++ header files
00034 #include <istream>
00035 #include <ostream>
00036 
00037 // include selected header files from the CHomP library
00038 #include "chomp/system/config.h"
00039 #include "chomp/system/timeused.h"
00040 #include "chomp/system/textfile.h"
00041 #include "chomp/struct/hashsets.h"
00042 
00043 // include relevant local header files
00044 #include "chaincon/combchain.h"
00045 #include "chaincon/comblinmap.h"
00046 
00047 
00048 // --------------------------------------------------
00049 // ------------------ Homology GVF ------------------
00050 // --------------------------------------------------
00051 
00052 /// Computes the homology gradient vector field for the given
00053 /// filtered finite cell complex "K".
00054 /// Cells that represent homology generators are appended to the vector "H".
00055 /// The projection map "pi", the inclusion from "H" to the complex "K",
00056 /// and the homology gradient vector field "phi"
00057 /// are assumed to be initially zero and are constructed.
00058 template <class CellT, class CellArray1, class CellArray2>
00059 void homologyGVF2 (const CellArray1 &K, CellArray2 &H,
00060         tCombLinMap<CellT,CellT> &pi,
00061         tCombLinMap<CellT,CellT> &incl,
00062         tCombLinMap<CellT,CellT> &phi)
00063 {
00064         using chomp::homology::sout;
00065         using chomp::homology::scon;
00066 
00067         // don't do anything for an empty complex
00068         if (K. empty ())
00069                 return;
00070 
00071         // show a message indicating what is being computed
00072         sout << "Computing a homology gradient vector field...\n";
00073 
00074         // start measuring computation time
00075         chomp::homology::timeused compTime;
00076         compTime = 0;
00077 
00078         // prepare a set of cells that represent homology generators
00079         chomp::homology::hashedset<CellT> homGener;
00080 
00081         // prepare the transpose of the projection pi
00082         tCombLinMap<CellT,CellT> piT;
00083 
00084         // process all the remaining cells in the filter
00085         int_t KSize = K. size ();
00086         for (int_t i = 0; i < KSize; ++ i)
00087         {
00088                 // show progress indicator
00089                 if (!(i % 17))
00090                         scon << i << " out of " << KSize << ", " <<
00091                                 (i * 100 / KSize) << "% done.\r";
00092 
00093                 // retrieve the i-th cell in the filter
00094                 const CellT &c = K [i];
00095 
00096                 // compute the modified cell
00097                 tCombChain<CellT> ch (c);
00098                 ch. add (phi (boundary (c)));
00099 
00100                 // compute the boundary of the modified cell
00101                 tCombChain<CellT> bd_ch (boundary (ch));
00102 
00103                 // if the boundary is zero
00104                 if (bd_ch. empty ())
00105                 {
00106                         // add this cell to the set of homology representants
00107                         homGener. add (c);
00108 
00109                         // define the inclusion for this cell
00110                         incl. add (c, ch);
00111 
00112                         // define the projection on this cell
00113                         pi. add (c, c);
00114                         piT. add (c, c);
00115 
00116                         // skip the rest
00117                         continue;
00118                 }
00119 
00120                 // project the boundary onto the homology generators
00121                 tCombChain<CellT> d (pi (bd_ch));
00122                 int_t dsize = d. size ();
00123 
00124                 // make sure that this projection is nontrivial
00125                 if (d. empty ())
00126                 {
00127                         sout << "Debug: c = " << c << ".\n";
00128                         sout << "Debug: bd_c = " << boundary (c) <<
00129                                 ".\n";
00130                         sout << "Debug: ch = " << ch << ".\n";
00131                         sout << "Debug: bd_ch = " << bd_ch << ".\n";
00132                         throw "Empty boundary in the homology algorithm.";
00133                 }
00134 
00135                 // choose any element of this boundary
00136                 const CellT &u = d [0];
00137 
00138                 // go through all the cells which have this element
00139                 // in their image by pi
00140                 tCombChain<CellT> piTu (piT (u));
00141                 int_t size = piTu. size ();
00142                 for (int_t j = 0; j < size; ++ j)
00143                 {
00144                         // retrieve the j-th cell
00145                         const CellT &cj = piTu [j];
00146 
00147                         // compute new phi (cj) by adding ch to it
00148                         phi. add (cj, ch);
00149 
00150                         // retrieve the image of the cell cj for editing
00151                         tCombChain<CellT> &picj = pi. getImage (cj);
00152 
00153                         // remember the previous image of cj by pi
00154                         tCombChain<CellT> prev (picj);
00155 
00156                         // compute the new image of cj by the projection
00157                         picj. add (d);
00158 
00159                         // update the transpose of the projection
00160                         for (int_t k = 0; k < dsize; ++ k)
00161                         {
00162                                 // if this cell is in the new pi (cj)
00163                                 if (picj. contains (d [k]))
00164                                 {
00165                                         // if it wasn't there before
00166                                 //      if (!prev. contains (d [k]))
00167                                         // add it to the transposed matrix
00168                                         piT. add (d [k], cj);
00169                                 }
00170                                 // if this cell disapeared from pi (cj)
00171                                 else
00172                                 {
00173                                         // remove it from the transpose of pi
00174                                         piT. add (d [k], cj);
00175                                 }
00176                         }
00177                 }
00178 
00179                 // remove the cell from the set of homology representants
00180                 homGener. remove (u);
00181                 incl. remove (u);
00182                 piT. remove (u);
00183         }
00184 
00185         // copy the computed homology generators
00186         int_t genSize = homGener. size ();
00187         for (int_t i = 0; i < genSize; ++ i)
00188                 H. push_back (homGener [i]);
00189 
00190         // show information on the computation time
00191         sout << "Homology gvf computed in " << compTime << ".\n";
00192 
00193         return;
00194 } /* homologyGVF2 */
00195 
00196 
00197 #endif // _CHAINCON_HOMGVF2_H_
00198 

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