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 
23 #include "SelectableImageViewer.h"
24 
25 
26 using namespace armarx;
27 
29  visionx::ImageViewerArea(parent)
30 {
31 }
32 
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
42  || clickedY < 0 || clickedY > dimensions.y)
43  {
44  return; // ignore
45  }
46 
47 
48  float relX = std::min(float(clickedX), dimensions.x - 1); // in [0 .. dims.x - 1]
49  float relY = std::min(float(clickedY), dimensions.y - 1); // in [0 .. dims.y - 1]
50 
51  relX /= dimensions.x; // in [0 .. 1)
52  relY /= dimensions.y; // in [0 .. 1)
53 
54  // find corresponsing image and adapt relX accordingly
55 
56  int numberImages = getNumberImages();
57  int imageIndex = int(relX * numberImages); // in [0 .. numImages]
58 
59  // move relX to [0, 1/numImages)
60  relX -= float(imageIndex) / numberImages;
61  // e.g. 1st (idx 0) of 2 imgs: subtract 0/2 = 0.0 => relX in [0 .. 0.5)
62  // e.g. 3rd (idx 2) of 3 imgs: subtract 2/3 = 0.67 => relX in [0 .. 0.33)
63 
64  // scale up to [0, 1)
65  relX *= numberImages;
66 
67  emit selected();
68  emit selected(imageIndex, relX, relY);
69 }
70 
armarx::SelectableImageViewer::selected
void selected()
Signals that a pixel was selected in the image viewer.
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:694
armarx::SelectableImageViewer::SelectableImageViewer
SelectableImageViewer(QWidget *parent=0)
Definition: SelectableImageViewer.cpp:28
visionx::ImageViewerArea::getScaledImageDimensions
Vec2d getScaledImageDimensions()
Definition: ImageViewerArea.cpp:137
SelectableImageViewer.h
float
#define float
Definition: 16_Level.h:22
armarx::SelectableImageViewer::mousePressEvent
void mousePressEvent(QMouseEvent *ev) override
Definition: SelectableImageViewer.cpp:33
visionx::ImageViewerArea::getNumberImages
int getNumberImages()
Definition: ImageViewerArea.cpp:65
min
T min(T t1, T t2)
Definition: gdiam.h:42
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28