Salome HOME
828da59ff2ae0d86b9e9ac2d90f21972a6df4dac
[modules/multipr.git] / src / MULTIPR / MULTIPR_DecimationFilter.hxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_DecimationFilter.hxx
6  *
7  * \brief   Interface DecimationFilter: filter used for decimation.
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 #ifndef MULTIPR_DECIMATION_FILTER_HXX
15 #define MULTIPR_DECIMATION_FILTER_HXX
16
17 //*****************************************************************************
18 // Includes section
19 //*****************************************************************************
20
21 extern "C"
22 {
23         #include "med.h"
24 }
25
26 #include <iostream>
27 #include <vector>
28
29
30 namespace multipr
31 {
32
33 //*****************************************************************************
34 // Predeclaration
35 //*****************************************************************************
36
37 class Mesh;
38 class PointOfField;
39
40
41 //*****************************************************************************
42 // Interface DecimationFilter and factory to build filters.
43 //*****************************************************************************
44
45 class DecimationFilter
46 {
47 public:
48         /**
49          * Decimation filter factory.
50          * \param  pFilterName name of the filter to be instanciated.
51          * \return a new instance of the given filter. 
52          */
53         static DecimationFilter* create(const char* pFilterName);
54         
55 public:
56         
57         /** 
58          * Builds an empty DecimationFilter (default constructor).
59          */
60         DecimationFilter() { }
61         
62         /**
63          * Destructor. Removes everything.
64          */
65         virtual ~DecimationFilter() { } 
66         
67         /**
68          * Interface. Creates a new Mesh by decimating the given Mesh with this DecimationFilter.
69          * \param  pMesh        any mesh to be decimated; must not be NULL.
70          * \param  pArgv        all the arguments of the filter as a string; must not be NULL.
71          * \param  pNameNewMesh name of the decimated mesh; must not be NULL.
72          * \return the decimated mesh.
73          */
74         virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh) = 0;
75         
76 private:
77         
78         // do not allow copy constructor
79         DecimationFilter(const DecimationFilter&);
80         
81         // do not allow copy
82         DecimationFilter& operator=(const DecimationFilter&);
83         
84         // do not allow operator ==
85         bool operator==(const DecimationFilter&); 
86
87 }; // class DecimationFilter
88
89
90 //*****************************************************************************
91 // Filter : Average Gradient
92 //*****************************************************************************
93
94 class DecimationFilterGradAvg : public DecimationFilter
95 {
96 public:
97
98         /**
99          * Builds an empty DecimationFilterGradAvg (default constructor).
100          */
101         DecimationFilterGradAvg();
102         
103         /**
104          * Destructor. Removes everything.
105          */
106         virtual ~DecimationFilterGradAvg();
107         
108         /**
109          * Creates a new Mesh by decimating the given Mesh with this DecimationFilter.
110          * 
111          * For each element
112          *     Keep this element if all its points (related to a field) have a |gradient| > threshold.
113          *
114          * For each point, gradient is computed by considering all the neighbours in a sphere of radius r.
115          *
116          * \param  pMesh        any mesh to be decimated; must not be NULL.
117          * \param  pArgv        all the arguments of the filter as a string; must not be NULL.
118          *                      for GradAvg, expected "fieldName fieldIt threshold radius boxing" (5 parameters).
119          * \param  pNameNewMesh name of the decimated mesh; must not be NULL.
120          * \return the decimated mesh.
121          */
122         virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh);
123         
124         /**
125          * Returns information about gradient.
126          */
127         void getGradientInfo(
128                 Mesh*       pMesh, 
129                 const char* pFieldName, 
130                 int         pFieldIt, 
131                 double      pRadius,
132                 int         pBoxing,
133                 double*     pOutGradMin,
134                 double*     pOutGradAvg,
135                 double*     pOutGradMax);
136         
137 private:
138
139         /**
140          * Returns the norm of the gradient of the field at the given point.
141          * Sub-method used by apply().
142          * \param  pPt        any point in the field.
143          * \param  pNeigbours neighbourhood of pPt.
144          * \return the norm of the gradient of the field in pPt.
145          */
146         med_float computeNormGrad(const PointOfField& pPt, const std::vector<PointOfField>& pNeighbours) const;
147         
148 private:
149         
150         // do not allow copy constructor
151         DecimationFilterGradAvg(const DecimationFilterGradAvg&);
152         
153         // do not allow copy
154         DecimationFilterGradAvg& operator=(const DecimationFilterGradAvg&);
155         
156         // do not allow operator ==
157         bool operator==(const DecimationFilterGradAvg&); 
158         
159 }; // class DecimationFilterGradAvg
160
161
162 } // namespace MULTIPR
163
164
165 #endif // MULTIPR_DECIMATION_FILTER_HXX
166
167 // EOF