Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SphericalRectification.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 
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 <Image/SphericalRectification.hh>
26 #include <Geometry/ProjectionParametersGreatCircles.hh>
27 
28 #include <iostream>
29 using namespace std;
30 using namespace BIAS;
31 
32 
33 #define SUPERPARENT RectificationBase<InputStorageType, OutputStorageType>
34 #define PARENT RectificationViaProjectionMappingBase<InputStorageType, OutputStorageType>
35 
36 
37 template <class InputStorageType, class OutputStorageType>
40 PARENT::RectificationViaProjectionMappingBase("SphericalRectification")
41 { }
42 
43 template <class InputStorageType, class OutputStorageType>
46 { }
47 
48 
49 template <class InputStorageType, class OutputStorageType>
53 {
54  const ProjectionParametersSpherical* pps =
55  dynamic_cast<const ProjectionParametersSpherical*>(proj);
56 
57  if(pps == NULL)
58  return false;
59 
60  return true;
61 }
62 
63 
64 template <class InputStorageType, class OutputStorageType>
67 {
68 
69  Pose poseA = SUPERPARENT::ppBA_->GetPose();
70  Pose poseB = SUPERPARENT::ppBB_->GetPose();
71  Pose rectPoseA, rectPoseB;
72  if(SUPERPARENT::CalculateRectifiedBases(poseA, poseB,
73  rectPoseA, rectPoseB, false)!=0)
74  return -1;
75 
76  delete PARENT::rectPPA_;
77  delete PARENT::rectPPB_;
80  PARENT::rectPPA_ = ppgcA = new ProjectionParametersGreatCircles();
81  PARENT::rectPPB_ = ppgcB = new ProjectionParametersGreatCircles();
82 
83  PARENT::rectPPA_->SetPose(rectPoseA);
84  PARENT::rectPPB_->SetPose(rectPoseB);
85 
86  const ProjectionParametersSpherical* ppsA =
87  dynamic_cast<const ProjectionParametersSpherical*>(SUPERPARENT::ppBA_);
88  const ProjectionParametersSpherical* ppsB =
89  dynamic_cast<const ProjectionParametersSpherical*>(SUPERPARENT::ppBB_);
90  BIASASSERT(ppsA != NULL && ppsB != NULL);
91 
92 
93 
94  //determine angle offset
95  HomgPoint3D z(0,0,1,1);
96  HomgPoint3D worldOpticalAxisA = poseA.LocalToGlobal(z);
97 
98  // if(camAngleAlpha>M_PI_2) camAngleAlpha = M_PI_2;
99  double minThetaA, minPhiA, maxThetaA, maxPhiA;
100  if(!ppgcA -> GetAngleInterval(worldOpticalAxisA,
101  ppsA->GetMaxCamAngle(),
102  minThetaA, maxThetaA,
103  minPhiA, maxPhiA) ) {
104  cerr<<"phi A = ("<<minPhiA<<", "<<maxPhiA<<")\n";
105  return -1;
106  }
107 
108  HomgPoint3D worldOpticalAxisB = poseB.LocalToGlobal(z);
109  double minThetaB, minPhiB, maxThetaB, maxPhiB;
110 
111  if(!ppgcB -> GetAngleInterval(worldOpticalAxisB,
112  ppsB->GetMaxCamAngle(),
113  minThetaB, maxThetaB,
114  minPhiB, maxPhiB) ){
115  cerr<<"phi B = ("<<minPhiB<<", "<<maxPhiB<<")\n";
116  return -1;
117  }
118 // cerr<<"phi A = ("<<minPhiA<<", "<<maxPhiA<<")\n";
119 // cerr<<"phi B = ("<<minPhiB<<", "<<maxPhiB<<")\n";
120 
121  //find the smallest common viewing directions
122  //parallel boundry rays should be the max/min
123  //use the smaller/larger of the values to search
124  //all possible match positions
125  double commonThetaMin, commonPhiMin, commonThetaMax, commonPhiMax;
126  commonThetaMin = (minThetaA<minThetaB) ? minThetaA : minThetaB;
127  //propagete the larger here since only common epilines are of interest!
128  commonPhiMin = (minPhiA>minPhiB) ? minPhiA : minPhiB;
129 
130  //cerr<<"commonPhiMin "<<commonPhiMin<<endl;
131 
132  //override angles are applied restrain the fov,
133  //use max of min angles:
134  if(commonThetaMin<PARENT::thetaMinOverride_)
135  commonThetaMin= PARENT::thetaMinOverride_;
136  if(commonPhiMin<PARENT::phiMinOverride_)
137  commonPhiMin= PARENT::phiMinOverride_;
138 
139  commonThetaMax = (maxThetaA>maxThetaB) ? maxThetaA : maxThetaB;
140  //propagete the smaller here since only common epilines are of interest!
141  commonPhiMax = (maxPhiA>maxPhiB) ? maxPhiB : maxPhiA;
142  //override angles are applied restrain the fov,
143  //use min of max angles :
144  if(commonPhiMax>PARENT::phiMaxOverride_)
145  commonPhiMax = PARENT::phiMaxOverride_;
146  if(commonThetaMax>PARENT::thetaMaxOverride_)
147  commonThetaMax = PARENT::thetaMaxOverride_;
148 
149 
150  //determine smallest angular sampling distance:
151  //
152  //smallest angular sampling step in phi:
153  double maxRadius = ppsA->GetRadius();
154  if(ppsB->GetRadius()>maxRadius)
155  maxRadius = ppsB->GetRadius();
156  double angularSamplingDistancePhi = 1.0/maxRadius;
157 
158  //smallest angular sampling step in theta:
159  double angularSamplingDistanceThetaA =
160  ppsA->GetMaxCamAngle()/ppsA->GetRadius();
161  double angularSamplingDistanceThetaB =
162  ppsB->GetMaxCamAngle()/ppsB->GetRadius();
163  double angularSamplingDistanceTheta =
164  (angularSamplingDistanceThetaA < angularSamplingDistanceThetaB) ?
165  angularSamplingDistanceThetaA : angularSamplingDistanceThetaB;
166 
167  //overall minimal sampling step
168  double minAngularSamplingDistance =
169  (angularSamplingDistancePhi<angularSamplingDistanceTheta) ?
170  angularSamplingDistancePhi : angularSamplingDistanceTheta ;
171 
172  //use angle ranges and minial sampling distance to find common resolution:
173  double angleRangeTheta = commonThetaMax - commonThetaMin;
174  double angleRangePhi = commonPhiMax - commonPhiMin;
175  double numSamplesOnEpiLine = angleRangeTheta/minAngularSamplingDistance;
176  double numEpiLines = angleRangePhi/minAngularSamplingDistance;
177 
178 // cerr<<"common Theta = ("<<commonThetaMin<<", "<<commonThetaMax<<")\n";
179 // cerr<<"common phi = ("<<commonPhiMin<<", "<<commonPhiMax<<")\n";
180 
181  ppgcA->SetInternals(commonPhiMin, commonPhiMax,
182  commonThetaMin, commonThetaMax,
183  (unsigned int)floor(numSamplesOnEpiLine),
184  (unsigned int)floor(numEpiLines));
185  ppgcB->SetInternals(commonPhiMin, commonPhiMax,
186  commonThetaMin, commonThetaMax,
187  (unsigned int)floor(numSamplesOnEpiLine),
188  (unsigned int)floor(numEpiLines));
189 
190 
191 
192  return 0;
193 }
194 
195 // template <class InputStorageType, class OutputStorageType>
196 // int BIAS::SphericalRectification<InputStorageType, OutputStorageType>::
197 // DetermineGreatCircleParametersFromSpherical_(
198 // ProjectionParametersSpherical* ppsIn,
199 // Pose& rectPose,
200 // double& minAlpha,
201 // double& minBeta,
202 // double& alphaRange,
203 // double& betaRange,
204 // double& relativeAlphaRes,
205 // double& relativeBetaRes)
206 // {
207 
208 // }
209 
210 namespace BIAS{
215 
216 #if defined(BUILD_IMAGE_CHAR)
219 #endif
220 
221 #if defined(BUILD_IMAGE_USHORT)
223 #endif
224 
225 #if defined(BUILD_IMAGE_SHORT)
227 #endif
228 
229 #if defined(BUILD_IMAGE_SHORT)&&defined(BUILD_IMAGE_USHORT)
231 #endif
232 
233 #if defined(BUILD_IMAGE_INT)
234 template class SphericalRectification<int,int>;
235 #endif
236 
237 #if defined(BUILD_IMAGE_USHORT)
239 #endif
240 
241 #if defined(BUILD_IMAGE_USHORT) && defined(BUILD_IMAGE_INT)
243 #endif
244 
245 #if defined(BUILD_IMAGE_DOUBLE)
247 #endif
248 }
void SetInternals(const double minPhi, const double maxPhi, const double minTheta, const double maxTheta, const unsigned int imgWidth, const unsigned int imgHeight)
Calculates and sets internal camera parameters.
Base class for rectification implementations that make use of projections to represent rectified stat...
virtual int DetermineRectificationParameters_()
Calculating the projection parameters for specific rectification.
virtual bool IsInputCameraValid(const BIAS::Image< InputStorageType > &img, const BIAS::ProjectionParametersBase *proj)
only spherical cameras are allowed for now
spherical camera that samples along big circles containig the H vector.
Represents 3d pose transformations, parametrized as Euclidean translation and unit quaternion orienta...
Definition: Pose.hh:73
Class implements rectification by image projection onto a sphere.
camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
HomgPoint3D LocalToGlobal(const HomgPoint3D &X_L) const
Transform point from local frame to world coordinate frame.
double GetRadius() const
Return radius of spherical image in pixels.
Camera parameters which define the mapping between rays in the camera coordinate system and pixels in...
double GetMaxCamAngle() const
Get maximal camera angle (in rad), i.e.