]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPR/MULTIPR_DecimationAccel.hxx
Salome HOME
f85f846656fea101ac41753b9db921236800f96e
[modules/multipr.git] / src / MULTIPR / MULTIPR_DecimationAccel.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_DecimationAccel.hxx
6  *
7  * \brief   Interface DecimationAccel: acceleration structure used for decimation.
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  * 
11  * \date    01/2007
12  */
13
14 #ifndef MULTIPR_DECIMATION_ACCEL_HXX
15 #define MULTIPR_DECIMATION_ACCEL_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 PointOfField;
38
39
40 //*****************************************************************************
41 // Interface DecimationAccel
42 //*****************************************************************************
43
44 class DecimationAccel
45 {       
46 public:
47         
48         /** 
49          * Builds an empty DecimationAccel (default constructor).
50          */
51         DecimationAccel() { /* do nothing */ }
52         
53         /**
54          * Destructor. Removes everything.
55          */
56         virtual ~DecimationAccel() { /* do nothing */ } 
57         
58         //---------------------------------------------------------------------
59         // Algorithms
60         //---------------------------------------------------------------------
61         
62         /**
63          * Interface. Configures this acceleration structure. String is used for genericity.
64          * \param  pArgv all the configuration parameters in a string.
65          */
66         virtual void configure(const char* pArgv) = 0;
67         
68         /**
69          * Interface. Creates a new acceleration structure and fills it with the given list of points.
70          * \param  pPts list of points to be inserted in the acceleration structure.
71          */
72         virtual void create(const std::vector<PointOfField>& pPts) = 0;
73         
74         /**
75          * Interface. Finds all the points in a sphere defined by its center (x,y,z) and its radius.
76          * \param  pCenterX x-coordinates of the center of the sphere.
77          * \param  pCenterY y-coordinates of the center of the sphere.
78          * \param  pCenterZ z-coordinates of the center of the sphere.
79          * \param  pRadius  radius of the sphere.
80          * \return all the points in a sphere defined by its center (x,y,z) and its radius.
81          */
82         virtual std::vector<PointOfField> findNeighbours(
83                 med_float pCenterX,
84                 med_float pCenterY,
85                 med_float pCenterZ,
86                 med_float pRadius) const = 0;
87         
88         //---------------------------------------------------------------------
89         // I/O
90         //---------------------------------------------------------------------
91         
92         /**
93          * Sets the flag which control the stream operator <<.
94          * \param  pFlag new flag value.
95          */
96         void setPrintAll(bool pFlag) { mFlagPrintAll = pFlag; } 
97         
98         /**
99          * Dumps any GaussLoc to the given output stream.
100          * \param  pOs any output stream.
101          * \param  pA  any DecimationAccel.
102          * \return the output stream pOs.
103          */
104         friend std::ostream& operator<<(std::ostream& pOs, DecimationAccel& pA);
105         
106 protected:
107
108         bool mFlagPrintAll;  /** Flag to control the behaviour of the stream operator <<. */
109         
110 private:
111         
112         // do not allow copy constructor
113         DecimationAccel(const DecimationAccel&);
114         
115         // do not allow copy
116         DecimationAccel& operator=(const DecimationAccel&);
117         
118         // do not allow operator ==
119         bool operator==(const DecimationAccel&); 
120
121 }; // class DecimationAccel
122
123
124 //*****************************************************************************
125 // Interface DecimationFilter and factory to build filters.
126 //*****************************************************************************
127
128 class DecimationAccelGrid : public DecimationAccel
129 {
130 public:
131
132         /**
133          * Builds an empty DecimationAccelGrid (default constructor).
134          */
135         DecimationAccelGrid();
136         
137         /**
138          * Destructor. Removes everything.
139          */
140         virtual ~DecimationAccelGrid();
141         
142         /**
143          * Resets this object in its state by default (empty). Cleans memory.
144          */
145         void reset();
146         
147         //---------------------------------------------------------------------
148         // Algorithms
149         //---------------------------------------------------------------------
150         
151         /**
152          * Configures this acceleration structure. String is used for genericity.
153          * \param  pArgv assumes "size_x size_y size_z": number of cells along each axis.
154          */
155         virtual void configure(const char* pArgv);
156         
157         /**
158          * Creates a new acceleration structure and fills it with the given list of points.
159          * setSize() must have been called before.
160          * \param  pPts list of points to be inserted in the acceleration structure.
161          * \throw  IllegalStateException if setSize() has not been called before.
162          */
163         virtual void create(const std::vector<PointOfField>& pPts);
164         
165         /**
166          * Finds all the points in a sphere defined by its center (x,y,z) and its radius.
167          * \param  pCenterX x-coordinates of the center of the sphere.
168          * \param  pCenterY y-coordinates of the center of the sphere.
169          * \param  pCenterZ z-coordinates of the center of the sphere.
170          * \param  pRadius  radius of the sphere.
171          * \return all the points in a sphere defined by its center (x,y,z) and its radius.
172          */
173         virtual std::vector<PointOfField> findNeighbours(
174                 med_float pCenterX,
175                 med_float pCenterY,
176                 med_float pCenterZ,
177                 med_float pRadius) const;
178         
179         /**
180          * Returns the coordinates of the cell which contain the point (x,y,z).
181          * Clamping is performed on (pIx, pIy, pIz) to avoid out of bounds.
182          * \param  pX  (in) X-coordinates of the point.
183          * \param  pY  (in) Y-coordinates of the point.
184          * \param  pZ  (in) Z-coordinates of the point.
185          * \param  pIx (out) X-index of the cell which contain the point (x,y,z).
186          * \param  pIy (out) Y-index.
187          * \param  pIz (out) Z-index.
188          */
189         void getCellCoord(
190                 med_float pX, med_float pY, med_float pZ,
191                 int* pIx, int* pIy, int* pIz) const;
192         
193         /**
194          * Returns the index of the cell whose coordinates are (i, j, k).
195          * \param  pI
196          * \param  pJ
197          * \param  pK
198          * \return the index of the cell (i, j, k).
199          */
200         int getCellIndex(int pI, int pJ, int pK) const;
201         
202         /**
203          * Returns the list of points contained in the cell of pPt.
204          * \param  pPt any point which coordinates are in the bbox of this acceleration structure.
205          * \return the list of points contained in the cell of pPt.
206          */
207         std::vector<PointOfField>& getCell(const PointOfField& pPt);
208         
209         //---------------------------------------------------------------------
210         // I/O
211         //---------------------------------------------------------------------
212         
213         /**
214          * Dumps any GaussLoc to the given output stream.
215          * \param  pOs any output stream.
216          * \param  pG  any DecimationAccelGrid.
217          * \return the output stream pOs.
218          */
219         friend std::ostream& operator<<(std::ostream& pOs, DecimationAccelGrid& pG);
220         
221 private:
222         
223         /**
224          * Computes the axis-aligned bounding box of a set of points.
225          * Sets the fields mMin/mMax.
226          * \param  pPts list of points.
227          */
228         void computeBBox(const std::vector<PointOfField>& pPts);
229         
230 private:
231         
232         int                         mNum;        /**< Number of points in the grid. */
233         med_float                   mMin[3];     /**< Bounding box, min corner. */
234         med_float                   mMax[3];     /**< Bounding box, max corner. */
235         med_float                   mInvLen[3];  /**< 1/length of cells, along each dimension. */
236         med_int                     mSize[3];    /**< Number of cells along each dimension. */
237         std::vector<PointOfField>*  mGrid;       /**< Flatten grid structure; each cell is a vector of PointOfField. */         
238         
239 private:
240         
241         // do not allow copy constructor
242         DecimationAccelGrid(const DecimationAccelGrid&);
243         
244         // do not allow copy
245         DecimationAccelGrid& operator=(const DecimationAccelGrid&);
246         
247         // do not allow operator ==
248         bool operator==(const DecimationAccelGrid&); 
249         
250 }; // class DecimationAccelGrid
251
252
253 } // namespace MULTIPR
254
255
256 #endif // MULTIPR_DECIMATION_ACCEL_HXX
257
258 // EOF