Go to the documentation of this file.00001
00002
00003
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef _CHOMP_CUBES_CUBEBASE_H_
00038 #define _CHOMP_CUBES_CUBEBASE_H_
00039
00040 #include "chomp/system/config.h"
00041 #include "chomp/system/textfile.h"
00042 #include "chomp/cubes/pointset.h"
00043 #include "chomp/struct/bitfield.h"
00044 #include "chomp/struct/integer.h"
00045 #include "chomp/struct/hashsets.h"
00046 #include "chomp/cubes/pointbas.h"
00047 #include "chomp/cubes/cubemain.h"
00048
00049 #include <iostream>
00050 #include <fstream>
00051 #include <cstdlib>
00052 #include <cstring>
00053
00054 namespace chomp {
00055 namespace homology {
00056
00057
00058
00059 template <class coordtype>
00060 class tCellBase;
00061
00062
00063
00064
00065
00066
00071 template <class coordtype>
00072 class tCubeBase
00073 {
00074 public:
00076 typedef coordtype CoordType;
00077
00079 typedef tCellBase<coordtype> CellType;
00080
00082 static const int MaxDim = MaxBasDim;
00083
00085 typedef tPointBase<coordtype> PointBase;
00086
00088 tCubeBase ();
00089
00091 tCubeBase (const coordtype *c, int dim);
00092
00095 tCubeBase (int_t number, int dim);
00096
00098 tCubeBase (const tCubeBase<coordtype> &c);
00099
00101 tCubeBase<coordtype> &operator =
00102 (const tCubeBase<coordtype> &c);
00103
00105 int dim () const;
00106
00108
00109
00110 coordtype *coord (coordtype *c) const;
00111
00113 int_t hashkey1 () const;
00114
00116 int_t hashkey2 () const;
00117
00119 static const char *name ();
00120
00122 static const char *pluralname ();
00123
00124
00125
00127 friend inline int operator == (const tCubeBase<coordtype> &c1,
00128 const tCubeBase<coordtype> &c2)
00129 {
00130 return c1. n == c2. n;
00131 }
00132
00133
00134 friend class tCellBase<coordtype>;
00135
00136 private:
00138 int_t num () const;
00139
00143 int_t n;
00144
00145 };
00146
00147
00148
00149 template <class coordtype>
00150 inline int_t tCubeBase<coordtype>::num () const
00151 {
00152 return (n & NumMask);
00153 }
00154
00155
00156
00157 template <class coordtype>
00158 inline tCubeBase<coordtype>::tCubeBase ()
00159 : n (0)
00160 {
00161 return;
00162 }
00163
00164 template <class coordtype>
00165 inline tCubeBase<coordtype>::tCubeBase (const coordtype *c,
00166 int dim)
00167 {
00168 if (dim <= 0)
00169 throw "Non-positive dimension of a cube.";
00170 if (dim >= MaxDim)
00171 throw "Too high space dimension.";
00172 n = PointBase::number (c, dim);
00173 if (n < 0)
00174 throw "Negative number of a cube.";
00175 n |= (static_cast<int_t> (dim) << NumBits);
00176 return;
00177 }
00178
00179 template <class coordtype>
00180 inline tCubeBase<coordtype>::tCubeBase (int_t number, int dim)
00181 {
00182 n = number | (static_cast<int_t> (dim) << NumBits);
00183 return;
00184 }
00185
00186 template <class coordtype>
00187 inline tCubeBase<coordtype>::tCubeBase (const tCubeBase<coordtype> &c)
00188 {
00189 n = c. n;
00190 return;
00191 }
00192
00193 template <class coordtype>
00194 inline tCubeBase<coordtype> &tCubeBase<coordtype>::operator =
00195 (const tCubeBase<coordtype> &c)
00196 {
00197 n = c. n;
00198 return *this;
00199 }
00200
00201 template <class coordtype>
00202 inline int tCubeBase<coordtype>::dim () const
00203 {
00204 return static_cast<int> (n >> NumBits);
00205 }
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 template <class coordtype>
00219 inline coordtype *tCubeBase<coordtype>::coord (coordtype *c) const
00220 {
00221 int d = dim ();
00222 const coordtype *tab = PointBase::coord (num (), d);
00223 for (int i = 0; i < d; ++ i)
00224 c [i] = tab [i];
00225 return c;
00226 }
00227
00228 template <class coordtype>
00229 inline int_t tCubeBase<coordtype>::hashkey1 () const
00230 {
00231 return static_cast<int_t>
00232 (((n ^ 0x55555555u) << 17) ^ ((n ^ 0xAA00AA00u) << 7) ^
00233 ((n ^ 0x00AA00AAu) >> 7));
00234 }
00235
00236 template <class coordtype>
00237 inline int_t tCubeBase<coordtype>::hashkey2 () const
00238 {
00239 return static_cast<int_t>
00240 (((n ^ 0xAAAAAAAAu) << 18) ^ ((n ^ 0x55005500u) >> 8) ^
00241 ((n ^ 0x00550055u) << 10));
00242 }
00243
00244 template <class coordtype>
00245 inline const char *tCubeBase<coordtype>::name ()
00246 {
00247 return "cube";
00248 }
00249
00250 template <class coordtype>
00251 inline const char *tCubeBase<coordtype>::pluralname ()
00252 {
00253 return "cubes";
00254 }
00255
00256
00257
00259 template <class coordtype>
00260 inline int operator != (const tCubeBase<coordtype> &c1,
00261 const tCubeBase<coordtype> &c2)
00262 {
00263 return !(c1 == c2);
00264 }
00265
00266
00267
00269 template <class coordtype>
00270 inline tCubeBase<coordtype> operator * (const tCubeBase<coordtype> &c1,
00271 const tCubeBase<coordtype> &c2)
00272 {
00273 int dim1 = c1. dim (), dim2 = c2. dim ();
00274 if (dim1 + dim2 >= tCubeBase<coordtype>::MaxDim)
00275 throw "Dimension too high to concatenate coordinates.";
00276 coordtype coord [tCubeBase<coordtype>::MaxDim];
00277 c1. coord (coord);
00278 c2. coord (coord + dim1);
00279 return tCubeBase<coordtype> (coord, dim1 + dim2);
00280 }
00281
00282
00283
00287 template <class coordtype>
00288 inline std::ostream &operator << (std::ostream &out,
00289 const tCubeBase<coordtype> &c)
00290 {
00291 return WriteCube (out, c);
00292 }
00293
00297 template <class coordtype>
00298 inline std::istream &operator >> (std::istream &in, tCubeBase<coordtype> &c)
00299 {
00300 return ReadCube (in, c);
00301 }
00302
00304 template <class coordtype>
00305 inline std::istream &operator >> (std::istream &in,
00306 hashedset<tCubeBase<coordtype> > &s)
00307 {
00308 return ReadCubes (in, s);
00309 }
00310
00312 template <class coordtype>
00313 inline std::istream &operator >> (std::istream &in,
00314 mvmap<tCubeBase<coordtype>,tCubeBase<coordtype> > &m)
00315 {
00316 return ReadCubicalMap (in, m);
00317 }
00318
00319
00320 }
00321 }
00322
00323 #endif // _CHOMP_CUBES_CUBEBASE_H_
00324
00326