Salome HOME
Update copyright
[modules/smesh.git] / src / StdMeshers / StdMeshers_Distribution.hxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH StdMeshers : implementaion of point distribution algorithm
24 //  File   : StdMeshers_Distribution.hxx
25 //  Author : Alexandre SOLOVYOV
26 //  Module : SMESH
27 //  $Header$
28 //
29 #ifndef _STD_MESHERS_DISTRIBUTION_HXX_
30 #define _STD_MESHERS_DISTRIBUTION_HXX_
31
32 #include "SMESH_StdMeshers.hxx"
33
34 #include <vector>
35 #include <math_Function.hxx>
36 #include <ExprIntrp_GenExp.hxx>
37 #include <Expr_Array1OfNamedUnknown.hxx>
38 #include <TColStd_Array1OfReal.hxx>
39
40
41 class STDMESHERS_EXPORT Function 
42 {
43 public:
44   Function( const int );
45   virtual ~Function();
46   virtual bool   value( const double, double& ) const;
47   virtual double integral( const double, const double ) const = 0;
48
49 private:
50   int myConv;
51 };
52
53 class STDMESHERS_EXPORT FunctionIntegral : public Function
54 {
55 public:
56   FunctionIntegral( const Function*, const double );
57   virtual ~FunctionIntegral();
58   virtual bool   value( const double, double& ) const;
59   virtual double integral( const double, const double ) const;
60
61 private:
62   Function* myFunc;
63   double    myStart;
64 };
65
66 class STDMESHERS_EXPORT FunctionTable : public Function
67 {
68 public:
69   FunctionTable( const std::vector<double>&, const int );
70   virtual ~FunctionTable();
71   virtual bool   value( const double, double& ) const;
72   virtual double integral( const double, const double ) const;
73
74 private:
75   bool    findBounds( const double, int&, int& ) const;
76
77   //integral from x[i] to x[i+1]
78   double  integral( const int i ) const;
79
80   //integral from x[i] to x[i]+d
81   //warning: function is presented as linear on interaval from x[i] to x[i]+d,
82   //         for correct result d must be >=0 and <=x[i+1]-x[i]
83   double  integral( const int i, const double d ) const;
84
85 private:
86   std::vector<double>  myData;
87 };
88
89 class STDMESHERS_EXPORT FunctionExpr : public Function, public math_Function
90 {
91 public:
92   FunctionExpr( const char*, const int );
93   virtual ~FunctionExpr();
94   virtual Standard_Boolean Value( const Standard_Real, Standard_Real& );
95   virtual bool   value( const double, double& ) const;
96   virtual double integral( const double, const double ) const;
97
98 private:
99   Handle(ExprIntrp_GenExp)    myExpr;
100   Expr_Array1OfNamedUnknown   myVars;
101   TColStd_Array1OfReal        myValues;
102 };
103
104 STDMESHERS_EXPORT
105 bool buildDistribution( const Function& f,
106                         const double start, const double end,
107                         const int nbSeg,
108                         std::vector<double>& data,
109                         const double eps );
110
111 STDMESHERS_EXPORT
112 bool buildDistribution( const TCollection_AsciiString& f, const int conv, const double start, const double end,
113                         const int nbSeg, std::vector<double>& data, const double eps );
114 STDMESHERS_EXPORT
115 bool buildDistribution( const std::vector<double>& f, const int conv, const double start, const double end,
116                         const int nbSeg, std::vector<double>& data, const double eps );
117
118 #endif