1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
27 //----------------------------------------------------------------------------------------------------------------
28 // Class definition include
29 //----------------------------------------------------------------------------------------------------------------
32 // ---------------------------------------------------------------------------------------------------------------
33 // WX headers inclusion.
34 // For compilers that support precompilation, includes <wx/wx.h>.
35 // ---------------------------------------------------------------------------------------------------------------
41 //----------------------------------------------------------------------------------------------------------------
42 // Class implementation
43 //----------------------------------------------------------------------------------------------------------------
44 /** @file pFigure.cxx */
45 IMPLEMENT_CLASS(pFigure, wxObject)
47 //------------------------------------------------------------------------------------------------------------
48 // Constructors & Destructors
49 //------------------------------------------------------------------------------------------------------------
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
57 pFigure :: pFigure(int edges_n, int _w, int _h, int _orientation, bool bar_orientation)
60 orientation = _orientation;
63 setBarOrientation( bar_orientation );
71 //------------------------------------------------------------------------------------------------------------
73 //------------------------------------------------------------------------------------------------------------
76 * Gets the number of edges of the figure
77 * @retval edges Number of edges in the figure
79 int pFigure :: getNumberEdges()
85 * Sets the vertex points of the figure
86 * @param edges Number of edges in the figure to set
88 void pFigure :: setNumberEdges(int n_edges)
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
98 void pFigure :: getVertexPoints(wxPoint thePoints[])
100 if (edges == TRIANGLE)
104 if ( barOrientation ) // HORIZONTAL
106 halfWidth = (int)(width/2);
107 halfHeigth = (int)(heigth/2);
108 switch ( orientation )
111 thePoints[0].x = halfWidth;
113 thePoints[1].x = width;
114 thePoints[1].y = heigth;
115 thePoints[2].x = -halfWidth;
116 thePoints[2].y = heigth;
120 thePoints[0].x = halfWidth;
121 thePoints[0].y = heigth;
122 thePoints[1].x = width;
124 thePoints[2].x = -halfWidth;
130 thePoints[0].y = halfHeigth;
131 thePoints[1].x = width;
133 thePoints[2].x = width;
134 thePoints[2].y = heigth;
138 thePoints[0].x = width;
139 thePoints[0].y = halfHeigth;
143 thePoints[2].y = heigth;
149 halfWidth = (int)(heigth/2);
150 halfHeigth = (int)(width/2);
151 switch ( orientation )
154 thePoints[0].x = halfWidth;
156 thePoints[1].x = heigth;
157 thePoints[1].y = width;
158 thePoints[2].x = -halfWidth;
159 thePoints[2].y = width;
163 thePoints[0].x = halfWidth;
164 thePoints[0].y = width;
165 thePoints[1].x = heigth;
167 thePoints[2].x = -halfWidth;
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;
181 thePoints[0].x = heigth;
182 thePoints[0].y = halfHeigth;
184 thePoints[1].y = -halfHeigth;
186 thePoints[2].y = width;
191 else if (edges == RECTANGLE)
193 if ( barOrientation ) // HORIZONTAL
197 thePoints[1].x = width;
199 thePoints[2].x = width;
200 thePoints[2].y = heigth;
202 thePoints[3].y = heigth;
208 thePoints[1].x = heigth;
210 thePoints[2].x = heigth;
211 thePoints[2].y = width;
213 thePoints[3].y = width;
219 * Sets the vertex points of the figure
220 * @param edges Vertex points distribution in the figure to set
222 void pFigure :: setVertexPoints(wxPoint * n_points)
228 * Sets the heigth of the figure
229 * @param _h The heigth to set
231 void pFigure :: setHeigth(int _h)
237 * Gets the heigth of the figure
238 * @retval heigth The heigth of the figure
240 int pFigure :: getHeigth()
246 * Sets the width of the figure
247 * @param _w The width to set
249 void pFigure :: setWidth(int _w)
255 * Gets the width of the figure
256 * @retval width The width of the figure
258 int pFigure :: getWidth()
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
269 bool pFigure :: isPointInside(int xFig_PixelPoint, int xPixel)
271 bool isInside = false;
273 if (edges == TRIANGLE)
275 int halfWidth = (int)(width/2)+1;
276 int halfHeigth = (int)(heigth/2)+1;
277 if ( orientation == UP || orientation == DOWN )
279 isInside = (xPixel>=xFig_PixelPoint-halfWidth) && (xPixel<=xFig_PixelPoint+halfWidth);
281 else if( orientation == LEFT || orientation == RIGHT )
283 isInside = (xPixel>=xFig_PixelPoint-halfHeigth) && (xPixel<=xFig_PixelPoint+halfHeigth);
286 else if (edges == RECTANGLE)
288 isInside = (xPixel >= xFig_PixelPoint) && (xPixel<=xFig_PixelPoint+width);
294 * Sets the bar orientation
295 * @ bar_orientation The orientation to set (true for horizontal, false for vertical)
297 void pFigure :: setBarOrientation(bool bar_orientation)
299 barOrientation = bar_orientation;
303 * Sets the bar orientation used for triangles
304 * @ bar_orientation The orientation to set (LEFT = -4, RIGHT = -6, UP = -8, DOWN = -2)
306 void pFigure :: setFigureOrientation(int fig_orientation)
308 orientation = fig_orientation;