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 
28 SelectableImageViewer::SelectableImageViewer(QWidget* parent) : visionx::ImageViewerArea(parent)
29 {
30 }
31 
32 void
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 }
armarx::SelectableImageViewer::selected
void selected()
Signals that a pixel was selected in the image viewer.
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::SelectableImageViewer::SelectableImageViewer
SelectableImageViewer(QWidget *parent=0)
Definition: SelectableImageViewer.cpp:28
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:736
visionx::ImageViewerArea::getScaledImageDimensions
Vec2d getScaledImageDimensions()
Definition: ImageViewerArea.cpp:149
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:44
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27