CVR-Lib last update 20 Sep 2009

cvrGenericLattice1D.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007-2008
00003  * Pablo Alvarado
00004  *
00005  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00006  *
00007  * The CVR-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the BSD License.
00009  *
00010  * All rights reserved.
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are met:
00014  *
00015  * 1. Redistributions of source code must retain the above copyright notice,
00016  *    this list of conditions and the following disclaimer.
00017  *
00018  * 2. Redistributions in binary form must reproduce the above copyright notice,
00019  *    this list of conditions and the following disclaimer in the documentation
00020  *    and/or other materials provided with the distribution.
00021  *
00022  * 3. Neither the name of the authors nor the names of its contributors may be
00023  *    used to endorse or promote products derived from this software without
00024  *    specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00027  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00030  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00031  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00032  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00033  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00034  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00036  * POSSIBILITY OF SUCH DAMAGE.
00037  */
00038 
00039 /**
00040  * \file   cvrGenericLattice1D.h
00041  *         Contains a one-dimensional lattice container, which is somewhat
00042  *         similar to a genericVector but with a selectable initial index, 
00043  *         that, besides zero, can be positive or negative.
00044  * \author Pablo Alvarado
00045  * \date   09.04.1999
00046  *
00047  * $Id: cvrGenericLattice1D.h,v 1.16 2007/09/15 03:36:57 alvarado Exp $
00048  */
00049 
00050 #ifndef _CVR_GENERIC_LATTICE_1D_H_
00051 #define _CVR_GENERIC_LATTICE_1D_H_
00052 
00053 #include "cvrContainer.h"
00054 #include "cvrConstantReferenceType.h"
00055 #include "cvrConstReferenceException.h"
00056 #include "cvrAllocException.h"
00057 #include "cvrTypes.h"
00058 #include "cvrAssert.h"
00059 #include "cvrResizeType.h"
00060 #include "cvrDebugIterator.h"
00061 #include "cvrGenericVector.h"
00062 #include "cvrInterval.h"
00063 
00064 #include <vector>
00065 
00066 namespace cvr {
00067   /**
00068    * Generic Lattice 1D container.
00069    *
00070    * This container is inspired on mathematical integer lattices, at least with
00071    * respect to the indices, which are taken from \f$Z^n\f$ in the general
00072    * case with $n=1$ in this particular case.
00073    *
00074    * You can consider this a generalization of a cvr::genericVector, in which
00075    * the index of the first element is not necessarily zero, but a negative or
00076    * positive value.
00077    *
00078    * The main goal of this class is to provide a \b fast implementation for
00079    * random access containers, addressable with negative indices, like filter
00080    * kernels, and since speed is the premise, it is achieved at some memory
00081    * costs.  This means this class has some storage overhead in order to
00082    * provide some information at zero time, like size, first and last indices
00083    * the begin and end iterators, etc., which is only possible by storing them
00084    * directly.
00085    *
00086    * This class cannot be used to contain objects which use some sort of
00087    * dynamic memory allocation.  This means, you should not try to make a
00088    * cvr::genericLattice1D of other vectors or matrices, which administrate
00089    * some memory.  If you do so, the behaviour of copy or fill operations will
00090    * be unpredictable.
00091    *
00092    * Most of times you will want to use cvr::lattice1D instead, since they
00093    * provide some mathematical functionality.
00094    *
00095    * The difference between cvr::genericLattice1D and its most used inherited
00096    * class cvr::lattice1D is the support for arithmetical operations.  The
00097    * generic lattice is more a "pure" container.  It inherits its memory
00098    * management versatility to cvr::lattice1D.  Again, it is usually employed
00099    * as a container of any \e static type, which do not do by itself any memory
00100    * managment.
00101    *
00102    * The genericLattice1D class is a generic container class implemented as a
00103    * template, where the template type \c T is the type of the elements
00104    * assigned to each point in the lattice.
00105    *
00106    * If you need to create a lattice of floats with 255 elements indexed from
00107    * -127 to 127, all of them initialized with a value of 4.27 just create it
00108    * with
00109    *
00110    * \code
00111    * cvr::genericLattice1D<float> myLat(-127,127,4.27f);
00112    * \endcode
00113    *
00114    * To access the lattice elements use the access operators at() (or the
00115    * overloaded operator[]()).  For example:
00116    *
00117    * \code
00118    * float accu = 0; // initialize accumulator
00119    *
00120    * for (int i = myLat.firstIndex(); i <= myLat.lastIndex(); i++) {
00121    *   accu += myLat.at(i); // access each element of the vector
00122    * }
00123    * \endcode
00124    *
00125    * In the CVR-Lib, the debug-mode library always makes a boundary check for
00126    * both at() and operator[](), and in the release-mode there is no check for
00127    * any of both methods.
00128    *
00129    * @ingroup gAggregate
00130    */
00131   template<typename T>
00132   class genericLattice1D : public container {
00133   public:
00134 
00135     /**
00136      * \name Internal types and classes
00137      */
00138     //@{
00139 
00140     /**
00141      * Exception thrown when a constant reference is violated.
00142      */
00143     typedef cvr::constReferenceException constReferenceException;
00144 
00145     /**
00146      * Type of the genericLattice1D elements.
00147      */
00148     typedef typename genericVector<T>::value_type value_type;
00149 
00150     /**
00151      * Return type of the size() member
00152      */
00153     typedef typename genericVector<T>::size_type size_type;
00154 
00155     /**
00156      * Pointer to value_type
00157      */
00158     typedef typename genericVector<T>::pointer pointer;
00159 
00160     /**
00161      * Const pointer to value_type
00162      */
00163     typedef typename genericVector<T>::const_pointer const_pointer;
00164     
00165     /**
00166      * Reference to value_type
00167      */
00168     typedef typename genericVector<T>::reference reference;
00169 
00170     /**
00171      * Const reference to value_type
00172      */
00173     typedef typename genericVector<T>::const_reference const_reference;
00174 
00175     /**
00176      * \c iterator type (allows read and write operations).
00177      *
00178      * The use of the iterator classes is similar to the iterators of the STL
00179      * (Standard Template Library). See cvr::genericLattice1D::begin() and
00180      * cvr::genericLattice1D::inverseBegin() for examples.
00181      *
00182      * For the debugging version of the iterators, boundary check will be
00183      * done!  This explains the low speed of the iterators of the debug
00184      * version.  In the release version, no boundary check will be done,
00185      * and the iterators are sometimes a factor 10 faster than the
00186      * debug iterators.
00187      *
00188      * The use of the access operator at() is faster than the iterators in the
00189      * debug version only.  If you need to iterate on a genericLattice1D use
00190      * iterators instead (in the release version iterators are approximately a
00191      * factor 3 faster than at()).
00192      *
00193      * \warning Try to use the prefix incremental operator (i.e. ++it) instead
00194      * of the postfix operator (i.e. it++) to allow efficient code also in
00195      * debug-modus!
00196      *
00197      * @see genericLattice1D<T>::const_iterator
00198      */
00199     typedef typename genericVector<T>::iterator iterator;
00200 
00201     /**
00202      * \c const_iterator type (allows read-only operations).
00203      *
00204      * The use of the iterator classes is similar to the iterators of the STL
00205      * (Standard Template Library). See cvr::genericLattice1D::begin() for an
00206      * example.
00207      *
00208      * For the debugging version of the iterators, boundary check will be
00209      * done!  This explains the low speed of the iterators of the debug
00210      * version.  In the release version, no boundary check will be done, and
00211      * the iterators are sometimes a factor 10 faster than the debug
00212      * iterators.
00213      *
00214      * The use of the access operator at() is faster than the iterators in the
00215      * debug version only.  If you need to iterate on a genericLattice1D use
00216      * iterators instead (in the release version iterators are approximately a
00217      * factor 3 faster than at()).
00218      *
00219      * \warning Try to use the prefix incremental operator (i.e. ++it) instead
00220      * of the postfix operator (i.e. it++) to allow efficient code also in
00221      * debug-modus!
00222      *
00223      * @see genericLattice1D<T>::iterator
00224      */
00225     typedef typename genericVector<T>::const_iterator const_iterator;
00226     //@}
00227 
00228     /**
00229      * Default constructor creates an empty genericLattice1D
00230      */
00231     genericLattice1D();
00232 
00233     /**
00234      * Create a genericLattice1D indexed by the given interval but do \b not
00235      * initialize its elements.
00236      *
00237      * @param from initial index.
00238      * @param to   final index.
00239      * 
00240      * The size of the container will be to-from+1.  The \c to value must be
00241      * greater or equal than the \c from value, otherwise an empty lattice will
00242      * be created.
00243      */
00244     explicit genericLattice1D(const size_type from,const size_type to);
00245 
00246     /**
00247      * Create a genericLattice1D indexed by the given interval but do \b not
00248      * initialize its elements.
00249      *
00250      * @param indices interval of indices to be used.
00251      */
00252     explicit genericLattice1D(const iinterval& indices);
00253 
00254     /**
00255      * Create a genericLattice1D indexed by the given interval and initialize
00256      * it with the given value.
00257      *
00258      * @param from initial index value
00259      * @param to final index value
00260      * @param iniValue all elements will be initialized with this value.
00261      */
00262     explicit genericLattice1D(const size_type from,
00263                               const size_type to,
00264                               const_reference iniValue);
00265 
00266     /**
00267      * Create a genericLattice1D indexed by the given interval and initialize
00268      * it with the given value.
00269      *
00270      * @param indices interval of indices to be used.
00271      * @param iniValue all elements will be initialized with this value.
00272      */
00273     explicit genericLattice1D(const iinterval& indices,
00274                               const_reference iniValue);
00275 
00276     /**
00277      * Create a genericLattice1D indexed by the given interval and initialize
00278      * it with the given data. The \a data will be copied.
00279      *
00280      * If you need to just use the memory block without copying it, then you
00281      * can wether use a third parameter of eConstantReference type or later
00282      * call the useExternData() method.
00283      *
00284      * @see useExternData()
00285      *
00286      * @param from initial index value
00287      * @param to final index value
00288      * @param data a pointer to the data that will be copied.
00289      */
00290     genericLattice1D(const size_type from,
00291                      const size_type to,
00292                      const value_type data[]);
00293 
00294     /**
00295      * Create a genericLattice1D indexed by the given interval and initialize
00296      * it with the given data. The \a data will be copied.
00297      *
00298      * If you need to just use the memory block without copying it, then you
00299      * can wether use a third parameter of eConstantReference type or later
00300      * call the useExternData() method.
00301      *
00302      * @see useExternData()
00303      *
00304      * @param indices interval of indices to be used.
00305      * @param data a pointer to the data that will be copied.
00306      */
00307     genericLattice1D(const iinterval& indices,
00308                      const value_type data[]);
00309 
00310     /**
00311      * Create a genericLattice1D indexed by the given interval and initialize
00312      * it with the given data, the same way "useExternData" does, i.e. the 
00313      * \a data will \b not be copied!.
00314      *
00315      * @see useExternData()
00316      *
00317      * @param from initial index
00318      * @param to final index
00319      * @param data a pointer to the data that will be used.
00320      * @param constRef if this parameter is \c ConstantReference it will not be
00321      *                 possible to change the pointer to the external memory
00322      *                 block nor to resize the genericLattice1D.  Despite this,
00323      *                 the value of each element can be changed by the access
00324      *                 operators.
00325      */
00326     genericLattice1D(const size_type from,
00327                      const size_type to,
00328                      value_type data[],
00329                      const eConstantReference constRef);
00330 
00331     /**
00332      * Create a genericLattice1D indexed by the given interval and initialize
00333      * it with the given data, the same way "useExternData" does, i.e. the 
00334      * \a data will \b not be copied!.
00335      *
00336      * @see useExternData()
00337      *
00338      * @param indices interval used for the lattice indices
00339      * @param data a pointer to the data that will be used.
00340      * @param constRef if this parameter is \c ConstantReference it will not be
00341      *                 possible to change the pointer to the external memory
00342      *                 block nor to resize the genericLattice1D.  Despite this,
00343      *                 the value of each element can be changed by the access
00344      *                 operators.
00345      */
00346     genericLattice1D(const iinterval& indices,
00347                      value_type data[],
00348                      const eConstantReference constRef);
00349 
00350     /**
00351      * Create this genericLattice1D as a copy of another genericLattice1D
00352      * @param other the genericLattice1D to be copied.
00353      */
00354     genericLattice1D(const genericLattice1D<T>& other);
00355 
00356     /**
00357      * Create this genericLattice1D as a copy of the specified interval of
00358      * elements of another genericLattice1D.  The \c from and \c to values are
00359      * truncated to the interval used by the \c other lattice.
00360      *
00361      * @param other the genericLattice1D to be copied.
00362      * @param from starting index of \c other lattice.
00363      * @param to end index of the \c other lattice.
00364      */
00365     genericLattice1D(const genericLattice1D<T>& other,
00366                      const size_type from, const size_type to=MaxIndex);
00367 
00368     /**
00369      * Create this genericLattice1D as a copy of the specified interval of
00370      * elements of another genericLattice1D.  The \c from and \c to values are
00371      * truncated to the interval used by the \c other lattice.
00372      *
00373      * @param other the genericLattice1D to be copied.
00374      * @param indices index interval of the elements of \c other to be copied.
00375      */
00376     genericLattice1D(const genericLattice1D<T>& other,
00377                      const iinterval& indices);
00378 
00379 
00380     /**
00381      * Create this genericLattice1D as a copy of another std::vector<T>
00382      *
00383      * @param other the genericLattice1D to be copied.
00384      * @param firstIndex index to be used for the first element of the vector.
00385      */
00386     genericLattice1D(const std::vector<T>& other,const int firstIndex=0);
00387 
00388     /**
00389      * Create this genericLattice1D as a copy of another cvr::genericVector.
00390      *
00391      * @param other the genericLattice1D to be copied.
00392      * @param firstIndex optional argument indicating which index is
00393      *        going to be assigned to the first vector element.
00394      */
00395     genericLattice1D(const genericVector<T>& other,const int firstIndex=0);
00396 
00397     /**
00398      * Destructor
00399      */
00400     virtual ~genericLattice1D();
00401 
00402     /**
00403      * Check whether this %object owns the data.
00404      *
00405      * @return \a false if this genericLattice1D contains a reference to extern
00406      * data.
00407      */
00408     inline bool ownsData() const;
00409 
00410     /**
00411      * Restore ownership.
00412      *
00413      * If this object does not own its data, this member will create a new
00414      * memory buffer with the same data and will make this vector its owner.
00415      *
00416      * If this genericLattice1D already owns its data nothing happens.
00417      */
00418     inline void restoreOwnership();
00419 
00420     /**
00421      * Reference to extern data.
00422      *
00423      * This member allows the use of this %object as an wrapper-%object to
00424      * access some memory block as a genericLattice1D.
00425      * The user must take care for memory allocation and deallocation of
00426      * the block.  This %object will never delete the external data!.
00427      *
00428      * @param from initial index
00429      * @param to   final index
00430      * @param data    pointer to the external memory block.
00431      * @param constRef if this parameter is true, it will not be possible to
00432      *                 change the pointer to the external memory block nor to
00433      *                 resize the genericLattice1D.  Despite this, the value of
00434      *                 each element can be changed by the access operators.
00435      *
00436      * For Example:
00437      * \code
00438      * int i;
00439      * double tmp;
00440      * double a[10];               // memory block!
00441      *
00442      * for (i=0;i<10;i++) {
00443      *   a[i]=2*i;                 // initialize the memory block
00444      * }
00445      *
00446      * cvr::genericLattice1D<double> myLat;  // an empty genericLattice1D
00447      *
00448      * myLat.resize(-2,2,0);       // resize the genericLattice1D: now 5
00449      *                             // elements initialized with 0
00450      *
00451      * myLat.useExternData(-4,5,a,true); // use the genericLattice1D as wrapper
00452      *                             // for the memory block
00453      *
00454      * tmp = myLat.at(5);          // tmp is now 10
00455      *
00456      * myLat.at(9) = 3;            // the last element of myLat
00457      *                             // has now the value 3
00458      *
00459      * myLat.resize(0,5);          // INVALID!! this will throw an exception
00460      *                             // constReferenceException()
00461      * \endcode
00462      *
00463      *
00464      * If the size (from-to+1) is greater than the allocated memory, the
00465      * behaviour could be unpredictible.
00466      */
00467     inline void 
00468     useExternData(const size_type from,
00469                   const size_type to,
00470                   pointer data,
00471                   const eConstantReference constRef=VariableReference);
00472 
00473     /**
00474      * Reference to extern data.
00475      *
00476      * This member allows the use of this %object as an wrapper-%object to
00477      * access some memory block as a genericLattice1D.
00478      * The user must take care for memory allocation and deallocation of
00479      * the block.  This %object will never delete the external data!.
00480      *
00481      * @param indices interval to be used by the lattice to access the data.
00482      *                Note that this is NOT the number of bytes of the external
00483      *                block.
00484      * @param data    pointer to the external memory block.
00485      * @param constRef if this parameter is true, it will not be possible to
00486      *                 change the pointer to the external memory block nor to
00487      *                 resize the genericLattice1D.  Despite this, the value of
00488      *                 each element can be changed by the access operators.
00489      *
00490      * For Example:
00491      * \code
00492      * int i;
00493      * double tmp;
00494      * double a[10];               // memory block!
00495      *
00496      * for (i=0;i<10;i++) {
00497      *   a[i]=2*i;                 // initialize the memory block
00498      * }
00499      *
00500      * cvr::genericLattice1D<double> myLat;  // an empty genericLattice1D
00501      *
00502      * myLat.resize(-2,2,0);       // resize the genericLattice1D: now 5
00503      *                             // elements initialized with 0
00504      *
00505      * myLat.useExternData(-4,5,a,true); // use the genericLattice1D as wrapper
00506      *                             // for the memory block
00507      *
00508      * tmp = myLat.at(5);          // tmp is now 10
00509      *
00510      * myLat.at(9) = 3;            // the last element of myLat
00511      *                             // has now the value 3
00512      *
00513      * myLat.resize(0,5);          // INVALID!! this will throw an exception
00514      *                             // constReferenceException()
00515      * \endcode
00516      *
00517      *
00518      * If the size (from-to+1) is greater than the allocated memory, the
00519      * behaviour could be unpredictible.
00520      */
00521     inline void 
00522     useExternData(const iinterval& indices,
00523                   pointer data,
00524                   const eConstantReference constRef=VariableReference);
00525 
00526     /**
00527      * Attach extern data to the vector.
00528      *
00529      * This member allows the use of this %object as an access-functor for
00530      * the 'data'. An access to the element at(x) is equivalent to
00531      * data[x].
00532      * If \a theSize is an invalid dimension, the behaviour will be
00533      * unpredictible.
00534      *
00535      * The memory will be administrated by this genericLattice1D
00536      * instance, and may be deleted if required (e.g. genericLattice1D deleted
00537      * or resized!).  The user should not try to manipulate the memory
00538      * allocation of the data after the attachment!  See also
00539      * useExternData().
00540      *
00541      * @param from initial index
00542      * @param to final index
00543      * @param data a pointer to the memory block to be used
00544      *
00545      * Example:
00546      * \code
00547      * cvr::genericLattice1D<int> myLat;
00548      * int block1[25];
00549      * int* block2;
00550      * block2 = new int[25];
00551      *
00552      * myLat.useExternData(25,block1); // ok
00553      * myLat.attach(25,block1); // wrong!!! matrix will try to manipulate
00554      *                          // stack memory: DO NOT DO THIS!!!!!
00555      * myLat.attach(25,block2); // ok!  but do not try to delete the memory
00556      *                          //      block2!!
00557      * \endcode
00558      */
00559     inline void attach(const size_type from,
00560                        const size_type to,
00561                        value_type data[]);
00562 
00563     /**
00564      * Attach extern data to the vector.
00565      *
00566      * This member allows the use of this %object as an access-functor for
00567      * the 'data'. An access to the element at(x) is equivalent to
00568      * data[x].
00569      * If \a theSize is an invalid dimension, the behaviour will be
00570      * unpredictible.
00571      *
00572      * The memory will be administrated by this genericLattice1D
00573      * instance, and may be deleted if required (e.g. genericLattice1D deleted
00574      * or resized!).  The user should not try to manipulate the memory
00575      * allocation of the data after the attachment!  See also
00576      * useExternData().
00577      *
00578      * @param indices interval of indices for the lattice.
00579      * @param data a pointer to the memory block to be used
00580      *
00581      * Example:
00582      * \code
00583      * cvr::genericLattice1D<int> myLat;
00584      * int block1[25];
00585      * int* block2;
00586      * block2 = new int[25];
00587      *
00588      * myLat.useExternData(25,block1); // ok
00589      * myLat.attach(25,block1); // wrong!!! matrix will try to manipulate
00590      *                          // stack memory: DO NOT DO THIS!!!!!
00591      * myLat.attach(25,block2); // ok!  but do not try to delete the memory
00592      *                          //      block2!!
00593      * \endcode
00594      */
00595     inline void attach(const iinterval& indices,pointer data);
00596 
00597     /**
00598      * Free the data of this object and hand it over to the
00599      * "receiver". The value of ownsData is also transfered to the
00600      * receiver. (see Note).
00601      *
00602      * This function makes a "memory block transfusion" to another
00603      * genericLattice1D.  It is a very efficient way to make a copy of
00604      * this genericLattice1D, if you don't need the source data anymore!
00605      *
00606      * \b Note: Take care that if the attach() or useExternData()
00607      * methods of this genericLattice1D have been called before detachment, the
00608      * same rules for memory management apply now for the receiver.
00609      *
00610      * At the end of the detachment, this genericLattice1D will be empty.
00611      * @param receiver the genericLattice1D which will receive the memory
00612      *        block.  All data of that genericLattice1D will be first deleted!
00613      */
00614     void detach(genericLattice1D<T>& receiver);
00615 
00616     /**
00617      * Exchange (in a fast way) the data between this and the other
00618      * genericLattice1D.  Similar to detach(), this method will exchange
00619      * the complete memory blocks, avoiding an element-wise copy.
00620      * @param other the genericLattice1D with which the data will be
00621      *              exchanged.
00622      */
00623     void swap(genericLattice1D<T>& other);
00624 
00625     /**
00626      * Returns the number of elements of the genericLattice1D
00627      */
00628     inline size_type size() const;
00629 
00630     /**
00631      * Returns first element as a const_iterator.
00632      *
00633      * Note that you can not change the values of the genericLattice1D
00634      * elements when you use a const_iterator. See also begin()
00635      */
00636     inline const_iterator begin() const;
00637 
00638     /**
00639      * Returns iterator pointing to the first element.
00640      *
00641      * The use of the iterators is similar to the iterators of the
00642      * Standard Template Library (STL).
00643      * If you need to iterate on all elements of the genericLattice1D, you can
00644      * use following code:
00645      *
00646      * \code
00647      *   int tmp,accu;                        // a temporal variable
00648      *   // genericLattice1D with 10 elements
00649      *   cvr::genericLattice1D<int> myLat(10,1); 
00650      *   // an iterator set to the beginning of myLat
00651      *   cvr::genericLattice1D<int>::iterator it=myLat.begin();
00652      *   // an iterator set to the end of myLat
00653      *   cvr::genericLattice1D<int>::iterator eit=myLat.begin();
00654      *
00655      *   for (; it!=eit ; ++it) {
00656      *     tmp = *it;     // tmp has value of element pointed
00657      *                    // by the iterator.
00658      *     accu += tmp;
00659      *     (*it) = accu;  // change the value in the genericLattice1D.
00660      *   }
00661      * \endcode
00662      *
00663      * \note It is significantly faster in debug builds to use a pre-increment
00664      * with iterators (++it) than a post-increment (it++).
00665      *
00666      * Please note that if you define \a it as a const_iterator, you can not do
00667      * something like \a *it=accu.
00668      */
00669     inline iterator begin();
00670 
00671     /**
00672      * Returns first index (in a genericLattice1D this is always size()-1)
00673      */
00674     inline size_type firstIndex() const;
00675 
00676     /**
00677      * Returns last index (in a genericLattice1D this is always size()-1)
00678      */
00679     inline size_type lastIndex() const;
00680 
00681     /**
00682      * Returns last index as a const_iterator.
00683      *
00684      * For an example see begin()
00685      */
00686     inline const_iterator end() const;
00687 
00688     /**
00689      * Returns last index as an iterator
00690      *
00691      * For an example see begin()
00692      */
00693     inline iterator end();
00694 
00695     /**
00696      * This method returns an iterator that points to the \b last valid element
00697      * of the genericLattice1D. It is used for inverse order iteration through
00698      * the genericLattice1D using normal iterators (as opposed to
00699      * reverse_iterators used in the STL). This has the advantage that
00700      * iterators going from front to end and in the inverse direction are the
00701      * same and can thus be compared, copied etc. Further the implementation of
00702      * reverse_iterators is not as fast as that of iterators and thus not
00703      * desired in the CVR-Lib.
00704      *
00705      * \code
00706      * igenericLattice1D v(false,10);
00707      * int i,tmp;
00708      * for (i=0; i<10; i++) {
00709      *   v.at(i)=i;
00710      * }
00711      * igenericLattice1D::iterator forwardIt=v.begin();
00712      * igenericLattice1D::iterator backIt=v.inverseBegin();
00713      *
00714      * while (forwardIt<=backIt) {
00715      *   tmp = (*forwardIt); (*forwardIt)=(*backIt); (*backIt)=tmp;
00716      *   ++forwardIt; ++backIt;
00717      * }
00718      * \endcode
00719      */
00720     inline iterator inverseBegin();
00721 
00722     /**
00723      * Return an iterator that points to the \b last valid element of the
00724      * genericLattice1D. See inverseBegin() for more details.
00725      */
00726     inline const_iterator inverseBegin() const;
00727 
00728     /**
00729      * Return an iterator that points to the element \b
00730      * before the \b first valid element of the genericLattice1D. It is used to
00731      * mark the end for inverse order iteration through the genericLattice1D
00732      * using normal iterators (as opposed to reverse_iterators as used
00733      * in the STL). This has the advantage that iterators going from
00734      * front to end and in the inverse direction are the same and can
00735      * thus be compared, copied etc.Further the implementation of
00736      * reverse_iterators is not as fast as that of iterators and thus
00737      * not desired in the CVR-Lib.
00738      */
00739     inline iterator inverseEnd();
00740 
00741     /**
00742      * Return an iterator that points to the element \b before the \b first
00743      * valid element of the genericLattice1D.
00744      */
00745     inline const_iterator inverseEnd() const;
00746 
00747     /**
00748      * Change dimension and if desired the contents of the genericVector.
00749      *
00750      * @param from initial index
00751      * @param to   final index
00752      * @param iniValue the initialization value.
00753      * @param resizeType specifies what should happen with the data of the
00754      *                   resized vector.
00755      *
00756      * For example:
00757      * \code
00758      *   cvr::genericVector<int> myVct;  // creates empty genericVector
00759      *   myVct.resize(5,0);       // genericVector with 5 elements initialized
00760      *                            // with 0
00761      *   myVct.resize(10,2);      // genericVector has now 10 elements: the
00762      *                            // first five are still 0 and the
00763      *                            // rest have a 2
00764      *   myVct.resize(20,3,cvr::AllocateOnly); // now the genericVector has 20
00765      *                                         // elements but their values
00766      *                                         // are unknown.
00767      *   myVct.resize(5,1,cvr::Init); // the genericVector has now 5
00768      *                                // elements initialized with 1
00769      *
00770      * \endcode
00771      *
00772      * If the resize is possible (see useExternData()), after the resize, this
00773      * %object will always own the data!
00774      *
00775      * @see eResizeType, resize(const int), allocate(), assign()
00776      */
00777     void resize(const size_type from,
00778                 const size_type to,
00779                 const_reference iniValue,
00780                 const eResizeType resizeType=CopyAndInit);
00781 
00782     /**
00783      * Change dimension and if desired the contents of the genericVector.
00784      *
00785      * @param indices interval to be used by the lattice indices.
00786      * @param iniValue the initialization value.
00787      * @param resizeType specifies what should happen with the data of the
00788      *                   resized vector.
00789      *
00790      * For example:
00791      * \code
00792      *   cvr::genericVector<int> myVct;  // creates empty genericVector
00793      *   myVct.resize(5,0);       // genericVector with 5 elements initialized
00794      *                            // with 0
00795      *   myVct.resize(10,2);      // genericVector has now 10 elements: the
00796      *                            // first five are still 0 and the
00797      *                            // rest have a 2
00798      *   myVct.resize(20,3,cvr::AllocateOnly); // now the genericVector has 20
00799      *                                         // elements but their values
00800      *                                         // are unknown.
00801      *   myVct.resize(5,1,cvr::Init); // the genericVector has now 5
00802      *                                // elements initialized with 1
00803      *
00804      * \endcode
00805      *
00806      * If the resize is possible (see useExternData()), after the resize, this
00807      * %object will always own the data!
00808      *
00809      * @see eResizeType, resize(const int), allocate(), assign()
00810      */
00811     inline void resize(const iinterval& indices,
00812                        const_reference iniValue,
00813                        const eResizeType resizeType=CopyAndInit);
00814 
00815     /**
00816      * Resize the vector keeping all the old elements, but \b without
00817      * initializing the new ones.
00818      *
00819      * This is an alias for resize(from,to,T(),Copy);
00820      *
00821      * @param from initial index
00822      * @param to final index
00823      *
00824      * @see resize(const int,const_reference,const eResizeType)
00825      * @see allocate(),assign()
00826      */
00827     inline void resize(const size_type from,const size_type to);
00828 
00829     /**
00830      * Resize the vector keeping all the old elements, but \b without
00831      * initializing the new ones.
00832      *
00833      * This is an alias for resize(from,to,T(),Copy);
00834      *
00835      * @param indices interval used for the lattice indices.
00836      *
00837      * @see resize(const int,const_reference, const eResizeType),
00838      * @see allocate(),assign()
00839      */
00840     inline void resize(const iinterval& indices);
00841 
00842     /**
00843      * Change the vector to contain exactltly the given number of elements.  In
00844      * opposition to resize, allocate() does \b not copy the previous data but
00845      * only modifies the size of the vector, discarding all contained data and
00846      * leaving the new data uninitialized.
00847      *
00848      * This is in principle an alias to
00849      * resize(newSize,T(),AllocateOnly).
00850      *
00851      * @param from initial index
00852      * @param to final index
00853      * 
00854      * All current data will be discarded.
00855      *
00856      * @see eResizeType, resize(const int,const_reference, const eResizeType)
00857      * @see resize(const int),allocate(), assign()
00858      */
00859     inline void allocate(const size_type from,const size_type to);
00860 
00861     /**
00862      * Change the vector to contain exactltly the given number of elements.  In
00863      * opposition to resize, allocate() does \b not copy the previous data but
00864      * only modifies the size of the vector, discarding all contained data and
00865      * leaving the new data uninitialized.
00866      *
00867      * This is in principle an alias to
00868      * resize(newSize,T(),AllocateOnly).
00869      *
00870      * @param indices interval used for the indices of this lattice.
00871      * 
00872      * All current data will be discarded.
00873      *
00874      * @see eResizeType, 
00875      * @see resize(const int,const int,const_reference, const eResizeType)
00876      * @see resize(const int),allocate(), assign()
00877      */
00878     inline void allocate(const iinterval& indices);
00879 
00880     /**
00881      * Assign copies of \a initValue to the genericVector such that the given
00882      * interval is covered.
00883      *
00884      * Change the size and contents of this vector to be exactly \a newSize
00885      * elements long, with all the elements initialized to the value indicated
00886      * in \a initValue.  In opposition to resize, this method does \b not copy
00887      * the previous data but changes the size of the vector, discarding all
00888      * contained data, replacing it with \a newSize copies of \a initValue.
00889      *
00890      * This is in principle an alias to resize(newSize,T(),Init).
00891      *
00892      * @param from initial index.
00893      * @param to final index.
00894      * @param initValue all elements of the vector will be initialized with
00895      *        this value.
00896      */
00897     inline void assign(const size_type from,
00898                        const size_type to,
00899                        const_reference initValue);
00900 
00901     /**
00902      * Assign copies of \a initValue to the genericVector such that the given
00903      * interval is covered.
00904      *
00905      * Change the size and contents of this vector to be exactly \a newSize
00906      * elements long, with all the elements initialized to the value indicated
00907      * in \a initValue.  In opposition to resize, this method does \b not copy
00908      * the previous data but changes the size of the vector, discarding all
00909      * contained data, replacing it with \a newSize copies of \a initValue.
00910      *
00911      * This is in principle an alias to resize(newSize,T(),Init).
00912      *
00913      * @param indices interval of indices to be used.
00914      * @param initValue all elements of the vector will be initialized with
00915      *        this value.
00916      */
00917     inline void assign(const iinterval& indices,
00918                        const_reference initValue);
00919 
00920     /**
00921      * Removes all elements from the genericVector (Set dimensions to 0)
00922      */
00923     void clear();
00924 
00925     /**
00926      * Returns true if the genericVector is empty
00927      */
00928     inline bool empty() const;
00929 
00930     /**
00931      * Fills the genericLattice1D elements with \a iniValue between
00932      * \a from and \a to.
00933      * @param iniValue the elements will be initialized with this
00934      *                 value.
00935      * @param from     first element index
00936      * @param to       last element index
00937      *
00938      * If \a from or \a to are out of bounds, they will be (internaly) adjusted
00939      * to correct values.
00940      *
00941      * Example:
00942      * \code
00943      *   cvr::genericLattice1D<double> myLat(-1,8,0); // genericLattice1D with 
00944      *                                                // 10 elements with 0
00945      *   myLat.fill(9,1,3);                      // myLat=[0,0,9,9,9,0,0,0,0,0]
00946      * \endcode
00947      */
00948     void fill(const_reference iniValue,
00949               const size_type from = MinIndex,
00950               const size_type to = MaxIndex);
00951 
00952     /**
00953      * Fills the genericLattice1D elements with \a iniValue between
00954      * \a from and \a to.
00955      * @param iniValue the elements will be initialized with this value.
00956      * @param indices interval of the lattice to be filled in
00957      *
00958      * If \a from or \a to are out of bounds, they will be (internaly) adjusted
00959      * to correct values.
00960      *
00961      * Example:
00962      * \code
00963      *   cvr::genericLattice1D<double> myLat(0,9,0); // genericLattice1D with
00964      *                                               // 10 elements with 0
00965      *   myLat.fill(9,iinterval(1,3));          // myLat=[0,9,9,9,0,0,0,0,0,0]
00966      * \endcode
00967      */
00968     inline void fill(const_reference iniValue,
00969                      const iinterval& indices);
00970 
00971     /**
00972      * Fills the genericLattice1D elements with data pointed by \a data
00973      * between \a from and \a to.
00974      *
00975      * @param data the data to by copied into this genericLattice1D
00976      * @param from first element index
00977      * @param to   last element index
00978      *
00979      * If \a from or \a to are out of bounds, they will be (internaly) adjusted
00980      * to correct values.
00981      *
00982      * Example:
00983      * \code
00984      *   double* data = {2,4,8,16};
00985      *   cvr::genericLattice1D<double> myLat(10,0);// genericLattice1D with 10
00986      *                                             // elements with 0
00987      *   myLat.fill(data,1,3);             // myLat=[0,2,4,8,0,0,0,0,0,0]
00988      * \endcode
00989      */
00990     void fill(const value_type data[],
00991               const size_type from = MinIndex,
00992               const size_type to = MaxIndex);
00993 
00994     /**
00995      * Fills the genericLattice1D elements with data pointed by \a data
00996      * between \a from and \a to.
00997      * @param data the data to by copied into this genericLattice1D
00998      * @param indices interval of the lattice to be filled in.
00999      *
01000      * If \a from or \a to are out of bounds, they will be (internaly) adjusted
01001      * to to correct value.
01002      *
01003      * Example:
01004      * \code
01005      *   double* data = {2,4,8,16};
01006      *   cvr::genericLattice1D<double> myLat(-5,5,0);// genericLattice1D with
01007      *                                               // 11 elements with 0
01008      *   myLat.fill(data,1,3);             // myLat=[0,0,0,0,0,0,2,4,8,0,0]
01009      * \endcode
01010      */
01011     inline void fill(const value_type data[],const iinterval& indices);
01012 
01013     /**
01014      * Fills the genericLattice1D elements from \a from to \a to with the
01015      * elements of \a vct starting at \a startAt.
01016      *
01017      * @param lat genericLattice1D with the elements to be copied
01018      * @param from first element index of the actual genericLattice1D
01019      * @param to   last element index of the actual genericLattice1D
01020      * @param startAt start index of the source genericLattice1D \a vct.
01021      */
01022     inline void fill(const genericLattice1D<T>& lat,
01023                      const size_type from = MinIndex,
01024                      const size_type to   = MaxIndex,
01025                      const size_type startAt = 0);
01026 
01027     /**
01028      * Fills the genericLattice1D elements from \a from to \a to with the
01029      * elements of \a vct starting at \a startAt.
01030      *
01031      * @param vct genericLattice1D with the elements to be copied.
01032      * @param indices interval of the lattice to be filled.
01033      * @param startAt start index of the source genericLattice1D \a vct.
01034      */
01035     inline void fill(const genericLattice1D<T>& vct,
01036                      const iinterval& indices,
01037                      const size_type startAt = 0);
01038 
01039     /**
01040      * Access element x of the genericLattice1D
01041      *
01042      * @param x index of the genericLattice1D element to be accessed. It should
01043      * be between firstIndex() and lastIndex()
01044      */
01045     inline reference at(const size_type x);
01046 
01047     /**
01048      * Access element x of the genericLattice1D in a read-only modus.
01049      *
01050      * @param x index of the genericLattice1D element to be accessed. It should
01051      * be between firstIndex() and lastIndex()
01052      */
01053     inline const_reference at(const size_type x) const;
01054 
01055     /**
01056      * Access operator (alias for at(const size_type x)).
01057      */
01058     inline reference operator[](const size_type x);
01059 
01060     /**
01061      * Constant access operator (alias for at(const size_type x) const).
01062      */
01063     inline const_reference operator[](const size_type x) const;
01064 
01065     /**
01066      * Access element \p n of the genericLattice1D as a vector.
01067      *
01068      * The lattice is indexed from 0 to to-from.
01069      *
01070      * This member function is needed for generic programming with different
01071      * container types. 
01072      */
01073     inline reference elem(const size_type n);
01074 
01075     /**
01076      * Constant access to element \p n of the genericLattice1D as a vector.
01077      *
01078      * The lattice is indexed from 0 to to-from.
01079      *
01080      * This member function is needed for generic programming with different
01081      * container types.
01082      */
01083     inline const_reference elem(const size_type n) const;
01084 
01085     /**
01086      * Assigment operator.
01087      *
01088      * Copy the contents of \a other in this %object.
01089      *
01090      * If this instance has a constReference, then only the contents are
01091      * copied.
01092      *
01093      * @param other the source genericLattice1D to be copied.
01094      *
01095      * @return Reference to the current object.
01096      */
01097     genericLattice1D<T>& copy(const genericLattice1D<T>& other);
01098 
01099     /**
01100      * Assignment operator.
01101      *
01102      * Copy a specified interval of elements of another genericLattice1D.  At
01103      * the end this vector will contain t-f+1 elements, where
01104      * f=max(other.firstIndex(),from) and t=min(other.lastIndex(),to).
01105      *
01106      * @param other the genericLattice1D to be copied.
01107      * @param from starting index
01108      * @param to final index.
01109      *
01110      * @return Reference to the current object.
01111      */
01112     genericLattice1D<T>& copy(const genericLattice1D<T>& other,
01113                               const size_type from, 
01114                               const size_type to=MaxIndex);
01115 
01116     /**
01117      * Assignment operator.
01118      *
01119      * Copy a specified interval of elements of another genericLattice1D.  At
01120      * the end this vector will contain t-f+1 elements, where f=max(0,from) and
01121      * t=min(other.lastIndex()-1,to).
01122      *
01123      * @param other the genericLattice1D to be copied.
01124      * @param indices interval of the other lattice to be copied into this one.
01125      *
01126      * @return Reference to the current object.
01127      */
01128     inline genericLattice1D<T>& copy(const genericLattice1D<T>& other,
01129                                      const iinterval& indices);
01130 
01131     /**
01132      * Assigment operator (alias for copy(other)).
01133      *
01134      * @param other the genericLattice1D to be copied
01135      *
01136      * @return a reference to the actual genericLattice1D
01137      */
01138     genericLattice1D<T>& operator=(const genericLattice1D<T>& other);
01139 
01140     /**
01141      * Returns the name of this type
01142      */
01143     virtual const std::string& name() const;
01144 
01145     /**
01146      * Create a clone of this genericLattice1D.
01147      *
01148      * @return A pointer to a copy of this genericLattice1D.
01149      */
01150     virtual genericLattice1D<T>* clone() const;
01151 
01152     /**
01153      * Create a clone of this genericLattice1D.
01154      *
01155      * @return a pointer to a copy of this genericLattice1D
01156      */
01157     virtual genericLattice1D<T>* newInstance() const;
01158 
01159     /**
01160      * Compare this genericLattice1D with other.
01161      *
01162      * @param other the other genericLattice1D to be compared with
01163      *
01164      * @return \c true if both genericLattice1Ds have the same elements and
01165      *          same definition interval
01166      */
01167     bool equals(const genericLattice1D<T>& other) const;
01168 
01169     /**
01170      * Compare this genericLattice1D with other.
01171      *
01172      * @param other the other genericLattice1D to be compared with
01173      *
01174      * @return true if both genericLattice1Ds have the same elements and same
01175      *         size
01176      */
01177     inline bool operator==(const genericLattice1D<T>& other) const;
01178 
01179     /**
01180      * Compare this genericLattice1D with other.
01181      *
01182      * @param other the other genericLattice1D to be compared with.
01183      *
01184      * @return true if both genericLattice1Ds different dimensions or elements
01185      */
01186     inline bool operator!=(const genericLattice1D<T>& other) const;
01187 
01188     /**
01189      * Copy the \a other genericLattice1D by casting each of its elements.
01190      *
01191      * @param other The genericLattice1D to be copied.
01192      *
01193      * For Example:
01194      * \code
01195      *   cvr::genericLattice1D<int> vctA(10,1);// a genericLattice1D of ints
01196      *   cvr::genericLattice1D<double> vctB;   // a genericLattice1D of doubles
01197      *
01198      *   vctB.castFrom(vctA);          // this will copy vctA in vctB!!
01199      * \endcode
01200      */
01201     template<typename U>
01202     genericLattice1D<T>& castFrom(const genericLattice1D<U>& other);
01203 
01204     /**
01205      * This is just an alias for copy(const genericLattice1D<T>&) to facilitate
01206      * generic programming.
01207      *
01208      * @param other The genericLattice1D to be copied.
01209      */
01210     genericLattice1D<T>& castFrom(const genericLattice1D<T>& other);
01211 
01212     /**
01213      * Copy a subvector of the \a other genericLattice1D by casting each of its
01214      * elements.
01215      *
01216      * @param other The genericLattice1D to be copied.
01217      * @param from starting point included
01218      * @param to end point included.
01219      *
01220      * @return A reference to the current casted subvector
01221      */
01222     template<typename U>
01223     genericLattice1D<T>& castFrom(const genericLattice1D<U>& other,
01224                                   const size_type from,
01225                                   const size_type to=MaxIndex);
01226 
01227     /**
01228      * Copy a subvector of the \a other genericLattice1D by casting each of its
01229      * elements.
01230      *
01231      * @param other The genericLattice1D to be copied.
01232      * @param indices interval of indices to be copied from \c other.
01233      *
01234      * @return A reference to the current casted subvector
01235      */
01236     template<typename U>
01237     inline genericLattice1D<T>& castFrom(const genericLattice1D<U>& other,
01238                                          const iinterval& indices);
01239 
01240     /**
01241      * This is just an alias for 
01242      * copy(const genericLattice1D<T>&,
01243      *      const size_type from, const size_type to)
01244      * to facilitate generic programming.
01245      *
01246      * @param other The genericLattice1D to be copied.
01247      * @param from starting point included
01248      * @param to end point included
01249      */
01250     genericLattice1D<T>& castFrom(const genericLattice1D<T>& other,
01251                                   const size_type from,
01252                                   const size_type to=MaxIndex);
01253 
01254 
01255     /**
01256      * This is just an alias for 
01257      * copy(const genericLattice1D<T>&, const size_type from, 
01258      *      const size_type to)
01259      * to facilitate generic programming.
01260      *
01261      * @param other The genericLattice1D to be copied.
01262      * @param indices interval of \c other to be copied in this lattice.
01263      */
01264     genericLattice1D<T>& castFrom(const genericLattice1D<T>& other,
01265                                   const iinterval& indices);
01266 
01267     /**
01268      * Cast from a std::genericLattice1D of the same type
01269      * @param other vector to be copied
01270      * @param firstIndex index used for the first element of the vector.
01271      */
01272     template<typename U>
01273     genericLattice1D<T>& castFrom(const std::vector<U>& other,
01274                                   const int firstIndex = 0);
01275 
01276     /**
01277      * Cast from a std::genericLattice1D of the same type
01278      * @param other vector to be copied
01279      * @param firstIndex index used for the first element of the vector.
01280      */
01281     template<typename U>
01282     genericLattice1D<T>& castFrom(const genericVector<U>& other,
01283                                   const int firstIndex = 0);
01284 
01285     /**
01286      * Get a read-only reference to this container as a vector
01287      */
01288     inline const genericVector<T>& getAsVector() const;
01289 
01290     /**
01291      * @name Apply Methods
01292      */
01293     //@{
01294 
01295     /**
01296      * Applies a C-function to each element of the genericLattice1D.
01297      *
01298      * In the following example, %genericLattice1D \a vct is initialized with
01299      * 4.0. After applying \a sqrt(), all elements of \a vct are 2.0.
01300      * \code
01301      * genericLattice1D<float> vct(4,4.0);
01302      * vct.apply(sqrt);
01303      * \endcode
01304      *
01305      * @param function a pointer to a C-function
01306      *
01307      * @return A reference to the actual genericLattice1D
01308      */
01309     genericLattice1D<T>& apply(T (*function)(T));
01310 
01311     /**
01312      * Applies a C-function to each element of the other genericLattice1D and
01313      * leaves the result here.
01314      *
01315      * @param other the source genericLattice1D
01316      * @param function a pointer to a C-function
01317      *
01318      * @return A reference to the actual genericLattice1D
01319      */
01320     genericLattice1D<T>& apply(const genericLattice1D<T>& other,
01321                                T (*function)(T));
01322 
01323     /**
01324      * Applies a C-function to each element of the genericLattice1D.
01325      *
01326      * @param function a pointer to a C-function
01327      *
01328      * @return A reference to the actual genericLattice1D
01329      */
01330     genericLattice1D<T>& apply(T (*function)(const T&));
01331 
01332     /**
01333      * Applies a C-function to each element the other genericLattice1D and
01334      * leaves the result here.
01335      *
01336      * @param other the genericLattice1D with the source data
01337      * @param function a pointer to a C-function
01338      *
01339      * @return A reference to the actual genericLattice1D
01340      */
01341     genericLattice1D<T>& apply(const genericLattice1D<T>& other,
01342                                T (*function)(const T&));
01343 
01344     /**
01345      * A two-parameter C-function receives the i-th elements of this and the
01346      * given genericLattice1D and the result will be left in this
01347      * genericLattice1D.  Note that both genericLattice1Ds MUST have the same
01348      * size!  If both genericLattice1Ds have different size, the function will
01349      * throw an assertion without changing anything!
01350      *
01351      * @param other the second genericLattice1D to be considered (the first
01352      *              genericLattice1D will be this object!)
01353      * @param function a pointer to a two parameters C-function
01354      *
01355      * @return A reference to the actual genericLattice1D.
01356      */
01357     genericLattice1D<T>& apply(const genericLattice1D<T>& other,
01358                             T (*function)(const T&,const T&));
01359 
01360     /**
01361      * A two-parameter C-function receives the i-th elements of this and the
01362      * given genericLattice1D and the result will be left in this
01363      * genericLattice1D.  Note that both genericLattice1Ds MUST have the same
01364      * size!  If both genericLattice1Ds have different size, the function will
01365      * throw an assertion without changing anything!
01366      *
01367      * @param other the second genericLattice1D to be considered (the first
01368      *              genericLattice1D will be this object!)
01369      * @param function a pointer to a two parameters C-function
01370      *
01371      * @return A reference to the actual genericLattice1D.
01372      */
01373     genericLattice1D<T>& apply(const genericLattice1D<T>& other,
01374                                T (*function)(T,T));
01375 
01376     /**
01377      * A two-parameter C-function receives the i-th elements of the given
01378      * genericLattice1Ds and leaves the result here.  Note that both
01379      * genericLattice1Ds MUST have the same size!  If both genericLattice1Ds
01380      * have different size, the function will throw an assertion without
01381      * changing anything!
01382      *
01383      * The following example uses cvr::min as function. The genericLattice1Ds
01384      * \a a and \a b contain the values [1,2,3,4] and [4,3,2,1],
01385      * respectively. After applying the function, %genericLattice1D \a c
01386      * contains the values [1,2,2,1].
01387      *
01388      * \code
01389      * igenericLattice1D a,b,c;
01390      * int i=0;
01391      * for (i=0; i<4; ++i) {
01392      *   a.at(i)=i+1;
01393      *   b.at(i)=4-i;
01394      * }
01395      * c.apply(a,b,cvr::min);
01396      * \endcode
01397      *
01398      * @param a the first genericLattice1D
01399      * @param b the second genericLattice1D
01400      * @param function a pointer to a two parameters C-function
01401      *
01402      * @return A reference to the actual genericLattice1D
01403      */
01404     genericLattice1D<T>& apply(const genericLattice1D<T>& a,
01405                                const genericLattice1D<T>& b,
01406                                T (*function)(const T&,const T&));
01407 
01408     /**
01409      * A two-parameter C-function receives the i-th elements of the
01410      * given genericLattice1Ds and leaves the result here.
01411      *
01412      * Note that both genericLattice1Ds MUST have the same size!  If both
01413      * genericLattice1Ds have different size, the function will throw an
01414      * assertion without changing anything!
01415      *
01416      * @param a the first genericLattice1D
01417      * @param b the second genericLattice1D
01418      * @param function a pointer to a two parameters C-function
01419      *
01420      * @return a reference to the actual genericLattice1D
01421      */
01422     genericLattice1D<T>& apply(const genericLattice1D<T>& a,
01423                                const genericLattice1D<T>& b,
01424                                T (*function)(T,T));
01425 
01426     //@}
01427 
01428     /**
01429      * @name Input and Output
01430      */
01431     //@{
01432     /**
01433      * Write the object in the given ioHandler
01434      */
01435     virtual bool write(ioHandler& handler,const bool complete = true) const;
01436 
01437     /**
01438      * Read the object from the given ioHandler
01439      */
01440     virtual bool read(ioHandler& handler,const bool complete = true);
01441     //@}
01442 
01443   protected:
01444     /**
01445      * Index of the last element of the genericLattice1D.
01446      *
01447      * We sacrifice this sizeof(int) to improve speed in many operations that
01448      * require this first index.
01449      */
01450     size_type first_;
01451 
01452     /**
01453      * Index of the last element of the genericLattice1D (always
01454      * vectorSize-1)
01455      *
01456      * We sacrifice this sizeof(int) to improve speed in many operations that
01457      * require this last index.
01458      */
01459     size_type last_;
01460 
01461     /**
01462      * Pointer to the element with index zero.
01463      */
01464     pointer theElements0_;
01465 
01466     /**
01467      * A generic vector is used to contain the data.
01468      */
01469     genericVector<T> data_;
01470   };
01471 
01472 } // namespace cvr
01473 
01474 namespace std {
01475   /*
01476    * outputs the elements of the genericLattice1D on a std::stream
01477    */
01478   template <typename T>
01479   ostream& operator<<(ostream& s,const cvr::genericLattice1D<T>& v);
01480 }
01481 
01482 #include "cvrGenericLattice1D_inline.h"
01483 #include "cvrGenericLattice1D_template.h"
01484 
01485 #else
01486 
01487 #include "cvrGenericLattice1D_template.h"
01488 
01489 #endif
01490 

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