last update 20 Sep 2009 |
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 cvrGenericLattice2D.h 00043 * Contains a template class to describe 2D lattices, which are like 00044 * matrices but addressable with negative indices, and whose rows are 00045 * of type cvr::genericLattice1D. 00046 * \author Pablo Alvarado 00047 * \date 27.12.2007 00048 * 00049 * $Id: cvrGenericLattice2D.h,v 1.19 2007/09/15 03:36:57 alvarado Exp $ 00050 */ 00051 00052 #ifndef _CVR_GENERIC_LATTICE_2_D_H_ 00053 #define _CVR_GENERIC_LATTICE_2_D_H_ 00054 00055 #include "cvrContainer.h" 00056 #include "cvrGenericLattice1D.h" 00057 #include "cvrPoint.h" 00058 #include "cvrRectangle.h" 00059 #include "cvrAssert.h" 00060 #include "cvrResizeType.h" 00061 #include "cvrDebugIterator.h" 00062 #include "cvrDeprecated.h" 00063 00064 namespace cvr { 00065 /** 00066 * Container class for two dimensional lattices. 00067 * 00068 * The cvr::genericLattice2D class is a container class implemented as a 00069 * template. 00070 * 00071 * The cvr::genericLattice2D class allows the representation of two 00072 * dimensional lattice, containing an element at each point of the lattice. 00073 * The points are inidicated with an ordered pair \e n x \e m, where n and m 00074 * can be taken from intervals selected at construction time, that may 00075 * include negative values. 00076 * 00077 * The type of the elements contained must be static in nature. All types 00078 * defined in cvrTypes.h use static members and can be contained by the 00079 * cvr::genericLattice1D and cvr::genericLattice2D classes. 00080 * 00081 * If you need to create a genericLattice2D of floats with 20 rows and 00082 * 15 columns, all elements initialized with an initial value of 00083 * 4.27 just create it: 00084 * 00085 * \code 00086 * cvr::genericLattice2D<float> myMat(-9,10, 00087 * -7,8,4.27f) // creates genericLattice2D 00088 * // with 300 elements all 00089 * // initialized with 4.27f 00090 * \endcode 00091 * 00092 * To access the cvr::genericLattice2D elements use the access operators. 00093 * There are many possibilities. With at(const int row, const int 00094 * col) it is possible to access an element directly. 00095 * 00096 * With getRow(const int row) you can get the row cvr::lattice1D. You cannot 00097 * for instance resize nor change the memory referenced in this lattice1D 00098 * (see cvr::lattice1D::resize). For example: 00099 * 00100 * \code 00101 * float accu = 0; // initialize accumulator 00102 * cvr::genericLattice2D<float> myMat(-9,10,-7,8,4.27f) 00103 * cvr::genericLattice1D<float> myLat; 00104 * 00105 * for (int j = myMat.firstRow(); j <= myMat.lastRow(); j++) { 00106 * for (int i = myMat.firstColumn(); i <= myMat.lastColumn(); i++) { 00107 * tmp += myMat.at(j,i); // access each element of the genericLattice2D: 00108 * // j is the row and i the column 00109 * } 00110 * } 00111 * 00112 * myMat.getRowCopy(5,myLat); // copy the row with index 5 in myLat! 00113 * myLat.resize(-6,6); // Valid, the vector has its own memory! 00114 * myMat.getRow(5).resize(-6,6); // ERROR!! the vector is not resizable! 00115 * 00116 * \endcode 00117 * 00118 * Lattices in the CVR-Lib use always a continuous block of memory, which 00119 * allows efficient elementwise operations. 00120 * 00121 * @see cvr::lattice2D 00122 * 00123 * The genericLattice2D has following methods: 00124 * - Constructors Constructors 00125 * - You can construct an empty genericLattice2D with the default 00126 * constructor (genericLattice2D()). 00127 * - If you know the number of rows and columns use 00128 * genericLattice2D(const int fromRow,const int toRow, 00129 * const int fromColumn, const int toRow, 00130 * const T& initialValue) 00131 * - Access members 00132 * - at(), operator[]() 00133 * - The rows() member returns the number of rows of the genericLattice2D. 00134 * - The columns() member returns the number of columns of the 00135 genericLattice2D. 00136 * - Fill and Copy members 00137 * - With the fill() members you can fill the genericLattice2D with a given 00138 * constant value or with values taken from other matrices. 00139 * - With the copy() member you can copy another genericLattice2D. 00140 * - You can specify, that the genericLattice2D should be used just as a 00141 * wrapper-object to access external memory regions: useExternData(). 00142 * To check if a genericLattice2D is a wrapper-object you can use 00143 * ownsData(). 00144 * - Iterators 00145 * - It is possible to iterate within the genericLattice2D by making use of 00146 * the genericLattice2D iterators. (see begin() for more information) 00147 * - Instead of reverse_iterators as in the STL we use iterators 00148 * going backwards, due to faster execution times (see 00149 * inverseBegin() for more information) 00150 * 00151 * @ingroup gLinearAlgebra 00152 * @ingroup gAggregate 00153 */ 00154 template<class T> 00155 class genericLattice2D : public container { 00156 public: 00157 00158 /** 00159 * \name Internal types and classes 00160 */ 00161 //@{ 00162 00163 /** 00164 * Exception thrown when a constant reference is violated. 00165 */ 00166 typedef cvr::constReferenceException constReferenceException; 00167 00168 /** 00169 * Type of the contained data 00170 */ 00171 typedef T value_type; 00172 00173 /** 00174 * Return type of the size() member 00175 */ 00176 typedef ipoint size_type; 00177 00178 /** 00179 * Vector type of each row 00180 */ 00181 typedef genericLattice1D<T> row_type; 00182 00183 /** 00184 * Pointer to value_type 00185 */ 00186 typedef T* pointer; 00187 00188 /** 00189 * Const pointer to value_type 00190 */ 00191 typedef const T* const_pointer; 00192 00193 /** 00194 * Reference to value_type 00195 */ 00196 typedef T& reference; 00197 00198 /** 00199 * Const reference to value_type 00200 */ 00201 typedef const T& const_reference; 00202 00203 # ifdef NDEBUG 00204 /** 00205 * Iterator type (allows read and write operations) 00206 * 00207 * The use of the iterator classes is similar to the iterators of 00208 * the STL (Standard Template Library). See cvr::genericLattice2D::begin() 00209 * for an example . 00210 * 00211 * For the debugging version of the iterators, boundary check will be 00212 * done! This explains the low speed of the iterators of the debug 00213 * version. In the release version, no boundary check will be done, 00214 * and the iterators are sometimes a factor 10 faster than the 00215 * debug iterators. 00216 * 00217 * The use of the access operator at() is faster than the iterators in the 00218 * debug version only. If you need to iterate on a genericLattice2D use 00219 * iterators instead (in the release version iterators are approximately a 00220 * factor 3 faster than "at()"). 00221 * 00222 * \warning Try to use the prefix incremental operator (i.e. ++it) over the 00223 * postfix operator (i.e. it++) to allow efficient code also in 00224 * debug-modus! 00225 */ 00226 typedef T* iterator; 00227 00228 /** 00229 * Constant iterator type (allows read-only operations) 00230 * 00231 * The use of the iterator classes is similar to the iterators of 00232 * the STL (Standard Template Library). See cvr::genericLattice2D::begin() 00233 * for an example. 00234 * 00235 * For the debugging version of the iterators, boundary check will be 00236 * done! This explains the low speed of the iterators of the debug 00237 * version. In the release version, no boundary check will be done, 00238 * and the iterators are sometimes a factor 10 faster than the 00239 * debug iterators. 00240 * 00241 * The use of the access operator at() is faster than the iterators in the 00242 * debug version only. If you need to iterate on a genericLattice2D use 00243 * iterators instead (in the release version iterators are approximately a 00244 * factor 3 faster than "at()"). 00245 * 00246 * \warning Try to use the prefix incremental operator (i.e. ++it) instead 00247 * of the postfix operator (i.e. it++) to allow efficient code also in 00248 * debug-modus! 00249 */ 00250 typedef const T* const_iterator; 00251 00252 # else 00253 00254 /** 00255 * Iterator type (allows read and write operations) 00256 * 00257 * The use of the iterator classes is similar to the iterators of 00258 * the STL (Standard Template Library). See cvr::genericLattice2D::begin() 00259 * for an example . 00260 * 00261 * For the debugging version of the iterators, boundary check will be 00262 * done! This explains the low speed of the iterators of the debug 00263 * version. In the release version, no boundary check will be done, 00264 * and the iterators are sometimes a factor 10 faster than the 00265 * debug iterators. 00266 * 00267 * The use of the access operator at() is faster than the iterators in the 00268 * debug version only. If you need to iterate on a genericLattice2D use 00269 * iterators instead (in the release version iterators are approximately a 00270 * factor 3 faster than "at()"). 00271 * 00272 * \warning Try to use the prefix incremental operator (i.e. ++it) over 00273 * the postfix operator (i.e. it++) to allow efficient code also in 00274 * debug-modus! 00275 */ 00276 typedef internal::debugIterator<genericLattice2D<T>,false> iterator; 00277 00278 /** 00279 * Constant iterator type (allows read-only operations) 00280 * 00281 * The use of the iterator classes is similar to the iterators of 00282 * the STL (Standard Template Library). See cvr::genericLattice2D::begin() 00283 * for an example. 00284 * 00285 * For the debugging version of the iterators, boundary check will be 00286 * done! This explains the low speed of the iterators of the debug 00287 * version. In the release version, no boundary check will be done, 00288 * and the iterators are sometimes a factor 10 faster than the 00289 * debug iterators. 00290 * 00291 * The use of the access operator at() is faster than the iterators in the 00292 * debug version only. If you need to iterate on a genericLattice2D use 00293 * iterators instead (in the release version iterators are approximately a 00294 * factor 3 faster than "at()"). 00295 * 00296 * \warning Try to use the prefix incremental operator (i.e. ++it) instead 00297 * of the postfix operator (i.e. it++) to allow efficient code also in 00298 * debug-modus! 00299 */ 00300 typedef internal::debugIterator<genericLattice2D<T>,true> const_iterator; 00301 # endif 00302 //@} 00303 00304 /** 00305 * Default constructor creates an empty genericLattice2D 00306 */ 00307 genericLattice2D(); 00308 00309 /** 00310 * Create a genericLattice2D with uninitialized elements. 00311 * 00312 * @param fromRow lowest row index 00313 * @param fromCol lowest column index 00314 * @param toRow highest row index (inclusive) 00315 * @param toCol highest column index (inclusive) 00316 */ 00317 genericLattice2D(const int fromRow, 00318 const int fromCol, 00319 const int toRow, 00320 const int toCol); 00321 00322 /** 00323 * Create a \a rows x \a cols genericLattice2D with uninitialized elements. 00324 * 00325 * @param from lowest row and column 00326 * @param to highest row and column 00327 */ 00328 genericLattice2D(const size_type& from, 00329 const size_type& to); 00330 00331 /** 00332 * Create a genericLattice2D with uninitialized elements. 00333 * 00334 * @param rows interval used for the rows 00335 * @param columns interval used for the columns 00336 */ 00337 genericLattice2D(const iinterval& rows, 00338 const iinterval& columns); 00339 00340 /** 00341 * Create a genericLattice2D and initialize all elements with the given 00342 * value. 00343 * 00344 * @param fromRow lowest row index 00345 * @param fromCol lowest column index 00346 * @param toRow highest row index (inclusive) 00347 * @param toCol highest column index (inclusive) 00348 * @param value value used for initializing the elements 00349 */ 00350 genericLattice2D(const int fromRow, 00351 const int fromCol, 00352 const int toRow, 00353 const int toCol, 00354 const T& value); 00355 00356 /** 00357 * Create a genericLattice2D and initialize all elements with the given 00358 * value. 00359 * 00360 * @param from lowest index 00361 * @param to highest index (inclusive) 00362 * @param value value used for initializing the elements 00363 */ 00364 genericLattice2D(const size_type& from, 00365 const size_type& to, 00366 const T& value); 00367 00368 /** 00369 * Create a genericLattice2D and initialize all elements with the given 00370 * value. 00371 * 00372 * @param rows interval used for the rows 00373 * @param columns interval used for the columns 00374 * @param value value used for initializing the elements 00375 */ 00376 genericLattice2D(const iinterval& rows, 00377 const iinterval& columns, 00378 const T& value); 00379 00380 /** 00381 * Create a genericLattice2D and initialize all elements with the data 00382 * pointed by \a data. 00383 * 00384 * The first elements of the data will be \b copied on the 00385 * first row, the next ones on the second row and so on. 00386 * 00387 * @param fromRow lowest row index 00388 * @param fromCol lowest column index 00389 * @param toRow highest row index (inclusive) 00390 * @param toCol highest column index (inclusive) 00391 * @param data pointer to the memory block with the data to be initialized 00392 * with. 00393 */ 00394 genericLattice2D(const int fromRow, 00395 const int fromCol, 00396 const int toRow, 00397 const int toCol, 00398 const T data[]); 00399 00400 /** 00401 * Create a genericLattice2D and initialize all elements with the data 00402 * pointed by \a data. 00403 * 00404 * The first elements of the data will be \b copied on the 00405 * first row, the next ones on the second row and so on. 00406 * 00407 * @param from lowest index 00408 * @param to highest index (inclusive) 00409 * @param data pointer to the memory block with the data to be initialized 00410 * with. 00411 */ 00412 genericLattice2D(const size_type& from, 00413 const size_type& to, 00414 const T data[]); 00415 00416 /** 00417 * Create a genericLattice2D and initialize all elements with the data 00418 * pointed by \a data. 00419 * 00420 * The first elements of the data will be \b copied on the 00421 * first row, the next ones on the second row and so on. 00422 * 00423 * @param rows interval used for the rows 00424 * @param columns interval used for the columns 00425 * @param data pointer to the memory block with the data to be initialized 00426 * with. 00427 */ 00428 genericLattice2D(const iinterval& rows, 00429 const iinterval& columns, 00430 const T data[]); 00431 00432 /** 00433 * Create a genericLattice2D and use the given \a data as if it was given 00434 * through the useExternData(). 00435 * 00436 * @see useExternData() 00437 * 00438 * The first elements of the data will be copied on the first row, the next 00439 * ones on the second row and so on. 00440 * 00441 * \note Please observe that the last argument makes a huge difference to 00442 * the constructors that do not have it. Here the data is \b not copied, 00443 * just a reference is kept. Without the last argument, the data is 00444 * always copied. 00445 * 00446 * @param fromRow lowest row index 00447 * @param fromCol lowest column index 00448 * @param toRow highest row index (inclusive) 00449 * @param toCol highest column index (inclusive) 00450 * @param data pointer to the memory block with the data to be initialized 00451 * with. 00452 * @param constRef usually you want this value to be ConstantReference. 00453 */ 00454 genericLattice2D(const int fromRow, 00455 const int fromCol, 00456 const int toRow, 00457 const int toCol, 00458 T data[], 00459 const eConstantReference constRef); 00460 00461 /** 00462 * Create a genericLattice2D and use the given \a data as if it was given 00463 * through the useExternData(). 00464 * 00465 * @see useExternData() 00466 * 00467 * The first elements of the data will be copied on the first row, the next 00468 * ones on the second row and so on. 00469 * 00470 * \note Please observe that the last argument makes a huge difference to 00471 * the constructors that do not have it. Here the data is \b not copied, 00472 * just a reference is kept. Without the last argument, the data is 00473 * always copied. 00474 * 00475 * @param from lowest index 00476 * @param to highest index (inclusive) 00477 * @param data pointer to the memory block with the data to be initialized 00478 * with. 00479 * @param constRef usually you want this value to be ConstantReference. 00480 */ 00481 genericLattice2D(const size_type& from, 00482 const size_type& to, 00483 T data[], 00484 const eConstantReference constRef); 00485 00486 00487 /** 00488 * Create a genericLattice2D and use the given \a data as if it was given 00489 * through the useExternData(). 00490 * 00491 * @see useExternData() 00492 * 00493 * The first elements of the data will be copied on the first row, the next 00494 * ones on the second row and so on. 00495 * 00496 * \note Please observe that the last argument makes a huge difference to 00497 * the constructors that do not have it. Here the data is \b not copied, 00498 * just a reference is kept. Without the last argument, the data is 00499 * always copied. 00500 * 00501 * @param rows interval for rows 00502 * @param columns interval for columns 00503 * @param data pointer to the memory block with the data to be initialized 00504 * with. 00505 * @param constRef usually you want this value to be ConstantReference. 00506 */ 00507 genericLattice2D(const iinterval& rows, 00508 const iinterval& columns, 00509 T data[], 00510 const eConstantReference constRef); 00511 00512 /** 00513 * Copy constructor. 00514 * 00515 * Create this genericLattice2D as a copy of another genericLattice2D. 00516 * 00517 * @param other the genericLattice2D to be copied. 00518 */ 00519 genericLattice2D(const genericLattice2D<T>& other); 00520 00521 /** 00522 * Copy constructor. 00523 * 00524 * Create this genericLattice2D as a copy of another genericLattice2D for 00525 * this const version, the data will be always copied! 00526 * 00527 * @param other the genericLattice2D to be copied. 00528 * @param fromRow initial row of the other genericLattice2D to be copied 00529 * @param fromCol initial column of the other genericLattice2D to be copied 00530 * @param toRow last row to be copied of the other genericLattice2D 00531 * @param toCol last column to be copied of the other genericLattice2D 00532 */ 00533 genericLattice2D(const genericLattice2D<T>& other, 00534 const int fromRow, 00535 const int fromCol, 00536 const int toRow=MaxIndex, 00537 const int toCol=MaxIndex); 00538 00539 /** 00540 * Copy constructor. 00541 * 00542 * Create this genericLattice2D as a copy of a sublattice2D of another 00543 * genericLattice2D. 00544 * 00545 * @param other the genericLattice2D to be copied. 00546 * @param from initial position in the other genericLattice2D to be copied 00547 * @param to last position to be copied of the other genericLattice2D 00548 */ 00549 genericLattice2D(const genericLattice2D<T>& other, 00550 const size_type& from, 00551 const size_type& to); 00552 00553 /** 00554 * Copy constructor. 00555 * 00556 * Create this genericLattice2D as a copy of a sublattice2D of another 00557 * genericLattice2D. 00558 * 00559 * @param other the genericLattice2D to be copied. 00560 * @param rows interval of rows to be copied. 00561 * @param columns interval of columns to be copied. 00562 */ 00563 genericLattice2D(const genericLattice2D<T>& other, 00564 const iinterval& rows, 00565 const iinterval& columns); 00566 00567 /** 00568 * Copy constructor. 00569 * 00570 * Create this genericLattice2D as a copy of another genericLattice2D 00571 * taking only the rows indicated by the vector. 00572 * 00573 * The data will be always copied! Multiple occurence of one row index in 00574 * \a rows is allowed. 00575 * 00576 * @param other the genericLattice2D to be copied. 00577 * @param rows indices of the rows to be copied 00578 */ 00579 genericLattice2D(const genericLattice2D<T>& other, 00580 const genericLattice1D<int>& rows); 00581 00582 /** 00583 * Destructor 00584 */ 00585 virtual ~genericLattice2D(); 00586 00587 /** 00588 * Owns this %object the data? 00589 * returns <em>false</em> if this genericLattice2D contains a reference to 00590 * extern data. 00591 */ 00592 inline bool ownsData() const; 00593 00594 /** 00595 * If this object does not own its data, this member will create a new 00596 * memory buffer with the same data and will make this genericLattice2D as 00597 * its owner. If this genericLattice2D already owns its data nothing 00598 * happens. 00599 */ 00600 void restoreOwnership(); 00601 00602 /** 00603 * Reference to extern data. 00604 * 00605 * This member allows the use of this %object as an access-functor for 00606 * the 'data'. An access to the element at (r,c) is equivalent to 00607 * data[r*columns() + c]. 00608 * The user must take care for memory allocation and deallocation: 00609 * this object will never delete the data!. 00610 * If <em>rows</em> and <em>cols</em> are invalid dimensions, the 00611 * behaviour will be unpredictible. 00612 * @param fromRow initial row index 00613 * @param fromCol initial column index 00614 * @param toRow final row index 00615 * @param toCol final column index 00616 * @param data a pointer to the memory block to be used 00617 * @param constRef constant reference 00618 * 00619 * For an example see attach() 00620 */ 00621 void useExternData(const int fromRow, 00622 const int fromCol, 00623 const int toRow, 00624 const int toCol, 00625 T data[], 00626 const eConstantReference constRef=VariableReference); 00627 00628 /** 00629 * Reference to extern data. 00630 * 00631 * This member allows the use of this %object as an access-functor for 00632 * the 'data'. An access to the element at (r,c) is equivalent to 00633 * data[r*columns() + c]. 00634 * The user must take care for memory allocation and deallocation: 00635 * this object will never delete the data!. 00636 * If <em>rows</em> and <em>cols</em> are invalid dimensions, the 00637 * behaviour will be unpredictible. 00638 * @param from initial index 00639 * @param to initial index 00640 * @param data a pointer to the memory block to be used 00641 * @param constRef constant reference 00642 * 00643 * For an example see attach() 00644 */ 00645 inline void 00646 useExternData(const size_type& from, 00647 const size_type& to, 00648 T data[], 00649 const eConstantReference constRef=VariableReference); 00650 00651 /** 00652 * Reference to extern data. 00653 * 00654 * This member allows the use of this %object as an access-functor for 00655 * the 'data'. An access to the element at (r,c) is equivalent to 00656 * data[r*columns() + c]. 00657 * The user must take care for memory allocation and deallocation: 00658 * this object will never delete the data!. 00659 * If <em>rows</em> and <em>cols</em> are invalid dimensions, the 00660 * behaviour will be unpredictible. 00661 * @param rows interval of rows to be used. 00662 * @param columns interval of columns to be used. 00663 * @param data a pointer to the memory block to be used. 00664 * @param constRef constant reference. 00665 * 00666 * For an example see attach() 00667 */ 00668 inline void 00669 useExternData(const iinterval& rows, 00670 const iinterval& columns, 00671 T data[], 00672 const eConstantReference constRef=VariableReference); 00673 00674 00675 /** 00676 * Attach extern data to the genericLattice2D. 00677 * 00678 * This member allows the use of this %object as an access-functor for 00679 * the 'data'. An access to the element at (r,c) is equivalent to 00680 * data[r*columns() + c]. 00681 * If <em>rows</em> and <em>cols</em> are invalid dimensions, the 00682 * behaviour will be unpredictible. 00683 * 00684 * The memory will be administrated by this genericLattice2D object, 00685 * and may be deleted if required (genericLattice2D deleted or 00686 * resized!). The user should not try to manipulate the memory 00687 * allocation of the data after the attachment! See also 00688 * useExternData(). 00689 * 00690 * @param fromRow initial row index 00691 * @param fromCol initial column index 00692 * @param toRow final row index (inclusive) 00693 * @param toCol final column index (inclusive) 00694 * @param data a pointer to the memory block to be used 00695 */ 00696 void attach(const int fromRow, 00697 const int fromCol, 00698 const int toRow, 00699 const int toCol, 00700 T* data); 00701 00702 /** 00703 * Attach extern data to the genericLattice2D. 00704 * 00705 * This member allows the use of this %object as an access-functor for 00706 * the 'data'. An access to the element at (r,c) is equivalent to 00707 * data[r*columns() + c]. 00708 * If <em>rows</em> and <em>cols</em> are invalid dimensions, the 00709 * behaviour will be unpredictible. 00710 * 00711 * The memory will be administrated by this genericLattice2D object, 00712 * and may be deleted if required (genericLattice2D deleted or 00713 * resized!). The user should not try to manipulate the memory 00714 * allocation of the data after the attachment! See also 00715 * useExternData(). 00716 * 00717 * @param from initial index 00718 * @param to final index (inclusive) 00719 * @param data a pointer to the memory block to be used 00720 */ 00721 inline void attach(const size_type& from, 00722 const size_type& to, 00723 T* data); 00724 00725 /** 00726 * Attach extern data to the genericLattice2D. 00727 * 00728 * This member allows the use of this %object as an access-functor for 00729 * the 'data'. An access to the element at (r,c) is equivalent to 00730 * data[r*columns() + c]. 00731 * If <em>rows</em> and <em>cols</em> are invalid dimensions, the 00732 * behaviour will be unpredictible. 00733 * 00734 * The memory will be administrated by this genericLattice2D object, 00735 * and may be deleted if required (genericLattice2D deleted or 00736 * resized!). The user should not try to manipulate the memory 00737 * allocation of the data after the attachment! See also 00738 * useExternData(). 00739 * 00740 * @param rows interval for rows 00741 * @param columns interval fro columns 00742 * @param data a pointer to the memory block to be used 00743 */ 00744 inline void attach(const iinterval& rows, 00745 const iinterval& columns, 00746 T* data); 00747 00748 00749 /** 00750 * Free the data of this object and hand it over to the 00751 * "receiver". The value of ownsData is also transfered to the 00752 * receiver. (see Note). 00753 * 00754 * This function makes a "memory block transfusion" to another 00755 * genericLattice2D. It is a very efficient way to make a copy of 00756 * this genericLattice2D, if you don't need the source data anymore! 00757 * 00758 * If the current lattice2D does not own its data, neither will the 00759 * receiver lattice2D, which will also be just a wrapper of the same data. 00760 * 00761 * If the current lattice2D is lined, then the other lattice2D will end as 00762 * an exact copy if this one, and this one will be emptied after the 00763 * detachment. In other words, it works similar like a swap() followed by 00764 * clear(). In extremely time critical situations you may want to use 00765 * swap() as it does not need to deallocate any memory of the receiver and 00766 * is therefore a little bit faster. 00767 * 00768 * Please take special care to the memory management issues involved if the 00769 * current object does not own its data, as its control will still be 00770 * yours. 00771 * 00772 * At the end of the detachment, this genericLattice2D will be empty. 00773 * 00774 * @param receiver the genericLattice2D which will receive the memory 00775 * block. All data of that genericLattice2D will be first deleted! 00776 */ 00777 void detach(genericLattice2D<T>& receiver); 00778 00779 /** 00780 * Free the data of this object and hand it over to the 00781 * "receiver". The value of ownsData is also transfered to the 00782 * receiver. (see Note). 00783 * 00784 * This function makes a "memory block transfusion" to a vector by 00785 * concatenating the rows of the genericLattice2D. It is a very efficient 00786 * way to move the data of this genericLattice2D into a vector, if you 00787 * don't need the source data anymore! 00788 * 00789 * \b Note: If the attach() or useExternData() methods of this 00790 * genericLattice2D have been called before detachment, the same rules for 00791 * memory management apply now for the \c receiver. 00792 * 00793 * At the end of the detachment, this genericLattice2D will be empty. 00794 * 00795 * @param receiver the genericLattice2D which will receive the memory 00796 * block. 00797 * All data of that genericLattice2D will be first deleted! 00798 */ 00799 void detach(genericVector<T>& receiver); 00800 00801 /** 00802 * Exchange (in a fast way) the data between this and the other 00803 * genericLattice2D. 00804 * 00805 * Similar to detach(), this method will exchange the complete memory 00806 * blocks, avoiding an element-wise copy. 00807 * @param other the genericLattice2D with which the data will be exchanged. 00808 */ 00809 void swap(genericLattice2D<T>& other); 00810 00811 /** 00812 * Number of rows of the genericLattice2D 00813 */ 00814 inline int rows() const; 00815 00816 /** 00817 * Number of columns of the genericLattice2D 00818 */ 00819 inline int columns() const; 00820 00821 /** 00822 * Index of the first row (rows()-1) 00823 */ 00824 inline int firstRow() const; 00825 00826 /** 00827 * Index of the first columns (columns()-1) 00828 */ 00829 inline int firstColumn() const; 00830 00831 /** 00832 * Index of the last row (rows()-1) 00833 */ 00834 inline int lastRow() const; 00835 00836 /** 00837 * Index of the last columns (columns()-1) 00838 */ 00839 inline int lastColumn() const; 00840 00841 /** 00842 * Returns the size of the %genericLattice2D in a cvr::ipoint structure. 00843 * 00844 * @return cvr::ipoint with the number of columns in its 00845 * \a x coordinate and the number of rows in its 00846 * \a y coordinate. 00847 */ 00848 inline const size_type& size() const; 00849 00850 /** 00851 * Returns a read-only reference to the last index of the lattice2D 00852 * 00853 * @return cvr::ipoint with the number of columns in its 00854 * \a x coordinate and the number of rows in its 00855 * \a y coordinate. 00856 */ 00857 inline const size_type& firstIndex() const; 00858 00859 /** 00860 * Returns a read-only reference to the last index of the lattice2D 00861 * 00862 * @return cvr::ipoint with the number of columns in its 00863 * \a x coordinate and the number of rows in its 00864 * \a y coordinate. 00865 */ 00866 inline const size_type& lastIndex() const; 00867 00868 /** 00869 * Return iterator to the begin of the genericLattice2D. 00870 * 00871 * The use of the interators is similar to the iterators of the 00872 * Standard Template Library (STL). 00873 * If you need to iterate on all elements of the genericLattice2D, you can 00874 * use following code: 00875 * \code 00876 * int tmp,accu; // a temporal variable 00877 * cvr::genericLattice2D<int> myMat(10,8,1); // a vector with 10 elements 00878 * cvr::genericLattice2D<int>::iterator it; // an iterator 00879 * 00880 * for (it=myMat.begin();it!=myMat.end();it++) { 00881 * tmp = *it; // tmp has value of element pointed 00882 * // by the iterator. 00883 * accu += tmp; 00884 * (*it) = accu; // change the value in the lattice. 00885 * } 00886 * \endcode 00887 * 00888 * Please note that if you define \c it as a const_iterator, 00889 * you can not do something like <code>*it=accu</code>. 00890 */ 00891 inline iterator begin(); 00892 00893 /** 00894 * Return first element of the genericLattice2D as a const_iterator. 00895 * 00896 * Note that you can not change the values of the genericLattice2D 00897 * elements when you use a const_iterator. See also begin() for an example 00898 */ 00899 inline const_iterator begin() const; 00900 00901 /** 00902 * returns iterator to the end of the genericLattice2D 00903 */ 00904 inline iterator end(); 00905 00906 /** 00907 * returns iterator to the end of the genericLattice2D 00908 */ 00909 inline const_iterator end() const; 00910 00911 00912 /** 00913 * This method returns an iterator that points to the \b last valid element 00914 * of the genericLattice2D. It is used for inverse order iteration through 00915 * the genericLattice2D using normal iterators (as opposed to reverse 00916 * iterators). This has the advantage that iterators going from front to 00917 * end and in the inverse direction are the same and can thus be compared, 00918 * copied etc. Further the implementation of reverse_iterators is not as 00919 * fast as that of iterators and thus not desired in the CVR-Lib. 00920 * 00921 * See cvr::genericVector<T>::inverseBegin() for an example. 00922 */ 00923 inline iterator inverseBegin(); 00924 00925 /** 00926 * This method returns an iterator that points to the \b last valid element 00927 * of the genericLattice2D. See inverseBegin() for more details. 00928 */ 00929 inline const_iterator inverseBegin() const; 00930 00931 /** 00932 * This method returns an iterator that points to the element \b 00933 * before the \b first valid element of the genericLattice2D. It is used to 00934 * mark the end for inverse order iteration through the genericLattice2D 00935 * using normal iterators (as opposed to reverse iterators). This 00936 * has the advantage that iterators going from front to end and in 00937 * the inverse direction are the same and can thus be compared, 00938 * copied etc. 00939 */ 00940 inline iterator inverseEnd(); 00941 00942 /** 00943 * This method returns an iterator that points to the element \b 00944 * before the \b first valid element of the genericLattice2D. 00945 */ 00946 inline const_iterator inverseEnd() const; 00947 00948 /** 00949 * Change the dimensions of the genericLattice2D. 00950 * 00951 * @param fromRow initial row index 00952 * @param fromCol initial column index 00953 * @param toRow final row index (inclusive) 00954 * @param toCol final column index (inclusive) 00955 * @param iniValue the initialization value. 00956 * @param resizeType specifies what should happen with the data of the 00957 * resized lattice2D. 00958 * 00959 * If the resize is possible (see useExternData()), this %object 00960 * will always owns the data! 00961 * 00962 * @see eResizeType, assign(),allocate() 00963 */ 00964 void resize(const int fromRow, 00965 const int fromCol, 00966 const int toRow, 00967 const int toCol, 00968 const T& iniValue, 00969 const eResizeType resizeType=CopyAndInit); 00970 00971 /** 00972 * Change the dimensions of the genericLattice2D. 00973 * 00974 * @param from initial index 00975 * @param to final index 00976 * @param iniValue value to initialize the rest 00977 * @param resizeType specifies what should happen with the data of the 00978 * resized lattice2D. 00979 * 00980 * If the resize is possible (see useExternData()), this %object 00981 * will always own the data! 00982 * 00983 * This is equivalent to call 00984 * resize(newDim.y,newDim.x,iniValue,resizeType) 00985 * 00986 * @see eResizeType 00987 */ 00988 inline void resize(const size_type& from, 00989 const size_type& to, 00990 const T& iniValue, 00991 const eResizeType resizeType=CopyAndInit); 00992 00993 /** 00994 * Change the dimensions of the genericLattice2D. 00995 * 00996 * @param rows interval of valid rows 00997 * @param columns interval of valid columns 00998 * @param iniValue value to initialize the rest 00999 * @param resizeType specifies what should happen with the data of the 01000 * resized lattice2D. 01001 * 01002 * If the resize is possible (see useExternData()), this %object 01003 * will always own the data! 01004 * 01005 * This is equivalent to call 01006 * resize(newDim.y,newDim.x,iniValue,resizeType) 01007 * 01008 * @see eResizeType 01009 */ 01010 inline void resize(const iinterval& rows, 01011 const iinterval& columns, 01012 const T& iniValue, 01013 const eResizeType resizeType=CopyAndInit); 01014 01015 01016 01017 /** 01018 * Change the dimensions of the genericLattice2D, copying old data but 01019 * leaving all new elements uninitialized. 01020 * 01021 * @param fromRow initial row index 01022 * @param fromCol initial column index 01023 * @param toRow final row index (inclusive) 01024 * @param toCol final column index (inclusive) 01025 * 01026 * If the resize is possible (see useExternData()), this %object 01027 * will always owns the data! 01028 * 01029 * @see eResizeType, assign(),allocate() 01030 */ 01031 inline void resize(const int fromRow, 01032 const int fromCol, 01033 const int toRow, 01034 const int toCol); 01035 01036 /** 01037 * Change the dimensions of the genericLattice2D, copying old data but 01038 * leaving all new elements uninitialized. 01039 * 01040 * @param from initial index 01041 * @param to final index 01042 * 01043 * If the resize is possible (see useExternData()), this %object 01044 * will always own the data! 01045 * 01046 * This is equivalent to call 01047 * resize(newDim.y,newDim.x,iniValue,resizeType) 01048 * 01049 * @see eResizeType 01050 */ 01051 inline void resize(const size_type& from, 01052 const size_type& to); 01053 01054 /** 01055 * Change the dimensions of the genericLattice2D, copying old data but 01056 * leaving all new elements uninitialized. 01057 * 01058 * @param rows interval of valid rows 01059 * @param columns interval of valid columns 01060 * 01061 * If the resize is possible (see useExternData()), this %object 01062 * will always own the data! 01063 * 01064 * This is equivalent to call 01065 * resize(newDim.y,newDim.x,iniValue,resizeType) 01066 * 01067 * @see eResizeType 01068 */ 01069 inline void resize(const iinterval& rows, 01070 const iinterval& columns); 01071 01072 01073 01074 /** 01075 * Change the dimensions of the genericLattice2D and leave ALL data 01076 * uninitialized. 01077 * 01078 * @param fromRow initial row index 01079 * @param fromCol initial column index 01080 * @param toRow final row index (inclusive) 01081 * @param toCol final column index (inclusive) 01082 * 01083 * The old values will be discarded and the new data will be kept 01084 * uninitialized. In principle this is an alias for 01085 * \c resize(newRows,newCols,T(),AllocateOnly). 01086 * 01087 * If the resize is possible (see useExternData()), this %object 01088 * will always own the data! 01089 */ 01090 inline void allocate(const int fromRow, 01091 const int fromCol, 01092 const int toRow, 01093 const int toCol); 01094 01095 /** 01096 * Change the dimensions of the genericLattice2D and leave ALL data 01097 * uninitialized. 01098 * 01099 * @param from initial index 01100 * @param to final index 01101 * 01102 * The old values will be discarded and the new data will be kept 01103 * uninitialized. In principle this is an alias for 01104 * \c resize(newSize.y, newSize.x, T(), AllocateOnly). 01105 * 01106 * If the resize is possible (see useExternData()), this %object 01107 * will always own the data! 01108 */ 01109 inline void allocate(const size_type& from, 01110 const size_type& to); 01111 01112 /** 01113 * Change the dimensions of the genericLattice2D and leave ALL data 01114 * uninitialized. 01115 * 01116 * @param rows interval of valid rows 01117 * @param columns interval of valid columns 01118 * 01119 * The old values will be discarded and the new data will be kept 01120 * uninitialized. In principle this is an alias for 01121 * \c resize(newSize.y, newSize.x, T(), AllocateOnly). 01122 * 01123 * If the resize is possible (see useExternData()), this %object 01124 * will always own the data! 01125 */ 01126 inline void allocate(const iinterval& rows, 01127 const iinterval& columns); 01128 01129 /** 01130 * Change the dimensions of the genericLattice2D and initialize ALL data 01131 * with the given value. 01132 * 01133 * The old values will be discarded and all data will be initialized with 01134 * initValue. In principle this is an alias for \c 01135 * resize(newRows, newCols, initValue, Init). 01136 * 01137 * If the resize is possible (see useExternData()), this %object 01138 * will always own the data! 01139 * 01140 * @param fromRow initial row index 01141 * @param fromCol initial column index 01142 * @param toRow final row index (inclusive) 01143 * @param toCol final column index (inclusive) 01144 * @param initValue value to be assigned to all lattice2D elements 01145 */ 01146 inline void assign(const int fromRow, 01147 const int fromCol, 01148 const int toRow, 01149 const int toCol, 01150 const T& initValue); 01151 01152 /** 01153 * Change the dimensions of the genericLattice2D and initialize ALL data 01154 * with the given value. 01155 * 01156 * The old values will be discarded and all data will be initialized with 01157 * initValue. In principle this is an alias for \c 01158 * resize(newSize.y, newSize.x, initValue, Init). 01159 * 01160 * If the resize is possible (see useExternData()), this %object 01161 * will always own the data! 01162 * 01163 * @param from initial index 01164 * @param to final index 01165 * @param initValue value to be assigned to all lattice2D elements 01166 */ 01167 inline void assign(const size_type& from, 01168 const size_type& to, 01169 const T& initValue); 01170 01171 /** 01172 * Change the dimensions of the genericLattice2D and initialize ALL data 01173 * with the given value. 01174 * 01175 * The old values will be discarded and all data will be initialized with 01176 * initValue. In principle this is an alias for \c 01177 * resize(newSize.y, newSize.x, initValue, Init). 01178 * 01179 * If the resize is possible (see useExternData()), this %object 01180 * will always own the data! 01181 * 01182 * @param rows interval of valid rows 01183 * @param columns interval of valid columns 01184 * @param initValue value to be assigned to all lattice2D elements 01185 */ 01186 inline void assign(const iinterval& rows, 01187 const iinterval& columns, 01188 const T& initValue); 01189 01190 /** 01191 * Clears the genericLattice2D (at the end this will be an empty 01192 * genericLattice2D) 01193 */ 01194 void clear(); 01195 01196 /** 01197 * Returns true if the genericLattice2D is empty 01198 */ 01199 inline bool empty() const; 01200 01201 /** 01202 * Fills genericLattice2D elements with \a iniValue. 01203 * The fill "area" is limited by \a fromCol,\a toCol, 01204 * \a fromRow and \a toRow. 01205 * If these values are out of bounds, they will be (internally) 01206 * adjusted to correct values. 01207 * 01208 * @param iniValue the elements will be initialized with this value 01209 * @param fromRow first row of the sublattice2D to be filled 01210 * @param fromCol first column of the sublattice2D to be filled 01211 * @param toRow last row of the sublattice2D to be filled 01212 * @param toCol last column of the sublattice2D to be filled 01213 */ 01214 void fill(const T& iniValue, 01215 const int fromRow=MinIndex, 01216 const int fromCol=MinIndex, 01217 const int toRow=MaxIndex, 01218 const int toCol=MaxIndex); 01219 01220 /** 01221 * Fills genericLattice2D elements with \a iniValue. 01222 * The fill "area" is limited by \a from and \a to 01223 * points 01224 * If these values are out of bounds, they will be (internally) 01225 * adjusted to correct values. 01226 * 01227 * @param iniValue the elements will be initialized with this value 01228 * @param from first position of the sublattice2D to be filled 01229 * @param to last row of the sublattice2D to be filled 01230 */ 01231 inline void fill(const T& iniValue, 01232 const size_type& from, 01233 const size_type& to=size_type(MaxIndex,MaxIndex)); 01234 01235 /** 01236 * Fills genericLattice2D elements with \a iniValue. 01237 * The fill "area" is limited by \a window. 01238 * If these values are out of bounds, they will be (internally) 01239 * adjusted to correct values. 01240 * @param iniValue the elements will be initialized with this value 01241 * @param window the window to be filled 01242 */ 01243 inline void fill(const T& iniValue,const irectangle& window); 01244 01245 /** 01246 * Fills genericLattice2D elements with the data pointed by \a data. 01247 * The fill "area" is limited by \a fromCol,\a toCol, 01248 * \a fromRow and \a toRow. 01249 * If these values are out of bounds, they will be (internally) 01250 * adjusted to correct values. 01251 * 01252 * @param data pointer to the data to be copied. 01253 * @param fromRow first row of the sublattice2D to be filled 01254 * @param fromCol first column of the sublattice2D to be filled 01255 * @param toRow last row of the sublattice2D to be filled 01256 * @param toCol last column of the sublattice2D to be filled 01257 */ 01258 void fill(const T data[], 01259 const int fromRow=MinIndex, 01260 const int fromCol=MinIndex, 01261 const int toRow=MaxIndex, 01262 const int toCol=MaxIndex); 01263 01264 /** 01265 * Fills genericLattice2D elements with the data pointed by \a data. 01266 * The fill "area" is limited by \a fromCol,\a toCol, 01267 * \a fromRow and \a toRow. 01268 * If these values are out of bounds, they will be (internally) 01269 * adjusted to correct values. 01270 * 01271 * @param data pointer to the data to be copied. 01272 * @param from first position of the sublattice2D to be filled 01273 * @param to last position of the sublattice2D to be filled 01274 */ 01275 inline void fill(const T data[], 01276 const size_type& from, 01277 const size_type& to=size_type(MaxIndex,MaxIndex)); 01278 01279 /** 01280 * Fills genericLattice2D elements with \a iniValue. 01281 * 01282 * The fill "area" is limited by \a window. 01283 * 01284 * If these values are out of bounds, they will be (internally) adjusted to 01285 * correct values. 01286 * 01287 * @param data pointer to the data to be copied 01288 * @param window the window to be filled 01289 */ 01290 inline void fill(const T data[],const irectangle& window); 01291 01292 /** 01293 * Fills this genericLattice2D between the "from's" and "to's" with 01294 * the contents of the genericLattice2D \a mat starting at 01295 * \a startAtRow and \a startAtCol 01296 * 01297 * @param mat the genericLattice2D with the data to be copied 01298 * @param fromRow first row of the sublattice2D to be filled 01299 * @param fromCol first column of the sublattice2D to be filled 01300 * @param toRow last row of the sublattice2D to be filled 01301 * @param toCol last column of the sublattice2D to be filled 01302 * @param startAtRow starting row of \a mat where the data is 01303 * located. 01304 * @param startAtCol starting column of \a mat where the data 01305 * is located. 01306 */ 01307 void fill(const genericLattice2D<T>& mat, 01308 const int fromRow=MinIndex, 01309 const int fromCol=MinIndex, 01310 const int toRow=MaxIndex, 01311 const int toCol=MaxIndex, 01312 const int startAtRow=MinIndex, 01313 const int startAtCol=MinIndex); 01314 01315 /** 01316 * Fills this genericLattice2D between the "from's" and "to's" with 01317 * the contents of the genericLattice2D \a mat starting at 01318 * \a startAtRow and \a startAtCol 01319 * 01320 * @param mat the genericLattice2D with the data to be copied 01321 * @param from first position of the sublattice2D to be filled 01322 * @param to last position of the sublattice2D to be filled 01323 * @param startAt starting position of \a mat where the data is 01324 * located. 01325 */ 01326 inline void fill(const genericLattice2D<T>& mat, 01327 const size_type& from, 01328 const size_type& to=size_type(MaxIndex,MaxIndex), 01329 const size_type& startAt=size_type(MinIndex,MinIndex)); 01330 01331 /** 01332 * Fills the region of this genericLattice2D specified by \a window with the 01333 * contents of the genericLattice2D \a mat starting at \a start. If these 01334 * values are out of bounds, they will be (internally) adjusted to correct 01335 * values. 01336 * 01337 * @param mat pointer to the data to be copied 01338 * @param window the window to be filled 01339 * @param start the start position of the region to be copied of the 01340 * genericLattice2D \a mat 01341 */ 01342 inline void fill(const genericLattice2D<T>& mat, 01343 const irectangle& window, 01344 const size_type& start=size_type(MinIndex,MinIndex)); 01345 01346 /** 01347 * Access element at the given row and column 01348 * 01349 * @param row the row of the element 01350 * @param col the column of the element 01351 * @return a reference to the genericLattice2D element 01352 */ 01353 inline T& at(const int row, const int col); 01354 01355 /** 01356 * Read-only access at the given row and column 01357 * 01358 * @param row the row of the element 01359 * @param col the column of the element 01360 * @return a reference to the genericLattice2D element 01361 */ 01362 inline const T& at(const int row, const int col) const; 01363 01364 /** 01365 * Access operator of genericLattice2D element as a point in a 2D-Map 01366 * 01367 * @param p position of the element (this is equivalent to at(p.y,p.x)) 01368 * @return a reference to the genericLattice2D element 01369 */ 01370 inline T& at(const size_type& p); 01371 01372 /** 01373 * Const access operator of genericLattice2D element as a point in a 2D-Map 01374 * 01375 * @param p position of the element (this is equivalent to at(p.y,p.x)) 01376 * @return a const reference to the vector element 01377 */ 01378 inline const T& at(const size_type& p) const; 01379 01380 /** 01381 * Access element at the given position. 01382 * 01383 * With this operator the genericLattice2D can be accessed as a 01384 * vector, where the rows of the genericLattice2D are concatenated. 01385 * The access to the genericLattice2D with at(row,col) is equivalent 01386 * to elem(row*columns()+col), but more efficient. 01387 * 01388 * @param pos the index of the element of the genericLattice2D 01389 * 01390 * @return a reference to the genericLattice2D element 01391 */ 01392 inline T& elem(const int pos); 01393 01394 /** 01395 * Access element at the given position. 01396 * 01397 * With this operator the genericLattice2D can be accessed as a 01398 * vector, where the rows of the genericLattice2D are concatenated. 01399 * The access to the genericLattice2D with at(row,col) is equivalent 01400 * to elem(row*columns()+col), but more efficient. 01401 * 01402 * @param pos the index of the element of the genericLattice2D 01403 * 01404 * @return a reference to the genericLattice2D element 01405 */ 01406 inline const T& elem(const int pos) const; 01407 01408 /** 01409 * Return genericLattice2D-row as a vector. 01410 * 01411 * This method works fast, since it returns a reference to the row vector. 01412 * The data will NOT be copied. 01413 * 01414 * @param row the row to be accessed 01415 * @return a reference to the vector row 01416 */ 01417 inline row_type& getRow(const int row); 01418 01419 /** 01420 * Return genericLattice2D-row as a const vector. 01421 * This method works fast, since it returns a reference to the row vector. 01422 * The data will NOT be copied. 01423 * 01424 * @param row the row to be accessed 01425 * @return a const reference to the vector row 01426 */ 01427 inline const row_type& getRow(const int row) const; 01428 01429 /** 01430 * Alias for getRow() 01431 */ 01432 inline row_type& operator[](const int row); 01433 01434 /** 01435 * Alias for getRow() 01436 */ 01437 inline const row_type& operator[](const int row) const; 01438 01439 /** 01440 * Copy a row vector in the given parameter. 01441 * 01442 * This method copies the data of a given row of the genericLattice2D 01443 * in the given vector. 01444 * 01445 * @param row the number of the row to be copied 01446 * @param theRow the vector, where the data will be copied 01447 * @see getRow() 01448 */ 01449 inline void getRowCopy(const int row,row_type& theRow) const; 01450 01451 /** 01452 * Return genericLattice2D-row as a vector. 01453 * 01454 * This method copies the data of the genericLattice2D, therefore is not as 01455 * fast as getRow(). 01456 * 01457 * @param row the number of the row to be copied 01458 * @return a vector with the contents of the row of the genericLattice2D 01459 */ 01460 inline row_type getRowCopy(const int row) const; 01461 01462 /** 01463 * Return genericLattice2D-column as a vector. 01464 * 01465 * This method copies the data of the genericLattice2D, therefore is not as 01466 * fast as getRow(). 01467 * 01468 * @param col the number of the column to be copied 01469 * @param theCol a vector, where the column vector of the genericLattice2D 01470 * should be copied. 01471 */ 01472 void getColumnCopy(const int col,row_type& theCol) const; 01473 01474 /** 01475 * Return genericLattice2D-column as a vector. 01476 * 01477 * This method copies the data of the genericLattice2D, therefore is not as 01478 * fast as getRow() 01479 * @param col the number of the column to be copied 01480 * @return a vector with the contents of the column of the genericLattice2D 01481 */ 01482 inline row_type getColumnCopy(const int col) const; 01483 01484 /** 01485 * Copy the data of a vector in a given row. 01486 * 01487 * @param row the row that receives the data. 01488 * @param theRow the vector with the data to be copied 01489 */ 01490 inline void setRow(const int row,const row_type& theRow); 01491 01492 /** 01493 * Copy the data of a vector in a given column 01494 * @param col the column that receives the data. 01495 * @param theCol the vector with the data to be copied 01496 */ 01497 void setColumn(const int col,const row_type& theCol); 01498 01499 /** 01500 * Assigment operator. 01501 * 01502 * Copy the contents of \a other in this object. 01503 * 01504 * @param other the other genericLattice2D to be copied 01505 */ 01506 genericLattice2D<T>& copy(const genericLattice2D<T>& other); 01507 01508 /** 01509 * Assigment operator. 01510 * 01511 * Copy the contents of a sublattice2D of \a other into this object. The 01512 * content of the current object is removed and at the end it will contain 01513 * a copy the sublattice2D only. 01514 * 01515 * @param other the other genericLattice2D to be copied 01516 * @param fromRow initial row of the other genericLattice2D to be copied 01517 * @param fromCol initial column of the other genericLattice2D to be copied 01518 * @param toRow last row to be copied of the other genericLattice2D 01519 * @param toCol last column to be copied of the other genericLattice2D 01520 */ 01521 genericLattice2D<T>& copy(const genericLattice2D<T>& other, 01522 const int fromRow, 01523 const int fromCol, 01524 const int toRow=MaxIndex, 01525 const int toCol=MaxIndex); 01526 01527 01528 /** 01529 * Assigment operator. 01530 * 01531 * Copy the contents of a sublattice2D of \a other into this object. The 01532 * content of the current object is removed and at the end it will contain 01533 * only the sublattice2D. 01534 * 01535 * @param other the other genericLattice2D to be copied 01536 * @param from initial sublattice2D indices (x,y) to be copied 01537 * @param to last sublattice2D indices (x,y) to be copied (inclusive) 01538 */ 01539 inline genericLattice2D<T>& copy(const genericLattice2D<T>& other, 01540 const size_type& from, 01541 const size_type& to); 01542 01543 /** 01544 * Assigment operator. 01545 * 01546 * copy the contents of \a other in this object. 01547 * 01548 * The result of the copy is always a connected lattice2D. I.e. you cannot 01549 * copy the sub-lattice2D property of another lattice2D. 01550 * 01551 * @param other the other lattice2D to be copied 01552 * @param r interval used for the rows 01553 * @param c interval used for the columns 01554 */ 01555 inline genericLattice2D<T>& copy(const genericLattice2D<T>& other, 01556 const iinterval& r, 01557 const iinterval& c); 01558 01559 /** 01560 * Assigment operator. 01561 * 01562 * Copy the contents of a sublattice2D of \a other into this object. The 01563 * content of the current object is removed and at the end it will contain 01564 * only the copy of the sublattice2D. 01565 * 01566 * @param other the other genericLattice2D to be copied 01567 * @param window rectangle define the copy area 01568 */ 01569 inline genericLattice2D<T>& copy(const genericLattice2D<T>& other, 01570 const irectangle& window); 01571 01572 /** 01573 * Assigment operator. 01574 * 01575 * Copy the contents of the specified rows of \a other into this 01576 * object. Multiple occurence of one row index in \a idx is allowed. 01577 * 01578 * @param other the other genericLattice2D to be copied 01579 * @param idx indices of the rows to be copied. 01580 */ 01581 genericLattice2D<T>& copyRows(const genericLattice2D<T>& other, 01582 const genericLattice1D<int>& idx); 01583 01584 /** 01585 * Assigment operator. 01586 * 01587 * Copy the contents of the specified columns of \a other into this 01588 * object. Multiple occurence of one column index in \a idx is allowed. 01589 * 01590 * @param other the other genericLattice2D to be copied 01591 * @param idx indices of the rows to be copied. 01592 */ 01593 genericLattice2D<T>& copyColumns(const genericLattice2D<T>& other, 01594 const genericLattice1D<int>& idx); 01595 01596 /** 01597 * Copy the \a other genericLattice2D by casting each of 01598 * its elements 01599 * 01600 * @param other The genericLattice2D to be casted 01601 */ 01602 template<typename U> 01603 genericLattice2D<T>& castFrom(const genericLattice2D<U>& other); 01604 01605 /** 01606 * This is just an alias for copy(const genericLattice2D<T>&) to facilitate 01607 * generic programming. 01608 * 01609 * @param other The genericLattice2D to be copied. 01610 */ 01611 genericLattice2D<T>& castFrom(const genericLattice2D<T>& other); 01612 01613 /** 01614 * Copy a sublattice2D of the \a other genericLattice2D by casting each of 01615 * its elements. 01616 * 01617 * @param other The genericLattice2D to be casted 01618 * @param fromRow initial row of the other genericLattice2D to be copied 01619 * @param fromCol initial column of the other genericLattice2D to be copied 01620 * @param toRow last row to be copied of the other genericLattice2D 01621 * @param toCol last column to be copied of the other genericLattice2D 01622 * 01623 * @return a reference to the current casted lattice2D. 01624 */ 01625 template<typename U> 01626 genericLattice2D<T>& castFrom(const genericLattice2D<U>& other, 01627 const int fromRow, 01628 const int fromCol, 01629 const int toRow=MaxIndex, 01630 const int toCol=MaxIndex); 01631 01632 /** 01633 * This is just an alias for copy(const genericLattice2D<T>&, const int 01634 * fromRow, const int fromCol, const int toRow, const int toCol) to 01635 * facilitate generic programming. 01636 * 01637 * @param other The genericLattice2D to be copied. 01638 * @param fromRow initial row of the other genericLattice2D to be copied 01639 * @param fromCol initial column of the other genericLattice2D to be copied 01640 * @param toRow last row to be copied of the other genericLattice2D 01641 * @param toCol last column to be copied of the other genericLattice2D 01642 * 01643 * @return a reference to the current casted lattice2D. 01644 */ 01645 genericLattice2D<T>& castFrom(const genericLattice2D<T>& other, 01646 const int fromRow, 01647 const int fromCol, 01648 const int toRow=MaxIndex, 01649 const int toCol=MaxIndex); 01650 01651 /** 01652 * Returns the name of this type. 01653 */ 01654 virtual const std::string& name() const; 01655 01656 /** 01657 * Create a clone of this genericLattice2D 01658 * @return a pointer to a copy of this genericLattice2D 01659 */ 01660 virtual genericLattice2D<T>* clone() const; 01661 01662 /** 01663 * Create a new instance of genericLattice2D 01664 * @return a pointer to a new instance of genericLattice2D 01665 */ 01666 virtual genericLattice2D<T>* newInstance() const; 01667 01668 /** 01669 * Compare this genericLattice2D with other. 01670 * 01671 * @param other the other genericLattice2D to be compared with 01672 * @return true if both matrices have the same elements and same size 01673 */ 01674 bool equals(const genericLattice2D<T>& other) const; 01675 01676 /** 01677 * Compare the contents of each element of this genericLattice2D with the 01678 * other one. It assumes the type T can be compared using the 01679 * operator==. 01680 * 01681 * @param other the other genericLattice2D to be compared with 01682 * @return true if both matrices have the same elements and same size 01683 */ 01684 inline bool operator==(const genericLattice2D<T>& other) const; 01685 01686 /** 01687 * Assigment operator (alias for copy(other)). 01688 * 01689 * @param other the genericLattice2D to be copied 01690 * @return a reference to the actual genericLattice2D 01691 */ 01692 inline genericLattice2D<T>& operator=(const genericLattice2D<T>& other); 01693 01694 /** 01695 * \name Apply Methods 01696 * 01697 * Following methods are used to apply simple functions to each element 01698 * of the vector. 01699 */ 01700 //@{ 01701 01702 /** 01703 * Applies a C-function to each element of the genericLattice2D. 01704 * @param function a pointer to a C-function 01705 * @return a reference to the actual genericLattice2D 01706 */ 01707 genericLattice2D<T>& apply(T (*function)(T)); 01708 01709 /** 01710 * Applies a C-function to each element of the other genericLattice2D 01711 * @param other the genericLattice2D which elements will go through the 01712 * given function. 01713 * @param function a pointer to a C-function 01714 * @return a reference to the actual genericLattice2D 01715 */ 01716 genericLattice2D<T>& apply(const genericLattice2D<T>& other, 01717 T (*function)(T)); 01718 01719 /** 01720 * Applies a C-function to each element of the genericLattice2D. 01721 * @param function a pointer to a C-function 01722 * @return a reference to the actual genericLattice2D 01723 */ 01724 genericLattice2D<T>& apply(T (*function)(const T&)); 01725 01726 /** 01727 * Applies a C-function to each element of the other genericLattice2D 01728 * @param other the genericLattice2D which elements will go through the 01729 * given function. 01730 * @param function a pointer to a C-function 01731 * @return a reference to the actual genericLattice2D 01732 */ 01733 genericLattice2D<T>& apply(const genericLattice2D<T>& other, 01734 T (*function)(const T&)); 01735 01736 /** 01737 * A two-parameter C-function receives the i-th elements of this 01738 * and the given genericLattice2D and the result will be left in this 01739 * genericLattice2D. Note that both matrices must have the same size! 01740 * @param other the second genericLattice2D to be considered (the first 01741 * genericLattice2D will be this object!) 01742 * @param function a pointer to C-function with two parameters 01743 * @return a reference to the actual genericLattice2D 01744 */ 01745 genericLattice2D<T>& apply(const genericLattice2D<T>& other, 01746 T (*function)(const T&,const T&)); 01747 01748 /** 01749 * A two-parameter C-function receives the i-th elements of this 01750 * and the given genericLattice2D and the result will be left in this 01751 * genericLattice2D. Note that both matrices must have the same size! 01752 * @param other the second genericLattice2D to be considered (the first 01753 * genericLattice2D will be this object!) 01754 * @param function a pointer to C-function with two parameters 01755 * @return a reference to the actual genericLattice2D 01756 */ 01757 genericLattice2D<T>& apply(const genericLattice2D<T>& other, 01758 T (*function)(T,T)); 01759 01760 /** 01761 * A two-parameter C-function receives the i-th elements of both given 01762 * matrices and leaves the result here. 01763 * Note that both matrices must have the same size! 01764 * @param a the first genericLattice2D 01765 * @param b the second genericLattice2D 01766 * @param function a pointer to C-function with two parameters 01767 * @return a reference to the actual genericLattice2D 01768 */ 01769 genericLattice2D<T>& apply(const genericLattice2D<T>& a, 01770 const genericLattice2D<T>& b, 01771 T (*function)(const T&,const T&)); 01772 01773 /** 01774 * A two-parameter C-function receives the i-th elements of both given 01775 * matrices and leaves the result here. 01776 * Note that both matrices must have the same size! 01777 * @param a the first genericLattice2D 01778 * @param b the second genericLattice2D 01779 * @param function a pointer to C-function with two parameters 01780 * @return a reference to the actual genericLattice2D 01781 */ 01782 genericLattice2D<T>& apply(const genericLattice2D<T>& a, 01783 const genericLattice2D<T>& b, 01784 T (*function)(T,T)); 01785 01786 //@} 01787 01788 /** 01789 * @name Input and Output 01790 */ 01791 //@{ 01792 01793 /** 01794 * Write the object in the given ioHandler 01795 */ 01796 virtual bool write(ioHandler& handler,const bool complete = true) const; 01797 01798 /** 01799 * Read the object from the given ioHandler 01800 */ 01801 virtual bool read(ioHandler& handler,const bool complete = true); 01802 //@} 01803 01804 protected: 01805 01806 /** 01807 * @name Memory allocation and deallocation 01808 * 01809 * Restrict all memory allocation and deallocation to these functions. 01810 */ 01811 //@{ 01812 /** 01813 * Allocate \a n number of rows or the appropriate type. 01814 * 01815 * Never remove the returned pointer directly, since it is moved with 01816 * an offset of fromRow. 01817 * 01818 * You need to add to the pointer "fromRow" before deleting it. 01819 * 01820 * If the given interval is invalid (fromRow > toRow) then a null 01821 * pointer will be returned. 01822 */ 01823 inline virtual row_type* allocNewRows(const int fromRow, 01824 const int toRow); 01825 01826 /** 01827 * Reserve just a memory block of the given size; 01828 */ 01829 inline T* reserveNewMem(const int theSize) const; 01830 01831 /** 01832 * Reserve memory. 01833 * 01834 * This method allocates memory for the elements, for the rows and 01835 * distributes the memory into the blocks 01836 */ 01837 void reserveMem(const int fromRow, 01838 const int fromColumn, 01839 const int toRow, 01840 const int toColumn); 01841 01842 /** 01843 * Release the given block of memory. 01844 * 01845 * The block is directly released (not previously modified with the 01846 * offset). 01847 */ 01848 void releaseMem(T*& block) const; 01849 01850 /** 01851 * Release the internal memory blocks, including 01852 * theElements_ and the row array. 01853 */ 01854 void releaseMem(); 01855 01856 /** 01857 * Allocate \a n number of rows or the appropriate type. 01858 */ 01859 inline void releaseRows(row_type*& theRows, 01860 const int offset) const; 01861 01862 /** 01863 * Take the memory block and distribute it on the 01864 * allocated vectors pointed by theRows. 01865 */ 01866 void distributeMem(const int firstRow,const int firstColumn, 01867 const int lastRow,const int lastColumn, 01868 T* block, 01869 row_type* theRows) const; 01870 //@} 01871 01872 /** 01873 * Size of the lattice2D as point 01874 */ 01875 size_type theSize_; 01876 01877 /** 01878 * Index of the last row, i.e. last_.x=theSize.x-1, and last_.y=theSize.y-1 01879 */ 01880 size_type first_; 01881 01882 /** 01883 * Index of the last row, i.e. last_.x=theSize.x-1, and last_.y=theSize.y-1 01884 */ 01885 size_type last_; 01886 01887 /** 01888 * Size of theElements_ memory block, i.e. theSize_.x*theSize_.y; 01889 */ 01890 int totalSize_; 01891 01892 /** 01893 * Indicates if \a theElements points to own data or to 01894 * external data. 01895 */ 01896 bool ownData_; 01897 01898 /** 01899 * If constReference=true, is not possible to resize or change 01900 * the reference of this genericVector. 01901 * 01902 * Very important for an efficient lattice2D class!! 01903 * (see useExternData()) 01904 */ 01905 eConstantReference constReference_; 01906 01907 /** 01908 * Pointer to the elements of the genericLattice2D 01909 */ 01910 T* theElements_; 01911 01912 /** 01913 * Table of pointers to the rows 01914 */ 01915 row_type* rowAddressTable_; 01916 }; 01917 } 01918 01919 namespace std { 01920 /* 01921 * Outputs the elements of the vector on a stream 01922 */ 01923 template <class T> 01924 ostream& operator<<(ostream& s,const cvr::genericLattice2D<T>& amat); 01925 } 01926 01927 #include "cvrGenericLattice2D_inline.h" 01928 #include "cvrGenericLattice2D_template.h" 01929 01930 #else 01931 #include "cvrGenericLattice2D_template.h" 01932 #endif