PARP Research Group University of Murcia, Spain


src/qvmath/qvtensorindex.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008. 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 <QMap>
00029 #include <qvdefines.h>
00030 
00031 #ifndef DOXYGEN_IGNORE_THIS
00032 class QVTensorIndexRange;
00033 class QVTensorIndexValues: public QList<QVTensorIndexRange>
00034         {
00035         public:
00036                 QVTensorIndexValues(): QList<QVTensorIndexRange>()      {}
00037 
00038                 const QVTensorIndexValues operator&(const QVTensorIndexRange &indexRange) const
00039                         {
00040                         QVTensorIndexValues result = *this;
00041                         result.append(indexRange);
00042                         return result;
00043                         }
00044 
00045                 QMap<int, QVector<int> > getIndexesValues() const;
00046         };
00047 
00048 class QVTensorIndexRange
00049         {
00050         friend class QVTensorIndex;
00051 
00052         public:
00053                 int id, rangeMin, rangeMax;
00054 
00055                 QVTensorIndexRange(const QVTensorIndexRange &tensorIndexRange):
00056                         id(tensorIndexRange.id), rangeMin(tensorIndexRange.rangeMin), rangeMax(tensorIndexRange.rangeMax) { }
00057 
00058                 const QVTensorIndexValues operator&(const QVTensorIndexRange &indexRange) const
00059                         {
00060                         QVTensorIndexValues result;
00061                         result.append(*this);
00062                         result.append(indexRange);
00063                         return result;
00064                         }
00065 
00066                 operator QVTensorIndexValues() const
00067                         {
00068                         QVTensorIndexValues result;
00069                         result.append(*this);
00070                         return result;
00071                         }
00072         private:
00073                 QVTensorIndexRange(const int id, const int rangeMin, const int rangeMax):       id(id), rangeMin(rangeMin), rangeMax(rangeMax)  { }
00074         };
00075 
00077 // NOTA: identificador = -1, o 1 indica que el Ă­ndice no existe, no concuerda con ningĂșn otro.
00078 class QVTensorIndex;
00079 class QVTensorValence: public QList<QVTensorIndex>
00080         {
00081         public:
00082                 QVTensorValence(): QList<QVTensorIndex>()       {}
00083 
00084                 const QVTensorValence operator*(const QVTensorIndex &index) const
00085                         {
00086                         QVTensorValence result = *this;
00087                         result.append(index);
00088                         return result;
00089                         }
00090 
00091                 const QVTensorValence operator&(const QVTensorIndex &index) const
00092                         {
00093                         QVTensorValence result = *this;
00094                         result.append(index);
00095                         return result;
00096                         }
00097 
00098                 const QVTensorValence operator+(const QVTensorValence &indexList) const
00099                         { return *this + indexList; }
00100 
00101                 QMap<int, QVector<int> > getIndexesPositions() const;
00102         };
00103 
00104 #endif
00105 
00118 class QVTensorIndex
00119         {
00120         public:
00123                 QVTensorIndex(const int dimension): dim(dimension), id(nextIndexId++)                                                   { }
00124 
00128                 QVTensorIndex(const QVTensorIndex &tensorIndex): dim(tensorIndex.dim), id(tensorIndex.id)                                       { }
00129 
00132                 QVTensorIndex cov()             const { return QVTensorIndex(*this, true); }
00133 
00136                 QVTensorIndex covariant()       const { return QVTensorIndex(*this, true); }
00137 
00140                 QVTensorIndexRange range(const int min, const int max)  const { return QVTensorIndexRange(ABS(id), min, max); }
00141 
00144                 const QVTensorIndexRange operator[](const int value)    const { return QVTensorIndexRange(ABS(id), value, value); }
00145 
00146                 #ifndef DOXYGEN_IGNORE_THIS
00147                 QVTensorIndex(): dim(0), id(1)                                                                                          { }
00148                 QVTensorIndex(const int dimension, const int ident): dim(dimension), id(ident)                                          { }
00149                 QVTensorIndex(const QVTensorIndex &tensorIndex, bool variate): dim(tensorIndex.dim), id((variate?-1:1)*tensorIndex.id)  { }
00150 
00151                 int dim, id;
00152                 const QVTensorValence operator*(const QVTensorIndex &index) const
00153                         {
00154                         QVTensorValence result;
00155                         result.append(*this);
00156                         result.append(index);
00157                         return result;
00158                         }
00159 
00160                 bool operator==(const QVTensorIndex &index) const
00161                         { return true; }
00162 
00163                 operator QVTensorValence() const
00164                         {
00165                         QVTensorValence result;
00166                         result.append(*this);
00167                         return result;
00168                         }
00169 
00170                 const QVTensorValence operator*(const QVTensorValence &indexList) const
00171                         {
00172                         QVTensorValence result = *this;
00173                         result << indexList;
00174                         return result;
00175                         }
00176                 #endif
00177         private:
00178                 static int nextIndexId;
00179                 static QVTensorIndex anyIndex;
00180         };
00181 #endif



QVision framework. PARP research group, copyright 2007, 2008.