Salome HOME
Join modifications from branch BR_3_1_0deb
[modules/smesh.git] / src / StdMeshers / StdMeshers_Distribution.hxx
1 //  SMESH StdMeshers : implementaion of point distribution algorithm
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
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 <vector>
33 #include <math_Function.hxx>
34 #include <ExprIntrp_GenExp.hxx>
35 #include <Expr_Array1OfNamedUnknown.hxx>
36 #include <TColStd_Array1OfReal.hxx>
37
38
39 class Function 
40 {
41 public:
42   Function( const int );
43   virtual ~Function();
44   virtual bool   value( const double, double& ) const;
45   virtual double integral( const double, const double ) const = 0;
46
47 private:
48   int myConv;
49 };
50
51 class FunctionIntegral : public Function
52 {
53 public:
54   FunctionIntegral( const Function*, const double );
55   virtual ~FunctionIntegral();
56   virtual bool   value( const double, double& ) const;
57   virtual double integral( const double, const double ) const;
58
59 private:
60   Function* myFunc;
61   double    myStart;
62 };
63
64 class FunctionTable : public Function
65 {
66 public:
67   FunctionTable( const std::vector<double>&, const int );
68   virtual ~FunctionTable();
69   virtual bool   value( const double, double& ) const;
70   virtual double integral( const double, const double ) const;
71
72 private:
73   bool    findBounds( const double, int&, int& ) const;
74
75   //integral from x[i] to x[i+1]
76   double  integral( const int i ) const;
77
78   //integral from x[i] to x[i]+d
79   //warning: function is presented as linear on interaval from x[i] to x[i]+d,
80   //         for correct result d must be >=0 and <=x[i+1]-x[i]
81   double  integral( const int i, const double d ) const;
82
83 private:
84   std::vector<double>  myData;
85 };
86
87 class FunctionExpr : public Function, public math_Function
88 {
89 public:
90   FunctionExpr( const char*, const int );
91   virtual ~FunctionExpr();
92   virtual Standard_Boolean Value( Standard_Real, Standard_Real& );
93   virtual bool   value( const double, double& ) const;
94   virtual double integral( const double, const double ) const;
95
96 private:
97   Handle(ExprIntrp_GenExp)    myExpr;
98   Expr_Array1OfNamedUnknown   myVars;
99   TColStd_Array1OfReal        myValues;
100 };
101
102 bool buildDistribution( const Function& f,
103                         const double start, const double end,
104                         const int nbSeg,
105                         vector<double>& data,
106                         const double eps );
107
108 bool buildDistribution( const TCollection_AsciiString& f, const int conv, const double start, const double end,
109                         const int nbSeg, vector<double>& data, const double eps );
110 bool buildDistribution( const std::vector<double>& f, const int conv, const double start, const double end,
111                         const int nbSeg, vector<double>& data, const double eps );
112
113 #endif