Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DisplacementMapping.cpp
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 BIAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13 
14 BIAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License
20 along with BIAS; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 
24 #include <Base/Common/BIASpragma.hh>
25 #if defined(WIN32) && defined(_MSC_VER)
26 # pragma warning (disable: 4661) /* no suitable def. for explicit instantiation */
27 #endif
28 
29 #include "DisplacementMapping.hh"
30 #include <Base/Geometry/HomgPoint2D.hh>
31 #include <Base/Image/ImageIO.hh>
32 using namespace std;
33 using namespace BIAS;
34 
35 template <class InputStorageType, class OutputStorageType>
38 {}
39 
40 //Example of how to use DisplacementMapping is in ExampleHomography
41 //state: 18-05-2007
42 
43 template <class InputStorageType, class OutputStorageType>
46  mapped_ = false;
47 }
48 
49 template <class InputStorageType, class OutputStorageType>
52  mapped_ = false;
53  SetDisplacementMap(dismap);
54 }
55 
56 template <class InputStorageType, class OutputStorageType>
59  if(dismap.GetChannelCount()!=3){
60  cout << "Displacement Map must have 3 Channels but has only "
61  << dismap.GetChannelCount() << endl;
62  return -1;
63  }
64  if(!dismap.IsInterleaved()){
65  cout << "Displacement map must be INTERLEAVED but is not" << endl;
66  return -1;
67  }
68  dismap_ = dismap;
69  mapped_ = true;
70  return 0;
71 }
72 
73 template <class InputStorageType, class OutputStorageType>
76  HomgPoint2D& source) const {
77  BIASASSERT(sink[2]==1.0);
78 
79  //check if the displacement map is computed
80  if(!mapped_){
81  //cout << "No Displacement Map in DisplacementMapper activated" << endl;
82  return -1;
83  }
84 
85  //check if sink-point is within the displacement map
86  if(sink[0] >= dismap_.GetWidth() || sink[1] >= dismap_.GetHeight())
87  return -1;
88  if(sink[0] < 0 || sink[1] < 0)
89  return -1;
90 
91  //get the index
92  const float* Data = dismap_.GetImageData();
93 
94  //get index of the displacement-map image (unflipped index)
95  int index = (int)(3.0*(((double)dismap_.GetHeight()-1.0-sink[1])*
96  (double)dismap_.GetWidth()+sink[0]));
97 
98  //result
99  source[0] = Data[index];
100  source[1] = Data[index+1];
101  source[2] = Data[index+2];
102 
103  return 0;
104 }
105 
106 namespace BIAS{
108 template class DisplacementMapping<float, float>;
111 
112 #if defined(BUILD_IMAGE_CHAR)
114 template class DisplacementMapping<char, char>;
115 #endif
116 
117 #if defined(BUILD_IMAGE_USHORT)
119 #endif
120 
121 #if defined(BUILD_IMAGE_SHORT)
122 template class DisplacementMapping<short, short>;
123 #endif
124 
125 #if defined(BUILD_IMAGE_SHORT)&&defined(BUILD_IMAGE_USHORT)
127 #endif
128 
129 #if defined(BUILD_IMAGE_INT)
130 template class DisplacementMapping<int,int>;
131 #endif
132 
133 #if defined(BUILD_IMAGE_USHORT)
135 #endif
136 
137 #if defined(BUILD_IMAGE_USHORT) && defined(BUILD_IMAGE_INT)
139 #endif
140 
141 #if defined(BUILD_IMAGE_DOUBLE)
143 #endif
144 }
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
Definition: HomgPoint2D.hh:67
bool IsInterleaved() const
Definition: ImageBase.hh:491
Maps image src to image sink with displacement mapl generated by backwardmapping method.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382