src/qtensor/qtensorindex.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00024 
00025 #ifndef QVTENSORINDEX_H
00026 #define QVTENSORINDEX_H
00027 
00028 #include <QList>
00029 #include <QMap>
00030 #include <QVector>
00031 
00032 #define ABS(X)          (((X)>0)?(X):(-(X)))
00033 
00034 #ifndef DOXYGEN_IGNORE_THIS
00035 class QTensorIndexRange;
00036 class QTensorIndexValues: public QList<QTensorIndexRange>
00037         {
00038         public:
00039                 QTensorIndexValues(): QList<QTensorIndexRange>()        {}
00040 
00041                 const QTensorIndexValues operator&(const QTensorIndexRange &indexRange) const
00042                         {
00043                         QTensorIndexValues result = *this;
00044                         result.append(indexRange);
00045                         return result;
00046                         }
00047 
00048                 bool operator==(const QTensorIndexValues &indexList) const
00049                         { return true; }
00050 
00051                 QMap<int, QVector<int> > getIndexesValues() const;
00052         };
00053 
00054 class QTensorIndexRange
00055         {
00056         friend class QTensorIndex;
00057 
00058         public:
00059                 int id, rangeMin, rangeMax;
00060 
00061                 QTensorIndexRange(const QTensorIndexRange &tensorIndexRange):
00062                         id(tensorIndexRange.id), rangeMin(tensorIndexRange.rangeMin), rangeMax(tensorIndexRange.rangeMax) { }
00063 
00064                 const QTensorIndexValues operator&(const QTensorIndexRange &indexRange) const
00065                         {
00066                         QTensorIndexValues result;
00067                         result.append(*this);
00068                         result.append(indexRange);
00069                         return result;
00070                         }
00071 
00072                 operator QTensorIndexValues() const
00073                         {
00074                         QTensorIndexValues result;
00075                         result.append(*this);
00076                         return result;
00077                         }
00078         private:
00079                 QTensorIndexRange(const int id, const int rangeMin, const int rangeMax):        id(id), rangeMin(rangeMin), rangeMax(rangeMax)  { }
00080         };
00081 
00083 // NOTA: identificador = -1, o 1 indica que el Ă­ndice no existe, no concuerda con ningĂșn otro.
00084 class QTensorIndex;
00085 class QTensorValence: public QList<QTensorIndex>
00086         {
00087         public:
00088                 QTensorValence(): QList<QTensorIndex>() {}
00089 
00090                 const QTensorValence operator*(const QTensorIndex &index) const
00091                         {
00092                         QTensorValence result = *this;
00093                         result.append(index);
00094                         return result;
00095                         }
00096 
00097                 const QTensorValence operator&(const QTensorIndex &index) const
00098                         {
00099                         QTensorValence result = *this;
00100                         result.append(index);
00101                         return result;
00102                         }
00103 
00104                 bool operator==(const QTensorValence &indexList) const
00105                         {
00106                         return true;
00107                         }
00108 
00109                 const QTensorValence operator+(const QTensorValence &indexList) const
00110                         { return *this + indexList; }
00111 
00112                 //QMap<int, QVector<int> > getIndexesValues() const;
00113                 QMap<int, QVector<int> > getIndexesPositions() const;
00114         };
00115 
00116 #endif
00117 
00130 class QTensorIndex
00131         {
00132         public:
00136                 QTensorIndex(const int dimension): dim(dimension), id(nextIndexId++)                                                    { }
00137 
00141                 QTensorIndex(const QTensorIndex &tensorIndex): dim(tensorIndex.dim), id(tensorIndex.id)                                 { }
00142 
00145                 QTensorIndex cov()              const { return QTensorIndex(*this, true); }
00146 
00149                 QTensorIndex covariant()        const { return QTensorIndex(*this, true); }
00150 
00153                 QTensorIndexRange range(const int min, const int max)   const { return QTensorIndexRange(ABS(id), min, max); }
00154 
00157                 const QTensorIndexRange operator[](const int value)     const { return QTensorIndexRange(ABS(id), value, value); }
00158 
00159                 #ifndef DOXYGEN_IGNORE_THIS
00160                 QTensorIndex(): dim(0), id(1)                                                                                           { }
00161                 QTensorIndex(const int dimension, const int ident): dim(dimension), id(ident)                                           { }
00162                 QTensorIndex(const QTensorIndex &tensorIndex, bool variate): dim(tensorIndex.dim), id((variate?-1:1)*tensorIndex.id)    { }
00163 
00164                 int dim, id;
00165                 const QTensorValence operator*(const QTensorIndex &index) const
00166                         {
00167                         QTensorValence result;
00168                         result.append(*this);
00169                         result.append(index);
00170                         return result;
00171                         }
00172 
00173                 bool operator==(const QTensorIndex &index) const
00174                         { return true; }
00175 
00176                 operator QTensorValence() const
00177                         {
00178                         QTensorValence result;
00179                         result.append(*this);
00180                         return result;
00181                         }
00182 
00183                 const QTensorValence operator*(const QTensorValence &indexList) const
00184                         {
00185                         QTensorValence result = *this;
00186                         result << indexList;
00187                         return result;
00188                         }
00189                 #endif
00190         private:
00191                 static int nextIndexId;
00192                 static QTensorIndex anyIndex;
00193         };
00194 #endif

Generated on Thu Mar 13 19:18:16 2008 for QVision by  doxygen 1.5.3