Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TextureMapping.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include <Base/Common/BIASpragmaStart.hh>
26 
27 #ifndef __TextureMapping_hh__
28 #define __TextureMapping_hh__
29 
30 #include <Image/BackwardMapping.hh>
31 #include <Image/TextureTransform.hh>
32 
33 namespace BIAS {
34 
35  /** @class TextureMapping
36  @ingroup g_filter
37  @brief Maps source pixel to sink pixel given any TextureTransform
38 
39  @author koeser
40  @date 2008
41  */
42  template <class InputStorageType, class OutputStorageType>
43  class BIASImage_EXPORT TextureMapping
44  : public BackwardMapping<InputStorageType, OutputStorageType> {
45 
46  public:
47 
48  virtual ~TextureMapping();
49 
51 
52  /** required because assignment is
53  @author Jan Woetzel */
54  TextureMapping(const TextureMapping & src);
55 
56  /** required because of const members
57  @author Jan Woetzel */
59  operator=(const TextureMapping & src);
60 
61  /** @brief create clone of your texture tranform and set for mapping */
62  inline void SetTextureTransform(const TextureTransform& T) {
63  if (T_!=NULL) delete T_;
64  T_ = T.Clone();
65  }
66 
67 
68  virtual int GetBoundingBox(unsigned int srcwidth,
69  unsigned int srcheight,
70  unsigned int sinkwidth,
71  unsigned int sinkheight,
72  int &tlx, int &tly,
73  int &brx, int &bry)
74  {
75  tlx=0; tly=0;
76  brx=sinkwidth; bry=sinkheight;
77 
78  HomgPoint2D sink;
79  T_->MapForward(HomgPoint2D(0,0), sink);
80  if (tlx>sink[0]) tlx = int(rint(sink[0]-1.0));
81  if (tly>sink[1]) tly = int(rint(sink[1]-1.0));
82  if (brx<sink[0]) brx = int(rint(sink[0]+1.0));
83  if (bry<sink[1]) bry = int(rint(sink[1]+1.0));
84  T_->MapForward(HomgPoint2D(srcwidth-1,0), sink);
85  if (tlx>sink[0]) tlx = int(rint(sink[0]-1.0));
86  if (tly>sink[1]) tly = int(rint(sink[1]-1.0));
87  if (brx<sink[0]) brx = int(rint(sink[0]+1.0));
88  if (bry<sink[1]) bry = int(rint(sink[1]+1.0));
89  T_->MapForward(HomgPoint2D(0,srcheight-1), sink);
90  if (tlx>sink[0]) tlx = int(rint(sink[0]-1.0));
91  if (tly>sink[1]) tly = int(rint(sink[1]-1.0));
92  if (brx<sink[0]) brx = int(rint(sink[0]+1.0));
93  if (bry<sink[1]) bry = int(rint(sink[1]+1.0));
94  T_->MapForward(HomgPoint2D(srcwidth-1, srcheight-1), sink);
95  if (tlx>sink[0]) tlx = int(rint(sink[0]-1.0));
96  if (tly>sink[1]) tly = int(rint(sink[1]-1.0));
97  if (brx<sink[0]) brx = int(rint(sink[0]+1.0));
98  if (bry<sink[1]) bry = int(rint(sink[1]+1.0));
99 
100  return 0;
101  }
102 
103  protected:
104  /** @brief analytic jacobian */
105  virtual int GetJacobian_(const HomgPoint2D& sink,
106  Matrix2x2<double>& Jacobian) const;
107 
108  /** @brief Reimplementation for Pixel transformation,
109  takes sink and computes coordinates in source.
110  */
111  virtual int GetSourceCoordinates_(const HomgPoint2D& sink,
112  HomgPoint2D& source) const;
113 
114  /// Textures for backward mapping: Run over sink and compute source
116 
117  };
118 
119 } // namespace
120 
121 #endif
122 
123 #include <Base/Common/BIASpragmaEnd.hh>
124 
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
Abstract base class to map an image (texture) src to an image sink with an arbitrary continuous funct...
TextureTransform * T_
Textures for backward mapping: Run over sink and compute source.
class for representing parameterized image warps, such as homography, displacement, ...
virtual TextureTransform * Clone() const =0
virtual covariant copy constructor, caller must eventually destroy the created object ...
void SetTextureTransform(const TextureTransform &T)
create clone of your texture tranform and set for mapping
Maps source pixel to sink pixel given any TextureTransform.
virtual int GetBoundingBox(unsigned int srcwidth, unsigned int srcheight, unsigned int sinkwidth, unsigned int sinkheight, int &tlx, int &tly, int &brx, int &bry)
calculates the bounding box in sink image, where to do the backward mapping.
class BIASGeometryBase_EXPORT HomgPoint2D