SelectableImageViewer.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package VisionX::ArmarXObjects::SelectableImageViewer
17 * @author Rainer Kartmann ( rainer dot kartmann at student dot kit dot edu )
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25
26using namespace armarx;
27
31
32void
34{
35 int clickedX = ev->x();
36 int clickedY = ev->y();
37
38 Vec2d dimensions = getScaledImageDimensions();
39
40 // should probably not happen, but check it just in case
41 if (clickedX < 0 || clickedX > dimensions.x || clickedY < 0 || clickedY > dimensions.y)
42 {
43 return; // ignore
44 }
45
46
47 float relX = std::min(float(clickedX), dimensions.x - 1); // in [0 .. dims.x - 1]
48 float relY = std::min(float(clickedY), dimensions.y - 1); // in [0 .. dims.y - 1]
49
50 relX /= dimensions.x; // in [0 .. 1)
51 relY /= dimensions.y; // in [0 .. 1)
52
53 // find corresponsing image and adapt relX accordingly
54
55 int numberImages = getNumberImages();
56 int imageIndex = int(relX * numberImages); // in [0 .. numImages]
57
58 // move relX to [0, 1/numImages)
59 relX -= float(imageIndex) / numberImages;
60 // e.g. 1st (idx 0) of 2 imgs: subtract 0/2 = 0.0 => relX in [0 .. 0.5)
61 // e.g. 3rd (idx 2) of 3 imgs: subtract 2/3 = 0.67 => relX in [0 .. 0.33)
62
63 // scale up to [0, 1)
64 relX *= numberImages;
65
66 emit selected();
67 emit selected(imageIndex, relX, relY);
68}
#define float
Definition 16_Level.h:22
void mousePressEvent(QMouseEvent *ev) override
void selected()
Signals that a pixel was selected in the image viewer.
ImageViewerArea(QWidget *parent=0)
This file offers overloads of toIce() and fromIce() functions for STL container types.
ArmarX headers.