The Original CHomP Software
Files | Namespaces | Classes | Functions | Variables
HomologyEngines

Files

file  algstruct.h
 This file defines an algebraic data structure which is used to store the information about computed homology groups.
 
file  cubfiles.h
 This file defines various types of cubical sets whose homology can be computed by homology engines.
 
file  cubiset.h
 This file defines a very simple interface to manipulating a full cubical set represented as a bitmap for the purpose of homology computation.
 
file  engines.h
 This file defines several engines for the homology computation of cubical sets.
 
file  homology.h
 This file defines a top-level interface to a homology computation procedure of full cubical sets represented in terms of a bitmap.
 

Namespaces

namespace  chomp
 This namespace contains the entire CHomP library interface.
 

Classes

class  CubicalSet
 This class stores a full cubical set and implements some basic operations on such a set, like adding or removing cubes with given coordinates. More...
 

Functions

void ComputeBettiNumbers (const CubicalSet &s, int *result, const char *engine=0, bool quiet=false)
 Computes the Betti numbers of a full cubical set represented by an object of the class "CubicalSet". More...
 
void ComputeBettiNumbers (const void *buffer, int *sizes, int dim, int *result, const char *engine=0, const int *wrapping=0, bool quiet=false)
 Computes the Betti numbers of the given set of full cubes encoded in a binary bitmap. More...
 
 CubicalSet::CubicalSet (const int *left_coords, const int *right_coords, int dim=EMBEDDING_DIM, const int *space_wrapping=0)
 The only constructor allowed: Creates an empty cubical bitmap of the given size. More...
 
 CubicalSet::~CubicalSet ()
 The destructor. More...
 
 CubicalSet::CubicalSet (const CubicalSet &c)
 The copy constructor. More...
 
CubicalSetCubicalSet::operator= (const CubicalSet &c)
 The assignment operator. More...
 
int CubicalSet::ByteOffset (const int *coords) const
 Computes the right word offset in the buffer. More...
 
int CubicalSet::BitMask (const int *coords) const
 Computes the mask for the bit in the right word. More...
 
bool CubicalSet::Inside (const int *coords)
 Verifies whether the cube is within the bounding box. More...
 
int CubicalSet::Add (const int *coords)
 Adds a cube to the set unless the cube is outside the box. More...
 
int CubicalSet::Delete (const int *coords)
 Deletes a cube from the set. More...
 
bool CubicalSet::Contains (const int *coords) const
 Verifies whether the given cube is contained in the cubical set. More...
 
void CubicalSet::Clear ()
 Clears the bitmap and makes the cubical set empty. More...
 
void CubicalSet::ComputeBettiNumbers (int *result, const char *engine=0, bool quiet=false) const
 Computes the Betti numbers of the cubical set. More...
 

Variables

ofstreamcout fcout
 An output stream defined by M. Mrozek in the CAPD library. More...
 

Detailed Description

Function Documentation

◆ Add()

int CubicalSet::Add ( const int *  coords)
inline

Adds a cube to the set unless the cube is outside the box.

Returns 0 if the cube is within the box or -1 otherwise.

Definition at line 235 of file cubiset.h.

236{
237 if (!Inside (coords))
238 return -1;
239 buffer [ByteOffset (coords)] |= BitMask (coords);
240 return 0;
241} /* CubicalSet::Add */
unsigned char * buffer
The binary buffer for storing the cubes.
Definition: cubiset.h:97
bool Inside(const int *coords)
Verifies whether the cube is within the bounding box.
Definition: cubiset.h:223
int BitMask(const int *coords) const
Computes the mask for the bit in the right word.
Definition: cubiset.h:218
int ByteOffset(const int *coords) const
Computes the right word offset in the buffer.
Definition: cubiset.h:206

References CubicalSet::BitMask(), CubicalSet::buffer, CubicalSet::ByteOffset(), and CubicalSet::Inside().

◆ BitMask()

int CubicalSet::BitMask ( const int *  coords) const
inlineprivate

Computes the mask for the bit in the right word.

Definition at line 218 of file cubiset.h.

219{
220 return 1 << ((coords [0] - minimal [0]) & 0x07);
221} /* CubicalSet::BitMask */
int * minimal
The coordinates of the minimal vertex of the buffer box.
Definition: cubiset.h:109

References CubicalSet::minimal.

Referenced by CubicalSet::Add(), CubicalSet::Contains(), and CubicalSet::Delete().

◆ ByteOffset()

int CubicalSet::ByteOffset ( const int *  coords) const
inlineprivate

Computes the right word offset in the buffer.

Definition at line 206 of file cubiset.h.

207{
208 int offset = (coords [0] - minimal [0]) >> 3;
209 int multiply = ((sizes [0] + 31) >> 5) << 2;
210 for (int i = 1; i < dim; ++ i)
211 {
212 offset += multiply * (coords [i] - minimal [i]);
213 multiply *= sizes [i];
214 }
215 return offset;
216} /* CubicalSet::ByteOffset */
int * sizes
The sizes of the binary data in the buffer.
Definition: cubiset.h:106
int dim
The dimension of the embedding space.
Definition: cubiset.h:103

References CubicalSet::dim, CubicalSet::minimal, and CubicalSet::sizes.

Referenced by CubicalSet::Add(), CubicalSet::Contains(), and CubicalSet::Delete().

◆ Clear()

void CubicalSet::Clear ( )
inline

Clears the bitmap and makes the cubical set empty.

Definition at line 256 of file cubiset.h.

257{
258 std::memset (buffer, 0, bufsize);
259 return;
260} /* CubicalSet::Clear */
int bufsize
The actual size of the buffer.
Definition: cubiset.h:100

References CubicalSet::buffer, and CubicalSet::bufsize.

◆ ComputeBettiNumbers() [1/3]

void ComputeBettiNumbers ( const CubicalSet s,
int *  result,
const char *  engine = 0,
bool  quiet = false 
)
inline

Computes the Betti numbers of a full cubical set represented by an object of the class "CubicalSet".

Definition at line 272 of file cubiset.h.

274{
275 s. ComputeBettiNumbers (result, engine, quiet);
276 return;
277} /* ComputeBettiNumbers */
void ComputeBettiNumbers(const CubicalSet &s, int *result, const char *engine=0, bool quiet=false)
Computes the Betti numbers of a full cubical set represented by an object of the class "CubicalSet".
Definition: cubiset.h:272

References ComputeBettiNumbers().

Referenced by ComputeBettiNumbers().

◆ ComputeBettiNumbers() [2/3]

void ComputeBettiNumbers ( const void *  buffer,
int *  sizes,
int  dim,
int *  result,
const char *  engine = 0,
const int *  wrapping = 0,
bool  quiet = false 
)
inline

Computes the Betti numbers of the given set of full cubes encoded in a binary bitmap.

Parameters
buffer- a buffer that contains the bitmap which defines the cubes; each byte stores 8 subsequent positions, with lower bits corresponding to cubes placed to the left from the higher bits; the width of each line must be a multiple of 4 bytes (if the number of cubes is less than that, then the lines must be padded with zeros) - this is required by the MM* engines; the first line corresponds to pixels with the coordinates (0,0,0,...,0), (1,0,0,...,0), ..., (n,0,0,...,0); the next line in the bitmap corresponds to the pixels (0,1,0,...,0), ..., (n,1,0,...,0), etc.
sizes- a table of the sizes of the bitmap in each direction,
dim- the space dimension,
result- a table into which the result is written; its size must be at least (dim + 1),
engine- the name of a homology engine to choose; the engine is automatically selected if this is zero
wrapping- space wrapping in each direction (0 = no wrapping)
quiet- true = the function should display no messages to the standard output stream; false = show a lot of messages

Definition at line 63 of file homology.h.

66{
67 using namespace chomp::homology;
68 // turn off screen output if requested to
69 bool soutput = sout. show;
70 bool coutput = scon. show;
71 if (quiet)
72 {
73 sout. show = false;
74 scon. show = false;
75 fcout. turnOff ();
76 }
77 else
78 fcout. turnOn ();
79
80 // create a corresponding set of cubes
81 chomp::homengin::cubitmap X (reinterpret_cast<const char *> (buffer),
82 sizes, dim);
83
84 // set the space wrapping
85 if (wrapping)
86 X. setwrapping (wrapping, dim);
87
88 // find the best engine to use for the homology computation
90 if (!engine)
92
93 // another possibility: find the engine with the given name
94 else
96
97 // compute the homology of the set of cubes
99 e -> homology (X, hom);
100 sout << "The computed homology is " << hom << ".\n";
101
102 // fill in the resulting table of Betti numbers
103 int levels = hom. countLevels ();
104 for (int i = 0; i <= dim; ++ i)
105 result [i] = (i < levels) ? hom. getBetti (i) : 0;
106
107 // restore the message settings
108 chomp::homology::sout. show = soutput;
109 chomp::homology::scon. show = coutput;
110 return;
111} /* ComputeBettiNumbers */
An algebraic structure that represents a finitely generated Abelian group with gradation.
Definition: algstruct.h:68
A bitmap buffer stored in the memory, not in a file.
Definition: cubfiles.h:783
An abstract class that is inherited by all the homology engines.
Definition: engines.h:79
static const engine * find(const cubfile *X, const cubfile *Y, const engine::enginelist &elist=engine::engines)
Finds the most appropriate homology engine.
ofstreamcout fcout
An output stream defined by M. Mrozek in the CAPD library.
This namespace contains the core of the homology computation procedures and related classes and templ...
Definition: bitmaps.h:52
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
outputstream scon
The console output stream to which one should put all the junk that spoils the log file,...

References fcout, chomp::homengin::engine::find(), chomp::homology::scon, and chomp::homology::sout.

◆ ComputeBettiNumbers() [3/3]

void CubicalSet::ComputeBettiNumbers ( int *  result,
const char *  engine = 0,
bool  quiet = false 
) const
inline

Computes the Betti numbers of the cubical set.

Note: The size of the result table must be at least dim+1.

Definition at line 262 of file cubiset.h.

264{
265 ::ComputeBettiNumbers (buffer, sizes, dim, result, engine,
266 wrapping, quiet);
267 return;
268} /* CubicalSet::ComputeBettiNumbers */
int * wrapping
The space wrapping in each direction, if defined.
Definition: cubiset.h:112
void ComputeBettiNumbers(int *result, const char *engine=0, bool quiet=false) const
Computes the Betti numbers of the cubical set.
Definition: cubiset.h:262

References CubicalSet::buffer, CubicalSet::ComputeBettiNumbers(), CubicalSet::dim, CubicalSet::sizes, and CubicalSet::wrapping.

Referenced by CubicalSet::ComputeBettiNumbers().

◆ Contains()

bool CubicalSet::Contains ( const int *  coords) const
inline

Verifies whether the given cube is contained in the cubical set.

Returns 'true' if yes, 'false' if not.

Definition at line 251 of file cubiset.h.

252{
253 return buffer [ByteOffset (coords)] & BitMask (coords);
254} /* CubicalSet::Contains */

References CubicalSet::BitMask(), CubicalSet::buffer, and CubicalSet::ByteOffset().

◆ CubicalSet() [1/2]

CubicalSet::CubicalSet ( const CubicalSet c)
inline

The copy constructor.

Definition at line 168 of file cubiset.h.

169{
170 dim = c. dim;
171 bufsize = c. bufsize;
172 sizes = new int [dim];
173 minimal = new int [dim];
174 for (int i = 0; i < dim; ++ i)
175 {
176 minimal [i] = c. minimal [i];
177 sizes [i] = c. sizes [i];
178 }
179 buffer = new unsigned char [bufsize];
180 std::memcpy (buffer, c. buffer, bufsize);
181 return;
182} /* CubicalSet::CubicalSet */

References CubicalSet::buffer, CubicalSet::bufsize, CubicalSet::dim, CubicalSet::minimal, and CubicalSet::sizes.

◆ CubicalSet() [2/2]

CubicalSet::CubicalSet ( const int *  left_coords,
const int *  right_coords,
int  dim = EMBEDDING_DIM,
const int *  space_wrapping = 0 
)
inline

The only constructor allowed: Creates an empty cubical bitmap of the given size.

Definition at line 118 of file cubiset.h.

120{
121 if (dim <= 0)
122 throw "Non-positive dimension of a cubical complex.";
123 this -> dim = dim;
124 this -> sizes = new int [dim];
125 this -> minimal = new int [dim];
126 this -> wrapping = space_wrapping ? new int [dim] : 0;
127 this -> bufsize = 0;
128 for (int i = 0; i < dim; ++ i)
129 {
130 minimal [i] = left_coords [i];
131 sizes [i] = right_coords [i] - left_coords [i];
132 if (sizes [i] <= 0)
133 throw "Non-positive size of a cubical complex.";
134 if (!i)
135 {
136 sizes [0] = (sizes [0] + 63) & ~63;
137 bufsize = sizes [0] >> 3;
138 }
139 else
140 bufsize *= sizes [i];
141 }
142 if (space_wrapping)
143 {
144 for (int i = 0; i < dim; ++ i)
145 {
146 wrapping [i] = space_wrapping [i];
147 if (wrapping [i] < 0)
148 wrapping [i] = -space_wrapping [i];
149 }
150 }
151 if (bufsize <= 0)
152 throw "Wrong buffer size in a cubical complex.";
153 buffer = new unsigned char [bufsize];
154 std::memset (buffer, 0, bufsize);
155 return;
156} /* CubicalSet::CubicalSet */

References CubicalSet::buffer, CubicalSet::bufsize, CubicalSet::dim, CubicalSet::minimal, CubicalSet::sizes, and CubicalSet::wrapping.

◆ Delete()

int CubicalSet::Delete ( const int *  coords)
inline

Deletes a cube from the set.

Returns 0 if deleted or -1 if the cube is outside the box.

Definition at line 243 of file cubiset.h.

244{
245 if (!Inside (coords))
246 return -1;
247 buffer [ByteOffset (coords)] &= ~(BitMask (coords));
248 return 0;
249} /* CubicalSet::Delete */

References CubicalSet::BitMask(), CubicalSet::buffer, CubicalSet::ByteOffset(), and CubicalSet::Inside().

◆ Inside()

bool CubicalSet::Inside ( const int *  coords)
inlineprivate

Verifies whether the cube is within the bounding box.

Definition at line 223 of file cubiset.h.

224{
225 for (int i = 0; i < dim; ++ i)
226 {
227 if (coords [i] < minimal [i])
228 return false;
229 if (coords [i] >= minimal [i] + sizes [i])
230 return false;
231 }
232 return true;
233} /* CubicalSet::Inside */

References CubicalSet::dim, CubicalSet::minimal, and CubicalSet::sizes.

Referenced by CubicalSet::Add(), and CubicalSet::Delete().

◆ operator=()

CubicalSet & CubicalSet::operator= ( const CubicalSet c)
inline

The assignment operator.

Definition at line 184 of file cubiset.h.

185{
186 delete [] sizes;
187 delete [] minimal;
188 delete [] buffer;
189
190 dim = c. dim;
191 bufsize = c. bufsize;
192 sizes = new int [dim];
193 minimal = new int [dim];
194 for (int i = 0; i < dim; ++ i)
195 {
196 minimal [i] = c. minimal [i];
197 sizes [i] = c. sizes [i];
198 if (i > 0)
199 bufsize *= sizes [i];
200 }
201 buffer = new unsigned char [bufsize];
202 std::memcpy (buffer, c. buffer, bufsize);
203 return *this;
204} /* CubicalSet::operator = */

References CubicalSet::buffer, CubicalSet::bufsize, CubicalSet::dim, CubicalSet::minimal, and CubicalSet::sizes.

◆ ~CubicalSet()

CubicalSet::~CubicalSet ( )
inline

The destructor.

Definition at line 158 of file cubiset.h.

159{
160 delete [] sizes;
161 delete [] minimal;
162 delete [] buffer;
163 if (wrapping)
164 delete [] wrapping;
165 return;
166} /* CubicalSet::~CubicalSet */

References CubicalSet::buffer, CubicalSet::minimal, CubicalSet::sizes, and CubicalSet::wrapping.

Variable Documentation

◆ fcout

ofstreamcout fcout
extern

An output stream defined by M. Mrozek in the CAPD library.

Referenced by ComputeBettiNumbers().