[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]
![]() |
vigra/affinegeometry.hxx | ![]() |
---|
00001 /************************************************************************/ 00002 /* */ 00003 /* Copyright 2005-2006 by Ullrich Koethe */ 00004 /* Cognitive Systems Group, University of Hamburg, Germany */ 00005 /* */ 00006 /* This file is part of the VIGRA computer vision library. */ 00007 /* ( Version 1.5.0, Dec 07 2006 ) */ 00008 /* The VIGRA Website is */ 00009 /* http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/ */ 00010 /* Please direct questions, bug reports, and contributions to */ 00011 /* koethe@informatik.uni-hamburg.de or */ 00012 /* vigra@kogs1.informatik.uni-hamburg.de */ 00013 /* */ 00014 /* Permission is hereby granted, free of charge, to any person */ 00015 /* obtaining a copy of this software and associated documentation */ 00016 /* files (the "Software"), to deal in the Software without */ 00017 /* restriction, including without limitation the rights to use, */ 00018 /* copy, modify, merge, publish, distribute, sublicense, and/or */ 00019 /* sell copies of the Software, and to permit persons to whom the */ 00020 /* Software is furnished to do so, subject to the following */ 00021 /* conditions: */ 00022 /* */ 00023 /* The above copyright notice and this permission notice shall be */ 00024 /* included in all copies or substantial portions of the */ 00025 /* Software. */ 00026 /* */ 00027 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */ 00028 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */ 00029 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */ 00030 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */ 00031 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */ 00032 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */ 00033 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */ 00034 /* OTHER DEALINGS IN THE SOFTWARE. */ 00035 /* */ 00036 /************************************************************************/ 00037 00038 #ifndef VIGRA_AFFINEGEOMETRY_HXX 00039 #define VIGRA_AFFINEGEOMETRY_HXX 00040 00041 #include "mathutil.hxx" 00042 #include "splineimageview.hxx" 00043 #include <cmath> 00044 00045 namespace vigra { 00046 00047 /** \addtogroup GeometricTransformations Geometric Transformations 00048 */ 00049 //@{ 00050 00051 /********************************************************/ 00052 /* */ 00053 /* rotateImage */ 00054 /* */ 00055 /********************************************************/ 00056 00057 /** \brief Rotate image by an arbitrary angle. 00058 00059 The algorithm performs a rotation about the given center point (the image center by default) 00060 using the given SplineImageView for interpolation. The destination imae must have the same size 00061 as the source SplineImageView. The rotation is counter-clockwise, and the angle must be given in degrees. 00062 00063 <b> Declarations:</b> 00064 00065 pass arguments explicitly: 00066 \code 00067 namespace vigra { 00068 // rotate about given center point 00069 template <int ORDER, class T, 00070 class DestIterator, class DestAccessor> 00071 void rotateImage(SplineImageView<ORDER, T> const & src, 00072 DestIterator id, DestAccessor dest, 00073 double angleInDegree, TinyVector<double, 2> const & center); 00074 00075 // rotate about image center 00076 template <int ORDER, class T, 00077 class DestIterator, class DestAccessor> 00078 void 00079 rotateImage(SplineImageView<ORDER, T> const & src, 00080 DestIterator id, DestAccessor dest, 00081 double angleInDegree) 00082 } 00083 \endcode 00084 00085 use argument objects in conjunction with \ref ArgumentObjectFactories: 00086 \code 00087 namespace vigra { 00088 // rotate about given center point 00089 template <int ORDER, class T, 00090 class DestIterator, class DestAccessor> 00091 void 00092 rotateImage(SplineImageView<ORDER, T> const & src, 00093 pair<DestImageIterator, DestAccessor> dest, 00094 double angleInDegree, TinyVector<double, 2> const & center); 00095 00096 // rotate about image center 00097 template <int ORDER, class T, 00098 class DestIterator, class DestAccessor> 00099 void 00100 rotateImage(SplineImageView<ORDER, T> const & src, 00101 pair<DestImageIterator, DestAccessor> dest, 00102 double angleInDegree); 00103 } 00104 \endcode 00105 00106 <b> Usage:</b> 00107 00108 <b>\#include</b> "<a href="affinegeometry_8hxx-source.html">vigra/affinegeometry.hxx</a>"<br> 00109 Namespace: vigra 00110 00111 \code 00112 00113 Image src(width, height); 00114 vigra::SplineImageView<3, Image::value_type> spline(srcImageRange(src)); 00115 00116 Image dest(width, height); 00117 00118 vigra::rotateImage(spline, destImage(dest), 38.5); 00119 00120 \endcode 00121 00122 <b> Required Interface:</b> 00123 00124 \code 00125 DestImageIterator dest_upperleft; 00126 00127 double x = ..., y = ...; 00128 00129 if (spline.isInside(x,y)) 00130 dest_accessor.set(spline(x, y), dest_upperleft); 00131 00132 \endcode 00133 */ 00134 template <int ORDER, class T, 00135 class DestIterator, class DestAccessor> 00136 void rotateImage(SplineImageView<ORDER, T> const & src, 00137 DestIterator id, DestAccessor dest, 00138 double angleInDegree, TinyVector<double, 2> const & center) 00139 { 00140 int w = src.width(); 00141 int h = src.height(); 00142 00143 double angle = angleInDegree*M_PI/180.0; 00144 double c = std::cos(angle); 00145 double s = std::sin(angle); 00146 00147 for(int y = 0; y < h; ++y, ++id.y) 00148 { 00149 typename DestIterator::row_iterator rd = id.rowIterator(); 00150 double sy = (y - center[1])*c - center[0]*s + center[1]; 00151 double sx = -(y - center[1])*s - center[0]*c + center[0]; 00152 for(int x=0; x < w; ++x, ++rd, sx += c, sy += s) 00153 { 00154 if(src.isInside(sx, sy)) 00155 dest.set(src(sx, sy), rd); 00156 } 00157 } 00158 } 00159 00160 template <int ORDER, class T, 00161 class DestIterator, class DestAccessor> 00162 inline void 00163 rotateImage(SplineImageView<ORDER, T> const & src, 00164 pair<DestIterator, DestAccessor> dest, 00165 double angleInDegree, TinyVector<double, 2> const & center) 00166 { 00167 rotateImage(src, dest.first, dest.second, angleInDegree, center); 00168 } 00169 00170 template <int ORDER, class T, 00171 class DestIterator, class DestAccessor> 00172 inline void 00173 rotateImage(SplineImageView<ORDER, T> const & src, 00174 DestIterator id, DestAccessor dest, 00175 double angleInDegree) 00176 { 00177 TinyVector<double, 2> center((src.width()-1.0) / 2.0, (src.height()-1.0) / 2.0); 00178 rotateImage(src, id, dest, angleInDegree, center); 00179 } 00180 00181 template <int ORDER, class T, 00182 class DestIterator, class DestAccessor> 00183 inline void 00184 rotateImage(SplineImageView<ORDER, T> const & src, 00185 pair<DestIterator, DestAccessor> dest, 00186 double angleInDegree) 00187 { 00188 TinyVector<double, 2> center((src.width()-1.0) / 2.0, (src.height()-1.0) / 2.0); 00189 rotateImage(src, dest.first, dest.second, angleInDegree, center); 00190 } 00191 00192 //@} 00193 00194 } // namespace vigra 00195 00196 00197 #endif /* VIGRA_AFFINEGEOMETRY_HXX */
© Ullrich Köthe (koethe@informatik.uni-hamburg.de) |
html generated using doxygen and Python
|