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

Generated on Thu Jul 17 17:23:28 2008 for QVision by  doxygen 1.5.3