CVR-Lib last update 20 Sep 2009

cvrLattice2D.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998-2004
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  * Copyright (C) 2007-2008
00005  * Pablo Alvarado
00006  *
00007  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00008  *
00009  * The CVR-Lib is free software; you can redistribute it and/or
00010  * modify it under the terms of the BSD License.
00011  *
00012  * All rights reserved.
00013  *
00014  * Redistribution and use in source and binary forms, with or without
00015  * modification, are permitted provided that the following conditions are met:
00016  *
00017  * 1. Redistributions of source code must retain the above copyright notice,
00018  *    this list of conditions and the following disclaimer.
00019  *
00020  * 2. Redistributions in binary form must reproduce the above copyright notice,
00021  *    this list of conditions and the following disclaimer in the documentation
00022  *    and/or other materials provided with the distribution.
00023  *
00024  * 3. Neither the name of the authors nor the names of its contributors may be
00025  *    used to endorse or promote products derived from this software without
00026  *    specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00029  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00032  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00033  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00034  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00035  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00036  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00037  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00038  * POSSIBILITY OF SUCH DAMAGE.
00039  */
00040 
00041 /**
00042  * \file   cvrLattice2D.h
00043  *         Declares the mathematical version of genericLattice2D, which also
00044  *         provides some arithmetical operations and extrems search methods.
00045  * \author Pablo Alvarado
00046  * \date   17.01.2008
00047  *
00048  * $Id: cvrLattice2D.h,v 1.13 2007/09/14 17:17:43 alvarado Exp $
00049  */
00050 
00051 #ifndef _CVR_LATTICE_2D_H_
00052 #define _CVR_LATTICE_2D_H_
00053 
00054 #include "cvrTypes.h"
00055 #include "cvrLattice1D.h"
00056 
00057 #define _CVR_GENERIC_LATTICE_2_D_DONT_INSTANTIATE_REQUEST 1
00058 #include "cvrGenericLattice2D.h"
00059 #undef _CVR_GENERIC_LATTICE_2_D_DONT_INSTANTIATE_REQUEST
00060 
00061 namespace cvr {
00062   /**
00063    * Container class for two dimensional lattices with arithmetical operations.
00064    *
00065    * The cvr::lattice2D class is a container class implemented as a
00066    * template, but explicitelly instantiated to a set of commonly used types:
00067    * - ubyte
00068    * - byte
00069    * - char
00070    * - uint16
00071    * - int16
00072    * - int32
00073    * - uint32
00074    * - long
00075    * - float
00076    * - double
00077    * - rgbaPixel
00078    * - frgbPixel
00079    * - ipoint
00080    * - fpoint
00081    * - dpoint
00082    * - ipoint3D
00083    * - fpoint3D
00084    * - dpoint3D
00085    * - fcomplex
00086    * - dcomplex
00087    *
00088    * If you need a container for other type, use cvr::genericLattice2D instead.
00089    *
00090    * The cvr::genericLattice2D class allows the representation of two
00091    * dimensional lattice, containing an element at each point of the lattice.
00092    * The points are inidicated with an ordered pair \e n x \e m, where n and m
00093    * can be taken from intervals selected at construction time, that may
00094    * include negative values. 
00095    *
00096    * This class is similar to a cvr::matrix, but allows indexing with negative
00097    * values as well, a feature useful in the representation of filter kernels
00098    * or image masks.  It can also be seen as a special type of
00099    * cvr::genericLattice2D to which a set of arithmetical and simple linear
00100    * algebra operations has been added.
00101    *
00102    * @ingroup gLinearAlgebra
00103    * @ingroup gAggregate
00104    */
00105   template<typename T>
00106   class lattice2D : public genericLattice2D<T> {
00107   public:
00108 
00109     /**
00110      * @name Internal classes and types
00111      */
00112     //@{
00113 
00114     /**
00115      * Type of the contained data
00116      */
00117     typedef typename genericLattice2D<T>::value_type value_type;
00118 
00119     /**
00120      * Return type of the size() member
00121      */
00122     typedef typename genericLattice2D<T>::size_type size_type;
00123 
00124     /**
00125      * The row type of a cvr::lattice2D is a cvr::vector
00126      */
00127     typedef lattice1D<T> row_type;
00128 
00129     /**
00130      * Pointer to value_type
00131      */
00132     typedef typename genericLattice2D<T>::pointer pointer;
00133 
00134     /**
00135      * Const pointer to value_type
00136      */
00137     typedef typename genericLattice2D<T>::const_pointer const_pointer;
00138     
00139     /**
00140      * Reference to value_type
00141      */
00142     typedef typename genericLattice2D<T>::reference reference;
00143 
00144     /**
00145      * Const reference to value_type
00146      */
00147     typedef typename genericLattice2D<T>::const_reference const_reference;
00148 
00149     /**
00150      * Iterator
00151      */
00152     typedef typename genericLattice2D<T>::iterator iterator;
00153 
00154     /**
00155      * Const iterator
00156      */
00157     typedef typename genericLattice2D<T>::const_iterator const_iterator;
00158 
00159     //@}
00160 
00161     /**
00162      * Default constructor creates an empty lattice2D
00163      */
00164     lattice2D();
00165 
00166     /**
00167      * Create a lattice2D with uninitialized elements.
00168      *
00169      * @param fromRow lowest row index
00170      * @param fromCol lowest column index
00171      * @param toRow highest row index (inclusive)
00172      * @param toCol highest column index (inclusive)
00173      */
00174     lattice2D(const int fromRow,
00175               const int fromCol,
00176               const int toRow,
00177               const int toCol);
00178     
00179     /**
00180      * Create a \a rows x \a cols lattice2D with uninitialized elements.
00181      *
00182      * @param from lowest index
00183      * @param to   highest index (inclusive)
00184      */
00185     lattice2D(const size_type& from,
00186               const size_type& to);
00187 
00188     /**
00189      * Create a lattice2D with uninitialized elements.
00190      *
00191      * @param rows interval used for the rows
00192      * @param columns interval used for the columns
00193      */
00194     lattice2D(const iinterval& rows,
00195               const iinterval& columns);
00196 
00197     /**
00198      * Create a lattice2D and initialize all elements with the given
00199      * value.
00200      *
00201      * @param fromRow lowest row index
00202      * @param fromCol lowest column index
00203      * @param toRow highest row index (inclusive)
00204      * @param toCol highest column index (inclusive)
00205      * @param value value used for initializing the elements
00206      */
00207     lattice2D(const int fromRow,
00208               const int fromCol,
00209               const int toRow,
00210               const int toCol,
00211               const T& value);
00212     
00213     /**
00214      * Create a lattice2D and initialize all elements with the given
00215      * value.
00216      *
00217      * @param from lowest index
00218      * @param to   highest index (inclusive)
00219      * @param value value used for initializing the elements
00220      */
00221     lattice2D(const size_type& from,
00222               const size_type& to,
00223               const T& value);
00224     
00225     /**
00226      * Create a lattice2D and initialize all elements with the given
00227      * value.
00228      *
00229      * @param rows interval used for the rows
00230      * @param columns interval used for the columns
00231      * @param value value used for initializing the elements
00232      */
00233     lattice2D(const iinterval& rows,
00234               const iinterval& columns,
00235               const T& value);
00236     
00237     /**
00238      * Create a lattice2D and initialize all elements with the data
00239      * pointed by \a data.
00240      *
00241      * The first elements of the data will be \b copied on the
00242      * first row, the next ones on the second row and so on.
00243      *
00244      * @param fromRow lowest row index
00245      * @param fromCol lowest column index
00246      * @param toRow highest row index (inclusive)
00247      * @param toCol highest column index (inclusive)
00248      * @param data pointer to the memory block with the data to be initialized
00249      *             with.
00250      */
00251     lattice2D(const int fromRow,
00252               const int fromCol,
00253               const int toRow,
00254               const int toCol,
00255               const T data[]);
00256     
00257     /**
00258      * Create a lattice2D and initialize all elements with the data
00259      * pointed by \a data.
00260      *
00261      * The first elements of the data will be \b copied on the
00262      * first row, the next ones on the second row and so on.
00263      *
00264      * @param from lowest index
00265      * @param to   highest index (inclusive)
00266      * @param data pointer to the memory block with the data to be initialized
00267      *             with.
00268      */
00269     lattice2D(const size_type& from,
00270               const size_type& to,
00271               const T data[]);
00272     
00273     /**
00274      * Create a lattice2D and initialize all elements with the data
00275      * pointed by \a data.
00276      *
00277      * The first elements of the data will be \b copied on the
00278      * first row, the next ones on the second row and so on.
00279      *
00280      * @param rows interval used for the rows
00281      * @param columns interval used for the columns
00282      * @param data pointer to the memory block with the data to be initialized
00283      *             with.
00284      */
00285     lattice2D(const iinterval& rows,
00286               const iinterval& columns,
00287               const T data[]);
00288     
00289     /**
00290      * Create a lattice2D and use the given \a data as if it was given
00291      * through the useExternData().
00292      *
00293      * @see useExternData()
00294      *
00295      * The first elements of the data will be copied on the first row, the next
00296      * ones on the second row and so on.
00297      *
00298      * \note Please observe that the last argument makes a huge difference to
00299      * the constructors that do not have it.  Here the data is \b not copied,
00300      * just a reference is kept.  Without the last argument, the data is
00301      * always copied.
00302      *
00303      * @param fromRow lowest row index
00304      * @param fromCol lowest column index
00305      * @param toRow highest row index (inclusive)
00306      * @param toCol highest column index (inclusive)
00307      * @param data pointer to the memory block with the data to be initialized
00308      *            with.
00309      * @param constRef usually you want this value to be ConstantReference.
00310      */
00311     lattice2D(const int fromRow,
00312               const int fromCol,
00313               const int toRow,
00314               const int toCol,
00315               T data[],
00316               const eConstantReference constRef);
00317     
00318     /**
00319      * Create a lattice2D and use the given \a data as if it was given
00320      * through the useExternData().
00321      *
00322      * @see useExternData()
00323      *
00324      * The first elements of the data will be copied on the first row, the next
00325      * ones on the second row and so on.
00326      *
00327      * \note Please observe that the last argument makes a huge difference to
00328      * the constructors that do not have it.  Here the data is \b not copied,
00329      * just a reference is kept.  Without the last argument, the data is
00330      * always copied.
00331      *
00332      * @param from lowest index
00333      * @param to highest index (inclusive)
00334      * @param data pointer to the memory block with the data to be initialized
00335      *            with.
00336      * @param constRef usually you want this value to be ConstantReference.
00337      */
00338     lattice2D(const size_type& from,
00339               const size_type& to,
00340               T data[],
00341               const eConstantReference constRef);
00342 
00343 
00344     /**
00345      * Create a lattice2D and use the given \a data as if it was given
00346      * through the useExternData().
00347      *
00348      * @see useExternData()
00349      *
00350      * The first elements of the data will be copied on the first row, the next
00351      * ones on the second row and so on.
00352      *
00353      * \note Please observe that the last argument makes a huge difference to
00354      * the constructors that do not have it.  Here the data is \b not copied,
00355      * just a reference is kept.  Without the last argument, the data is
00356      * always copied.
00357      *
00358      * @param rows interval for rows
00359      * @param columns interval for columns
00360      * @param data pointer to the memory block with the data to be initialized
00361      *            with.
00362      * @param constRef usually you want this value to be ConstantReference.
00363      */
00364     lattice2D(const iinterval& rows,
00365               const iinterval& columns,
00366               T data[],
00367               const eConstantReference constRef);
00368 
00369     /**
00370      * Copy constructor.
00371      *
00372      * Create this lattice2D as a copy of another lattice2D.
00373      *
00374      * @param other the lattice2D to be copied.
00375      */
00376     lattice2D(const genericLattice2D<T>& other);
00377 
00378     /**
00379      * Copy constructor.
00380      *
00381      * Create this lattice2D as a copy of another lattice2D for
00382      * this const version, the data will be always copied!
00383      *
00384      * @param other the genericLattice2D to be copied.
00385      * @param fromRow initial row of the other genericLattice2D to be copied
00386      * @param fromCol initial column of the other genericLattice2D to be copied
00387      * @param toRow last row to be copied of the other genericLattice2D
00388      * @param toCol last column to be copied of the other genericLattice2D
00389      */
00390     lattice2D(const genericLattice2D<T>& other,
00391               const int fromRow,
00392               const int fromCol,
00393               const int toRow=container::MaxIndex,
00394               const int toCol=container::MaxIndex);
00395     
00396     /**
00397      * Copy constructor.
00398      *
00399      * Create this lattice2D as a copy of a section of another lattice2D
00400      *
00401      * @param other the genericLattice2D to be copied.
00402      * @param from initial position in the other genericLattice2D to be copied
00403      * @param to last position to be copied of the other genericLattice2D
00404      */
00405     lattice2D(const genericLattice2D<T>& other,
00406               const size_type& from,
00407               const size_type& to);
00408 
00409     /**
00410      * Copy constructor.
00411      *
00412      * Create this lattice2D as a copy of a sublattice2D of another
00413      * genericLattice2D.
00414      *
00415      * @param other the genericLattice2D to be copied.
00416      * @param rows interval of rows to be copied.
00417      * @param columns interval of columns to be copied.
00418      */
00419     lattice2D(const genericLattice2D<T>& other,
00420               const iinterval& rows,
00421               const iinterval& columns);
00422 
00423     /**
00424      * Copy constructor.
00425      *
00426      * Create this lattice2D as a copy of another genericLattice2D
00427      * taking only the rows indicated by the vector.
00428      *
00429      * The data will be always copied!  Multiple occurence of one row index in
00430      * \a rows is allowed.
00431      *
00432      * @param other the genericLattice2D to be copied.
00433      * @param rows indices of the rows to be copied
00434      */
00435     lattice2D(const genericLattice2D<T>& other,
00436               const genericLattice1D<int>& rows);
00437 
00438     /**
00439      * Destructor
00440      */
00441     virtual ~lattice2D();
00442 
00443     /**
00444      * Return lattice2D-row as a vector.
00445      *
00446      * This method works fast, since it returns a reference to the row vector.
00447      * The data will NOT be copied.
00448      * @param row the row to be accessed
00449      * @return a reference to the vector row
00450      */
00451     inline row_type& getRow(const int row);
00452 
00453     /**
00454      * Return lattice2D-row as a const vector.
00455      *
00456      * This method works fast, since it returns a reference to the row vector.
00457      * The data will NOT be copied.
00458      * @param row the row to be accessed
00459      * @return a const reference to the vector row
00460      */
00461     inline const row_type& getRow(const int row) const;
00462 
00463     /**
00464      * Alias for getRow()
00465      */
00466     inline row_type& operator[](const int row);
00467 
00468     /**
00469      * Alias for getRow()
00470      */
00471     inline const row_type& operator[](const int row) const;
00472 
00473     /**
00474      * Return lattice2D-row as a vector.
00475      * This method copies the data of the lattice2D, therefore is not as
00476      * fast as getRow()
00477      * @param row the number of tthe row to be copied
00478      * @return a vector with the contents of the row of the lattice2D
00479      */
00480     inline row_type getRowCopy(const int row) const;
00481 
00482     /**
00483      * Copy a row vector in the given parameter.
00484      *
00485      * This method copies the data of a given row of the genericLattice2D
00486      * in the given vector.
00487      *
00488      * @param row the number of the row to be copied
00489      * @param theRow the vector, where the data will be copied
00490      * @see getRow()
00491      */
00492     inline void getRowCopy(const int row,row_type& theRow) const;
00493 
00494     /**
00495      * Return lattice2D-column as a vector.
00496      * This method copies the data of the lattice2D, therefore is not as
00497      * fast as getRow()
00498      * @param col the number of the column to be copied
00499      * @return a vector with the contents of the column of the lattice2D
00500      */
00501     inline row_type getColumnCopy(const int col) const;
00502 
00503     /**
00504      * Return genericLattice2D-column as a vector.
00505      * This method copies the data of the genericLattice2D, therefore is not as
00506      * fast as getRow()
00507      * @param col the number of the column to be copied
00508      * @param theCol a vector, where the column vector of the genericLattice2D
00509      *               should be copied.
00510      */
00511     inline void getColumnCopy(const int col,row_type& theCol) const;
00512 
00513     /**
00514      * Assigment operator.
00515      *
00516      * Copy the contents of \a other in this object.
00517      *
00518      * The result of the copy is always a connected lattice2D.  I.e. you cannot
00519      * copy the sub-lattice2D property of another lattice2D.
00520      *
00521      * @param other the other lattice2D to be copied
00522      */
00523     inline lattice2D<T>& copy(const genericLattice2D<T>& other);
00524 
00525     /**
00526      * Assigment operator.
00527      *
00528      * copy the contents of \a other in this object.
00529      *
00530      * The result of the copy is always a connected lattice2D.  I.e. you cannot
00531      * copy the sub-lattice2D property of another lattice2D.
00532      *
00533      * @param other the other lattice2D to be copied
00534      * @param fromRow initial row of the other lattice2D to be copied
00535      * @param fromCol initial column of the other lattice2D to be copied
00536      * @param toRow last row to be copied of the other lattice2D
00537      * @param toCol last column to be copied of the other lattice2D
00538      */
00539     inline lattice2D<T>& copy(const genericLattice2D<T>& other,
00540                               const int fromRow,
00541                               const int fromCol,
00542                               const int toRow=container::MaxIndex,
00543                               const int toCol=container::MaxIndex);
00544 
00545     /**
00546      * Assigment operator.
00547      *
00548      * copy the contents of \a other in this object.
00549      *
00550      * The result of the copy is always a connected lattice2D.  I.e. you cannot
00551      * copy the sub-lattice2D property of another lattice2D.
00552      *
00553      * @param other the other lattice2D to be copied
00554      * @param from initial indices of sublattice2D to be copied
00555      * @param to   final indices of sublattice2D to be copied (included)
00556      */
00557     inline lattice2D<T>& copy(const genericLattice2D<T>& other,
00558                               const size_type& from,
00559                               const size_type& to);
00560 
00561 
00562     /**
00563      * Assigment operator.
00564      *
00565      * copy the contents of \a other in this object.
00566      *
00567      * The result of the copy is always a connected lattice2D.  I.e. you cannot
00568      * copy the sub-lattice2D property of another lattice2D.
00569      *
00570      * @param other the other lattice2D to be copied
00571      * @param r interval used for the rows
00572      * @param c interval used for the columns
00573      */
00574     inline lattice2D<T>& copy(const genericLattice2D<T>& other,
00575                               const iinterval& r,
00576                               const iinterval& c);
00577 
00578     /**
00579      * Assigment operator.
00580      *
00581      * Copy the contents of \a other in this object.
00582      *
00583      * The result of the copy is always a connected lattice2D.  I.e. you cannot
00584      * copy the sub-lattice2D property of another lattice2D.
00585      *
00586      * @param other the other lattice2D to be copied
00587      * @param window rectangle define the copy area
00588      */
00589     inline lattice2D<T>& copy(const genericLattice2D<T>& other,
00590                               const irectangle& window);
00591 
00592     /**
00593      * Assigment operator.
00594      *
00595      * Copy the contents of the specified rows of
00596      * \a other into this object. Multiple occurence of one
00597      * row index in \a idx is allowed.
00598      *
00599      * @param other the other lattice2D to be copied
00600      * @param idx indices of the rows to be copied.
00601      */
00602     inline lattice2D<T>& copyRows(const genericLattice2D<T>& other,
00603                                   const genericLattice1D<int>& idx);
00604 
00605     /**
00606      * Assigment operator.
00607      *
00608      * Copy the contents of the specified columns of
00609      * \a other into this object. Multiple occurence of one
00610      * column index in \a idx is allowed.
00611      *
00612      * @param other the other lattice2D to be copied
00613      * @param idx indices of the rows to be copied.
00614      */
00615     inline lattice2D<T>& copyColumns(const genericLattice2D<T>& other,
00616                                      const genericLattice1D<int>& idx);
00617 
00618 
00619     /**
00620      * Copy the \a other lattice2D by casting each of its elements
00621      * Example:
00622      * \code
00623      *   cvr::lattice2D<int> matA(10,10,1);// a lattice2D of integers
00624      *   cvr::lattice2D<double> matB;      // a lattice2D of doubles
00625      *
00626      *   matB.castFrom(matA);          // this will copy matA in matB!!
00627      * \endcode
00628      *
00629      * @param other The lattice2D to be casted
00630      * @returns reference to this lattice2D
00631      */
00632     template<typename U>
00633     inline lattice2D<T>& castFrom(const genericLattice2D<U>& other);
00634 
00635     /**
00636      * Copy the \a other lattice2D by casting each of its elements. This
00637      * 'specialization' ensures that the copy() method is used when
00638      * U==T.
00639      *
00640      * @param other The lattice2D to be casted (copied)
00641      */
00642     inline lattice2D<T>& castFrom(const genericLattice2D<T>& other);
00643 
00644     /**
00645      * Copy a sublattice2D of the \a other genericLattice2D by casting each of
00646      * its elements.
00647      *
00648      * @param other The genericLattice2D to be casted
00649      * @param fromRow initial row of the other genericLattice2D to be copied
00650      * @param fromCol initial column of the other genericLattice2D to be copied
00651      * @param toRow last row to be copied of the other genericLattice2D
00652      * @param toCol last column to be copied of the other genericLattice2D
00653      *
00654      * @return a reference to the current casted lattice2D.
00655      */
00656     template<typename U>
00657     inline lattice2D<T>& castFrom(const genericLattice2D<U>& other,
00658                                   const int fromRow,
00659                                   const int fromCol,
00660                                   const int toRow=container::MaxIndex,
00661                                   const int toCol=container::MaxIndex);
00662 
00663     /**
00664      * This is just an alias for copy(const genericLattice2D<T>&, const int
00665      * fromRow, const int fromCol, const int toRow, const int toCol) to
00666      * facilitate generic programming.
00667      *
00668      * @param other The genericLattice2D to be copied.
00669      * @param fromRow initial row of the other genericLattice2D to be copied
00670      * @param fromCol initial column of the other genericLattice2D to be copied
00671      * @param toRow last row to be copied of the other genericLattice2D
00672      * @param toCol last column to be copied of the other genericLattice2D
00673      *
00674      * @return a reference to the current casted lattice2D.
00675      */
00676     lattice2D<T>& castFrom(const genericLattice2D<T>& other,
00677                            const int fromRow,
00678                            const int fromCol,
00679                            const int toRow=container::MaxIndex,
00680                            const int toCol=container::MaxIndex);
00681 
00682     /**
00683      * Returns the name of this class.
00684      */
00685     const std::string& name() const;
00686 
00687     /**
00688      * Create a clone of this lattice2D
00689      * @return a pointer to a copy of this lattice2D
00690      */
00691     virtual lattice2D<T>* clone() const;
00692 
00693     /**
00694      * Create a new empty lattice2D
00695      * @return a pointer to a copy of this lattice2D
00696      */
00697     virtual lattice2D<T>* newInstance() const;
00698 
00699     /**
00700      * Compare this lattice2D with other, and use the given tolerance to
00701      * determine if the value of each element of the other lattice2D
00702      * approximately equals the values of the actual lattice2D elements.
00703      *
00704      * An element <i>x</i> is approximately equal to another element <i>y</i>
00705      * with a tolerance <i>t</i>, if following equation holds:
00706      * <i>x</i>-t < <i>y</i> < <i>x</i>+t
00707      *
00708      * This method is mainly used for matrices containing floating point
00709      * values.
00710      *
00711      * @param other the other lattice2D to be compared with
00712      * @param tolerance the tolerance to be used
00713      *
00714      * @return true if both matrices are approximatly equal
00715      */
00716     bool prettyCloseTo(const genericLattice2D<T>& other,
00717                        const T& tolerance) const;
00718 
00719     /**
00720      * Assigment operator (alias for copy(other)).
00721      * @param other the lattice2D to be copied
00722      * @return a reference to the actual lattice2D
00723      */
00724     inline lattice2D<T>& operator=(const genericLattice2D<T>& other);
00725 
00726     /**
00727      * @name Apply Methods.
00728      *
00729      * Following methods are used to apply simple functions to each element
00730      * of the vector.
00731      */
00732     //@{
00733 
00734     /**
00735      * Applies a C-function to each element of the lattice2D.
00736      * @param function a pointer to a C-function
00737      * @return a reference to the actual lattice2D
00738      */
00739     inline lattice2D<T>& apply(T (*function)(T));
00740 
00741     /**
00742      * Applies a C-function to each element of the other lattice2D
00743      * @param other the lattice2D which elements will go through the given
00744      *              function.
00745      * @param function a pointer to a C-function
00746      * @return a reference to the actual lattice2D
00747      */
00748     inline lattice2D<T>& apply(const genericLattice2D<T>& other,
00749                                T (*function)(T));
00750 
00751     /**
00752      * Applies a C-function to each element of the lattice2D.
00753      * @param function a pointer to a C-function
00754      * @return a reference to the actual lattice2D
00755      */
00756     inline lattice2D<T>& apply(T (*function)(const T&));
00757 
00758     /**
00759      * Applies a C-function to each element of the other lattice2D
00760      * @param other the lattice2D which elements will go through the given
00761      *              function.
00762      * @param function a pointer to a C-function
00763      * @return a reference to the actual lattice2D
00764      */
00765     inline lattice2D<T>& apply(const genericLattice2D<T>& other,
00766                                T (*function)(const T&));
00767 
00768     /**
00769      * A two-parameter C-function receives the i-th elements of this
00770      * and the given lattice2D and the result will be left in this
00771      * lattice2D.  Note that both matrices must have the same size!
00772      * @param other the second lattice2D to be considered (the first
00773      *              lattice2D will be this object!)
00774      * @param function a pointer to C-function with two parameters
00775      * @return a reference to the actual lattice2D
00776      */
00777     inline lattice2D<T>& apply(const genericLattice2D<T>& other,
00778                                T (*function)(const T&,const T&));
00779 
00780     /**
00781      * A two-parameter C-function receives the i-th elements of this
00782      * and the given lattice2D and the result will be left in this
00783      * lattice2D.  Note that both matrices must have the same size!
00784      * @param other the second lattice2D to be considered (the first
00785      *              lattice2D will be this object!)
00786      * @param function a pointer to C-function with two parameters
00787      * @return a reference to the actual lattice2D
00788      */
00789     inline lattice2D<T>& apply(const genericLattice2D<T>& other,
00790                                T (*function)(T,T));
00791 
00792     /**
00793      * A two-parameter C-function receives the i-th elements of both given
00794      * matrices and leaves the result here.
00795      * Note that both matrices must have the same size!
00796      * @param a the first lattice2D
00797      * @param b the second lattice2D
00798      * @param function a pointer to C-function with two parameters
00799      * @return a reference to the actual lattice2D
00800      */
00801     inline lattice2D<T>& apply(const genericLattice2D<T>& a,
00802                                const genericLattice2D<T>& b,
00803                                T (*function)(const T&,const T&));
00804 
00805     /**
00806      * A two-parameter C-function receives the i-th elements of both given
00807      * matrices and leaves the result here.
00808      * Note that both matrices must have the same size!
00809      * @param a the first lattice2D
00810      * @param b the second lattice2D
00811      * @param function a pointer to C-function with two parameters
00812      * @return a reference to the actual lattice2D
00813      */
00814     inline lattice2D<T>& apply(const genericLattice2D<T>& a,
00815                                const genericLattice2D<T>& b,
00816                                T (*function)(T,T));
00817 
00818     //@}
00819 
00820     /**
00821      * @name Arithmetical Operations
00822      */
00823     //@{
00824 
00825     /**
00826      * Add \a other lattice2D to this lattice2D, and leave result here
00827      * @param other the lattice2D to be added with
00828      * @return a reference to the actual lattice2D
00829      */
00830     lattice2D<T>& add(const genericLattice2D<T>& other);
00831 
00832     /**
00833      * Add  matrices \a a and \a b and write the result
00834      * in this lattice2D
00835      * @param a the first lattice2D
00836      * @param b the second lattice2D
00837      * @return a reference to the actual lattice2D
00838      */
00839     lattice2D<T>& add(const genericLattice2D<T>& a, 
00840                       const genericLattice2D<T>& b);
00841 
00842     /**
00843      * Add constant value to this lattice2D, and leave result here
00844      * @param value a constant value to be added to all lattice2D elements
00845      * @return a reference to the actual lattice2D
00846      */
00847     lattice2D<T>& add(const T value);
00848 
00849     /**
00850      * Add constant value to the other lattice2D and leave result here.
00851      * @param other the other lattice2D
00852      * @param value a constant value to be added to all lattice2D elements
00853      * @return a reference to the actual lattice2D
00854      */
00855     lattice2D<T>& add(const genericLattice2D<T>& other,const T value);
00856 
00857     /**
00858      * Alias for add(const T value)
00859      * @param value a constant value to be added to all lattice2D elements
00860      * @return a reference to the actual lattice2D
00861      */
00862     inline lattice2D<T>& operator+=(const T value);
00863 
00864     /**
00865      * Alias for add(const lattice2D)
00866      * @param other the lattice2D to be added with
00867      * @return a reference to the actual lattice2D
00868      */
00869     inline lattice2D<T>& operator+=(const genericLattice2D<T>& other);
00870 
00871     /**
00872      * Add \a other lattice2D to this lattice2D and leave the result in
00873      * a new lattice2D.  This object is not changed.
00874      * @param other the other lattice2D to be added with.
00875      * @return a lattice2D with the sum of this lattice2D and \a other
00876      *
00877      * \warning Note that the use of this operator is not as efficient
00878      * as the use of the add() methods, in which the programmer can
00879      * decide when to use temporal and when not...
00880      */
00881     lattice2D<T> operator+(const genericLattice2D<T>& other) const;
00882 
00883     /**
00884      * Add constant value to this lattice2D, and leave result in a new
00885      * lattice2D. This object is not changed.
00886      * @param value a constant value to be added to all lattice2D elements
00887      * @return a new lattice2D with the result
00888      */
00889     lattice2D<T> operator+(const T value) const;
00890 
00891     /**
00892      * Subtract \a other lattice2D from this lattice2D and leave the result in
00893      * a new lattice2D.  This object is not changed.
00894      * @param other the other lattice2D to be added with.
00895      * @return a lattice2D with the sum of this lattice2D and \a other
00896      *
00897      * \warning Note that the use of this operator is not as efficient
00898      * as the use of the add() methods, in which the programmer can
00899      * decide when to use temporal and when not...
00900      */
00901     lattice2D<T> operator-(const genericLattice2D<T>& other) const;
00902 
00903     /**
00904      * Subtract constant value from this lattice2D, and leave result in a new
00905      * lattice2D. This object is not changed.
00906      * @param value a constant value to be added to all lattice2D elements
00907      * @return a new lattice2D with the result
00908      */
00909     lattice2D<T> operator-(const T value) const;
00910 
00911     /**
00912      * Add another lattice2D scaled by \f$b\f$ to this lattice2D. The matrices
00913      * must be of the same types and dimensions. Let \f$A\f$ be this lattice2D
00914      * and \f$B\f$ the other lattice2D, then this method performs:<p>
00915      * \f$A=A+b\cdot B\f$
00916      * @param b scaling factor for <b>other</b>
00917      * @param other the lattice2D to be added after scaling
00918      * @return a reference to this lattice2D
00919      */
00920     lattice2D<T>& addScaled(const T b, const genericLattice2D<T>& other);
00921 
00922     /**
00923      * Add a lattice2D A with a lattice2D B scaled by \f$b\f$, and leave the
00924      * result in this lattice2D. The matrices must be of the same types
00925      * and dimensions. This method performs:<p> \f$A+b\cdot B\f$
00926      * @param matA the first lattice2D
00927      * @param b scaling factor for <b>matB</b>
00928      * @param matB the lattice2D to be added after scaling
00929      * @return a reference to this lattice2D
00930      */
00931     lattice2D<T>& addScaled(const genericLattice2D<T>& matA,
00932                             const T b,
00933                             const genericLattice2D<T>& matB);
00934 
00935     /**
00936      * Leave the scaled %sum of two matrices in this lattice2D. The matrices
00937      * must be of the same types and dimensions. Let \f$A\f$ be the
00938      * first lattice2D and \f$B\f$ the second lattice2D with corresponding
00939      * scaling factors \f$a\f$ and \f$b\f$, further \f$C\f$ this
00940      * lattice2D, then this method performs:<p>
00941      * \f$C=a\cdot A+b\cdot B\f$
00942      * @param a scaling factor for <b>first</b>
00943      * @param first the first lattice2D to be added after scaling
00944      * @param b scaling factor for <b>second</b>
00945      * @param second the second lattice2D to be added after scaling
00946      * @return a reference to this lattice2D
00947      */
00948     lattice2D<T>& addScaled(const T a, const genericLattice2D<T>& first,
00949                             const T b, const genericLattice2D<T>& second);
00950 
00951 
00952     /**
00953      * Subtract \a other lattice2D from this lattice2D, and leave result
00954      * here.
00955      * @param other the lattice2D to be subtracted
00956      * @return a reference to this lattice2D.
00957      */
00958     lattice2D<T>& subtract(const genericLattice2D<T>& other);
00959 
00960     /**
00961      * Subtract matrices \a b from \a a and write result
00962      * in this lattice2D.
00963      * @param a the first lattice2D
00964      * @param b the second lattice2D
00965      * @return a reference to this lattice2D, which is now a-b.
00966      */
00967     lattice2D<T>& subtract(const genericLattice2D<T>& a, 
00968                            const genericLattice2D<T>& b);
00969 
00970     /**
00971      * Subtract constant value from this lattice2D, and leave result here
00972      *
00973      * @param value a constant value to be subtracted from all lattice2D
00974      *        elements
00975      * @return a reference to the actual lattice2D
00976      */
00977     lattice2D<T>& subtract(const T value);
00978 
00979     /**
00980      * Subtract constant value from the other lattice2D and leave result here.
00981      *
00982      * @param other the other lattice2D
00983      * @param value a constant value to be subtracted from all lattice2D
00984      *        elements
00985      * @return a reference to the actual lattice2D
00986      */
00987     lattice2D<T>& subtract(const genericLattice2D<T>& other,const T value);
00988 
00989     /**
00990      * Alias for subtract(const T value)
00991      *
00992      * @param value a constant value to be subtracted from all lattice2D
00993      *        elements
00994      * @return a reference to the actual lattice2D
00995      */
00996     inline lattice2D<T>& operator-=(const T value);
00997 
00998     /**
00999      * Alias for subtract(const lattice2D)
01000      *
01001      * @param other the lattice2D to be subtracted
01002      * @return a reference to the actual lattice2D
01003      */
01004     inline lattice2D<T>& operator-=(const genericLattice2D<T>& other);
01005 
01006     /**
01007      * Multiply constant value with this lattice2D, and leave result here
01008      * @param value the constant value to be multiplied with
01009      * @return a reference to the actual lattice2D
01010      */
01011     lattice2D<T>& multiply(const T value);
01012 
01013     /**
01014      * Multiply constant value with the other lattice2D and leave result here.
01015      * @param other the other lattice2D
01016      * @param value the constant value to be multiplied with
01017      * @return a reference to the actual lattice2D
01018      */
01019     lattice2D<T>& multiply(const genericLattice2D<T>& other,const T value);
01020 
01021     /**
01022      * Alias for multiply(const T& value)
01023      * @param value the constant value to be multiplied with
01024      * @return a reference to this lattice2D.
01025      */
01026     inline lattice2D<T>& operator*=(const T value);
01027 
01028     /**
01029      * Divide the elements of the lattice2D by a constant value, and leave
01030      * the result here
01031      * @param value the constant value (divisor)
01032      * @return a reference to the actual lattice2D
01033      */
01034     lattice2D<T>& divide(const T value);
01035 
01036     /**
01037      * Divide the elements of the other lattice2D by a constant value and leave
01038      * the result here.
01039      * @param other the other lattice2D
01040      * @param value the constant value (divisor)
01041      * @return a reference to the actual lattice2D
01042      */
01043     lattice2D<T>& divide(const genericLattice2D<T>& other,const T value);
01044 
01045     /**
01046      * Alias for divide(const T& value)
01047      * @param value the constant value to be divided by
01048      * @return a reference to this lattice2D.
01049      */
01050     lattice2D<T>& operator/=(const T value);
01051 
01052     /**
01053      * Element-wise multiplication with other lattice2D
01054      * @param other the other lattice2D.  It should have the same dimensions of
01055      *              this lattice2D.
01056      * @return a reference to the actual lattice2D
01057      */
01058     lattice2D<T>& emultiply(const genericLattice2D<T>& other);
01059 
01060     /**
01061      * Element-wise multiplication of \a a and \a b.
01062      * @param a the first lattice2D
01063      * @param b the second lattice2D (with same dimensions of a)
01064      * @return a reference to the actual lattice2D
01065      */
01066     lattice2D<T>& emultiply(const genericLattice2D<T>& a,
01067                             const genericLattice2D<T>& b);
01068 
01069     /**
01070      * Element-wise division with other lattice2D
01071      * @param other the other lattice2D.  It should have the same dimensions of
01072      *              this lattice2D.
01073      * @return a reference to the actual lattice2D
01074      */
01075     lattice2D<T>& edivide(const genericLattice2D<T>& other);
01076 
01077     /**
01078      * Element-wise division of \a a and \a b.
01079      * @param a the first lattice2D
01080      * @param b the second lattice2D (with same dimensions of a)
01081      * @return a reference to the actual lattice2D
01082      */
01083     lattice2D<T>& edivide(const genericLattice2D<T>& a, 
01084                           const genericLattice2D<T>& b);
01085 
01086     /**
01087      * Outer-product of two vectors.
01088      *
01089      * The result will be left in this lattice2D.
01090      * The dimensions of this lattice2D will change if needed.
01091      * The outer product of two column vectors is defined as
01092      * \f$a \cdot b^T\f$
01093      *
01094      * @param a first vector (will determine the number of rows)
01095      * @param b second vector (will determine the number of columns)
01096      * @return a reference to the actual lattice2D
01097      */
01098     lattice2D<T>& outerProduct(const row_type& a,
01099                                const row_type& b);
01100 
01101     /**
01102      * Transpose lattice2D and leave the result here.
01103      *
01104      * If the lattice2D is square this is actually a fast on-place
01105      * operation. However, if the lattice2D is not square a temporary
01106      * lattice2D is created with the new dimensions. This can be less
01107      * efficient than using transpose(const lattice2D&) directly on a
01108      * temporary lattice2D if many matrices of the same size need to be
01109      * transposed.
01110      *
01111      * @return a reference to the actual (now transposed) lattice2D
01112      */
01113     lattice2D<T>& transpose();
01114 
01115     /**
01116      * Transpose the other lattice2D and leave the result here.
01117      *
01118      * If U!=T each element of \a other is static_cast<T> in the
01119      * process.
01120      *
01121      * @return a reference to the actual (now transposed) lattice2D
01122      */
01123     template <typename U>
01124     lattice2D<T>& transpose(const genericLattice2D<U>& other);
01125 
01126     /**
01127      * Calculate the sum of all elements of the lattice2D.
01128      * This member can be used with classes which define the operator '+='
01129      */
01130     T computeSumOfElements() const;
01131 
01132     /**
01133      * Calculate the product of all elements of the vector.
01134      * This member can be used with classes which define the operator '*='
01135      */
01136     T computeProductOfElements() const;
01137     //@}
01138 
01139     /**
01140      * @name Find extreme values
01141      */
01142     //@{
01143 
01144     /**
01145      * Get the smallest element of the lattice2D
01146      */
01147     T findMinimum() const;
01148 
01149     /**
01150      * Get the index of the smallest element of the lattice2D
01151      */
01152     size_type findIndexOfMinimum() const;
01153 
01154     /**
01155      * Get the biggest element of the lattice2D
01156      */
01157     T findMaximum() const;
01158 
01159     /**
01160      * Get the index of the biggest element of the lattice2D
01161      */
01162     size_type findIndexOfMaximum() const;
01163 
01164     /**
01165      * Get the extremes of the lattice2D (smallest and biggest elements)
01166      */
01167     void findExtremes(T& theMinimum, T& theMaximum) const;
01168 
01169     /**
01170      * Get the indices of the extremes of the lattice2D
01171      * (smallest and biggest elements)
01172      */
01173     void findIndexOfExtremes(size_type& theIdxMinimum,
01174                              size_type& theIdxMaximum) const;
01175 
01176     //@}
01177   protected:
01178 
01179     /**
01180      * @name Memory allocation and deallocation
01181      *
01182      * Restrict all memory allocation and deallocation to these functions.
01183      */
01184     //@{
01185     /**
01186      * Allocate \a n number of rows or the appropriate type.
01187      */
01188     inline virtual row_type* allocNewRows(const int fromRow,
01189                                           const int toRow);
01190     //@}
01191 
01192   };
01193 }
01194 
01195 #include "cvrLattice2D_inline.h"
01196 
01197 namespace cvr {
01198   /**
01199    * Lattice2D of double
01200    */
01201   typedef lattice2D<double> dlattice2D;
01202   /**
01203    * Lattice2D of float
01204    */
01205   typedef lattice2D<float>  flattice2D;
01206   /**
01207    * Lattice2D of integer
01208    */
01209   typedef lattice2D<int32>  ilattice2D;
01210 
01211 }
01212 
01213 #endif
01214 

Generated on Sun Sep 20 22:07:59 2009 for CVR-Lib by Doxygen 1.5.8