[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
vigra/meshgrid.hxx | ![]() |
00001 /************************************************************************/ 00002 /* */ 00003 /* Copyright 2009 by Ullrich Koethe */ 00004 /* */ 00005 /* This file is part of the VIGRA computer vision library. */ 00006 /* The VIGRA Website is */ 00007 /* http://hci.iwr.uni-heidelberg.de/vigra/ */ 00008 /* Please direct questions, bug reports, and contributions to */ 00009 /* ullrich.koethe@iwr.uni-heidelberg.de or */ 00010 /* vigra@informatik.uni-hamburg.de */ 00011 /* */ 00012 /* Permission is hereby granted, free of charge, to any person */ 00013 /* obtaining a copy of this software and associated documentation */ 00014 /* files (the "Software"), to deal in the Software without */ 00015 /* restriction, including without limitation the rights to use, */ 00016 /* copy, modify, merge, publish, distribute, sublicense, and/or */ 00017 /* sell copies of the Software, and to permit persons to whom the */ 00018 /* Software is furnished to do so, subject to the following */ 00019 /* conditions: */ 00020 /* */ 00021 /* The above copyright notice and this permission notice shall be */ 00022 /* included in all copies or substantial portions of the */ 00023 /* Software. */ 00024 /* */ 00025 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */ 00026 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */ 00027 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */ 00028 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */ 00029 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */ 00030 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */ 00031 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */ 00032 /* OTHER DEALINGS IN THE SOFTWARE. */ 00033 /* */ 00034 /************************************************************************/ 00035 00036 #ifndef VIGRA_MESHGRID_HXX 00037 #define VIGRA_MESHGRID_HXX 00038 00039 #include "tinyvector.hxx" 00040 #include "diff2d.hxx" 00041 00042 namespace vigra{ 00043 /** \addtogroup RangesAndPoints */ 00044 //@{ 00045 00046 /********************************************************/ 00047 /* */ 00048 /* MeshGridAccessor */ 00049 /* */ 00050 /********************************************************/ 00051 /** Accessor for turning iteration over Diff2D into a mesh grid. 00052 00053 The mesh grid concept is adapted from MATLAB. It is a two banded image 00054 (i.e. with 2D vector pixel type) whose first band contains the x-coordinates 00055 of the current pixel, and whose second band contains the y-coordinates. 00056 See \ref meshGrid() for more detailed documentation. 00057 */ 00058 struct MeshGridAccessor 00059 { 00060 /** the value_type of a mesh grid is a 2D vector 00061 */ 00062 typedef TinyVector<Diff2D::MoveX, 2> value_type; 00063 00064 /** read the current data item 00065 */ 00066 template <class ITERATOR> 00067 value_type operator()(ITERATOR const & i) const 00068 { 00069 return value_type(i->x, i->y); 00070 } 00071 00072 /** read the data item at an offset (can be 1D or 2D or higher order difference). 00073 */ 00074 template <class ITERATOR, class DIFFERENCE> 00075 value_type operator()(ITERATOR const & i, DIFFERENCE const & diff) const 00076 { 00077 return value_type(i->x+diff.x, i->y+diff.y); 00078 } 00079 }; 00080 00081 /** Create a mesh grid for the specified rectangle. 00082 00083 The mesh grid concept is adapted from MATLAB. It is a two banded image 00084 (i.e. with 2D vector pixel type) whose first band contains the x-coordinates 00085 of the current pixel, and whose second band contains the y-coordinates. 00086 If \a upperLeft is not the point (0,0), the mesh grid is translated relative to 00087 the pixel indices. 00088 00089 <b> Declarations:</b> 00090 00091 \code 00092 triple<Diff2D, Diff2D, MeshGridAccessor> 00093 meshGrid(Diff2D upperLeft, Diff2D lowerRight); 00094 00095 triple<Diff2D, Diff2D, MeshGridAccessor> 00096 meshGrid(Rect2D const & r); 00097 00098 \endcode 00099 00100 <b>Usage:</b> 00101 00102 \code 00103 #include <vigra/meshgrid.hxx> 00104 // create an image whose values are equal to each pixel's distance from the image center 00105 int width = 5, height = 7; 00106 int xc = width/2, yc = height/2; // the image center 00107 00108 FImage dist(width, height); 00109 Point2D upperLeft(-xc, -yc); 00110 00111 using namespace vigra::functor; 00112 transformImage(meshGrid(upperLeft, upperLeft+dist.size()), 00113 destImage(dist), 00114 norm(Arg1())); 00115 \endcode 00116 */ 00117 inline 00118 triple<Diff2D, Diff2D, MeshGridAccessor> 00119 meshGrid(Diff2D upperLeft, Diff2D lowerRight) 00120 { 00121 return triple<Diff2D, Diff2D, MeshGridAccessor>(upperLeft, lowerRight, MeshGridAccessor()); 00122 } 00123 00124 inline 00125 triple<Diff2D, Diff2D, MeshGridAccessor> 00126 meshGrid(Rect2D const & r) 00127 { 00128 return triple<Diff2D, Diff2D, MeshGridAccessor>(r.upperLeft(), r.lowerRight(), MeshGridAccessor()); 00129 } 00130 00131 }//namespace vigra 00132 //@} 00133 #endif //VIGRA_MESHGRID_HXX
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|