Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MULTIPR / MULTIPR_DecimationFilter.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Partitioning/decimation module for the SALOME v3.2 platform
20 //
21 /**
22  * \file    MULTIPR_DecimationFilter.hxx
23  *
24  * \brief   Interface DecimationFilter: filter used for decimation.
25  *
26  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
27  * 
28  * \date    01/2007
29  */
30
31 #ifndef MULTIPR_DECIMATION_FILTER_HXX
32 #define MULTIPR_DECIMATION_FILTER_HXX
33
34 //*****************************************************************************
35 // Includes section
36 //*****************************************************************************
37
38 extern "C"
39 {
40     #include "med.h"
41 }
42
43 #include <iostream>
44 #include <vector>
45
46
47 namespace multipr
48 {
49
50 //*****************************************************************************
51 // Predeclaration
52 //*****************************************************************************
53
54 class Mesh;
55 class PointOfField;
56
57
58 //*****************************************************************************
59 // Interface DecimationFilter and factory to build filters.
60 // Should be derivated to implement new filter.
61 //*****************************************************************************
62
63 class DecimationFilter
64 {
65 public:
66     /**
67      * Decimation filter factory. Must be used to build any new filter from its name.
68      * \param  pFilterName name of the filter to be instanciated.
69      * \return a new instance of the given filter. 
70      */
71     static DecimationFilter* create(const char* pFilterName);
72     
73 public:
74     
75     /** 
76      * Builds an empty DecimationFilter (default constructor).
77      */
78     DecimationFilter() { /* do nothing */ }
79     
80     /**
81      * Destructor. Removes everything.
82      */
83     virtual ~DecimationFilter() { /* do nothing */ } 
84     
85     /**
86      * Interface. Creates a new Mesh by decimating the given Mesh with this DecimationFilter.
87      * \param  pMesh        any mesh to be decimated; must not be NULL.
88      * \param  pArgv        all the arguments of the filter as a string; must not be NULL.
89      * \param  pNameNewMesh name of the decimated mesh; must not be NULL.
90      * \return the decimated mesh.
91      */
92     virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh) = 0;
93     
94 private:
95     
96     // do not allow copy constructor
97     DecimationFilter(const DecimationFilter&);
98     
99     // do not allow copy
100     DecimationFilter& operator=(const DecimationFilter&);
101     
102     // do not allow operator ==
103     bool operator==(const DecimationFilter&); 
104
105 }; // class DecimationFilter
106
107
108 //*****************************************************************************
109 // Filter : Average Gradient
110 //*****************************************************************************
111
112 class DecimationFilterGradAvg : public DecimationFilter
113 {
114 public:
115
116     /**
117      * Builds an empty DecimationFilterGradAvg (default constructor).
118      */
119     DecimationFilterGradAvg();
120     
121     /**
122      * Destructor. Removes everything.
123      */
124     virtual ~DecimationFilterGradAvg();
125     
126     /**
127      * Creates a new Mesh by decimating the given Mesh with this DecimationFilter.
128      * 
129      * For each element
130      *     Keep this element if all its points (related to a field) have a |gradient| > threshold.
131      *
132      * For each point, gradient is computed by considering all the neighbours in a sphere of radius r.
133      *
134      * \param  pMesh        any mesh to be decimated; must not be NULL.
135      * \param  pArgv        all the arguments of the filter as a string; must not be NULL.
136      *                      for GradAvg, expected "fieldName fieldIt threshold radius boxing" (5 parameters).
137      * \param  pNameNewMesh name of the decimated mesh; must not be NULL.
138      * \return the decimated mesh.
139      */
140     virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh);
141     
142     /**
143      * Returns information about gradient.
144      */
145     void getGradientInfo(
146         Mesh*       pMesh, 
147         const char* pFieldName, 
148         int         pFieldIt, 
149         double      pRadius,
150         int         pBoxing,
151         double*     pOutGradMin,
152         double*     pOutGradAvg,
153         double*     pOutGradMax);
154     
155 private:
156
157     /**
158      * Returns the norm of the gradient of the field at the given point.
159      * Sub-method used by apply().
160      * \param  pPt        any point in the field.
161      * \param  pNeigbours neighbourhood of pPt.
162      * \return the norm of the gradient of the field in pPt.
163      */
164     med_float computeNormGrad(const PointOfField& pPt, const std::vector<PointOfField>& pNeighbours) const;
165     
166 private:
167     
168     // do not allow copy constructor
169     DecimationFilterGradAvg(const DecimationFilterGradAvg&);
170     
171     // do not allow copy
172     DecimationFilterGradAvg& operator=(const DecimationFilterGradAvg&);
173     
174     // do not allow operator ==
175     bool operator==(const DecimationFilterGradAvg&); 
176     
177 }; // class DecimationFilterGradAvg
178
179 //*****************************************************************************
180 // Filter : Treshold
181 //*****************************************************************************
182
183 class DecimationFilterTreshold : public DecimationFilter
184 {
185 public:
186
187     /**
188      * Builds an empty DecimationFilterTreshold (default constructor).
189      */
190     DecimationFilterTreshold();
191     
192     /**
193      * Destructor. Removes everything.
194      */
195     virtual ~DecimationFilterTreshold();
196     
197     /**
198      * Creates a new Mesh by decimating the given Mesh with this DecimationFilter.
199      * 
200      * For each element
201      *     Keep this element if all its points (related to a field) have a value > threshold.
202      *
203      * \param  pMesh        any mesh to be decimated; must not be NULL.
204      * \param  pArgv        all the arguments of the filter as a string; must not be NULL.
205      *                      for GradAvg, expected "fieldName fieldIt threshold radius boxing" (5 parameters).
206      * \param  pNameNewMesh name of the decimated mesh; must not be NULL.
207      * \return the decimated mesh.
208      */
209     virtual Mesh* apply(Mesh* pMesh, const char* pArgv, const char* pNameNewMesh);
210
211     
212 private:
213     
214     // do not allow copy constructor
215     DecimationFilterTreshold(const DecimationFilterTreshold&);
216     
217     // do not allow copy
218     DecimationFilterTreshold& operator=(const DecimationFilterTreshold&);
219     
220     // do not allow operator ==
221     bool operator==(const DecimationFilterTreshold&); 
222     
223 }; // class DecimationFilterTreshold
224
225 } // namespace MULTIPR
226
227
228 #endif // MULTIPR_DECIMATION_FILTER_HXX
229
230 // EOF