Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Quadric3D.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 __QUADRIC3D_HH__
27 #define __QUADRIC3D_HH__
28 #include "bias_config.h"
29 
30 #include <Base/Debug/Error.hh>
31 #include <Base/Debug/Debug.hh>
32 #include <Base/Math/Matrix4x4.hh>
33 #include <Base/Geometry/HomgPoint3D.hh>
34 #include <Geometry/CovMatrix3x3.hh>
35 
36 #define QUADRIC3D_TYPE double
37 
38 // defines for confidence of new inlying measurement, see text below
39 #define GAUSS3D_CONFIDENCE_20_PERCENT 1.00
40 #define GAUSS3D_CONFIDENCE_39_PERCENT 1.36
41 #define GAUSS3D_CONFIDENCE_50_PERCENT 1.54
42 #define GAUSS3D_CONFIDENCE_68_PERCENT 1.88
43 #define GAUSS3D_CONFIDENCE_90_PERCENT 2.50
44 #define GAUSS3D_CONFIDENCE_95_PERCENT 2.79
45 #define GAUSS3D_CONFIDENCE_99_PERCENT 3.37
46 
47 
48 
49 namespace BIAS {
50 
51  /** @class Quadric3D
52  @ingroup g_geometry
53  @brief A quadric as a 4x4 matrix describing a surface in 3d projective
54  space defined by a quadratic equation, e.g. a sphere.
55 
56  Quadric3D is a 4x4 matrix Q, which describes a surface in 3d.
57  All points x that lie on this surface, fulfill x^T Q x = 0,
58  which is a quadratic equation in the components of x.
59  For quadrics such as spheres or ellipsoids you can check if
60  a point is inside or outside the quadric using LocatePoint(),
61  for others you can also get the "side" the point lies relative to the
62  Quadric.
63  If the Quadric is a _normalized_ ellipsoid, points inside yield negative
64  values while LocatePoint computes positive ones for points ouside.
65 
66  Projective cameras map quadrics to conics (see Conic2D) in the image
67  plane.
68 
69  Construction of Quadrics (i.e. ellipsoids) from covariance matrices:
70  You can construct a Quadric3D from a CovMatrix3x3, the 3d surface
71  will then represent all points of some constant probability of the
72  3d-normal distribution. The decision which probability to choose
73  as a threshold, and thus how large the ellipsoid should become,
74  depends on the desired probability for a new measurement
75  to lie inside the quadric.
76 
77  The standard confidence region is the set of points which lie inside
78  the ellipsoid defined by main axes' length = sigma_i
79  The probability that a measurement falls into this region is only 20%.
80  If you want to increase the confidence that a point falls into your
81  ellipsoid, you may enlarge the main axes by multiplication with a
82  constant factor (see 3D column in subsequent table).
83  For comparison purposes, the coresponding factors for 1D/2D are also
84  given in the table:
85 
86 
87  - 1-D 2-D 3-D Conf(%)
88  - 0.01 0.14 0.33 .. 01
89  - 0.06 0.32 0.59 .. 05
90  - 0.14 0.46 0.76 .. 10
91  - 0.25 0.66 1.00 .. 20
92  - 0.52 1.00 1.36 .. 39
93  - 0.68 1.18 1.54 .. 50
94  - 1.00 1.52 1.88 .. 68
95  - 1.64 2.15 2.50 .. 90
96  - 1.96 2.45 2.79 .. 95
97  - 2.58 3.04 3.37 .. 99
98  - 2.81 3.26 3.58 .. 99.5
99 
100  Suppose you have a covariance matrix and want to create an ellipsoid,
101  where 99% of new measurements will fall in. In that case you have
102  to use main axes of length (sigma_i*3.37)
103 
104  @author koeser 10/2003 */
105 
106  class BIASGeometry_EXPORT Quadric3D : public Matrix4x4<QUADRIC3D_TYPE>
107  {
108 
109  public:
110  Quadric3D() {};
111 
112  /** @brief set default matrix values */
113  explicit Quadric3D(const MatrixInitType& i)
114  : Matrix4x4<QUADRIC3D_TYPE>(i){};
115 
116  Quadric3D(const Matrix<QUADRIC3D_TYPE> &M) { (*this) = M; };
117 
118  /** @brief constructs an ellipsoid around the center C
119 
120  The covariance matrix's stddevs along the main axes (multiplied by
121  dSize) are used as the ellipsoid's radii
122  for dsize==1 this is the standard confidence region (SCR)
123  see Kanatani: "Statistical optimization ...", p.122
124  The probability that the point is in the SCR is about 20%
125  See doc above for values for other probabilities */
126  Quadric3D(const HomgPoint3D& C, const CovMatrix3x3& cov,
127  const double& dScale = GAUSS3D_CONFIDENCE_20_PERCENT);
128 
129  /** @brief determines if point3D is inside/on/outside the surface
130 
131  For a normalized ellipsoid,
132  a negative return value means the point is inside, a positive value
133  means outside and 0 means exactly on the surface (you
134  have to use epsilon environments for all tests)
135  LocatePoint internally computes the difference of Mahalanobis distances
136  of point3D from the center and a surface point from the center */
137  inline double LocatePoint(const HomgPoint3D& point3D) const {
138  return ( point3D *((*this)*point3D) ); }
139 
140  /** @brief sets trace of upperleft submatrix3x3 to unity */
141  inline bool Normalize() {
142  double d = (*this)[0][0]+(*this)[1][1]+(*this)[2][2];
143  if (fabs(d)<DBL_EPSILON) return false;
144  (*this) /= d; return true; }
145 
147  Matrix4x4<QUADRIC3D_TYPE>::operator=(M); return (*this);
148  }
149 
150  /** @brief computes the dual quadric (points <-> planes)
151  @param UseSVD use numerically robust svd or fast analytic inverse
152  @author koeser 03/2005 */
153  Quadric3D GetDualQuadric(bool UseSVD = false) const;
154 
155  /** @brief computes signature of matrix,
156  (no. of neg. eigenvalues) - (no. of pos. eigenvalues) or vice versa
157  if there are more pos. eigenvalues */
158  unsigned int GetSignature();
159 
160  };
161 
162 
163 }
164 
165 #endif
MatrixInitType
can be passed to matrix constructors to init the matrix with the most often used values ...
Definition: Matrix.hh:59
A quadric as a 4x4 matrix describing a surface in 3d projective space defined by a quadratic equation...
Definition: Quadric3D.hh:106
Quadric3D & operator=(const Matrix< QUADRIC3D_TYPE > &M)
Definition: Quadric3D.hh:146
Quadric3D(const MatrixInitType &i)
set default matrix values
Definition: Quadric3D.hh:113
class for 3x3 covariance matrices
Definition: CovMatrix3x3.hh:50
double LocatePoint(const HomgPoint3D &point3D) const
determines if point3D is inside/on/outside the surface
Definition: Quadric3D.hh:137
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
Definition: HomgPoint3D.hh:61
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix4x4.hh:54
Matrix4x4 & operator=(const Matrix< T > &mat)
assignment operators calling corresponding operator from base class &quot;TNT::Matrix&quot; if appropriate ...
Definition: Matrix4x4.cpp:61
bool Normalize()
sets trace of upperleft submatrix3x3 to unity
Definition: Quadric3D.hh:141
Quadric3D(const Matrix< QUADRIC3D_TYPE > &M)
Definition: Quadric3D.hh:116