00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef ELLIPSOID_H
00017 #define ELLIPSOID_H
00018
00019 #include "math_types.h"
00020 #include <OpenTissue/utility/gl/gl_draw_ellipsoid.h>
00021
00025 enum ELLIPSOID_PROJECTION_TYPE
00026 {
00027 MAHALANOBIS
00028 };
00029
00033 class ellipsoid
00034 {
00035 public:
00036 typedef double real_type;
00037 typedef vector3 vector3_type;
00038
00042 ellipsoid ()
00043 : r0 (0), r1 (0), r2 (0)
00044 {
00045 };
00046
00069 ellipsoid (vector3 C, vector3 a0, vector3 a1, vector3 a2, double _r0, double _r1, double _r2)
00070 : m_center (C),
00071 m_axis0 (a0),
00072 m_axis1 (a1),
00073 m_axis2 (a2),
00074 r0 (_r0),
00075 r1 (_r1),
00076 r2 (_r2)
00077 {
00078 };
00079
00105 void init (vector3 C, vector3 a0, vector3 a1, vector3 a2, double _r0, double _r1, double _r2)
00106 {
00107 m_center = C;
00108 m_axis0 = a0;
00109 m_axis1 = a1;
00110 m_axis2 = a2;
00111 r0 = _r0;
00112 r1 = _r1;
00113 r2 = _r2;
00114 }
00115
00128 void project_point (const vector3 &input, vector3 &output, ELLIPSOID_PROJECTION_TYPE proj_type = MAHALANOBIS) const
00129 {
00130 double N;
00131 project_point (input, output, N, proj_type);
00132 }
00133
00148 void project_point (const vector3 &input, vector3 &output, double &N, ELLIPSOID_PROJECTION_TYPE proj_type = MAHALANOBIS) const
00149 {
00150 if (proj_type == MAHALANOBIS)
00151 {
00152 const vector3 delta = input - m_center;
00153 N = square (dot (delta, m_axis0))/r0 + square (dot (delta, m_axis1))/r1 + square (dot (delta, m_axis2))/r2;
00154 output = delta/N + m_center;
00155 }
00156 }
00157
00158 double euc_mahalanobis2 (const vector3 &p) const
00159 {
00160 return euc_mahalanobis2 (p, m_center);
00161 }
00162
00163 double euc_mahalanobis2 (const vector3 &p, const vector3 ¢er) const
00164 {
00165 const vector3 delta = p - center;
00166 const double dist2 = square (dot (delta, m_axis0)) / r0
00167 + square (dot (delta, m_axis1)) / r1
00168 + square (dot (delta, m_axis2)) / r2;
00169 return dist2;
00170 }
00171
00172 void show () const
00173 {
00174 OpenTissue::gl::ColorPicker (0.7, 0.7, 0.7, 0.5);
00175 OpenTissue::gl::DrawEllipsoid<ellipsoid> (*this);
00176 }
00177
00178 const vector3& center () const
00179 {
00180 return m_center;
00181 };
00182
00183 const vector3& axis0 () const
00184 {
00185 return m_axis0;
00186 };
00187
00188 const vector3& axis1 () const
00189 {
00190 return m_axis1;
00191 };
00192
00193 const vector3& axis2 () const
00194 {
00195 return m_axis2;
00196 };
00197
00198 const double& radius0 () const
00199 {
00200 return r0;
00201 };
00202
00203 const double& radius1 () const
00204 {
00205 return r1;
00206 };
00207
00208 const double& radius2 () const
00209 {
00210 return r2;
00211 };
00212
00213 private:
00214 vector3 m_center, m_axis0, m_axis1, m_axis2;
00215 double r0, r1, r2;
00216 };
00217
00218 #endif // ELLIPSOID_H