Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SphericalCoordinates.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 
26 
27 #include <Geometry/SphericalCoordinates.hh>
28 
29 using namespace BIAS;
30 using namespace std;
31 
32 
34 SetAffineBase(const CoordinateTransform3D& newAffineBase)
35 {
36  affineReferenceFrame_ = newAffineBase;
37 }
38 
41 {
42  return affineReferenceFrame_;
43 }
44 
45 
48  double& rho,
49  double& phi, double& theta) const
50 {
51  HomgPoint3D localPoint = affineReferenceFrame_.GlobalToLocal(point);
52  localPoint[3] = 0;
53  rho = localPoint.NormL2();
54 
55  const double x = localPoint[0];
56  const double y = localPoint[1];
57  const double z = localPoint[2];
58 
59  if((rho<1e-12) || (fabs(x)<1e-12 && fabs(y)<1e-12)) {
60  rho = 0;
61  phi = 0;
62  theta = 0;
63 
64  } else {
65  phi = atan2(y,x);
66  theta = acos(z/rho);
67  }
68 
69  BIASASSERT(phi>-M_PI);
70  BIASASSERT(phi<=M_PI);
71  BIASASSERT(theta>=0);
72  BIASASSERT(theta<=M_PI);
73 
74 }
75 
76 
78 GetCartesianRayFromFullPhi(const double& phi, const double& theta,
79  HomgPoint3D& ray) const
80 {
81  ray[0] = sin(theta)*cos(phi);
82  ray[1] = sin(theta)*sin(phi);
83  ray[2] = cos(theta);
84  ray[3] = 0;
85 
86  ray = affineReferenceFrame_.LocalToGlobal(ray);
87 }
88 
89 
90 
const CoordinateTransform3D & GetAffineBase() const
void GetCartesianRayFromFullPhi(const double &phi, const double &theta, HomgPoint3D &ray) const
Calculates the Euclidean ray belonging to the passed angles in the world coordinate frame...
void SetAffineBase(const CoordinateTransform3D &newAffineBase)
Sets the &quot;local&quot; coordinate frame of the spherical coordinates.
double NormL2() const
Return the L2 norm: sqrt(a^2 + b^2 + c^2 + d^2)
Definition: Vector4.hh:510
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
void GetSphericalCoordinatesFullPhi(const HomgPoint3D &point, double &rho, double &phi, double &theta) const
Method calculates spherical coordinates, hereby phi will lie in the range (-M_PI, M_PI] while theta l...
Transforms 3d points between two different coodinate systems, e.g.