0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / math / math_Gauss.hxx
1 // Created on: 1991-05-13
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _math_Gauss_HeaderFile
18 #define _math_Gauss_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Boolean.hxx>
25 #include <math_Matrix.hxx>
26 #include <math_IntegerVector.hxx>
27 #include <Standard_Real.hxx>
28 #include <math_Vector.hxx>
29 #include <Standard_OStream.hxx>
30 class math_NotSquare;
31 class Standard_DimensionError;
32 class StdFail_NotDone;
33 class math_Matrix;
34
35
36
37 //! This class implements the Gauss LU decomposition (Crout algorithm)
38 //! with partial pivoting (rows interchange) of a square matrix and
39 //! the different possible derived calculation :
40 //! - solution of a set of linear equations.
41 //! - inverse of a matrix.
42 //! - determinant of a matrix.
43 class math_Gauss 
44 {
45 public:
46
47   DEFINE_STANDARD_ALLOC
48
49   
50
51   //! Given an input n X n matrix A this constructor performs its LU
52   //! decomposition with partial pivoting (interchange of rows).
53   //! This LU decomposition is stored internally and may be used to
54   //! do subsequent calculation.
55   //! If the largest pivot found is less than MinPivot the matrix A is
56   //! considered as singular.
57   //! Exception NotSquare is raised if A is not a square matrix.
58   Standard_EXPORT math_Gauss(const math_Matrix& A, const Standard_Real MinPivot = 1.0e-20);
59   
60   //! Returns true if the computations are successful, otherwise returns false
61     Standard_Boolean IsDone() const;
62   
63
64   //! Given the input Vector B this routine returns the solution X of the set
65   //! of linear equations A . X = B.
66   //! Exception NotDone is raised if the decomposition of A was not done
67   //! successfully.
68   //! Exception DimensionError is raised if the range of B is not
69   //! equal to the number of rows of A.
70   Standard_EXPORT void Solve (const math_Vector& B, math_Vector& X) const;
71   
72
73   //! Given the input Vector B this routine solves the set of linear
74   //! equations A . X = B. B is replaced by the vector solution X.
75   //! Exception NotDone is raised if the decomposition of A was not done
76   //! successfully.
77   //! Exception DimensionError is raised if the range of B is not
78   //! equal to the number of rows of A.
79   Standard_EXPORT void Solve (math_Vector& B) const;
80   
81
82   //! This routine returns the value of the determinant of the previously LU
83   //! decomposed matrix A.
84   //! Exception NotDone may be raised if the decomposition of A was not done
85   //! successfully, zero is returned if the matrix A was considered as singular.
86   Standard_EXPORT Standard_Real Determinant() const;
87   
88
89   //! This routine outputs Inv the inverse of the previously LU decomposed
90   //! matrix A.
91   //! Exception DimensionError is raised if the ranges of B are not
92   //! equal to the ranges of A.
93   Standard_EXPORT void Invert (math_Matrix& Inv) const;
94   
95   //! Prints on the stream o information on the current state
96   //! of the object.
97   //! Is used to redefine the operator <<.
98   Standard_EXPORT void Dump (Standard_OStream& o) const;
99
100
101
102
103 protected:
104
105
106
107   Standard_Boolean Singular;
108   math_Matrix LU;
109   math_IntegerVector Index;
110   Standard_Real D;
111
112
113 private:
114
115
116
117   Standard_Boolean Done;
118
119
120 };
121
122
123 #include <math_Gauss.lxx>
124
125
126
127
128
129 #endif // _math_Gauss_HeaderFile