Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
HomgPlane3D.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
21 #include "HomgPlane3D.hh"
22 
23 #include <Base/Common/CompareFloatingPoint.hh>
24 
25 using namespace BIAS;
26 using namespace std;
27 
28 void HomgPlane3D::
29 Set(const HomgPoint3D& PointOnPlane, const Vector3<double>& NormalVector)
30 {
31  HomgPoint3D poph(PointOnPlane); // de-const
32  // normalise for numerical stability
33  // zero point is not a valid point in projective space
34  BIASASSERT(!Equal(poph.NormL2(), 0.0));
35  poph /= poph.NormL2();
36 
37  // normalise for numerical stability, only the direction of the
38  // normal vector is important, not its length
39  Vector3<double> normal(NormalVector);
40  BIASASSERT(!Equal(normal.NormL2(), 0.0));
41  normal /= normal.NormL2();
42 
43  // the plane with normal parallel to NormalVector is given by
44  // [ NormalVector' p4 ]'
45  // since the plane is an entity in projective space, the same plane is
46  // described by
47  // lambda * [ NormalVector' p4 ]'
48  // for each lambda != 0
49  // The PointOnPlane only resides on the plane when the scalar product
50  // between point and plane vanishes
51  // plane' * PointOnPlane = 0
52  // or alternatively
53  // pop' * lambda * NormalVector + w * lambda * p4 = 0 (i)
54  // with PointOnPlane = [ pop' w ]'
55  Vector3<double> pop(poph[0], poph[1], poph[2]);
56  double sp = normal.ScalarProduct(pop);
57  if ( fabs(poph[3]) > fabs(sp) ){
58  // setting lambda = 1, equation (i) can easily be resolved
59  // p4 = - pop' * NormalVector / w
60  data_[0] = normal[0];
61  data_[1] = normal[1];
62  data_[2] = normal[2];
63  data_[3] = -sp / poph[3];
64  } else {
65  // setting lambda * p4 = 1
66  // results in
67  // lambda = -w / pop' * NormalVector
68  double lambda = -poph[3] / sp;
69  data_[0] = lambda * normal[0];
70  data_[1] = lambda * normal[1];
71  data_[2] = lambda * normal[2];
72  data_[3] = 1.0;
73  }
74 }
75 
76 
void ScalarProduct(const Vector3< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
Definition: Vector3.hh:603
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
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
void Set(const Vector3< double > &PointOnPlane, const Vector3< double > &NormalVector)
construct plane, given arbitrary point and normal
Definition: HomgPlane3D.hh:103
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
Definition: Vector3.hh:633