PARP Research Group University of Murcia, Spain


src/qvmath/qvtensorindex.h

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



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