Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
HomgLine3D.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 
26 #ifndef __HOMGLINE3D_HH__
27 #define __HOMGLINE3D_HH__
28 #include "bias_config.h"
29 
30 #include "HomgPoint3D.hh"
31 
32 #define HOMGLINE3D_TYPE double
33 #define HOMGLINE3D_EPS 1e-12
34 namespace BIAS{
35 
36  /**
37  @class HomgLine3D
38  a homogenous homogenized line is described by a direction vector PointInf_
39  (a point at infinity) and a starting point PointFin_ (which is the
40  closest vector from the coordinate origin to the line
41  if the line is not homogenized, it can bve described by any two points
42  */
43  class BIASGeometryBase_EXPORT HomgLine3D
44  {
45  public:
46  inline HomgLine3D();
47 
48  inline HomgLine3D(const HomgPoint3D& p1, const HomgPoint3D& p2);
49 
50  inline ~HomgLine3D();
51 
52  inline HomgPoint3D GetPointInf() const
53  { return PointInf_; };
54 
55  inline HomgPoint3D GetPointFin() const
56  { return PointFin_; };
57 
58  inline void Set(const HomgPoint3D& p1, const HomgPoint3D& p2);
59 
60  inline void Homogenize();
61 
62  void CalculateFootpoint(HomgPoint3D& p, HomgPoint3D& footp);
63 
64  inline void Distance(HomgPoint3D& p, HOMGLINE3D_TYPE& dist);
65 
66  protected:
67  HomgPoint3D PointInf_, PointFin_;
68  };
69 
70 
71 
72  inline HomgLine3D::HomgLine3D() : PointInf_(), PointFin_()
73  {}
74 
75  inline HomgLine3D::HomgLine3D(const HomgPoint3D& p1, const HomgPoint3D& p2)
76  : PointInf_(p1), PointFin_(p2)
77  {}
78 
80  {}
81 
82  inline void HomgLine3D::Set(const HomgPoint3D& p1, const HomgPoint3D& p2)
83  {
84  PointInf_ = p1;
85  PointFin_ = p2;
86  }
87 
88  inline void HomgLine3D::Homogenize()
89  {
90  Vector3<double> vi, v;
93 
94  // assume one point in euklidean space
95  BIASASSERT(PointInf_.GetW() != 0.0 || PointFin_.GetW() != 0.0);
96 
97  if (PointFin_.GetW() == 0){ // points are swapped
98  HomgPoint3D tmp = PointFin_;
100  PointInf_ = tmp;
101  }
102 
103  if (PointInf_.GetW() != 0.0){ // move PointInf_ to infinity
105  // norm2 can be used because w == 0
107  }
108 
109  // calculate footpoint to coordinate origin on line
110  vi[0] = PointInf_[0];
111  vi[1] = PointInf_[1];
112  vi[2] = PointInf_[2];
113  v[0] = PointFin_[0];
114  v[1] = PointFin_[1];
115  v[2] = PointFin_[2];
116  double t;
117  v.ScalarProduct(vi, t);
118  v = v - (vi * t);
119  PointFin_[0] = v[0];
120  PointFin_[1] = v[1];
121  PointFin_[2] = v[2];
122  PointFin_[3] = 1.0;
123  }
124 
125 
127  HomgPoint3D& footp)
128  {
129  Vector3<double> vi, v, tmp;
130 
131  Homogenize();
132  // cannot calculate footpoint to infinite point
133  BIASASSERT(p.GetW() !=0.0);
134  vi[0] = PointInf_[0];
135  vi[1] = PointInf_[1];
136  vi[2] = PointInf_[2];
137  v[0] = PointFin_[0];
138  v[1] = PointFin_[1];
139  v[2] = PointFin_[2];
140  tmp[0] = p[0] / p.GetW();
141  tmp[1] = p[1] / p.GetW();
142  tmp[2] = p[2] / p.GetW();
143  double t;
144  tmp.SubIP(v);
145  vi.ScalarProduct(v, t);
146  v = v + (vi * t);
147  footp[0] = v[0];
148  footp[1] = v[1];
149  footp[2] = v[2];
150  footp[3] = 1.0;
151  }
152 
153  inline void
154  HomgLine3D::Distance(HomgPoint3D& p, HOMGLINE3D_TYPE& dist)
155  {
156  HomgPoint3D footp;
157  CalculateFootpoint(p, footp);
158  footp -= p;
159  dist = footp.NormL2();
160  }
161 
162 } // namespace BIAS
163 
164 
165 #endif // __HOMGLINE3D_HH__
a homogenous homogenized line is described by a direction vector PointInf_ (a point at infinity) and ...
Definition: HomgLine3D.hh:43
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
HomgPoint3D PointFin_
Definition: HomgLine3D.hh:67
void Homogenize()
homogenize class data member elements to W==1 by divison by W
Definition: HomgPoint3D.hh:308
double NormL2() const
Return the L2 norm: sqrt(a^2 + b^2 + c^2 + d^2)
Definition: Vector4.hh:510
HOMGPOINT3D_TYPE GetW() const
Definition: HomgPoint3D.hh:257
void CalculateFootpoint(HomgPoint3D &p, HomgPoint3D &footp)
Definition: HomgLine3D.hh:126
void Distance(HomgPoint3D &p, HOMGLINE3D_TYPE &dist)
Definition: HomgLine3D.hh:154
HomgPoint3D PointInf_
Definition: HomgLine3D.hh:67
HomgPoint3D GetPointFin() const
Definition: HomgLine3D.hh:55
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
void SubIP(const T &scalar)
Substraction (in place) of an scalar.
Definition: Vector3.hh:318
HomgPoint3D GetPointInf() const
Definition: HomgLine3D.hh:52
void Set(const HomgPoint3D &p1, const HomgPoint3D &p2)
Definition: HomgLine3D.hh:82