]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pFigure.cxx
#2490 creaMaracasVisu Feature New High - Histogram Interaction
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pFigure.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
30 #include "pFigure.h"
31
32 // ---------------------------------------------------------------------------------------------------------------
33 // WX headers inclusion.
34 // For compilers that support precompilation, includes <wx/wx.h>.
35 // ---------------------------------------------------------------------------------------------------------------
36
37 #ifndef WX_PRECOMP
38 #include <wx/wx.h>
39 #endif
40
41 //----------------------------------------------------------------------------------------------------------------
42 // Class implementation
43 //----------------------------------------------------------------------------------------------------------------
44 /** @file pFigure.cxx */
45 IMPLEMENT_CLASS(pFigure, wxObject)
46
47         //------------------------------------------------------------------------------------------------------------
48         // Constructors & Destructors
49         //------------------------------------------------------------------------------------------------------------
50         /**
51         * Create a figure with edges_n edges
52         * @param edges_n The number of edges of the new figure
53         * @param _w The width to set
54         * @param _h The height to set
55         * @param _orientation The orientation to set
56         */
57         pFigure :: pFigure(int edges_n, int _w, int _h, int _orientation, bool bar_orientation)
58         {
59                 edges           = edges_n;
60                 orientation = _orientation;
61                 width           = _w;
62                 heigth          = _h;
63                 setBarOrientation( bar_orientation );
64         }
65
66         pFigure :: ~pFigure()
67         {
68
69         }
70
71         //------------------------------------------------------------------------------------------------------------
72         // Methods
73         //------------------------------------------------------------------------------------------------------------
74
75         /**
76         * Gets the number of edges of the figure
77         * @retval edges Number of edges in the figure
78         */
79         int pFigure :: getNumberEdges()
80         {
81                 return edges;
82         }
83
84         /**
85         * Sets the vertex points of the figure
86         * @param edges Number of edges in the figure to set
87         */
88         void pFigure :: setNumberEdges(int n_edges)
89         {
90                 edges = n_edges;
91         }
92
93         /**
94         * Gets the vertex points of the figure
95         * @param wxPoint The vector to get the points
96         * @retval points Vertex points distribution in the figure
97         */
98         void pFigure :: getVertexPoints(wxPoint thePoints[])
99         {
100                 if (edges == TRIANGLE)
101                 {
102                         int halfWidth = 0;
103                         int halfHeigth = 0;
104                         if ( barOrientation ) // HORIZONTAL
105                         {
106                                 halfWidth = (int)(width/2);
107                                 halfHeigth = (int)(heigth/2);
108                                 switch ( orientation ) 
109                                 {
110                                   case UP : 
111                                         thePoints[0].x = halfWidth;
112                                         thePoints[0].y = 0;
113                                         thePoints[1].x = width;
114                                         thePoints[1].y = heigth;
115                                         thePoints[2].x = -halfWidth;
116                                         thePoints[2].y = heigth;
117                                         break;
118                                         
119                                   case DOWN : 
120                                         thePoints[0].x = halfWidth;
121                                         thePoints[0].y = heigth;
122                                         thePoints[1].x = width;
123                                         thePoints[1].y = 0;
124                                         thePoints[2].x = -halfWidth;
125                                         thePoints[2].y = 0;
126                                         break;
127
128                                   case LEFT : 
129                                         thePoints[0].x = 0;
130                                         thePoints[0].y = halfHeigth;
131                                         thePoints[1].x = width;
132                                         thePoints[1].y = 0;
133                                         thePoints[2].x = width;
134                                         thePoints[2].y = heigth;
135                                         break;
136
137                                   case RIGHT :          
138                                         thePoints[0].x = width;
139                                         thePoints[0].y = halfHeigth;            
140                                         thePoints[1].x = 0;
141                                         thePoints[1].y = 0;
142                                         thePoints[2].x = 0;
143                                         thePoints[2].y = heigth;
144                                         break;
145                                 }                       
146                         }
147                         else // VERTICAL
148                         {
149                                 halfWidth = (int)(heigth/2);
150                                 halfHeigth = (int)(width/2);
151                                 switch ( orientation ) 
152                                 {
153                                   case UP : 
154                                         thePoints[0].x = halfWidth;
155                                         thePoints[0].y = 0;
156                                         thePoints[1].x = heigth;
157                                         thePoints[1].y = width;
158                                         thePoints[2].x = -halfWidth;
159                                         thePoints[2].y = width;
160                                         break;
161                                         
162                                   case DOWN : 
163                                         thePoints[0].x = halfWidth;
164                                         thePoints[0].y = width;
165                                         thePoints[1].x = heigth;
166                                         thePoints[1].y = 0;
167                                         thePoints[2].x = -halfWidth;
168                                         thePoints[2].y = 0;
169                                         break;
170
171                                   case LEFT : 
172                                         thePoints[0].x = 0;
173                                         thePoints[0].y = halfHeigth;
174                                         thePoints[1].x = heigth;
175                                         thePoints[1].y = -halfHeigth;
176                                         thePoints[2].x = heigth;
177                                         thePoints[2].y = width;
178                                         break;
179
180                                   case RIGHT :          
181                                         thePoints[0].x = heigth;
182                                         thePoints[0].y = halfHeigth;            
183                                         thePoints[1].x = 0;
184                                         thePoints[1].y = -halfHeigth;
185                                         thePoints[2].x = 0;
186                                         thePoints[2].y = width;
187                                         break;
188                                 }       
189                         }                               
190                 }
191                 else if (edges == RECTANGLE)
192                 {
193                         if ( barOrientation ) // HORIZONTAL
194                         {
195                                 thePoints[0].x = 0;
196                                 thePoints[0].y = 0;             
197                                 thePoints[1].x = width;
198                                 thePoints[1].y = 0;
199                                 thePoints[2].x = width;
200                                 thePoints[2].y = heigth;
201                                 thePoints[3].x = 0;
202                                 thePoints[3].y = heigth;
203                         }
204                         else // VERTICAL
205                         {
206                                 thePoints[0].x = 0;
207                                 thePoints[0].y = 0;             
208                                 thePoints[1].x = heigth;
209                                 thePoints[1].y = 0;
210                                 thePoints[2].x = heigth;
211                                 thePoints[2].y = width;
212                                 thePoints[3].x = 0;
213                                 thePoints[3].y = width;
214                         }
215                 }
216         }
217
218         /**
219         * Sets the vertex points of the figure
220         * @param edges Vertex points distribution in the figure to set
221         */
222         void pFigure :: setVertexPoints(wxPoint * n_points)
223         {
224                 v_points = n_points;
225         }
226
227         /*
228         * Sets the heigth of the figure
229         * @param _h The heigth to set
230         */
231         void pFigure :: setHeigth(int _h)
232         {
233                 heigth = _h;
234         }
235
236         /*
237         * Gets the heigth of the figure
238         * @retval heigth The heigth of the figure
239         */
240         int pFigure :: getHeigth()
241         {
242                 return heigth;
243         }
244
245         /*
246         * Sets the width of the figure
247         * @param _w The width to set
248         */
249         void pFigure :: setWidth(int _w)
250         {
251                 width = _w;
252         }
253
254         /*
255         * Gets the width of the figure
256         * @retval width The width of the figure
257         */
258         int pFigure :: getWidth()
259         {
260                 return width;
261         }
262
263         /*
264         * Indicates if a pixel point is inside the figure
265         * @param xFig_PixelPoint The known reference point inside the figure
266         * @param xPixel The x-pixel coord asking for
267         * @retval Returns true if the point is inside
268         */
269         bool pFigure :: isPointInside(int xFig_PixelPoint, int xPixel)
270         {
271                 bool isInside = false;
272
273                 if (edges == TRIANGLE)
274                 {
275                         int halfWidth = (int)(width/2)+1;
276                         int halfHeigth = (int)(heigth/2)+1;
277                         if ( orientation == UP || orientation == DOWN )
278                         {
279                                 isInside = (xPixel>=xFig_PixelPoint-halfWidth) && (xPixel<=xFig_PixelPoint+halfWidth);
280                         }
281                         else if( orientation == LEFT || orientation == RIGHT )
282                         {
283                                 isInside = (xPixel>=xFig_PixelPoint-halfHeigth) && (xPixel<=xFig_PixelPoint+halfHeigth);
284                         }                                               
285                 }
286                 else if (edges == RECTANGLE)
287                 {
288                         isInside = (xPixel >= xFig_PixelPoint) && (xPixel<=xFig_PixelPoint+width);
289                 }
290                 return isInside;
291         }
292
293         /*
294         * Sets the bar orientation 
295         * @ bar_orientation The orientation to set (true for horizontal, false for vertical)
296         */
297         void pFigure :: setBarOrientation(bool bar_orientation)
298         {
299                 barOrientation = bar_orientation;
300         }
301
302         /*
303         * Sets the bar orientation used for triangles
304         * @ bar_orientation The orientation to set (LEFT = -4, RIGHT = -6, UP = -8, DOWN = -2)
305         */
306         void pFigure :: setFigureOrientation(int fig_orientation)
307         {
308                 orientation = fig_orientation;
309         }
310
311
312
313