]> Creatis software - clitk.git/blob - tools/clitkEllipse.h
Ported C99 std::isnormal function
[clitk.git] / tools / clitkEllipse.h
1 /*=========================================================================
2                                                                                 
3   Program:   clitk
4   Language:  C++
5                                                                                 
6   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
7   l'Image). All rights reserved. See Doc/License.txt or
8   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
9                                                                                 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notices for more information.
13                                                                              
14 =========================================================================*/
15
16 #ifndef CLITKELLIPSE_H
17 #define CLITKELLIPSE_H
18
19 #include "clitkCommon.h"
20 #include "clitkSignal.h"
21 #include "itkVector.h"
22 #include <vnl/algo/vnl_generalized_eigensystem.h>
23 #include <vnl/algo/vnl_symmetric_eigensystem.h>
24 #include <vnl/algo/vnl_real_eigensystem.h>
25
26 namespace clitk {
27
28   //---------------------------------------------------------------------
29   class Ellipse : public itk::Vector<double,6> {
30   public:
31     typedef itk::Vector<double,2> Vector2d;
32     typedef itk::Vector<double,6> Vector6d;
33     typedef itk::Matrix<double,6,6> Matrix6x6d;
34     typedef itk::Matrix<double,3,3> Matrix3x3d;
35
36     Ellipse();
37     Ellipse(const Ellipse & e);
38     void InitialiseEllipseFitting(double eta, unsigned int n, clitk::Signal & inputX, clitk::Signal & inputY);
39     double EllipseFittingNextIteration();
40     Vector2d ComputeCenter();
41     Vector2d ComputeSemiAxeLengths();
42     double ComputeAngleInRad();
43     void SetCenterAndSemiAxes(double x0, double y0, double r1, double r2);
44     void Copy(const Vector6d & a);
45     double GetEta() { return mEta; }
46     void UpdateSMatrix(unsigned int begin, unsigned int n, 
47                        clitk::Signal & inputX, clitk::Signal & inputY);
48
49   protected:
50     double mEta;
51     double & a;
52     double & b;
53     double & c;
54     double & d;
55     double & e;
56     double & f;
57     Matrix6x6d C;
58     Matrix6x6d Ct;
59     Matrix6x6d W;
60     Matrix6x6d Wt;
61     Matrix6x6d S;
62     Matrix6x6d Sinv;
63     Matrix6x6d St;
64     std::vector<Vector6d> z;
65     clitk::Signal * mInputX;
66     clitk::Signal * mInputY;
67
68     void CopyBlock(Matrix6x6d & out, const Matrix6x6d & in, 
69                    int ox, int oy, int l, double factor=1.0);
70     void CopyBlock(Matrix6x6d & out, const Matrix3x3d & in, 
71                    int ox, int oy, double factor=1.0);
72     Matrix3x3d GetBlock3x3(const Matrix6x6d & M, int x, int y);
73
74   };
75   //---------------------------------------------------------------------
76     
77 } // end namespace
78
79 #endif